Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[toppingwizard] Export all ili2db settings to metaconfig file #986

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repos:

# Remove unused imports/variables
- repo: https://github.com/myint/autoflake
rev: v1.4
rev: v2.3.1
hooks:
- id: autoflake
args:
Expand Down
22 changes: 16 additions & 6 deletions QgisModelBaker/gui/topping_wizard/ili2dbsettings_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@
* *
***************************************************************************/
"""
import tempfile
from enum import IntEnum

from qgis.core import QgsMapLayer, QgsProject
from qgis.core import Qgis, QgsMapLayer, QgsMessageLog, QgsProject
from qgis.PyQt.QtCore import QAbstractItemModel, QModelIndex, Qt
from qgis.PyQt.QtWidgets import QHeaderView, QTableView, QWizardPage

from QgisModelBaker.libs.modelbaker.iliwrapper.ili2dbconfig import (
Ili2DbCommandConfiguration,
)
from QgisModelBaker.libs.modelbaker.utils import db_utils
from QgisModelBaker.libs.modelbaker.utils.ili2db_utils import Ili2DbUtils
from QgisModelBaker.libs.modelbaker.utils.qt_utils import make_file_selector
from QgisModelBaker.utils import gui_utils

Expand Down Expand Up @@ -288,14 +290,22 @@ def _refresh_combobox(self):

def _schema_changed(self):
configuration = self.schema_combobox.currentData()
parsed_from_file = False
if configuration:
db_connector = db_utils.get_db_connector(configuration)
if db_connector:
self.topping_wizard.topping.metaconfig.ili2db_settings.parse_parameters_from_db(
db_connector
_, tmp_ini_file = tempfile.mkstemp(".ini")

ili2db_utils = Ili2DbUtils()
ili2db_utils.log_on_error.connect(self._log_on_export_metagonfig_error)
res, msg = ili2db_utils.export_metaconfig(tmp_ini_file, configuration)
if res:
parsed_from_file = self.topping_wizard.topping.metaconfig.ili2db_settings.parse_parameters_from_ini_file(
tmp_ini_file
)
else:
if not parsed_from_file:
self.topping_wizard.topping.metaconfig.ili2db_settings.parameters = {}
self.parameters_model.refresh_model(
self.topping_wizard.topping.metaconfig.ili2db_settings.parameters
)

def _log_on_export_metagonfig_error(self, log):
QgsMessageLog.logMessage(log, self.tr("Export metaConfig"), Qgis.Critical)