Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the option for specify the project title on packaged project #615

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 42 additions & 20 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 @@ -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")
)
Expand All @@ -73,10 +72,9 @@ 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
self.run_package_project
)
self.button_box.button(QDialogButtonBox.Reset).setText(
self.tr("Configure current project...")
Expand Down Expand Up @@ -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())
Expand All @@ -140,20 +136,43 @@ def setup_gui(self):
else:
self.show_package_page()

def get_export_folder_from_dialog(self):
"""Get the export folder according to the inputs in the selected"""
# manual
return self.manualDir.text()
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],
)
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 show_package_page(self):
self.nextButton.setVisible(False)
self.button_box.setVisible(True)
self.stackedWidget.setCurrentWidget(self.packagePage)

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 Filename"),
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)

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
Expand All @@ -165,18 +184,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
Expand Down Expand Up @@ -206,7 +228,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."
Expand Down
4 changes: 2 additions & 2 deletions qfieldsync/tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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"],
Expand Down
58 changes: 21 additions & 37 deletions qfieldsync/ui/package_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,13 @@
<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>
</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;Project:&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="QLabel" name="project_lbl">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
Expand Down Expand Up @@ -111,16 +81,25 @@
<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="packagedProjectTitleLineEdit"/>
</item>
<item row="0" column="1">
<widget class="QToolButton" name="manualDir_btn">
<property name="text">
<string>...</string>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Packaged Project Filename</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<widget class="QgsFileWidget" name="packagedProjectFileWidget">
<property name="storageMode">
<enum>QgsFileWidget::SaveFile</enum>
</property>
</widget>
</item>
Expand Down Expand Up @@ -279,6 +258,11 @@
<header>qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsFileWidget</class>
<extends>QWidget</extends>
<header>qgsfilewidget.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/5ba992c1f91ae74418a07c372a7ae11db557b10e.tar.gz
libqfieldsync @ https://github.com/opengisch/libqfieldsync/archive/1b923ba27ecfc8def5adcd255e94a226ae92b3eb.tar.gz
Loading