Skip to content

Commit

Permalink
Merge pull request #798 from opengisch/exportmodels
Browse files Browse the repository at this point in the history
Graphical user interface to pass `--exportModels` to ili2db on export or validation.
  • Loading branch information
signedav authored Apr 7, 2023
2 parents eb260c3 + c9fbb7d commit e2c702c
Show file tree
Hide file tree
Showing 12 changed files with 338 additions and 58 deletions.
76 changes: 76 additions & 0 deletions QgisModelBaker/gui/panel/export_models_panel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
"""
/***************************************************************************
begin : 22.11.2021
git sha : :%H$
copyright : (C) 2021 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.PyQt.QtWidgets import QWidget

import QgisModelBaker.utils.gui_utils as gui_utils
from QgisModelBaker.utils import gui_utils

WIDGET_UI = gui_utils.get_ui_class("export_models_panel.ui")


# could be renamed since it's not only model - it's dataset and basket as well
class ExportModelsPanel(QWidget, WIDGET_UI):
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.setupUi(self)
self.parent = parent

def setup_dialog(self, validation=False):
self._generate_texts(validation)
self.export_models_checkbox.setChecked(False)
self.items_view.setVisible(False)
if self.parent:
self.items_view.setModel(self.parent.current_export_models_model)
self.items_view.clicked.connect(self.items_view.model().check)
self.items_view.space_pressed.connect(self.items_view.model().check)

self.export_models_checkbox.setChecked(
self.parent.current_export_models_active
)
self.export_models_checkbox.stateChanged.connect(self._active_state_changed)
self._active_state_changed(self.parent.current_export_models_active)

def _generate_texts(self, validation):
self.export_models_checkbox.setText(
self.tr(
"{verb} the data in a model other than the one where it is stored"
).format(verb="Validate" if validation else "Export")
)
self.export_models_checkbox.setToolTip(
self.tr(
"""
<html><head/><body>
<p>If your data is in the format of the cantonal model, but you want to {verb} it in the format of the national model.</p>
<p>The data that cannot be {pastverb} in the selected model is {pastverb} in the model it is stored.</p>
<p>Usually, this is one single model. However, it is also possible to pass multiple models, which makes sense if there are multiple base models in the schema you want to {verb}.</p>
<p>This is the value passed to <span style=" font-family:'monospace';">--exportModels</span></p>
</body></html>
"""
).format(
verb="validate" if validation else "export",
pastverb="validated" if validation else "exported",
)
)

def _active_state_changed(self, checked):
self.items_view.setVisible(checked)
if not checked:
# on uncheck disable all
self.items_view.model().check_all([])
self.parent.current_export_models_active = checked
65 changes: 55 additions & 10 deletions QgisModelBaker/gui/panel/session_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __init__(
models,
datasets,
baskets,
export_models,
db_action_type,
parent=None,
):
Expand All @@ -68,6 +69,7 @@ def __init__(
self.models = models
self.datasets = datasets
self.baskets = baskets
self.export_models = export_models

# set up the gui
self.create_text = self.tr("Run")
Expand Down Expand Up @@ -109,27 +111,70 @@ def __init__(
if os.path.isfile(self.file):
self.configuration.ilifile = self.file
self.configuration.ilimodels = ";".join(self.models)
self.info_label.setText(self.tr("Import {}").format(", ".join(self.models)))
self.info_label.setText(
self.tr(
"""
<html><head/><body>
<p>Import <b>{models}</b></p>
</body></html>
"""
).format(models=", ".join(self.models))
)
elif self.db_action_type == DbActionType.IMPORT_DATA:
self.configuration.xtffile = self.file
self.configuration.ilimodels = ";".join(self.models)
self.configuration.with_importtid = self._get_tid_handling()
self.info_label.setText(
self.tr("Import {} of {}").format(", ".join(self.models), self.file)
)
if self.datasets:

self.info_label.setText(
self.tr(
"""
<html><head/><body>
<p>Update the data in dataset <b>{dataset}</b></p>
<p>with the data from <i>{file}</i></p>
</body></html>
"""
).format(dataset=self.datasets[0], file=self.file)
)
else:
self.info_label.setText(
self.tr(
"""
<html><head/><body>
<p>Import the data from <i>{file}</i></p>
</body></html>
"""
).format(file=self.file)
)

self.configuration.dataset = self.datasets[0] if self.datasets else None
elif self.db_action_type == DbActionType.EXPORT:
self.configuration.xtffile = self.file
self.configuration.ilimodels = ";".join(self.models)
self.configuration.with_exporttid = self._get_tid_handling()
self.configuration.iliexportmodels = ";".join(self.export_models)
self.info_label.setText(
self.tr('Export of "{}" \nto {}').format(
'", "'.join(self.models)
or '", "'.join(self.datasets)
or '", "'.join(self.baskets),
self.file,
self.tr(
"""
<html><head/><body>
<p>Export the data of <b>{filtered_data}</b></p>
{export_model_part}
<p>to file <i>{file}</i></p>
</body></html>
"""
).format(
filtered_data=", ".join(self.models)
or ", ".join(self.datasets)
or ", ".join(self.baskets),
export_model_part=self.tr(
"<p>in the format of <b>{export_models}</b></p>"
).format(export_models=", ".join(self.export_models))
if self.export_models
else "",
file=self.file,
)
)

self.configuration.ilimodels = ";".join(self.models)
self.configuration.dataset = ";".join(self.datasets)
self.configuration.baskets = self.baskets

Expand Down
25 changes: 25 additions & 0 deletions QgisModelBaker/gui/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from qgis.PyQt.QtWidgets import QAction, QDockWidget, QFileDialog, QHeaderView, QMenu

import QgisModelBaker.libs.modelbaker.utils.db_utils as db_utils
from QgisModelBaker.gui.panel.export_models_panel import ExportModelsPanel
from QgisModelBaker.gui.panel.filter_data_panel import FilterDataPanel
from QgisModelBaker.libs.modelbaker.db_factory.db_simple_factory import DbSimpleFactory
from QgisModelBaker.libs.modelbaker.iliwrapper import ilivalidator
Expand Down Expand Up @@ -105,6 +106,7 @@ def __init__(self):
self.models_model = SchemaModelsModel()
self.datasets_model = SchemaDatasetsModel()
self.baskets_model = SchemaBasketsModel()
self.export_models_model = SchemaModelsModel()
self.result_model = None

def __init__(self, base_config, iface):
Expand All @@ -125,10 +127,16 @@ def __init__(self, base_config, iface):
self.current_datasets_model = SchemaDatasetsModel()
self.current_baskets_model = SchemaBasketsModel()
self.current_filter_mode = SchemaDataFilterMode.NO_FILTER
self.current_export_models_model = SchemaModelsModel()
self.current_export_models_active = False

self.filter_data_panel = FilterDataPanel(self)
self.filter_data_panel.setMaximumHeight(self.fontMetrics().lineSpacing() * 10)
self.filter_layout.addWidget(self.filter_data_panel)

self.export_models_panel = ExportModelsPanel(self)
self.export_models_panel.setMaximumHeight(self.fontMetrics().lineSpacing() * 10)
self.export_models_layout.addWidget(self.export_models_panel)
self._reset_gui()

self.run_button.clicked.connect(self._run)
Expand Down Expand Up @@ -161,6 +169,8 @@ def _reset_current_values(self):
self.current_datasets_model = SchemaDatasetsModel()
self.current_baskets_model = SchemaBasketsModel()
self.current_filter_mode = SchemaDataFilterMode.NO_FILTER
self.current_export_models_model = SchemaModelsModel()
self.current_export_models_active = False

def _reset_gui(self):
self._reset_current_values()
Expand Down Expand Up @@ -253,7 +263,12 @@ def set_current_layer(self, layer):
self.current_baskets_model = self.schema_validations[
self.current_schema_identificator
].baskets_model
self.current_export_models_model = self.schema_validations[
self.current_schema_identificator
].export_models_model

self.filter_data_panel.setup_dialog(self._basket_handling())
self.export_models_panel.setup_dialog(True)
self.setDisabled(False)

def _visibility_changed(self, visible):
Expand All @@ -271,6 +286,9 @@ def _refresh_schemadata_models(self):
self.schema_validations[
self.current_schema_identificator
].baskets_model.refresh_model(db_connector)
self.schema_validations[
self.current_schema_identificator
].export_models_model.refresh_model([db_connector])
return

def _basket_handling(self):
Expand Down Expand Up @@ -317,6 +335,13 @@ def _run(self, edited_command=None):
self.current_models_model.stringList()
)

if self.current_export_models_active:
validator.configuration.iliexportmodels = ";".join(
self.current_export_models_model.checked_entries()
)
else:
validator.configuration.iliexportmodels = ""

validator.configuration.skip_geometry_errors = (
self.skip_geometry_errors_check_box.isChecked()
)
Expand Down
8 changes: 8 additions & 0 deletions QgisModelBaker/gui/workflow_wizard/execution_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,19 @@ def setup_sessions(self, configuration, sessions):
)
baskets = sessions[key]["baskets"] if "baskets" in sessions[key] else None

export_models = (
sessions[key]["export_models"]
if "export_models" in sessions[key]
else None
)

skipped_session_widget = self._find_skipped_session_widget(
(
key,
models,
datasets,
baskets,
export_models,
db_utils.get_schema_identificator_from_configuration(configuration),
)
)
Expand All @@ -115,6 +122,7 @@ def setup_sessions(self, configuration, sessions):
models,
datasets,
baskets,
export_models,
self.db_action_type,
)
session.on_done_or_skipped.connect(self._on_done_or_skipped_received)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from qgis.PyQt.QtWidgets import QWizardPage

import QgisModelBaker.utils.gui_utils as gui_utils
from QgisModelBaker.gui.panel.export_models_panel import ExportModelsPanel
from QgisModelBaker.gui.panel.filter_data_panel import FilterDataPanel
from QgisModelBaker.libs.modelbaker.utils.qt_utils import (
FileValidator,
Expand All @@ -45,6 +46,9 @@ def __init__(self, parent, title):
self.filter_data_panel = FilterDataPanel(self.workflow_wizard)
self.filter_layout.addWidget(self.filter_data_panel)

self.export_models_panel = ExportModelsPanel(self.workflow_wizard)
self.export_models_layout.addWidget(self.export_models_panel)

self.is_complete = False

self.xtf_file_browse_button.clicked.connect(
Expand Down Expand Up @@ -84,6 +88,7 @@ def nextId(self):

def setup_dialog(self, basket_handling):
self.filter_data_panel.setup_dialog(basket_handling)
self.export_models_panel.setup_dialog()

def _set_current_export_target(self, text):
self.setComplete(
Expand Down
10 changes: 10 additions & 0 deletions QgisModelBaker/gui/workflow_wizard/workflow_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ def __init__(self, iface, base_config, parent):
self.current_export_target = ""
self.current_filter_mode = SchemaDataFilterMode.NO_FILTER

# the current_export_models_model keeps every single model found in the current database and keeps the selected models
self.current_export_models_model = SchemaModelsModel()
self.current_export_models_active = False

# pages setup
self.intro_page = IntroPage(self, self._current_page_title(PageIds.Intro))
self.source_selection_page = ImportSourceSelectionPage(
Expand Down Expand Up @@ -345,6 +349,7 @@ def id_changed(self, new_id):
models = []
datasets = []
baskets = []
export_models = []
if self.current_filter_mode == SchemaDataFilterMode.MODEL:
models = self.current_models_model.checked_entries()
elif self.current_filter_mode == SchemaDataFilterMode.DATASET:
Expand All @@ -355,9 +360,13 @@ def id_changed(self, new_id):
# no filter - export all models
models = self.current_models_model.stringList()

if self.current_export_models_active:
export_models = self.current_export_models_model.checked_entries()

sessions[self.current_export_target]["models"] = models
sessions[self.current_export_target]["datasets"] = datasets
sessions[self.current_export_target]["baskets"] = baskets
sessions[self.current_export_target]["export_models"] = export_models

self.export_data_execution_page.setup_sessions(
self.export_data_configuration, sessions
Expand Down Expand Up @@ -413,6 +422,7 @@ def refresh_export_models(self):
self.current_models_model.refresh_model([db_connector])
self.current_datasets_model.refresh_model(db_connector)
self.current_baskets_model.refresh_model(db_connector)
self.current_export_models_model.refresh_model([db_connector])
return

def refresh_import_models(self, silent=False):
Expand Down
Loading

0 comments on commit e2c702c

Please sign in to comment.