Commit 3c25bb16 authored by Benjamin Jakimow's avatar Benjamin Jakimow
Browse files

Merge remote-tracking branch 'origin/develop' into develop

parents 02b27a7d 328e92df
......@@ -27,10 +27,11 @@
import pathlib
import sys
import typing
from qgis.core import QgsApplication
import warnings
from qgis.core import QgsApplication, Qgis
from qgis.gui import QgsMapLayerConfigWidgetFactory
MIN_QGIS_VERSION = '3.14'
__version__ = '1.0'
DIR_QPS = pathlib.Path(__file__).parent
......@@ -40,6 +41,8 @@ QPS_RESOURCE_FILE = DIR_QPS / 'qpsresources_rc.py'
MAPLAYER_CONFIGWIDGET_FACTORIES = list()
if Qgis.QGIS_VERSION < MIN_QGIS_VERSION:
warnings.warn(f'Your QGIS is outdated. Please update to QGIS >= {MIN_QGIS_VERSION}', RuntimeWarning)
def registerMapLayerConfigWidgetFactory(factory: QgsMapLayerConfigWidgetFactory):
"""
......
......@@ -236,6 +236,9 @@ class CursorLocationMapTool(QgsMapToolEmitPoint):
self.marker.setIconType(QgsVertexMarker.ICON_CROSS) # or ICON_CROSS, ICON_X
self.hideRubberband()
def flags(self) -> QgsMapTool.Flags:
return QgsMapTool.ShowContextMenu
def setMouseButtons(self, listOfButtons):
assert isinstance(listOfButtons)
self.mButtons = listOfButtons
......@@ -311,14 +314,19 @@ class MapToolCenter(CursorLocationMapTool):
:type canvas: QgsMapCanvas
"""
super(MapToolCenter, self).__init__(canvas)
self.sigLocationRequest.connect(self.setMapCenter)
self.sigLocationRequest[QgsCoordinateReferenceSystem, QgsPointXY].\
connect(lambda crs, pt: self.setMapCenter(SpatialPoint(crs, pt)))
def flags(self) -> QgsMapTool.Flags:
return QgsMapTool.ShowContextMenu
def setMapCenter(self, point: SpatialPoint):
"""
Call to center the linked QgsMapCanvas to a point
:param point: SpatialPoint to center the map canvas to.
"""
point = point.toCrs(self.canvas().destinationCrs())
assert isinstance(point, SpatialPoint)
point = point.toCrs(self.canvas().mapSettings().destinationCrs())
if isinstance(point, SpatialPoint):
self.canvas().setCenter(point)
self.canvas().refresh()
......@@ -336,12 +344,11 @@ class PixelScaleExtentMapTool(QgsMapTool):
self.setCursor(self.mCursor)
canvas.setCursor(self.mCursor)
def flags(self):
def flags(self) -> QgsMapTool.Flags:
"""
:return:
"""
return QgsMapTool.Transient
return QgsMapTool.Transient | QgsMapTool.ShowContextMenu
def canvasReleaseEvent(self, mouseEvent: QgsMapMouseEvent):
"""
......@@ -385,7 +392,7 @@ class FullExtentMapTool(QgsMapTool):
self.canvas().zoomToFullExtent()
def flags(self):
return QgsMapTool.Transient
return QgsMapTool.Transient | QgsMapTool.ShowContextMenu
class PointLayersMapTool(CursorLocationMapTool):
......@@ -396,6 +403,8 @@ class PointLayersMapTool(CursorLocationMapTool):
self.identifyMode = QgsMapToolIdentify.LayerSelection
QgsMapToolIdentify.__init__(self, canvas)
def flags(self) -> QgsMapTool.Flags:
return QgsMapTool.ShowContextMenu
class SpatialExtentMapTool(QgsMapToolEmitPoint):
"""
......@@ -410,6 +419,9 @@ class SpatialExtentMapTool(QgsMapToolEmitPoint):
self.setStyle(Qt.red, 1)
self.reset()
def flags(self) -> QgsMapTool.Flags:
return QgsMapTool.ShowContextMenu
def setStyle(self, color: QColor, width: int):
"""
Sets the style of the rectangle shows when selecting the SpatialExtent
......@@ -486,6 +498,9 @@ class RectangleMapTool(QgsMapToolEmitPoint):
self.rubberBand.setWidth(1)
self.reset()
def flags(self) -> QgsMapTool:
return QgsMapTool.ShowContextMenu
def reset(self):
self.startPoint = self.endPoint = None
self.isEmittingPoint = False
......@@ -1723,6 +1738,9 @@ class QgsMapToolSelect(QgsMapTool):
self.mSelectionHandler.geometryChanged.connect(self.selectFeatures)
self.setSelectionMode(QgsMapToolSelectionHandler.SelectionMode.SelectSimple)
def flags(self) -> QgsMapTool.Flags:
return QgsMapTool.ShowContextMenu
def setSelectionMode(self, selectionMode: QgsMapToolSelectionHandler.SelectionMode):
self.mSelectionHandler.setSelectionMode(selectionMode)
if selectionMode == QgsMapToolSelectionHandler.SelectionMode.SelectSimple:
......
......@@ -43,7 +43,7 @@ from qgis.core import QgsMapLayer, QgsRasterLayer, QgsVectorLayer, QgsContrastEn
from qgis.gui import QgsMapCanvas, QgisInterface, QgsFloatingWidget, QgsUserInputWidget, \
QgsAdvancedDigitizingDockWidget, QgsMapCanvasItem, \
QgsMapTool, QgsMapToolPan, QgsMapToolZoom, QgsMapToolCapture, QgsMapToolIdentify, \
QgsGeometryRubberBand
QgsGeometryRubberBand, QgsMapMouseEvent
from .externals.qps.classification.classificationscheme import ClassificationScheme, ClassInfo
......@@ -396,7 +396,7 @@ class MapCanvas(QgsMapCanvas):
self.mMapLayerStore: QgsProject = QgsProject.instance()
if Qgis.QGIS_VERSION >= '3.16':
self.contextMenuAboutToShow.connect(self.createContextMenu)
self.contextMenuAboutToShow.connect(self.populateContextMenu)
self.mMapTools = None
......@@ -887,7 +887,7 @@ class MapCanvas(QgsMapCanvas):
"""
return self.grab()
def createContextMenu(self, menu: QMenu, pos: QPoint):
def populateContextMenu(self, menu: QMenu, pos: QPoint):
"""
Creates the MapCanvas context menu with options relevant for pixel position ``pos``.
:param pos: QPoint
......@@ -1252,19 +1252,22 @@ class MapCanvas(QgsMapCanvas):
r.setInput(proxyLayer.dataProvider())
proxyLayer.setRenderer(r)
def contextMenuEvent(self, event: QContextMenuEvent):
"""
Create and shows the MapCanvas context menu.
:param event: QEvent
"""
def mousePressEvent(self, event: QMouseEvent):
if Qgis.QGIS_VERSION >= '3.16':
super(MapCanvas, self).contextMenuEvent(event)
super(MapCanvas, self).mousePressEvent(event)
else:
if not isinstance(self.mapTool(), QgsMapToolCapture):
menu = QMenu()
self.createContextMenu(menu, event.pos())
menu.exec_(event.globalPos())
if event.button() == Qt.RightButton:
mt: QgsMapTool = self.mapTool()
if isinstance(mt, QgsMapTool):
if bool(mt.flags() & QgsMapTool.ShowContextMenu):
menu = QMenu()
mt.populateContextMenu(menu)
self.populateContextMenu(menu, event.pos())
menu.exec_(event.globalPos())
return
super().mousePressEvent(event)
def addLayers2QGIS(self, mapLayers):
import qgis.utils
......
......@@ -320,7 +320,7 @@ class TestMapVisualization(EOTSVTestCase):
self.assertIsInstance(mv, MapView)
for l in mv.layers():
eotsv.setCurrentLayer(l)
mv.mMapLayerTreeViewMenuProvider.createContextMenu()
mv.mMapLayerTreeViewMenuProvider.populateContextMenu()
def test_renderer(self):
styleFiles = file_search(os.path.dirname(__file__), 'style*.txt')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment