Ejemplo n.º 1
0
    def __init__(self, iface):
        self.iface = iface
        self.settings = MySettings()
        self.mainDialog = MainDialog()

        # Initialise the translation environment.
        userPluginPath = QFileInfo(QgsApplication.qgisUserDbFilePath()).path(
        ) + "/python/plugins/qwat"
        systemPluginPath = QgsApplication.prefixPath(
        ) + "/share/qgis/python/plugins/qwat"
        locale = QSettings().value("locale/userLocale")
        myLocale = locale[0:2]
        if QFileInfo(userPluginPath).exists():
            pluginPath = userPluginPath + "/i18n/qwat_" + myLocale + ".qm"
        elif QFileInfo(systemPluginPath).exists():
            pluginPath = systemPluginPath + "/i18n/qwat_" + myLocale + ".qm"
        self.localePath = pluginPath
        if QFileInfo(self.localePath).exists():
            self.translator = QTranslator()
            self.translator.load(self.localePath)
            QCoreApplication.installTranslator(self.translator)
Ejemplo n.º 2
0
 def __init__(self, iface):
     self.iface = iface
     self.settings = MySettings()
     self.docks = {}
Ejemplo n.º 3
0
class itemBrowser():
    def __init__(self, iface):
        self.iface = iface
        self.settings = MySettings()
        self.docks = {}

    def initGui(self):
        # browse action
        self.browserAction = QAction(
            QIcon(":/plugins/itembrowser/icons/itembrowser.svg"),
            "Browse selected items of current layer", self.iface.mainWindow())
        self.browserAction.setEnabled(False)
        self.browserAction.triggered.connect(lambda (x): self.openBrowserDock(
        ))  # prevent passing "False" to the method
        self.iface.addToolBarIcon(self.browserAction)
        self.iface.addPluginToMenu("&Item Browser", self.browserAction)
        # settings
        self.uisettingsAction = QAction(
            QIcon(":/plugins/itembrowser/icons/settings.svg"), "settings",
            self.iface.mainWindow())
        self.uisettingsAction.triggered.connect(self.showSettings)
        self.iface.addPluginToMenu("&Item Browser", self.uisettingsAction)
        # help
        self.helpAction = QAction(
            QIcon(":/plugins/itembrowser/icons/help.svg"), "Help",
            self.iface.mainWindow())
        self.helpAction.triggered.connect(lambda: QDesktopServices().openUrl(
            QUrl("http://3nids.github.io/itembrowser")))
        self.iface.addPluginToMenu("&Item Browser", self.helpAction)

        self.iface.currentLayerChanged.connect(self.currentLayerChanged)
        self.iface.mapCanvas().selectionChanged.connect(
            self.currentLayerChanged)
        QgsProject.instance().readProject.connect(self.reloadSession)

        self.currentLayerChanged(self.iface.activeLayer())

    def unload(self):
        self.iface.removePluginMenu("&Item Browser", self.browserAction)
        self.iface.removePluginMenu("&Item Browser", self.uisettingsAction)
        self.iface.removePluginMenu("&Item Browser", self.helpAction)
        self.iface.removeToolBarIcon(self.browserAction)

    def currentLayerChanged(self, layer):
        enable = (layer is not None and layer.type() == QgsMapLayer.VectorLayer
                  and layer.hasGeometryType()
                  and len(layer.selectedFeaturesIds()) > 1)
        self.browserAction.setEnabled(enable)

    def openBrowserDock(self, layer=None, currentFeature=0):
        if layer is None:
            layer = self.iface.legendInterface().currentLayer()
        if layer is None:
            return
        if layer.id() in self.docks:
            #print "layer already docked"
            return
        dock = ItemBrowserDock(self.iface, layer, currentFeature)
        dock.dockRemoved.connect(self.dockRemoved)
        if self.settings.value("dockArea") == 1:
            self.iface.addDockWidget(Qt.RightDockWidgetArea, dock)
        else:
            self.iface.addDockWidget(Qt.LeftDockWidgetArea, dock)
        self.docks[layer.id()] = dock

    def dockRemoved(self, layerid):
        del self.docks[layerid]

    def reloadSession(self):
        if not self.settings.value("saveSelectionInProject"):
            return
        for layer in self.iface.legendInterface().layers():
            exec("selection = %s" %
                 layer.customProperty("itemBrowserSelection", "[]"))
            if len(selection) > 0:
                currentFeature = long(
                    layer.customProperty("itemBrowserCurrentItem", 0))
                layer.setSelectedFeatures(selection)
                if len(layer.selectedFeaturesIds()) < 1:
                    return
                if layer.id() in self.docks:
                    self.docks[layer.id()].setCurrentItem(currentFeature)
                else:
                    self.openBrowserDock(layer, currentFeature)

    def showSettings(self):
        MySettingsDialog().exec_()
