[QGIS-Developer] reload attribute table does not work for attribute changed by dataProvider
Matthias Kuhn
matthias at opengis.ch
Wed Jun 13 03:16:57 PDT 2018
Glad you like it :)
Forwading this answer also to the mailing list for future reference,
Ethan, you need to use "reply to all" in your mail application or other
are not able to follow our conversation (which would be a pity ;) ).
Best regards
Matthias
On 06/13/2018 12:13 PM, Zhang Qun wrote:
> Wow, i was about to look into the with() statement. It looks much
> better. Many thanks for the link.
>
> Regards,
> Ethan
>
>
> On Wed, Jun 13, 2018, 6:03 PM Matthias Kuhn <matthias at opengis.ch
> <mailto:matthias at opengis.ch>> wrote:
>
> Hi Ethan,
>
> there are of course advantages and disadvantages of both methods, but in
> most cases the QgsVectorLayer ones just "do the right thing", especially
> when used with a `with` block, see also this post:
>
> http://www.opengis.ch/2015/08/12/with-edit-layer/
>
> Cheers
> Matthias
>
> On 06/13/2018 11:59 AM, Zhang Qun wrote:
> > Hi Matthias,
> >
> > Thanks very much for the instruction. I will try it out. The
> > dataProvider method seems simpler to me and it can set attributes in
> > batch as it takes a list as input. The layer method seems only
> takes one
> > input. If i want to change 10 attributes of a feature, i have to issue
> > 10 commands.
> >
> > Best regards,
> > Ethan
> >
> >
> > On Wed, Jun 13, 2018, 5:45 PM Matthias Kuhn <matthias at opengis.ch
> <mailto:matthias at opengis.ch>
> > <mailto:matthias at opengis.ch <mailto:matthias at opengis.ch>>> wrote:
> >
> > Hi Ethan
> >
> > On 06/13/2018 11:18 AM, Zhang Qun wrote:
> > > Hi everyone, i"m using QGIS2.18, and trying to change feature
> > attributes
> > > using the following two methods:
> > >
> > > *dataProvider:*
> > >
> > > |attrs
> > ={0:"hello",1:123}layer.dataProvider().changeAttributeValues({fid
> > > :attrs })|
> > >
> > > *layer object:*
> > >
> > >
> >
> |layer.startEditing()layer.changeAttributeValue(fid,fieldIndex,value)layer.commitChanges()|
> > >
> > > I keep the attribute table open, and monitor the changes.
> The first
> > > method dataProvider is not able to update the attribute
> table on the
> > > fly, even the "reload table" button on the top menu of the
> table does
> > > not work. I have to re-open the table to see the changes.
> The second
> > > method is working, the attribute table gets instantly updated.
> > >
> > > I would like to stay with the dataProvider method but not
> sure how to
> > > get instantly updated attribute table?
> >
> > The provider's dataChanged() signal needs to be emitted, I
> think you can
> > directly emit that or call `dataProvider().forceReload()`.
> >
> > Out of curiosity, why would you like to stay with the
> dataProvider
> > method?
> >
> > Bests
> > Matthias
> >
> >
> > >
> > > Thanks.
> > >
> > > Best regards,
> > > Ethan
> > >
> > >
> > > _______________________________________________
> > > QGIS-Developer mailing list
> > > QGIS-Developer at lists.osgeo.org
> <mailto:QGIS-Developer at lists.osgeo.org>
> <mailto:QGIS-Developer at lists.osgeo.org
> <mailto:QGIS-Developer at lists.osgeo.org>>
> > > List info:
> https://lists.osgeo.org/mailman/listinfo/qgis-developer
> > > Unsubscribe:
> https://lists.osgeo.org/mailman/listinfo/qgis-developer
> > >
> > _______________________________________________
> > QGIS-Developer mailing list
> > QGIS-Developer at lists.osgeo.org
> <mailto:QGIS-Developer at lists.osgeo.org>
> <mailto:QGIS-Developer at lists.osgeo.org
> <mailto:QGIS-Developer at lists.osgeo.org>>
> > List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> > Unsubscribe:
> https://lists.osgeo.org/mailman/listinfo/qgis-developer
> >
>
More information about the QGIS-Developer
mailing list