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)
    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)
    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')
Beispiel #4
0
    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')