Skip to content

Commit

Permalink
Merge pull request #855 from opengisch/toppinglayer-identificator-docs
Browse files Browse the repository at this point in the history
UsabILItyHub: Filter Toppings according to the Database Source
  • Loading branch information
signedav authored Dec 1, 2023
2 parents 7749b69 + 9431e78 commit f042415
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 47 deletions.
39 changes: 37 additions & 2 deletions QgisModelBaker/gui/topping_wizard/models_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,27 @@ def validatePage(self) -> bool:
self.tr("No models set."),
gui_utils.LogColor.COLOR_SUCCESS,
)
self.topping_wizard.topping.preferred_datasource = (
self.source_combobox.currentData()
)
return super().validatePage()

def _refresh(self):
self._load_available_models()
self._load_available_models_and_sources()
self.models_model.check_entries(self.topping_wizard.topping.models)

def _load_available_models(self):
def _load_available_models_and_sources(self):
"""
Collects all the available sources in the project and makes the models_model to refresh accordingly.
"""
checked_identificators = []
db_connectors = []
sources = set()

for layer in QgsProject.instance().mapLayers().values():
if layer.type() == QgsMapLayer.VectorLayer:
source_provider = layer.dataProvider()
self._append_possible_sources(sources, source_provider)
schema_identificator = (
db_utils.get_schema_identificator_from_sourceprovider(
source_provider
Expand All @@ -101,3 +107,32 @@ def _load_available_models(self):
if db_connector:
db_connectors.append(db_connector)
self.models_model.refresh_model(db_connectors)

self._refresh_source_combobox(sources)

def _append_possible_sources(self, sources, provider):
if provider.name() == "postgres":
sources.add("pg")
elif provider.name() == "mssql":
sources.add("mssql")
elif provider.name() == "ogr" and provider.storageType() == "GPKG":
sources.add("gpkg")

def _refresh_source_combobox(self, sources):
display_map = {"pg": "PostGIS", "gpkg": "GeoPackage", "mssql": "MSSQL"}

self.source_combobox.clear()
for source in list(sources):
self.source_combobox.addItem(display_map[source], source)

none_text = self.tr("No source defined (allow all)")

self.source_combobox.addItem(none_text, None)

if len(sources) == 1:
# it's clear which one we take
self.source_combobox.setCurrentText(display_map[list(sources)[0]])
else:
# no sources or it's not clear which one
self.source_combobox.setCurrentText(none_text)
self.source_combobox.setEnabled(bool(sources))
4 changes: 2 additions & 2 deletions QgisModelBaker/gui/topping_wizard/referencedata_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import QgisModelBaker.utils.gui_utils as gui_utils
from QgisModelBaker.libs.modelbaker.iliwrapper.ilicache import (
IliDataCache,
IliDataFileCompleterDelegate,
IliDataItemModel,
MetaConfigCompleterDelegate,
)
from QgisModelBaker.libs.modelbaker.utils.qt_utils import (
FileValidator,
Expand Down Expand Up @@ -76,7 +76,7 @@ def __init__(self, parent, title):
self.topping_wizard.log_panel.show_message
)

self.ilireferencedata_delegate = MetaConfigCompleterDelegate()
self.ilireferencedata_delegate = IliDataFileCompleterDelegate()
self.input_line_edit.setPlaceholderText(
self.tr("[Search referenced data files from Repositories or Local System]")
)
Expand Down
2 changes: 1 addition & 1 deletion QgisModelBaker/gui/topping_wizard/topping_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def _current_page_title(self, id):
if id == ToppingWizardPageIds.Target:
return self.tr("Target Folder Selection")
elif id == ToppingWizardPageIds.Models:
return self.tr("Model Selection")
return self.tr("Model and Source Selection")
elif id == ToppingWizardPageIds.Layers:
return self.tr("Layer Configuration")
elif id == ToppingWizardPageIds.Additives:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
import QgisModelBaker.utils.gui_utils as gui_utils
from QgisModelBaker.gui.dataset_manager import DatasetManagerDialog
from QgisModelBaker.libs.modelbaker.iliwrapper.ilicache import (
IliDataFileCompleterDelegate,
IliDataItemModel,
MetaConfigCompleterDelegate,
)
from QgisModelBaker.utils.globals import CATALOGUE_DATASETNAME, DEFAULT_DATASETNAME
from QgisModelBaker.utils.gui_utils import CheckDelegate, LogColor
Expand Down Expand Up @@ -118,7 +118,7 @@ def __init__(self, parent, title):
self.workflow_wizard.ilireferencedatacache.file_download_failed.connect(
self._on_referencedata_failed
)
self.ilireferencedata_delegate = MetaConfigCompleterDelegate()
self.ilireferencedata_delegate = IliDataFileCompleterDelegate()
self.ilireferencedata_line_edit.setPlaceholderText(
self.tr("[Search referenced data files from UsabILIty Hub]")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
from qgis.PyQt.QtWidgets import QCompleter, QWizardPage

from QgisModelBaker.gui.ili2db_options import Ili2dbOptionsDialog
from QgisModelBaker.libs.modelbaker.iliwrapper.globals import DbIliMode
from QgisModelBaker.libs.modelbaker.iliwrapper.ilicache import (
IliDataCache,
IliDataFileCompleterDelegate,
IliDataItemModel,
MetaConfigCompleterDelegate,
)
from QgisModelBaker.utils import gui_utils
from QgisModelBaker.utils.globals import CRS_PATTERNS
Expand Down Expand Up @@ -71,7 +72,7 @@ def __init__(self, parent, title):
self.ilimetaconfigcache = IliDataCache(
self.workflow_wizard.import_schema_configuration.base_configuration
)
self.metaconfig_delegate = MetaConfigCompleterDelegate()
self.metaconfig_delegate = IliDataFileCompleterDelegate()
self.metaconfig = configparser.ConfigParser()
self.current_models = []
self.current_metaconfig_id = None
Expand Down Expand Up @@ -158,8 +159,6 @@ def _update_models_dependent_info(self):
- Calls update of ilireferencedata cache to load referenced
"""
model_list = self.model_list_view.model().checked_models()
if set(model_list) == set(self.current_models):
return
self.current_models = model_list
for pattern, crs in CRS_PATTERNS.items():
if re.search(pattern, ", ".join(model_list)):
Expand All @@ -173,6 +172,11 @@ def _update_ilimetaconfigcache(self):
self.ilimetaconfigcache = IliDataCache(
self.workflow_wizard.import_schema_configuration.base_configuration,
models=";".join(self.model_list_view.model().checked_models()),
datasources=["pg"]
if (self.workflow_wizard.import_schema_configuration.tool & DbIliMode.pg)
else ["gpkg"]
if (self.workflow_wizard.import_schema_configuration.tool & DbIliMode.gpkg)
else None,
)
self.ilimetaconfigcache.file_download_succeeded.connect(
lambda dataset_id, path: self._on_metaconfig_received(path)
Expand Down
25 changes: 5 additions & 20 deletions QgisModelBaker/gui/workflow_wizard/import_source_selection_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,19 @@ def __init__(self, parent, title):
self.workflow_wizard.import_schema_configuration.base_configuration
)
self.model_delegate = ModelCompleterDelegate()
self._refresh_ili_models_cache()
self.input_line_edit.setPlaceholderText(
self.tr("[Browse for file or search model from repository]")
)

# very unhappy about this behavior, but okay for prototype
self.first_time_punched = False
self.input_line_edit.punched.connect(self._first_time_punch)
self.input_line_edit.textChanged.connect(self._complete_models_completer)
self.input_line_edit.punched.connect(self._complete_models_completer)

self.source_list_view.setModel(self.workflow_wizard.source_model)
self.add_button.clicked.connect(self._add_row)
self.remove_button.clicked.connect(self._remove_selected_rows)

self.add_button.setEnabled(self._valid_source())
self.add_button.setEnabled(False)
self.input_line_edit.textChanged.connect(
lambda: self.add_button.setEnabled(self._valid_source())
)
Expand All @@ -106,24 +105,10 @@ def __init__(self, parent, title):
self.clear_cache_button.clicked.connect(self._clear_cache_button_clicked)

def nextId(self):
self._disconnect_punch_slots()
return self.workflow_wizard.next_id()

def _first_time_punch(self):
# might be nicer
self.input_line_edit.punched.disconnect(self._first_time_punch)
self.input_line_edit.textChanged.emit(self.input_line_edit.text())
self.input_line_edit.textChanged.connect(self._complete_models_completer)
self.input_line_edit.punched.connect(self._complete_models_completer)
self.first_time_punched = True

def _disconnect_punch_slots(self):
# might be nicer
if self.first_time_punched:
self.input_line_edit.textChanged.disconnect(self._complete_models_completer)
self.input_line_edit.punched.disconnect(self._complete_models_completer)
self.input_line_edit.punched.connect(self._first_time_punch)
self.first_time_punched = False
def initializePage(self) -> None:
self._refresh_ili_models_cache()

def _refresh_ili_models_cache(self):
self.ilicache.new_message.connect(self.workflow_wizard.log_panel.show_message)
Expand Down
65 changes: 50 additions & 15 deletions QgisModelBaker/ui/topping_wizard/models.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@
<string>Select Files</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="4" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>693</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="description">
<property name="minimumSize">
Expand All @@ -28,8 +41,11 @@
<bold>true</bold>
</font>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Select the type for which this topping should be made or specify none (allow all). This value will be written into the categories and the toppings will be filtered accordingly.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Select the Models of Interest. These are the models on what you will find the metaconfiguration / topping at UsabILIty Hub.</string>
<string>Select the models for which you want to find this topping at UsabILIty Hub.</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
Expand All @@ -39,6 +55,13 @@
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QPushButton" name="refresh_button">
<property name="text">
<string>Refresh</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="SpaceCheckListView" name="items_view" native="true">
<property name="sizePolicy">
Expand All @@ -49,23 +72,35 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QComboBox" name="source_combobox">
<item>
<property name="text">
<string>Allow all sources</string>
</property>
</item>
<item>
<property name="text">
<string>PostGIS</string>
</property>
</item>
<item>
<property name="text">
<string>GeoPackage</string>
</property>
</item>
</widget>
</item>
<item row="2" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>693</width>
<height>20</height>
</size>
<widget class="QLabel" name="source_description">
<property name="toolTip">
<string/>
</property>
</spacer>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="refresh_button">
<property name="text">
<string>Refresh</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Select the database type for which you want to find this topping (or specify none to be visible for all).&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
Expand Down
2 changes: 1 addition & 1 deletion docs/background_info/usabilityhub/technical_concept.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Additional servers/repositories can be linked via the `ilisite.xml`. The `Datase
</DatasetIdx16.Code_>
<DatasetIdx16.Code_>
<!-- Codes können auch generisch sein -->
<value>http://codes.opengis.ch/modelbaker</value>
<value>http://codes.modelbaker.ch/preferredDataSource/gpkg</value>
<!-- müssen aber eine URL sein -->
</DatasetIdx16.Code_>
</categories>
Expand Down

0 comments on commit f042415

Please sign in to comment.