Skip to content

Commit

Permalink
Merge pull request #8925 from signedav/basic-values
Browse files Browse the repository at this point in the history
Enable/disable value relation widget
  • Loading branch information
3nids authored Jan 24, 2019
2 parents b5febe5 + 237e0bc commit ff20d18
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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 );
}
}
}
Expand Down
22 changes: 20 additions & 2 deletions tests/src/python/test_qgseditwidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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}"
Expand Down

0 comments on commit ff20d18

Please sign in to comment.