QGIS API Documentation 3.99.0-Master (7d2ca374f2d)
Loading...
Searching...
No Matches
qgsmaptoolselectannotation.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaptoolselectannotation.h
3 ----------------
4 copyright : (C) 2025 by Mathieu Pellerin
5 email : mathieu at opengis dot ch
6 ***************************************************************************/
7
8/***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17#ifndef QGSMAPTOOLSELECTANNOTATION_H
18#define QGSMAPTOOLSELECTANNOTATION_H
19
20#include "qgis_gui.h"
21#include "qgis_sip.h"
26#include "qgspointxy.h"
27#include "qgsrectangle.h"
28#include "qgsrubberband.h"
29#include "qobjectuniqueptr.h"
30
31#define SIP_NO_FILE
32
33class QgsRubberBand;
37class QgsAnnotationItemNodesSpatialIndex;
38class QgsMapToolSelectAnnotationMouseHandles;
39
40
48{
49 Q_OBJECT
50
51 public:
55 explicit QgsAnnotationItemRubberBand( const QString &layerId, const QString &itemId, QgsMapCanvas *canvas );
56 ~QgsAnnotationItemRubberBand() override = default;
57
61 QString layerId() const { return mLayerId; }
62
66 QgsAnnotationLayer *layer() const;
67
71 QString itemId() const { return mItemId; }
72
76 QgsAnnotationItem *item() const;
77
81 QgsRectangle boundingBox() const { return mBoundingBox; }
82
86 void updateBoundingBox( const QgsRectangle &boundingBox );
87
91 bool needsUpdatedBoundingBox() const { return mNeedsUpdatedBoundingBox; }
92
96 void setNeedsUpdatedBoundingBox( bool needsUpdatedBoundingBox );
97
98 private:
99 QString mLayerId;
100 QString mItemId;
101 QgsRectangle mBoundingBox;
102 bool mNeedsUpdatedBoundingBox = true;
103};
104
105
113{
114 Q_OBJECT
115
116 public:
122
123 void activate() override;
124 void deactivate() override;
125 void cadCanvasMoveEvent( QgsMapMouseEvent *event ) override;
126 void cadCanvasPressEvent( QgsMapMouseEvent *event ) override;
127 void cadCanvasReleaseEvent( QgsMapMouseEvent *event ) override;
128 void keyPressEvent( QKeyEvent *event ) override;
129 bool shortcutEvent( QKeyEvent *event ) override;
130
134 QList<QgsAnnotationItemRubberBand *> selectedItems() const;
135
142 void attemptMoveBy( QgsAnnotationItemRubberBand *annotationItemRubberBand, double deltaX, double deltaY );
143
149 void attemptRotateBy( QgsAnnotationItemRubberBand *annotationItemRubberBand, double deltaDegree );
150
156 void attemptSetSceneRect( QgsAnnotationItemRubberBand *annotationItemRubberBand, const QRectF &rect );
157
158 signals:
159
164
168 void singleItemSelected( QgsAnnotationLayer *layer, const QString &itemId );
169
174
179
180 private slots:
181 void onCanvasRefreshed();
182
183 private:
184 long long annotationItemRubberBandIndexFromId( const QString &layerId, const QString &itemId );
185
186 void setSelectedItemFromPoint( const QgsPointXY &mapPoint, bool toggleSelection = false );
187 void setSelectedItemsFromRect( const QgsRectangle &mapRect, bool toggleSelection = false );
188 void clearSelectedItems();
189 void updateSelectedItem();
190
191 std::vector<std::unique_ptr<QgsAnnotationItemRubberBand>> mSelectedItems;
192 std::vector<std::unique_ptr<QgsAnnotationItem>> mCopiedItems;
193 QgsPointXY mCopiedItemsTopLeft;
194
196 bool mHoveringMouseHandles = false;
197 QPointF mLastScenePos;
198
199 QObjectUniquePtr<QgsRubberBand> mSelectionRubberBand;
200 QRect mSelectionRect;
201
202 bool mDragging = false;
203 bool mCanceled = false;
204};
205
206#endif // QGSMAPTOOLSELECTANNOTATION_H
Keeps a pointer to a QObject and deletes it whenever this object is deleted.
A dockable widget used to handle the CAD tools on top of a selection of map tools.
An annotation item rubberband used by QgsMapToolSelectAnnotation to represent selected items.
bool needsUpdatedBoundingBox() const
Returns true if the bounding box requires updating on fresh annotation item rendering.
QgsRectangle boundingBox() const
Returns the item bounding box.
QString itemId() const
Returns the annotation item ID.
QgsAnnotationItemRubberBand(const QString &layerId, const QString &itemId, QgsMapCanvas *canvas)
Constructor for QgsAnnotationItemRubberBand.
QString layerId() const
Returns the annotation layer ID.
~QgsAnnotationItemRubberBand() override=default
Abstract base class for annotation items which are drawn with QgsAnnotationLayers.
Represents a map layer containing a set of georeferenced annotations, e.g.
QgsAnnotationMapTool(QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget)
Constructor for QgsAnnotationMapTool.
Map canvas is a class for displaying all GIS data types on a canvas.
A mouse event which is the result of a user interaction with a QgsMapCanvas.
virtual QgsMapLayer * layer() const
Returns the layer associated with the map tool.
QgsAdvancedDigitizingDockWidget * cadDockWidget() const
QList< QgsAnnotationItemRubberBand * > selectedItems() const
Returns the current list of selected annotation item rubberband items.
void cadCanvasReleaseEvent(QgsMapMouseEvent *event) override
Override this method when subclassing this class.
void singleItemSelected(QgsAnnotationLayer *layer, const QString &itemId)
Emitted when the selected items list has changed and a single item is selected.
void attemptRotateBy(QgsAnnotationItemRubberBand *annotationItemRubberBand, double deltaDegree)
Attempts to rotate am annotation item.
void keyPressEvent(QKeyEvent *event) override
Key event for overriding. Default implementation does nothing.
void activate() override
Registers this maptool with the cad dock widget.
void attemptSetSceneRect(QgsAnnotationItemRubberBand *annotationItemRubberBand, const QRectF &rect)
Attempts to move and resize an annotation item.
QgsMapToolSelectAnnotation(QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget)
Constructor for QgsMapToolSelectAnnotation.
void multipleItemsSelected()
Emitted when the selected items list has changed and multiple items are selected.
void cadCanvasMoveEvent(QgsMapMouseEvent *event) override
Override this method when subclassing this class.
void attemptMoveBy(QgsAnnotationItemRubberBand *annotationItemRubberBand, double deltaX, double deltaY)
Attempts to move an annotation item.
void cadCanvasPressEvent(QgsMapMouseEvent *event) override
Override this method when subclassing this class.
void selectedItemsChanged()
Emitted when the selected items list has changed.
void selectionCleared()
Emitted when the selected items list is cleared.
void deactivate() override
Unregisters this maptool from the cad dock widget.
bool shortcutEvent(QKeyEvent *event) override
Shortcut events coming from the application for overriding.
QgsMapCanvas * canvas() const
returns pointer to the tool's map canvas
Represents a 2D point.
Definition qgspointxy.h:62
A rectangle specified with double values.
Contains information about a rendered annotation item.
Responsible for drawing transient features (e.g.
QgsRubberBand(QgsMapCanvas *mapCanvas, Qgis::GeometryType geometryType=Qgis::GeometryType::Line)
Creates a new RubberBand.