Skip to content

Commit

Permalink
On export, take over the datasource of a layer in the current project…
Browse files Browse the repository at this point in the history
…. You still can edit it. This - and the previous commits - resove #847
  • Loading branch information
signedav committed Jun 21, 2024
1 parent ef6f9a3 commit b89bb10
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
54 changes: 42 additions & 12 deletions QgisModelBaker/gui/workflow_wizard/database_selection_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
***************************************************************************/
"""

from qgis.core import QgsProject
from qgis.PyQt.QtCore import QSettings
from qgis.PyQt.QtWidgets import QWizardPage

from QgisModelBaker.gui.panel import db_panel_utils
from QgisModelBaker.libs.modelbaker.db_factory.db_simple_factory import DbSimpleFactory
from QgisModelBaker.libs.modelbaker.iliwrapper.globals import DbIliMode
from QgisModelBaker.libs.modelbaker.iliwrapper.ili2dbconfig import (
Ili2DbCommandConfiguration,
)
from QgisModelBaker.libs.modelbaker.utils import db_utils
from QgisModelBaker.libs.modelbaker.utils.globals import DbActionType
from QgisModelBaker.utils import gui_utils
Expand Down Expand Up @@ -83,21 +87,38 @@ def _type_changed(self):
if is_current_panel_selected:
value._show_panel()

def restore_configuration(self, configuration):
# takes settings from QSettings and provides it to the gui (not the configuration)
# it needs the configuration - this is the same for Schema or Data Config
settings = QSettings()
def restore_configuration(self, configuration, get_config_from_project=False):
configuration = Ili2DbCommandConfiguration()
valid = False
mode = None

if get_config_from_project:
# tries to take settings from the project
layer = self._relevant_layer()
if layer:
source_provider = layer.dataProvider()
valid, mode = db_utils.get_configuration_from_sourceprovider(
source_provider, configuration
)

for db_id in self.db_simple_factory.get_db_list(False):
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)
if valid and mode:
# uses the settings from the project and provides it to the gui
configuration.tool = mode
else:
# takes settings from QSettings and provides it to the gui
settings = QSettings()

mode = settings.value("QgisModelBaker/importtype")
mode = DbIliMode[mode] if mode else self.db_simple_factory.default_database
mode = mode & ~DbIliMode.ili
for db_id in self.db_simple_factory.get_db_list(False):
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()

mode = settings.value("QgisModelBaker/importtype")
mode = DbIliMode[mode] if mode else self.db_simple_factory.default_database
mode = mode & ~DbIliMode.ili
configuration.tool = mode

self._lst_panel[mode].set_fields(configuration)
self.type_combo_box.setCurrentIndex(self.type_combo_box.findData(mode))
self._type_changed()

Expand All @@ -119,6 +140,15 @@ def save_configuration(self, updated_configuration):
config_manager = db_factory.get_db_command_config_manager(updated_configuration)
config_manager.save_config_in_qsettings()

def _relevant_layer(self):
layer = None

for layer in [self.workflow_wizard.iface.activeLayer()] + list(
QgsProject.instance().mapLayers().values()
):
if layer and layer.dataProvider() and layer.dataProvider().isValid():
return layer

def is_valid(self):
db_id = self.type_combo_box.currentData()
res, message = self._lst_panel[db_id].is_valid()
Expand Down
2 changes: 1 addition & 1 deletion QgisModelBaker/gui/workflow_wizard/workflow_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def id_changed(self, new_id):

if self.current_id == PageIds.ExportDatabaseSelection:
self.export_database_selection_page.restore_configuration(
self.export_data_configuration
self.export_data_configuration, True
)

if self.current_id == PageIds.ImportSchemaConfiguration:
Expand Down

0 comments on commit b89bb10

Please sign in to comment.