Skip to content

Commit

Permalink
Handle XMLs separately
Browse files Browse the repository at this point in the history
  • Loading branch information
domi4484 committed Nov 30, 2023
1 parent 458f908 commit ea8e763
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
22 changes: 8 additions & 14 deletions QgisModelBaker/qgismodelbaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,22 +524,16 @@ 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())
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
41 changes: 28 additions & 13 deletions QgisModelBaker/utils/gui_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
"""
Expand Down

0 comments on commit ea8e763

Please sign in to comment.