Skip to content

Commit

Permalink
Merge pull request #824 from opengisch/fix_drop
Browse files Browse the repository at this point in the history
Support drop of INI Files as well in Source Selector
  • Loading branch information
signedav authored Sep 29, 2023
2 parents 2a3bbcc + 416644d commit 8f24470
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 12 additions & 2 deletions QgisModelBaker/gui/workflow_wizard/workflow_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
)
from QgisModelBaker.libs.modelbaker.utils.globals import DbActionType
from QgisModelBaker.utils.gui_utils import (
FileDropListView,
ImportDataModel,
ImportModelsModel,
LogColor,
Expand Down Expand Up @@ -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.")
)
Expand Down
6 changes: 3 additions & 3 deletions QgisModelBaker/qgismodelbaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand All @@ -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(
Expand Down
12 changes: 10 additions & 2 deletions QgisModelBaker/utils/gui_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -258,6 +259,7 @@ def dragEnterEvent(self, event):
if (
pathlib.Path(url.toLocalFile()).suffix[1:]
in FileDropListView.ValidExtenstions
+ FileDropListView.ValidIniExtensions
):
event.acceptProposedAction()
break
Expand All @@ -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()


Expand Down

0 comments on commit 8f24470

Please sign in to comment.