From 7fed37b8dc09f74492cc5dd30d7a9d0182c6ee86 Mon Sep 17 00:00:00 2001 From: Johnny Sequeira Date: Fri, 4 Oct 2024 20:21:26 -0600 Subject: [PATCH] Adding line edit for specify the project name, and improve the synchronization of packaged projects --- qfieldsync/gui/package_dialog.py | 19 +++++-- qfieldsync/gui/synchronize_dialog.py | 4 +- qfieldsync/ui/package_dialog.ui | 75 +++++++++++++++++----------- 3 files changed, 64 insertions(+), 34 deletions(-) diff --git a/qfieldsync/gui/package_dialog.py b/qfieldsync/gui/package_dialog.py index ef732a12..a190df74 100644 --- a/qfieldsync/gui/package_dialog.py +++ b/qfieldsync/gui/package_dialog.py @@ -42,7 +42,7 @@ from libqfieldsync.project import ProjectConfiguration from libqfieldsync.project_checker import ProjectChecker from libqfieldsync.utils.file_utils import fileparts -from libqfieldsync.utils.qgis import open_project +from libqfieldsync.utils.qgis import open_project, make_temp_qgis_file from qgis.core import Qgis, QgsApplication, QgsProject from qgis.PyQt.QtCore import QDir, Qt, QUrl from qgis.PyQt.QtGui import QIcon @@ -70,11 +70,15 @@ def __init__(self, iface, project, offline_editing, parent=None): self.iface = iface self.offliner = QgisCoreOffliner(offline_editing=offline_editing) self.project = project + self.original_project_path = self.project.fileName() self.qfield_preferences = Preferences() self.dirsToCopyWidget = DirsToCopyWidget() self.__project_configuration = ProjectConfiguration(self.project) self.original_project_title = project.title() - self.packaged_project_title.setText(self.original_title_project) + self.packaged_project_title.setText(self.original_project_title) + self.packaged_project_name.setText(self.project.baseName()) + self.tmp_project = make_temp_qgis_file(self.project) + self.button_box.button(QDialogButtonBox.Save).setText(self.tr("Create")) self.button_box.button(QDialogButtonBox.Save).clicked.connect( self.package_project @@ -169,7 +173,13 @@ def package_project(self): self.qfield_preferences.set_value("exportDirectoryProject", export_folder) self.dirsToCopyWidget.save_settings() - self.project.setTitle(self.new_project_title.text()) + tmp_path = os.path.dirname(self.tmp_project) + + new_project_path = os.path.join( + tmp_path, f"{self.packaged_project_name.text()}.qgs" + ) + self.project.write(new_project_path) + self.project.setFileName(new_project_path) offline_convertor = OfflineConverter( self.project, @@ -192,8 +202,7 @@ def package_project(self): try: QApplication.setOverrideCursor(Qt.WaitCursor) offline_convertor.convert() - self.project.setTitle(self.original_title_project) - open_project(self.project.fileName()) + open_project(self.original_project_path) self.do_post_offline_convert_action(True) except Exception as err: self.do_post_offline_convert_action(False) diff --git a/qfieldsync/gui/synchronize_dialog.py b/qfieldsync/gui/synchronize_dialog.py index 401b4062..e34c9845 100644 --- a/qfieldsync/gui/synchronize_dialog.py +++ b/qfieldsync/gui/synchronize_dialog.py @@ -113,7 +113,9 @@ def start_synchronization(self): self.offline_editing.synchronize() project_config = ProjectConfiguration(QgsProject.instance()) - original_path = Path(project_config.original_project_path or "") + original_path = Path( + current_path or project_config.original_project_path or "" + ) if not original_path.exists(): answer = QMessageBox.warning( diff --git a/qfieldsync/ui/package_dialog.ui b/qfieldsync/ui/package_dialog.ui index 23d8028f..9f9da392 100644 --- a/qfieldsync/ui/package_dialog.ui +++ b/qfieldsync/ui/package_dialog.ui @@ -7,7 +7,7 @@ 0 0 599 - 570 + 700 @@ -15,34 +15,53 @@ - - - 0 + + + bold - - - - <html><head/><body><p><span style=" font-weight:600;">Exported Project Title:</span></p></body></html> - - - Qt::RichText - - - - - - - - 0 - 0 - - - - - - - - + + <html><head/><body><p><span style=" font-weight:600;">Packaged Project Name</span></p></body></html> + + + Qt::RichText + + + + + + + + 0 + 0 + + + + + + + + + + + <p><span style=" font-weight:600;">Packaged Project Title</span></p> + + + Qt::RichText + + + + + + + + 0 + 0 + + + + + +