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

Keep Settings in UsabILIty Exporter on Navigation #873

Merged
merged 4 commits into from
Dec 22, 2023
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
12 changes: 4 additions & 8 deletions QgisModelBaker/gui/topping_wizard/additives_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
"""

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

VARIABLE_PREFIX_BLACKLIST = ["default_basket"]
VARIABLE_PREFIX_BLACKLIST = ["default_basket", "optimize_strategy"]


class AdditivesPage(QWizardPage, PAGE_UI):
Expand Down Expand Up @@ -55,8 +54,7 @@ def __init__(self, parent, title):

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_model.refresh_stringlist(maptheme_collection.mapThemes())
self.mapthemes_view.setVisible(self.mapthemes_model.rowCount())
self.mapthemes_label.setVisible(self.mapthemes_model.rowCount())

Expand All @@ -69,15 +67,13 @@ def initializePage(self) -> None:
if blacklisted_prefix not in variable_key
]

self.variables_model.setStringList(variables_keys)
self.variables_model.check_all(Qt.Checked)
self.variables_model.refresh_stringlist(variables_keys)
self.variables_view.setVisible(self.variables_model.rowCount())
self.variables_label.setVisible(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_model.refresh_stringlist(layout_names)
self.layouts_view.setVisible(self.layouts_model.rowCount())
self.layouts_label.setVisible(self.layouts_model.rowCount())
return super().initializePage()
Expand Down
2 changes: 2 additions & 0 deletions QgisModelBaker/gui/topping_wizard/ili2dbsettings_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ def _refresh_combobox(self):
for layer in QgsProject.instance().mapLayers().values():
if layer.type() == QgsMapLayer.VectorLayer:
source_provider = layer.dataProvider()
if not source_provider:
continue
schema_identificator = (
db_utils.get_schema_identificator_from_sourceprovider(
source_provider
Expand Down
21 changes: 21 additions & 0 deletions QgisModelBaker/gui/topping_wizard/layer_style_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,31 @@ def __init__(self, parent=None):
self.style_categories_list_view.model().check
)

self.select_all_checkbox.stateChanged.connect(self._select_all_items)
self.model.dataChanged.connect(lambda: self._set_select_all_checkbox())

self.ok_button.clicked.connect(self.accept)

def _set_select_all_checkbox(self):
self.select_all_checkbox.setCheckState(self._evaluated_check_state(self.model))

def _evaluated_check_state(self, model):
nbr_of_checked = len(model.checked_entries())
if nbr_of_checked:
if nbr_of_checked == model.rowCount():
return Qt.Checked
return Qt.PartiallyChecked
return Qt.Unchecked

def _select_all_items(self, state):
if state != Qt.PartiallyChecked and state != self._evaluated_check_state(
self.model
):
self.model.check_all(state)

def set_categories(self, categories: QgsMapLayer.StyleCategories):
self.style_categories_list_view.model().set_categories(categories)
self._set_select_all_checkbox()

@property
def categories(self):
Expand Down
11 changes: 7 additions & 4 deletions QgisModelBaker/gui/topping_wizard/layers_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def __init__(self, layertree: QgsLayerTree, export_settings=ExportSettings()):
self.use_definition_nodes = {}
self.ili_schema_identificators = []

self.reload()
self.reload(True)

def columnCount(self, parent=None):
return len(LayerModel.Columns)
Expand Down Expand Up @@ -311,9 +311,10 @@ def check(self, index):
else:
self.setData(index, Qt.CheckStateRole, Qt.Checked)

def reload(self):
def reload(self, load_defaults=False):
self._load_ili_schema_identificators()
self._set_default_values()
if load_defaults:
self._set_default_values()

def _disable_children(self, parent: QModelIndex):
for child_row in range(self.rowCount(parent)):
Expand Down Expand Up @@ -359,6 +360,8 @@ def _load_ili_schema_identificators(self):
for layer in QgsProject.instance().mapLayers().values():
if layer.type() == QgsMapLayer.VectorLayer:
source_provider = layer.dataProvider()
if not source_provider:
continue
schema_identificator = (
db_utils.get_schema_identificator_from_sourceprovider(
source_provider
Expand Down Expand Up @@ -551,7 +554,7 @@ def __init__(self, parent, title):

self.categories_dialog = LayerStyleCategoriesDialog()
self.stylecat_delegate.button_clicked.connect(self.open_categories_dialog)
self.reset_button.clicked.connect(self.layermodel.reload)
self.reset_button.clicked.connect(lambda: self.layermodel.reload(True))

def open_categories_dialog(self, index):
layername = index.data(int(Qt.DisplayRole))
Expand Down
2 changes: 2 additions & 0 deletions QgisModelBaker/gui/topping_wizard/models_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def _load_available_models_and_sources(self):
for layer in QgsProject.instance().mapLayers().values():
if layer.type() == QgsMapLayer.VectorLayer:
source_provider = layer.dataProvider()
if not source_provider:
continue
self._append_possible_sources(sources, source_provider)
schema_identificator = (
db_utils.get_schema_identificator_from_sourceprovider(
Expand Down
22 changes: 16 additions & 6 deletions QgisModelBaker/ui/topping_wizard/layer_style_categories.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
<string>Layer Style Categories</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="1">
<item row="1" column="0" colspan="2">
<widget class="SpaceCheckListView" name="style_categories_list_view" native="true"/>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="ok_button">
<property name="text">
<string>Ok</string>
Expand All @@ -24,7 +27,7 @@
</property>
</widget>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QDialogButtonBox" name="button_box">
<property name="orientation">
<enum>Qt::Horizontal</enum>
Expand All @@ -34,21 +37,28 @@
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="SpaceCheckListView" name="style_categories_list_view"/>
<item row="0" column="0">
<widget class="SemiTristateCheckbox" name="select_all_checkbox">
<property name="text">
<string>Select all</string>
</property>
</widget>
</item>
</layout>
</widget>

<customwidgets>
<customwidget>
<class>SpaceCheckListView</class>
<extends></extends>
<header>QgisModelBaker.utils.gui_utils</header>
<container>1</container>
</customwidget>
<customwidget>
<class>SemiTristateCheckbox</class>
<extends>QWidget</extends>
<header>QgisModelBaker.utils.gui_utils</header>
</customwidget>
</customwidgets>

<resources/>
<connections>
<connection>
Expand Down
30 changes: 24 additions & 6 deletions QgisModelBaker/utils/gui_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,10 +902,13 @@ def _emit_data_changed(self):
self.dataChanged.emit(self.index(0, 0), self.index(self.rowCount(), 0))

def checked_entries(self):
"""
Provides the selected entries as list
"""
return [
name
for name in self.stringList()
if self._checked_entries[name] == Qt.Checked
if self._checked_entries.get(name, Qt.Unchecked) == Qt.Checked
]

def check_entries(self, entries: list = []):
Expand All @@ -918,6 +921,25 @@ def check_entries(self, entries: list = []):
else:
self._checked_entries[name] == Qt.Unchecked

def refresh_stringlist(self, values):
"""
This sets the values to the string list, keeps thes status (checked_entries) when they still exist, and sets the new ones to Checked
"""

self.setStringList(values)

# if there where already entries with a status we take it and otherwise we set checked per default
new_checked_entries = {}
for value in values:
if value in self._checked_entries:
new_checked_entries[value] = self._checked_entries[value]
else:
new_checked_entries[value] = Qt.Checked
self._checked_entries = new_checked_entries

self._emit_data_changed()
return self.rowCount()


class SchemaModelsModel(CheckEntriesModel):
"""
Expand Down Expand Up @@ -980,11 +1002,7 @@ def refresh_model(self, db_connectors=[]):
modelnames.append(name)
self._parent_models[name] = db_model["parents"]

self.setStringList(modelnames)

self._checked_entries = {modelname: Qt.Checked for modelname in modelnames}

return self.rowCount()
return self.refresh_stringlist(modelnames)


class SchemaDatasetsModel(CheckEntriesModel):
Expand Down
Loading