Exemple #1
0
    def initGui(self):
        """ 
        Set up UI within QGIS 
        """

        # set srs
        self._displayCrs = QgsCoordinateReferenceSystem()
        self._displayCrs.createFromOgcWmsCrs('EPSG:4167')
        self.iface.mapCanvas().mapSettings().setDestinationCrs(
            self._displayCrs)

        # init layerManager
        self._layerManager = LayerManager(self.iface, self)
        self._layerManager.registerFunctions()
        # init Highlighter
        self.highlighter = FeatureHighlighter(self.iface, self._layerManager,
                                              self)

        # Build an action list from QGIS navigation toolbar
        actionList = self.iface.mapNavToolToolBar().actions()
        self.actions = self.iface.mapNavToolToolBar().actions()

        # Main address editing window
        self._loadaction = QAction(
            QIcon(':/plugins/QGIS-AIMS-Plugin/resources/loadaddress.png'),
            'QGIS-AIMS-Plugin', self.iface.mainWindow())
        self._loadaction.setWhatsThis('Open the QGIS-AIMS-Plugin')
        self._loadaction.setStatusTip('Open the QGIS-AIMS-Plugin')
        self._loadaction.triggered.connect(self.loadQueues)
        self._loadaction.triggered.connect(self.loadLayers)
        self._loadaction.triggered.connect(self.enableAddressLayer)
        self._loadaction.triggered.connect(self.startDM)

        # Create new address tool
        self._createnewaddressaction = QAction(
            QIcon(':/plugins/QGIS-AIMS-Plugin/resources/newaddresspoint.png'),
            'Create AIMS Feature', self.iface.mainWindow())
        self._createnewaddressaction.setWhatsThis('Create AIMS Feature')
        self._createnewaddressaction.setStatusTip('Create AIMS Feature')
        self._createnewaddressaction.setEnabled(False)
        self._createnewaddressaction.setCheckable(True)
        self._createnewaddressaction.triggered.connect(
            self.startNewAddressTool)
        self._createnewaddresstool = CreateNewAddressTool(
            self.iface, self._layerManager, self)
        self._createnewaddresstool.setAction(self._createnewaddressaction)
        self.actions.append(self._createnewaddressaction)

        # Delete address point
        self._deladdressaction = QAction(
            QIcon(':/plugins/QGIS-AIMS-Plugin/resources/deleteaddress.png'),
            'Delete AIMS Feature', self.iface.mainWindow())
        self._deladdressaction.setWhatsThis('Delete AIMS Feature')
        self._deladdressaction.setStatusTip('Delete AIMS Feature')
        self._deladdressaction.setEnabled(False)
        self._deladdressaction.setCheckable(True)
        self._deladdressaction.triggered.connect(self.startDelAddressTool)
        self._deladdtool = DelAddressTool(self.iface, self._layerManager, self)
        self._deladdtool.setAction(self._deladdressaction)
        self.actions.append(self._deladdressaction)

        # Move address
        self._moveaddressaction = QAction(
            QIcon(':/plugins/QGIS-AIMS-Plugin/resources/moveaddress.png'),
            'Move AIMS Feature(s)', self.iface.mainWindow())
        self._moveaddressaction.setWhatsThis('Move AIMS Feature(s)')
        self._moveaddressaction.setStatusTip('Move AIMS Feature(s)')
        self._moveaddressaction.setEnabled(False)
        self._moveaddressaction.setCheckable(True)
        self._moveaddressaction.triggered.connect(self.startMoveAddressTool)
        self._moveaddtool = MoveAddressTool(self.iface, self._layerManager,
                                            self)
        self._moveaddtool.setAction(self._moveaddressaction)
        self.actions.append(self._moveaddressaction)

        # Update address
        self._updateaddressaction = QAction(
            QIcon(':/plugins/QGIS-AIMS-Plugin/resources/updateaddress.png'),
            'Update AIMS Feature', self.iface.mainWindow())
        self._updateaddressaction.setWhatsThis('Update AIMS Feature')
        self._updateaddressaction.setStatusTip('Update AIMS Feature')
        self._updateaddressaction.setEnabled(False)
        self._updateaddressaction.setCheckable(True)
        self._updateaddressaction.triggered.connect(
            self.startUpdateAddressTool)
        self._updateaddtool = UpdateAddressTool(self.iface, self._layerManager,
                                                self)
        self._updateaddtool.setAction(self._updateaddressaction)
        self.actions.append(self._updateaddressaction)

        # RCL tool -- Not a QAction as triggered from many palaces but not the toolbar
        self._rcltool = GetRcl(self.iface, self._layerManager, self)

        # UpdateReview Position tool -- Not a QAction as triggered initiated from review queue form
        self._updateReviewPos = UpdateReviewPosition(self.iface,
                                                     self._layerManager, self)

        # Address lineage
        """
        self._lineageaction = QAction(QIcon(':/plugins/QGIS-AIMS-Plugin/resources/lineage.png'), 
            'Build Lineage Relationships Between Features', self.iface.mainWindow())
        self._lineageaction.setWhatsThis('Build Lineage Relationships Between Features')
        self._lineageaction.setStatusTip('Build Lineage Relationships Between Features')
        self._lineageaction.setEnabled(False)
        self._lineageaction.setCheckable(True)
        self._lineagetool = LineageTool( self.iface, self._layerManager, self)
        self._lineageaction.triggered.connect(self._lineagetool.setEnabled)
        self.actions.append(self._lineageaction)
        """

        # Address highlighter
        self._highlightaction = QAction(
            QIcon(":/plugins/QGIS-AIMS-Plugin/resources/addresshighlight.png"),
            "Electoral address highlighter", self.iface.mainWindow())
        self._highlightaction.setWhatsThis(
            "Turn the electoral address highlighter on or off")
        self._highlightaction.setStatusTip(
            "Turn the electoral address highlighter on or off")
        self._highlightaction.setText('Highlightaction')
        self._highlightaction.setEnabled(False)
        self._highlightaction.setCheckable(True)
        self._highlightaction.toggled.connect(self.highlighter.setEnabled)

        # Add to own toolbar
        self._toolbar = self.iface.addToolBar('QGIS-AIMS-Plugin')
        self._toolbar.addAction(self._createnewaddressaction)
        self._toolbar.addAction(self._deladdressaction)
        self._toolbar.addAction(self._updateaddressaction)
        self._toolbar.addAction(self._moveaddressaction)
        #self._toolbar.addAction(self._lineageaction)
        self._toolbar.addAction(self._highlightaction)

        # Add actions to menu
        self.iface.addToolBarIcon(self._loadaction)
        self.iface.addPluginToMenu('&QGIS-AIMS-Plugin', self._loadaction)
        self.iface.addPluginToMenu('&QGIS-AIMS-Plugin',
                                   self._createnewaddressaction)
        self.iface.addPluginToMenu('&QGIS-AIMS-Plugin', self._deladdressaction)
        self.iface.addPluginToMenu('&QGIS-AIMS-Plugin',
                                   self._updateaddressaction)
        self.iface.addPluginToMenu('&QGIS-AIMS-Plugin',
                                   self._moveaddressaction)
        self.iface.addPluginToMenu('&QGIS-AIMS-Plugin', self._highlightaction)

        # capture maptool selection changes
        QObject.connect(self.iface.mapCanvas(),
                        SIGNAL("mapToolSet(QgsMapTool *)"),
                        self.mapToolChanged)

        # Add actions from QGIS attributes toolbar (handling QWidgetActions)
        tmpActionList = self.iface.attributesToolBar().actions()
        for action in tmpActionList:
            if isinstance(action, QWidgetAction):
                actionList.extend(action.defaultWidget().actions())
            else:
                actionList.append(action)
        # ... could add other toolbars' action lists...

        # Build a group with actions from actionList
        group = QActionGroup(self.iface.mainWindow())
        group.setExclusive(True)
        for qgisAction in actionList:
            group.addAction(qgisAction)

        # Add our own actions
        for action in self.actions:
            if action.text() == 'Highlightaction': continue
            group.addAction(action)