Skip to content

Commit

Permalink
Fix - load_only, reset, error selection, test
Browse files Browse the repository at this point in the history
  • Loading branch information
mcharzat committed Aug 11, 2021
1 parent 10392df commit 5a83e07
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 9 deletions.
4 changes: 2 additions & 2 deletions QuickOSM/core/parser/osm_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def processing_parse(self):
uri + layer, file_name + ' ' + layer, 'ogr')

if not layers[layer].isValid():
message = tr('Error on the layer : {layer}').format(layer=layer)
message = tr('Error on the layer : {layer} is not valid.').format(layer=layer)
raise QuickOsmException(message)

return layers
Expand All @@ -125,7 +125,7 @@ def processing_parse(self):
uri + layer, 'test_' + layer, 'ogr')

if not layers[layer]['vectorLayer'].isValid():
message = 'Error on the layer : {layer}'.format(layer=layer)
message = 'Error on the layer : {layer} is not valid.'.format(layer=layer)
raise QuickOsmException(message)

if self.feedback_alg:
Expand Down
4 changes: 2 additions & 2 deletions QuickOSM/quick_osm.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
__license__ = 'GPL version 3'
__email__ = '[email protected]'

LOGGER = logging.getLogger(plugin_name())
LOGGER = logging.getLogger('QuickOSM')


class QuickOSMPlugin:
Expand Down Expand Up @@ -237,7 +237,7 @@ def run_tests():
try:
from pathlib import Path

from qgis_plugin_tools.infrastructure.test_runner import (
from QuickOSM.qgis_plugin_tools.infrastructure.test_runner import (
test_package,
)
test_package('{}.__init__'.format(Path(__file__).parent.name))
Expand Down
16 changes: 16 additions & 0 deletions QuickOSM/test/test_file_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import unittest

from qgis.core import QgsProject

from QuickOSM.definitions.osm import MultiType
from QuickOSM.qgis_plugin_tools.tools.resources import plugin_test_data_path
from QuickOSM.ui.dialog import Dialog
from QuickOSM.ui.osm_file_panel import OsmFilePanel

__copyright__ = 'Copyright 2021, 3Liz'
Expand Down Expand Up @@ -53,6 +56,19 @@ def test_generate_filter(self):
expected_exp = '\"foo\"=\'bar\' OR \"foofoo\"=\'barbar\''
self.assertEqual(expected_exp, expression)

def test_load_only(self):
"""Test if we can only load a file."""

dialog = Dialog()
dialog.osm_file.setFilePath(self.file)
dialog.radio_osm_conf.setChecked(True)
dialog.button_run_file.click()
project = QgsProject().instance()
nb_layers = len(project.mapLayers())
self.assertEqual(nb_layers, 4)

project.clear()


if __name__ == '__main__':
unittest.main()
18 changes: 16 additions & 2 deletions QuickOSM/ui/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ def reset_form(self):
"""Reset all the GUI to default state."""
LOGGER.info('Dialog has been reset')

# Map preset
self.list_personal_preset_mp.clearSelection()
self.list_default_mp.clearSelection()

# Quickquery
self.combo_preset_qq.setCurrentIndex(0)
self.table_keys_values_qq.setRowCount(1)
Expand All @@ -340,22 +344,32 @@ def reset_form(self):
self.table_keys_values_f.cellWidget(0, 1).setCurrentIndex(0)
self.table_keys_values_f.cellWidget(0, 2).lineEdit().setText('')

# Query type
for q_type in self.query_type_buttons.values():
q_type.setCurrentIndex(0)

# Place nominatim
for edit in self.places_edits.values():
edit.setText('')

# Option selected features
for option in self.selection_features.values():
option.setChecked(False)

# Output layers
for panel in self.output_buttons.values():
for output in panel:
output.setChecked(True)

# Directories
for edit in self.output_directories.values():
edit.lineEdit().setText('')
if edit:
edit.lineEdit().setText('')

# Prefix
for edit in self.prefix_edits.values():
edit.setText('')
if edit:
edit.setText('')

def set_progress_percentage(self, percent: int):
"""Slot to update percentage during process."""
Expand Down
5 changes: 3 additions & 2 deletions QuickOSM/ui/map_preset_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,6 @@ def prepare_run(self):
"""Prepare the data before running the process."""
selection = self.dialog.list_default_mp.selectedIndexes()
try:
if not len(selection):
raise NoSelectedPreset

if selection:
preset = self.dialog.list_default_mp.item(selection[0].row())
Expand All @@ -267,6 +265,9 @@ def prepare_run(self):
preset_folder = resources_path('map_preset')
else:
selection = self.dialog.list_personal_preset_mp.selectedIndexes()
if not len(selection):
raise NoSelectedPreset

preset = self.dialog.list_personal_preset_mp.item(selection[0].row())
preset_widget = self.dialog.list_personal_preset_mp.itemWidget(preset)
preset_label = preset_widget.layout().itemAt(0).itemAt(0).widget().text()
Expand Down
2 changes: 1 addition & 1 deletion QuickOSM/ui/osm_file_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def _run(self):
load_only=True,
osm_conf=properties['osm_conf'],
layers=output_geom_legacy)
layers = osm_parser.parse()
layers = osm_parser.processing_parse()
for item in layers.values():
# noinspection PyArgumentList
QgsProject.instance().addMapLayer(item)
Expand Down

0 comments on commit 5a83e07

Please sign in to comment.