def testDefaultAction(self):
        """ test default action for layer"""

        self.manager.clearActions()
        action1 = QgsAction(QgsAction.GenericPython, 'test_action', '', 'i=1', False, actionScopes={'Feature'})
        self.manager.addAction(action1)
        action2 = QgsAction(QgsAction.GenericPython, 'test_action2', 'i=2')
        self.manager.addAction(action2)

        # initially should be not set
        self.assertFalse(self.manager.defaultAction('Feature').isValid())

        # set bad default action
        self.manager.setDefaultAction('Feature', QUuid.createUuid())
        self.assertFalse(self.manager.defaultAction('Feature').isValid())

        # set good default action
        self.manager.setDefaultAction('Feature', action1.id())
        self.assertTrue(self.manager.defaultAction('Feature').isValid())
        self.assertEqual(self.manager.defaultAction('Feature').id(), action1.id())
        self.assertNotEqual(self.manager.defaultAction('Feature').id(), action2.id())

        # if default action is removed, should be reset to -1
        self.manager.clearActions()
        self.assertFalse(self.manager.defaultAction('Feature').isValid())
    def testAddAction(self):
        """ Test adding actions """

        # should be empty to start with
        self.assertEqual(self.manager.actions(), [])

        # add an action
        action1 = QgsAction(QgsAction.GenericPython, 'Test Action', 'i=1')
        self.manager.addAction(action1)
        self.assertEqual(len(self.manager.actions()), 1)
        self.assertEqual(self.manager.actions()[0].type(), QgsAction.GenericPython)
        self.assertEqual(self.manager.actions()[0].name(), 'Test Action')
        self.assertEqual(self.manager.actions()[0].command(), 'i=1')

        # add another action
        action2 = QgsAction(QgsAction.Windows, 'Test Action2', 'i=2')
        self.manager.addAction(action2)
        self.assertEqual(len(self.manager.actions()), 2)
        self.assertEqual(self.manager.action(action2.id()).type(), QgsAction.Windows)
        self.assertEqual(self.manager.action(action2.id()).name(), 'Test Action2')
        self.assertEqual(self.manager.action(action2.id()).command(), 'i=2')

        id3 = self.manager.addAction(QgsAction.Generic, 'Test Action3', 'i=3')
        self.assertEqual(len(self.manager.actions()), 3)
        self.assertEqual(self.manager.action(id3).type(), QgsAction.Generic)
        self.assertEqual(self.manager.action(id3).name(), 'Test Action3')
        self.assertEqual(self.manager.action(id3).command(), 'i=3')
示例#3
0
    def testDefaultAction(self):
        """ test default action for layer"""

        self.manager.clearActions()
        action1 = QgsAction(QgsAction.GenericPython, "test_action", "", "i=1", False, actionScopes={"Feature"})
        self.manager.addAction(action1)
        action2 = QgsAction(QgsAction.GenericPython, "test_action2", "i=2")
        self.manager.addAction(action2)

        # initially should be not set
        self.assertFalse(self.manager.defaultAction("Feature").isValid())

        # set bad default action
        self.manager.setDefaultAction("Feature", QUuid.createUuid())
        self.assertFalse(self.manager.defaultAction("Feature").isValid())

        # set good default action
        self.manager.setDefaultAction("Feature", action1.id())
        self.assertTrue(self.manager.defaultAction("Feature").isValid())
        self.assertEquals(self.manager.defaultAction("Feature").id(), action1.id())
        self.assertNotEquals(self.manager.defaultAction("Feature").id(), action2.id())

        # if default action is removed, should be reset to -1
        self.manager.clearActions()
        self.assertFalse(self.manager.defaultAction("Feature").isValid())
    def testDefaultAction(self):
        """ test default action for layer"""

        self.manager.clearActions()
        action1 = QgsAction(QgsAction.GenericPython,
                            'test_action',
                            '',
                            'i=1',
                            False,
                            actionScopes={'Feature'})
        self.manager.addAction(action1)
        action2 = QgsAction(QgsAction.GenericPython, 'test_action2', 'i=2')
        self.manager.addAction(action2)

        # initially should be not set
        self.assertFalse(self.manager.defaultAction('Feature').isValid())

        # set bad default action
        self.manager.setDefaultAction('Feature', QUuid.createUuid())
        self.assertFalse(self.manager.defaultAction('Feature').isValid())

        # set good default action
        self.manager.setDefaultAction('Feature', action1.id())
        self.assertTrue(self.manager.defaultAction('Feature').isValid())
        self.assertEqual(
            self.manager.defaultAction('Feature').id(), action1.id())
        self.assertNotEqual(
            self.manager.defaultAction('Feature').id(), action2.id())

        # if default action is removed, should be reset to -1
        self.manager.clearActions()
        self.assertFalse(self.manager.defaultAction('Feature').isValid())
