QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
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
22#include <QBrush>
23#include <QObject>
24#include <QPen>
25
26#define SIP_NO_FILE
27
28class QgsModelGraphicsView;
29class QGraphicsRectItem;
30class QGraphicsEllipseItem;
31class QGraphicsPathItem;
32class QGraphicsPolygonItem;
33
40class GUI_EXPORT QgsModelViewRubberBand : public QObject
41{
42 Q_OBJECT
43
44 public:
45
49 QgsModelViewRubberBand( QgsModelGraphicsView *view = nullptr );
50
51 ~QgsModelViewRubberBand() override = default;
52
56 virtual QgsModelViewRubberBand *create( QgsModelGraphicsView *view ) const = 0 SIP_FACTORY;
57
62 virtual void start( QPointF position, Qt::KeyboardModifiers modifiers ) = 0;
63
68 virtual void update( QPointF position, Qt::KeyboardModifiers modifiers ) = 0;
69
75 virtual QRectF finish( QPointF position = QPointF(), Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers() ) = 0;
76
80 QgsModelGraphicsView *view() const;
81
87 QBrush brush() const;
88
94 void setBrush( const QBrush &brush );
95
101 QPen pen() const;
102
108 void setPen( const QPen &pen );
109
110 signals:
111
118 void sizeChanged( const QString &size );
119
120 protected:
121
128 QRectF updateRect( QPointF start, QPointF position, bool constrainSquare, bool fromCenter );
129
130 private:
131 QgsModelGraphicsView *mView = nullptr;
132
133 QBrush mBrush = Qt::NoBrush;
134 QPen mPen = QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 );
135};
136
137
144{
145 Q_OBJECT
146
147 public:
148
152 QgsModelViewRectangularRubberBand( QgsModelGraphicsView *view = nullptr );
153 QgsModelViewRectangularRubberBand *create( QgsModelGraphicsView *view ) const override SIP_FACTORY;
154
156
157 void start( QPointF position, Qt::KeyboardModifiers modifiers ) override;
158 void update( QPointF position, Qt::KeyboardModifiers modifiers ) override;
159 QRectF finish( QPointF position = QPointF(), Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers() ) override;
160
161 private:
163 QGraphicsRectItem *mRubberBandItem = nullptr;
164
166 QPointF mRubberBandStartPos;
167};
168
175{
176 Q_OBJECT
177
178 public:
179
183 QgsModelViewBezierRubberBand( QgsModelGraphicsView *view = nullptr );
184 QgsModelViewBezierRubberBand *create( QgsModelGraphicsView *view ) const override SIP_FACTORY;
185
187
188 void start( QPointF position, Qt::KeyboardModifiers modifiers ) override;
189 void update( QPointF position, Qt::KeyboardModifiers modifiers ) override;
190 QRectF finish( QPointF position = QPointF(), Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers() ) override;
191
192 private:
194 QGraphicsPathItem *mRubberBandItem = nullptr;
195
197 QPointF mRubberBandStartPos;
198};
199
200
201#endif // QGSMODELVIEWRUBBERBAND_H
void update(QPointF position, Qt::KeyboardModifiers modifiers) override
Called when a rubber band should be updated to reflect a temporary ending position (in model coordina...
QgsModelViewBezierRubberBand * create(QgsModelGraphicsView *view) const override
Creates a new instance of the QgsModelViewRubberBand subclass.
QgsModelViewBezierRubberBand(QgsModelGraphicsView *view=nullptr)
Constructor for QgsModelViewRectangularRubberBand.
QRectF finish(QPointF position=QPointF(), Qt::KeyboardModifiers modifiers=Qt::KeyboardModifiers()) override
Called when a rubber band use has finished and the rubber band is no longer required.
void start(QPointF position, Qt::KeyboardModifiers modifiers) override
Called when a rubber band should be created at the specified starting position (in model coordinate s...
QgsModelViewRectangularRubberBand(QgsModelGraphicsView *view=nullptr)
Constructor for QgsModelViewRectangularRubberBand.
void update(QPointF position, Qt::KeyboardModifiers modifiers) override
Called when a rubber band should be updated to reflect a temporary ending position (in model coordina...
void start(QPointF position, Qt::KeyboardModifiers modifiers) override
Called when a rubber band should be created at the specified starting position (in model coordinate s...
QgsModelViewRectangularRubberBand * create(QgsModelGraphicsView *view) const override
Creates a new instance of the QgsModelViewRubberBand subclass.
QRectF finish(QPointF position=QPointF(), Qt::KeyboardModifiers modifiers=Qt::KeyboardModifiers()) override
Called when a rubber band use has finished and the rubber band is no longer required.
QRectF updateRect(QPointF start, QPointF position, bool constrainSquare, bool fromCenter)
Calculates an updated bounding box rectangle from a original start position and new position.
void setPen(const QPen &pen)
Sets the pen used for drawing the rubber band.
void setBrush(const QBrush &brush)
Sets the brush used for drawing the rubber band.
QgsModelViewRubberBand(QgsModelGraphicsView *view=nullptr)
Constructor for QgsModelViewRubberBand.
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.
QPen pen() const
Returns the pen used for drawing the rubber band.
QgsModelGraphicsView * view() const
Returns the view associated with the rubber band.
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...
QBrush brush() const
Returns the brush used for drawing the rubber band.
#define SIP_FACTORY
Definition qgis_sip.h:84