@@ -1,201 +1,201 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 | 30 | #ifndef CHARTAXIS_H |
|
31 | 31 | #define CHARTAXIS_H |
|
32 | 32 | |
|
33 | 33 | #include "qchartglobal.h" |
|
34 | 34 | #include "chartelement_p.h" |
|
35 | 35 | #include "axisanimation_p.h" |
|
36 | 36 | #include <QGraphicsItem> |
|
37 | 37 | #include <QGraphicsLayoutItem> |
|
38 | 38 | #include <QFont> |
|
39 | 39 | |
|
40 | 40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
41 | 41 | |
|
42 | 42 | class QAbstractAxis; |
|
43 | 43 | class ChartPresenter; |
|
44 | 44 | |
|
45 | 45 | class ChartAxis : public ChartElement, public QGraphicsLayoutItem |
|
46 | 46 | { |
|
47 | 47 | Q_OBJECT |
|
48 | 48 | Q_INTERFACES(QGraphicsLayoutItem) |
|
49 | 49 | public: |
|
50 | 50 | |
|
51 | 51 | ChartAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis = false); |
|
52 | 52 | ~ChartAxis(); |
|
53 | 53 | |
|
54 | 54 | QAbstractAxis* axis() const { return m_chartAxis; } |
|
55 | 55 | |
|
56 | 56 | void setArrowOpacity(qreal opacity); |
|
57 | 57 | qreal arrowOpacity() const; |
|
58 | 58 | void setArrowVisibility(bool visible); |
|
59 | 59 | |
|
60 | 60 | void setGridOpacity(qreal opacity); |
|
61 | 61 | qreal gridOpacity() const; |
|
62 | 62 | void setGridVisibility(bool visible); |
|
63 | 63 | |
|
64 | 64 | void setLabelsOpacity(qreal opacity); |
|
65 | 65 | qreal labelsOpacity() const; |
|
66 | 66 | void setLabelsVisibility(bool visible); |
|
67 | 67 | |
|
68 | 68 | void setShadesOpacity(qreal opacity); |
|
69 | 69 | qreal shadesOpacity() const; |
|
70 | 70 | void setShadesVisibility(bool visible); |
|
71 | 71 | |
|
72 | 72 | void setLabelsAngle(int angle); |
|
73 | 73 | int labelsAngle()const { return m_labelsAngle; } |
|
74 | 74 | |
|
75 | 75 | void setShadesBrush(const QBrush &brush); |
|
76 | 76 | void setShadesPen(const QPen &pen); |
|
77 | 77 | |
|
78 | 78 | void setArrowPen(const QPen &pen); |
|
79 | 79 | void setGridPen(const QPen &pen); |
|
80 | 80 | |
|
81 | 81 | void setLabelsPen(const QPen &pen); |
|
82 | 82 | void setLabelsBrush(const QBrush &brush); |
|
83 | 83 | void setLabelsFont(const QFont &font); |
|
84 | 84 | void setLabelPadding(int padding); |
|
85 | 85 | int labelPadding() const { return m_labelPadding;}; |
|
86 | 86 | |
|
87 | 87 | void setTitlePen(const QPen &pen); |
|
88 | 88 | void setTitleBrush(const QBrush &brush); |
|
89 | 89 | void setTitleFont(const QFont &font); |
|
90 | 90 | QFont titleFont() const { return m_titleFont; }; |
|
91 | 91 | void setTitleText(const QString &title); |
|
92 | 92 | QString titleText() const {return m_titleText; }; |
|
93 | 93 | |
|
94 | 94 | void setLayout(QVector<qreal> &layout); |
|
95 | 95 | QVector<qreal> layout() const { return m_layoutVector; } |
|
96 | 96 | |
|
97 | 97 | void setAnimation(AxisAnimation *animation); |
|
98 | 98 | ChartAnimation *animation() const { return m_animation; }; |
|
99 | 99 | |
|
100 | 100 | Qt::Orientation orientation() const; |
|
101 | 101 | Qt::Alignment alignment() const; |
|
102 | 102 | |
|
103 | 103 | bool isVisible(); |
|
104 | 104 | void hide(); |
|
105 | 105 | |
|
106 | 106 | void setGeometry(const QRectF &axis, const QRectF &grid); |
|
107 | 107 | QRectF axisGeometry() const { return m_axisRect; } |
|
108 | 108 | QRectF gridGeometry() const { return m_gridRect; } |
|
109 | 109 | |
|
110 | 110 | void setLabels(const QStringList &labels); |
|
111 | 111 | QStringList labels() const { return m_labelsList; } |
|
112 | 112 | |
|
113 | 113 | //this flag indicates that axis is used to show intervals it means labels are in between ticks |
|
114 | 114 | bool intervalAxis() const { return m_intervalAxis; } |
|
115 | 115 | |
|
116 | 116 | virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; |
|
117 | 117 | |
|
118 | 118 | protected: |
|
119 | 119 | void setGeometry(const QRectF &size) { Q_UNUSED(size);}; |
|
120 | 120 | virtual void updateGeometry() = 0; |
|
121 | 121 | virtual QVector<qreal> calculateLayout() const = 0; |
|
122 | 122 | |
|
123 | 123 | QList<QGraphicsItem *> lineItems() { return m_grid->childItems(); }; |
|
124 | 124 | QList<QGraphicsItem *> labelItems() { return m_labels->childItems();}; |
|
125 | 125 | QList<QGraphicsItem *> shadeItems() { return m_shades->childItems();}; |
|
126 | 126 | QList<QGraphicsItem *> arrowItems() { return m_arrow->childItems();}; |
|
127 | QGraphicsSimpleTextItem* titleItem() const { return m_title;} | |
|
127 | QGraphicsSimpleTextItem* titleItem() const { return m_title.data();} | |
|
128 | 128 | |
|
129 | 129 | QFont font() const { return m_font; } |
|
130 | 130 | qreal min() const {return m_min; } |
|
131 | 131 | qreal max() const {return m_max; } |
|
132 | 132 | QStringList createValueLabels(int ticks) const; |
|
133 | 133 | QStringList createDateTimeLabels(const QString &format, int ticks) const; |
|
134 | 134 | |
|
135 | 135 | public Q_SLOTS: |
|
136 | 136 | virtual void handleAxisUpdated(); |
|
137 | 137 | virtual void handleDomainUpdated(); |
|
138 | 138 | |
|
139 | 139 | private: |
|
140 | 140 | inline bool isEmpty(); |
|
141 | 141 | void createItems(int count); |
|
142 | 142 | void deleteItems(int count); |
|
143 | 143 | void updateLayout(QVector<qreal> &layout); |
|
144 | 144 | void axisSelected(); |
|
145 | 145 | |
|
146 | 146 | private: |
|
147 | 147 | QAbstractAxis *m_chartAxis; |
|
148 | 148 | int m_labelsAngle; |
|
149 | 149 | QRectF m_axisRect; |
|
150 | 150 | QRectF m_gridRect; |
|
151 | 151 | QScopedPointer<QGraphicsItemGroup> m_grid; |
|
152 | 152 | QScopedPointer<QGraphicsItemGroup> m_shades; |
|
153 | 153 | QScopedPointer<QGraphicsItemGroup> m_labels; |
|
154 | 154 | QScopedPointer<QGraphicsItemGroup> m_arrow; |
|
155 |
QGraphicsSimpleTextItem |
|
|
155 | QScopedPointer<QGraphicsSimpleTextItem> m_title; | |
|
156 | 156 | QVector<qreal> m_layoutVector; |
|
157 | 157 | qreal m_min; |
|
158 | 158 | qreal m_max; |
|
159 | 159 | AxisAnimation *m_animation; |
|
160 | 160 | QFont m_font; |
|
161 | 161 | QFont m_titleFont; |
|
162 | 162 | QString m_titleText; |
|
163 | 163 | int m_labelPadding; |
|
164 | 164 | QStringList m_labelsList; |
|
165 | 165 | bool m_intervalAxis; |
|
166 | 166 | |
|
167 | 167 | friend class AxisAnimation; |
|
168 | 168 | friend class AxisItem; |
|
169 | 169 | |
|
170 | 170 | }; |
|
171 | 171 | |
|
172 | 172 | class AxisItem: public QGraphicsLineItem |
|
173 | 173 | { |
|
174 | 174 | |
|
175 | 175 | public: |
|
176 | 176 | explicit AxisItem(ChartAxis *axis, QGraphicsItem *parent = 0) : QGraphicsLineItem(parent), m_axis(axis) {} |
|
177 | 177 | |
|
178 | 178 | protected: |
|
179 | 179 | void mousePressEvent(QGraphicsSceneMouseEvent *event) { |
|
180 | 180 | Q_UNUSED(event) |
|
181 | 181 | m_axis->axisSelected(); |
|
182 | 182 | } |
|
183 | 183 | |
|
184 | 184 | QRectF boundingRect() const { |
|
185 | 185 | return shape().boundingRect(); |
|
186 | 186 | } |
|
187 | 187 | |
|
188 | 188 | QPainterPath shape() const { |
|
189 | 189 | QPainterPath path = QGraphicsLineItem::shape(); |
|
190 | 190 | QRectF rect = path.boundingRect(); |
|
191 | 191 | path.addRect(rect.adjusted(0, 0, m_axis->orientation() != Qt::Horizontal ? 8 : 0, m_axis->orientation() != Qt::Vertical ? 8 : 0)); |
|
192 | 192 | return path; |
|
193 | 193 | } |
|
194 | 194 | |
|
195 | 195 | private: |
|
196 | 196 | ChartAxis *m_axis; |
|
197 | 197 | }; |
|
198 | 198 | |
|
199 | 199 | QTCOMMERCIALCHART_END_NAMESPACE |
|
200 | 200 | |
|
201 | 201 | #endif /* CHARTAXI_H */ |
General Comments 0
You need to be logged in to leave comments.
Login now