diff --git a/QgisModelBaker/gui/topping_wizard/additives_page.py b/QgisModelBaker/gui/topping_wizard/additives_page.py new file mode 100644 index 000000000..66adf532e --- /dev/null +++ b/QgisModelBaker/gui/topping_wizard/additives_page.py @@ -0,0 +1,84 @@ +# -*- coding: utf-8 -*- +""" +/*************************************************************************** + ------------------- + begin : 2022-12-07 + git sha : :%H$ + copyright : (C) 2022 by Dave Signer + email : david at 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 QgsProject +from qgis.PyQt.QtCore import Qt +from qgis.PyQt.QtWidgets import QWizardPage + +from QgisModelBaker.utils import gui_utils +from QgisModelBaker.utils.gui_utils import CheckEntriesModel + +PAGE_UI = gui_utils.get_ui_class("topping_wizard/additives.ui") + + +class AdditivesPage(QWizardPage, PAGE_UI): + def __init__(self, parent, title): + QWizardPage.__init__(self) + + self.topping_wizard = parent + + self.setupUi(self) + + self.setStyleSheet(gui_utils.DEFAULT_STYLE) + self.setTitle(title) + + self.mapthemes_model = CheckEntriesModel() + self.mapthemes_view.setModel(self.mapthemes_model) + self.mapthemes_view.clicked.connect(self.mapthemes_view.model().check) + self.mapthemes_view.space_pressed.connect(self.mapthemes_view.model().check) + self.variables_model = CheckEntriesModel() + self.variables_view.setModel(self.variables_model) + self.variables_view.clicked.connect(self.variables_view.model().check) + self.variables_view.space_pressed.connect(self.variables_view.model().check) + self.layouts_model = CheckEntriesModel() + self.layouts_view.setModel(self.layouts_model) + self.layouts_view.clicked.connect(self.layouts_view.model().check) + self.layouts_view.space_pressed.connect(self.layouts_view.model().check) + + def initializePage(self) -> None: + maptheme_collection = QgsProject.instance().mapThemeCollection() + self.mapthemes_model.setStringList(maptheme_collection.mapThemes()) + self.mapthemes_model.check_all(Qt.Checked) + self.mapthemes_view.setEnabled(self.mapthemes_model.rowCount()) + + variables_keys = [] + variables_keys = QgsProject.instance().customVariables().keys() + self.variables_model.setStringList(variables_keys) + self.variables_model.check_all(Qt.Checked) + self.mapthemes_view.setEnabled(self.variables_model.rowCount()) + + layout_manager = QgsProject.instance().layoutManager() + layout_names = [layout.name() for layout in layout_manager.printLayouts()] + self.layouts_model.setStringList(layout_names) + self.layouts_model.check_all(Qt.Checked) + self.layouts_view.setEnabled(self.layouts_model.rowCount()) + return super().initializePage() + + def validatePage(self) -> bool: + self.topping_wizard.topping.export_settings.mapthemes = ( + self.mapthemes_model.checked_entries() + ) + self.topping_wizard.topping.export_settings.variables = ( + self.variables_model.checked_entries() + ) + self.topping_wizard.topping.export_settings.layouts = ( + self.layouts_model.checked_entries() + ) + return super().validatePage() diff --git a/QgisModelBaker/gui/topping_wizard/layers_page.py b/QgisModelBaker/gui/topping_wizard/layers_page.py index a72a9221e..251df2942 100644 --- a/QgisModelBaker/gui/topping_wizard/layers_page.py +++ b/QgisModelBaker/gui/topping_wizard/layers_page.py @@ -24,6 +24,7 @@ from qgis.core import ( QgsApplication, QgsLayerTree, + QgsLayerTreeLayer, QgsLayerTreeModel, QgsMapLayer, QgsProject, @@ -215,7 +216,7 @@ def setData(self, index, role, data): index.column() == LayerModel.Columns.USE_STYLE and not QgsLayerTree.isGroup(node) ): - self.export_settings.set_setting_values( + self._set_export_settings_values_for_all_styles( ExportSettings.ToppingType.QMLSTYLE, node, None, @@ -244,7 +245,7 @@ def setData(self, index, role, data): if bool(data): # when the definition is checked the others become unchecked - self.export_settings.set_setting_values( + self._set_export_settings_values_for_all_styles( ExportSettings.ToppingType.QMLSTYLE, node, None, @@ -296,7 +297,7 @@ def setData(self, index, role, data): ): node = self.index2node(index) if node: - self.export_settings.set_setting_values( + self._set_export_settings_values_for_all_styles( ExportSettings.ToppingType.QMLSTYLE, node, None, True, data ) return True @@ -407,7 +408,7 @@ def _set_default_values(self): self.beginResetModel() for layernode in layernodes: if self._is_ili_schema(layernode.layer()): - self.export_settings.set_setting_values( + self._set_export_settings_values_for_all_styles( ExportSettings.ToppingType.QMLSTYLE, layernode, None, @@ -426,7 +427,7 @@ def _set_default_values(self): bool(False), ) else: - self.export_settings.set_setting_values( + self._set_export_settings_values_for_all_styles( ExportSettings.ToppingType.QMLSTYLE, layernode, None, @@ -465,6 +466,24 @@ def _set_default_values(self): ) self.endResetModel() + def _set_export_settings_values_for_all_styles( + self, + type=ExportSettings.ToppingType.QMLSTYLE, + node: QgsLayerTreeLayer = None, + name: str = None, + export=True, + categories=None, + ): + """ + Currently individual settings per style is not supported by the exporter. + So we have this function applying the setting (export True/False and category) on each style. + """ + if isinstance(node, QgsLayerTreeLayer): + for style_name in node.layer().styleManager().styles(): + self.export_settings.set_setting_values( + type, node, name, export, categories, style_name + ) + class StyleCatDelegate(QStyledItemDelegate): diff --git a/QgisModelBaker/gui/topping_wizard/topping_wizard.py b/QgisModelBaker/gui/topping_wizard/topping_wizard.py index 0b121c9fa..a6365f70e 100644 --- a/QgisModelBaker/gui/topping_wizard/topping_wizard.py +++ b/QgisModelBaker/gui/topping_wizard/topping_wizard.py @@ -23,6 +23,7 @@ from qgis.PyQt.QtWidgets import QDialog, QSplitter, QVBoxLayout, QWizard from QgisModelBaker.gui.panel.log_panel import LogPanel +from QgisModelBaker.gui.topping_wizard.additives_page import AdditivesPage from QgisModelBaker.gui.topping_wizard.generation_page import GenerationPage from QgisModelBaker.gui.topping_wizard.ili2dbsettings_page import Ili2dbSettingsPage from QgisModelBaker.gui.topping_wizard.layers_page import LayersPage @@ -62,6 +63,9 @@ def __init__(self, iface, base_config, parent): self.layers_page = LayersPage( self, self._current_page_title(ToppingWizardPageIds.Layers) ) + self.additives_page = AdditivesPage( + self, self._current_page_title(ToppingWizardPageIds.Additives) + ) self.referencedata_page = ReferencedataPage( self, self._current_page_title(ToppingWizardPageIds.ReferenceData) ) @@ -75,6 +79,7 @@ def __init__(self, iface, base_config, parent): self.setPage(ToppingWizardPageIds.Target, self.target_page) self.setPage(ToppingWizardPageIds.Models, self.models_page) self.setPage(ToppingWizardPageIds.Layers, self.layers_page) + self.setPage(ToppingWizardPageIds.Additives, self.additives_page) self.setPage(ToppingWizardPageIds.ReferenceData, self.referencedata_page) self.setPage(ToppingWizardPageIds.Ili2dbSettings, self.ili2dbsettings_page) self.setPage(ToppingWizardPageIds.Generation, self.generation_page) @@ -100,6 +105,8 @@ def _current_page_title(self, id): return self.tr("Model Selection") elif id == ToppingWizardPageIds.Layers: return self.tr("Layer Configuration") + elif id == ToppingWizardPageIds.Additives: + return self.tr("Additive Project Settings") elif id == ToppingWizardPageIds.ReferenceData: return self.tr("Reference Data Selection") elif id == ToppingWizardPageIds.Ili2dbSettings: diff --git a/QgisModelBaker/ui/topping_wizard/additives.ui b/QgisModelBaker/ui/topping_wizard/additives.ui new file mode 100644 index 000000000..d2a7afde4 --- /dev/null +++ b/QgisModelBaker/ui/topping_wizard/additives.ui @@ -0,0 +1,105 @@ + + + Models + + + + 0 + 0 + 800 + 600 + + + + Select Files + + + + + + + 0 + 0 + + + + + 75 + true + + + + Select the Map Themes that should be exported, as well as the custom project variables and the print layouts. + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + + + + + + 0 + 0 + + + + + + + + Custom Project Variables + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + + + + + Print Layouts (exported as templates) + + + + + + + Map Themes + + + + + + + + SpaceCheckListView + +
QgisModelBaker.utils.gui_utils
+ 1 +
+
+ + +
diff --git a/QgisModelBaker/utils/gui_utils.py b/QgisModelBaker/utils/gui_utils.py index d3eccdc60..81ea70913 100644 --- a/QgisModelBaker/utils/gui_utils.py +++ b/QgisModelBaker/utils/gui_utils.py @@ -169,9 +169,10 @@ class ToppingWizardPageIds: Target = 1 Models = 2 Layers = 3 - ReferenceData = 4 - Ili2dbSettings = 5 - Generation = 6 + Additives = 4 + ReferenceData = 5 + Ili2dbSettings = 6 + Generation = 7 # Util functions @@ -793,14 +794,17 @@ class CheckEntriesModel(QStringListModel): def __init__(self): super().__init__() - self._checked_entries = None + self._checked_entries = {} def flags(self, index): return Qt.ItemIsSelectable | Qt.ItemIsEnabled def data(self, index, role): if role == Qt.CheckStateRole: - return self._checked_entries[self.data(index, Qt.DisplayRole)] + if self.data(index, Qt.DisplayRole) in self._checked_entries: + return self._checked_entries[self.data(index, Qt.DisplayRole)] + else: + return Qt.Unchecked else: return QStringListModel.data(self, index, role)