From 5118656ed57e10018d1cebf15a4eb1f0288e5b7b Mon Sep 17 00:00:00 2001 From: Johnny Sequeira Date: Wed, 25 Sep 2024 11:26:49 -0600 Subject: [PATCH 1/6] Adding the option for specify the project title on the exported packaged QField project Co-authored-by: Ivan Ivanov --- qfieldsync/gui/package_dialog.py | 52 ++++++++++++++++++---------- qfieldsync/ui/package_dialog.ui | 58 ++++++++++++-------------------- 2 files changed, 55 insertions(+), 55 deletions(-) diff --git a/qfieldsync/gui/package_dialog.py b/qfieldsync/gui/package_dialog.py index 39c95e07..7bb0314c 100644 --- a/qfieldsync/gui/package_dialog.py +++ b/qfieldsync/gui/package_dialog.py @@ -21,6 +21,7 @@ ***************************************************************************/ """ import os +from pathlib import Path from libqfieldsync.layer import LayerSource from libqfieldsync.offline_converter import ExportType, OfflineConverter @@ -54,8 +55,6 @@ from qfieldsync.gui.dirs_to_copy_widget import DirsToCopyWidget from qfieldsync.gui.project_configuration_dialog import ProjectConfigurationDialog -from ..utils.qt_utils import make_folder_selector - DialogUi, _ = loadUiType( os.path.join(os.path.dirname(__file__), "../ui/package_dialog.ui") ) @@ -73,7 +72,6 @@ def __init__(self, iface, project, offline_editing, parent=None): self.qfield_preferences = Preferences() self.dirsToCopyWidget = DirsToCopyWidget() self.__project_configuration = ProjectConfiguration(self.project) - self.project_lbl.setText(get_project_title(self.project)) self.button_box.button(QDialogButtonBox.Save).setText(self.tr("Create")) self.button_box.button(QDialogButtonBox.Save).clicked.connect( self.package_project @@ -105,15 +103,13 @@ def update_progress(self, sent, total): def setup_gui(self): """Populate gui and connect signals of the push dialog""" - export_dirname = self.qfield_preferences.value("exportDirectoryProject") - if not export_dirname: - export_dirname = os.path.join( - self.qfield_preferences.value("exportDirectory"), - fileparts(QgsProject.instance().fileName())[1], - ) + self.packagedProjectTitleLineEdit.setText(get_project_title(self.project)) + self.packagedProjectFileWidget.setFilter("QGIS Project Files (*.qgs)") + self.packagedProjectFileWidget.setConfirmOverwrite(True) + self.packagedProjectFileWidget.setFilePath( + self.get_export_filename_suggestion() + ) - self.manualDir.setText(QDir.toNativeSeparators(str(export_dirname))) - self.manualDir_btn.clicked.connect(make_folder_selector(self.manualDir)) self.update_info_visibility() self.nextButton.clicked.connect(lambda: self.show_package_page()) @@ -140,10 +136,27 @@ def setup_gui(self): else: self.show_package_page() - def get_export_folder_from_dialog(self): + def get_export_folder(self): """Get the export folder according to the inputs in the selected""" - # manual - return self.manualDir.text() + export_dirname = self.qfield_preferences.value("exportDirectoryProject") + if not export_dirname: + export_dirname = os.path.join( + self.qfield_preferences.value("exportDirectory"), + fileparts(QgsProject.instance().fileName())[1], + ) + return QDir.toNativeSeparators(str(export_dirname)) + + def get_export_filename_suggestion(self): + export_folder = Path(self.get_export_folder()) + full_project_name_suggestion = export_folder.joinpath( + f"{self.project.baseName()}_qfield.qgs" + ) + return str(full_project_name_suggestion) + + def set_export_filename_suggested(self): + self.packagedProjectFileWidget.setFilePath( + self.get_export_filename_suggestion() + ) def show_package_page(self): self.nextButton.setVisible(False) @@ -153,7 +166,7 @@ def show_package_page(self): def package_project(self): self.button_box.button(QDialogButtonBox.Save).setEnabled(False) - export_folder = self.get_export_folder_from_dialog() + packaged_project_file = Path(self.packagedProjectFileWidget.filePath()) area_of_interest = ( self.__project_configuration.area_of_interest if self.__project_configuration.area_of_interest @@ -165,18 +178,21 @@ def package_project(self): else QgsProject.instance().crs().authid() ) - self.qfield_preferences.set_value("exportDirectoryProject", export_folder) + self.qfield_preferences.set_value( + "exportDirectoryProject", packaged_project_file.parent + ) self.dirsToCopyWidget.save_settings() offline_convertor = OfflineConverter( self.project, - export_folder, + packaged_project_file, area_of_interest, area_of_interest_crs, self.qfield_preferences.value("attachmentDirs"), self.offliner, ExportType.Cable, dirs_to_copy=self.dirsToCopyWidget.dirs_to_copy(), + export_title=self.packagedProjectTitleLineEdit.text(), ) # progress connections @@ -206,7 +222,7 @@ def do_post_offline_convert_action(self, is_success): with a nice link to open the result folder. """ if is_success: - export_folder = self.get_export_folder_from_dialog() + export_folder = str(Path(self.packagedProjectFileWidget.filePath()).parent) result_message = self.tr( "Finished creating the project at {result_folder}. Please copy this folder to " "your QField device." diff --git a/qfieldsync/ui/package_dialog.ui b/qfieldsync/ui/package_dialog.ui index 4f423b7d..d3df43d8 100644 --- a/qfieldsync/ui/package_dialog.ui +++ b/qfieldsync/ui/package_dialog.ui @@ -7,43 +7,13 @@ 0 0 599 - 570 + 700 Package Project for QField - - - - 0 - - - - - <html><head/><body><p><span style=" font-weight:600;">Project:</span></p></body></html> - - - Qt::RichText - - - - - - - - 0 - 0 - - - - - - - - - @@ -111,16 +81,25 @@ - Export Directory + Packaged Project Title - + - - - - ... + + + + + + + Packaged Project Filename + + + + + + QgsFileWidget::SaveFile @@ -279,6 +258,11 @@
qgscollapsiblegroupbox.h
1 + + QgsFileWidget + QWidget +
qgsfilewidget.h
+
From f60f4d7230b1ac1406fc55b525aac1f21b757191 Mon Sep 17 00:00:00 2001 From: Johnny Sequeira Date: Thu, 24 Oct 2024 12:58:01 -0600 Subject: [PATCH 2/6] Ensuring the filename have the .qgs extension --- qfieldsync/gui/package_dialog.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/qfieldsync/gui/package_dialog.py b/qfieldsync/gui/package_dialog.py index 7bb0314c..3abd0f0e 100644 --- a/qfieldsync/gui/package_dialog.py +++ b/qfieldsync/gui/package_dialog.py @@ -74,7 +74,7 @@ def __init__(self, iface, project, offline_editing, parent=None): self.__project_configuration = ProjectConfiguration(self.project) self.button_box.button(QDialogButtonBox.Save).setText(self.tr("Create")) self.button_box.button(QDialogButtonBox.Save).clicked.connect( - self.package_project + self.run_package_project ) self.button_box.button(QDialogButtonBox.Reset).setText( self.tr("Configure current project...") @@ -163,6 +163,20 @@ def show_package_page(self): self.button_box.setVisible(True) self.stackedWidget.setCurrentWidget(self.packagePage) + def run_package_project(self): + export_packaged_project = Path(self.packagedProjectFileWidget.filePath()) + + if export_packaged_project.suffix != ".qgs": + QMessageBox.critical( + self, + self.tr("Invalid File"), + self.tr('The filename must have a ".qgs" extension.'), + ) + return + + else: + self.package_project() + def package_project(self): self.button_box.button(QDialogButtonBox.Save).setEnabled(False) From f1635877f0fd4dcb7972dd8400fd74e0bcad94d8 Mon Sep 17 00:00:00 2001 From: Johnny Sequeira Date: Fri, 1 Nov 2024 09:06:02 -0600 Subject: [PATCH 3/6] Adding typing hints --- qfieldsync/gui/package_dialog.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/qfieldsync/gui/package_dialog.py b/qfieldsync/gui/package_dialog.py index 3abd0f0e..54ce9f73 100644 --- a/qfieldsync/gui/package_dialog.py +++ b/qfieldsync/gui/package_dialog.py @@ -136,7 +136,7 @@ def setup_gui(self): else: self.show_package_page() - def get_export_folder(self): + def get_export_folder(self) -> str: """Get the export folder according to the inputs in the selected""" export_dirname = self.qfield_preferences.value("exportDirectoryProject") if not export_dirname: @@ -146,14 +146,14 @@ def get_export_folder(self): ) return QDir.toNativeSeparators(str(export_dirname)) - def get_export_filename_suggestion(self): + def get_export_filename_suggestion(self) -> str: export_folder = Path(self.get_export_folder()) full_project_name_suggestion = export_folder.joinpath( f"{self.project.baseName()}_qfield.qgs" ) return str(full_project_name_suggestion) - def set_export_filename_suggested(self): + def set_export_filename_suggested(self) -> None: self.packagedProjectFileWidget.setFilePath( self.get_export_filename_suggestion() ) @@ -163,13 +163,13 @@ def show_package_page(self): self.button_box.setVisible(True) self.stackedWidget.setCurrentWidget(self.packagePage) - def run_package_project(self): + def run_package_project(self) -> None: export_packaged_project = Path(self.packagedProjectFileWidget.filePath()) if export_packaged_project.suffix != ".qgs": QMessageBox.critical( self, - self.tr("Invalid File"), + self.tr("Invalid Filename"), self.tr('The filename must have a ".qgs" extension.'), ) return From f5328f330ea208055ec46fd04bdb7d3d016db1bc Mon Sep 17 00:00:00 2001 From: Johnny Sequeira Date: Thu, 7 Nov 2024 03:03:24 -0600 Subject: [PATCH 4/6] Deleting unnecessary function and joining the export_folder to in the suggestion function --- qfieldsync/gui/package_dialog.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/qfieldsync/gui/package_dialog.py b/qfieldsync/gui/package_dialog.py index 54ce9f73..b2bcca22 100644 --- a/qfieldsync/gui/package_dialog.py +++ b/qfieldsync/gui/package_dialog.py @@ -136,28 +136,20 @@ def setup_gui(self): else: self.show_package_page() - def get_export_folder(self) -> str: - """Get the export folder according to the inputs in the selected""" + def get_export_filename_suggestion(self) -> str: + """Get the suggested export filename""" export_dirname = self.qfield_preferences.value("exportDirectoryProject") if not export_dirname: export_dirname = os.path.join( self.qfield_preferences.value("exportDirectory"), fileparts(QgsProject.instance().fileName())[1], ) - return QDir.toNativeSeparators(str(export_dirname)) - - def get_export_filename_suggestion(self) -> str: - export_folder = Path(self.get_export_folder()) + export_folder = Path(QDir.toNativeSeparators(str(export_dirname))) full_project_name_suggestion = export_folder.joinpath( f"{self.project.baseName()}_qfield.qgs" ) return str(full_project_name_suggestion) - def set_export_filename_suggested(self) -> None: - self.packagedProjectFileWidget.setFilePath( - self.get_export_filename_suggestion() - ) - def show_package_page(self): self.nextButton.setVisible(False) self.button_box.setVisible(True) From 916379103f932bae85ac5b4ae448984b97e6fc63 Mon Sep 17 00:00:00 2001 From: Johnny Sequeira Date: Wed, 13 Nov 2024 00:45:47 -0600 Subject: [PATCH 5/6] Adding libqfieldsync dependency for properly working --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 10f200cf..4878552d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,4 +7,4 @@ future transifex-client # NOTE `libqfielsync` version should be defined in the `*.tar.gz` format, not `git+https://` to make `wheel` happy -libqfieldsync @ https://github.com/opengisch/libqfieldsync/archive/7901b65225caa2fb8788639f1e21b1050c87a6f3.tar.gz +libqfieldsync @ https://github.com/opengisch/libqfieldsync/archive/1b923ba27ecfc8def5adcd255e94a226ae92b3eb.tar.gz From 627a677ffa0168915613969bc821a46fa37b6263 Mon Sep 17 00:00:00 2001 From: Johnny Sequeira Date: Wed, 13 Nov 2024 13:56:08 -0600 Subject: [PATCH 6/6] Fixing tests --- qfieldsync/tests/test_export.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qfieldsync/tests/test_export.py b/qfieldsync/tests/test_export.py index d3d687e4..703fff56 100644 --- a/qfieldsync/tests/test_export.py +++ b/qfieldsync/tests/test_export.py @@ -70,7 +70,7 @@ def test_copy(self): offline_editing = QgsOfflineEditing() offline_converter = OfflineConverter( project, - str(self.target_dir), + self.target_dir.joinpath("project_qfield.qgs"), "POLYGON((1 1, 5 0, 5 5, 0 5, 1 1))", QgsProject.instance().crs().authid(), ["DCIM"], @@ -110,7 +110,7 @@ def test_primary_keys_custom_property(self): offline_editing = QgsOfflineEditing() offline_converter = OfflineConverter( project, - str(self.target_dir), + self.target_dir.joinpath("project_qfield.qgs"), "POLYGON((1 1, 5 0, 5 5, 0 5, 1 1))", QgsProject.instance().crs().authid(), ["DCIM"],