From 458f908f2a9bd2daad7b05870ad4fe968c455d00 Mon Sep 17 00:00:00 2001 From: Damiano Lombardi Date: Tue, 21 Nov 2023 16:54:51 +0100 Subject: [PATCH 1/2] Don't handle xml files again They are already handled by FileDropListView.ValidExtenstions Fix #837 --- QgisModelBaker/qgismodelbaker.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/QgisModelBaker/qgismodelbaker.py b/QgisModelBaker/qgismodelbaker.py index cd74c2c06..856d8b506 100644 --- a/QgisModelBaker/qgismodelbaker.py +++ b/QgisModelBaker/qgismodelbaker.py @@ -530,11 +530,6 @@ def eventFilter(self, obj, event): if pathlib.Path(url.toLocalFile()).suffix[1:] in FileDropListView.ValidExtenstions ] - additional_xml_files = [ - url.toLocalFile() - for url in event.mimeData().urls() - if pathlib.Path(url.toLocalFile()).suffix[1:] in ["xml", "XML"] - ] additional_ini_files = [ url.toLocalFile() for url in event.mimeData().urls() @@ -542,11 +537,9 @@ def eventFilter(self, obj, event): in FileDropListView.ValidIniExtensions ] if dropped_files: - if self._is_handling_requested( - dropped_files + additional_xml_files + additional_ini_files - ): + if self._is_handling_requested(dropped_files + additional_ini_files): if self.parent.handle_dropped_files( - dropped_files + additional_xml_files, additional_ini_files + dropped_files, additional_ini_files ): return True return False From ef6221fc0ccb35824054c7cee5d98408c68e3707 Mon Sep 17 00:00:00 2001 From: Damiano Lombardi Date: Thu, 30 Nov 2023 08:43:59 +0100 Subject: [PATCH 2/2] Handle XMLs separately --- QgisModelBaker/qgismodelbaker.py | 24 ++++++++---------- QgisModelBaker/utils/gui_utils.py | 41 +++++++++++++++++++++---------- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/QgisModelBaker/qgismodelbaker.py b/QgisModelBaker/qgismodelbaker.py index 856d8b506..20d66611a 100644 --- a/QgisModelBaker/qgismodelbaker.py +++ b/QgisModelBaker/qgismodelbaker.py @@ -524,22 +524,18 @@ def eventFilter(self, obj, event): When files are dropped, then ask to use it in the model baker. """ if event.type() == QEvent.Drop: - dropped_files = [ - url.toLocalFile() - for url in event.mimeData().urls() - if pathlib.Path(url.toLocalFile()).suffix[1:] - in FileDropListView.ValidExtenstions - ] - additional_ini_files = [ - url.toLocalFile() - for url in event.mimeData().urls() - if pathlib.Path(url.toLocalFile()).suffix[1:] - in FileDropListView.ValidIniExtensions - ] + ( + dropped_files, + dropped_xml_files, + dropped_ini_files, + ) = FileDropListView.extractDroppedFiles(event.mimeData().urls()) + + # Outside wizard, accept drops only for "real" interlis files, as xml and ini are too generic to assume must be handled by MB if dropped_files: - if self._is_handling_requested(dropped_files + additional_ini_files): + dropped_files.extend(dropped_xml_files) + if self._is_handling_requested(dropped_files + dropped_ini_files): if self.parent.handle_dropped_files( - dropped_files, additional_ini_files + dropped_files, dropped_ini_files ): return True return False diff --git a/QgisModelBaker/utils/gui_utils.py b/QgisModelBaker/utils/gui_utils.py index 6ac5b1d04..8c6ec1de3 100644 --- a/QgisModelBaker/utils/gui_utils.py +++ b/QgisModelBaker/utils/gui_utils.py @@ -244,7 +244,8 @@ class FileDropListView(QListView): List view allowing to drop ili and transfer files. """ - ValidExtenstions = ["xtf", "XTF", "itf", "ITF", "ili", "XML", "xml"] + ValidExtenstions = ["xtf", "XTF", "itf", "ITF", "ili"] + ValidXmlExtensions = ["XML", "xml"] ValidIniExtensions = ["ini", "INI", "toml", "TOML"] files_dropped = pyqtSignal(list, list) @@ -265,21 +266,35 @@ def dragEnterEvent(self, event): break def dropEvent(self, event): - dropped_files = [ - url.toLocalFile() - for url in event.mimeData().urls() - if pathlib.Path(url.toLocalFile()).suffix[1:] - in FileDropListView.ValidExtenstions - ] - dropped_ini_files = [ - url.toLocalFile() - for url in event.mimeData().urls() - if pathlib.Path(url.toLocalFile()).suffix[1:] - in FileDropListView.ValidIniExtensions - ] + dropped_files, dropped_xml_files, dropped_ini_files = self.extractDroppedFiles( + event.mimeData().urls() + ) + + dropped_files.extend(dropped_xml_files) self.files_dropped.emit(dropped_files, dropped_ini_files) event.acceptProposedAction() + @staticmethod + def extractDroppedFiles(url_list): + dropped_interlis_files = [] + dropped_xml_files = [] + dropped_ini_files = [] + for url in url_list: + local_file = url.toLocalFile() + suffix = pathlib.Path(local_file).suffix[1:] + if suffix in FileDropListView.ValidExtenstions: + dropped_interlis_files.append(local_file) + continue + + if suffix in FileDropListView.ValidXmlExtensions: + dropped_xml_files.append(local_file) + continue + + if suffix in FileDropListView.ValidIniExtensions: + dropped_ini_files.append(local_file) + + return dropped_interlis_files, dropped_xml_files, dropped_ini_files + class SourceModel(QStandardItemModel): """