QGIS API Documentation 3.43.0-Master (b60ef06885e)
qgsplotrubberband.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsplotrubberband.h
3 ---------------
4 begin : March 2022
5 copyright : (C) 2022 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
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
18#ifndef QGSPLOTRUBBERBAND_H
19#define QGSPLOTRUBBERBAND_H
20
21#include "qgis_gui.h"
22#include "qgis_sip.h"
23
24#include <QPointF>
25#include <QObject>
26#include <QBrush>
27#include <QPen>
28
29class QgsPlotCanvas;
30class QGraphicsRectItem;
31
38class GUI_EXPORT QgsPlotRubberBand : public QObject
39{
40 Q_OBJECT
41
42 public:
46 QgsPlotRubberBand( QgsPlotCanvas *canvas = nullptr );
47
48 ~QgsPlotRubberBand() override = default;
49
54 virtual void start( QPointF position, Qt::KeyboardModifiers modifiers ) = 0;
55
60 virtual void update( QPointF position, Qt::KeyboardModifiers modifiers ) = 0;
61
67 virtual QRectF finish( QPointF position = QPointF(), Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers() ) = 0;
68
72 QgsPlotCanvas *canvas() const;
73
79 QBrush brush() const;
80
86 void setBrush( const QBrush &brush );
87
93 QPen pen() const;
94
100 void setPen( const QPen &pen );
101
102 protected:
109 QRectF updateRect( QPointF start, QPointF position, bool constrainSquare, bool fromCenter );
110
111 private:
112 QgsPlotCanvas *mCanvas = nullptr;
113
114 QBrush mBrush = Qt::NoBrush;
115 QPen mPen = QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 );
116};
117
124{
125 Q_OBJECT
126
127 public:
131 QgsPlotRectangularRubberBand( QgsPlotCanvas *canvas = nullptr );
132
134
135 void start( QPointF position, Qt::KeyboardModifiers modifiers ) override;
136 void update( QPointF position, Qt::KeyboardModifiers modifiers ) override;
137 QRectF finish( QPointF position = QPointF(), Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers() ) override;
138
139 private:
141 QGraphicsRectItem *mRubberBandItem = nullptr;
142
144 QPointF mRubberBandStartPos;
145};
146
147#endif // QGSPLOTRUBBERBAND_H
Plot canvas is a class for displaying interactive 2d charts and plots.
A rectangular rubber band for use within QgsPlotCanvas widgets.
An abstract base class for temporary rubber band items in various shapes, for use within QgsPlotCanva...
virtual QRectF finish(QPointF position=QPointF(), Qt::KeyboardModifiers modifiers=Qt::KeyboardModifiers())=0
Called when a rubber band use has finished and the rubber band is no longer required.
virtual void update(QPointF position, Qt::KeyboardModifiers modifiers)=0
Called when a rubber band should be updated to reflect a temporary ending position (in canvas coordin...
~QgsPlotRubberBand() override=default
virtual void start(QPointF position, Qt::KeyboardModifiers modifiers)=0
Called when a rubber band should be created at the specified starting position (in canvas coordinate ...