You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The QgsField operator== does not recognize changes of the editor widget setup type. As a consequence, a call QgsVectorLayer::setEditorWidgetSetup(...), which calls QgsVectorLayer::updateFields(), will not recognize the change of field attributes and not trigger the QgsVectorLayer::updatedFields() signal.
According to the docs, the QgsVectorLayer::updatedFields() signal should be emitted whenever the fields available from this layer have been changed. As this is not the case, objects / widgets that rely on the signal and use QgsField information may have problems to get refreshed accordingly.
As a workaround, a call to QgsVectorLayer::setEditorWidgetSetup(...) may explicitely followed by an emit of updatedFields, like in this python snippet:
The following python code that two fields are considered equal despite having different
fromqgis.PyQt.QtCoreimportQVariantfromqgis._coreimportQgsVectorLayerfromqgis.coreimportQgsField, QgsEditorWidgetSetup, editfromqgis.guiimportQgsGuifromqgis.testingimportstart_appstart_app()
iflen(QgsGui.editorWidgetRegistry().factories()) ==0:
QgsGui.editorWidgetRegistry().initEditors()
# Example 1: change editor widget setupdefonFieldsUpdated():
print('-- updatedFields emitted!')
uri="point?crs=epsg:4326&field=color:string"layer=QgsVectorLayer(uri, "Scratch point layer", "memory")
layer.updatedFields.connect(onFieldsUpdated)
# Example 1: updatesFields is not emitted when changing the editorWidgetSetupwithedit(layer):
# this emits the updatedFields signalprint('Add QgsField')
layer.addAttribute(QgsField('info', QVariant.String))
# this does not emit the updatedFields signalprint('Change QgsField editorWidgetSetup (no emit of updatedFields)')
layer.setEditorWidgetSetup(0, QgsEditorWidgetSetup('Color', {}))
# Example 2: editorWidgetSetup and comment not considered in field comparisonfield1=QgsField('info', QVariant.String)
field2=QgsField('info', QVariant.String)
assertfield1==field2assertfield1.editorWidgetSetup().type() ==field2.editorWidgetSetup().type()
assertfield1.comment() ==field2.comment()
# change comment and editorWidgetSetupfield2.setEditorWidgetSetup(QgsEditorWidgetSetup('Color', {}))
field2.setComment('Color info value')
assertfield1.editorWidgetSetup().type() !=field2.editorWidgetSetup().type()
assertfield1.comment() !=field2.comment()
# different QgsEditorWidgetSetup types, but still same field?assertfield1!=field2
Versions
<style type="text/css">
p, li { white-space: pre-wrap; }
</style>
QGIS version
3.34.2-Prizren
QGIS code revision
[7d19979](https://github.com/qgis/QGIS/commit/7d199797fc)
Qt version
5.15.3
Python version
3.9.5
Compiled against GDAL/OGR
3.8.2
Running against GDAL/OGR
3.8.3
PROJ version
9.3.1
EPSG Registry database version
v10.098 (2023-11-24)
GEOS version
3.12.1-CAPI-1.18.1
SQLite version
3.41.1
PDAL version
2.6.0
PostgreSQL client version
15.2
SpatiaLite version
5.1.0
QWT version
6.1.6
QScintilla2 version
2.13.4
OS version
Windows 10 Version 2009
Supported QGIS version
I'm running a supported QGIS version according to the roadmap.
What is the bug or the crash?
The QgsField operator== does not recognize changes of the editor widget setup type. As a consequence, a call
QgsVectorLayer::setEditorWidgetSetup(...)
, which callsQgsVectorLayer::updateFields()
, will not recognize the change of field attributes and not trigger theQgsVectorLayer::updatedFields()
signal.According to the docs, the
QgsVectorLayer::updatedFields()
signal should be emitted whenever the fields available from this layer have been changed. As this is not the case, objects / widgets that rely on the signal and use QgsField information may have problems to get refreshed accordingly.As a workaround, a call to
QgsVectorLayer::setEditorWidgetSetup(...)
may explicitely followed by an emit ofupdatedFields
, like in this python snippet:Steps to reproduce the issue
The following python code that two fields are considered equal despite having different
Versions
<style type="text/css"> p, li { white-space: pre-wrap; } </style>Supported QGIS version
New profile
Additional context
No response
The text was updated successfully, but these errors were encountered: