Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Nov 20, 2017
1 parent 456ceba commit f8a8cb9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/gui/editorwidgets/core/qgseditorwidgetwrapper.cpp
Expand Up @@ -38,8 +38,9 @@ int QgsEditorWidgetWrapper::fieldIdx() const

QgsField QgsEditorWidgetWrapper::field() const
{
if ( mFieldIdx < layer()->fields().count() )
return layer()->fields().at( mFieldIdx );
QgsVectorLayer *vl = layer();
if ( vl && mFieldIdx < vl->fields().count() )
return vl->fields().at( mFieldIdx );
else
return QgsField();
}
Expand Down
26 changes: 17 additions & 9 deletions tests/src/python/test_qgsattributeformeditorwidget.py
Expand Up @@ -18,6 +18,7 @@
QgsAttributeFormEditorWidget,
QgsDefaultSearchWidgetWrapper,
QgsAttributeForm,
QgsSearchWidgetToolButton,
QgsGui
)
from qgis.core import (QgsVectorLayer)
Expand All @@ -37,14 +38,17 @@ def testCurrentFilterExpression(self):
layer = QgsVectorLayer("Point?field=fldint:integer", "test", "memory")
parent = QWidget()
w = QgsDefaultSearchWidgetWrapper(layer, 0, parent)
af = QgsAttributeFormEditorWidget(None, None)
setup = QgsGui.editorWidgetRegistry().findBest(layer, "fldint")
wrapper = QgsGui.editorWidgetRegistry().create(layer, 0, None, parent)
af = QgsAttributeFormEditorWidget(wrapper, setup.type(), None)
af.setSearchWidgetWrapper(w)

# test that filter combines both current value in search widget wrapper and flags from search tool button
w.lineEdit().setText('5.5')
af.searchWidgetToolButton().setActiveFlags(QgsSearchWidgetWrapper.EqualTo)
sb = af.findChild(QWidget, "SearchWidgetToolButton")
sb.setActiveFlags(QgsSearchWidgetWrapper.EqualTo)
self.assertEqual(af.currentFilterExpression(), '"fldint"=5.5')
af.searchWidgetToolButton().setActiveFlags(QgsSearchWidgetWrapper.NotEqualTo)
sb.setActiveFlags(QgsSearchWidgetWrapper.NotEqualTo)
self.assertEqual(af.currentFilterExpression(), '"fldint"<>5.5')

def testSetActive(self):
Expand All @@ -53,10 +57,12 @@ def testSetActive(self):
layer = QgsVectorLayer("Point?field=fldtext:string&field=fldint:integer", "test", "memory")
parent = QWidget()
w = QgsDefaultSearchWidgetWrapper(layer, 0, parent)
af = QgsAttributeFormEditorWidget(None, None)
setup = QgsGui.editorWidgetRegistry().findBest(layer, "fldint")
wrapper = QgsGui.editorWidgetRegistry().create(layer, 0, None, parent)
af = QgsAttributeFormEditorWidget(wrapper, setup.type(), None)
af.setSearchWidgetWrapper(w)

sb = af.searchWidgetToolButton()
sb = af.findChild(QWidget, "SearchWidgetToolButton")
# start with inactive
sb.setActiveFlags(QgsSearchWidgetWrapper.FilterFlags())
# set to inactive
Expand All @@ -78,17 +84,19 @@ def testBetweenFilter(self):
""" Test creating a between type filter """
layer = QgsVectorLayer("Point?field=fldtext:string&field=fldint:integer", "test", "memory")
form = QgsAttributeForm(layer)
af = QgsAttributeFormEditorWidget(None, form)
af.createSearchWidgetWrappers("DateTime", 0, {})
wrapper = QgsGui.editorWidgetRegistry().create(layer, 0, None, form)
af = QgsAttributeFormEditorWidget(wrapper, 'DateTime', None)
af.createSearchWidgetWrappers()

d1 = af.findChildren(QDateTimeEdit)[0]
d2 = af.findChildren(QDateTimeEdit)[1]
d1.setDateTime(QDateTime(QDate(2013, 5, 6), QTime()))
d2.setDateTime(QDateTime(QDate(2013, 5, 16), QTime()))

af.searchWidgetToolButton().setActiveFlags(QgsSearchWidgetWrapper.Between)
sb = af.findChild(QWidget, "SearchWidgetToolButton")
sb.setActiveFlags(QgsSearchWidgetWrapper.Between)
self.assertEqual(af.currentFilterExpression(), '"fldtext">=\'2013-05-06\' AND "fldtext"<=\'2013-05-16\'')
af.searchWidgetToolButton().setActiveFlags(QgsSearchWidgetWrapper.IsNotBetween)
sb.setActiveFlags(QgsSearchWidgetWrapper.IsNotBetween)
self.assertEqual(af.currentFilterExpression(), '"fldtext"<\'2013-05-06\' OR "fldtext">\'2013-05-16\'')


Expand Down

0 comments on commit f8a8cb9

Please sign in to comment.