diff --git a/QgisModelBaker/gui/topping_wizard/additives_page.py b/QgisModelBaker/gui/topping_wizard/additives_page.py
index a4a41494f..1707f9e48 100644
--- a/QgisModelBaker/gui/topping_wizard/additives_page.py
+++ b/QgisModelBaker/gui/topping_wizard/additives_page.py
@@ -18,7 +18,6 @@
"""
from qgis.core import QgsProject
-from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtWidgets import QWizardPage
from QgisModelBaker.utils import gui_utils
@@ -26,7 +25,7 @@
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):
@@ -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())
@@ -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()
diff --git a/QgisModelBaker/gui/topping_wizard/ili2dbsettings_page.py b/QgisModelBaker/gui/topping_wizard/ili2dbsettings_page.py
index b4c485aa5..d64d330e3 100644
--- a/QgisModelBaker/gui/topping_wizard/ili2dbsettings_page.py
+++ b/QgisModelBaker/gui/topping_wizard/ili2dbsettings_page.py
@@ -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
diff --git a/QgisModelBaker/gui/topping_wizard/layer_style_categories.py b/QgisModelBaker/gui/topping_wizard/layer_style_categories.py
index 6223c27a3..c5a0cae87 100644
--- a/QgisModelBaker/gui/topping_wizard/layer_style_categories.py
+++ b/QgisModelBaker/gui/topping_wizard/layer_style_categories.py
@@ -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):
diff --git a/QgisModelBaker/gui/topping_wizard/layers_page.py b/QgisModelBaker/gui/topping_wizard/layers_page.py
index 4b57f51a5..34ff0f4a6 100644
--- a/QgisModelBaker/gui/topping_wizard/layers_page.py
+++ b/QgisModelBaker/gui/topping_wizard/layers_page.py
@@ -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)
@@ -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)):
@@ -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
@@ -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))
diff --git a/QgisModelBaker/gui/topping_wizard/models_page.py b/QgisModelBaker/gui/topping_wizard/models_page.py
index e16363224..09fcbdc88 100644
--- a/QgisModelBaker/gui/topping_wizard/models_page.py
+++ b/QgisModelBaker/gui/topping_wizard/models_page.py
@@ -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(
diff --git a/QgisModelBaker/ui/topping_wizard/layer_style_categories.ui b/QgisModelBaker/ui/topping_wizard/layer_style_categories.ui
index 74547bb43..ad5eaee26 100644
--- a/QgisModelBaker/ui/topping_wizard/layer_style_categories.ui
+++ b/QgisModelBaker/ui/topping_wizard/layer_style_categories.ui
@@ -14,7 +14,10 @@
Layer Style Categories
- -
+
-
+
+
+ -
Ok
@@ -24,7 +27,7 @@
- -
+
-
Qt::Horizontal
@@ -34,12 +37,15 @@
- -
-
+
-
+
+
+ Select all
+
+
-
SpaceCheckListView
@@ -47,8 +53,12 @@
QgisModelBaker.utils.gui_utils
1
+
+ SemiTristateCheckbox
+ QWidget
+ QgisModelBaker.utils.gui_utils
+
-
diff --git a/QgisModelBaker/utils/gui_utils.py b/QgisModelBaker/utils/gui_utils.py
index d33f07be6..8614524b5 100644
--- a/QgisModelBaker/utils/gui_utils.py
+++ b/QgisModelBaker/utils/gui_utils.py
@@ -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 = []):
@@ -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):
"""
@@ -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):