-
Notifications
You must be signed in to change notification settings - Fork 0
/
qgis_issue_55873_updatefields.py
47 lines (35 loc) · 1.6 KB
/
qgis_issue_55873_updatefields.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from qgis.PyQt.QtCore import QVariant
from qgis._core import QgsVectorLayer
from qgis.core import QgsField, QgsEditorWidgetSetup, edit
from qgis.gui import QgsGui
from qgis.testing import start_app
start_app()
if len(QgsGui.editorWidgetRegistry().factories()) == 0:
QgsGui.editorWidgetRegistry().initEditors()
# Example 1: change editor widget setup
def onFieldsUpdated():
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 editorWidgetSetup
with edit(layer):
# this emits the updatedFields signal
print('Add QgsField')
layer.addAttribute(QgsField('info', QVariant.String))
# this does not emit the updatedFields signal
print('Change QgsField editorWidgetSetup (no emit of updatedFields)')
layer.setEditorWidgetSetup(0, QgsEditorWidgetSetup('Color', {}))
# Example 2: editorWidgetSetup and comment not considered in field comparison
field1 = QgsField('info', QVariant.String)
field2 = QgsField('info', QVariant.String)
assert field1 == field2
assert field1.editorWidgetSetup().type() == field2.editorWidgetSetup().type()
assert field1.comment() == field2.comment()
# change comment and editorWidgetSetup
field2.setEditorWidgetSetup(QgsEditorWidgetSetup('Color', {}))
field2.setComment('Color info value')
assert field1.editorWidgetSetup().type() != field2.editorWidgetSetup().type()
assert field1.comment() != field2.comment()
# different QgsEditorWidgetSetup types, but still same field?
assert field1 != field2