QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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:
48 QgsModelViewRubberBand( QgsModelGraphicsView *view = nullptr );
49
50 ~QgsModelViewRubberBand() override = default;
51
55 virtual QgsModelViewRubberBand *create( QgsModelGraphicsView *view ) const = 0 SIP_FACTORY;
56
61 virtual void start( QPointF position, Qt::KeyboardModifiers modifiers ) = 0;
62
67 virtual void update( QPointF position, Qt::KeyboardModifiers modifiers ) = 0;
68
74 virtual QRectF finish( QPointF position = QPointF(), Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers() ) = 0;
75
79 QgsModelGraphicsView *view() const;
80
86 QBrush brush() const;
87
93 void setBrush( const QBrush &brush );
94
100 QPen pen() const;
101
107 void setPen( const QPen &pen );
108
109 signals:
110
117 void sizeChanged( const QString &size );
118
119 protected:
126 QRectF updateRect( QPointF start, QPointF position, bool constrainSquare, bool fromCenter );
127
128 private:
129 QgsModelGraphicsView *mView = nullptr;
130
131 QBrush mBrush = Qt::NoBrush;
132 QPen mPen = QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 );
133};
134
135
142{
143 Q_OBJECT
144
145 public:
149 QgsModelViewRectangularRubberBand( QgsModelGraphicsView *view = nullptr );
150 QgsModelViewRectangularRubberBand *create( QgsModelGraphicsView *view ) const override SIP_FACTORY;
151
153
154 void start( QPointF position, Qt::KeyboardModifiers modifiers ) override;
155 void update( QPointF position, Qt::KeyboardModifiers modifiers ) override;
156 QRectF finish( QPointF position = QPointF(), Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers() ) override;
157
158 private:
160 QGraphicsRectItem *mRubberBandItem = nullptr;
161
163 QPointF mRubberBandStartPos;
164};
165
172{
173 Q_OBJECT
174
175 public:
179 QgsModelViewBezierRubberBand( QgsModelGraphicsView *view = nullptr );
180 QgsModelViewBezierRubberBand *create( QgsModelGraphicsView *view ) const override SIP_FACTORY;
181
183
184 void start( QPointF position, Qt::KeyboardModifiers modifiers ) override;
185 void update( QPointF position, Qt::KeyboardModifiers modifiers ) override;
186 QRectF finish( QPointF position = QPointF(), Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers() ) override;
187
188 private:
190 QGraphicsPathItem *mRubberBandItem = nullptr;
191
193 QPointF mRubberBandStartPos;
194};
195
196
197#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