Пример #1
0
def changeVersion(layer):
    if hasLocalChanges(layer):
        QMessageBox.warning(
            config.iface.mainWindow(), 'Cannot change version',
            "There are local changes that would be overwritten.\n"
            "Revert them before changing version.", QMessageBox.Ok)
    else:
        tracking = getTrackingInfo(layer)
        repo = Repository(tracking.repoUrl)
        dlg = HistoryViewerDialog(repo, tracking.layername)
        dlg.exec_()
        if dlg.ref is not None:
            layers = repo.trees(dlg.ref)
            if tracking.layername not in layers:
                QMessageBox.warning(
                    config.iface.mainWindow(), 'Cannot change version',
                    "The selected version does not contain the specified layer.",
                    QMessageBox.Ok)
            else:
                repo.checkoutlayer(tracking.geopkg, tracking.layername, None,
                                   dlg.ref)
                config.iface.messageBar().pushMessage(
                    "GeoGig",
                    "Layer has been updated to version %s" % dlg.ref,
                    level=QgsMessageBar.INFO,
                    duration=5)
                layer.reload()
                layer.triggerRepaint()
                repoWatcher.layerUpdated.emit(layer)
                repoWatcher.repoChanged.emit(repo)
def changeVersion(layer):
    if hasLocalChanges(layer):
        QMessageBox.warning(config.iface.mainWindow(), 'Cannot change commit',
                "The layer has local changes that would be overwritten. "
                "Either sync layer with branch or revert local changes "
                "before changing commit.",
                QMessageBox.Ok)
    else:
        tracking = getTrackingInfo(layer)
        repo = Repository(tracking.repoUrl)
        dlg = HistoryViewerDialog(repo, tracking.layername)
        dlg.exec_()
        if dlg.ref is not None:
            layers = repo.trees(dlg.ref)
            if tracking.layername not in layers:
                QMessageBox.warning(config.iface.mainWindow(), 'Cannot change commit',
                "The selected commit does not contain the specified layer.",
                QMessageBox.Ok)
            else:
                repo.checkoutlayer(tracking.geopkg, tracking.layername, None, dlg.ref)
                config.iface.messageBar().pushMessage("GeoGig", "Layer has been updated to commit %s" % dlg.ref,
                                                       level=QgsMessageBar.INFO,
                                                       duration=5)
                layer.reload()
                layer.triggerRepaint()
                repoWatcher.layerUpdated.emit(layer)
                repoWatcher.repoChanged.emit(repo)
def revertChange(layer):
    if hasLocalChanges(layer):
        QMessageBox.warning(config.iface.mainWindow(), 'Cannot revert commit',
                "The layer has local changes.\n"
                "Revert local changes before reverting a previous commit.",
                QMessageBox.Ok)
        return
    tracking = getTrackingInfo(layer)
    repo = Repository(tracking.repoUrl)
    filename, layername = namesFromLayer(layer)
    from geogig.gui.dialogs.historyviewer import HistoryViewerDialog
    dlg = HistoryViewerDialog(repo, layername)
    dlg.exec_()
    if dlg.ref is not None:
        #TODO check that selected commit is in history line

        commit = Commit.fromref(repo, dlg.ref)
        # check if we are reverting commit which adds layer to the repo
        if commit.addsLayer():
            QMessageBox.warning(config.iface.mainWindow(), 'Cannot revert commit',
                    "Commits which add layer to the repository can not "
                    "be reverted. Use GeoGig Navigator to remove layer "
                    "from branch.")
            return

        applyLayerChanges(repo, layer, commit.commitid, commit.parent.commitid, False)
        layer.reload()
        layer.triggerRepaint()
        config.iface.messageBar().pushMessage("GeoGig", "Commit changes have been reverted in local layer",
                                                      level=QgsMessageBar.INFO,
                                                      duration=5)
        commitdialog.suggestedMessage = "Reverted changes from commit %s [%s] " % (commit.commitid, commit.message)
 def changeVersion(self, repo, layer, commit):
     if hasLocalChanges(layer):
         QMessageBox.warning(config.iface.mainWindow(), 'Cannot switch to this commit',
             "There are local changes that would be overwritten.\n"
             "Revert them before retrying this operation.",
             QMessageBox.Ok)
     else:
         tracking = getTrackingInfo(layer)
         repo.checkoutlayer(tracking.geopkg, tracking.layername, None, commit)
         config.iface.messageBar().pushMessage("GeoGig", "Layer has been updated to commit %s" % commit,
                                                level=QgsMessageBar.INFO,
                                                duration=5)
         layer.reload()
         layer.triggerRepaint()
         repoWatcher.layerUpdated.emit(layer)
def revertLocalChanges(layer):
    if hasLocalChanges(layer):
        tracking = getTrackingInfo(layer)
        repo = Repository(tracking.repoUrl)
        commitid = getCommitId(layer)
        repo.checkoutlayer(tracking.geopkg, tracking.layername, None, commitid)
        config.iface.messageBar().pushMessage("GeoGig", "Local changes have been discarded",
                                                      level=QgsMessageBar.INFO,
                                                      duration=5)
        layer.reload()
        layer.triggerRepaint()
    else:
        config.iface.messageBar().pushMessage("GeoGig", "No local changes were found",
                                                      level=QgsMessageBar.INFO,
                                                      duration=5)
Пример #6
0
def revertLocalChanges(layer):
    if hasLocalChanges(layer):
        tracking = getTrackingInfo(layer)
        repo = Repository(tracking.repoUrl)
        commitid = getCommitId(layer)
        repo.checkoutlayer(tracking.geopkg, tracking.layername, None, commitid)
        config.iface.messageBar().pushMessage(
            "GeoGig",
            "Local changes have been discarded",
            level=QgsMessageBar.INFO,
            duration=5)
        layer.reload()
        layer.triggerRepaint()
    else:
        config.iface.messageBar().pushMessage("GeoGig",
                                              "No local changes were found",
                                              level=QgsMessageBar.INFO,
                                              duration=5)
