commit 5dcc4bc15a109d6dd30086917629efa664b66515
parent f6d7559e83c8b55795bdf38416418c054ac5d18c
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Fri, 5 Jun 2026 21:47:04 +0300
feat: replace print with QgsMessageLog; add QgsPlotTool fallback in deactivate (B1+B2+T5)
Diffstat:
2 files changed, 42 insertions(+), 5 deletions(-)
diff --git a/profile_interpreter/profile_interpreter.py b/profile_interpreter/profile_interpreter.py
@@ -30,6 +30,7 @@ from qgis.core import (
QgsFeature,
QgsField,
QgsGeometry,
+ QgsMessageLog,
QgsPoint,
QgsPointXY,
QgsProject,
@@ -168,7 +169,9 @@ class ProfileInterpreterPlugin:
if self._canvas is not None and self._pick_tool is not None:
if QgsPlotToolPan is not None:
self._pan_tool = QgsPlotToolPan(self._canvas)
- self._canvas.setTool(self._pan_tool)
+ else:
+ self._pan_tool = QgsPlotTool(self._canvas, 'Inactive')
+ self._canvas.setTool(self._pan_tool)
self._pick_tool = None
self._canvas = None
@@ -230,10 +233,10 @@ class ProfileInterpreterPlugin:
canvas.refresh()
id_label = f' #{feature_id}' if feature_id is not None else ''
- print(
- f'{MENU}: placed point{id_label} '
- f'at x={x:.3f} y={y:.3f} z={elevation:.3f} '
- f'(distance={distance:.3f})'
+ QgsMessageLog.logMessage(
+ f'placed point{id_label} at x={x:.3f} y={y:.3f} z={elevation:.3f} '
+ f'(distance={distance:.3f})',
+ MENU, level=Qgis.Info,
)
self.iface.messageBar().pushMessage(
MENU,
diff --git a/test/test_profile_interpreter.py b/test/test_profile_interpreter.py
@@ -448,5 +448,39 @@ class TestOnPickAddFeaturesFailure(unittest.TestCase):
self.assertEqual(canvas.refresh_count, 0)
+# ── _deactivate ───────────────────────────────────────────────────────────
+
+class TestDeactivate(unittest.TestCase):
+ def _make_active_plugin(self):
+ canvas = _FakeCanvas()
+ iface = _FakeIface()
+ plugin = ProfileInterpreterPlugin(iface)
+ plugin._canvas = canvas
+ pick_tool = fq.QgsPlotTool(canvas, 'test')
+ plugin._pick_tool = pick_tool
+ canvas._tool = pick_tool
+ return plugin, canvas, pick_tool
+
+ def test_pick_tool_replaced_when_pan_available(self):
+ plugin, canvas, pick_tool = self._make_active_plugin()
+ plugin._deactivate()
+ self.assertIsNot(canvas._tool, pick_tool)
+ self.assertIsNone(plugin._pick_tool)
+ self.assertIsNone(plugin._canvas)
+
+ def test_pick_tool_replaced_when_pan_none(self):
+ import profile_interpreter.profile_interpreter as pi_module
+ plugin, canvas, pick_tool = self._make_active_plugin()
+ original = pi_module.QgsPlotToolPan
+ pi_module.QgsPlotToolPan = None
+ try:
+ plugin._deactivate()
+ finally:
+ pi_module.QgsPlotToolPan = original
+ self.assertIsNot(canvas._tool, pick_tool)
+ self.assertIsNone(plugin._pick_tool)
+ self.assertIsNone(plugin._canvas)
+
+
if __name__ == '__main__':
unittest.main()