QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
29 class QgsPlotCanvas;
30 class QGraphicsRectItem;
31 
38 class GUI_EXPORT QgsPlotRubberBand : public QObject
39 {
40 
41  Q_OBJECT
42 
43  public:
44 
48  QgsPlotRubberBand( QgsPlotCanvas *canvas = nullptr );
49 
50  ~QgsPlotRubberBand() override = default;
51 
56  virtual void start( QPointF position, Qt::KeyboardModifiers modifiers ) = 0;
57 
62  virtual void update( QPointF position, Qt::KeyboardModifiers modifiers ) = 0;
63 
69  virtual QRectF finish( QPointF position = QPointF(), Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers() ) = 0;
70 
74  QgsPlotCanvas *canvas() const;
75 
81  QBrush brush() const;
82 
88  void setBrush( const QBrush &brush );
89 
95  QPen pen() const;
96 
102  void setPen( const QPen &pen );
103 
104  protected:
105 
112  QRectF updateRect( QPointF start, QPointF position, bool constrainSquare, bool fromCenter );
113 
114  private:
115 
116  QgsPlotCanvas *mCanvas = nullptr;
117 
118  QBrush mBrush = Qt::NoBrush;
119  QPen mPen = QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 );
120 
121 };
122 
129 {
130  Q_OBJECT
131 
132  public:
133 
137  QgsPlotRectangularRubberBand( QgsPlotCanvas *canvas = nullptr );
138 
139  ~QgsPlotRectangularRubberBand() override;
140 
141  void start( QPointF position, Qt::KeyboardModifiers modifiers ) override;
142  void update( QPointF position, Qt::KeyboardModifiers modifiers ) override;
143  QRectF finish( QPointF position = QPointF(), Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers() ) override;
144 
145  private:
146 
148  QGraphicsRectItem *mRubberBandItem = nullptr;
149 
151  QPointF mRubberBandStartPos;
152 
153 };
154 
155 #endif // QGSPLOTRUBBERBAND_H
QgsPlotRectangularRubberBand
QgsPlotRectangularRubberBand is rectangular rubber band for use within QgsPlotCanvas widgets.
Definition: qgsplotrubberband.h:128
QgsPlotRubberBand::finish
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.
QgsPlotRubberBand::update
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...
qgis_sip.h
QgsPlotCanvas
Plot canvas is a class for displaying interactive 2d charts and plots.
Definition: qgsplotcanvas.h:53
QgsPlotRubberBand::start
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 ...
QgsPlotRubberBand
QgsPlotRubberBand is an abstract base class for temporary rubber band items in various shapes,...
Definition: qgsplotrubberband.h:38