diff --git a/qfieldsync/core/cloud_converter.py b/qfieldsync/core/cloud_converter.py index 55804ef9..350bbefe 100644 --- a/qfieldsync/core/cloud_converter.py +++ b/qfieldsync/core/cloud_converter.py @@ -27,11 +27,11 @@ from qfieldsync.libqfieldsync.layer import LayerSource from qfieldsync.libqfieldsync.utils.file_utils import copy_images -from qfieldsync.utils.qgis_utils import ( +from qfieldsync.libqfieldsync.utils.qgis import ( get_qgis_files_within_dir, make_temp_qgis_file, - open_project, ) +from qfieldsync.utils.qgis_utils import open_project class CloudConverter(QObject): diff --git a/qfieldsync/core/cloud_project.py b/qfieldsync/core/cloud_project.py index 3a3c4269..f63d6854 100644 --- a/qfieldsync/core/cloud_project.py +++ b/qfieldsync/core/cloud_project.py @@ -29,7 +29,7 @@ from qgis.core import QgsProject from qfieldsync.core.preferences import Preferences -from qfieldsync.utils.qgis_utils import get_qgis_files_within_dir +from qfieldsync.libqfieldsync.utils.qgis import get_qgis_files_within_dir class ProjectFileCheckout(IntFlag): diff --git a/qfieldsync/gui/cloud_browser_tree.py b/qfieldsync/gui/cloud_browser_tree.py index 6f4e8fcd..e5388060 100644 --- a/qfieldsync/gui/cloud_browser_tree.py +++ b/qfieldsync/gui/cloud_browser_tree.py @@ -40,7 +40,7 @@ from qfieldsync.gui.cloud_login_dialog import CloudLoginDialog from qfieldsync.gui.cloud_projects_dialog import CloudProjectsDialog from qfieldsync.gui.cloud_transfer_dialog import CloudTransferDialog -from qfieldsync.utils.qgis_utils import get_qgis_files_within_dir +from qfieldsync.libqfieldsync.utils.qgis import get_qgis_files_within_dir class QFieldCloudItemProvider(QgsDataItemProvider): diff --git a/qfieldsync/gui/cloud_projects_dialog.py b/qfieldsync/gui/cloud_projects_dialog.py index 9270f97e..85d1cae2 100644 --- a/qfieldsync/gui/cloud_projects_dialog.py +++ b/qfieldsync/gui/cloud_projects_dialog.py @@ -70,9 +70,9 @@ from qfieldsync.gui.cloud_converter_dialog import CloudConverterDialog from qfieldsync.gui.cloud_login_dialog import CloudLoginDialog from qfieldsync.gui.cloud_transfer_dialog import CloudTransferDialog +from qfieldsync.libqfieldsync.utils.qgis import get_qgis_files_within_dir from qfieldsync.utils.cloud_utils import closure, to_cloud_title from qfieldsync.utils.permissions import can_change_project_owner, can_delete_project -from qfieldsync.utils.qgis_utils import get_qgis_files_within_dir from qfieldsync.utils.qt_utils import rounded_pixmap CloudProjectsDialogUi, _ = loadUiType( diff --git a/qfieldsync/gui/cloud_transfer_dialog.py b/qfieldsync/gui/cloud_transfer_dialog.py index 0a6c7303..450e7e90 100644 --- a/qfieldsync/gui/cloud_transfer_dialog.py +++ b/qfieldsync/gui/cloud_transfer_dialog.py @@ -47,9 +47,11 @@ from qfieldsync.core.cloud_transferrer import CloudTransferrer, TransferFileLogsModel from qfieldsync.core.preferences import Preferences from qfieldsync.libqfieldsync.utils.file_utils import get_unique_empty_dirname -from qfieldsync.utils.qgis_utils import get_qgis_files_within_dir +from qfieldsync.libqfieldsync.utils.qgis import ( + get_memory_layers, + get_qgis_files_within_dir, +) -from ..utils.qgis_utils import get_memory_layers from ..utils.qt_utils import make_folder_selector, make_icon, make_pixmap CloudTransferDialogUi, _ = loadUiType( diff --git a/qfieldsync/gui/package_dialog.py b/qfieldsync/gui/package_dialog.py index dfbe24a0..629cf2d6 100644 --- a/qfieldsync/gui/package_dialog.py +++ b/qfieldsync/gui/package_dialog.py @@ -32,8 +32,8 @@ from qfieldsync.gui.project_configuration_dialog import ProjectConfigurationDialog from qfieldsync.libqfieldsync import LayerSource, OfflineConverter, ProjectConfiguration from qfieldsync.libqfieldsync.utils.file_utils import fileparts +from qfieldsync.libqfieldsync.utils.qgis import get_project_title -from ..utils.qgis_utils import get_project_title from ..utils.qt_utils import make_folder_selector DialogUi, _ = loadUiType( diff --git a/qfieldsync/gui/synchronize_dialog.py b/qfieldsync/gui/synchronize_dialog.py index 08ed1806..6bf726f3 100644 --- a/qfieldsync/gui/synchronize_dialog.py +++ b/qfieldsync/gui/synchronize_dialog.py @@ -36,11 +36,8 @@ get_project_in_folder, import_file_checksum, ) -from qfieldsync.utils.qgis_utils import ( - import_checksums_of_project, - make_temp_qgis_file, - open_project, -) +from qfieldsync.libqfieldsync.utils.qgis import make_temp_qgis_file, open_project +from qfieldsync.utils.qgis_utils import import_checksums_of_project from qfieldsync.utils.qt_utils import make_folder_selector DialogUi, _ = loadUiType( diff --git a/qfieldsync/libqfieldsync b/qfieldsync/libqfieldsync index 1b6fc311..e5c1831a 160000 --- a/qfieldsync/libqfieldsync +++ b/qfieldsync/libqfieldsync @@ -1 +1 @@ -Subproject commit 1b6fc3111f9c88780f64cf8688246a946d7ffd82 +Subproject commit e5c1831ad477ef05c27fb45c92fec1457cc0bcd3 diff --git a/qfieldsync/utils/qgis_utils.py b/qfieldsync/utils/qgis_utils.py index f6b20d0a..a68176ce 100644 --- a/qfieldsync/utils/qgis_utils.py +++ b/qfieldsync/utils/qgis_utils.py @@ -19,46 +19,13 @@ ***************************************************************************/ """ -import os -import tempfile -from pathlib import Path -from typing import List, Union +from typing import List -from qgis.core import QgsMapLayer, QgsProject -from qgis.PyQt.QtCore import QCoreApplication +from qgis.core import QgsProject from qfieldsync.libqfieldsync import ProjectConfiguration from qfieldsync.libqfieldsync.utils.file_utils import get_project_in_folder - - -def get_project_title(project: QgsProject) -> str: - """ Gets project title, or if non available, the basename of the filename""" - if project.title(): - return project.title() - else: - return Path(project.fileName()).stem - - -def open_project(filename: str, filename_to_read: str = None) -> bool: - project = QgsProject.instance() - QCoreApplication.processEvents() - project.clear() - QCoreApplication.processEvents() - - is_success = project.read(filename_to_read or filename) - project.setFileName(filename) - - return is_success - - -def make_temp_qgis_file(project: QgsProject) -> str: - project_backup_dir = tempfile.mkdtemp() - original_filename = project.fileName() - backup_filename = os.path.join(project_backup_dir, f"{project.baseName()}.qgs") - project.write(backup_filename) - project.setFileName(original_filename) - - return backup_filename +from qfieldsync.libqfieldsync.utils.qgis import open_project def import_checksums_of_project(dirname: str) -> List[str]: @@ -68,16 +35,3 @@ def import_checksums_of_project(dirname: str) -> List[str]: original_project_path = ProjectConfiguration(project).original_project_path open_project(original_project_path) return ProjectConfiguration(project).imported_files_checksums - - -def get_memory_layers(project: QgsProject) -> List[QgsMapLayer]: - return [ - layer - for layer in project.mapLayers().values() - if layer.isValid() and layer.dataProvider().name() == "memory" - ] - - -def get_qgis_files_within_dir(dirname: Union[str, Path]) -> List[Path]: - dirname = Path(dirname) - return list(dirname.glob("*.qgs")) + list(dirname.glob("*.qgz"))