QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
qgsmaptoolselectannotationmousehandles.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaptoolselectannotationmousehandles.cpp
3 -----------------------
4 begin : November 2025
5 copyright : (C) 2025 by Mathieu Pellrin
6 email : mathieu at opengis dot ch
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19
20#include <limits>
21
22#include "qgis.h"
23#include "qgsannotationitem.h"
26#include "qgsannotationlayer.h"
27#include "qgsgui.h"
29
30#include <QGraphicsSceneHoverEvent>
31#include <QGraphicsView>
32#include <QPainter>
33#include <QWidget>
34
35#include "moc_qgsmaptoolselectannotationmousehandles.cpp"
36
38
39QgsMapToolSelectAnnotationMouseHandles::QgsMapToolSelectAnnotationMouseHandles( QgsMapToolSelectAnnotation *mapTool, QgsMapCanvas *canvas )
40 : QgsGraphicsViewMouseHandles( canvas )
41 , mMapTool( mapTool )
42 , mCanvas( canvas )
43{
44 setZValue( 100 );
45
46 connect( mMapTool, &QgsMapToolSelectAnnotation::selectedItemsChanged, this, &QgsMapToolSelectAnnotationMouseHandles::selectionChanged );
47 connect( mCanvas, &QgsMapCanvas::extentsChanged, this, [this] { updateHandles(); } );
48 mCanvas->scene()->addItem( this );
49
50 setRotationEnabled( true );
51 setCadMouseDigitizingModeEnabled( true );
52}
53
54void QgsMapToolSelectAnnotationMouseHandles::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget )
55{
56 paintInternal( painter, true, true, true, option, widget );
57}
58
59void QgsMapToolSelectAnnotationMouseHandles::selectionChanged()
60{
61 updateHandles();
62}
63
64void QgsMapToolSelectAnnotationMouseHandles::setViewportCursor( Qt::CursorShape cursor )
65{
66 if ( qobject_cast<QgsMapToolSelectAnnotation *>( mCanvas->mapTool() ) )
67 {
68 mCanvas->viewport()->setCursor( cursor );
69 }
70}
71
72QList<QGraphicsItem *> QgsMapToolSelectAnnotationMouseHandles::sceneItemsAtPoint( QPointF scenePoint )
73{
74 QList<QGraphicsItem *> graphicsItems;
75 const QList<QgsAnnotationItemRubberBand *> items = mMapTool->selectedItems();
76 for ( auto item : items )
77 {
78 if ( item->sceneBoundingRect().contains( scenePoint ) )
79 {
80 graphicsItems << item;
81 }
82 }
83 return graphicsItems;
84}
85
86QList<QGraphicsItem *> QgsMapToolSelectAnnotationMouseHandles::selectedSceneItems( bool ) const
87{
88 QList<QGraphicsItem *> graphicsItems;
89 const QList<QgsAnnotationItemRubberBand *> items = mMapTool->selectedItems();
90 for ( auto item : items )
91 {
92 graphicsItems << item;
93 }
94 return graphicsItems;
95}
96
97QRectF QgsMapToolSelectAnnotationMouseHandles::itemRect( QGraphicsItem *item ) const
98{
99 return item->boundingRect();
100}
101
102void QgsMapToolSelectAnnotationMouseHandles::moveItem( QGraphicsItem *item, double deltaX, double deltaY )
103{
104 QgsAnnotationItemRubberBand *annotationRubberBandItem = qgis::down_cast<QgsAnnotationItemRubberBand *>( item );
105 mMapTool->attemptMoveBy( annotationRubberBandItem, deltaX, deltaY );
106}
107
108void QgsMapToolSelectAnnotationMouseHandles::rotateItem( QGraphicsItem *item, double deltaDegree, double deltaCenterX, double deltaCenterY )
109{
110 QgsAnnotationItemRubberBand *annotationRubberBandItem = qgis::down_cast<QgsAnnotationItemRubberBand *>( item );
111 mMapTool->attemptMoveBy( annotationRubberBandItem, deltaCenterX, deltaCenterY );
112 mMapTool->attemptRotateBy( annotationRubberBandItem, deltaDegree );
113}
114
115void QgsMapToolSelectAnnotationMouseHandles::setItemRect( QGraphicsItem *item, QRectF rect )
116{
117 QgsAnnotationItemRubberBand *annotationRubberBandItem = qgis::down_cast<QgsAnnotationItemRubberBand *>( item );
118 mMapTool->attemptSetSceneRect( annotationRubberBandItem, rect );
119}
120
An annotation item rubberband used by QgsMapToolSelectAnnotation to represent selected items.
Map canvas is a class for displaying all GIS data types on a canvas.
void extentsChanged()
Emitted when the extents of the map change.
A map tool for selecting, moving, and rotating annotations in a QgsAnnotationLayer.
void selectedItemsChanged()
Emitted when the selected items list has changed.