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, {})

        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)
        self.assertEqual(af.currentFilterExpression(), '"fldtext">=\'2013-05-06\' AND "fldtext"<=\'2013-05-16\'')
        af.searchWidgetToolButton().setActiveFlags(QgsSearchWidgetWrapper.IsNotBetween)
        self.assertEqual(af.currentFilterExpression(), '"fldtext"<\'2013-05-06\' OR "fldtext">\'2013-05-16\'')
    def testCurrentFilterExpression(self):
        """ Test creating an expression using the widget"""

        layer = QgsVectorLayer("Point?field=fldint:integer", "test", "memory")
        parent = QWidget()
        w = QgsDefaultSearchWidgetWrapper(layer, 0, parent)
        af = QgsAttributeFormEditorWidget(None, 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)
        self.assertEqual(af.currentFilterExpression(), '"fldint"=5.5')
        af.searchWidgetToolButton().setActiveFlags(QgsSearchWidgetWrapper.NotEqualTo)
        self.assertEqual(af.currentFilterExpression(), '"fldint"<>5.5')
    def testSetActive(self):
        """ Test setting the search as active - should set active flags to match search widget wrapper's defaults """

        layer = QgsVectorLayer("Point?field=fldtext:string&field=fldint:integer", "test", "memory")
        parent = QWidget()
        w = QgsDefaultSearchWidgetWrapper(layer, 0, parent)
        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.findChild(QWidget, "SearchWidgetToolButton")
        # start with inactive
        sb.setActiveFlags(QgsSearchWidgetWrapper.FilterFlags())
        # set to inactive
        sb.setActive()
        # check that correct default flag was taken from search widget wrapper
        self.assertTrue(sb.activeFlags() & QgsSearchWidgetWrapper.Contains)

        # try again with numeric field - default should be "EqualTo"
        w = QgsDefaultSearchWidgetWrapper(layer, 1, parent)
        af.setSearchWidgetWrapper(w)
        # start with inactive
        sb.setActiveFlags(QgsSearchWidgetWrapper.FilterFlags())
        # set to inactive
        sb.setActive()
        # check that correct default flag was taken from search widget wrapper
        self.assertTrue(sb.activeFlags() & QgsSearchWidgetWrapper.EqualTo)
Exemplo n.º 4
0
    def testBetweenFilter(self):
        """ Test creating a between type filter """
        layer = QgsVectorLayer(
            "Point?field=fldtext:string&field=fldint:integer", "test",
            "memory")
        form = QgsAttributeForm(layer)
        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()))

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