From ef6221fc0ccb35824054c7cee5d98408c68e3707 Mon Sep 17 00:00:00 2001 From: Damiano Lombardi Date: Thu, 30 Nov 2023 08:43:59 +0100 Subject: [PATCH] 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): """