def importClicked(self):
        if self.repo is None:
            connector = PyQtConnectorDecorator()
            connector.checkIsAlive()
            self.repo = Repository(self.repos[self.repoCombo.currentText()], connector)
        if self.layer is None:
            text = self.layerCombo.currentText()
            self.layer = resolveLayer(text)

        source = self.layer.source()
        hasIdField = self.layer.dataProvider().fieldNameIndex("geogigid") != -1

        if not hasIdField:
            autoAddId = config.getConfigValue(config.GENERAL, config.AUTO_ADD_ID)
            if not autoAddId:
                dlg = AddGeogigIdDialog(self)
                ok, check = dlg.exec_()
                if ok == QtGui.QMessageBox.No:
                    self.close()
                    return
                if check:
                    config.setConfigValue(config.GENERAL, config.AUTO_ADD_ID, True)

            QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
            addIdField(self.layer)
            QtGui.QApplication.restoreOverrideCursor()
            hasIdField = self.layer.dataProvider().fieldNameIndex("geogigid") != -1
            if not hasIdField:
                QtGui.QMessageBox.warning(self, "Error",
                            "Could not add 'geogigid' field to layer.\n"
                            "Possible causes for this are:\n"
                            "- No permission to edit the layer.\n",
                            QtGui.QMessageBox.Ok, QtGui.QMessageBox.Ok)
                return

        # determine encoding
        # first look in .cpg file
        cpgPath = source.replace('.shp', '.cpg')
        if os.path.exists(cpgPath):
            with open(cpgPath) as f:
                charset = f.readline().strip('\r\n')
        else:
            # try to get encoding from provider
            charset = self.layer.dataProvider().encoding()
            if charset.lower() == 'system':
                # get encoding from system
                charset = locale.getpreferredencoding()

        self.repo.importshp(source, False, self.layer.name(), "geogigid", True, charset)
        message = self.messageBox.toPlainText()
        self.repo.add()
        try:
            self.repo.commit(message)
        except UnconfiguredUserException, e:
            configureUser()
            self.repo.commit(message)
def removeLayer(layer):
    ret = QtGui.QMessageBox.warning(config.iface.mainWindow(), "Delete layer",
                        "Are you sure you want to delete this layer?",
                        QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
                        QtGui.QMessageBox.Yes);
    if ret == QtGui.QMessageBox.No:
        return
    repo, layername = _repoForLayer(layer)
    repo.removetrees([layername])
    try:
        repo.addandcommit("Removed layer '%s'" % layername)
    except UnconfiguredUserException, e:
        configureUser()
        repo.addandcommit("Removed layer '%s'" % layername)
示例#3
0
def removeLayer(layer):
    ret = QtGui.QMessageBox.warning(
        config.iface.mainWindow(), "Delete layer",
        "Are you sure you want to delete this layer?",
        QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.Yes)
    if ret == QtGui.QMessageBox.No:
        return
    repo, layername = _repoForLayer(layer)
    repo.removetrees([layername])
    try:
        repo.addandcommit("Removed layer '%s'" % layername)
    except UnconfiguredUserException, e:
        configureUser()
        repo.addandcommit("Removed layer '%s'" % layername)
    def importClicked(self):
        if self.repo is None:
            connector = PyQtConnectorDecorator()
            connector.checkIsAlive()
            self.repo = Repository(self.repos[self.repoCombo.currentText()],
                                   connector)
        if self.layer is None:
            text = self.layerCombo.currentText()
            self.layer = resolveLayer(text)

        source = self.layer.source()
        hasIdField = self.layer.dataProvider().fieldNameIndex("geogigid") != -1

        if not hasIdField:
            autoAddId = config.getConfigValue(config.GENERAL,
                                              config.AUTO_ADD_ID)
            if not autoAddId:
                dlg = AddGeogigIdDialog(self)
                ok, check = dlg.exec_()
                if ok == QtGui.QMessageBox.No:
                    self.close()
                    return
                if check:
                    config.setConfigValue(config.GENERAL, config.AUTO_ADD_ID,
                                          True)

            QtGui.QApplication.setOverrideCursor(
                QtGui.QCursor(QtCore.Qt.WaitCursor))
            addIdField(self.layer)
            QtGui.QApplication.restoreOverrideCursor()
            hasIdField = self.layer.dataProvider().fieldNameIndex(
                "geogigid") != -1
            if not hasIdField:
                QtGui.QMessageBox.warning(
                    self, "Error", "Could not add 'geogigid' field to layer.\n"
                    "Possible causes for this are:\n"
                    "- No permission to edit the layer.\n",
                    QtGui.QMessageBox.Ok, QtGui.QMessageBox.Ok)
                return

        # determine encoding
        # first look in .cpg file
        cpgPath = source.replace('.shp', '.cpg')
        if os.path.exists(cpgPath):
            with open(cpgPath) as f:
                charset = f.readline().strip('\r\n')
        else:
            # try to get encoding from provider
            charset = self.layer.dataProvider().encoding()
            if charset.lower() == 'system':
                # get encoding from system
                charset = locale.getpreferredencoding()

        self.repo.importshp(source, False, self.layer.name(), "geogigid", True,
                            charset)
        message = self.messageBox.toPlainText()
        self.repo.add()
        try:
            self.repo.commit(message)
        except UnconfiguredUserException, e:
            configureUser()
            self.repo.commit(message)