QGIS API Documentation 3.99.0-Master (a8882ad4560)
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
132 QList<QgsAnnotationItemRubberBand *> selectedItems() const;
133
140 void attemptMoveBy( QgsAnnotationItemRubberBand *annotationItemRubberBand, double deltaX, double deltaY );
141
147 void attemptRotateBy( QgsAnnotationItemRubberBand *annotationItemRubberBand, double deltaDegree );
148
154 void attemptSetSceneRect( QgsAnnotationItemRubberBand *annotationItemRubberBand, const QRectF &rect );
155
156 signals:
157
162
166 void singleItemSelected( QgsAnnotationLayer *layer, const QString &itemId );
167
172
177
178 private slots:
179 void onCanvasRefreshed();
180
181 private:
182 long long annotationItemRubberBandIndexFromId( const QString &layerId, const QString &itemId );
183
184 void setSelectedItemFromPoint( const QgsPointXY &mapPoint, bool toggleSelection = false );
185 void setSelectedItemsFromRect( const QgsRectangle &mapRect, bool toggleSelection = false );
186 void clearSelectedItems();
187 void updateSelectedItem();
188
189 std::vector<std::unique_ptr<QgsAnnotationItemRubberBand>> mSelectedItems;
190 QList<QPair<QString, QString>> mCopiedItems;
191 QgsPointXY mCopiedItemsTopLeft;
192
194 bool mHoveringMouseHandles = false;
195 QPointF mLastScenePos;
196
197 QObjectUniquePtr<QgsRubberBand> mSelectionRubberBand;
198 QRect mSelectionRect;
199
200 bool mDragging = false;
201 bool mCanceled = false;
202};
203
204#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.
QgsMapCanvas * canvas() const
returns pointer to the tool's map canvas
Represents a 2D point.
Definition qgspointxy.h:60
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.