From f9a1ed4f060ef5cfab5d0f40ace12d19fb104842 Mon Sep 17 00:00:00 2001 From: signedav Date: Thu, 7 Sep 2023 17:01:56 +0200 Subject: [PATCH 1/2] Support drop of INI Files as well in Source Selector and fix break of signal --- QgisModelBaker/utils/gui_utils.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/QgisModelBaker/utils/gui_utils.py b/QgisModelBaker/utils/gui_utils.py index 4ab1c117c..6ac5b1d04 100644 --- a/QgisModelBaker/utils/gui_utils.py +++ b/QgisModelBaker/utils/gui_utils.py @@ -245,8 +245,9 @@ class FileDropListView(QListView): """ ValidExtenstions = ["xtf", "XTF", "itf", "ITF", "ili", "XML", "xml"] + ValidIniExtensions = ["ini", "INI", "toml", "TOML"] - files_dropped = pyqtSignal(list) + files_dropped = pyqtSignal(list, list) def __init__(self, parent=None): super().__init__(parent) @@ -258,6 +259,7 @@ def dragEnterEvent(self, event): if ( pathlib.Path(url.toLocalFile()).suffix[1:] in FileDropListView.ValidExtenstions + + FileDropListView.ValidIniExtensions ): event.acceptProposedAction() break @@ -269,7 +271,13 @@ def dropEvent(self, event): if pathlib.Path(url.toLocalFile()).suffix[1:] in FileDropListView.ValidExtenstions ] - self.files_dropped.emit(dropped_files) + dropped_ini_files = [ + url.toLocalFile() + for url in event.mimeData().urls() + if pathlib.Path(url.toLocalFile()).suffix[1:] + in FileDropListView.ValidIniExtensions + ] + self.files_dropped.emit(dropped_files, dropped_ini_files) event.acceptProposedAction() From 416644d0cd02e42d40464da5fd76c11373e10dba Mon Sep 17 00:00:00 2001 From: signedav Date: Mon, 25 Sep 2023 16:31:08 +0200 Subject: [PATCH 2/2] add config files (ini/toml) to the list and be able to remove them in the source selector --- .../import_source_selection_page.py | 2 +- .../gui/workflow_wizard/workflow_wizard.py | 14 ++++++++++++-- QgisModelBaker/qgismodelbaker.py | 6 +++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/QgisModelBaker/gui/workflow_wizard/import_source_selection_page.py b/QgisModelBaker/gui/workflow_wizard/import_source_selection_page.py index f1b1343bc..fb82ee0ac 100644 --- a/QgisModelBaker/gui/workflow_wizard/import_source_selection_page.py +++ b/QgisModelBaker/gui/workflow_wizard/import_source_selection_page.py @@ -195,7 +195,7 @@ def _add_row(self): def _remove_selected_rows(self): indices = self.source_list_view.selectionModel().selectedIndexes() - self.source_list_view.model().remove_sources(indices) + self.workflow_wizard.remove_sources(indices) self.remove_button.setEnabled(self._valid_selection()) def _clear_cache_button_clicked(self): diff --git a/QgisModelBaker/gui/workflow_wizard/workflow_wizard.py b/QgisModelBaker/gui/workflow_wizard/workflow_wizard.py index cd580dffb..3db32c7d8 100644 --- a/QgisModelBaker/gui/workflow_wizard/workflow_wizard.py +++ b/QgisModelBaker/gui/workflow_wizard/workflow_wizard.py @@ -56,6 +56,7 @@ ) from QgisModelBaker.libs.modelbaker.utils.globals import DbActionType from QgisModelBaker.utils.gui_utils import ( + FileDropListView, ImportDataModel, ImportModelsModel, LogColor, @@ -579,9 +580,18 @@ def add_source(self, source, origin_info): path = None return self.source_model.add_source(name, type, path, origin_info) + def remove_sources(self, indices): + # if it's a ini/toml file that should be removed, then remove it from the config + if ( + indices[0].data(int(SourceModel.Roles.TYPE)) + in FileDropListView.ValidIniExtensions + ): + self.schema_configuration_page.ili2db_options.set_toml_file("") + return self.source_model.remove_sources(indices) + def append_dropped_files(self, dropped_files, dropped_ini_files): - if dropped_files: - for dropped_file in dropped_files: + if dropped_files or dropped_ini_files: + for dropped_file in dropped_files + dropped_ini_files: self.add_source( dropped_file, self.tr("Added by user with drag'n'drop.") ) diff --git a/QgisModelBaker/qgismodelbaker.py b/QgisModelBaker/qgismodelbaker.py index 1eab2c05d..cd74c2c06 100644 --- a/QgisModelBaker/qgismodelbaker.py +++ b/QgisModelBaker/qgismodelbaker.py @@ -54,7 +54,7 @@ from QgisModelBaker.libs.modelbaker.dataobjects.project import Project from QgisModelBaker.libs.modelbaker.generator.generator import Generator from QgisModelBaker.libs.modelbaker.iliwrapper.ili2dbconfig import BaseConfiguration -from QgisModelBaker.utils.gui_utils import DropMode +from QgisModelBaker.utils.gui_utils import DropMode, FileDropListView class QgisModelBakerPlugin(QObject): @@ -528,7 +528,7 @@ def eventFilter(self, obj, event): url.toLocalFile() for url in event.mimeData().urls() if pathlib.Path(url.toLocalFile()).suffix[1:] - in ["xtf", "XTF", "itf", "ITF", "ili"] + in FileDropListView.ValidExtenstions ] additional_xml_files = [ url.toLocalFile() @@ -539,7 +539,7 @@ def eventFilter(self, obj, event): url.toLocalFile() for url in event.mimeData().urls() if pathlib.Path(url.toLocalFile()).suffix[1:] - in ["ini", "INI", "toml", "TOML"] + in FileDropListView.ValidIniExtensions ] if dropped_files: if self._is_handling_requested(