Skip to content

Commit

Permalink
Merge pull request #815 from opengisch/tomlDragEDrop
Browse files Browse the repository at this point in the history
Drag&Drop support for extra meta attribute files (toml/ini)
  • Loading branch information
domi4484 authored Aug 14, 2023
2 parents 972fe0f + ca7497d commit 0309942
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
3 changes: 3 additions & 0 deletions QgisModelBaker/gui/ili2db_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ def set_toml_file_key(self, key_postfix):
self.toml_file_key = None
self.restore_configuration()

def set_toml_file(self, toml_file):
self.toml_file_line_edit.setText(toml_file)

def toml_file(self):
return self.toml_file_line_edit.text().strip()

Expand Down
19 changes: 16 additions & 3 deletions QgisModelBaker/gui/workflow_wizard/workflow_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* *
***************************************************************************/
"""
import logging
import os
import pathlib
import re
Expand Down Expand Up @@ -578,13 +579,25 @@ def add_source(self, source, origin_info):
path = None
return self.source_model.add_source(name, type, path, origin_info)

def append_dropped_files(self, dropped_files):
def append_dropped_files(self, dropped_files, dropped_ini_files):
if dropped_files:
for dropped_file in dropped_files:
self.add_source(
dropped_file, self.tr("Added by user with drag'n'drop.")
)

if dropped_ini_files:
if len(dropped_ini_files) > 1:
logging.warning(
"Only one INI/TOML file is supported by drag&drop: {}".format(
dropped_ini_files
)
)

self.schema_configuration_page.ili2db_options.set_toml_file(
dropped_ini_files[0]
)


class WorkflowWizardDialog(QDialog):
def __init__(self, iface, base_config, parent):
Expand All @@ -607,10 +620,10 @@ def __init__(self, iface, base_config, parent):
layout.addWidget(splitter)
self.setLayout(layout)

def append_dropped_files(self, dropped_files):
def append_dropped_files(self, dropped_files, dropped_ini_files):
"""
Appends the files, restarts the wizard and jumps to the next page (what is ImportSourceSelection)
"""
self.workflow_wizard.append_dropped_files(dropped_files)
self.workflow_wizard.append_dropped_files(dropped_files, dropped_ini_files)
self.workflow_wizard.restart()
self.workflow_wizard.next()
16 changes: 12 additions & 4 deletions QgisModelBaker/qgismodelbaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,11 @@ def create_project(
qgis_project = QgsProject.instance()
project.create(None, qgis_project, group)

def handle_dropped_files(self, dropped_files):
def handle_dropped_files(self, dropped_files, dropped_ini_files):
if not self.workflow_wizard_dlg:
self._set_dropped_file_configuration()
self.show_workflow_wizard_dialog()
self.workflow_wizard_dlg.append_dropped_files(dropped_files)
self.workflow_wizard_dlg.append_dropped_files(dropped_files, dropped_ini_files)
return True

def _set_dropped_file_configuration(self):
Expand Down Expand Up @@ -538,10 +538,18 @@ def eventFilter(self, obj, event):
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()
if pathlib.Path(url.toLocalFile()).suffix[1:]
in ["ini", "INI", "toml", "TOML"]
]
if dropped_files:
if self._is_handling_requested(dropped_files + additional_xml_files):
if self._is_handling_requested(
dropped_files + additional_xml_files + additional_ini_files
):
if self.parent.handle_dropped_files(
dropped_files + additional_xml_files
dropped_files + additional_xml_files, additional_ini_files
):
return True
return False

0 comments on commit 0309942

Please sign in to comment.