Skip to content

Commit

Permalink
Merge pull request #5853 from m-kuhn/valueRelationReadonly
Browse files Browse the repository at this point in the history
Value relation widget: respect readonly state
  • Loading branch information
m-kuhn authored Dec 28, 2017
2 parents 99abc8d + 375daf1 commit a650a03
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class GUI_EXPORT QgsValueRelationWidgetWrapper : public QgsEditorWidgetWrapper
QgsValueRelationFieldFormatter::ValueRelationCache mCache;
QgsVectorLayer *mLayer = nullptr;

bool mEnabled = false;
bool mEnabled = true;

friend class QgsValueRelationWidgetFactory;
friend class TestQgsValueRelationWidgetWrapper;
Expand Down
10 changes: 6 additions & 4 deletions tests/src/gui/testqgsvaluerelationwidgetwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ void TestQgsValueRelationWidgetWrapper::testScrollBarUnlocked()
QgsProject::instance()->addMapLayer( &vl1, false, false );

// build a value relation widget wrapper
QListWidget lw;
QWidget editor;
QgsValueRelationWidgetWrapper w( &vl1, 0, &editor, nullptr );
QgsValueRelationWidgetWrapper w( &vl1, 0, nullptr, nullptr );

QVariantMap config;
config.insert( QStringLiteral( "AllowMulti" ), true );
w.setConfig( config );
w.widget();
w.setEnabled( true );
w.initWidget( &lw );

// add an item virtually
QListWidgetItem item;
Expand Down
41 changes: 31 additions & 10 deletions tests/src/python/test_qgseditwidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

class TestQgsTextEditWidget(unittest.TestCase):

VALUEMAP_NULL_TEXT = "{2839923C-8B7D-419E-B84B-CA2FE9B80EC7}"

@classmethod
def setUpClass(cls):
QgsGui.editorWidgetRegistry().initEditors()
Expand All @@ -39,8 +37,8 @@ def createLayerWithOnePoint(self):
f = QgsFeature()
f.setAttributes(["test", 123])
f.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(100, 200)))
assert pr.addFeatures([f])
assert self.layer.pendingFeatureCount() == 1
self.assertTrue(pr.addFeatures([f]))
self.assertEqual(self.layer.pendingFeatureCount(), 1)
return self.layer

def doAttributeTest(self, idx, expected):
Expand All @@ -50,16 +48,16 @@ def doAttributeTest(self, idx, expected):
editwidget = reg.create('TextEdit', self.layer, idx, config, None, None)

editwidget.setValue('value')
assert editwidget.value() == expected[0]
self.assertEqual(editwidget.value(), expected[0])

editwidget.setValue(123)
assert editwidget.value() == expected[1]
self.assertEqual(editwidget.value(), expected[1])

editwidget.setValue(None)
assert editwidget.value() == expected[2]
self.assertEqual(editwidget.value(), expected[2])

editwidget.setValue(NULL)
assert editwidget.value() == expected[3]
self.assertEqual(editwidget.value(), expected[3])

def test_SetValue(self):
self.createLayerWithOnePoint()
Expand All @@ -70,7 +68,7 @@ def test_SetValue(self):
def testStringWithMaxLen(self):
""" tests that text edit wrappers correctly handle string fields with a maximum length """
layer = QgsVectorLayer("none?field=fldint:integer", "layer", "memory")
assert layer.isValid()
self.assertTrue(layer.isValid())
layer.dataProvider().addAttributes([QgsField('max', QVariant.String, 'string', 10),
QgsField('nomax', QVariant.String, 'string', 0)])
layer.updateFields()
Expand All @@ -94,9 +92,29 @@ def testStringWithMaxLen(self):

QgsProject.instance().removeAllMapLayers()


class TestQgsValueRelationWidget(unittest.TestCase):

def test_enableDisable(self):
reg = QgsGui.editorWidgetRegistry()
layer = QgsVectorLayer("none?field=number:integer", "layer", "memory")
wrapper = reg.create('ValueRelation', layer, 0, {}, None, None)

widget = wrapper.widget()

self.assertTrue(widget.isEnabled())
wrapper.setEnabled(False)
self.assertFalse(widget.isEnabled())
wrapper.setEnabled(True)
self.assertTrue(widget.isEnabled())


class TestQgsValueMapEditWidget(unittest.TestCase):
VALUEMAP_NULL_TEXT = "{2839923C-8B7D-419E-B84B-CA2FE9B80EC7}"

def test_ValueMap_set_get(self):
layer = QgsVectorLayer("none?field=number:integer", "layer", "memory")
assert layer.isValid()
self.assertTrue(layer.isValid())
QgsProject.instance().addMapLayer(layer)
reg = QgsGui.editorWidgetRegistry()
configWdg = reg.createConfigWidget('ValueMap', layer, 0, None)
Expand All @@ -110,4 +128,7 @@ def test_ValueMap_set_get(self):
self.assertEqual(configWdg.config(), config)

QgsProject.instance().removeAllMapLayers()


if __name__ == "__main__":
unittest.main()

0 comments on commit a650a03

Please sign in to comment.