QGIS API Documentation 3.43.0-Master (a6cade80589)
qgsmodelviewrubberband.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmodelviewrubberband.h
3 -------------------------
4 Date : March 2020
5 Copyright : (C) 2020 Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSMODELVIEWRUBBERBAND_H
17#define QGSMODELVIEWRUBBERBAND_H
18
19#include "qgis_gui.h"
20#include "qgis_sip.h"
21#include <QBrush>
22#include <QPen>
23#include <QObject>
24
25#define SIP_NO_FILE
26
27class QgsModelGraphicsView;
28class QGraphicsRectItem;
29class QGraphicsEllipseItem;
30class QGraphicsPathItem;
31class QGraphicsPolygonItem;
32
39class GUI_EXPORT QgsModelViewRubberBand : public QObject
40{
41 Q_OBJECT
42
43 public:
47 QgsModelViewRubberBand( QgsModelGraphicsView *view = nullptr );
48
49 ~QgsModelViewRubberBand() override = default;
50
54 virtual QgsModelViewRubberBand *create( QgsModelGraphicsView *view ) const = 0 SIP_FACTORY;
55
60 virtual void start( QPointF position, Qt::KeyboardModifiers modifiers ) = 0;
61
66 virtual void update( QPointF position, Qt::KeyboardModifiers modifiers ) = 0;
67
73 virtual QRectF finish( QPointF position = QPointF(), Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers() ) = 0;
74
78 QgsModelGraphicsView *view() const;
79
85 QBrush brush() const;
86
92 void setBrush( const QBrush &brush );
93
99 QPen pen() const;
100
106 void setPen( const QPen &pen );
107
108 signals:
109
116 void sizeChanged( const QString &size );
117
118 protected:
125 QRectF updateRect( QPointF start, QPointF position, bool constrainSquare, bool fromCenter );
126
127 private:
128 QgsModelGraphicsView *mView = nullptr;
129
130 QBrush mBrush = Qt::NoBrush;
131 QPen mPen = QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 );
132};
133
134
141{
142 Q_OBJECT
143
144 public:
148 QgsModelViewRectangularRubberBand( QgsModelGraphicsView *view = nullptr );
149 QgsModelViewRectangularRubberBand *create( QgsModelGraphicsView *view ) const override SIP_FACTORY;
150
152
153 void start( QPointF position, Qt::KeyboardModifiers modifiers ) override;
154 void update( QPointF position, Qt::KeyboardModifiers modifiers ) override;
155 QRectF finish( QPointF position = QPointF(), Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers() ) override;
156
157 private:
159 QGraphicsRectItem *mRubberBandItem = nullptr;
160
162 QPointF mRubberBandStartPos;
163};
164
171{
172 Q_OBJECT
173
174 public:
178 QgsModelViewBezierRubberBand( QgsModelGraphicsView *view = nullptr );
179 QgsModelViewBezierRubberBand *create( QgsModelGraphicsView *view ) const override SIP_FACTORY;
180
182
183 void start( QPointF position, Qt::KeyboardModifiers modifiers ) override;
184 void update( QPointF position, Qt::KeyboardModifiers modifiers ) override;
185 QRectF finish( QPointF position = QPointF(), Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers() ) override;
186
187 private:
189 QGraphicsPathItem *mRubberBandItem = nullptr;
190
192 QPointF mRubberBandStartPos;
193};
194
195
196#endif // QGSMODELVIEWRUBBERBAND_H
A bezier curve rubber band for use within QgsModelGraphicsView widgets.
A rectangular rubber band for use within QgsModelGraphicsView widgets.
An abstract base class for temporary rubber band items in various shapes, for use within QgsModelGrap...
virtual void update(QPointF position, Qt::KeyboardModifiers modifiers)=0
Called when a rubber band should be updated to reflect a temporary ending position (in model coordina...
~QgsModelViewRubberBand() override=default
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.
void sizeChanged(const QString &size)
Emitted when the size of the rubber band is changed.
virtual QgsModelViewRubberBand * create(QgsModelGraphicsView *view) const =0
Creates a new instance of the QgsModelViewRubberBand subclass.
virtual void start(QPointF position, Qt::KeyboardModifiers modifiers)=0
Called when a rubber band should be created at the specified starting position (in model coordinate s...
#define SIP_FACTORY
Definition qgis_sip.h:76