@@ -1,335 +1,335 | |||
|
1 | 1 | #include "axisitem_p.h" |
|
2 | 2 | #include "qchartaxis.h" |
|
3 | 3 | #include "chartpresenter_p.h" |
|
4 | 4 | #include <QPainter> |
|
5 | 5 | #include <QDebug> |
|
6 | 6 | |
|
7 | 7 | static int label_padding = 5; |
|
8 | 8 | |
|
9 | 9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | 10 | |
|
11 | 11 | AxisItem::AxisItem(AxisType type,QGraphicsItem* parent) : |
|
12 | 12 | ChartItem(parent), |
|
13 | 13 | m_type(type), |
|
14 | 14 | m_labelsAngle(0), |
|
15 | 15 | m_grid(parent), |
|
16 | 16 | m_shades(parent), |
|
17 | 17 | m_labels(parent), |
|
18 | 18 | m_axis(parent) |
|
19 | 19 | { |
|
20 | 20 | //initial initialization |
|
21 | 21 | m_axis.setZValue(ChartPresenter::AxisZValue); |
|
22 | 22 | m_shades.setZValue(ChartPresenter::ShadesZValue); |
|
23 | 23 | m_grid.setZValue(ChartPresenter::GridZValue); |
|
24 | 24 | setFlags(QGraphicsItem::ItemHasNoContents); |
|
25 | 25 | } |
|
26 | 26 | |
|
27 | 27 | AxisItem::~AxisItem() |
|
28 | 28 | { |
|
29 | 29 | } |
|
30 | 30 | |
|
31 | 31 | QRectF AxisItem::boundingRect() const |
|
32 | 32 | { |
|
33 | 33 | return QRectF(); |
|
34 | 34 | } |
|
35 | 35 | |
|
36 | 36 | void AxisItem::createItems(int count) |
|
37 | 37 | { |
|
38 | 38 | if(m_axis.children().size()==0) |
|
39 | 39 | m_axis.addToGroup(new QGraphicsLineItem()); |
|
40 | 40 | for (int i = 0; i < count; ++i) { |
|
41 | 41 | m_grid.addToGroup(new QGraphicsLineItem()); |
|
42 | 42 | m_labels.addToGroup(new QGraphicsSimpleTextItem()); |
|
43 | 43 | if(m_grid.childItems().size()%2) m_shades.addToGroup(new QGraphicsRectItem()); |
|
44 | 44 | m_axis.addToGroup(new QGraphicsLineItem()); |
|
45 | 45 | } |
|
46 | 46 | } |
|
47 | 47 | |
|
48 | 48 | void AxisItem::clear(int count) |
|
49 | 49 | { |
|
50 | 50 | QList<QGraphicsItem *> lines = m_grid.childItems(); |
|
51 | 51 | QList<QGraphicsItem *> labels = m_labels.childItems(); |
|
52 | 52 | QList<QGraphicsItem *> shades = m_shades.childItems(); |
|
53 | 53 | QList<QGraphicsItem *> axis = m_axis.childItems(); |
|
54 | 54 | |
|
55 | 55 | for (int i = 0; i < count; ++i) { |
|
56 | 56 | delete(lines.takeLast()); |
|
57 | 57 | delete(labels.takeLast()); |
|
58 | 58 | if(lines.size()%2) delete(shades.takeLast()); |
|
59 | 59 | delete(axis.takeLast()); |
|
60 | 60 | } |
|
61 | 61 | |
|
62 | 62 | m_thicksList.clear(); |
|
63 | 63 | |
|
64 | 64 | } |
|
65 | 65 | |
|
66 | 66 | void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
67 | 67 | { |
|
68 | 68 | Q_UNUSED(painter); |
|
69 | 69 | Q_UNUSED(option); |
|
70 | 70 | Q_UNUSED(widget); |
|
71 | 71 | } |
|
72 | 72 | |
|
73 | 73 | void AxisItem::updateItems(QVector<qreal>& vector) |
|
74 | 74 | { |
|
75 | 75 | calculateLayout(vector); |
|
76 | 76 | if(vector.count()==0) return; |
|
77 | 77 | applyLayout(vector); |
|
78 | 78 | } |
|
79 | 79 | |
|
80 | 80 | void AxisItem::handleAxisUpdate(QChartAxis* axis) |
|
81 | 81 | { |
|
82 | 82 | if(m_layoutVector.count()==0) return; |
|
83 | 83 | |
|
84 | 84 | if(axis->isAxisVisible()) { |
|
85 | 85 | setAxisOpacity(100); |
|
86 | 86 | } |
|
87 | 87 | else { |
|
88 | 88 | setAxisOpacity(0); |
|
89 | 89 | } |
|
90 | 90 | |
|
91 | 91 | if(axis->isGridVisible()) { |
|
92 | 92 | setGridOpacity(100); |
|
93 | 93 | } |
|
94 | 94 | else { |
|
95 | 95 | setGridOpacity(0); |
|
96 | 96 | } |
|
97 | 97 | |
|
98 |
if(axis-> |
|
|
98 | if(axis->labelsVisible()) | |
|
99 | 99 | { |
|
100 | 100 | setLabelsOpacity(100); |
|
101 | 101 | } |
|
102 | 102 | else { |
|
103 | 103 | setLabelsOpacity(0); |
|
104 | 104 | } |
|
105 | 105 | |
|
106 |
if(axis-> |
|
|
106 | if(axis->shadesVisible()) { | |
|
107 | 107 | setShadesOpacity(axis->shadesOpacity()); |
|
108 | 108 | } |
|
109 | 109 | else { |
|
110 | 110 | setShadesOpacity(0); |
|
111 | 111 | } |
|
112 | 112 | |
|
113 | 113 | setLabelsAngle(axis->labelsAngle()); |
|
114 | 114 | setAxisPen(axis->axisPen()); |
|
115 | 115 | setLabelsPen(axis->labelsPen()); |
|
116 | 116 | setLabelsBrush(axis->labelsBrush()); |
|
117 | 117 | setLabelsFont(axis->labelsFont()); |
|
118 | 118 | setGridPen(axis->gridPen()); |
|
119 | 119 | setShadesPen(axis->shadesPen()); |
|
120 | 120 | setShadesBrush(axis->shadesBrush()); |
|
121 | 121 | } |
|
122 | 122 | |
|
123 | 123 | void AxisItem::handleLabelsChanged(QChartAxis* axis,const QStringList& labels) |
|
124 | 124 | { |
|
125 | 125 | int diff = m_thicksList.size() - labels.size(); |
|
126 | 126 | |
|
127 | 127 | if(diff>0){ |
|
128 | 128 | clear(diff); |
|
129 | 129 | }else if(diff<0){ |
|
130 | 130 | createItems(-diff); |
|
131 | 131 | } |
|
132 | 132 | m_thicksList=labels; |
|
133 | 133 | m_layoutVector.resize(m_thicksList.size()); |
|
134 | 134 | updateItems(m_layoutVector); |
|
135 | 135 | if(diff!=0) handleAxisUpdate(axis); |
|
136 | 136 | } |
|
137 | 137 | |
|
138 | 138 | void AxisItem::handleGeometryChanged(const QRectF& rect) |
|
139 | 139 | { |
|
140 | 140 | m_rect = rect; |
|
141 | 141 | updateItems(m_layoutVector); |
|
142 | 142 | } |
|
143 | 143 | |
|
144 | 144 | void AxisItem::setAxisOpacity(qreal opacity) |
|
145 | 145 | { |
|
146 | 146 | m_axis.setOpacity(opacity); |
|
147 | 147 | } |
|
148 | 148 | |
|
149 | 149 | qreal AxisItem::axisOpacity() const |
|
150 | 150 | { |
|
151 | 151 | return m_axis.opacity(); |
|
152 | 152 | } |
|
153 | 153 | |
|
154 | 154 | void AxisItem::setGridOpacity(qreal opacity) |
|
155 | 155 | { |
|
156 | 156 | m_grid.setOpacity(opacity); |
|
157 | 157 | } |
|
158 | 158 | |
|
159 | 159 | qreal AxisItem::gridOpacity() const |
|
160 | 160 | { |
|
161 | 161 | return m_grid.opacity(); |
|
162 | 162 | } |
|
163 | 163 | |
|
164 | 164 | void AxisItem::setLabelsOpacity(qreal opacity) |
|
165 | 165 | { |
|
166 | 166 | m_labels.setOpacity(opacity); |
|
167 | 167 | } |
|
168 | 168 | |
|
169 | 169 | qreal AxisItem::labelsOpacity() const |
|
170 | 170 | { |
|
171 | 171 | return m_labels.opacity(); |
|
172 | 172 | } |
|
173 | 173 | |
|
174 | 174 | void AxisItem::setShadesOpacity(qreal opacity) |
|
175 | 175 | { |
|
176 | 176 | m_shades.setOpacity(opacity); |
|
177 | 177 | } |
|
178 | 178 | |
|
179 | 179 | qreal AxisItem::shadesOpacity() const |
|
180 | 180 | { |
|
181 | 181 | return m_shades.opacity(); |
|
182 | 182 | } |
|
183 | 183 | |
|
184 | 184 | void AxisItem::setLabelsAngle(int angle) |
|
185 | 185 | { |
|
186 | 186 | foreach(QGraphicsItem* item , m_labels.childItems()) { |
|
187 | 187 | QPointF center = item->boundingRect().center(); |
|
188 | 188 | item->setRotation(angle); |
|
189 | 189 | } |
|
190 | 190 | |
|
191 | 191 | m_labelsAngle=angle; |
|
192 | 192 | } |
|
193 | 193 | |
|
194 | 194 | void AxisItem::setLabelsPen(const QPen& pen) |
|
195 | 195 | { |
|
196 | 196 | foreach(QGraphicsItem* item , m_labels.childItems()) { |
|
197 | 197 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); |
|
198 | 198 | } |
|
199 | 199 | } |
|
200 | 200 | |
|
201 | 201 | void AxisItem::setLabelsBrush(const QBrush& brush) |
|
202 | 202 | { |
|
203 | 203 | foreach(QGraphicsItem* item , m_labels.childItems()) { |
|
204 | 204 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); |
|
205 | 205 | } |
|
206 | 206 | } |
|
207 | 207 | |
|
208 | 208 | void AxisItem::setLabelsFont(const QFont& font) |
|
209 | 209 | { |
|
210 | 210 | foreach(QGraphicsItem* item , m_labels.childItems()) { |
|
211 | 211 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); |
|
212 | 212 | } |
|
213 | 213 | } |
|
214 | 214 | |
|
215 | 215 | void AxisItem::setShadesBrush(const QBrush& brush) |
|
216 | 216 | { |
|
217 | 217 | foreach(QGraphicsItem* item , m_shades.childItems()) { |
|
218 | 218 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); |
|
219 | 219 | } |
|
220 | 220 | } |
|
221 | 221 | |
|
222 | 222 | void AxisItem::setShadesPen(const QPen& pen) |
|
223 | 223 | { |
|
224 | 224 | foreach(QGraphicsItem* item , m_shades.childItems()) { |
|
225 | 225 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); |
|
226 | 226 | } |
|
227 | 227 | } |
|
228 | 228 | |
|
229 | 229 | void AxisItem::setAxisPen(const QPen& pen) |
|
230 | 230 | { |
|
231 | 231 | foreach(QGraphicsItem* item , m_axis.childItems()) { |
|
232 | 232 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
233 | 233 | } |
|
234 | 234 | } |
|
235 | 235 | |
|
236 | 236 | void AxisItem::setGridPen(const QPen& pen) |
|
237 | 237 | { |
|
238 | 238 | foreach(QGraphicsItem* item , m_grid.childItems()) { |
|
239 | 239 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
240 | 240 | } |
|
241 | 241 | } |
|
242 | 242 | |
|
243 | 243 | void AxisItem::calculateLayout(QVector<qreal>& points) |
|
244 | 244 | { |
|
245 | 245 | switch (m_type) |
|
246 | 246 | { |
|
247 | 247 | case X_AXIS: |
|
248 | 248 | { |
|
249 | 249 | const qreal deltaX = m_rect.width()/(m_thicksList.size()-1); |
|
250 | 250 | for (int i = 0; i < m_thicksList.size(); ++i) { |
|
251 | 251 | int x = i * deltaX + m_rect.left(); |
|
252 | 252 | points[i]=x; |
|
253 | 253 | } |
|
254 | 254 | } |
|
255 | 255 | break; |
|
256 | 256 | case Y_AXIS: |
|
257 | 257 | { |
|
258 | 258 | const qreal deltaY = m_rect.height()/(m_thicksList.size()-1); |
|
259 | 259 | for (int i = 0; i < m_thicksList.size(); ++i) { |
|
260 | 260 | int y = i * -deltaY + m_rect.bottom(); |
|
261 | 261 | points[i]=y; |
|
262 | 262 | } |
|
263 | 263 | } |
|
264 | 264 | break; |
|
265 | 265 | } |
|
266 | 266 | } |
|
267 | 267 | |
|
268 | 268 | void AxisItem::applyLayout(const QVector<qreal>& points) |
|
269 | 269 | { |
|
270 | 270 | Q_ASSERT(points.size() == m_thicksList.size()); |
|
271 | 271 | |
|
272 | 272 | QList<QGraphicsItem *> lines = m_grid.childItems(); |
|
273 | 273 | QList<QGraphicsItem *> labels = m_labels.childItems(); |
|
274 | 274 | QList<QGraphicsItem *> shades = m_shades.childItems(); |
|
275 | 275 | QList<QGraphicsItem *> axis = m_axis.childItems(); |
|
276 | 276 | |
|
277 | 277 | Q_ASSERT(labels.size() == m_thicksList.size()); |
|
278 | 278 | |
|
279 | 279 | switch (m_type) |
|
280 | 280 | { |
|
281 | 281 | case X_AXIS: |
|
282 | 282 | { |
|
283 | 283 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
284 | 284 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); |
|
285 | 285 | |
|
286 | 286 | for (int i = 0; i < points.size(); ++i) { |
|
287 | 287 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
288 | 288 | lineItem->setLine(points[i], m_rect.top(), points[i], m_rect.bottom()); |
|
289 | 289 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
290 | 290 | labelItem->setText(m_thicksList.at(i)); |
|
291 | 291 | QPointF center = labelItem->boundingRect().center(); |
|
292 | 292 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
293 | 293 | labelItem->setPos(points[i] - center.x(), m_rect.bottom() + label_padding); |
|
294 | 294 | if(i%2){ |
|
295 | 295 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2)); |
|
296 | 296 | rectItem->setRect(points[i],m_rect.top(),points[i+1]-points[i],m_rect.height()); |
|
297 | 297 | } |
|
298 | 298 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
299 | 299 | lineItem->setLine(points[i],m_rect.bottom(),points[i],m_rect.bottom()+5); |
|
300 | 300 | } |
|
301 | 301 | } |
|
302 | 302 | break; |
|
303 | 303 | |
|
304 | 304 | case Y_AXIS: |
|
305 | 305 | { |
|
306 | 306 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
307 | 307 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); |
|
308 | 308 | |
|
309 | 309 | for (int i = 0; i < points.size(); ++i) { |
|
310 | 310 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
311 | 311 | lineItem->setLine(m_rect.left() , points[i], m_rect.right(), points[i]); |
|
312 | 312 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
313 | 313 | labelItem->setText(m_thicksList.at(i)); |
|
314 | 314 | QPointF center = labelItem->boundingRect().center(); |
|
315 | 315 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
316 | 316 | labelItem->setPos(m_rect.left() - labelItem->boundingRect().width() - label_padding , points[i]-center.y()); |
|
317 | 317 | if(i%2){ |
|
318 | 318 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2)); |
|
319 | 319 | rectItem->setRect(m_rect.left(),points[i],m_rect.width(),points[i]-points[i+1]); |
|
320 | 320 | } |
|
321 | 321 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
322 | 322 | lineItem->setLine(m_rect.left()-5,points[i],m_rect.left(),points[i]); |
|
323 | 323 | } |
|
324 | 324 | } |
|
325 | 325 | break; |
|
326 | 326 | default: |
|
327 | 327 | qDebug()<<"Unknown axis type"; |
|
328 | 328 | break; |
|
329 | 329 | } |
|
330 | 330 | } |
|
331 | 331 | |
|
332 | 332 | //TODO "nice numbers algorithm" |
|
333 | 333 | #include "moc_axisitem_p.cpp" |
|
334 | 334 | |
|
335 | 335 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,353 +1,353 | |||
|
1 | 1 | #include "qchartaxis.h" |
|
2 | 2 | |
|
3 | 3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
4 | 4 | |
|
5 | 5 | /*! |
|
6 | 6 | \class QChartAxis |
|
7 | 7 | \brief The QChartAxis class is used for manipulating chart's axis |
|
8 | 8 | and for adding optional axes to the chart. |
|
9 | 9 | \mainclass |
|
10 | 10 | |
|
11 | 11 | There is only one x Axis, however there can be multiple y axes. |
|
12 | 12 | Each chart series can be bound to exactly one Y axis and the share common X axis. |
|
13 | 13 | Axis can be setup to show axis line with ticks, gird lines and shades. |
|
14 | 14 | |
|
15 | 15 | */ |
|
16 | 16 | |
|
17 | 17 | /*! |
|
18 | 18 | \fn bool QChartAxis::isAxisVisible() const |
|
19 | 19 | \brief Returns if axis is visible |
|
20 | 20 | \sa setAxisVisible() |
|
21 | 21 | */ |
|
22 | 22 | |
|
23 | 23 | /*! |
|
24 | 24 | \fn QPen QChartAxis::axisPen() const |
|
25 | 25 | \brief Returns pen used to draw axis and ticks. |
|
26 | 26 | \sa setAxisPen() |
|
27 | 27 | */ |
|
28 | 28 | |
|
29 | 29 | |
|
30 | 30 | /*! |
|
31 | 31 | \fn bool QChartAxis::isGridVisible() const |
|
32 | 32 | \brief Returns if grid is visible |
|
33 | 33 | \sa setGridVisible() |
|
34 | 34 | */ |
|
35 | 35 | |
|
36 | 36 | /*! |
|
37 | 37 | \fn QPen QChartAxis::gridPen() const |
|
38 | 38 | \brief Returns pen used to draw grid. |
|
39 | 39 | \sa setGridPen() |
|
40 | 40 | */ |
|
41 | 41 | |
|
42 | 42 | /*! |
|
43 |
\fn bool QChartAxis:: |
|
|
43 | \fn bool QChartAxis::labelsVisible() const | |
|
44 | 44 | \brief Returns if grid is visible |
|
45 | 45 | \sa setLabelsVisible() |
|
46 | 46 | */ |
|
47 | 47 | |
|
48 | 48 | /*! |
|
49 | 49 | \fn QPen QChartAxis::labelsPen() const |
|
50 | 50 | \brief Returns the pen used to labels. |
|
51 | 51 | \sa setLabelsPen() |
|
52 | 52 | */ |
|
53 | 53 | |
|
54 | 54 | /*! |
|
55 | 55 | \fn QBrush QChartAxis::labelsBrush() const |
|
56 | 56 | \brief Returns brush used to draw labels. |
|
57 | 57 | \sa setLabelsBrush() |
|
58 | 58 | */ |
|
59 | 59 | |
|
60 | 60 | /*! |
|
61 | 61 | \fn QFont QChartAxis::labelsFont() const |
|
62 | 62 | \brief Returns font used to draw labels. |
|
63 | 63 | \sa setLabelsFont() |
|
64 | 64 | */ |
|
65 | 65 | |
|
66 | 66 | /*! |
|
67 | 67 | \fn QFont QChartAxis::labelsAngle() const |
|
68 | 68 | \brief Returns angle used to draw labels. |
|
69 | 69 | \sa setLabelsAngle() |
|
70 | 70 | */ |
|
71 | 71 | |
|
72 | 72 | /*! |
|
73 |
\fn bool QChartAxis:: |
|
|
73 | \fn bool QChartAxis::shadesVisible() const | |
|
74 | 74 | \brief Returns if shades are visible. |
|
75 | 75 | \sa setShadesVisible() |
|
76 | 76 | */ |
|
77 | 77 | |
|
78 | 78 | /*! |
|
79 | 79 | \fn qreal QChartAxis::shadesOpacity() const |
|
80 | 80 | \brief Returns opacity of shades. |
|
81 | 81 | */ |
|
82 | 82 | |
|
83 | 83 | /*! |
|
84 | 84 | \fn QPen QChartAxis::shadesPen() const |
|
85 | 85 | \brief Returns pen used to draw shades. |
|
86 | 86 | \sa setShadesPen() |
|
87 | 87 | */ |
|
88 | 88 | |
|
89 | 89 | /*! |
|
90 | 90 | \fn QBrush QChartAxis::shadesBrush() const |
|
91 | 91 | \brief Returns brush used to draw shades. |
|
92 | 92 | \sa setShadesBrush() |
|
93 | 93 | */ |
|
94 | 94 | |
|
95 | 95 | /*! |
|
96 | 96 | \fn qreal QChartAxis::min() const |
|
97 | 97 | \brief Returns minimum value on the axis. |
|
98 | 98 | \sa setMin() |
|
99 | 99 | */ |
|
100 | 100 | |
|
101 | 101 | /*! |
|
102 | 102 | \fn qreal QChartAxis::max() const |
|
103 | 103 | \brief Returns maximim value on the axis. |
|
104 | 104 | \sa setMax() |
|
105 | 105 | */ |
|
106 | 106 | |
|
107 | 107 | /*! |
|
108 | 108 | \fn void QChartAxis::minChanged(qreal min) |
|
109 | 109 | \brief Axis emits signal when \a min of axis has changed. |
|
110 | 110 | */ |
|
111 | 111 | |
|
112 | 112 | /*! |
|
113 | 113 | \fn void QChartAxis::maxChanged(qreal max) |
|
114 | 114 | \brief Axis emits signal when \a max of axis has changed. |
|
115 | 115 | */ |
|
116 | 116 | /*! |
|
117 | 117 | \fn int QChartAxis::ticksCount() const |
|
118 | 118 | \brief Return number of ticks on the axis |
|
119 | 119 | \sa setTicksCount() |
|
120 | 120 | */ |
|
121 | 121 | |
|
122 | 122 | /*! |
|
123 | 123 | \fn void QChartAxis::update(QChartAxis*) |
|
124 | 124 | \brief \internal |
|
125 | 125 | */ |
|
126 | 126 | |
|
127 | 127 | /*! |
|
128 | 128 | \fn void QChartAxis::ticksChanged(QChartAxis*) |
|
129 | 129 | \brief \internal |
|
130 | 130 | */ |
|
131 | 131 | |
|
132 | 132 | /*! |
|
133 | 133 | Constructs new axis object which is a child of \a parent. Ownership is taken by |
|
134 | 134 | QChatView or QChart when axis added. |
|
135 | 135 | */ |
|
136 | 136 | |
|
137 | 137 | QChartAxis::QChartAxis(QObject* parent):QObject(parent), |
|
138 | 138 | m_axisVisible(true), |
|
139 | 139 | m_gridVisible(true), |
|
140 | 140 | m_labelsVisible(true), |
|
141 | 141 | m_labelsAngle(0), |
|
142 | 142 | m_shadesVisible(true), |
|
143 | 143 | m_shadesOpacity(1.0), |
|
144 | 144 | m_min(0), |
|
145 | 145 | m_max(0), |
|
146 | 146 | m_ticksCount(5) |
|
147 | 147 | { |
|
148 | 148 | |
|
149 | 149 | } |
|
150 | 150 | |
|
151 | 151 | /*! |
|
152 | 152 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. |
|
153 | 153 | */ |
|
154 | 154 | |
|
155 | 155 | QChartAxis::~QChartAxis() |
|
156 | 156 | { |
|
157 | 157 | } |
|
158 | 158 | |
|
159 | 159 | /*! |
|
160 | 160 | Sets \a pen used to draw axis line and ticks. |
|
161 | 161 | */ |
|
162 | 162 | void QChartAxis::setAxisPen(const QPen& pen) |
|
163 | 163 | { |
|
164 | 164 | m_axisPen=pen; |
|
165 | 165 | emit update(this); |
|
166 | 166 | } |
|
167 | 167 | |
|
168 | 168 | /*! |
|
169 | 169 | Sets if axis and ticks are \a visible. |
|
170 | 170 | */ |
|
171 | 171 | void QChartAxis::setAxisVisible(bool visible) |
|
172 | 172 | { |
|
173 | 173 | m_axisVisible=visible; |
|
174 | 174 | emit update(this); |
|
175 | 175 | } |
|
176 | 176 | |
|
177 | 177 | /*! |
|
178 | 178 | Sets if grid is \a visible. |
|
179 | 179 | */ |
|
180 | 180 | void QChartAxis::setGridVisible(bool visible) |
|
181 | 181 | { |
|
182 | 182 | m_gridVisible=visible; |
|
183 | 183 | emit update(this); |
|
184 | 184 | } |
|
185 | 185 | |
|
186 | 186 | /*! |
|
187 | 187 | Sets \a pen used to draw grid. |
|
188 | 188 | */ |
|
189 | 189 | void QChartAxis::setGridPen(const QPen& pen) |
|
190 | 190 | { |
|
191 | 191 | m_gridPen=pen; |
|
192 | 192 | emit update(this); |
|
193 | 193 | } |
|
194 | 194 | |
|
195 | 195 | /*! |
|
196 | 196 | Sets if axis' labels are \a visible. |
|
197 | 197 | */ |
|
198 | 198 | void QChartAxis::setLabelsVisible(bool visible) |
|
199 | 199 | { |
|
200 | 200 | m_labelsVisible=visible; |
|
201 | 201 | emit update(this); |
|
202 | 202 | } |
|
203 | 203 | |
|
204 | 204 | /*! |
|
205 | 205 | Sets \a pen used to draw labels. |
|
206 | 206 | */ |
|
207 | 207 | void QChartAxis::setLabelsPen(const QPen& pen) |
|
208 | 208 | { |
|
209 | 209 | m_labelsPen=pen; |
|
210 | 210 | emit update(this); |
|
211 | 211 | } |
|
212 | 212 | |
|
213 | 213 | /*! |
|
214 | 214 | Sets \a brush used to draw labels. |
|
215 | 215 | */ |
|
216 | 216 | void QChartAxis::setLabelsBrush(const QBrush& brush) |
|
217 | 217 | { |
|
218 | 218 | m_labelsBrush=brush; |
|
219 | 219 | emit update(this); |
|
220 | 220 | } |
|
221 | 221 | |
|
222 | 222 | /*! |
|
223 | 223 | Sets \a font used to draw labels. |
|
224 | 224 | */ |
|
225 | 225 | void QChartAxis::setLabelsFont(const QFont& font) |
|
226 | 226 | { |
|
227 | 227 | m_labelsFont=font; |
|
228 | 228 | emit update(this); |
|
229 | 229 | } |
|
230 | 230 | |
|
231 | 231 | /*! |
|
232 | 232 | Sets \a angle for all the labels on given axis. |
|
233 | 233 | */ |
|
234 | 234 | void QChartAxis::setLabelsAngle(int angle) |
|
235 | 235 | { |
|
236 | 236 | m_labelsAngle=angle; |
|
237 | 237 | emit update(this); |
|
238 | 238 | } |
|
239 | 239 | |
|
240 | 240 | /*! |
|
241 | 241 | Sets if shades are \a visible. |
|
242 | 242 | */ |
|
243 | 243 | void QChartAxis::setShadesVisible(bool visible) |
|
244 | 244 | { |
|
245 | 245 | m_shadesVisible=visible; |
|
246 | 246 | emit update(this); |
|
247 | 247 | } |
|
248 | 248 | |
|
249 | 249 | /*! |
|
250 | 250 | Sets \a pen used to draw shades. |
|
251 | 251 | */ |
|
252 | 252 | void QChartAxis::setShadesPen(const QPen& pen) |
|
253 | 253 | { |
|
254 | 254 | m_shadesPen=pen; |
|
255 | 255 | emit update(this); |
|
256 | 256 | } |
|
257 | 257 | |
|
258 | 258 | /*! |
|
259 | 259 | Sets \a brush used to draw shades. |
|
260 | 260 | */ |
|
261 | 261 | void QChartAxis::setShadesBrush(const QBrush& brush) |
|
262 | 262 | { |
|
263 | 263 | m_shadesBrush=brush; |
|
264 | 264 | emit update(this); |
|
265 | 265 | } |
|
266 | 266 | |
|
267 | 267 | /*! |
|
268 | 268 | Sets \a opacity of the shades. |
|
269 | 269 | */ |
|
270 | 270 | void QChartAxis::setShadesOpacity(qreal opacity) |
|
271 | 271 | { |
|
272 | 272 | m_shadesOpacity=opacity; |
|
273 | 273 | emit update(this); |
|
274 | 274 | } |
|
275 | 275 | |
|
276 | 276 | /*! |
|
277 | 277 | Sets \a min value on the axis. |
|
278 | 278 | */ |
|
279 | 279 | void QChartAxis::setMin(qreal min) |
|
280 | 280 | { |
|
281 | 281 | if(m_min!=min){ |
|
282 | 282 | m_min=min; |
|
283 | 283 | emit minChanged(m_min); |
|
284 | 284 | } |
|
285 | 285 | } |
|
286 | 286 | |
|
287 | 287 | /*! |
|
288 | 288 | Sets \a max value on the axis. |
|
289 | 289 | */ |
|
290 | 290 | void QChartAxis::setMax(qreal max) |
|
291 | 291 | { |
|
292 | 292 | if(m_max!=max){ |
|
293 | 293 | m_max=max; |
|
294 | 294 | emit maxChanged(m_max); |
|
295 | 295 | } |
|
296 | 296 | } |
|
297 | 297 | |
|
298 | 298 | /*! |
|
299 | 299 | Sets range from \a min to \a max on the axis. |
|
300 | 300 | */ |
|
301 | 301 | void QChartAxis::setRange(qreal min, qreal max) |
|
302 | 302 | { |
|
303 | 303 | setMin(min); |
|
304 | 304 | setMax(max); |
|
305 | 305 | } |
|
306 | 306 | |
|
307 | 307 | /*! |
|
308 | 308 | Sets \a count for ticks on the axis. |
|
309 | 309 | */ |
|
310 | 310 | void QChartAxis::setTicksCount(int count) |
|
311 | 311 | { |
|
312 | 312 | m_ticksCount=count; |
|
313 | 313 | emit ticksChanged(this); |
|
314 | 314 | } |
|
315 | 315 | |
|
316 | 316 | /*! |
|
317 | 317 | TODO: refactor me. Sets string \a label for \a value on the axis. |
|
318 | 318 | */ |
|
319 | 319 | void QChartAxis::addAxisTickLabel(qreal value,const QString& label) |
|
320 | 320 | { |
|
321 | 321 | m_ticks.insert(value,label); |
|
322 | 322 | emit ticksChanged(this); |
|
323 | 323 | } |
|
324 | 324 | |
|
325 | 325 | /*! |
|
326 | 326 | TODO: refactor me. Removes label for \a value on the axis. |
|
327 | 327 | */ |
|
328 | 328 | void QChartAxis::removeAxisTickLabel(qreal value) |
|
329 | 329 | { |
|
330 | 330 | m_ticks.remove(value); |
|
331 | 331 | emit ticksChanged(this); |
|
332 | 332 | } |
|
333 | 333 | |
|
334 | 334 | /*! |
|
335 | 335 | TODO: refactor me. Returns label for \a value on the axis. |
|
336 | 336 | */ |
|
337 | 337 | QString QChartAxis::axisTickLabel(qreal value) const |
|
338 | 338 | { |
|
339 | 339 | return m_ticks.value(value); |
|
340 | 340 | } |
|
341 | 341 | |
|
342 | 342 | /*! |
|
343 | 343 | TODO: refactor me. Removes all the string labels for on the axis. |
|
344 | 344 | */ |
|
345 | 345 | void QChartAxis::clearAxisTickLabels() |
|
346 | 346 | { |
|
347 | 347 | m_ticks.clear(); |
|
348 | 348 | emit ticksChanged(this); |
|
349 | 349 | } |
|
350 | 350 | |
|
351 | 351 | #include "moc_qchartaxis.cpp" |
|
352 | 352 | |
|
353 | 353 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,101 +1,101 | |||
|
1 | 1 | #ifndef QCHARTAXIS_H_ |
|
2 | 2 | #define QCHARTAXIS_H_ |
|
3 | 3 | |
|
4 | 4 | #include <qchartglobal.h> |
|
5 | 5 | #include <QPen> |
|
6 | 6 | #include <QFont> |
|
7 | 7 | |
|
8 | 8 | |
|
9 | 9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | 10 | |
|
11 | 11 | class QTCOMMERCIALCHART_EXPORT QChartAxis : public QObject |
|
12 | 12 | { |
|
13 | 13 | Q_OBJECT |
|
14 | 14 | public: |
|
15 | 15 | QChartAxis(QObject* parent =0); |
|
16 | 16 | ~QChartAxis(); |
|
17 | 17 | |
|
18 | 18 | //axis handling |
|
19 | 19 | bool isAxisVisible() const { return m_axisVisible;}; |
|
20 | 20 | void setAxisVisible(bool visible); |
|
21 | 21 | void setAxisPen(const QPen& pen); |
|
22 | 22 | QPen axisPen() const { return m_axisPen;}; |
|
23 | 23 | |
|
24 | 24 | //grid handling |
|
25 | 25 | bool isGridVisible() const { return m_gridVisible;}; |
|
26 | 26 | void setGridVisible(bool visible); |
|
27 | 27 | void setGridPen(const QPen& pen); |
|
28 | 28 | QPen gridPen() const {return m_gridPen;} |
|
29 | 29 | |
|
30 | 30 | //labels handling |
|
31 |
bool |
|
|
31 | bool labelsVisible() const { return m_labelsVisible;}; | |
|
32 | 32 | void setLabelsVisible(bool visible); |
|
33 | 33 | void setLabelsPen(const QPen& pen); |
|
34 | 34 | QPen labelsPen() const { return m_labelsPen;} |
|
35 | 35 | void setLabelsBrush(const QBrush& brush); |
|
36 | 36 | QBrush labelsBrush() const { return m_labelsBrush;} |
|
37 | 37 | void setLabelsFont(const QFont& font); |
|
38 | 38 | QFont labelsFont() const { return m_labelsFont;} |
|
39 | 39 | void setLabelsAngle(int angle); |
|
40 | 40 | int labelsAngle() const { return m_labelsAngle;}; |
|
41 | 41 | |
|
42 | 42 | //shades handling |
|
43 |
bool |
|
|
43 | bool shadesVisible() const { return m_shadesVisible;}; | |
|
44 | 44 | void setShadesVisible(bool visible); |
|
45 | 45 | void setShadesPen(const QPen& pen); |
|
46 | 46 | QPen shadesPen() const { return m_shadesPen;} |
|
47 | 47 | void setShadesBrush(const QBrush& brush); |
|
48 | 48 | QBrush shadesBrush() const { return m_shadesBrush;} |
|
49 | 49 | void setShadesOpacity(qreal opacity); |
|
50 | 50 | qreal shadesOpacity() const { return m_shadesOpacity;} |
|
51 | 51 | |
|
52 | 52 | //range handling |
|
53 | 53 | void setMin(qreal min); |
|
54 | 54 | qreal min() const { return m_min;}; |
|
55 | 55 | void setMax(qreal max); |
|
56 | 56 | qreal max() const { return m_max;}; |
|
57 | 57 | void setRange(qreal min, qreal max); |
|
58 | 58 | |
|
59 | 59 | //ticks handling |
|
60 | 60 | void setTicksCount(int count); |
|
61 | 61 | int ticksCount() const { return m_ticksCount;} |
|
62 | 62 | void addAxisTickLabel(qreal value,const QString& label); |
|
63 | 63 | void removeAxisTickLabel(qreal value); |
|
64 | 64 | QString axisTickLabel(qreal value) const ; |
|
65 | 65 | void clearAxisTickLabels(); |
|
66 | 66 | |
|
67 | 67 | signals: |
|
68 | 68 | void minChanged(qreal min); |
|
69 | 69 | void maxChanged(qreal max); |
|
70 | 70 | //private signal |
|
71 | 71 | void update(QChartAxis*); |
|
72 | 72 | void ticksChanged(QChartAxis*); |
|
73 | 73 | |
|
74 | 74 | private: |
|
75 | 75 | bool m_axisVisible; |
|
76 | 76 | QPen m_axisPen; |
|
77 | 77 | QBrush m_axisBrush; |
|
78 | 78 | |
|
79 | 79 | bool m_gridVisible; |
|
80 | 80 | QPen m_gridPen; |
|
81 | 81 | |
|
82 | 82 | bool m_labelsVisible; |
|
83 | 83 | QPen m_labelsPen; |
|
84 | 84 | QBrush m_labelsBrush; |
|
85 | 85 | QFont m_labelsFont; |
|
86 | 86 | int m_labelsAngle; |
|
87 | 87 | |
|
88 | 88 | bool m_shadesVisible; |
|
89 | 89 | QPen m_shadesPen; |
|
90 | 90 | QBrush m_shadesBrush; |
|
91 | 91 | qreal m_shadesOpacity; |
|
92 | 92 | |
|
93 | 93 | qreal m_min; |
|
94 | 94 | qreal m_max; |
|
95 | 95 | |
|
96 | 96 | int m_ticksCount; |
|
97 | 97 | QMap<qreal, QString> m_ticks; |
|
98 | 98 | }; |
|
99 | 99 | |
|
100 | 100 | QTCOMMERCIALCHART_END_NAMESPACE |
|
101 | 101 | #endif /* QCHARTAXIS_H_ */ |
General Comments 0
You need to be logged in to leave comments.
Login now