Skip to content

Commit

Permalink
Changes suggested and improvements on UI
Browse files Browse the repository at this point in the history
  • Loading branch information
SeqLaz committed Oct 21, 2024
1 parent 218fc89 commit 16fe607
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 61 deletions.
51 changes: 41 additions & 10 deletions qfieldsync/gui/package_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
***************************************************************************/
"""
import os
from pathlib import Path

from libqfieldsync.layer import LayerSource
from libqfieldsync.offline_converter import ExportType, OfflineConverter
Expand Down Expand Up @@ -73,12 +74,9 @@ def __init__(self, iface, project, offline_editing, parent=None):
self.qfield_preferences = Preferences()
self.dirsToCopyWidget = DirsToCopyWidget()
self.__project_configuration = ProjectConfiguration(self.project)
self.packaged_project_filename.setText(self.project.baseName())
self.packaged_project_title.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
self.run_package_project
)
self.button_box.button(QDialogButtonBox.Reset).setText(
self.tr("Configure current project...")
Expand Down Expand Up @@ -115,7 +113,11 @@ def setup_gui(self):
)

self.manualDir.setText(QDir.toNativeSeparators(str(export_dirname)))
self.manualDir.textChanged.connect(self.set_export_filename_suggested)
self.manualDir_btn.clicked.connect(make_folder_selector(self.manualDir))
self.packaged_project_filename.setText(self.get_export_filename_suggestion())
self.packaged_project_title.setText(get_project_title(self.project))

self.update_info_visibility()

self.nextButton.clicked.connect(lambda: self.show_package_page())
Expand Down Expand Up @@ -147,15 +149,43 @@ def get_export_folder_from_dialog(self):
# manual
return self.manualDir.text()

def get_export_filename_suggestion(self):
export_folder = Path(self.get_export_folder_from_dialog())
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.packaged_project_filename.setText(self.get_export_filename_suggestion())

def show_package_page(self):
self.nextButton.setVisible(False)
self.button_box.setVisible(True)
self.stackedWidget.setCurrentWidget(self.packagePage)

def run_package_project(self):
export_packaged_project = Path(self.packaged_project_filename.text())

if export_packaged_project.exists():
reply = QMessageBox.question(
self,
"File Already Exists",
f"'{export_packaged_project.name}' already exists. Do you want to overwrite it?",
QMessageBox.Yes | QMessageBox.No,
QMessageBox.No,
)
if reply == QMessageBox.Yes:
self.package_project()
else:
self.show_package_page()
else:
self.package_project()

def package_project(self):
self.button_box.button(QDialogButtonBox.Save).setEnabled(False)

export_folder = self.get_export_folder_from_dialog()
export_packaged_project = Path(self.packaged_project_filename.text())
area_of_interest = (
self.__project_configuration.area_of_interest
if self.__project_configuration.area_of_interest
Expand All @@ -167,20 +197,21 @@ def package_project(self):
else QgsProject.instance().crs().authid()
)

self.qfield_preferences.set_value("exportDirectoryProject", export_folder)
self.qfield_preferences.set_value(
"exportDirectoryProject", export_packaged_project.parent
)
self.dirsToCopyWidget.save_settings()

offline_convertor = OfflineConverter(
self.project,
export_folder,
self.packaged_project_filename.text(),
self.packaged_project_title.text(),
export_packaged_project,
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.packaged_project_title.text(),
)

# progress connections
Expand Down Expand Up @@ -210,7 +241,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.packaged_project_filename.text()).parent)
result_message = self.tr(
"Finished creating the project at {result_folder}. Please copy this folder to "
"your QField device."
Expand Down
75 changes: 24 additions & 51 deletions qfieldsync/ui/package_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,6 @@
<string>Package Project for QField</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="label_2">
<property name="styleSheet">
<string notr="true">bold</string>
</property>
<property name="text">
<string>&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Packaged Project Name&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_filename">
<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">
<property name="currentIndex">
Expand Down Expand Up @@ -130,11 +81,33 @@
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Export Directory</string>
<string>Packaged Project Title</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLineEdit" name="manualDir"/>
<widget class="QLineEdit" name="packaged_project_title"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Packaged Project Filename</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item>
<widget class="QLineEdit" name="manualDir">
<property name="maximumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLineEdit" name="packaged_project_filename"/>
</item>
<item row="0" column="1">
<widget class="QToolButton" name="manualDir_btn">
Expand Down

0 comments on commit 16fe607

Please sign in to comment.