Skip to content

Commit

Permalink
Adding line edit for specify the project name, and improve the synchr…
Browse files Browse the repository at this point in the history
…onization of packaged projects
  • Loading branch information
SeqLaz committed Oct 5, 2024
1 parent c32b004 commit 7fed37b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 34 deletions.
19 changes: 14 additions & 5 deletions qfieldsync/gui/package_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion qfieldsync/gui/synchronize_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
75 changes: 47 additions & 28 deletions qfieldsync/ui/package_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,61 @@
<x>0</x>
<y>0</y>
<width>599</width>
<height>570</height>
<height>700</height>
</rect>
</property>
<property name="windowTitle">
<string>Package Project for QField</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="topMargin">
<number>0</number>
<widget class="QLabel" name="label_2">
<property name="styleSheet">
<string notr="true">bold</string>
</property>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Exported Project Title:&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="new_project_title">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Packaged Project Name&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="packaged_project_name">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Packaged Project Title&lt;/span&gt;&lt;/p&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="packaged_project_title">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QStackedWidget" name="stackedWidget">
Expand Down

0 comments on commit 7fed37b

Please sign in to comment.