diff --git a/QgisModelBaker/gui/export.py b/QgisModelBaker/gui/export.py
deleted file mode 100644
index 2de3ceaf8..000000000
--- a/QgisModelBaker/gui/export.py
+++ /dev/null
@@ -1,655 +0,0 @@
-"""
-/***************************************************************************
- -------------------
- begin : 30/05/17
- git sha : :%H$
- copyright : (C) 2017 by Germán Carrillo (BSF-Swissphoto)
- email : gcarrillo@linuxmail.org
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * 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. *
- * *
- ***************************************************************************/
-"""
-
-import os
-import os.path
-import re
-import webbrowser
-
-from qgis.core import Qgis
-from qgis.gui import QgsGui, QgsMessageBar
-from qgis.PyQt.QtCore import (
- QCoreApplication,
- QLocale,
- QSettings,
- QStringListModel,
- Qt,
- QTimer,
-)
-from qgis.PyQt.QtGui import QColor, QDesktopServices, QValidator
-from qgis.PyQt.QtWidgets import (
- QAction,
- QDialog,
- QDialogButtonBox,
- QGridLayout,
- QMessageBox,
- QSizePolicy,
-)
-
-from QgisModelBaker.gui.edit_command import EditCommandDialog
-from QgisModelBaker.gui.options import OptionsDialog
-from QgisModelBaker.gui.panel import db_panel_utils
-from QgisModelBaker.libs.modelbaker.db_factory.db_simple_factory import DbSimpleFactory
-from QgisModelBaker.libs.modelbaker.dbconnector.db_connector import DBConnectorError
-from QgisModelBaker.libs.modelbaker.iliwrapper import ili2dbconfig, iliexporter
-from QgisModelBaker.libs.modelbaker.iliwrapper.globals import DbIliMode
-from QgisModelBaker.libs.modelbaker.iliwrapper.ili2dbutils import (
- JavaNotFoundError,
- color_log_text,
-)
-from QgisModelBaker.libs.modelbaker.utils.globals import DbActionType
-from QgisModelBaker.libs.modelbaker.utils.qt_utils import (
- FileValidator,
- OverrideCursor,
- Validators,
- make_save_file_selector,
-)
-from QgisModelBaker.utils import gui_utils
-from QgisModelBaker.utils.globals import displayDbIliMode
-from QgisModelBaker.utils.gui_utils import LogColor
-
-DIALOG_UI = gui_utils.get_ui_class("export.ui")
-
-
-class ExportModels(QStringListModel):
-
- blacklist = [
- "CHBaseEx_MapCatalogue_V1",
- "CHBaseEx_WaterNet_V1",
- "CHBaseEx_Sewage_V1",
- "CHAdminCodes_V1",
- "AdministrativeUnits_V1",
- "AdministrativeUnitsCH_V1",
- "WithOneState_V1",
- "WithLatestModification_V1",
- "WithModificationObjects_V1",
- "GraphicCHLV03_V1",
- "GraphicCHLV95_V1",
- "NonVector_Base_V2",
- "NonVector_Base_V3",
- "NonVector_Base_LV03_V3_1",
- "NonVector_Base_LV95_V3_1",
- "GeometryCHLV03_V1",
- "GeometryCHLV95_V1",
- "InternationalCodes_V1",
- "Localisation_V1",
- "LocalisationCH_V1",
- "Dictionaries_V1",
- "DictionariesCH_V1",
- "CatalogueObjects_V1",
- "CatalogueObjectTrees_V1",
- "AbstractSymbology",
- "CodeISO",
- "CoordSys",
- "GM03_2_1Comprehensive",
- "GM03_2_1Core",
- "GM03_2Comprehensive",
- "GM03_2Core",
- "GM03Comprehensive",
- "GM03Core",
- "IliRepository09",
- "IliSite09",
- "IlisMeta07",
- "IliVErrors",
- "INTERLIS_ext",
- "RoadsExdm2ben",
- "RoadsExdm2ben_10",
- "RoadsExgm2ien",
- "RoadsExgm2ien_10",
- "StandardSymbology",
- "StandardSymbology",
- "Time",
- "Units",
- ]
-
- def __init__(self):
- super().__init__()
- self._checked_models = None
-
- def refresh_models(self, db_connector=None):
- modelnames = list()
-
- if db_connector:
- if db_connector.db_or_schema_exists() and db_connector.metadata_exists():
- db_models = db_connector.get_models()
- regex = re.compile(r"(?:\{[^\}]*\}|\s)")
- for db_model in db_models:
- for modelname in regex.split(db_model["modelname"]):
- if modelname and modelname not in ExportModels.blacklist:
- modelnames.append(modelname.strip())
-
- self.setStringList(modelnames)
-
- self._checked_models = {modelname: Qt.Checked for modelname in modelnames}
-
- def flags(self, index):
- return Qt.ItemIsSelectable | Qt.ItemIsEnabled
-
- def data(self, index, role):
- if role == Qt.CheckStateRole:
- return self._checked_models[self.data(index, Qt.DisplayRole)]
- else:
- return QStringListModel.data(self, index, role)
-
- def setData(self, index, role, data):
- if role == Qt.CheckStateRole:
- self._checked_models[self.data(index, Qt.DisplayRole)] = data
- else:
- QStringListModel.setData(self, index, role, data)
-
- def check(self, index):
- if self.data(index, Qt.CheckStateRole) == Qt.Checked:
- self.setData(index, Qt.CheckStateRole, Qt.Unchecked)
- else:
- self.setData(index, Qt.CheckStateRole, Qt.Checked)
-
- def checked_models(self):
- return [
- modelname
- for modelname in self.stringList()
- if self._checked_models[modelname] == Qt.Checked
- ]
-
-
-class ExportDialog(QDialog, DIALOG_UI):
- ValidExtensions = ["xtf", "XTF", "itf", "ITF", "gml", "GML", "xml", "XML"]
-
- def __init__(self, base_config, parent=None):
- QDialog.__init__(self, parent)
- self.setupUi(self)
- self.db_simple_factory = DbSimpleFactory()
- QgsGui.instance().enableAutoGeometryRestore(self)
- self.buttonBox.accepted.disconnect()
- self.buttonBox.clear()
- self.buttonBox.addButton(QDialogButtonBox.Cancel)
- self.buttonBox.addButton(QDialogButtonBox.Help)
- self.buttonBox.helpRequested.connect(self.help_requested)
-
- self.export_text = self.tr("Export")
- self.set_button_to_export_action = QAction(self.export_text, None)
- self.set_button_to_export_action.triggered.connect(self.set_button_to_export)
-
- self.export_without_validation_text = self.tr("Export without validation")
- self.set_button_to_export_without_validation_action = QAction(
- self.export_without_validation_text, None
- )
- self.set_button_to_export_without_validation_action.triggered.connect(
- self.set_button_to_export_without_validation
- )
-
- self.edit_command_action = QAction(self.tr("Edit ili2db command"), None)
- self.edit_command_action.triggered.connect(self.edit_command)
-
- self.export_tool_button.addAction(
- self.set_button_to_export_without_validation_action
- )
- self.export_tool_button.addAction(self.edit_command_action)
- self.export_tool_button.setText(self.export_text)
- self.export_tool_button.clicked.connect(self.accepted)
-
- self.xtf_file_browse_button.clicked.connect(
- make_save_file_selector(
- self.xtf_file_line_edit,
- title=self.tr("Save in XTF Transfer File"),
- file_filter=self.tr(
- "XTF Transfer File (*.xtf *XTF);;Interlis 1 Transfer File (*.itf *ITF);;XML (*.xml *XML);;GML (*.gml *GML)"
- ),
- extension=".xtf",
- extensions=["." + ext for ext in self.ValidExtensions],
- )
- )
- self.xtf_file_browse_button.clicked.connect(self.xtf_browser_opened_to_true)
- self.xtf_browser_was_opened = False
-
- self.type_combo_box.clear()
- self._lst_panel = dict()
-
- for db_id in self.db_simple_factory.get_db_list(False):
- self.type_combo_box.addItem(displayDbIliMode[db_id], db_id)
- item_panel = db_panel_utils.get_config_panel(
- db_id, self, DbActionType.EXPORT
- )
- self._lst_panel[db_id] = item_panel
- self.db_layout.addWidget(item_panel)
-
- self.validators = Validators()
-
- fileValidator = FileValidator(
- pattern=["*." + ext for ext in self.ValidExtensions],
- allow_non_existing=True,
- )
-
- self.xtf_file_line_edit.setValidator(fileValidator)
- self.xtf_file_line_edit.textChanged.connect(self.validators.validate_line_edits)
- self.xtf_file_line_edit.textChanged.connect(self.xtf_browser_opened_to_false)
- self.xtf_file_line_edit.textChanged.emit(self.xtf_file_line_edit.text())
-
- # Reset to export as default text
- self.xtf_file_line_edit.textChanged.connect(self.set_button_to_export)
-
- # refresh the models on changing values but avoid massive db connects by timer
- self.refreshTimer = QTimer()
- self.refreshTimer.setSingleShot(True)
- self.refreshTimer.timeout.connect(self.refresh_models)
-
- for key, value in self._lst_panel.items():
- value.notify_fields_modified.connect(self.request_for_refresh_models)
-
- self.validate_data = True # validates exported data by default, We use --disableValidation when is False
- self.base_configuration = base_config
- self.restore_configuration()
-
- self.export_models_model = ExportModels()
- self.export_models_view.setModel(self.export_models_model)
- self.export_models_view.clicked.connect(self.export_models_model.check)
- self.export_models_view.space_pressed.connect(self.export_models_model.check)
- self.request_for_refresh_models()
-
- self.type_combo_box.currentIndexChanged.connect(self.type_changed)
-
- self.bar = QgsMessageBar()
- self.bar.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
- self.txtStdout.setLayout(QGridLayout())
- self.txtStdout.layout().setContentsMargins(0, 0, 0, 0)
- self.txtStdout.layout().addWidget(self.bar, 0, 0, Qt.AlignTop)
-
- def request_for_refresh_models(self):
- # hold refresh back
- self.refreshTimer.start(500)
-
- def refresh_models(self):
- self.refreshed_export_models_model()
-
- def refreshed_export_models_model(self):
- tool = self.type_combo_box.currentData() & ~DbIliMode.ili
-
- configuration = self.updated_configuration()
- schema = configuration.dbschema
-
- db_factory = self.db_simple_factory.create_factory(tool)
- config_manager = db_factory.get_db_command_config_manager(configuration)
- uri_string = config_manager.get_uri(configuration.db_use_super_login)
-
- db_connector = None
-
- try:
- db_connector = db_factory.get_db_connector(uri_string, schema)
- except (DBConnectorError, FileNotFoundError):
- # when wrong connection parameters entered, there should just be returned an empty model - so let it pass
- pass
-
- self.export_models_model.refresh_models(db_connector)
-
- def db_ili_version(self, configuration):
- """
- Returns the ili2db version the database has been created with or None if the database
- could not be detected as a ili2db database
- """
- schema = configuration.dbschema
-
- db_factory = self.db_simple_factory.create_factory(configuration.tool)
- config_manager = db_factory.get_db_command_config_manager(configuration)
- uri_string = config_manager.get_uri(configuration.db_use_super_login)
-
- db_connector = None
-
- try:
- db_connector = db_factory.get_db_connector(uri_string, schema)
- return db_connector.ili_version()
- except (DBConnectorError, FileNotFoundError):
- return None
-
- def set_button_to_export(self):
- """
- Changes the text of the button to export (with validation) and sets the validate_data to true.
- So on clicking the button the export will start with validation.
- The buttons actions are changed to be able to switch the without-validation mode.
- """
- self.validate_data = True
- self.export_tool_button.removeAction(self.set_button_to_export_action)
- self.export_tool_button.removeAction(self.edit_command_action)
- self.export_tool_button.addAction(
- self.set_button_to_export_without_validation_action
- )
- self.export_tool_button.addAction(self.edit_command_action)
- self.export_tool_button.setText(self.export_text)
-
- def set_button_to_export_without_validation(self):
- """
- Changes the text of the button to export without validation and sets the validate_data to false.
- So on clicking the button the export will start without validation.
- The buttons actions are changed to be able to switch the with-validation mode.
- """
- self.validate_data = False
- self.export_tool_button.removeAction(
- self.set_button_to_export_without_validation_action
- )
- self.export_tool_button.removeAction(self.edit_command_action)
- self.export_tool_button.addAction(self.set_button_to_export_action)
- self.export_tool_button.addAction(self.edit_command_action)
- self.export_tool_button.setText(self.export_without_validation_text)
-
- def edit_command(self):
- """
- A dialog opens giving the user the possibility to edit the ili2db command used for the export
- """
- exporter = iliexporter.Exporter()
- exporter.tool = self.type_combo_box.currentData()
- exporter.configuration = self.updated_configuration()
- command = exporter.command(True)
- edit_command_dialog = EditCommandDialog(self)
- edit_command_dialog.command_edit.setPlainText(command)
- if edit_command_dialog.exec_():
- edited_command = edit_command_dialog.command_edit.toPlainText()
- self.accepted(edited_command)
-
- def accepted(self, edited_command=None):
- db_id = self.type_combo_box.currentData()
-
- res, message = self._lst_panel[db_id].is_valid()
-
- if not res:
- self.txtStdout.setText(message)
- return
-
- configuration = self.updated_configuration()
-
- if not edited_command:
- if (
- not self.xtf_file_line_edit.validator().validate(
- configuration.xtffile, 0
- )[0]
- == QValidator.Acceptable
- ):
- self.txtStdout.setText(
- self.tr(
- "Please set a valid INTERLIS XTF file before exporting data."
- )
- )
- self.xtf_file_line_edit.setFocus()
- return
- if not configuration.ilimodels:
- self.txtStdout.setText(
- self.tr("Please set a model before exporting data.")
- )
- self.export_models_view.setFocus()
- return
-
- # If xtf browser was opened and the file exists, the user already chose
- # to overwrite the file
- if (
- os.path.isfile(self.xtf_file_line_edit.text().strip())
- and not self.xtf_browser_was_opened
- ):
- self.msg = QMessageBox()
- self.msg.setIcon(QMessageBox.Warning)
- self.msg.setText(
- self.tr(
- "{filename} already exists.\nDo you want to replace it?"
- ).format(
- filename=os.path.basename(self.xtf_file_line_edit.text().strip())
- )
- )
- self.msg.setWindowTitle(self.tr("Save in XTF Transfer File"))
- self.msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
- msg_box = self.msg.exec_()
- if msg_box == QMessageBox.No:
- return
-
- with OverrideCursor(Qt.WaitCursor):
- self.progress_bar.show()
- self.progress_bar.setValue(0)
-
- self.disable()
- self.txtStdout.setTextColor(QColor(LogColor.COLOR_INFO))
- self.txtStdout.clear()
-
- exporter = iliexporter.Exporter()
- exporter.tool = self.type_combo_box.currentData()
- exporter.configuration = configuration
-
- self.save_configuration(configuration)
-
- exporter.stdout.connect(self.print_info)
- exporter.stderr.connect(self.on_stderr)
- exporter.process_started.connect(self.on_process_started)
- exporter.process_finished.connect(self.on_process_finished)
-
- self.progress_bar.setValue(25)
-
- try:
- if exporter.run(edited_command) != iliexporter.Exporter.SUCCESS:
- if configuration.db_ili_version == 3:
- # failed with a db created by ili2db version 3
- if not edited_command:
- # fallback because of issues with --export3 argument
- self.show_message(
- Qgis.Warning,
- self.tr(
- "Tried export with ili2db version 3.x.x (fallback)"
- ),
- )
-
- exporter.version = 3
- # ... and enforce the Exporter to use ili2db version 3.x.x
- if exporter.run() != iliexporter.Exporter.SUCCESS:
- self.enable()
- self.progress_bar.hide()
- return
- else:
- self.show_message(
- Qgis.Warning,
- self.tr(
- "Tried export with ili2db version 3.x.x (no fallback with editted command)"
- ),
- )
- return
- else:
- self.enable()
- self.progress_bar.hide()
- return
- except JavaNotFoundError as e:
- self.txtStdout.setTextColor(QColor(LogColor.COLOR_INFO))
- self.txtStdout.clear()
- self.txtStdout.setText(e.error_string)
- self.enable()
- self.progress_bar.hide()
-
- QApplication.restoreOverrideCursor()
- QMessageBox.critical(
- self, self.tr("Java not found error"), e.error_string
- )
-
- return
-
- self.buttonBox.clear()
- self.buttonBox.setEnabled(True)
- self.buttonBox.addButton(QDialogButtonBox.Close)
- self.progress_bar.setValue(100)
-
- def print_info(self, text):
- self.txtStdout.setTextColor(QColor(LogColor.COLOR_INFO))
- self.txtStdout.append(text)
- QCoreApplication.processEvents()
-
- def on_stderr(self, text):
- color_log_text(text, self.txtStdout)
- self.advance_progress_bar_by_text(text)
- QCoreApplication.processEvents()
-
- def show_message(self, level, message):
- if level == Qgis.Warning:
- self.bar.pushMessage(message, Qgis.Info, 10)
- elif level == Qgis.Critical:
- self.bar.pushMessage(message, Qgis.Warning, 10)
-
- def on_process_started(self, command):
- self.disable()
- self.txtStdout.setTextColor(QColor(LogColor.COLOR_INFO))
- self.txtStdout.clear()
- self.txtStdout.setText(command)
- QCoreApplication.processEvents()
-
- def on_process_finished(self, exit_code, result):
- color = "#004905" if exit_code == 0 else "#aa2222"
- self.txtStdout.setTextColor(QColor(color))
- self.txtStdout.append(self.tr("Finished ({})".format(exit_code)))
- if result == iliexporter.Exporter.SUCCESS:
- self.buttonBox.clear()
- self.buttonBox.setEnabled(True)
- self.buttonBox.addButton(QDialogButtonBox.Close)
- else:
- if self.export_without_validate():
- self.set_button_to_export_without_validation()
- self.enable()
-
- def export_without_validate(self):
- """
- Valid if an error occurred that prevents executing the export without validations
- :return: True if you can execute the export without validations, False in other case
- """
- log = self.txtStdout.toPlainText().lower()
- if "permission denied" in log or "access is denied" in log:
- return False
- return True
-
- def updated_configuration(self):
- """
- Get the configuration that is updated with the user configuration changes on the dialog.
- :return: Configuration
- """
- configuration = ili2dbconfig.ExportConfiguration()
-
- mode = self.type_combo_box.currentData()
- self._lst_panel[mode].get_fields(configuration)
-
- configuration.tool = mode
- configuration.xtffile = self.xtf_file_line_edit.text().strip()
- configuration.ilimodels = ";".join(self.export_models_model.checked_models())
- configuration.base_configuration = self.base_configuration
- configuration.db_ili_version = self.db_ili_version(configuration)
-
- if not self.validate_data:
- configuration.disable_validation = True
- return configuration
-
- def save_configuration(self, configuration):
- settings = QSettings()
- settings.setValue("QgisModelBaker/ili2pg/xtffile_export", configuration.xtffile)
- settings.setValue(
- "QgisModelBaker/importtype", self.type_combo_box.currentData().name
- )
-
- mode = self.type_combo_box.currentData()
- db_factory = self.db_simple_factory.create_factory(mode)
- config_manager = db_factory.get_db_command_config_manager(configuration)
- config_manager.save_config_in_qsettings()
-
- def restore_configuration(self):
- settings = QSettings()
-
- for db_id in self.db_simple_factory.get_db_list(False):
- configuration = iliexporter.ExportConfiguration()
- db_factory = self.db_simple_factory.create_factory(db_id)
- config_manager = db_factory.get_db_command_config_manager(configuration)
- config_manager.load_config_from_qsettings()
- self._lst_panel[db_id].set_fields(configuration)
-
- mode = settings.value("QgisModelBaker/importtype")
- mode = DbIliMode[mode] if mode else self.db_simple_factory.default_database
- mode = mode & ~DbIliMode.ili
-
- self.type_combo_box.setCurrentIndex(self.type_combo_box.findData(mode))
- self.refresh_db_panel()
-
- def disable(self):
- self.type_combo_box.setEnabled(False)
- for key, value in self._lst_panel.items():
- value.setEnabled(False)
- self.ili_config.setEnabled(False)
- self.buttonBox.setEnabled(False)
-
- def enable(self):
- self.type_combo_box.setEnabled(True)
- for key, value in self._lst_panel.items():
- value.setEnabled(True)
- self.ili_config.setEnabled(True)
- self.buttonBox.setEnabled(True)
-
- def type_changed(self):
- self.txtStdout.clear()
- self.set_button_to_export()
- self.refresh_db_panel()
- self.refresh_models()
- self.txtStdout.clear()
-
- def refresh_db_panel(self):
- self.progress_bar.hide()
-
- db_id = self.type_combo_box.currentData()
- self.db_wrapper_group_box.setTitle(displayDbIliMode[db_id])
-
- # Refresh panels
- for key, value in self._lst_panel.items():
- value.interlis_mode = False
- is_current_panel_selected = db_id == key
- value.setVisible(is_current_panel_selected)
- if is_current_panel_selected:
- value._show_panel()
-
- def link_activated(self, link):
- if link.url() == "#configure":
- cfg = OptionsDialog(self.base_configuration)
- if cfg.exec_():
- settings = QSettings()
- settings.beginGroup("QgisModelBaker/ili2db")
- self.base_configuration.save(settings)
- else:
- QDesktopServices.openUrl(link)
-
- def help_requested(self):
- os_language = QLocale(QSettings().value("locale/userLocale")).name()[:2]
- if os_language in ["es", "de"]:
- webbrowser.open(
- "https://opengisch.github.io/QgisModelBaker/docs/{}/user-guide.html#export-an-interlis-transfer-file-xtf".format(
- os_language
- )
- )
- else:
- webbrowser.open(
- "https://opengisch.github.io/QgisModelBaker/docs/user-guide.html#export-an-interlis-transfer-file-xtf"
- )
-
- def xtf_browser_opened_to_true(self):
- """
- Slot. Sets a flag to true to eventually avoid asking a user whether to overwrite a file.
- """
- self.xtf_browser_was_opened = True
-
- def xtf_browser_opened_to_false(self):
- """
- Slot. Sets a flag to false to eventually ask a user whether to overwrite a file.
- """
- self.xtf_browser_was_opened = False
-
- def advance_progress_bar_by_text(self, text):
- if text.strip() == "Info: compile models…":
- self.progress_bar.setValue(50)
- elif text.strip() == "Info: create table structure…":
- self.progress_bar.setValue(75)
diff --git a/QgisModelBaker/gui/generate_project.py b/QgisModelBaker/gui/generate_project.py
deleted file mode 100644
index c45960f66..000000000
--- a/QgisModelBaker/gui/generate_project.py
+++ /dev/null
@@ -1,1355 +0,0 @@
-"""
-/***************************************************************************
- -------------------
- begin : 29/03/17
- git sha : :%H$
- copyright : (C) 2017 by OPENGIS.ch
- email : info@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. *
- * *
- ***************************************************************************/
-"""
-import configparser
-import os
-import re
-import webbrowser
-
-import yaml
-from qgis.core import Qgis, QgsCoordinateReferenceSystem, QgsProject
-from qgis.gui import QgsGui, QgsMessageBar
-from qgis.PyQt.QtCore import (
- QCoreApplication,
- QEventLoop,
- QLocale,
- QSettings,
- Qt,
- QTimer,
-)
-from qgis.PyQt.QtGui import QColor, QDesktopServices, QValidator
-from qgis.PyQt.QtWidgets import (
- QAction,
- QCompleter,
- QDialog,
- QDialogButtonBox,
- QGridLayout,
- QMessageBox,
- QSizePolicy,
-)
-
-from QgisModelBaker.gui.edit_command import EditCommandDialog
-from QgisModelBaker.gui.ili2db_options import Ili2dbOptionsDialog
-from QgisModelBaker.gui.multiple_models import MultipleModelsDialog
-from QgisModelBaker.gui.options import OptionsDialog
-from QgisModelBaker.gui.panel import db_panel_utils
-from QgisModelBaker.libs.modelbaker.dataobjects.project import Project
-from QgisModelBaker.libs.modelbaker.db_factory.db_simple_factory import DbSimpleFactory
-from QgisModelBaker.libs.modelbaker.dbconnector.db_connector import DBConnectorError
-from QgisModelBaker.libs.modelbaker.generator.generator import Generator
-from QgisModelBaker.libs.modelbaker.iliwrapper import iliimporter
-from QgisModelBaker.libs.modelbaker.iliwrapper.globals import DbIliMode
-from QgisModelBaker.libs.modelbaker.iliwrapper.ili2dbconfig import (
- ImportDataConfiguration,
- SchemaImportConfiguration,
-)
-from QgisModelBaker.libs.modelbaker.iliwrapper.ili2dbutils import (
- JavaNotFoundError,
- color_log_text,
-)
-from QgisModelBaker.libs.modelbaker.iliwrapper.ilicache import (
- IliCache,
- IliDataCache,
- IliDataItemModel,
- IliToppingFileCache,
- IliToppingFileItemModel,
- MetaConfigCompleterDelegate,
- ModelCompleterDelegate,
-)
-from QgisModelBaker.libs.modelbaker.utils.globals import DbActionType
-from QgisModelBaker.libs.modelbaker.utils.qt_utils import (
- FileValidator,
- NonEmptyStringValidator,
- OverrideCursor,
- Validators,
- make_file_selector,
-)
-from QgisModelBaker.utils import gui_utils
-from QgisModelBaker.utils.globals import (
- CATALOGUE_DATASETNAME,
- CRS_PATTERNS,
- displayDbIliMode,
-)
-from QgisModelBaker.utils.gui_utils import LogColor
-
-DIALOG_UI = gui_utils.get_ui_class("generate_project.ui")
-
-
-class GenerateProjectDialog(QDialog, DIALOG_UI):
-
- ValidExtensions = ["ili"]
-
- def __init__(self, iface, base_config, parent=None):
- QDialog.__init__(self, parent)
- self.setupUi(self)
- self.iface = iface
- self.db_simple_factory = DbSimpleFactory()
- QgsGui.instance().enableAutoGeometryRestore(self)
-
- self.create_text = self.tr("Create")
- self.set_button_to_create_action = QAction(self.create_text, None)
- self.set_button_to_create_action.triggered.connect(self.set_button_to_create)
-
- self.create_without_constraints_text = self.tr("Create without constraints")
- self.set_button_to_create_without_constraints_action = QAction(
- self.create_without_constraints_text, None
- )
- self.set_button_to_create_without_constraints_action.triggered.connect(
- self.set_button_to_create_without_constraints
- )
-
- self.edit_command_action = QAction(self.tr("Edit ili2db command"), None)
- self.edit_command_action.triggered.connect(self.edit_command)
-
- self.create_tool_button.addAction(
- self.set_button_to_create_without_constraints_action
- )
- self.create_tool_button.addAction(self.edit_command_action)
- self.create_tool_button.setText(self.create_text)
- self.create_tool_button.clicked.connect(self.accepted)
-
- self.buttonBox.accepted.disconnect()
- self.buttonBox.clear()
- self.buttonBox.addButton(QDialogButtonBox.Cancel)
-
- self.create_constraints = True
-
- self.create_button.setText(self.tr("Create"))
- self.create_button.clicked.connect(self.accepted)
- self.ili_file_browse_button.clicked.connect(
- make_file_selector(
- self.ili_file_line_edit,
- title=self.tr("Open Interlis Model"),
- file_filter=self.tr("Interlis Model File (*.ili *.ILI)"),
- )
- )
- self.buttonBox.addButton(QDialogButtonBox.Help)
- self.buttonBox.helpRequested.connect(self.help_requested)
- self.crs = QgsCoordinateReferenceSystem()
- self.ili2db_options = Ili2dbOptionsDialog(self)
- self.ili2db_options_button.clicked.connect(self.ili2db_options.open)
- self.ili2db_options.finished.connect(self.fill_toml_file_info_label)
- self.multiple_models_dialog = MultipleModelsDialog(self)
- self.multiple_models_button.clicked.connect(self.multiple_models_dialog.open)
- self.multiple_models_dialog.accepted.connect(self.fill_models_line_edit)
-
- self.type_combo_box.clear()
- self._lst_panel = dict()
-
- for db_id in self.db_simple_factory.get_db_list(True):
- self.type_combo_box.addItem(displayDbIliMode[db_id], db_id)
-
- for db_id in self.db_simple_factory.get_db_list(False):
- item_panel = db_panel_utils.get_config_panel(
- db_id, self, DbActionType.GENERATE
- )
- self._lst_panel[db_id] = item_panel
- self.db_layout.addWidget(item_panel)
-
- self.type_combo_box.currentIndexChanged.connect(self.type_changed)
- self.txtStdout.anchorClicked.connect(self.link_activated)
- self.crsSelector.crsChanged.connect(self.crs_changed)
- self.base_configuration = base_config
-
- self.bar = QgsMessageBar()
- self.bar.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
- self.txtStdout.setLayout(QGridLayout())
- self.txtStdout.layout().setContentsMargins(0, 0, 0, 0)
- self.txtStdout.layout().addWidget(self.bar, 0, 0, Qt.AlignTop)
-
- self.validators = Validators()
- nonEmptyValidator = NonEmptyStringValidator()
- fileValidator = FileValidator(
- pattern=["*." + ext for ext in self.ValidExtensions], allow_empty=True
- )
-
- self.restore_configuration()
-
- self.ilimetaconfigcache = IliDataCache(self.base_configuration)
- self.metaconfig_delegate = MetaConfigCompleterDelegate()
- self.metaconfig = configparser.ConfigParser()
- self.current_models = None
- self.current_metaconfig_id = None
- self.ili_metaconfig_line_edit.setPlaceholderText(
- self.tr("[Search metaconfig / topping from UsabILIty Hub]")
- )
- self.ili_metaconfig_line_edit.setEnabled(False)
- completer = QCompleter(
- self.ilimetaconfigcache.model, self.ili_metaconfig_line_edit
- )
- completer.setCaseSensitivity(Qt.CaseInsensitive)
- completer.setFilterMode(Qt.MatchContains)
- completer.popup().setItemDelegate(self.metaconfig_delegate)
- self.ili_metaconfig_line_edit.setCompleter(completer)
- self.ili_metaconfig_line_edit.textChanged.emit(
- self.ili_metaconfig_line_edit.text()
- )
- self.ili_metaconfig_line_edit.textChanged.connect(
- self.complete_metaconfig_completer
- )
- self.ili_metaconfig_line_edit.punched.connect(
- self.complete_metaconfig_completer
- )
- self.ili_metaconfig_line_edit.textChanged.connect(
- self.on_metaconfig_completer_activated
- )
-
- self.ili_models_line_edit.setValidator(nonEmptyValidator)
- self.ili_file_line_edit.setValidator(fileValidator)
-
- self.ili_models_line_edit.textChanged.connect(
- self.validators.validate_line_edits
- )
- self.ili_models_line_edit.textChanged.emit(self.ili_models_line_edit.text())
- self.ili_models_line_edit.textChanged.connect(self.on_model_changed)
- self.ili_models_line_edit.textChanged.connect(self.complete_models_completer)
- self.ili_models_line_edit.punched.connect(self.complete_models_completer)
-
- self.ilicache = IliCache(self.base_configuration)
- self.model_delegate = ModelCompleterDelegate()
- self.refresh_ili_models_cache()
- self.ili_models_line_edit.setPlaceholderText(
- self.tr("[Search model from repository]")
- )
-
- self.ili_file_line_edit.textChanged.connect(self.validators.validate_line_edits)
- self.ili_file_line_edit.textChanged.connect(self.ili_file_changed)
- self.ili_file_line_edit.textChanged.emit(self.ili_file_line_edit.text())
-
- def set_button_to_create(self):
- """
- Changes the text of the button to create (with validation) and sets the validate_data to true.
- So on clicking the button the creation will start with validation.
- The buttons actions are changed to be able to switch the with-validation mode.
- """
- self.create_constraints = True
- self.create_tool_button.removeAction(self.set_button_to_create_action)
- self.create_tool_button.removeAction(self.edit_command_action)
- self.create_tool_button.addAction(
- self.set_button_to_create_without_constraints_action
- )
- self.create_tool_button.addAction(self.edit_command_action)
- self.create_tool_button.setText(self.create_text)
-
- def set_button_to_create_without_constraints(self):
- """
- Changes the text of the button to create without validation and sets the validate_data to false.
- So on clicking the button the creation will start without validation.
- The buttons actions are changed to be able to switch the with-validation mode.
- """
- self.create_constraints = False
- self.create_tool_button.removeAction(
- self.set_button_to_create_without_constraints_action
- )
- self.create_tool_button.removeAction(self.edit_command_action)
- self.create_tool_button.addAction(self.set_button_to_create_action)
- self.create_tool_button.addAction(self.edit_command_action)
- self.create_tool_button.setText(self.create_without_constraints_text)
-
- def edit_command(self):
- """
- A dialog opens giving the user the possibility to edit the ili2db command used for the creation
- """
- importer = iliimporter.Importer()
- importer.tool = self.type_combo_box.currentData()
- importer.configuration = self.updated_configuration()
- command = importer.command(True)
- edit_command_dialog = EditCommandDialog(self)
- edit_command_dialog.command_edit.setPlainText(command)
- if edit_command_dialog.exec_():
- edited_command = edit_command_dialog.command_edit.toPlainText()
- self.accepted(edited_command)
-
- def accepted(self, edited_command=None):
- ili_mode = self.type_combo_box.currentData()
- db_id = ili_mode & ~DbIliMode.ili
- interlis_mode = ili_mode & DbIliMode.ili
-
- res, message = self._lst_panel[db_id].is_valid()
-
- if not res:
- self.txtStdout.setText(message)
- return
-
- configuration = self.updated_configuration()
-
- if not edited_command:
- if interlis_mode:
- if not self.ili_file_line_edit.text().strip():
- if not self.ili_models_line_edit.text().strip():
- self.txtStdout.setText(
- self.tr(
- "Please set a valid INTERLIS model before creating the project."
- )
- )
- self.ili_models_line_edit.setFocus()
- return
-
- if (
- self.ili_file_line_edit.text().strip()
- and self.ili_file_line_edit.validator().validate(
- configuration.ilifile, 0
- )[0]
- != QValidator.Acceptable
- ):
-
- self.txtStdout.setText(
- self.tr(
- "Please set a valid INTERLIS file before creating the project. {}"
- ).format(self.ili_file_line_edit.validator().error)
- )
- self.ili_file_line_edit.setFocus()
- return
-
- configuration.dbschema = configuration.dbschema or configuration.database
- self.save_configuration(configuration)
-
- db_factory = self.db_simple_factory.create_factory(db_id)
-
- try:
- # raise warning when the schema or the database file already exists
- config_manager = db_factory.get_db_command_config_manager(configuration)
- db_connector = db_factory.get_db_connector(
- config_manager.get_uri(configuration.db_use_super_login)
- or config_manager.get_uri(),
- configuration.dbschema,
- )
-
- if db_connector.db_or_schema_exists():
- if interlis_mode:
- warning_box = QMessageBox(self)
- warning_box.setIcon(QMessageBox.Information)
- warning_title = (
- self.tr("{} already exists")
- .format(db_factory.get_specific_messages()["db_or_schema"])
- .capitalize()
- )
- warning_box.setWindowTitle(warning_title)
- warning_box.setText(
- self.tr(
- "{warning_title}:\n{db_or_schema_name}\n\nDo you want to "
- "import into the existing {db_or_schema}?"
- ).format(
- warning_title=warning_title,
- db_or_schema=db_factory.get_specific_messages()[
- "db_or_schema"
- ].capitalize(),
- db_or_schema_name=configuration.dbschema
- or config_manager.get_uri(),
- )
- )
- warning_box.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
- warning_box_result = warning_box.exec_()
- if warning_box_result == QMessageBox.No:
- return
- except (DBConnectorError, FileNotFoundError):
- # we don't mind when the database file is not yet created
- pass
-
- # create schema with superuser
- res, message = db_factory.pre_generate_project(configuration)
- if not res:
- self.txtStdout.setText(message)
- return
-
- with OverrideCursor(Qt.WaitCursor):
- self.progress_bar.show()
- self.progress_bar.setValue(0)
-
- self.disable()
- self.txtStdout.setTextColor(QColor(LogColor.COLOR_INFO))
-
- if interlis_mode:
- importer = iliimporter.Importer()
- importer.tool = self.type_combo_box.currentData()
- importer.configuration = configuration
- importer.stdout.connect(self.print_info)
- importer.stderr.connect(self.on_stderr)
- importer.process_started.connect(self.on_process_started)
- importer.process_finished.connect(self.on_process_finished)
- try:
- if importer.run(edited_command) != iliimporter.Importer.SUCCESS:
- self.enable()
- self.progress_bar.hide()
- return
- except JavaNotFoundError as e:
- self.txtStdout.setTextColor(QColor(LogColor.COLOR_INFO))
- self.txtStdout.clear()
- self.txtStdout.setText(e.error_string)
- self.enable()
- self.progress_bar.hide()
-
- QApplication.restoreOverrideCursor()
- QMessageBox.critical(
- self, self.tr("Java not found error"), e.error_string
- )
-
- return
-
- try:
- config_manager = db_factory.get_db_command_config_manager(configuration)
- uri = config_manager.get_uri(qgis=True)
- mgmt_uri = config_manager.get_uri(configuration.db_use_super_login)
- generator = Generator(
- configuration.tool,
- uri,
- configuration.inheritance,
- configuration.dbschema,
- mgmt_uri=mgmt_uri,
- consider_basket_handling=True,
- )
- generator.stdout.connect(self.print_info)
- generator.new_message.connect(self.show_message)
- self.progress_bar.setValue(30)
- except DBConnectorError as db_connector_error:
- self.txtStdout.setText(
- self.tr(
- "There was an error connecting to the database. Check connection parameters. Error details: {}".format(
- db_connector_error
- )
- )
- )
- self.progress_bar.setValue(0)
- return
- except FileNotFoundError as file_not_found_error:
- self.txtStdout.setText(
- self.tr(
- "There was an error connecting to the database. Check connection parameters. Error details: {}".format(
- file_not_found_error
- )
- )
- )
- self.progress_bar.setValue(0)
- return
-
- if not interlis_mode:
- if not generator.db_or_schema_exists():
- self.txtStdout.setText(
- self.tr(
- "Source {} does not exist. Check connection parameters."
- ).format(db_factory.get_specific_messages()["db_or_schema"])
- )
- self.enable()
- self.progress_bar.hide()
- return
-
- res, message = db_factory.post_generate_project_validations(configuration)
-
- if not res:
- self.txtStdout.setText(message)
- self.enable()
- self.progress_bar.hide()
- return
-
- self.print_info(
- f'\n{self.tr("Obtaining available layers from the database…")}'
- )
-
- available_layers = generator.layers()
-
- if not available_layers:
- text = self.tr("The {} has no layers to load into QGIS.").format(
- db_factory.get_specific_messages()["layers_source"]
- )
-
- self.txtStdout.setText(text)
- self.enable()
- self.progress_bar.hide()
- return
-
- self.progress_bar.setValue(40)
- self.print_info(self.tr("Obtaining relations from the database…"))
- relations, bags_of_enum = generator.relations(available_layers)
- self.progress_bar.setValue(45)
-
- self.print_info(self.tr("Arranging layers into groups…"))
- legend = generator.legend(available_layers)
-
- custom_layer_order_structure = list()
-
- # Project topping file for legend and layers: collect and download
- projecttopping_file_path_list = []
- if "CONFIGURATION" in self.metaconfig.sections():
- configuration_section = self.metaconfig["CONFIGURATION"]
- # get topping referenced in qgis.modelbaker.projecttopping
- key = "qgis.modelbaker.projecttopping"
- if key not in configuration_section:
- key = "qgis.modelbaker.layertree"
- self.print_info(
- self.tr(
- 'Keyword "qgis.modelbaker.layertree" is deprecated (but still working).. Use "qgis.modelbaker.projecttopping" instead.'
- ),
- LogColor.COLOR_TOPPING,
- )
- if key in configuration_section:
- self.print_info(
- self.tr("Metaconfig contains a project topping."),
- LogColor.COLOR_TOPPING,
- )
- projecttopping_data_list = configuration_section[key].split(";")
- projecttopping_file_path_list = self.get_topping_file_list(
- projecttopping_data_list
- )
-
- if len(projecttopping_file_path_list) > 1:
- self.print_info(
- self.tr(
- "Multiple project toppings can lead to unexpected behavior, when the sections are not clearly separated."
- ),
- LogColor.COLOR_TOPPING,
- )
-
- for projecttopping_file_path in projecttopping_file_path_list:
- self.print_info(
- self.tr("Parse project topping file {}…").format(
- projecttopping_file_path
- ),
- LogColor.COLOR_TOPPING,
- )
- with open(projecttopping_file_path) as stream:
- try:
- projecttopping_data = yaml.safe_load(stream)
- layertree_key = "layertree"
- if layertree_key not in projecttopping_data:
- layertree_key = "legend"
- self.print_info(
- self.tr(
- 'Keyword "legend" is deprecated (but still working).. Use "layertree" instead.'
- ),
- LogColor.COLOR_TOPPING,
- )
- if layertree_key in projecttopping_data:
- legend = generator.legend(
- available_layers,
- layertree_structure=projecttopping_data[layertree_key],
- path_resolver=lambda path: self.ilidata_path_resolver(
- os.path.dirname(projecttopping_file_path), path
- )
- if path
- else None,
- )
- if "layer-order" in projecttopping_data:
- custom_layer_order_structure = projecttopping_data[
- "layer-order"
- ]
- except yaml.YAMLError as exc:
- self.print_info(
- self.tr("Unable to parse project topping: {}").format(exc),
- LogColor.COLOR_TOPPING,
- )
-
- self.progress_bar.setValue(55)
-
- # on geopackages we don't use the transaction mode on default, since this leaded to troubles
- auto_transaction = not bool(configuration.tool & DbIliMode.gpkg)
- project = Project(
- auto_transaction,
- context={"catalogue_datasetname": CATALOGUE_DATASETNAME},
- )
- project.layers = available_layers
- project.relations = relations
- project.bags_of_enum = bags_of_enum
- project.legend = legend
- project.custom_layer_order_structure = custom_layer_order_structure
-
- self.print_info(self.tr("Configure forms and widgets…"))
- project.post_generate()
-
- qgis_project = QgsProject.instance()
-
- self.print_info(self.tr("Generate QGIS project…"))
- project.create(None, qgis_project)
-
- # Set the extent of the mapCanvas from the first layer extent found
- for layer in project.layers:
- if layer.extent is not None:
- self.iface.mapCanvas().setExtent(layer.extent)
- self.iface.mapCanvas().refresh()
- break
-
- self.progress_bar.setValue(60)
-
- # QML Toppings in the metadata: collect, download and apply
- # This configuration is legacy (should be in project topping instead), but it's still supported
- if "qgis.modelbaker.qml" in self.metaconfig.sections():
- self.print_info(
- self.tr(
- "Metaconfig contains QML toppings. Better practice would be to define QML toppings in the project topping file."
- ),
- LogColor.COLOR_TOPPING,
- )
- qml_section = dict(self.metaconfig["qgis.modelbaker.qml"])
- qml_file_model = self.get_topping_file_model(list(qml_section.values()))
- for layer in project.layers:
- if layer.alias:
- if any(layer.alias.lower() == s for s in qml_section):
- layer_qml = layer.alias.lower()
- elif any(f'"{layer.alias.lower()}"' == s for s in qml_section):
- layer_qml = f'"{layer.alias.lower()}"'
- else:
- continue
- matches = qml_file_model.match(
- qml_file_model.index(0, 0),
- Qt.DisplayRole,
- qml_section[layer_qml],
- 1,
- )
- if matches:
- style_file_path = matches[0].data(
- int(IliToppingFileItemModel.Roles.LOCALFILEPATH)
- )
- self.print_info(
- self.tr("Apply QML topping on layer {}:{}…").format(
- layer.alias, style_file_path
- ),
- LogColor.COLOR_TOPPING,
- )
- layer.layer.loadNamedStyle(style_file_path)
-
- self.progress_bar.setValue(80)
-
- # Cataloges and Transferfiles: collect, download and import
- if "CONFIGURATION" in self.metaconfig.sections():
- configuration_section = self.metaconfig["CONFIGURATION"]
- if "ch.interlis.referenceData" in configuration_section:
- self.print_info(
- self.tr(
- "Metaconfig contains transfer or catalogue toppings (reference data)."
- ),
- LogColor.COLOR_TOPPING,
- )
- reference_data_list = configuration_section[
- "ch.interlis.referenceData"
- ].split(";")
- referencedata_file_path_list = self.get_topping_file_list(
- reference_data_list
- )
- for referencedata_file_path in referencedata_file_path_list:
- self.print_info(
- self.tr("Import reference data file {}…").format(
- referencedata_file_path
- )
- )
-
- configuration = self.updated_referencedata_import_configuration(
- referencedata_file_path
- )
-
- # create schema with superuser
- db_factory = self.db_simple_factory.create_factory(db_id)
- res, message = db_factory.pre_generate_project(configuration)
-
- if not res:
- self.txtStdout.setText(message)
- return
-
- with OverrideCursor(Qt.WaitCursor):
-
- dataImporter = iliimporter.Importer(dataImport=True)
-
- dataImporter.tool = self.type_combo_box.currentData()
- dataImporter.configuration = configuration
-
- dataImporter.stdout.connect(self.print_info)
- dataImporter.stderr.connect(self.on_stderr)
- dataImporter.process_started.connect(
- self.on_process_started
- )
- dataImporter.process_finished.connect(
- self.on_process_finished
- )
-
- try:
- if (
- dataImporter.run(edited_command)
- != iliimporter.Importer.SUCCESS
- ):
- self.enable()
- self.progress_bar.hide()
- return
- except JavaNotFoundError as e:
- self.txtStdout.setTextColor(QColor(LogColor.COLOR_INFO))
- self.txtStdout.clear()
- self.txtStdout.setText(e.error_string)
- self.enable()
- self.progress_bar.hide()
-
- QApplication.restoreOverrideCursor()
- QMessageBox.critical(
- self,
- self.tr("Java not found error"),
- e.error_string,
- )
-
- return
-
- self.buttonBox.clear()
- self.buttonBox.setEnabled(True)
- self.buttonBox.addButton(QDialogButtonBox.Close)
- self.progress_bar.setValue(100)
- self.print_info(self.tr("\nDone!"), "#004905")
-
- def print_info(self, text, text_color=LogColor.COLOR_INFO):
- self.txtStdout.setTextColor(QColor(text_color))
- self.txtStdout.append(text)
- QCoreApplication.processEvents()
-
- def on_stderr(self, text):
- color_log_text(text, self.txtStdout)
- self.advance_progress_bar_by_text(text)
- QCoreApplication.processEvents()
-
- def on_process_started(self, command):
- self.print_info(self.tr("\n--- Process ---"))
- self.print_info(command)
- QCoreApplication.processEvents()
-
- def on_process_finished(self, exit_code, result):
- if exit_code == 0:
- color = LogColor.COLOR_SUCCESS
- message = self.tr(
- "Interlis model(s) successfully imported into the database!"
- )
- else:
- color = LogColor.COLOR_FAIL
- message = self.tr("Finished with errors!")
-
- self.txtStdout.setTextColor(QColor(color))
- self.txtStdout.append(message)
-
- def db_ili_version(self, configuration):
- """
- Returns the ili2db version the database has been created with or None if the database
- could not be detected as a ili2db database
- """
- schema = configuration.dbschema
-
- db_factory = self.db_simple_factory.create_factory(configuration.tool)
- config_manager = db_factory.get_db_command_config_manager(configuration)
- uri_string = config_manager.get_uri(configuration.db_use_super_login)
-
- try:
- db_connector = db_factory.get_db_connector(uri_string, schema)
- db_connector.new_message.connect(self.show_message)
- return db_connector.ili_version()
- except (DBConnectorError, FileNotFoundError):
- return None
-
- def updated_configuration(self):
- """
- Get the configuration that is updated with the user configuration changes on the dialog.
- :return: Configuration
- """
- configuration = SchemaImportConfiguration()
- configuration.create_basket_col = True
-
- mode = self.type_combo_box.currentData()
- db_id = mode & ~DbIliMode.ili
-
- self._lst_panel[db_id].get_fields(configuration)
-
- configuration.tool = mode
- configuration.srs_auth = self.srs_auth
- configuration.srs_code = self.srs_code
- configuration.inheritance = self.ili2db_options.inheritance_type()
- configuration.tomlfile = self.ili2db_options.toml_file()
- configuration.create_basket_col = self.ili2db_options.create_basket_col()
- configuration.create_import_tid = self.ili2db_options.create_import_tid()
- configuration.stroke_arcs = self.ili2db_options.stroke_arcs()
- configuration.pre_script = self.ili2db_options.pre_script()
- configuration.post_script = self.ili2db_options.post_script()
- configuration.db_ili_version = self.db_ili_version(configuration)
- configuration.metaconfig = self.metaconfig
- configuration.metaconfig_id = self.current_metaconfig_id
-
- configuration.base_configuration = self.base_configuration
- if self.ili_file_line_edit.text().strip():
- configuration.ilifile = self.ili_file_line_edit.text().strip()
-
- if self.ili_models_line_edit.text().strip():
- configuration.ilimodels = self.ili_models_line_edit.text().strip()
-
- if not self.create_constraints:
- configuration.disable_validation = True
-
- return configuration
-
- def updated_referencedata_import_configuration(self, file):
- """
- Get the configuration that is updated with the user configuration changes on the dialog.
- :return: Configuration
- """
- configuration = ImportDataConfiguration()
-
- mode = self.type_combo_box.currentData()
-
- db_id = mode & ~DbIliMode.ili
- self._lst_panel[db_id].get_fields(configuration)
-
- configuration.tool = mode
- configuration.xtffile = file
- configuration.delete_data = False
- configuration.base_configuration = self.base_configuration
- configuration.with_schemaimport = False
- # if not self.validate_data:
- # configuration.disable_validation = True
- return configuration
-
- def save_configuration(self, configuration):
- settings = QSettings()
- settings.setValue("QgisModelBaker/ili2db/ilifile", configuration.ilifile)
- settings.setValue("QgisModelBaker/ili2db/srs_auth", self.srs_auth)
- settings.setValue("QgisModelBaker/ili2db/srs_code", self.srs_code)
- settings.setValue(
- "QgisModelBaker/importtype", self.type_combo_box.currentData().name
- )
-
- mode = self.type_combo_box.currentData()
- db_factory = self.db_simple_factory.create_factory(mode)
- config_manager = db_factory.get_db_command_config_manager(configuration)
- config_manager.save_config_in_qsettings()
-
- def restore_configuration(self):
- settings = QSettings()
-
- self.ili_file_line_edit.setText(settings.value("QgisModelBaker/ili2db/ilifile"))
- srs_auth = settings.value("QgisModelBaker/ili2db/srs_auth", "EPSG")
- srs_code = settings.value("QgisModelBaker/ili2db/srs_code", 2056, int)
- crs = QgsCoordinateReferenceSystem("{}:{}".format(srs_auth, srs_code))
- if not crs.isValid():
- crs = QgsCoordinateReferenceSystem(srs_code) # Fallback
- self.crs = crs
- self.fill_toml_file_info_label()
- self.update_crs_info()
-
- for db_id in self.db_simple_factory.get_db_list(False):
- configuration = SchemaImportConfiguration()
- configuration.create_basket_col = True
- db_factory = self.db_simple_factory.create_factory(db_id)
- config_manager = db_factory.get_db_command_config_manager(configuration)
- config_manager.load_config_from_qsettings()
- self._lst_panel[db_id].set_fields(configuration)
-
- mode = settings.value("QgisModelBaker/importtype")
- mode = DbIliMode[mode] if mode else self.db_simple_factory.default_database
-
- self.type_combo_box.setCurrentIndex(self.type_combo_box.findData(mode))
- self.type_changed()
- self.crs_changed()
-
- def disable(self):
- self.type_combo_box.setEnabled(False)
- for key, value in self._lst_panel.items():
- value.setEnabled(False)
- self.ili_config.setEnabled(False)
- self.buttonBox.setEnabled(False)
-
- def enable(self):
- self.type_combo_box.setEnabled(True)
- for key, value in self._lst_panel.items():
- value.setEnabled(True)
- self.ili_config.setEnabled(True)
- self.buttonBox.setEnabled(True)
-
- def type_changed(self):
- self.txtStdout.clear()
- self.progress_bar.hide()
-
- ili_mode = self.type_combo_box.currentData()
- db_id = ili_mode & ~DbIliMode.ili
- interlis_mode = bool(ili_mode & DbIliMode.ili)
-
- self.ili_config.setVisible(interlis_mode)
- self.db_wrapper_group_box.setTitle(displayDbIliMode[db_id])
-
- self.create_button.setVisible(not interlis_mode)
- self.create_tool_button.setVisible(interlis_mode)
-
- # Refresh panels
- for key, value in self._lst_panel.items():
- value.interlis_mode = interlis_mode
- is_current_panel_selected = db_id == key
- value.setVisible(is_current_panel_selected)
- if is_current_panel_selected:
- value._show_panel()
-
- def on_model_changed(self, text):
- if not text:
- self.update_metaconfig_completer(0)
- return
- for pattern, crs in CRS_PATTERNS.items():
- if re.search(pattern, text):
- self.crs = QgsCoordinateReferenceSystem.fromEpsgId(int(crs))
- self.update_crs_info()
- break
- self.ili2db_options.set_toml_file_key(text)
- self.fill_toml_file_info_label()
- self.ilimetaconfigcache = IliDataCache(self.base_configuration, models=text)
- self.ilimetaconfigcache.file_download_succeeded.connect(
- lambda dataset_id, path: self.on_metaconfig_received(path)
- )
- self.ilimetaconfigcache.file_download_failed.connect(self.on_metaconfig_failed)
- self.ilimetaconfigcache.model_refreshed.connect(
- self.update_metaconfig_completer
- )
- self.refresh_ili_metaconfig_cache()
-
- def link_activated(self, link):
- if link.url() == "#configure":
- cfg = OptionsDialog(self.base_configuration)
- if cfg.exec_():
- settings = QSettings()
- settings.beginGroup("QgisModelBaker/ili2db")
- self.base_configuration.save(settings)
- else:
- QDesktopServices.openUrl(link)
-
- def update_crs_info(self):
- self.crsSelector.setCrs(self.crs)
-
- def crs_changed(self):
- self.srs_auth = "EPSG" # Default
- self.srs_code = 2056 # Default
- srs_auth, srs_code = self.crsSelector.crs().authid().split(":")
- if srs_auth == "USER":
- self.crs_label.setStyleSheet("color: orange")
- self.crs_label.setToolTip(
- self.tr(
- "Please select a valid Coordinate Reference System.\nCRSs from USER are valid for a single computer and therefore, a default EPSG:2056 will be used instead."
- )
- )
- else:
- self.crs_label.setStyleSheet("")
- self.crs_label.setToolTip(self.tr("Coordinate Reference System"))
- try:
- self.srs_code = int(srs_code)
- self.srs_auth = srs_auth
- except ValueError:
- # Preserve defaults if srs_code is not an integer
- self.crs_label.setStyleSheet("color: orange")
- self.crs_label.setToolTip(
- self.tr(
- "The srs code ('{}') should be an integer.\nA default EPSG:2056 will be used.".format(
- srs_code
- )
- )
- )
-
- def ili_file_changed(self):
- # If ili file is valid, models is optional
- if (
- self.ili_file_line_edit.text().strip()
- and self.ili_file_line_edit.validator().validate(
- self.ili_file_line_edit.text().strip(), 0
- )[0]
- == QValidator.Acceptable
- ):
- self.ili_models_line_edit.setValidator(None)
- self.ili_models_line_edit.textChanged.emit(self.ili_models_line_edit.text())
-
- # Update completer to add models from given ili file
- self.ilicache = IliCache(None, self.ili_file_line_edit.text().strip())
- self.refresh_ili_models_cache()
- models = self.ilicache.process_ili_file(
- self.ili_file_line_edit.text().strip()
- )
- try:
- self.ili_models_line_edit.setText(models[-1]["name"])
- self.ili_models_line_edit.setPlaceholderText(models[-1]["name"])
- except IndexError:
- self.ili_models_line_edit.setText("")
- self.ili_models_line_edit.setPlaceholderText(
- self.tr("[No models found in ili file]")
- )
- else:
- nonEmptyValidator = NonEmptyStringValidator()
- self.ili_models_line_edit.setValidator(nonEmptyValidator)
- self.ili_models_line_edit.textChanged.emit(self.ili_models_line_edit.text())
-
- # Update completer to add models from given ili file
- self.ilicache = IliCache(self.base_configuration)
- self.refresh_ili_models_cache()
- self.ili_models_line_edit.setPlaceholderText(
- self.tr("[Search model from repository]")
- )
-
- def refresh_ili_models_cache(self):
- self.ilicache.new_message.connect(self.show_message)
- self.ilicache.refresh()
- self.update_models_completer()
-
- def complete_models_completer(self):
- if not self.ili_models_line_edit.text():
- self.ili_models_line_edit.completer().setCompletionMode(
- QCompleter.UnfilteredPopupCompletion
- )
- self.ili_models_line_edit.completer().complete()
- else:
- match_contains = (
- self.ili_models_line_edit.completer()
- .completionModel()
- .match(
- self.ili_models_line_edit.completer().completionModel().index(0, 0),
- Qt.DisplayRole,
- self.ili_models_line_edit.text(),
- -1,
- Qt.MatchContains,
- )
- )
- if len(match_contains) > 1:
- self.ili_models_line_edit.completer().setCompletionMode(
- QCompleter.PopupCompletion
- )
- self.ili_models_line_edit.completer().complete()
-
- def update_models_completer(self):
- completer = QCompleter(self.ilicache.model, self.ili_models_line_edit)
- completer.setCaseSensitivity(Qt.CaseInsensitive)
- completer.setFilterMode(Qt.MatchContains)
- completer.popup().setItemDelegate(self.model_delegate)
- self.ili_models_line_edit.setCompleter(completer)
- self.multiple_models_dialog.models_line_edit.setCompleter(completer)
-
- def refresh_ili_metaconfig_cache(self):
- self.ilimetaconfigcache.new_message.connect(self.show_message)
- self.ilimetaconfigcache.refresh()
-
- def complete_metaconfig_completer(self):
- if not self.ili_metaconfig_line_edit.text():
- self.clean_metaconfig()
- self.ili_metaconfig_line_edit.completer().setCompletionMode(
- QCompleter.UnfilteredPopupCompletion
- )
- self.ili_metaconfig_line_edit.completer().complete()
- else:
- if ";" not in self.ili_metaconfig_line_edit.text():
- match_contains = (
- self.ili_metaconfig_line_edit.completer()
- .completionModel()
- .match(
- self.ili_metaconfig_line_edit.completer()
- .completionModel()
- .index(0, 0),
- Qt.DisplayRole,
- self.ili_metaconfig_line_edit.text(),
- -1,
- Qt.MatchContains,
- )
- )
- if len(match_contains) > 1:
- self.ili_metaconfig_line_edit.completer().setCompletionMode(
- QCompleter.PopupCompletion
- )
- self.ili_metaconfig_line_edit.completer().complete()
-
- def update_metaconfig_completer(self, rows):
- self.ili_metaconfig_line_edit.completer().setModel(
- self.ilimetaconfigcache.model
- )
- self.ili_metaconfig_line_edit.setEnabled(bool(rows))
- if self.ili_models_line_edit.text() != self.current_models:
- self.ili_metaconfig_line_edit.clear()
-
- def on_metaconfig_completer_activated(self, text=None):
- matches = self.ilimetaconfigcache.model.match(
- self.ilimetaconfigcache.model.index(0, 0),
- Qt.DisplayRole,
- self.ili_metaconfig_line_edit.text(),
- 1,
- Qt.MatchExactly,
- )
- if matches:
- model_index = matches[0]
- metaconfig_id = self.ilimetaconfigcache.model.data(
- model_index, int(IliDataItemModel.Roles.ID)
- )
-
- if self.current_metaconfig_id == metaconfig_id:
- return
- self.current_metaconfig_id = metaconfig_id
- self.metaconfig_file_info_label.setText(
- self.tr("Current Metaconfig File: {} ({})").format(
- self.ilimetaconfigcache.model.data(model_index, Qt.DisplayRole),
- metaconfig_id,
- )
- )
- self.metaconfig_file_info_label.setStyleSheet("color: #341d5c")
- repository = self.ilimetaconfigcache.model.data(
- model_index, int(IliDataItemModel.Roles.ILIREPO)
- )
- url = self.ilimetaconfigcache.model.data(
- model_index, int(IliDataItemModel.Roles.URL)
- )
- path = self.ilimetaconfigcache.model.data(
- model_index, int(IliDataItemModel.Roles.RELATIVEFILEPATH)
- )
- dataset_id = self.ilimetaconfigcache.model.data(
- model_index, int(IliDataItemModel.Roles.ID)
- )
- # disable the create button while downloading
- self.create_tool_button.setEnabled(False)
- if path:
- self.ilimetaconfigcache.download_file(repository, url, path, dataset_id)
- else:
- self.print_info(
- self.tr("File not specified for metaconfig with id {}.").format(
- dataset_id
- ),
- LogColor.COLOR_TOPPING,
- )
-
- self.set_metaconfig_line_edit_state(True)
- else:
- self.set_metaconfig_line_edit_state(
- not self.ili_metaconfig_line_edit.text()
- )
- self.clean_metaconfig()
-
- def clean_metaconfig(self):
- self.current_metaconfig_id = None
- self.metaconfig.clear()
- self.metaconfig_file_info_label.setText("")
- self.txtStdout.clear()
-
- def set_metaconfig_line_edit_state(self, valid):
- self.ili_metaconfig_line_edit.setStyleSheet(
- "QLineEdit {{ background-color: {} }}".format(
- "#ffffff" if valid else "#ffd356"
- )
- )
-
- def on_metaconfig_received(self, path):
- self.txtStdout.clear()
- self.print_info(
- self.tr("Metaconfig file successfully downloaded: {}").format(path),
- LogColor.COLOR_TOPPING,
- )
- # parse metaconfig
- self.metaconfig.clear()
- with open(path) as metaconfig_file:
- self.metaconfig.read_file(metaconfig_file)
- self.load_metaconfig()
- # enable the tool button again
- self.create_tool_button.setEnabled(True)
- self.fill_toml_file_info_label()
- self.print_info(
- self.tr("Metaconfig successfully loaded."), LogColor.COLOR_TOPPING
- )
-
- def on_metaconfig_failed(self, dataset_id, error_msg):
- self.print_info(
- self.tr("Download of metaconfig file failed: {}.").format(error_msg),
- LogColor.COLOR_TOPPING,
- )
- # enable the tool button again
- self.create_tool_button.setEnabled(True)
-
- def load_crs_from_metaconfig(self, ili2db_metaconfig):
- srs_auth = self.srs_auth
- srs_code = self.srs_code
- if "defaultSrsAuth" in ili2db_metaconfig:
- srs_auth = ili2db_metaconfig.get("defaultSrsAuth")
- if "defaultSrsCode" in ili2db_metaconfig:
- srs_code = ili2db_metaconfig.get("defaultSrsCode")
-
- crs = QgsCoordinateReferenceSystem("{}:{}".format(srs_auth, srs_code))
- if not crs.isValid():
- crs = QgsCoordinateReferenceSystem(srs_code) # Fallback
- self.crs = crs
- self.update_crs_info()
- self.crs_changed()
-
- def load_metaconfig(self):
- # load ili2db parameters to the GUI and into the configuration
- if "ch.ehi.ili2db" in self.metaconfig.sections():
- self.print_info(
- self.tr("Load the ili2db configurations from the metaconfig…"),
- LogColor.COLOR_TOPPING,
- )
-
- ili2db_metaconfig = self.metaconfig["ch.ehi.ili2db"]
-
- if (
- "defaultSrsAuth" in ili2db_metaconfig
- or "defaultSrsCode" in ili2db_metaconfig
- ):
- self.load_crs_from_metaconfig(ili2db_metaconfig)
- self.print_info(self.tr("- Loaded CRS"), LogColor.COLOR_TOPPING)
-
- if "models" in ili2db_metaconfig:
- model_list = self.ili_models_line_edit.text().strip().split(
- ";"
- ) + ili2db_metaconfig.get("models").strip().split(";")
- self.current_models = ";".join(set(model_list))
- self.ili_models_line_edit.setText(self.current_models)
- self.print_info(self.tr("- Loaded models"), LogColor.COLOR_TOPPING)
-
- self.ili2db_options.load_metaconfig(ili2db_metaconfig)
- self.print_info(self.tr("- Loaded ili2db options"), LogColor.COLOR_TOPPING)
-
- # get iliMetaAttrs (toml)
- if "iliMetaAttrs" in ili2db_metaconfig:
- self.print_info(
- self.tr("- Seek for iliMetaAttrs (toml) files:"),
- LogColor.COLOR_TOPPING,
- )
- ili_meta_attrs_list = ili2db_metaconfig.get("iliMetaAttrs").split(";")
- ili_meta_attrs_file_path_list = self.get_topping_file_list(
- ili_meta_attrs_list
- )
- self.ili2db_options.load_toml_file_path(
- self.ili_models_line_edit.text(),
- ";".join(ili_meta_attrs_file_path_list),
- )
- self.print_info(
- self.tr("- Loaded iliMetaAttrs (toml) files"),
- LogColor.COLOR_TOPPING,
- )
-
- # get prescript (sql)
- if "prescript" in ili2db_metaconfig:
- self.print_info(
- self.tr("- Seek for prescript (sql) files:"), LogColor.COLOR_TOPPING
- )
- prescript_list = ili2db_metaconfig.get("prescript").split(";")
- prescript_file_path_list = self.get_topping_file_list(prescript_list)
- self.ili2db_options.load_pre_script_path(
- ";".join(prescript_file_path_list)
- )
- self.print_info(
- self.tr("- Loaded prescript (sql) files"), LogColor.COLOR_TOPPING
- )
-
- # get postscript (sql)
- if "postscript" in ili2db_metaconfig:
- self.print_info(
- self.tr("- Seek for postscript (sql) files:"),
- LogColor.COLOR_TOPPING,
- )
- postscript_list = ili2db_metaconfig.get("postscript").split(";")
- postscript_file_path_list = self.get_topping_file_list(postscript_list)
- self.ili2db_options.load_post_script_path(
- ";".join(postscript_file_path_list)
- )
- self.print_info(
- self.tr("- Loaded postscript (sql) files"), LogColor.COLOR_TOPPING
- )
-
- def show_message(self, level, message):
- if level == Qgis.Warning:
- self.bar.pushMessage(message, Qgis.Info, 10)
- elif level == Qgis.Critical:
- self.bar.pushMessage(message, Qgis.Warning, 10)
-
- def fill_models_line_edit(self):
- self.ili_models_line_edit.setText(
- self.multiple_models_dialog.get_models_string()
- )
-
- def fill_toml_file_info_label(self):
- text = None
- if self.ili2db_options.toml_file():
- text = self.tr("Extra Meta Attribute File: {}").format(
- (
- "…"
- + self.ili2db_options.toml_file()[
- len(self.ili2db_options.toml_file()) - 40 :
- ]
- )
- if len(self.ili2db_options.toml_file()) > 40
- else self.ili2db_options.toml_file()
- )
- self.toml_file_info_label.setText(text)
- self.toml_file_info_label.setToolTip(self.ili2db_options.toml_file())
-
- def help_requested(self):
- os_language = QLocale(QSettings().value("locale/userLocale")).name()[:2]
- if os_language in ["es", "de"]:
- webbrowser.open(
- "https://opengisch.github.io/QgisModelBaker/docs/{}/user-guide.html#generate-project".format(
- os_language
- )
- )
- else:
- webbrowser.open(
- "https://opengisch.github.io/QgisModelBaker/docs/user-guide.html#generate-project"
- )
-
- def advance_progress_bar_by_text(self, text):
- if text.strip() == "Info: compile models…":
- self.progress_bar.setValue(20)
- elif text.strip() == "Info: create table structure…":
- self.progress_bar.setValue(30)
-
- def get_topping_file_list(self, id_list):
- topping_file_model = self.get_topping_file_model(id_list)
- file_path_list = []
-
- for file_id in id_list:
- matches = topping_file_model.match(
- topping_file_model.index(0, 0), Qt.DisplayRole, file_id, 1
- )
- if matches:
- file_path = matches[0].data(int(topping_file_model.Roles.LOCALFILEPATH))
- self.print_info(
- self.tr("- - Got file {}").format(file_path), LogColor.COLOR_TOPPING
- )
- file_path_list.append(file_path)
- return file_path_list
-
- def get_topping_file_model(self, id_list):
- topping_file_cache = IliToppingFileCache(self.base_configuration, id_list)
-
- # we wait for the download or we timeout after 30 seconds and we apply what we have
- loop = QEventLoop()
- topping_file_cache.download_finished.connect(lambda: loop.quit())
- timer = QTimer()
- timer.setSingleShot(True)
- timer.timeout.connect(lambda: loop.quit())
- timer.start(30000)
-
- topping_file_cache.refresh()
- self.print_info(self.tr("- - Downloading…"), LogColor.COLOR_TOPPING)
-
- if len(topping_file_cache.downloaded_files) != len(id_list):
- loop.exec()
-
- if len(topping_file_cache.downloaded_files) == len(id_list):
- self.print_info(
- self.tr("- - All topping files successfully downloaded"),
- LogColor.COLOR_TOPPING,
- )
- else:
- missing_file_ids = id_list
- for downloaded_file_id in topping_file_cache.downloaded_files:
- if downloaded_file_id in missing_file_ids:
- missing_file_ids.remove(downloaded_file_id)
- self.print_info(
- self.tr(
- "- - Some topping files where not successfully downloaded: {}"
- ).format(" ".join(missing_file_ids)),
- LogColor.COLOR_TOPPING,
- )
-
- return topping_file_cache.model
-
- def ilidata_path_resolver(self, base_path, path):
- if "ilidata:" in path or "file:" in path:
- data_file_path_list = self.get_topping_file_list([path])
- return data_file_path_list[0] if data_file_path_list else None
- return os.path.join(base_path, path)
diff --git a/QgisModelBaker/gui/import_data.py b/QgisModelBaker/gui/import_data.py
deleted file mode 100644
index 4559d3f7c..000000000
--- a/QgisModelBaker/gui/import_data.py
+++ /dev/null
@@ -1,600 +0,0 @@
-"""
-/***************************************************************************
- -------------------
- begin : 30/05/17
- git sha : :%H$
- copyright : (C) 2017 by Germán Carrillo (BSF-Swissphoto)
- email : gcarrillo@linuxmail.org
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * 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. *
- * *
- ***************************************************************************/
-"""
-
-import re
-import webbrowser
-
-from qgis.core import Qgis
-from qgis.gui import QgsGui, QgsMessageBar
-from qgis.PyQt.QtCore import QCoreApplication, QLocale, QSettings, Qt
-from qgis.PyQt.QtGui import QColor, QDesktopServices, QValidator
-from qgis.PyQt.QtWidgets import (
- QAction,
- QCompleter,
- QDialog,
- QDialogButtonBox,
- QGridLayout,
- QMessageBox,
- QSizePolicy,
-)
-
-from QgisModelBaker.gui.edit_command import EditCommandDialog
-from QgisModelBaker.gui.ili2db_options import Ili2dbOptionsDialog
-from QgisModelBaker.gui.multiple_models import MultipleModelsDialog
-from QgisModelBaker.gui.options import OptionsDialog
-from QgisModelBaker.gui.panel import db_panel_utils
-from QgisModelBaker.libs.modelbaker.db_factory.db_simple_factory import DbSimpleFactory
-from QgisModelBaker.libs.modelbaker.dbconnector.db_connector import DBConnectorError
-from QgisModelBaker.libs.modelbaker.iliwrapper import ili2dbconfig, iliimporter
-from QgisModelBaker.libs.modelbaker.iliwrapper.globals import DbIliMode
-from QgisModelBaker.libs.modelbaker.iliwrapper.ili2dbutils import (
- JavaNotFoundError,
- color_log_text,
-)
-from QgisModelBaker.libs.modelbaker.iliwrapper.ilicache import (
- IliCache,
- ModelCompleterDelegate,
-)
-from QgisModelBaker.libs.modelbaker.utils.globals import DbActionType
-from QgisModelBaker.libs.modelbaker.utils.qt_utils import (
- FileValidator,
- OverrideCursor,
- Validators,
- make_file_selector,
-)
-from QgisModelBaker.utils import gui_utils
-from QgisModelBaker.utils.globals import displayDbIliMode
-from QgisModelBaker.utils.gui_utils import LogColor
-
-DIALOG_UI = gui_utils.get_ui_class("import_data.ui")
-
-
-class ImportDataDialog(QDialog, DIALOG_UI):
-
- ValidExtensions = [
- "xtf",
- "XTF",
- "itf",
- "ITF",
- "pdf",
- "PDF",
- "xml",
- "XML",
- "xls",
- "XLS",
- "xlsx",
- "XLSX",
- ]
-
- ModelMissingRegExp = re.compile(r"Error: failed to query .*\.t_ili2db_seq")
-
- def __init__(self, iface, base_config, parent=None):
-
- QDialog.__init__(self, parent)
- self.iface = iface
- self.setupUi(self)
- QgsGui.instance().enableAutoGeometryRestore(self)
- self.db_simple_factory = DbSimpleFactory()
- self.buttonBox.accepted.disconnect()
- self.buttonBox.clear()
- self.buttonBox.addButton(QDialogButtonBox.Cancel)
- self.buttonBox.addButton(QDialogButtonBox.Help)
- self.buttonBox.helpRequested.connect(self.help_requested)
-
- self.import_text = self.tr("Import Data")
- self.set_button_to_import_action = QAction(self.import_text, None)
- self.set_button_to_import_action.triggered.connect(self.set_button_to_import)
-
- self.import_without_validation_text = self.tr("Import without validation")
- self.set_button_to_import_without_validation_action = QAction(
- self.import_without_validation_text, None
- )
- self.set_button_to_import_without_validation_action.triggered.connect(
- self.set_button_to_import_without_validation
- )
-
- self.edit_command_action = QAction(self.tr("Edit ili2db command"), None)
- self.edit_command_action.triggered.connect(self.edit_command)
-
- self.import_tool_button.addAction(
- self.set_button_to_import_without_validation_action
- )
- self.import_tool_button.addAction(self.edit_command_action)
- self.import_tool_button.setText(self.import_text)
- self.import_tool_button.clicked.connect(self.accepted)
-
- self.xtf_file_browse_button.clicked.connect(
- make_file_selector(
- self.xtf_file_line_edit,
- title=self.tr("Open Transfer or Catalog File"),
- file_filter=self.tr(
- "Transfer File (*.xtf *.itf *.XTF *.ITF);;Catalogue File (*.xml *.XML *.xls *.XLS *.xlsx *.XLSX)"
- ),
- )
- )
-
- self.type_combo_box.clear()
- self._lst_panel = dict()
-
- for db_id in self.db_simple_factory.get_db_list(False):
- self.type_combo_box.addItem(displayDbIliMode[db_id], db_id)
- item_panel = db_panel_utils.get_config_panel(
- db_id, self, DbActionType.IMPORT_DATA
- )
- self._lst_panel[db_id] = item_panel
- self.db_layout.addWidget(item_panel)
-
- self.type_combo_box.currentIndexChanged.connect(self.type_changed)
- self.ili2db_options = Ili2dbOptionsDialog(self, False)
- self.ili2db_options_button.clicked.connect(self.ili2db_options.open)
- self.ili2db_options.finished.connect(self.fill_toml_file_info_label)
-
- self.multiple_models_dialog = MultipleModelsDialog(self)
- self.multiple_models_button.clicked.connect(self.multiple_models_dialog.open)
- self.multiple_models_dialog.accepted.connect(self.fill_models_line_edit)
-
- self.validate_data = True # validates imported data by default, We use --disableValidation when is False
- self.base_configuration = base_config
- self.restore_configuration()
-
- self.validators = Validators()
- fileValidator = FileValidator(
- pattern=["*." + ext for ext in self.ValidExtensions]
- )
-
- self.xtf_file_line_edit.setValidator(fileValidator)
-
- self.ili_models_line_edit.setPlaceholderText(
- self.tr("[Search model in repository]")
- )
- self.ili_models_line_edit.textChanged.connect(self.complete_models_completer)
- self.ili_models_line_edit.punched.connect(self.complete_models_completer)
-
- self.xtf_file_line_edit.textChanged.connect(self.validators.validate_line_edits)
- self.xtf_file_line_edit.textChanged.emit(self.xtf_file_line_edit.text())
-
- # Reset to import as default text
- self.xtf_file_line_edit.textChanged.connect(self.set_button_to_import)
-
- settings = QSettings()
- ilifile = settings.value("QgisModelBaker/ili2db/ilifile")
- self.ilicache = IliCache(base_config, ilifile or None)
- self.update_models_completer()
- self.ilicache.refresh()
-
- self.bar = QgsMessageBar()
- self.bar.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
- self.txtStdout.setLayout(QGridLayout())
- self.txtStdout.layout().setContentsMargins(0, 0, 0, 0)
- self.txtStdout.layout().addWidget(self.bar, 0, 0, Qt.AlignTop)
-
- def set_button_to_import(self):
- """
- Changes the text of the button to import (with validation) and sets the validate_data to true.
- So on clicking the button the import will start with validation.
- The buttons actions are changed to be able to switch the without-validation mode.
- """
- self.validate_data = True
- self.import_tool_button.removeAction(self.set_button_to_import_action)
- self.import_tool_button.removeAction(self.edit_command_action)
- self.import_tool_button.addAction(
- self.set_button_to_import_without_validation_action
- )
- self.import_tool_button.addAction(self.edit_command_action)
- self.import_tool_button.setText(self.import_text)
-
- def set_button_to_import_without_validation(self):
- """
- Changes the text of the button to import without validation and sets the validate_data to false.
- So on clicking the button the import will start without validation.
- The buttons actions are changed to be able to switch the with-validation mode.
- """
- self.validate_data = False
- self.import_tool_button.removeAction(
- self.set_button_to_import_without_validation_action
- )
- self.import_tool_button.removeAction(self.edit_command_action)
- self.import_tool_button.addAction(self.set_button_to_import_action)
- self.import_tool_button.addAction(self.edit_command_action)
- self.import_tool_button.setText(self.import_without_validation_text)
-
- def edit_command(self):
- """
- A dialog opens giving the user the possibility to edit the ili2db command used for the import
- """
- importer = iliimporter.Importer()
- importer.tool = self.type_combo_box.currentData()
- importer.configuration = self.updated_configuration()
- command = importer.command(True)
- edit_command_dialog = EditCommandDialog(self)
- edit_command_dialog.command_edit.setPlainText(command)
- if edit_command_dialog.exec_():
- edited_command = edit_command_dialog.command_edit.toPlainText()
- self.accepted(edited_command)
-
- def accepted(self, edited_command=None):
- db_id = self.type_combo_box.currentData()
- res, message = self._lst_panel[db_id].is_valid()
-
- if not res:
- self.txtStdout.setText(message)
- return
-
- configuration = self.updated_configuration()
-
- if not edited_command:
- if (
- not self.xtf_file_line_edit.validator().validate(
- configuration.xtffile, 0
- )[0]
- == QValidator.Acceptable
- ):
- self.txtStdout.setText(
- self.tr(
- "Please set a valid INTERLIS transfer or catalogue file before importing data."
- )
- )
- self.xtf_file_line_edit.setFocus()
- return
-
- # create schema with superuser
- db_factory = self.db_simple_factory.create_factory(db_id)
- res, message = db_factory.pre_generate_project(configuration)
-
- if not res:
- self.txtStdout.setText(message)
- return
-
- with OverrideCursor(Qt.WaitCursor):
- self.progress_bar.show()
- self.progress_bar.setValue(0)
-
- self.disable()
- self.txtStdout.setTextColor(QColor(LogColor.COLOR_INFO))
- self.txtStdout.clear()
-
- dataImporter = iliimporter.Importer(dataImport=True)
-
- dataImporter.tool = self.type_combo_box.currentData()
- dataImporter.configuration = configuration
-
- self.save_configuration(configuration)
-
- dataImporter.stdout.connect(self.print_info)
- dataImporter.stderr.connect(self.on_stderr)
- dataImporter.process_started.connect(self.on_process_started)
- dataImporter.process_finished.connect(self.on_process_finished)
-
- self.progress_bar.setValue(25)
-
- try:
- if dataImporter.run(edited_command) != iliimporter.Importer.SUCCESS:
- self.enable()
- self.progress_bar.hide()
- return
- except JavaNotFoundError as e:
- self.txtStdout.setTextColor(QColor(LogColor.COLOR_INFO))
- self.txtStdout.clear()
- self.txtStdout.setText(e.error_string)
- self.enable()
- self.progress_bar.hide()
-
- QApplication.restoreOverrideCursor()
- QMessageBox.critical(
- self, self.tr("Java not found error"), e.error_string
- )
-
- return
-
- self.buttonBox.clear()
- self.buttonBox.setEnabled(True)
- self.buttonBox.addButton(QDialogButtonBox.Close)
- self.progress_bar.setValue(100)
-
- self.refresh_layers()
-
- def refresh_layers(self):
- # refresh layers
- try:
- for layer in self.iface.mapCanvas().layers():
- layer.dataProvider().reloadData()
- self.iface.layerTreeView().layerTreeModel().recursivelyEmitDataChanged()
- except AttributeError:
- pass
-
- def print_info(self, text, text_color=LogColor.COLOR_INFO):
- self.txtStdout.setTextColor(QColor(text_color))
- self.txtStdout.append(text)
- QCoreApplication.processEvents()
-
- def on_stderr(self, text):
- color_log_text(text, self.txtStdout)
- match = re.match(ImportDataDialog.ModelMissingRegExp, text)
- if match:
- color_log_text(
- "=======================================================================",
- self.txtStdout,
- )
- color_log_text(
- self.tr(
- "It looks like the required schema for the imported data has not been generated."
- ),
- self.txtStdout,
- )
- color_log_text(
- self.tr("Did you generate the model in the database?"), self.txtStdout
- )
- color_log_text(
- self.tr(
- "Note: the model for a catalogue may be different from the data model itself."
- ),
- self.txtStdout,
- )
- color_log_text(
- "=======================================================================",
- self.txtStdout,
- )
- self.advance_progress_bar_by_text(text)
-
- def show_message(self, level, message):
- if level == Qgis.Warning:
- self.bar.pushMessage(message, Qgis.Info, 10)
- elif level == Qgis.Critical:
- self.bar.pushMessage(message, Qgis.Warning, 10)
-
- def on_process_started(self, command):
- self.disable()
- self.txtStdout.setTextColor(QColor(LogColor.COLOR_INFO))
- self.txtStdout.clear()
- self.txtStdout.setText(command)
- QCoreApplication.processEvents()
-
- def on_process_finished(self, exit_code, result):
- color = "#004905" if exit_code == 0 else "#aa2222"
- self.txtStdout.setTextColor(QColor(color))
- self.txtStdout.append("Finished ({})".format(exit_code))
- if result == iliimporter.Importer.SUCCESS:
- self.buttonBox.clear()
- self.buttonBox.setEnabled(True)
- self.buttonBox.addButton(QDialogButtonBox.Close)
- else:
- if self.import_without_validate():
- self.set_button_to_import_without_validation()
- self.enable()
-
- def import_without_validate(self):
- """
- Valid if an error occurred that prevents executing the import without validations
- :return: True if you can execute the import without validations, False in other case
- """
- log = self.txtStdout.toPlainText().lower()
- if "no models given" in log:
- return False
- if "attribute bid missing in basket" in log:
- return False
- return True
-
- def db_ili_version(self, configuration):
- """
- Returns the ili2db version the database has been created with or None if the database
- could not be detected as a ili2db database
- """
- db_connector = self.__db_connector(configuration)
-
- if db_connector:
- return db_connector.ili_version()
-
- return None
-
- def updated_configuration(self):
- """
- Get the configuration that is updated with the user configuration changes on the dialog.
- :return: Configuration
- """
- configuration = ili2dbconfig.ImportDataConfiguration()
-
- mode = self.type_combo_box.currentData()
- self._lst_panel[mode].get_fields(configuration)
-
- configuration.tool = mode
- configuration.xtffile = self.xtf_file_line_edit.text().strip()
- configuration.delete_data = self.chk_delete_data.isChecked()
- configuration.ilimodels = self.ili_models_line_edit.text().strip()
- configuration.inheritance = self.ili2db_options.inheritance_type()
- configuration.create_basket_col = self.ili2db_options.create_basket_col()
- configuration.create_import_tid = self.ili2db_options.create_import_tid()
- configuration.stroke_arcs = self.ili2db_options.stroke_arcs()
- configuration.pre_script = self.ili2db_options.pre_script()
- configuration.post_script = self.ili2db_options.post_script()
- configuration.base_configuration = self.base_configuration
- configuration.db_ili_version = self.db_ili_version(configuration)
-
- configuration.with_schemaimport = True
- db_connector = self.__db_connector(configuration)
- if db_connector and db_connector.db_or_schema_exists():
- configuration.with_schemaimport = False
-
- if not self.validate_data:
- configuration.disable_validation = True
- return configuration
-
- def save_configuration(self, configuration):
- settings = QSettings()
- settings.setValue("QgisModelBaker/ili2pg/xtffile_import", configuration.xtffile)
- settings.setValue("QgisModelBaker/ili2pg/deleteData", configuration.delete_data)
- settings.setValue(
- "QgisModelBaker/importtype", self.type_combo_box.currentData().name
- )
-
- mode = self.type_combo_box.currentData()
- db_factory = self.db_simple_factory.create_factory(mode)
- config_manager = db_factory.get_db_command_config_manager(configuration)
- config_manager.save_config_in_qsettings()
-
- def restore_configuration(self):
- settings = QSettings()
- self.fill_toml_file_info_label()
- self.xtf_file_line_edit.setText(
- settings.value("QgisModelBaker/ili2pg/xtffile_import")
- )
- # set chk_delete_data always to unchecked because otherwise the user could delete the data accidentally
- self.chk_delete_data.setChecked(False)
-
- for db_id in self.db_simple_factory.get_db_list(False):
- configuration = iliimporter.ImportDataConfiguration()
- db_factory = self.db_simple_factory.create_factory(db_id)
- config_manager = db_factory.get_db_command_config_manager(configuration)
- config_manager.load_config_from_qsettings()
- self._lst_panel[db_id].set_fields(configuration)
-
- mode = settings.value("QgisModelBaker/importtype")
- mode = DbIliMode[mode] if mode else self.db_simple_factory.default_database
- mode = mode & ~DbIliMode.ili
-
- self.type_combo_box.setCurrentIndex(self.type_combo_box.findData(mode))
- self.type_changed()
-
- def disable(self):
- self.type_combo_box.setEnabled(False)
- for key, value in self._lst_panel.items():
- value.setEnabled(False)
- self.ili_config.setEnabled(False)
- self.buttonBox.setEnabled(False)
-
- def enable(self):
- self.type_combo_box.setEnabled(True)
- for key, value in self._lst_panel.items():
- value.setEnabled(True)
- self.ili_config.setEnabled(True)
- self.buttonBox.setEnabled(True)
-
- def type_changed(self):
- self.txtStdout.clear()
- self.set_button_to_import()
- self.progress_bar.hide()
-
- db_id = self.type_combo_box.currentData()
- self.db_wrapper_group_box.setTitle(displayDbIliMode[db_id])
-
- # Refresh panels
- for key, value in self._lst_panel.items():
- value.interlis_mode = False
- is_current_panel_selected = db_id == key
- value.setVisible(is_current_panel_selected)
- if is_current_panel_selected:
- value._show_panel()
-
- def link_activated(self, link):
- if link.url() == "#configure":
- cfg = OptionsDialog(self.base_configuration)
- if cfg.exec_():
- settings = QSettings()
- settings.beginGroup("QgisModelBaker/ili2db")
- self.base_configuration.save(settings)
- else:
- QDesktopServices.openUrl(link)
-
- def complete_models_completer(self):
- if not self.ili_models_line_edit.text():
- self.ili_models_line_edit.completer().setCompletionMode(
- QCompleter.UnfilteredPopupCompletion
- )
- self.ili_models_line_edit.completer().complete()
- else:
- match_contains = (
- self.ili_models_line_edit.completer()
- .completionModel()
- .match(
- self.ili_models_line_edit.completer().completionModel().index(0, 0),
- Qt.DisplayRole,
- self.ili_models_line_edit.text(),
- -1,
- Qt.MatchContains,
- )
- )
- if len(match_contains) > 1:
- self.ili_models_line_edit.completer().setCompletionMode(
- QCompleter.PopupCompletion
- )
- self.ili_models_line_edit.completer().complete()
-
- def update_models_completer(self):
- completer = QCompleter(self.ilicache.model, self.ili_models_line_edit)
- completer.setCaseSensitivity(Qt.CaseInsensitive)
- completer.setFilterMode(Qt.MatchContains)
- self.delegate = ModelCompleterDelegate()
- completer.popup().setItemDelegate(self.delegate)
- self.ili_models_line_edit.setCompleter(completer)
- self.multiple_models_dialog.models_line_edit.setCompleter(completer)
-
- def fill_models_line_edit(self):
- self.ili_models_line_edit.setText(
- self.multiple_models_dialog.get_models_string()
- )
-
- def fill_toml_file_info_label(self):
- text = None
- if self.ili2db_options.toml_file():
- text = self.tr("Extra Meta Attribute File: {}").format(
- (
- "…"
- + self.ili2db_options.toml_file()[
- len(self.ili2db_options.toml_file()) - 40 :
- ]
- )
- if len(self.ili2db_options.toml_file()) > 40
- else self.ili2db_options.toml_file()
- )
- self.toml_file_info_label.setText(text)
- self.toml_file_info_label.setToolTip(self.ili2db_options.toml_file())
-
- def help_requested(self):
- os_language = QLocale(QSettings().value("locale/userLocale")).name()[:2]
- if os_language in ["es", "de"]:
- webbrowser.open(
- "https://opengisch.github.io/QgisModelBaker/docs/{}/user-guide.html#import-an-interlis-transfer-file-xtf".format(
- os_language
- )
- )
- else:
- webbrowser.open(
- "https://opengisch.github.io/QgisModelBaker/docs/user-guide.html#import-an-interlis-transfer-file-xtf"
- )
-
- def advance_progress_bar_by_text(self, text):
- if text.strip() == "Info: compile models...":
- self.progress_bar.setValue(50)
- QCoreApplication.processEvents()
- elif text.strip() == "Info: create table structure...":
- self.progress_bar.setValue(75)
- QCoreApplication.processEvents()
-
- def __db_connector(self, configuration):
- db_factory = self.db_simple_factory.create_factory(configuration.tool)
- config_manager = db_factory.get_db_command_config_manager(configuration)
- try:
- db_connector = db_factory.get_db_connector(
- config_manager.get_uri(configuration.db_use_super_login)
- or config_manager.get_uri(),
- configuration.dbschema,
- )
- db_connector.new_message.connect(self.show_message)
- return db_connector
- except (DBConnectorError, FileNotFoundError):
- return None
diff --git a/QgisModelBaker/gui/multiple_models.py b/QgisModelBaker/gui/multiple_models.py
deleted file mode 100644
index b16c9cdf0..000000000
--- a/QgisModelBaker/gui/multiple_models.py
+++ /dev/null
@@ -1,67 +0,0 @@
-"""
-/***************************************************************************
- -------------------
- begin : 25.11.2017
- git sha : :%H$
- copyright : (C) 2017 by Germán Carrillo (BSF-Swissphoto)
- email : gcarrillo@linuxmail.org
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * 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.gui import QgsGui
-from qgis.PyQt.QtCore import Qt
-from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox, QListWidgetItem
-
-from QgisModelBaker.utils.gui_utils import get_ui_class
-
-DIALOG_UI = get_ui_class("multiple_models.ui")
-
-
-class MultipleModelsDialog(QDialog, DIALOG_UI):
- def __init__(self, parent=None):
- QDialog.__init__(self, parent)
- self.setupUi(self)
- QgsGui.instance().enableAutoGeometryRestore(self)
- self.parent = parent
-
- self.model_list.itemSelectionChanged.connect(self.on_selection_changed)
- self.on_selection_changed()
-
- self.add_button.clicked.connect(self.add_model)
- self.remove_button.clicked.connect(self.remove_model)
- self.buttonBox.accepted.connect(self.accepted)
-
- self.models_line_edit.textChanged.connect(self.update_add_button_state)
- self.models_line_edit.textChanged.emit(self.models_line_edit.text())
-
- def add_model(self):
- model_name = self.models_line_edit.text().strip()
- if not self.model_list.findItems(model_name, Qt.MatchExactly):
- self.model_list.addItem(QListWidgetItem(model_name))
- self.models_line_edit.setText("")
-
- def remove_model(self):
- for item in self.model_list.selectedItems():
- self.model_list.takeItem(self.model_list.row(item))
-
- def get_models_string(self):
- items = [self.model_list.item(x) for x in range(self.model_list.count())]
- models = ";".join([i.text().strip() for i in items if i.text().strip()])
- return models
-
- def on_selection_changed(self):
- enable = len(self.model_list.selectedItems()) == 1
- self.remove_button.setEnabled(enable)
-
- def update_add_button_state(self, text):
- self.add_button.setEnabled(bool(text.strip()))
- self.add_button.setDefault(bool(text.strip()))
- self.buttonBox.button(QDialogButtonBox.Ok).setDefault(not bool(text.strip()))
diff --git a/QgisModelBaker/images/QgisModelBaker-generate-icon.svg b/QgisModelBaker/images/QgisModelBaker-generate-icon.svg
deleted file mode 100644
index b81dcd63d..000000000
--- a/QgisModelBaker/images/QgisModelBaker-generate-icon.svg
+++ /dev/null
@@ -1,366 +0,0 @@
-
-
-
-
diff --git a/QgisModelBaker/images/QgisModelBaker-icon.png b/QgisModelBaker/images/QgisModelBaker-icon.png
deleted file mode 100644
index bec58a691..000000000
Binary files a/QgisModelBaker/images/QgisModelBaker-icon.png and /dev/null differ
diff --git a/QgisModelBaker/images/QgisModelBaker-xtf-export-icon.svg b/QgisModelBaker/images/QgisModelBaker-xtf-export-icon.svg
deleted file mode 100644
index 63ebb5fa6..000000000
--- a/QgisModelBaker/images/QgisModelBaker-xtf-export-icon.svg
+++ /dev/null
@@ -1,368 +0,0 @@
-
-
-
-
diff --git a/QgisModelBaker/images/QgisModelBaker-xtf-import-icon.svg b/QgisModelBaker/images/QgisModelBaker-xtf-import-icon.svg
deleted file mode 100644
index 52f13be50..000000000
--- a/QgisModelBaker/images/QgisModelBaker-xtf-import-icon.svg
+++ /dev/null
@@ -1,367 +0,0 @@
-
-
-
-
diff --git a/QgisModelBaker/qgismodelbaker.py b/QgisModelBaker/qgismodelbaker.py
index 27061fae9..54106e1d3 100644
--- a/QgisModelBaker/qgismodelbaker.py
+++ b/QgisModelBaker/qgismodelbaker.py
@@ -41,9 +41,6 @@
from QgisModelBaker.gui.dataset_manager import DatasetManagerDialog
from QgisModelBaker.gui.drop_message import DropMessageDialog
-from QgisModelBaker.gui.export import ExportDialog
-from QgisModelBaker.gui.generate_project import GenerateProjectDialog
-from QgisModelBaker.gui.import_data import ImportDataDialog
from QgisModelBaker.gui.options import OptionsDialog
from QgisModelBaker.gui.panel.dataset_selector import DatasetSelector
from QgisModelBaker.gui.topping_wizard.topping_wizard import ToppingWizardDialog
@@ -61,16 +58,10 @@ def __init__(self, iface):
self.iface = iface
self.plugin_dir = os.path.dirname(__file__)
- self.generate_dlg = None
- self.export_dlg = None
- self.importdata_dlg = None
self.workflow_wizard_dlg = None
self.datasetmanager_dlg = None
self.topping_wizard_dlg = None
- self.__generate_action = None
- self.__export_action = None
- self.__importdata_action = None
self.__workflow_wizard_action = None
self.__datasetmanager_action = None
self.__validate_action = None
@@ -121,35 +112,6 @@ def initGui(self):
pyplugin_installer.instance().uninstallPlugin(
"projectgenerator", quiet=True
)
- self.__generate_action = QAction(
- QIcon(
- os.path.join(
- os.path.dirname(__file__), "images/QgisModelBaker-generate-icon.svg"
- )
- ),
- self.tr("Generate"),
- None,
- )
- self.__export_action = QAction(
- QIcon(
- os.path.join(
- os.path.dirname(__file__),
- "images/QgisModelBaker-xtf-export-icon.svg",
- )
- ),
- self.tr("Export Interlis Transfer File (.xtf)"),
- None,
- )
- self.__importdata_action = QAction(
- QIcon(
- os.path.join(
- os.path.dirname(__file__),
- "images/QgisModelBaker-xtf-import-icon.svg",
- )
- ),
- self.tr("Import Interlis Transfer File (.xtf)"),
- None,
- )
self.__datasetmanager_action = QAction(
QIcon(
os.path.join(
@@ -198,20 +160,14 @@ def initGui(self):
self.__about_action = QAction(self.tr("About"), None)
# set these actions checkable to visualize that the dialog is open
- self.__generate_action.setCheckable(True)
- self.__export_action.setCheckable(True)
- self.__importdata_action.setCheckable(True)
self.__workflow_wizard_action.setCheckable(True)
self.__datasetmanager_action.setCheckable(True)
self.__validate_action.setCheckable(True)
self.__topping_wizard_action.setCheckable(True)
- self.__generate_action.triggered.connect(self.show_generate_dialog)
self.__configure_action.triggered.connect(self.show_options_dialog)
- self.__importdata_action.triggered.connect(self.show_importdata_dialog)
self.__datasetmanager_action.triggered.connect(self.show_datasetmanager_dialog)
self.__validate_action.triggered.connect(self.show_validate_dock)
- self.__export_action.triggered.connect(self.show_export_dialog)
self.__workflow_wizard_action.triggered.connect(
self.show_workflow_wizard_dialog
)
@@ -273,9 +229,6 @@ def unload(self):
self.iface.layerTreeView().currentLayerChanged.disconnect(
self.__dataset_selector.set_current_layer
)
- del self.__generate_action
- del self.__export_action
- del self.__importdata_action
del self.__workflow_wizard_action
del self.__datasetmanager_action
del self.__validate_action
@@ -290,40 +243,6 @@ def unload(self):
self.remove_validate_dock()
- def show_generate_dialog(self):
- if self.generate_dlg:
- self.generate_dlg.reject()
- else:
- self.generate_dlg = GenerateProjectDialog(
- self.iface, self.ili2db_configuration, self.iface.mainWindow()
- )
- self.generate_dlg.setAttribute(Qt.WA_DeleteOnClose)
- self.generate_dlg.setWindowFlags(self.generate_dlg.windowFlags() | Qt.Tool)
- self.generate_dlg.show()
- self.generate_dlg.finished.connect(self.generate_dialog_finished)
- self.__generate_action.setChecked(True)
-
- def generate_dialog_finished(self):
- self.__generate_action.setChecked(False)
- self.generate_dlg = None
-
- def show_export_dialog(self):
- if self.export_dlg:
- self.export_dlg.reject()
- else:
- self.export_dlg = ExportDialog(
- self.ili2db_configuration, self.iface.mainWindow()
- )
- self.export_dlg.setAttribute(Qt.WA_DeleteOnClose)
- self.export_dlg.setWindowFlags(self.export_dlg.windowFlags() | Qt.Tool)
- self.export_dlg.show()
- self.export_dlg.finished.connect(self.export_dialog_finished)
- self.__export_action.setChecked(True)
-
- def export_dialog_finished(self):
- self.__export_action.setChecked(False)
- self.export_dlg = None
-
def show_workflow_wizard_dialog(self):
if self.workflow_wizard_dlg:
self.workflow_wizard_dlg.reject()
@@ -366,25 +285,6 @@ def topping_wizard_dialog_finished(self):
self.__topping_wizard_action.setChecked(False)
self.topping_wizard_dlg = None
- def show_importdata_dialog(self):
- if self.importdata_dlg:
- self.importdata_dlg.reject()
- else:
- self.importdata_dlg = ImportDataDialog(
- self.iface, self.ili2db_configuration, self.iface.mainWindow()
- )
- self.importdata_dlg.setAttribute(Qt.WA_DeleteOnClose)
- self.importdata_dlg.setWindowFlags(
- self.importdata_dlg.windowFlags() | Qt.Tool
- )
- self.importdata_dlg.show()
- self.importdata_dlg.finished.connect(self.importdata_dialog_finished)
- self.__importdata_action.setChecked(True)
-
- def importdata_dialog_finished(self):
- self.__importdata_action.setChecked(False)
- self.importdata_dlg = None
-
def show_datasetmanager_dialog(self):
if self.datasetmanager_dlg:
self.datasetmanager_dlg.reject()
diff --git a/QgisModelBaker/ui/export.ui b/QgisModelBaker/ui/export.ui
deleted file mode 100644
index 07997d68e..000000000
--- a/QgisModelBaker/ui/export.ui
+++ /dev/null
@@ -1,233 +0,0 @@
-
-
- InterlisExport
-
-
-
- 0
- 0
- 718
- 771
-
-
-
- Export Interlis Data
-
-
- -
-
-
-
-
-
-
- 0
- 0
-
-
-
-
- 88
- 16777215
-
-
-
- Source
-
-
-
- -
-
-
-
-
- PostGIS
-
-
- -
-
- GeoPackage
-
-
-
-
-
-
- -
-
-
- 0
-
-
-
-
-
-
-
-
-
-
- 0
-
-
-
- -
-
-
- Qt::Horizontal
-
-
- QDialogButtonBox::Cancel|QDialogButtonBox::Help
-
-
-
- -
-
-
- ...
-
-
- QToolButton::MenuButtonPopup
-
-
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
- false
-
-
-
- -
-
-
- Interlis
-
-
-
-
-
-
- -
-
-
- Models
-
-
-
- -
-
-
- Qt::Horizontal
-
-
-
- 40
- 3
-
-
-
-
- -
-
-
- Browse XTF files
-
-
- …
-
-
-
- -
-
-
- XTF File
-
-
-
- -
-
-
-
-
-
- -
-
-
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
-
-
-
-
-
-
-
-
-
-
-
-
- SpaceCheckListView
-
- QgisModelBaker.utils.gui_utils
- 1
-
-
-
- type_combo_box
- xtf_file_line_edit
- xtf_file_browse_button
- txtStdout
-
-
-
-
- buttonBox
- accepted()
- InterlisExport
- accept()
-
-
- 248
- 254
-
-
- 157
- 274
-
-
-
-
- buttonBox
- rejected()
- InterlisExport
- reject()
-
-
- 316
- 260
-
-
- 286
- 274
-
-
-
-
-
diff --git a/QgisModelBaker/ui/generate_project.ui b/QgisModelBaker/ui/generate_project.ui
deleted file mode 100644
index 7d5687fed..000000000
--- a/QgisModelBaker/ui/generate_project.ui
+++ /dev/null
@@ -1,328 +0,0 @@
-
-
- InterlisImport
-
-
-
- 0
- 0
- 641
- 803
-
-
-
- Generate Project
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
- 88
- 16777215
-
-
-
- Source
-
-
-
- -
-
-
-
-
- Interlis (PostGIS)
-
-
- -
-
- Interlis (GeoPackage)
-
-
- -
-
- PostGIS
-
-
- -
-
- GeoPackage
-
-
-
-
- -
-
-
- 0
-
-
-
-
-
-
-
-
-
-
- false
-
-
-
- -
-
-
- Interlis
-
-
-
-
-
-
-
- 580
- 16777215
-
-
-
-
-
-
-
- -
-
-
- Qt::StrongFocus
-
-
-
- -
-
-
- [Optional]
-
-
-
- -
-
-
- Coordinate Reference System
-
-
- CRS
-
-
-
- -
-
-
- Models
-
-
-
- -
-
-
- Advanced Options
-
-
-
- -
-
-
- Select multiple Interlis models
-
-
- …
-
-
-
- -
-
-
- -
-
-
- -
-
-
- Metaconfiguration / Topping
-
-
-
- -
-
-
- Interlis File
-
-
-
- -
-
-
- Qt::Horizontal
-
-
-
- 40
- 20
-
-
-
-
- -
-
-
- Browse Interlis files
-
-
- …
-
-
-
- -
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
-
-
-
- -
-
-
-
-
-
- 0
-
-
-
- -
-
-
- Qt::Horizontal
-
-
- QDialogButtonBox::Cancel|QDialogButtonBox::Help
-
-
-
- -
-
-
- ...
-
-
- QToolButton::MenuButtonPopup
-
-
-
- -
-
-
- Create
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- QgsProjectionSelectionWidget
- QWidget
-
- 1
-
-
- CompletionLineEdit
-
- QgisModelBaker.utils.gui_utils
- 1
-
-
-
- type_combo_box
- ili_file_line_edit
- ili_file_browse_button
- ili_models_line_edit
- multiple_models_button
- crsSelector
- ili2db_options_button
- txtStdout
- buttonBox
-
-
-
-
- buttonBox
- accepted()
- InterlisImport
- accept()
-
-
- 248
- 254
-
-
- 157
- 274
-
-
-
-
- buttonBox
- rejected()
- InterlisImport
- reject()
-
-
- 316
- 260
-
-
- 286
- 274
-
-
-
-
-
diff --git a/QgisModelBaker/ui/import_data.ui b/QgisModelBaker/ui/import_data.ui
deleted file mode 100644
index ad0626191..000000000
--- a/QgisModelBaker/ui/import_data.ui
+++ /dev/null
@@ -1,276 +0,0 @@
-
-
- InterlisImportData
-
-
-
- 0
- 0
- 718
- 791
-
-
-
- Import Interlis Data
-
-
- -
-
-
-
-
-
-
- 0
- 0
-
-
-
-
- 88
- 16777215
-
-
-
- Target
-
-
-
- -
-
-
-
-
- PostGIS
-
-
- -
-
- GeoPackage
-
-
-
-
-
-
- -
-
-
- 0
-
-
-
-
-
-
-
- Interlis
-
-
-
-
-
-
- Browse XTF files
-
-
- …
-
-
-
- -
-
-
- Models
-
-
-
- -
-
-
- Select multiple Interlis models
-
-
- …
-
-
-
- -
-
-
- Advanced Options
-
-
-
- -
-
-
- -
-
-
- -
-
-
- XTF File
-
-
-
- -
-
-
- Qt::Horizontal
-
-
-
- 40
- 3
-
-
-
-
- -
-
-
- Delete existing data including dependencies like catalogues etc.
-
-
- Delete existing data in affected tables
-
-
-
- -
-
-
-
- 580
- 16777215
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
- false
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
- 0
-
-
-
- -
-
-
- Qt::Horizontal
-
-
- QDialogButtonBox::Cancel|QDialogButtonBox::Help
-
-
-
- -
-
-
- ...
-
-
- QToolButton::MenuButtonPopup
-
-
-
-
-
-
-
-
-
- CompletionLineEdit
-
- QgisModelBaker.utils.gui_utils
- 1
-
-
-
- type_combo_box
- xtf_file_line_edit
- xtf_file_browse_button
- ili_models_line_edit
- multiple_models_button
- chk_delete_data
- txtStdout
-
-
-
-
- buttonBox
- accepted()
- InterlisImportData
- accept()
-
-
- 248
- 254
-
-
- 157
- 274
-
-
-
-
- buttonBox
- rejected()
- InterlisImportData
- reject()
-
-
- 316
- 260
-
-
- 286
- 274
-
-
-
-
-
diff --git a/QgisModelBaker/ui/multiple_models.ui b/QgisModelBaker/ui/multiple_models.ui
deleted file mode 100644
index 8b9b9243a..000000000
--- a/QgisModelBaker/ui/multiple_models.ui
+++ /dev/null
@@ -1,181 +0,0 @@
-
-
- MultipleModelsDialog
-
-
-
- 0
- 0
- 413
- 266
-
-
-
- Select multiple Interlis models
-
-
- -
-
-
-
-
-
- Start typing a model name
-
-
-
- -
-
-
-
- false
-
-
-
- QListWidget::item { border-bottom: 1px #A4A4A4; border-style: dotted;}
-QListWidget::item:selected { color: white; background: #6699ff;}
-
-
- QFrame::StyledPanel
-
-
- QFrame::Sunken
-
-
- 0
-
-
- QAbstractItemView::NoEditTriggers
-
-
- true
-
-
- true
-
-
- QAbstractItemView::SingleSelection
-
-
- false
-
-
- QListView::ListMode
-
-
- false
-
-
- false
-
-
-
-
-
- -
-
-
-
-
-
-
- 101
- 0
-
-
-
- Add
-
-
- false
-
-
-
- -
-
-
-
- 50
- false
- false
-
-
-
- Remove
-
-
- false
-
-
- false
-
-
-
- -
-
-
- Qt::Vertical
-
-
-
- 20
- 40
-
-
-
-
-
-
- -
-
-
- Qt::Horizontal
-
-
- QDialogButtonBox::Cancel|QDialogButtonBox::Ok
-
-
-
-
-
-
- models_line_edit
- add_button
- model_list
- remove_button
- buttonBox
-
-
-
-
- buttonBox
- accepted()
- MultipleModelsDialog
- accept()
-
-
- 248
- 254
-
-
- 157
- 274
-
-
-
-
- buttonBox
- rejected()
- MultipleModelsDialog
- reject()
-
-
- 316
- 260
-
-
- 286
- 274
-
-
-
-
-