|
14 | 14 |
|
15 | 15 | import qgis # NOQA
|
16 | 16 |
|
17 |
| -from qgis.core import QgsMapLayerRegistry, QgsFeature, QgsGeometry, QgsPoint, QgsProject, QgsRelation, QgsVectorLayer, NULL |
| 17 | +from qgis.core import (QgsMapLayerRegistry, QgsFeature, QgsGeometry, QgsPoint, QgsProject, QgsRelation, QgsVectorLayer, NULL, |
| 18 | + QgsField) |
18 | 19 | from qgis.gui import QgsEditorWidgetRegistry
|
19 | 20 |
|
20 | 21 | from qgis.testing import start_app, unittest
|
| 22 | +from qgis.PyQt.QtCore import QVariant |
| 23 | +from qgis.PyQt.QtWidgets import QTextEdit |
21 | 24 |
|
22 | 25 | start_app()
|
23 | 26 |
|
@@ -63,6 +66,33 @@ def test_SetValue(self):
|
63 | 66 | self.doAttributeTest(0, ['value', '123', NULL, NULL])
|
64 | 67 | self.doAttributeTest(1, [NULL, 123, NULL, NULL])
|
65 | 68 |
|
| 69 | + def testStringWithMaxLen(self): |
| 70 | + """ tests that text edit wrappers correctly handle string fields with a maximum length """ |
| 71 | + layer = QgsVectorLayer("none?field=fldint:integer", "layer", "memory") |
| 72 | + assert layer.isValid() |
| 73 | + layer.dataProvider().addAttributes([QgsField('max', QVariant.String, 'string', 10), |
| 74 | + QgsField('nomax', QVariant.String, 'string', 0)]) |
| 75 | + layer.updateFields() |
| 76 | + QgsMapLayerRegistry.instance().addMapLayer(layer) |
| 77 | + |
| 78 | + reg = QgsEditorWidgetRegistry.instance() |
| 79 | + config = {'IsMultiline': 'True'} |
| 80 | + |
| 81 | + # first test for field without character limit |
| 82 | + editor = QTextEdit() |
| 83 | + editor.setPlainText('this_is_a_long_string') |
| 84 | + w = reg.create('TextEdit', layer, 2, config, editor, None) |
| 85 | + self.assertEqual(w.value(), 'this_is_a_long_string') |
| 86 | + |
| 87 | + # next test for field with character limit |
| 88 | + editor = QTextEdit() |
| 89 | + editor.setPlainText('this_is_a_long_string') |
| 90 | + w = reg.create('TextEdit', layer, 1, config, editor, None) |
| 91 | + |
| 92 | + self.assertEqual(w.value(), 'this_is_a_') |
| 93 | + |
| 94 | + QgsMapLayerRegistry.instance().removeAllMapLayers() |
| 95 | + |
66 | 96 | def test_ValueRelation_representValue(self):
|
67 | 97 |
|
68 | 98 | first_layer = QgsVectorLayer("none?field=foreign_key:integer",
|
|
0 commit comments