Skip to content
Permalink
Browse files

Fix failing tests

  • Loading branch information
m-kuhn committed Nov 20, 2017
1 parent 456ceba commit f8a8cb96b86399c055701600e331f1f2ec5cb50d
@@ -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();
}
@@ -18,6 +18,7 @@
QgsAttributeFormEditorWidget,
QgsDefaultSearchWidgetWrapper,
QgsAttributeForm,
QgsSearchWidgetToolButton,
QgsGui
)
from qgis.core import (QgsVectorLayer)
@@ -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):
@@ -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
@@ -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\'')


0 comments on commit f8a8cb9

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