Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
[general]
name=Red Layer
qgisMinimumVersion=2.99
qgisMaximumVersion=3.99
qgisMaximumVersion=4.99
supportsQt6=True
description=quick georeferenced sketches and annotations
version=2.2
author=Enrico Ferreguti
Expand Down
2 changes: 1 addition & 1 deletion note_class_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def newPoint(iface, segment, txt=None):
if not txt:
result = dialog.exec_()
dialog.show()
if QDialog.Accepted:
if QDialog.DialogCode.Accepted:
return dialog.getAnnotation()
else:
return None
Expand Down
28 changes: 18 additions & 10 deletions redLayerModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
QVariant,
)
from qgis.PyQt.QtGui import QColor, QIcon, QTextDocument
from qgis.PyQt.QtWidgets import QAction, QFileDialog, QMenu
from qgis.PyQt.QtWidgets import QAction, QFileDialog, QMenu, QToolButton
from qgis.utils import iface

# project package
Expand Down Expand Up @@ -262,7 +262,9 @@ def initGui(self):
path.join(self.plugin_dir, 'icons', 'canvas.svg'),
text=self.tr('Color and width canvas'),
callback=None,
parent=self.iface.mainWindow())
parent=self.iface.mainWindow(),
add_to_toolbar=False,
object_name='mCanvasAction')
self.eraseButton = self.add_action(
path.join(self.plugin_dir, 'icons', 'erase.svg'),
text=self.tr('Erase sketches'),
Expand Down Expand Up @@ -299,7 +301,13 @@ def initGui(self):
callback=self.loadAction,
parent=self.iface.mainWindow(),
object_name='mLoadSketchesFromFile')
self.canvasButton.setMenu(self.canvasMenu())
# create explicit QToolButton for canvas action (Qt5 & Qt6)
canvas_toolbutton = QToolButton(self.iface.mainWindow())
canvas_toolbutton.setDefaultAction(self.canvasButton)
canvas_toolbutton.setMenu(self.canvasMenu())
Comment thread
Nimrod51 marked this conversation as resolved.
canvas_toolbutton.setPopupMode(QToolButton.ToolButtonPopupMode.InstantPopup)
self.toolbar.addWidget(canvas_toolbutton)
self.canvasToolButton = canvas_toolbutton
self.noteButton.setCheckable(True)
self.penButton.setCheckable(True)
self.sketchButton.setCheckable(True)
Expand Down Expand Up @@ -458,7 +466,7 @@ def deactivate(self):

def canvasPressEvent(self, event):
# Press event handler inherited from QgsMapTool
if event.button() == Qt.RightButton:
if event.button() == Qt.MouseButton.RightButton:
if self.noteButton.isChecked():
midIdx = -int(self.points/2)
if midIdx == 0:
Expand Down Expand Up @@ -490,7 +498,7 @@ def canvasPressEvent(self, event):
snappedPoint = self.snapSys.snapToMap(self.pressedPoint)
if snappedPoint.isValid():
self.pressedPoint = snappedPoint.point()
self.sketch = QgsRubberBand(self.iface.mapCanvas(), QgsWkbTypes.LineGeometry)
self.sketch = QgsRubberBand(self.iface.mapCanvas(), QgsWkbTypes.GeometryType.LineGeometry)
self.sketch.setWidth(self.currentWidth)
self.sketch.setColor(self.currentColor)
self.sketch.addPoint(self.pressedPoint)
Expand All @@ -503,7 +511,7 @@ def canvasMoveEvent(self, event):
self.movedPoint = self.canvas.getCoordinateTransform().toMapCoordinates(x, y)
if self.canvasAction == "sketch":
if abs(x-self.px) > 3 or abs(y-self.py) > 3:
sketch = QgsRubberBand(self.iface.mapCanvas(), QgsWkbTypes.LineGeometry)
sketch = QgsRubberBand(self.iface.mapCanvas(), QgsWkbTypes.GeometryType.LineGeometry)
sketch.setWidth(self.currentWidth)
sketch.setColor(self.currentColor)
sketch.addPoint(self.pressedPoint)
Expand Down Expand Up @@ -543,7 +551,7 @@ def canvasMoveEvent(self, event):
logger.error(err)

def canvasReleaseEvent(self, event):
if event.button() == Qt.RightButton:
if event.button() == Qt.MouseButton.RightButton:
return
self.pressed = None
QgsProject.instance().setDirty(True)
Expand Down Expand Up @@ -647,9 +655,9 @@ def saveSketches(self, userFile=None):

# use Qt custom FileDialog to be more consistent with QGIS ui
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
options |= QFileDialog.Option.DontUseNativeDialog

# assk user where he wants to save his annotations
# ask user where he wants to save his annotations
sketch_filepath, sketch_suffix_filter = QFileDialog().getSaveFileName(
parent=None,
caption=self.tr("Save RedLayer sketches"),
Expand Down Expand Up @@ -740,7 +748,7 @@ def loadSketches(self, userFile=None):
print (line.replace("srs|","").replace("\n",""),source_srs, QgsProject.instance().crs())
continue
inline = line.split("|")
sketch = QgsRubberBand(self.iface.mapCanvas(), QgsWkbTypes.LineGeometry)
sketch = QgsRubberBand(self.iface.mapCanvas(), QgsWkbTypes.GeometryType.LineGeometry)
sketch.setWidth(int(inline[1]))
sketch.setColor(QColor(inline[0]))
load_geom = QgsGeometry.fromWkt(inline[2])
Expand Down