Skip to content

Commit

Permalink
Merge pull request #72 from traveltime-dev/2023-01_fix-tiles
Browse files Browse the repository at this point in the history
fix #54: exception with tiles actions
  • Loading branch information
olivierdalang authored Jan 3, 2023
2 parents f3620da + 8f2a5bc commit 15997ca
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 14 deletions.
41 changes: 27 additions & 14 deletions travel_time_platform_plugin/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
QLineEdit,
QMessageBox,
QPushButton,
QSplitter,
QTreeView,
QWidget,
)

from . import express, resources, tests, tiles, ui
Expand Down Expand Up @@ -212,22 +210,37 @@ def show_tiles(self):
browser.raise_()

# Get the XYZ item of the treeview
treeview = (
self.iface.mainWindow()
.findChild(QDockWidget, "Browser")
.findChild(QWidget, "mContents")
.findChild(QSplitter)
.widget(0)
.findChild(QTreeView)
)
treeview = browser.findChild(QTreeView)
model = treeview.model()
xyz_tiles_group_idx = model.match(
model.index(0, 0),
Qt.DisplayRole,
"XYZ Tiles",
)
if len(xyz_tiles_group_idx) == 0:
# Shouldn't happen, but let's play safe
return

match = model.match(model.index(0, 0), Qt.DisplayRole, "XYZ Tiles")[0]
# Fold everything and display it
treeview.collapseAll()
treeview.clearSelection()
treeview.expand(match)
treeview.setCurrentIndex(match)
treeview.scrollTo(match)
treeview.expand(xyz_tiles_group_idx[0])
treeview.setCurrentIndex(xyz_tiles_group_idx[0])
treeview.scrollTo(xyz_tiles_group_idx[0])

# If tiles were loaded, selected it
lux_tiles_idx = model.match(
model.index(0, 0, xyz_tiles_group_idx[0]),
Qt.DisplayRole,
"TravelTime - Lux",
)
if len(lux_tiles_idx) == 0:
# If not loaded (because missing API), good enough, we showed background tiles
return

# Display it
treeview.setCurrentIndex(lux_tiles_idx[0])
treeview.scrollTo(lux_tiles_idx[0])

def show_config(self):
self.config_dialog.exec_()
Expand Down
1 change: 1 addition & 0 deletions travel_time_platform_plugin/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def run_suite(stream) -> unittest.TestResult:
[
"travel_time_platform_plugin.tests.tests_express_tools",
"travel_time_platform_plugin.tests.tests_algorithms",
"travel_time_platform_plugin.tests.tests_misc",
]
)
runner = unittest.TextTestRunner(stream=stream, verbosity=2)
Expand Down
41 changes: 41 additions & 0 deletions travel_time_platform_plugin/tests/tests_misc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from qgis.PyQt.QtWidgets import QDockWidget, QTreeView
from qgis.utils import iface

from .base import TestCaseBase


class MiscTest(TestCaseBase):
"""Testing other features"""

def test_loading_map_tiles(self):

browser = iface.mainWindow().findChild(QDockWidget, "Browser")
treeview = browser.findChild(QTreeView)
model = treeview.model()

# Hide the browser
browser.setVisible(False)
# Select the first item
treeview.setCurrentIndex(model.index(0, 0))

self._feedback()

# Ensure the browser is hidden
self.assertFalse(browser.isVisible())
# Ensure the XYZ layer is not selected
self.assertNotEqual(
model.data(treeview.currentIndex()),
"TravelTime - Lux",
)

# Use the action
self.plugin.action_show_tiles.trigger()
self._feedback()

# Ensure the panel got shown
self.assertTrue(browser.isVisible())
# Ensure the XYZ layer got selected
self.assertEqual(
model.data(treeview.currentIndex()),
"TravelTime - Lux",
)

0 comments on commit 15997ca

Please sign in to comment.