|
19 | 19 | QgsRelation,
|
20 | 20 | QgsGeometry,
|
21 | 21 | QgsPointXY,
|
| 22 | + QgsAttributeEditorElement, |
22 | 23 | QgsProject
|
23 | 24 | )
|
| 25 | +from utilities import unitTestDataPath |
24 | 26 | from qgis.testing import start_app, unittest
|
| 27 | +import os |
25 | 28 |
|
26 | 29 | start_app()
|
27 | 30 |
|
@@ -156,6 +159,36 @@ def test_fieldPairs(self):
|
156 | 159 |
|
157 | 160 | assert (rel.fieldPairs() == {'foreignkey': 'y'})
|
158 | 161 |
|
| 162 | + def testValidRelationAfterChangingStyle(self): |
| 163 | + # load project |
| 164 | + myPath = os.path.join(unitTestDataPath(), 'relations.qgs') |
| 165 | + QgsProject.instance().read(myPath) |
| 166 | + |
| 167 | + # get referenced layer |
| 168 | + relations = QgsProject.instance().relationManager().relations() |
| 169 | + relation = relations[list(relations.keys())[0]] |
| 170 | + referencedLayer = relation.referencedLayer() |
| 171 | + |
| 172 | + # check that the relation is valid |
| 173 | + valid = False |
| 174 | + for tab in referencedLayer.editFormConfig().tabs(): |
| 175 | + for t in tab.children(): |
| 176 | + if (t.type() == QgsAttributeEditorElement.AeTypeRelation): |
| 177 | + valid = t.relation().isValid() |
| 178 | + self.assertTrue(valid) |
| 179 | + |
| 180 | + # update style |
| 181 | + referencedLayer.styleManager().setCurrentStyle("custom") |
| 182 | + |
| 183 | + # check that the relation is still valid |
| 184 | + referencedLayer = relation.referencedLayer() |
| 185 | + valid = False |
| 186 | + for tab in referencedLayer.editFormConfig().tabs(): |
| 187 | + for t in tab.children(): |
| 188 | + if (t.type() == QgsAttributeEditorElement.AeTypeRelation): |
| 189 | + valid = t.relation().isValid() |
| 190 | + self.assertTrue(valid) |
| 191 | + |
159 | 192 |
|
160 | 193 | if __name__ == '__main__':
|
161 | 194 | unittest.main()
|
0 commit comments