Skip to content

Commit

Permalink
Merge pull request #303 from opengisch/dry_metadata
Browse files Browse the repository at this point in the history
Metadata and filename path checks are now in LayerSource
  • Loading branch information
suricactus authored Sep 1, 2021
2 parents 9c6eebc + 0ebde8a commit 12c0dc9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 40 deletions.
16 changes: 4 additions & 12 deletions qfieldsync/core/cloud_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from pathlib import Path

from qgis.core import QgsMapLayer, QgsProject, QgsProviderRegistry
from qgis.core import QgsMapLayer, QgsProject
from qgis.PyQt.QtCore import QCoreApplication, QObject, pyqtSignal
from qgis.utils import iface

Expand Down Expand Up @@ -79,7 +79,6 @@ def convert(self) -> None: # noqa: C901
self.__layers = list(self.project.mapLayers().values())

# Loop through all layers and copy them to the destination folder
path_resolver = self.project.pathResolver()
for current_layer_index, layer in enumerate(self.__layers):
self.total_progress_updated.emit(
current_layer_index,
Expand All @@ -93,16 +92,9 @@ def convert(self) -> None: # noqa: C901
continue

if layer.dataProvider() is not None:
provider_metadata = QgsProviderRegistry.instance().providerMetadata(
layer.dataProvider().name()
)
if provider_metadata is not None:
decoded = provider_metadata.decodeUri(layer.source())
if "path" in decoded:
path = path_resolver.writePath(decoded["path"])
if path.startswith("localized:"):
# layer stored in localized data path, skip
continue
# layer stored in localized data path, skip
if layer_source.is_localized_path:
continue

if layer.type() == QgsMapLayer.VectorLayer:
if not layer_source.convert_to_gpkg(self.export_dirname):
Expand Down
20 changes: 7 additions & 13 deletions qfieldsync/gui/cloud_converter_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from pathlib import Path
from typing import Optional

from qgis.core import Qgis, QgsProject, QgsProviderRegistry
from qgis.core import Qgis, QgsProject
from qgis.gui import QgisInterface
from qgis.PyQt.QtCore import QDir, Qt
from qgis.PyQt.QtWidgets import (
Expand All @@ -48,6 +48,7 @@
from qfieldsync.core.cloud_transferrer import CloudTransferrer
from qfieldsync.core.preferences import Preferences
from qfieldsync.gui.cloud_login_dialog import CloudLoginDialog
from qfieldsync.libqfieldsync.layer import LayerSource
from qfieldsync.libqfieldsync.utils.file_utils import (
fileparts,
get_unique_empty_dirname,
Expand Down Expand Up @@ -230,21 +231,14 @@ def update_info_visibility(self):
"""
Show the info label if there are unconfigured layers
"""
pathResolver = QgsProject.instance().pathResolver()
localizedDataPathLayers = []
for layer in list(self.project.mapLayers().values()):
layer_source = LayerSource(layer)
if layer.dataProvider() is not None:
metadata = QgsProviderRegistry.instance().providerMetadata(
layer.dataProvider().name()
)
if metadata is not None:
decoded = metadata.decodeUri(layer.source())
if "path" in decoded:
path = pathResolver.writePath(decoded["path"])
if path.startswith("localized:"):
localizedDataPathLayers.append(
"- {} ({})".format(layer.name(), path[10:])
)
if layer_source.is_localized_path:
localizedDataPathLayers.append(
"- {} ({})".format(layer.name(), layer_source.filename)
)

if localizedDataPathLayers:
if len(localizedDataPathLayers) == 1:
Expand Down
21 changes: 7 additions & 14 deletions qfieldsync/gui/package_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"""
import os

from qgis.core import Qgis, QgsApplication, QgsProject, QgsProviderRegistry
from qgis.core import Qgis, QgsApplication, QgsProject
from qgis.PyQt.QtCore import QDir, Qt
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QApplication, QDialog, QDialogButtonBox, QMessageBox
Expand Down Expand Up @@ -156,24 +156,17 @@ def update_info_visibility(self):
"""
Show the info label if there are unconfigured layers
"""
pathResolver = QgsProject.instance().pathResolver()
showInfoConfiguration = False
localizedDataPathLayers = []
for layer in list(self.project.mapLayers().values()):
if not LayerSource(layer).is_configured:
layer_source = LayerSource(layer)
if not layer_source.is_configured:
showInfoConfiguration = True
if layer.dataProvider() is not None:
metadata = QgsProviderRegistry.instance().providerMetadata(
layer.dataProvider().name()

if layer_source.is_localized_path:
localizedDataPathLayers.append(
"- {} ({})".format(layer.name(), layer_source.filename)
)
if metadata is not None:
decoded = metadata.decodeUri(layer.source())
if "path" in decoded:
path = pathResolver.writePath(decoded["path"])
if path.startswith("localized:"):
localizedDataPathLayers.append(
"- {} ({})".format(layer.name(), path[10:])
)

self.infoConfigurationLabel.setVisible(showInfoConfiguration)
if localizedDataPathLayers:
Expand Down

0 comments on commit 12c0dc9

Please sign in to comment.