QGIS API Documentation 4.1.0-Master (31622b25bb0)
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
26class QgsModelComponentGraphicItem;
27class QgsModelArrowItem;
28
30
31
38class GUI_EXPORT QgsModelDesignerArrowBadgeItem : public QGraphicsRectItem SIP_SKIP
39{
40 public:
41 QgsModelDesignerArrowBadgeItem( QgsModelArrowItem *link SIP_TRANSFERTHIS );
42
46 void setCenter( const QPointF &center );
47
51 QgsModelArrowItem *arrow();
52
53 void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr ) override;
54
60 void setValue( const QVariant &value );
61
67 QVariant value() const;
68
72 static QString textForValue( const QVariant &value );
73
74 private:
75 void resizeToContents();
76
77 static constexpr int FONT_SIZE = 10; // Font size for the feature count text
78 static constexpr double BORDER_RADIUS = 5;
79 static constexpr double CONTENTS_MARGIN = 0.2;
80 QVariant mValue;
81};
82
83
90class GUI_EXPORT QgsModelArrowItem : public QObject, public QGraphicsPathItem
91{
92 Q_OBJECT
93 public:
94 enum Marker
95 {
96 Circle,
97 ArrowHead,
98 NoMarker
99 };
100
107 QgsModelArrowItem(
108 QgsModelComponentGraphicItem *startItem,
109 Qt::Edge startEdge,
110 int startIndex,
111 bool startIsOutgoing,
112 Marker startMarker,
113 QgsModelComponentGraphicItem *endItem,
114 Qt::Edge endEdge,
115 int endIndex,
116 bool endIsIncoming,
117 Marker endMarker
118 );
119
126 QgsModelArrowItem( QgsModelComponentGraphicItem *startItem, Qt::Edge startEdge, int startIndex, Marker startMarker, QgsModelComponentGraphicItem *endItem, Marker endMarker );
127
134 QgsModelArrowItem( QgsModelComponentGraphicItem *startItem, Marker startMarker, QgsModelComponentGraphicItem *endItem, Qt::Edge endEdge, int endIndex, Marker endMarker );
135
141 QgsModelArrowItem( QgsModelComponentGraphicItem *startItem, Marker startMarker, QgsModelComponentGraphicItem *endItem, Marker endMarker );
142
143 void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr ) override;
144
148 void setPenStyle( Qt::PenStyle style );
149
155 QgsModelComponentGraphicItem *startItem();
156
162 Qt::Edge startEdge() { return mStartEdge; }
163
169 int startIndex() { return mStartIndex; }
170
176 QgsModelComponentGraphicItem *endItem();
177
183 Qt::Edge endEdge() { return mEndEdge; }
184
190 int endIndex() { return mEndIndex; }
191
197 SIP_SKIP QgsModelDesignerArrowBadgeItem *badgeItem();
198
204 SIP_SKIP void setShowBadge( bool visible );
205
206 public slots:
207
211 void updatePath();
212
213 private:
214 QPointF bezierPointForCurve( const QPointF &point, Qt::Edge edge, bool incoming, bool hasSpecificDirectionalFlow ) const;
215
216 void drawArrowHead( QPainter *painter, const QPointF &point, const QPointF &vector );
217
218 QgsModelComponentGraphicItem *mStartItem = nullptr;
219 Qt::Edge mStartEdge = Qt::LeftEdge;
220 int mStartIndex = -1;
221 bool mStartIsOutgoing = true;
222 Marker mStartMarker;
223
224 QgsModelComponentGraphicItem *mEndItem = nullptr;
225 Qt::Edge mEndEdge = Qt::LeftEdge;
226 int mEndIndex = -1;
227 bool mEndIsIncoming = false;
228 Marker mEndMarker;
229
230 // Optional child badge item. Not created by default.
231 QgsModelDesignerArrowBadgeItem *mBadgeItem = nullptr;
232
233 QPointF mStartPoint;
234 QPointF mEndPoint;
235
236 QColor mColor;
237};
238
240
241#endif // QGSMODELARROWITEM_H
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:52
#define SIP_SKIP
Definition qgis_sip.h:133