示例#5
0
def add_relaunch_action(layer: QgsVectorLayer, layer_name: str = ""):
    """ Add the relaunch action """
    actions = layer.actions()

    title = tr('Reload the query in a new file')
    reload = QgsAction(
        QgsAction.GenericPython, title,
        ACTIONS_PATH + 'Actions.run_reload(layer_name="{layer_name}")'.format(
            layer_name=layer_name), '', False, title, [Visibility.Layer.value],
        '')
    actions.addAction(reload)
示例#6
0
    def testAddAction(self):
        """ Test adding actions """

        # should be empty to start with
        self.assertEqual(self.manager.actions(), [])

        # add an action
        action1 = QgsAction(QgsAction.GenericPython, 'Test Action', 'i=1')
        self.manager.addAction(action1)
        self.assertEqual(len(self.manager.actions()), 1)
        self.assertEqual(self.manager.actions()[0].type(),
                         QgsAction.GenericPython)
        self.assertEqual(self.manager.actions()[0].name(), 'Test Action')
        self.assertEqual(self.manager.actions()[0].command(), 'i=1')

        # add another action
        action2 = QgsAction(QgsAction.Windows, 'Test Action2', 'i=2')
        self.manager.addAction(action2)
        self.assertEqual(len(self.manager.actions()), 2)
        self.assertEqual(
            self.manager.action(action2.id()).type(), QgsAction.Windows)
        self.assertEqual(
            self.manager.action(action2.id()).name(), 'Test Action2')
        self.assertEqual(self.manager.action(action2.id()).command(), 'i=2')

        id3 = self.manager.addAction(QgsAction.Generic, 'Test Action3', 'i=3')
        self.assertEqual(len(self.manager.actions()), 3)
        self.assertEqual(self.manager.action(id3).type(), QgsAction.Generic)
        self.assertEqual(self.manager.action(id3).name(), 'Test Action3')
        self.assertEqual(self.manager.action(id3).command(), 'i=3')
    def setUpClass(cls):
        cls.layer = QgsVectorLayer(
            "Point?field=fldtxt:string&field=fldint:integer&field=flddate:datetime",
            "test_layer", "memory")

        QgsProject.instance().addMapLayers([cls.layer])

        cls.action_id1 = QUuid.createUuid()
        cls.action_id2 = QUuid.createUuid()
        cls.action_id3 = QUuid.createUuid()
        cls.action1 = QgsAction(cls.action_id1, QgsAction.GenericPython,
                                'Test Action 1 Desc', 'i=1', '', False,
                                'Test Action 1 Short Title')
        cls.action2 = QgsAction(cls.action_id2, QgsAction.GenericPython,
                                'Test Action 2 Desc', 'i=2',
                                QGISAPP.appIconPath(), False,
                                'Test Action 2 Short Title')
        cls.action3 = QgsAction(cls.action_id3, QgsAction.GenericPython,
                                'Test Action 3 Desc', 'i=3', '', False)
        cls.layer.actions().addAction(cls.action1)
        cls.layer.actions().addAction(cls.action2)
        cls.layer.actions().addAction(cls.action3)
