QGIS API Documentation 3.99.0-Master (1d785854362)
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
31class QgsRubberBand;
35class QgsAnnotationItemNodesSpatialIndex;
36class QgsMapToolSelectAnnotationMouseHandles;
37
38#define SIP_NO_FILE
39
47{
48 Q_OBJECT
49
50 public:
54 explicit QgsAnnotationItemRubberBand( const QString &layerId, const QString &itemId, QgsMapCanvas *canvas );
55 ~QgsAnnotationItemRubberBand() override = default;
56
60 QString layerId() const { return mLayerId; }
61
65 QgsAnnotationLayer *layer() const;
66
70 QString itemId() const { return mItemId; }
71
75 QgsAnnotationItem *item() const;
76
80 QgsRectangle boundingBox() const { return mBoundingBox; }
81
85 void updateBoundingBox( const QgsRectangle &boundingBox );
86
90 bool needsUpdatedBoundingBox() const { return mNeedsUpdatedBoundingBox; }
91
95 void setNeedsUpdatedBoundingBox( bool needsUpdatedBoundingBox );
96
97 private:
98 QString mLayerId;
99 QString mItemId;
100 QgsRectangle mBoundingBox;
101 bool mNeedsUpdatedBoundingBox = true;
102};
103
104
112{
113 Q_OBJECT
114
115 public:
121
122 void activate() override;
123 void deactivate() override;
124 void cadCanvasMoveEvent( QgsMapMouseEvent *event ) override;
125 void cadCanvasPressEvent( QgsMapMouseEvent *event ) override;
126 void cadCanvasReleaseEvent( QgsMapMouseEvent *event ) override;
127 void keyPressEvent( QKeyEvent *event ) override;
128 bool shortcutEvent( QKeyEvent *event ) override;
129
133 QList<QgsAnnotationItemRubberBand *> selectedItems() const;
134
141 void attemptMoveBy( QgsAnnotationItemRubberBand *annotationItemRubberBand, double deltaX, double deltaY );
142
148 void attemptRotateBy( QgsAnnotationItemRubberBand *annotationItemRubberBand, double deltaDegree );
149
155 void attemptSetSceneRect( QgsAnnotationItemRubberBand *annotationItemRubberBand, const QRectF &rect );
156
157 signals:
158
163
167 void singleItemSelected( QgsAnnotationLayer *layer, const QString &itemId );
168
173
178
179 private slots:
180 void onCanvasRefreshed();
181
182 private:
183 long long annotationItemRubberBandIndexFromId( const QString &layerId, const QString &itemId );
184
185 void setSelectedItemFromPoint( const QgsPointXY &mapPoint, bool toggleSelection = false );
186 void setSelectedItemsFromRect( const QgsRectangle &mapRect, bool toggleSelection = false );
187 void clearSelectedItems();
188 void updateSelectedItem();
189
190 std::vector<std::unique_ptr<QgsAnnotationItemRubberBand>> mSelectedItems;
191 std::vector<std::unique_ptr<QgsAnnotationItem>> mCopiedItems;
192 QgsPointXY mCopiedItemsTopLeft;
193
195 bool mHoveringMouseHandles = false;
196 QPointF mLastScenePos;
197
198 QObjectUniquePtr<QgsRubberBand> mSelectionRubberBand;
199 QRect mSelectionRect;
200
201 bool mDragging = false;
202 bool mCanceled = false;
203};
204
205#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.