Пример #7
0
 def changeVersion(self, repo, layer, commit):
     if hasLocalChanges(layer):
         QMessageBox.warning(
             config.iface.mainWindow(), 'Cannot switch to this commit',
             "There are local changes that would be overwritten.\n"
             "Revert them before retrying this operation.", QMessageBox.Ok)
     else:
         tracking = getTrackingInfo(layer)
         repo.checkoutlayer(tracking.geopkg, tracking.layername, None,
                            commit)
         config.iface.messageBar().pushMessage(
             "GeoGig",
             "Layer has been updated to commit %s" % commit,
             level=QgsMessageBar.INFO,
             duration=5)
         layer.reload()
         layer.triggerRepaint()
         repoWatcher.layerUpdated.emit(layer)
def revertChange(layer):
    if hasLocalChanges(layer):
        QMessageBox.warning(
            config.iface.mainWindow(), 'Cannot revert commit',
            "The layer has local changes.\n"
            "Revert local changes before reverting a previous commit.",
            QMessageBox.Ok)
        return
    tracking = getTrackingInfo(layer)
    repo = Repository(tracking.repoUrl)
    filename, layername = namesFromLayer(layer)
    from geogig.gui.dialogs.historyviewer import HistoryViewerDialog
    dlg = HistoryViewerDialog(repo, layername)
    dlg.exec_()
    if dlg.ref is not None:
        #TODO check that selected commit is in history line

        commit = Commit.fromref(repo, dlg.ref)
        # check if we are reverting commit which adds layer to the repo
        if commit.addsLayer():
            QMessageBox.warning(
                config.iface.mainWindow(), 'Cannot revert commit',
                "Commits which add layer to the repository can not "
                "be reverted. Use GeoGig Navigator to remove layer "
                "from branch.")
            return

        applyLayerChanges(repo, layer, commit.commitid, commit.parent.commitid,
                          False)
        layer.reload()
        layer.triggerRepaint()
        config.iface.messageBar().pushMessage(
            "GeoGig",
            "Commit changes have been reverted in local layer",
            level=QgsMessageBar.INFO,
            duration=5)
        commitdialog.suggestedMessage = "Reverted changes from commit %s [%s] " % (
            commit.commitid, commit.message)
Пример #9
0
def checkoutLayer(repo, layername, bbox, ref=None):
    ref = ref or repo.HEAD
    newCommitId = repo.revparse(ref)
    trackedlayer = getTrackingInfoForGeogigLayer(repo.url, layername)
    if trackedlayer is not None:
        if not os.path.exists(trackedlayer.geopkg):
            removeTrackedLayer(trackedlayer.source)
            trackedlayer = None
            filename = layerGeopackageFilename(layername, repo.title,
                                               repo.group)
            source = "%s|layername=%s" % (filename, layername)
        else:
            source = trackedlayer.source
    else:
        filename = layerGeopackageFilename(layername, repo.title, repo.group)
        source = "%s|layername=%s" % (filename, layername)

    if trackedlayer is None:
        repo.checkoutlayer(filename, layername, bbox, ref or repo.HEAD)
        addTrackedLayer(source, repo.url)
        try:
            layer = resolveLayerFromSource(source)
            iface.messageBar().pushMessage(
                "GeoGig",
                "Layer was already included in the current QGIS project",
                level=QgsMessageBar.INFO,
                duration=5)
        except WrongLayerSourceException:
            layer = loadLayerNoCrsDialog(source, layername, "ogr")
            QgsMapLayerRegistry.instance().addMapLayers([layer])
            iface.messageBar().pushMessage("GeoGig",
                                           "Layer correctly added to project",
                                           level=QgsMessageBar.INFO,
                                           duration=5)
    elif ref is not None:
        currentCommitId = getCommitId(source)
        try:
            layer = resolveLayerFromSource(source)
            wasLoaded = True
        except WrongLayerSourceException:
            layer = loadLayerNoCrsDialog(source, layername, "ogr")
            wasLoaded = False

        if newCommitId != currentCommitId:
            if hasLocalChanges(layer):
                raise HasLocalChangesError()
            filename, layername = namesFromLayer(layer)
            repo.checkoutlayer(filename, layername, bbox, ref)
            layer.reload()
            if not wasLoaded:
                QgsMapLayerRegistry.instance().addMapLayers([layer])
                iface.messageBar().pushMessage(
                    "GeoGig",
                    "Layer correctly added to project",
                    level=QgsMessageBar.INFO,
                    duration=5)
            else:
                iface.messageBar().pushMessage(
                    "GeoGig",
                    "Layer correctly updated to specified version",
                    level=QgsMessageBar.INFO,
                    duration=5)
                layer.triggerRepaint()
        else:
            if wasLoaded:
                iface.messageBar().pushMessage(
                    "GeoGig",
                    "Layer was already included in the current QGIS project",
                    level=QgsMessageBar.INFO,
                    duration=5)
            else:
                QgsMapLayerRegistry.instance().addMapLayers([layer])
                iface.messageBar().pushMessage(
                    "GeoGig",
                    "Layer correctly added to the current QGIS project",
                    level=QgsMessageBar.INFO,
                    duration=5)

    repoWatcher.repoChanged.emit(repo)
    return layer
def checkEdited(layername):
    layer = layerFromName(layername)
    if layer:
        return len(hasLocalChanges(layer)) > 0
    else:
        return False
Пример #11
0
def checkEdited():
    layer = iface.activeLayer()
    if layer:
        return hasLocalChanges(layer)
    else:
        return False