示例#8
0
    def test_post_multipart_action(self):
        """Test multipart"""

        self.body = None

        def _req_logger(self, params):
            self.body = bytes(params.content())

        QgsNetworkAccessManager.instance(
        ).requestAboutToBeCreated[QgsNetworkRequestParameters].connect(
            partial(_req_logger, self))

        temp_dir = QTemporaryDir()
        temp_path = temp_dir.path()
        temp_file = os.path.join(temp_path, 'multipart.txt')

        action = QgsAction(
            QgsAction.SubmitUrlMultipart, 'url_encoded',
            "http://fake_qgis_http_endpoint" + temp_file +
            r"?[% url_encode(map('a&+b', 'a and plus b', 'a=b', 'a equals b')) %]"
        )
        ctx = QgsExpressionContext()
        action.run(ctx)

        while not self.body:
            QgsApplication.instance().processEvents()

        self.assertEqual(
            re.sub(r'\.oOo\.[^\r]*', '.oOo.UUID', self.body.decode('utf8')),
            '\r\n'.join([
                '--boundary_.oOo.UUID',
                'Content-Disposition: form-data; name="a&+b"', '',
                'a and plus b', '--boundary_.oOo.UUID',
                'Content-Disposition: form-data; name="a=b"', '', 'a equals b',
                '--boundary_.oOo.UUID', ''
            ]))
示例#9
0
    def testAddAction(self):
        """ Test adding actions """

        # should be empty to start with
        self.assertEqual(self.manager.size(), 0)
        self.assertEqual(self.manager.listActions(), [])

        # add an action
        self.manager.addAction(QgsAction.GenericPython, 'test_action', 'i=1')
        self.assertEqual(self.manager.size(), 1)
        self.assertEqual(self.manager.listActions()[0].type(),
                         QgsAction.GenericPython)
        self.assertEqual(self.manager.listActions()[0].name(), 'test_action')
        self.assertEqual(self.manager.listActions()[0].action(), 'i=1')
        self.assertEqual(self.manager.at(0).name(), 'test_action')
        self.assertEqual(self.manager[0].name(), 'test_action')

        # add another action
        self.manager.addAction(QgsAction.Windows, 'test_action2', 'i=2')
        self.assertEqual(self.manager.size(), 2)
        self.assertEqual(self.manager.listActions()[1].type(),
                         QgsAction.Windows)
        self.assertEqual(self.manager.listActions()[1].name(), 'test_action2')
        self.assertEqual(self.manager.listActions()[1].action(), 'i=2')
        self.assertEqual(self.manager.at(1).name(), 'test_action2')
        self.assertEqual(self.manager[1].name(), 'test_action2')

        # add a predefined action
        action = QgsAction(QgsAction.Unix, 'test_action3', 'i=3', False)
        self.manager.addAction(action)
        self.assertEqual(self.manager.size(), 3)
        self.assertEqual(self.manager.listActions()[2].type(), QgsAction.Unix)
        self.assertEqual(self.manager.listActions()[2].name(), 'test_action3')
        self.assertEqual(self.manager.listActions()[2].action(), 'i=3')
        self.assertEqual(self.manager.at(2).name(), 'test_action3')
        self.assertEqual(self.manager[2].name(), 'test_action3')
示例#10
0
    def add_layer_actions(self):
        action_manager = self.layers['count'].actions()
        action_manager.clearActions()

        action = QgsAction(
            QgsAction.GenericPython, 'Exporter la configuration',
            ("from qgis.utils import plugins\n"
             "plugins['comptages'].do_export_configuration_action([% $id %])"))
        action.setActionScopes(['Feature'])
        action_manager.addAction(action)

        action = QgsAction(
            QgsAction.GenericPython, 'Importation',
            ("from qgis.utils import plugins\n"
             "plugins['comptages'].do_import_single_file_action([% $id %])"))
        action.setActionScopes(['Feature'])
        action_manager.addAction(action)

        action = QgsAction(
            QgsAction.GenericPython, 'Creer un rapport',
            ("from qgis.utils import plugins\n"
             "plugins['comptages'].do_generate_report_action([% $id %])"))
        action.setActionScopes(['Feature'])
        action_manager.addAction(action)

        action = QgsAction(
            QgsAction.GenericPython, 'Creer un plan',
            ("from qgis.utils import plugins\n"
             "plugins['comptages'].do_export_plan_action([% $id %])"))
        action.setActionScopes(['Feature'])
        action_manager.addAction(action)

        action = QgsAction(
            QgsAction.GenericPython, 'Générer les graphiques',
            ("from qgis.utils import plugins\n"
             "plugins['comptages'].do_generate_chart_action([% $id %])"))
        action.setActionScopes(['Feature'])
        action_manager.addAction(action)