Ejemplo n.º 4
0
 def __init__(self, iface):
     self.iface = iface
     self.settings = MySettings()
     self.docks = {}
Ejemplo n.º 5
0
class teamqgis():
    def __init__(self, iface):
        self.iface = iface
        self.settings = MySettings()
        self.docks = {}

    def initGui(self):
        # browse action
        self.browserAction = QAction(QIcon(":/plugins/teamqgis/icons/team.jpg"),
                                     "Browse selected items of current layer", self.iface.mainWindow())
        self.browserAction.setEnabled(False)
        self.browserAction.triggered.connect(lambda(x): self.openBrowserDock())  # prevent passing "False" to the method
        self.iface.addToolBarIcon(self.browserAction)
        self.iface.addPluginToMenu("&teamqgis", self.browserAction)
        # settings
        self.uisettingsAction = QAction(QIcon(":/plugins/teamqgis/icons/settings.svg"), "settings",
                                        self.iface.mainWindow())
        self.uisettingsAction.triggered.connect(self.showSettings)
        self.iface.addPluginToMenu("&teamqgis", self.uisettingsAction)     
        # help
        self.helpAction = QAction(QIcon(":/plugins/teamqgis/icons/help.svg"), "Help", self.iface.mainWindow())
        self.helpAction.triggered.connect(lambda: QDesktopServices().openUrl(QUrl("http://www.azvoleff.com/teamqgis")))
        self.iface.addPluginToMenu("&teamqgis", self.helpAction)

        self.iface.currentLayerChanged.connect(self.currentLayerChanged)
        self.iface.mapCanvas().selectionChanged.connect(self.currentLayerChanged)
        QgsProject.instance().readProject.connect(self.reloadSession)

        self.currentLayerChanged(self.iface.legendInterface().currentLayer())
              
    def unload(self):
        self.iface.removePluginMenu("&teamqgis", self.browserAction)
        self.iface.removePluginMenu("&teamqgis", self.uisettingsAction)
        self.iface.removePluginMenu("&teamqgis", self.helpAction)
        self.iface.removeToolBarIcon(self.browserAction)
        
    def currentLayerChanged(self, layer):
        enable = (layer is not None
                  and layer.type() == QgsMapLayer.VectorLayer
                  and layer.hasGeometryType()
                  and len(layer.selectedFeaturesIds()) >= 1)
        self.browserAction.setEnabled(enable)

    def openBrowserDock(self, layer=None, currentFeature=0):
        if layer is None:
            layer = self.iface.legendInterface().currentLayer()
        if layer is None:
            return
        if layer.id() in self.docks:
            #print "layer already docked"
            return
        dock = teamqgisDock(self.iface, layer, currentFeature)
        dock.dockRemoved.connect(self.dockRemoved)
        if self.settings.value("dockArea") == 1:
            self.iface.addDockWidget(Qt.RightDockWidgetArea, dock)
        else:
            self.iface.addDockWidget(Qt.LeftDockWidgetArea, dock)
        self.docks[layer.id()] = dock

    def dockRemoved(self, layerid):
        del self.docks[layerid]

    def reloadSession(self):
        if not self.settings.value("saveSelectionInProject"):
            return
        for layer in self.iface.legendInterface().layers():
            exec("selection = %s" % layer.customProperty("teamqgisSelection", "[]"))
            if len(selection) > 0:
                currentFeature = long(layer.customProperty("teamqgisCurrentItem", 0))
                if layer.id() in self.docks:
                    self.docks[layer.id()].listCombo.setCurrentIndex(currentFeature)
                else:
                    layer.setSelectedFeatures(selection)
                    self.openBrowserDock(layer, currentFeature)

    def showSettings(self):
        MySettingsDialog().exec_()