QGIS API Documentation 4.3.0-Master (6313fb5bce0)
Loading...
Searching...
No Matches
qgsmodelarrowitem.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmodelarrowitem.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 QGSMODELARROWITEM_H
17#define QGSMODELARROWITEM_H
18
19#include "qgis.h"
20#include "qgis_gui.h"
21
22#include <QGraphicsPathItem>
23#include <QGraphicsRectItem>
24#include <QObject>
25
26#define SIP_NO_FILE
27
28class QgsModelComponentGraphicItem;
29class QgsModelArrowItem;
30
31
33
34
41class GUI_EXPORT QgsModelDesignerArrowBadgeItem : public QGraphicsRectItem
42{
43 public:
44 QgsModelDesignerArrowBadgeItem( QgsModelArrowItem *link );
45
49 void setCenter( const QPointF &center );
50
54 QgsModelArrowItem *arrow();
55
56 void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr ) override;
57
63 void setValue( const QVariant &value );
64
70 QVariant value() const;
71
75 static QString textForValue( const QVariant &value );
76
77 private:
78 void resizeToContents();
79
80 static constexpr int FONT_SIZE = 10; // Font size for the feature count text
81 static constexpr double BORDER_RADIUS = 5;
82 static constexpr double CONTENTS_MARGIN = 0.2;
83 QVariant mValue;
84};
85
86
93class GUI_EXPORT QgsModelArrowItem : public QObject, public QGraphicsPathItem
94{
95 Q_OBJECT
96 public:
97 enum Marker
98 {
99 Circle,
100 ArrowHead,
101 NoMarker
102 };
103
110 QgsModelArrowItem(
111 QgsModelComponentGraphicItem *startItem,
112 Qt::Edge startEdge,
113 int startIndex,
114 bool startIsOutgoing,
115 Marker startMarker,
116 QgsModelComponentGraphicItem *endItem,
117 Qt::Edge endEdge,
118 int endIndex,
119 bool endIsIncoming,
120 Marker endMarker
121 );
122
129 QgsModelArrowItem( QgsModelComponentGraphicItem *startItem, Qt::Edge startEdge, int startIndex, Marker startMarker, QgsModelComponentGraphicItem *endItem, Marker endMarker );
130
137 QgsModelArrowItem( QgsModelComponentGraphicItem *startItem, Marker startMarker, QgsModelComponentGraphicItem *endItem, Qt::Edge endEdge, int endIndex, Marker endMarker );
138
144 QgsModelArrowItem( QgsModelComponentGraphicItem *startItem, Marker startMarker, QgsModelComponentGraphicItem *endItem, Marker endMarker );
145
146 void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr ) override;
147
151 void setPenStyle( Qt::PenStyle style );
152
158 QgsModelComponentGraphicItem *startItem();
159
165 Qt::Edge startEdge() { return mStartEdge; }
166
172 int startIndex() { return mStartIndex; }
173
179 QgsModelComponentGraphicItem *endItem();
180
186 Qt::Edge endEdge() { return mEndEdge; }
187
193 int endIndex() { return mEndIndex; }
194
200 QgsModelDesignerArrowBadgeItem *badgeItem();
201
207 void setShowBadge( bool visible );
208
209 public slots:
210
214 void updatePath();
215
216 private:
217 QPointF bezierPointForCurve( const QPointF &point, Qt::Edge edge, bool incoming, bool hasSpecificDirectionalFlow ) const;
218
219 void drawArrowHead( QPainter *painter, const QPointF &point, const QPointF &vector );
220
221 QgsModelComponentGraphicItem *mStartItem = nullptr;
222 Qt::Edge mStartEdge = Qt::LeftEdge;
223 int mStartIndex = -1;
224 bool mStartIsOutgoing = true;
225 Marker mStartMarker;
226
227 QgsModelComponentGraphicItem *mEndItem = nullptr;
228 Qt::Edge mEndEdge = Qt::LeftEdge;
229 int mEndIndex = -1;
230 bool mEndIsIncoming = false;
231 Marker mEndMarker;
232
233 // Optional child badge item. Not created by default.
234 QgsModelDesignerArrowBadgeItem *mBadgeItem = nullptr;
235
236 QPointF mStartPoint;
237 QPointF mEndPoint;
238
239 QColor mColor;
240};
241
243
244#endif // QGSMODELARROWITEM_H