def updateTrackedLayers(repo): head = repo.revparse(geogig.HEAD) repoLayers = [tree.path for tree in repo.trees] repoLayersInProject = False notLoaded = [] toUnload = [] for trackedlayer in tracked: if trackedlayer.repoFolder == repo.url: if trackedlayer.layername in repoLayers: if (trackedlayer.ref != head or not os.path.exists(trackedlayer.source)): repo.exportshp(geogig.HEAD, trackedlayer.layername, trackedlayer.source, 'utf-8') try: layer = resolveLayerFromSource(trackedlayer.source) layer.dataProvider().forceReload() layer.setCacheImage(None) layer.triggerRepaint() repoLayersInProject = True except WrongLayerSourceException: notLoaded.append(trackedlayer) trackedlayer.ref = head else: try: layer = resolveLayerFromSource(trackedlayer.source) repoLayersInProject = True except WrongLayerSourceException: notLoaded.append(trackedlayer) else: try: layer = resolveLayerFromSource(trackedlayer.source) toUnload.append(layer) except WrongLayerSourceException: pass saveTracked() if repoLayersInProject: if notLoaded: ret = QtGui.QMessageBox.warning(config.iface.mainWindow(), "Update layers", "The current QGIS project only contains certain layers from the\n" "current version of the repository.\n" "Do you want to load the remaining ones?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.Yes); if ret == QtGui.QMessageBox.Yes: layersToLoad = [] for layer in notLoaded: layersToLoad.append(loadLayerNoCrsDialog(layer.source, layer.layername, "ogr")) QgsMapLayerRegistry.instance().addMapLayers(layersToLoad) if toUnload: ret = QtGui.QMessageBox.warning(config.iface.mainWindow(), "Update layers", "The following layers are not present anymore in the repository:\n" "\t- " + "\n\t- ".join([layer.name() for layer in toUnload]) + "\nDo you want to remove them from the current QGIS project?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.Yes); if ret == QtGui.QMessageBox.Yes: for layer in toUnload: QgsMapLayerRegistry.instance().removeMapLayer(layer.id()) config.iface.mapCanvas().refresh()
def loadRepoExportedLayers(repo): paths = getTrackedPathsForRepo(repo) layers = [] for f in paths: try: layer = resolveLayerFromSource(f) layer.reload() layer.triggerRepaint() except WrongLayerSourceException: layername = os.path.splitext(os.path.basename(f))[0] layer = loadLayerNoCrsDialog(f, layername, "ogr") layers.append(layer) if layers: QgsMapLayerRegistry.instance().addMapLayers(layers)
def loadRepoExportedLayers(repo): paths = getTrackedPathsForRepo(repo) layers = [] for f in paths: try: layer = resolveLayerFromSource(f) layer.dataProvider().forceReload() layer.setCacheImage(None) layer.triggerRepaint() except WrongLayerSourceException: layername = os.path.splitext(os.path.basename(f))[0] layer = loadLayerNoCrsDialog(f, layername, "ogr") layers.append(layer) if layers: QgsMapLayerRegistry.instance().addMapLayers(layers)
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