From 9754d5ea097d75a8cc42f130edf419d7aee0a2e6 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Sun, 21 Jul 2024 17:37:07 +0700 Subject: [PATCH 1/3] Add map themes's default active layer configuration --- qfieldsync/gui/mapthemes_config_widget.py | 83 +++++++++++++++++++ .../gui/project_configuration_widget.py | 12 ++- qfieldsync/ui/project_configuration_widget.ui | 17 ++++ 3 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 qfieldsync/gui/mapthemes_config_widget.py diff --git a/qfieldsync/gui/mapthemes_config_widget.py b/qfieldsync/gui/mapthemes_config_widget.py new file mode 100644 index 00000000..c8ba2a66 --- /dev/null +++ b/qfieldsync/gui/mapthemes_config_widget.py @@ -0,0 +1,83 @@ +# -*- coding: utf-8 -*- +""" +/*************************************************************************** + MapThemesConfigWidget + A QGIS plugin + Sync your projects to QField + ------------------- + begin : 2020-10-10 + git sha : $Format:%H$ + copyright : (C) 2020 by OPENGIS.ch + email : info@opengis.ch + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +""" + +from qgis.core import Qgis +from qgis.gui import QgsMapLayerComboBox + +from qgis.PyQt.QtCore import Qt +from qgis.PyQt.QtWidgets import QTableWidgetItem, QTableWidget + + +class MapThemesConfigWidget(QTableWidget): + def __init__(self, project, configuration, parent=None): + """Constructor.""" + super(QTableWidget, self).__init__(parent=parent) + + self.project = project + + self.setMinimumHeight(200) + self.setColumnCount(2) + self.setHorizontalHeaderLabels( + [self.tr("Map Theme"), self.tr("Default Active Layer")] + ) + + self.reload(configuration) + + def reload(self, configuration): + """ + Load map themes into table. + """ + + self.setRowCount(0) + self.setSortingEnabled(False) + map_themes = self.project.mapThemeCollection().mapThemes() + for map_theme in map_themes: + count = self.rowCount() + self.insertRow(count) + item = QTableWidgetItem(map_theme) + item.setData(Qt.EditRole, map_theme) + self.setItem(count, 0, item) + + cmb = QgsMapLayerComboBox() + cmb.setAllowEmptyLayer(True) + cmb.setProject(self.project) + cmb.setFilters(Qgis.LayerFilter.VectorLayer) + if map_theme in configuration: + cmb.setLayer(self.project.mapLayer(configuration[map_theme])) + self.setCellWidget(count, 1, cmb) + + self.setColumnWidth(0, int(self.width() * 0.2)) + self.setColumnWidth(1, int(self.width() * 0.75)) + self.sortByColumn(0, Qt.AscendingOrder) + self.setSortingEnabled(True) + + def createConfiguration(self): + configuration = {} + for i in range(self.rowCount()): + item = self.item(i, 0) + map_theme = item.data(Qt.EditRole) + cmb = self.cellWidget(i, 1) + layer_id = cmb.currentLayer().id() if cmb.currentLayer() else "" + configuration[map_theme] = layer_id + + return configuration diff --git a/qfieldsync/gui/project_configuration_widget.py b/qfieldsync/gui/project_configuration_widget.py index 28de3858..691c750e 100644 --- a/qfieldsync/gui/project_configuration_widget.py +++ b/qfieldsync/gui/project_configuration_widget.py @@ -36,6 +36,7 @@ from qfieldsync.core.preferences import Preferences from qfieldsync.gui.layers_config_widget import LayersConfigWidget +from qfieldsync.gui.mapthemes_config_widget import MapThemesConfigWidget WidgetUi, _ = loadUiType( os.path.join(os.path.dirname(__file__), "../ui/project_configuration_widget.ui"), @@ -152,7 +153,7 @@ def reloadProject(self): self.cloudExportTab.layout().addWidget(infoLabel, 0, 2) self.cableExportTab.layout().addWidget(self.cableLayersConfigWidget) - # Load Map Themes + # Map Themes configuration widgets for theme in self.project.mapThemeCollection().mapThemes(): self.mapThemeComboBox.addItem(theme) @@ -166,6 +167,11 @@ def reloadProject(self): self.__project_configuration = ProjectConfiguration(self.project) + self.mapThemesConfigWidget = MapThemesConfigWidget( + self.project, self.__project_configuration.map_themes_active_layer + ) + self.mapThemesGroupBox.layout().addWidget(self.mapThemesConfigWidget) + # Base map settings self.createBaseMapGroupBox.setChecked( self.__project_configuration.create_base_map @@ -371,6 +377,10 @@ def apply(self): keys[item.text()] = 1 self.preferences.set_value("attachmentDirs", list(keys.keys())) + self.__project_configuration.map_themes_active_layer = ( + self.mapThemesConfigWidget.createConfiguration() + ) + def onForceAutoPushClicked(self, checked): self.forceAutoPushInterval.setEnabled(checked) diff --git a/qfieldsync/ui/project_configuration_widget.ui b/qfieldsync/ui/project_configuration_widget.ui index c1a0a3a3..2068859e 100644 --- a/qfieldsync/ui/project_configuration_widget.ui +++ b/qfieldsync/ui/project_configuration_widget.ui @@ -420,6 +420,23 @@ true + + + + Map Themes Configuration + + + false + + + false + + + true + + + + From 822eb309b65c7784a7031189eec94d2c78df3449 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Wed, 24 Jul 2024 15:37:25 +0700 Subject: [PATCH 2/3] Update libqfieldsync revision --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index c8820ca1..c1e22518 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/61523b5775dd1bccc25abcf4b9c7a266af18c214.tar.gz +libqfieldsync @ https://github.com/opengisch/libqfieldsync/archive/c670dcffb9aada9a7066591a7588188f024102a0.tar.gz From 542624dbc5c1b65636039b9387a2cb84a45f88ac Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Wed, 24 Jul 2024 17:32:30 +0700 Subject: [PATCH 3/3] Update qfieldsync/gui/mapthemes_config_widget.py Co-authored-by: Ivan Ivanov --- qfieldsync/gui/mapthemes_config_widget.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qfieldsync/gui/mapthemes_config_widget.py b/qfieldsync/gui/mapthemes_config_widget.py index c8ba2a66..76c6cc33 100644 --- a/qfieldsync/gui/mapthemes_config_widget.py +++ b/qfieldsync/gui/mapthemes_config_widget.py @@ -5,9 +5,9 @@ A QGIS plugin Sync your projects to QField ------------------- - begin : 2020-10-10 + begin : 2024-07-22 git sha : $Format:%H$ - copyright : (C) 2020 by OPENGIS.ch + copyright : (C) 2024 by OPENGIS.ch email : info@opengis.ch ***************************************************************************/