|
20 | 20 | QgsVectorLayer,
|
21 | 21 | QgsReadWriteContext,
|
22 | 22 | QgsEditFormConfig,
|
23 |
| - QgsFetchedContent) |
| 23 | + QgsFetchedContent, |
| 24 | + QgsAttributeEditorContainer, |
| 25 | + ) |
24 | 26 | from qgis.gui import QgsGui
|
25 | 27 |
|
26 | 28 | from qgis.testing import start_app, unittest
|
27 | 29 | from qgis.PyQt.QtXml import QDomDocument, QDomElement
|
| 30 | +from qgis.PyQt.QtGui import QColor |
28 | 31 | from utilities import unitTestDataPath
|
29 | 32 | import socketserver
|
30 | 33 | import threading
|
@@ -84,14 +87,16 @@ def testFormUi(self):
|
84 | 87 | config.setLayout(QgsEditFormConfig.GeneratedLayout)
|
85 | 88 | self.assertEqual(config.layout(), QgsEditFormConfig.GeneratedLayout)
|
86 | 89 |
|
87 |
| - uiLocal = os.path.join(unitTestDataPath(), '/qgis_local_server/layer_attribute_form.ui') |
| 90 | + uiLocal = os.path.join( |
| 91 | + unitTestDataPath(), '/qgis_local_server/layer_attribute_form.ui') |
88 | 92 | config.setUiForm(uiLocal)
|
89 | 93 | self.assertEqual(config.layout(), QgsEditFormConfig.UiFileLayout)
|
90 | 94 |
|
91 | 95 | config.setLayout(QgsEditFormConfig.GeneratedLayout)
|
92 | 96 | self.assertEqual(config.layout(), QgsEditFormConfig.GeneratedLayout)
|
93 | 97 |
|
94 |
| - uiUrl = 'http://localhost:' + str(self.port) + '/qgis_local_server/layer_attribute_form.ui' |
| 98 | + uiUrl = 'http://localhost:' + \ |
| 99 | + str(self.port) + '/qgis_local_server/layer_attribute_form.ui' |
95 | 100 | config.setUiForm(uiUrl)
|
96 | 101 | self.assertEqual(config.layout(), QgsEditFormConfig.UiFileLayout)
|
97 | 102 | content = QgsApplication.networkContentFetcherRegistry().fetch(uiUrl)
|
@@ -140,6 +145,19 @@ def testLabelOnTop(self):
|
140 | 145 | self.assertFalse(config.labelOnTop(0))
|
141 | 146 | self.assertFalse(config.labelOnTop(1))
|
142 | 147 |
|
| 148 | + def test_backgroundColorSerialize(self): |
| 149 | + """Test backgroundColor serialization""" |
| 150 | + |
| 151 | + layer = self.createLayer() |
| 152 | + config = layer.editFormConfig() |
| 153 | + color_name = '#ff00ff' |
| 154 | + container = QgsAttributeEditorContainer('container name', None, QColor('#ff00ff')) |
| 155 | + doc = QDomDocument() |
| 156 | + element = container.toDomElement(doc) |
| 157 | + config = QgsEditFormConfig() |
| 158 | + container2 = config.attributeEditorElementFromDomElement(element, None, self.layer.id()) |
| 159 | + self.assertEqual(container2.backgroundColor().name(), color_name) |
| 160 | + |
143 | 161 |
|
144 | 162 | if __name__ == '__main__':
|
145 | 163 | unittest.main()
|
0 commit comments