Skip to content
Permalink
Browse files

Merge pull request #8925 from signedav/basic-values

Enable/disable value relation widget
  • Loading branch information
3nids committed Jan 24, 2019
2 parents b5febe5 + 237e0bc commit ff20d1800ed82b3e11ddbc9153178b284a7f1cb2
Showing with 23 additions and 6 deletions.
  1. +3 −4 src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.cpp
  2. +20 −2 tests/src/python/test_qgseditwidgets.py
@@ -193,6 +193,8 @@ void QgsValueRelationWidgetWrapper::setValue( const QVariant &value )
if ( item )
{
item->setCheckState( checkList.contains( item->data( Qt::UserRole ).toString() ) ? Qt::Checked : Qt::Unchecked );
//re-set enabled state because it's lost after reloading items
item->setFlags( mEnabled ? item->flags() | Qt::ItemIsEnabled : item->flags() & ~Qt::ItemIsEnabled );
lastChangedItem = item;
}
}
@@ -399,10 +401,7 @@ void QgsValueRelationWidgetWrapper::setEnabled( bool enabled )
QTableWidgetItem *item = mTableWidget->item( j, i );
if ( item )
{
if ( enabled )
item->setFlags( item->flags() | Qt::ItemIsEnabled );
else
item->setFlags( item->flags() & ~Qt::ItemIsEnabled );
item->setFlags( enabled ? item->flags() | Qt::ItemIsEnabled : item->flags() & ~Qt::ItemIsEnabled );
}
}
}
@@ -18,8 +18,8 @@
from qgis.gui import QgsGui

from qgis.testing import start_app, unittest
from qgis.PyQt.QtCore import QVariant
from qgis.PyQt.QtWidgets import QTextEdit
from qgis.PyQt.QtCore import Qt, QVariant
from qgis.PyQt.QtWidgets import QTextEdit, QTableWidgetItem

start_app()

@@ -108,6 +108,24 @@ def test_enableDisable(self):
wrapper.setEnabled(True)
self.assertTrue(widget.isEnabled())

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

widget = wrapper.widget()
item = QTableWidgetItem('first item')
widget.setItem(0, 0, item)

# does not change the state the whole widget but the single items instead
wrapper.setEnabled(False)
# widget still true, but items false
self.assertTrue(widget.isEnabled())
self.assertNotEqual(widget.item(0, 0).flags(), widget.item(0, 0).flags() | Qt.ItemIsEnabled)
wrapper.setEnabled(True)
self.assertTrue(widget.isEnabled())
self.assertEqual(widget.item(0, 0).flags(), widget.item(0, 0).flags() | Qt.ItemIsEnabled)


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

0 comments on commit ff20d18

Please sign in to comment.
You can’t perform that action at this time.