[QGIS-Developer] reload attribute table does not work for attribute changed by dataProvider

Zhang Qun zhangq.rhy at gmail.com
Fri Jun 15 03:26:46 PDT 2018


it's QgsEditException. The edit(layer) statement is working just fine.

On Thu, Jun 14, 2018, 8:11 PM Thomas Baumann <rdbath.regiodata at gmail.com>
wrote:

> Hello,
> isnt it "QgsEditError" instead of "QgsEditException"?
>
> regards,
> Thomas
>
>
> Am Do., 14. Juni 2018 um 03:26 Uhr schrieb Zhang Qun <zhangq.rhy at gmail.com
> >:
>
>> Hi Matthias
>>
>> I follow the steps in the link you posted and get the following errors
>> when trying to import
>>
>> ImportError: cannot import name QgsEditException
>>
>> Do I have to install some modules? Didn't find any luck on google.
>>
>> Best regards,
>> Zhang Qun
>>
>> On Wed, Jun 13, 2018 at 6:16 PM, Matthias Kuhn <matthias at opengis.ch>
>> wrote:
>>
>>> 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
>>> >     >
>>> >
>>>
>>
>> _______________________________________________
>> QGIS-Developer mailing list
>> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20180615/fdcff5fa/attachment.html>


More information about the QGIS-Developer mailing list