示例#11
0
def add_actions(layer, keys):
    """Add actions on layer.

    :param layer: The layer.
    :type layer: QgsVectorLayer

    :param keys: The list of keys in the layer.
    :type keys: list
    """
    actions = layer.actions()

    title = tr('OpenStreetMap Browser')
    osm_browser = QgsAction(
        QgsAction.OpenUrl,
        title,
        'http://www.openstreetmap.org/browse/[% "osm_type" %]/[% "osm_id" %]',
        '',
        False,
        title,
        ACTIONS_VISIBILITY,
        ''
    )
    actions.addAction(osm_browser)

    title = 'Mapillary'
    mapillary = QgsAction(
        QgsAction.GenericPython,
        title,
        ACTIONS_PATH + 'Actions.run("mapillary","[% "mapillary" %]")',
        resources_path('icons', 'mapillary_logo.svg'),
        False,
        title,
        ACTIONS_VISIBILITY,
        ''
    )
    actions.addAction(mapillary)

    title = 'JOSM'
    josm = QgsAction(
        QgsAction.GenericPython,
        title,
        ACTIONS_PATH + 'Actions.run("josm","[% "full_id" %]")',
        resources_path('icons', 'josm_icon.svg'),
        False,
        title,
        ACTIONS_VISIBILITY,
        ''
    )
    actions.addAction(josm)

    title = tr('User default editor')
    default_editor = QgsAction(
        QgsAction.OpenUrl,
        title,
        'http://www.openstreetmap.org/edit?[% "osm_type" %]=[% "osm_id" %]',
        '',
        False,
        title,
        ACTIONS_VISIBILITY,
        ''
    )
    actions.addAction(default_editor)

    for link in ['url', 'website', 'wikipedia', 'wikidata', 'ref:UAI']:
        if link in keys:

            # Add an image to the action if available
            image = ''
            if link == 'wikipedia':
                image = resources_path('icons', 'wikipedia.png')
            elif link == 'wikidata':
                image = resources_path('icons', 'wikidata.png')
            elif link in ['url', 'website']:
                image = resources_path('icons', 'external_link.png')

            link = link.replace(":", "_")
            generic = QgsAction(
                QgsAction.GenericPython,
                link,
                (ACTIONS_PATH
                 + 'Actions.run("{link}","[% "{link}" %]")'.format(link=link)),
                image,
                False,
                link,
                ACTIONS_VISIBILITY,
                ''
            )
            actions.addAction(generic)

    if 'network' in keys and 'ref' in keys:
        sketch_line = QgsAction(
            QgsAction.GenericPython,
            tr('Sketchline'),
            (ACTIONS_PATH +
             'Actions.run_sketch_line("[% "network" %]","[% "ref" %]")'),
            '',
            False,
            '',
            ACTIONS_VISIBILITY,
            ''
        )
        actions.addAction(sketch_line)
    def initGui(self):
        """Create the menu entries and toolbar icons inside the QGIS GUI."""

        self.dlg = RuimtelijkePlannenDialog()
        self.settings_dlg = RuimtelijkePlannenSettingsDialog()

        self.add_action(dialog=None,
                        icon_path=':/plugins/RuimtelijkePlannen/help.png',
                        text=self.tr(u'Help'),
                        callback=self.open_help,
                        parent=self.iface.mainWindow(),
                        add_to_toolbar=False)

        self.add_action(dialog=None,
                        icon_path=':/plugins/RuimtelijkePlannen/settings.png',
                        text=self.tr(u'Settings'),
                        callback=self.run_settings,
                        parent=self.iface.mainWindow(),
                        add_to_toolbar=False)

        # add a button to click in map and find bestemmingsplannen
        self.action = self.add_action(
            dialog=None,
            icon_path=':/plugins/RuimtelijkePlannen/icon.png',
            text=self.tr(u'Click map query RuimtelijkePlannen'),
            callback=self.activate_tool,
            add_to_menu=True,
            status_tip=self.tr(u'Click map query RuimtelijkePlannen'),
            parent=self.iface.mainWindow())
        self.action.setCheckable(True)
        # add it to the same group as the pan/zoom tools
        self.iface.actionPan().actionGroup().addAction(self.action)
        self.xytool = GetPointTool(self.mapcanvas, self.getRPplannenByPoint)

        self.toolbarSearch = QLineEdit()
        self.toolbarSearch.setMaximumWidth(200)
        self.toolbarSearch.setAlignment(QtCore.Qt.AlignLeft)
        self.toolbarSearch.setPlaceholderText("NL.IMRO.")
        self.toolbar.addWidget(self.toolbarSearch)
        self.toolbarSearch.returnPressed.connect(self.addRPplanFromToolbar)

        self.proxyModel = QSortFilterProxyModel()
        self.sourceModel = QStandardItemModel()
        self.proxyModel.setSourceModel(self.sourceModel)

        self.dlg.treeView_results.setModel(self.proxyModel)
        self.dlg.treeView_results.setEditTriggers(
            QAbstractItemView.NoEditTriggers)
        self.dlg.treeView_results.setSortingEnabled(True)
        self.dlg.treeView_results.doubleClicked.connect(self.loadRPplan)

        # have an info icon at hand for keuzehulp
        self.infoIcon = QIcon(':/plugins/RuimtelijkePlannen/info.png')

        # have the right crs at hand
        self.rp_crs = QgsCoordinateReferenceSystem(28992)

        ## urls to RuimtelijkePlannen
        ## this one is the traditional one
        # self.rp_search_url = "https://www.ruimtelijkeplannen.nl/web-roo/rest/search"
        # self.rp_search_id_resource = "/plan/id/"
        # self.rp_search_xy_resource = "/plannen/xy/"
        ## this one is new and has more metadata with the "keuzehulp"!
        self.rp_search_url = "https://www.ruimtelijkeplannen.nl/plannenservice"
        self.rp_search_id_resource = "/plannen/identificatie/"
        self.rp_search_xy_resource = "/plannen/xy/"

        self.rp_wfs_url = "https://afnemers.ruimtelijkeplannen.nl/afnemers2012/services"

        # the following lists of plantypes comes from:
        # https://www.ruimtelijkeplannen.nl/viewer/planoverzicht
        self.rp_supported_planTypes = [\
            'aanwijzingsbesluit',
            'beheersverordening',
            'bestemmingsplan',
            'exploitatieplan',
            'gemeentelijk plan; bestemmingsplan artikel 10',
            'gemeentelijk plan; uitwerkingsplan artikel 11',
            'gemeentelijk plan; voorbereidingsbesluit',
            'gemeentelijk plan; wijzigingsplan artikel 11',
            'gemeentelijke visie; overig',
            'gerechtelijke uitspraak',
            'inpassingsplan',
            'omgevingsvergunning',
            'projectbesluit',
            'reactieve aanwijzing',
            'tijdelijke ontheffing buitenplans',
            'uitwerkingsplan',
            'voorbereidingsbesluit',
            'wijzigingsplan'
            ]
        self.rp_not_supported_plantypes = [\
            # these are the plan types which can have multiple maps

            'amvb',
            'provinciale verordening',
            'regeling',
            'structuurvisie'
            ]

        # layer action on RuimtelijkePlannen layers to show links to text
        self.rp_layer_action = QgsAction(QgsAction.GenericPython,
                                         'Open text link(s) in browser ',
                                         layer_action, "", False, "",
                                         {'Feature', 'Canvas'})