##// END OF EJS Templates
Adds draft of axis bar label support
Michal Klocek -
r497:9455cddd70de
parent child
Show More
@@ -1,393 +1,397
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(QChartAxis* axis,AxisType type,QGraphicsItem* parent) :
12 12 ChartItem(parent),
13 13 m_chartAxis(axis),
14 14 m_type(type),
15 15 m_labelsAngle(0),
16 16 m_grid(parent),
17 17 m_shades(parent),
18 18 m_labels(parent),
19 19 m_axis(parent)
20 20 {
21 21 //initial initialization
22 22 m_axis.setZValue(ChartPresenter::AxisZValue);
23 23 m_shades.setZValue(ChartPresenter::ShadesZValue);
24 24 m_grid.setZValue(ChartPresenter::GridZValue);
25 25 setFlags(QGraphicsItem::ItemHasNoContents);
26 26
27 27 QObject::connect(m_chartAxis,SIGNAL(updated()),this,SLOT(handleAxisUpdated()));
28 QObject::connect(m_chartAxis->categories(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated()));
28 29 }
29 30
30 31 AxisItem::~AxisItem()
31 32 {
32 33 }
33 34
34 35 QRectF AxisItem::boundingRect() const
35 36 {
36 37 return QRectF();
37 38 }
38 39
39 40 void AxisItem::createItems(int count)
40 41 {
41 42 if(m_axis.children().size()==0)
42 43 m_axis.addToGroup(new QGraphicsLineItem());
43 44 for (int i = 0; i < count; ++i) {
44 45 m_grid.addToGroup(new QGraphicsLineItem());
45 46 m_labels.addToGroup(new QGraphicsSimpleTextItem());
46 47 if(m_grid.childItems().size()%2) m_shades.addToGroup(new QGraphicsRectItem());
47 48 m_axis.addToGroup(new QGraphicsLineItem());
48 49 }
49 50 }
50 51
51 52 void AxisItem::clear(int count)
52 53 {
53 54 QList<QGraphicsItem *> lines = m_grid.childItems();
54 55 QList<QGraphicsItem *> labels = m_labels.childItems();
55 56 QList<QGraphicsItem *> shades = m_shades.childItems();
56 57 QList<QGraphicsItem *> axis = m_axis.childItems();
57 58
58 59 for (int i = 0; i < count; ++i) {
59 60 delete(lines.takeLast());
60 61 delete(labels.takeLast());
61 62 if(lines.size()%2) delete(shades.takeLast());
62 63 delete(axis.takeLast());
63 64 }
64 65 }
65 66
66 67 void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
67 68 {
68 69 Q_UNUSED(painter);
69 70 Q_UNUSED(option);
70 71 Q_UNUSED(widget);
71 72 }
72 73
73 74 void AxisItem::updateItem()
74 75 {
75 76 QStringList labels = createLabels(m_ticks,m_min,m_max);
76 77
77 78 int diff = m_thicksList.size() - labels.size();
78 79
79 80 if(diff>0) {
80 81 clear(diff);
81 82 }
82 83 else if(diff<0) {
83 84 createItems(-diff);
84 85 }
85 86
86 87 if(diff!=0) handleAxisUpdated();
87 88
88 89 m_thicksList=labels;
89 90
90 91 QVector<qreal> layout = calculateLayout();
91 92 if(layout.count()==0) return;
92 93 setLayout(layout);
93 94
94 95 }
95 96
96 97 QStringList AxisItem::createLabels(int ticks, qreal min, qreal max)
97 98 {
98
99
100 99 Q_ASSERT(max>=min);
101 100
102 101 QStringList labels;
103 102
104 //int ticks = axis->ticksCount()-1;
103 QChartAxisCategories* categories = m_chartAxis->categories();
105 104
106 105 for(int i=0; i<= ticks; i++) {
107 106 qreal value = min + (i * (max - min)/ ticks);
108 QString label ;//= axis->axisTickLabel(value);
109 if(label.isEmpty()) {
107 if(categories->count()==0) {
110 108 labels << QString::number(value);
111 109 }
112 110 else {
111 QString label = categories->label(value);
113 112 labels << label;
114 113 }
115 114 }
116 115 return labels;
117 116 }
118 117
119 118 void AxisItem::setAxisOpacity(qreal opacity)
120 119 {
121 120 m_axis.setOpacity(opacity);
122 121 }
123 122
124 123 qreal AxisItem::axisOpacity() const
125 124 {
126 125 return m_axis.opacity();
127 126 }
128 127
129 128 void AxisItem::setGridOpacity(qreal opacity)
130 129 {
131 130 m_grid.setOpacity(opacity);
132 131 }
133 132
134 133 qreal AxisItem::gridOpacity() const
135 134 {
136 135 return m_grid.opacity();
137 136 }
138 137
139 138 void AxisItem::setLabelsOpacity(qreal opacity)
140 139 {
141 140 m_labels.setOpacity(opacity);
142 141 }
143 142
144 143 qreal AxisItem::labelsOpacity() const
145 144 {
146 145 return m_labels.opacity();
147 146 }
148 147
149 148 void AxisItem::setShadesOpacity(qreal opacity)
150 149 {
151 150 m_shades.setOpacity(opacity);
152 151 }
153 152
154 153 qreal AxisItem::shadesOpacity() const
155 154 {
156 155 return m_shades.opacity();
157 156 }
158 157
159 158 void AxisItem::setLabelsAngle(int angle)
160 159 {
161 160 foreach(QGraphicsItem* item , m_labels.childItems()) {
162 161 QPointF center = item->boundingRect().center();
163 162 item->setRotation(angle);
164 163 }
165 164
166 165 m_labelsAngle=angle;
167 166 }
168 167
169 168 void AxisItem::setLabelsPen(const QPen& pen)
170 169 {
171 170 foreach(QGraphicsItem* item , m_labels.childItems()) {
172 171 static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen);
173 172 }
174 173 }
175 174
176 175 void AxisItem::setLabelsBrush(const QBrush& brush)
177 176 {
178 177 foreach(QGraphicsItem* item , m_labels.childItems()) {
179 178 static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush);
180 179 }
181 180 }
182 181
183 182 void AxisItem::setLabelsFont(const QFont& font)
184 183 {
185 184 foreach(QGraphicsItem* item , m_labels.childItems()) {
186 185 static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font);
187 186 }
188 187 }
189 188
190 189 void AxisItem::setShadesBrush(const QBrush& brush)
191 190 {
192 191 foreach(QGraphicsItem* item , m_shades.childItems()) {
193 192 static_cast<QGraphicsRectItem*>(item)->setBrush(brush);
194 193 }
195 194 }
196 195
197 196 void AxisItem::setShadesPen(const QPen& pen)
198 197 {
199 198 foreach(QGraphicsItem* item , m_shades.childItems()) {
200 199 static_cast<QGraphicsRectItem*>(item)->setPen(pen);
201 200 }
202 201 }
203 202
204 203 void AxisItem::setAxisPen(const QPen& pen)
205 204 {
206 205 foreach(QGraphicsItem* item , m_axis.childItems()) {
207 206 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
208 207 }
209 208 }
210 209
211 210 void AxisItem::setGridPen(const QPen& pen)
212 211 {
213 212 foreach(QGraphicsItem* item , m_grid.childItems()) {
214 213 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
215 214 }
216 215 }
217 216
218 217 QVector<qreal> AxisItem::calculateLayout() const
219 218 {
220 219 QVector<qreal> points;
221 220 points.resize(m_thicksList.size());
222 221
223 222 switch (m_type)
224 223 {
225 224 case X_AXIS:
226 225 {
227 226 const qreal deltaX = m_rect.width()/(m_thicksList.size()-1);
228 227 for (int i = 0; i < m_thicksList.size(); ++i) {
229 228 int x = i * deltaX + m_rect.left();
230 229 points[i] = x;
231 230 }
232 231 }
233 232 break;
234 233 case Y_AXIS:
235 234 {
236 235 const qreal deltaY = m_rect.height()/(m_thicksList.size()-1);
237 236 for (int i = 0; i < m_thicksList.size(); ++i) {
238 237 int y = i * -deltaY + m_rect.bottom();
239 238 points[i] = y;
240 239 }
241 240 }
242 241 break;
243 242 }
244 243 return points;
245 244 }
246 245
247 246 void AxisItem::setLayout(const QVector<qreal>& layout)
248 247 {
249 248
250 249 QList<QGraphicsItem *> lines = m_grid.childItems();
251 250 QList<QGraphicsItem *> labels = m_labels.childItems();
252 251 QList<QGraphicsItem *> shades = m_shades.childItems();
253 252 QList<QGraphicsItem *> axis = m_axis.childItems();
254 253
255 254 Q_ASSERT(labels.size() == m_thicksList.size());
256 255 Q_ASSERT(layout.size() == m_thicksList.size());
257 256
258 257 switch (m_type)
259 258 {
260 259 case X_AXIS:
261 260 {
262 261 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
263 262 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
264 263
265 264 for (int i = 0; i < layout.size(); ++i) {
266 265 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
267 266 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
268 267 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
269 268 labelItem->setText(m_thicksList.at(i));
270 269 QPointF center = labelItem->boundingRect().center();
271 270 labelItem->setTransformOriginPoint(center.x(), center.y());
272 271 labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding);
273 if(i%2){
272 if(i%2 && i+1 < layout.size()){
274 273 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2));
275 274 rectItem->setRect(layout[i],m_rect.top(),layout[i+1]-layout[i],m_rect.height());
276 275 }
277 276 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
278 277 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
279 278 }
280 279 }
281 280 break;
282 281
283 282 case Y_AXIS:
284 283 {
285 284 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
286 285 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
287 286
288 287 for (int i = 0; i < layout.size(); ++i) {
289 288 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
290 289 lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]);
291 290 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
292 291 labelItem->setText(m_thicksList.at(i));
293 292 QPointF center = labelItem->boundingRect().center();
294 293 labelItem->setTransformOriginPoint(center.x(), center.y());
295 294 labelItem->setPos(m_rect.left() - labelItem->boundingRect().width() - label_padding , layout[i]-center.y());
296 if(i%2){
295 if(i%2 && i+1 < layout.size()){
297 296 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2));
298 297 rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i]-layout[i+1]);
299 298 }
300 299 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
301 300 lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]);
302 301 }
303 302 }
304 303 break;
305 304 default:
306 305 qDebug()<<"Unknown axis type";
307 306 break;
308 307 }
309 308
310 309 m_layoutVector=layout;
311 310 }
312 311
313 312 //handlers
314 313
314 void AxisItem::handleAxisCategoriesUpdated()
315 {
316 updateItem();
317 }
318
315 319 void AxisItem::handleAxisUpdated()
316 320 {
321
322 int count = m_chartAxis->ticksCount();
323
324 if(m_ticks!=count){
325 m_ticks=count;
326 updateItem();
327 }
328
317 329 if(isEmpty()) return;
318 330
319 331 if(m_chartAxis->isAxisVisible()) {
320 332 setAxisOpacity(100);
321 333 }
322 334 else {
323 335 setAxisOpacity(0);
324 336 }
325 337
326 338 if(m_chartAxis->isGridVisible()) {
327 339 setGridOpacity(100);
328 340 }
329 341 else {
330 342 setGridOpacity(0);
331 343 }
332 344
333 345 if(m_chartAxis->labelsVisible())
334 346 {
335 347 setLabelsOpacity(100);
336 348 }
337 349 else {
338 350 setLabelsOpacity(0);
339 351 }
340 352
341 353 if(m_chartAxis->shadesVisible()) {
342 354 setShadesOpacity(m_chartAxis->shadesOpacity());
343 355 }
344 356 else {
345 357 setShadesOpacity(0);
346 358 }
347 359
348 360 setLabelsAngle(m_chartAxis->labelsAngle());
349 361 setAxisPen(m_chartAxis->axisPen());
350 362 setLabelsPen(m_chartAxis->labelsPen());
351 363 setLabelsBrush(m_chartAxis->labelsBrush());
352 364 setLabelsFont(m_chartAxis->labelsFont());
353 365 setGridPen(m_chartAxis->gridPen());
354 366 setShadesPen(m_chartAxis->shadesPen());
355 367 setShadesBrush(m_chartAxis->shadesBrush());
356 368
357 369 }
358 370
359 371 void AxisItem::handleRangeChanged(qreal min, qreal max)
360 372 {
361 373
362 374 m_min = min;
363 375 m_max = max;
364 376
365 377 if(isEmpty()) return;
366 378 updateItem();
367 379
368 380 }
369 381
370 void AxisItem::handleTicksCountChanged(int ticks)
371 {
372 m_ticks=ticks;
373
374 if(isEmpty()) return;
375 updateItem();
376 }
377
378 382 void AxisItem::handleGeometryChanged(const QRectF& rect)
379 383 {
380 384 m_rect = rect;
381 385 if(isEmpty()) return;
382 386 updateItem();
383 387 }
384 388
385 389 bool AxisItem::isEmpty()
386 390 {
387 391 return m_rect.isEmpty() || m_min==m_max || m_ticks==0;
388 392 }
389 393
390 394 //TODO "nice numbers algorithm"
391 395 #include "moc_axisitem_p.cpp"
392 396
393 397 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,88 +1,89
1 1 #ifndef AXISITEM_H_
2 2 #define AXISITEM_H_
3 3
4 4 #include "domain_p.h"
5 5 #include "chartitem_p.h"
6 6 #include <QGraphicsItem>
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 class QChartAxis;
11 11
12 12 class AxisItem : public QObject, public ChartItem
13 13 {
14 14 Q_OBJECT
15 15 public:
16 16 enum AxisType{X_AXIS,Y_AXIS};
17 17
18 18 AxisItem(QChartAxis* axis,AxisType type = X_AXIS,QGraphicsItem* parent = 0);
19 19 ~AxisItem();
20 20
21 21 //from QGraphicsItem
22 22 QRectF boundingRect() const;
23 23 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
24 24
25 25 AxisType axisType() const {return m_type;};
26 26
27 27 void setAxisOpacity(qreal opacity);
28 28 qreal axisOpacity() const;
29 29
30 30 void setGridOpacity(qreal opacity);
31 31 qreal gridOpacity() const;
32 32
33 33 void setLabelsOpacity(qreal opacity);
34 34 qreal labelsOpacity() const;
35 35
36 36 void setShadesOpacity(qreal opacity);
37 37 qreal shadesOpacity() const;
38 38
39 39 void setLabelsAngle(int angle);
40 40 int labelsAngle()const { return m_labelsAngle; }
41 41
42 42 void setShadesBrush(const QBrush& brush);
43 43 void setShadesPen(const QPen& pen);
44 44
45 45 void setAxisPen(const QPen& pen);
46 46 void setGridPen(const QPen& pen);
47 47
48 48 void setLabelsPen(const QPen& pen);
49 49 void setLabelsBrush(const QBrush& brush);
50 50 void setLabelsFont(const QFont& font);
51 51
52 52 public slots:
53 53 void handleAxisUpdated();//qchartaxis update calls
54 void handleAxisCategoriesUpdated();//qchartaxis update calls
54 55 void handleRangeChanged(qreal min , qreal max); //domain update calls
55 void handleTicksCountChanged(int ticks); //ticks changed
56 56 void handleGeometryChanged(const QRectF& size); //geometry update calls
57 57
58 58 public:
59 59 virtual void updateItem();
60 60 QVector<qreal> calculateLayout() const;
61 61 void setLayout(const QVector<qreal>& points);
62 62 QVector<qreal> layout() { return m_layoutVector;};
63 63
64 64 private:
65 65 inline bool isEmpty();
66 66 void clear(int count);
67 67 void createItems(int count);
68 68 QStringList createLabels(int ticks, qreal min, qreal max);
69
69 70 private:
70 71 QChartAxis* m_chartAxis;
71 72 AxisType m_type;
72 73 QRectF m_rect;
73 74 int m_labelsAngle;
74 75 QGraphicsItemGroup m_grid;
75 76 QGraphicsItemGroup m_shades;
76 77 QGraphicsItemGroup m_labels;
77 78 QGraphicsItemGroup m_axis;
78 79 QStringList m_thicksList;
79 80 QVector<qreal> m_layoutVector;
80 81 qreal m_min;
81 82 qreal m_max;
82 83 int m_ticks;
83 84
84 85 };
85 86
86 87 QTCOMMERCIALCHART_END_NAMESPACE
87 88
88 89 #endif /* AXISITEM_H_ */
@@ -1,103 +1,103
1 1 #ifndef QCHARTAXIS_H_
2 2 #define QCHARTAXIS_H_
3 3
4 4 #include <qchartaxiscategories.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 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 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
63 QChartAxisCategories& categories() { return m_category; }
63 QChartAxisCategories* categories() { return &m_category; }
64 64
65 65 signals:
66 66 void minChanged(qreal min);
67 67 void maxChanged(qreal max);
68 68 void rangeChanged(qreal min, qreal max);
69 69
70 70 //interal signal
71 71 void updated();
72 72 //internal slot
73 73 public slots:
74 74 void handleAxisRangeChanged(qreal min, qreal max);
75 75
76 76 private:
77 77 bool m_axisVisible;
78 78 QPen m_axisPen;
79 79 QBrush m_axisBrush;
80 80
81 81 bool m_gridVisible;
82 82 QPen m_gridPen;
83 83
84 84 bool m_labelsVisible;
85 85 QPen m_labelsPen;
86 86 QBrush m_labelsBrush;
87 87 QFont m_labelsFont;
88 88 int m_labelsAngle;
89 89
90 90 bool m_shadesVisible;
91 91 QPen m_shadesPen;
92 92 QBrush m_shadesBrush;
93 93 qreal m_shadesOpacity;
94 94
95 95 qreal m_min;
96 96 qreal m_max;
97 97
98 98 int m_ticksCount;
99 99 QChartAxisCategories m_category;
100 100 };
101 101
102 102 QTCOMMERCIALCHART_END_NAMESPACE
103 103 #endif /* QCHARTAXIS_H_ */
@@ -1,39 +1,44
1 1 #include "qchartaxiscategories.h"
2 2
3 3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4 4
5 5 QChartAxisCategories::QChartAxisCategories()
6 6 {
7 7 // TODO Auto-generated constructor stub
8 8
9 9 }
10 10
11 11 QChartAxisCategories::~QChartAxisCategories()
12 12 {
13 13 // TODO Auto-generated destructor stub
14 14 }
15 15
16 16 void QChartAxisCategories::insert(qreal value,QString label)
17 17 {
18 18 m_map.insert(value,label);
19 19 emit updated();
20 20 }
21 21 void QChartAxisCategories::remove(qreal value)
22 22 {
23 23 m_map.remove(value);
24 24 emit updated();
25 25 }
26 26 void QChartAxisCategories::clear()
27 27 {
28 28 m_map.clear();
29 29 emit updated();
30 30 }
31 31 int QChartAxisCategories::count()
32 32 {
33 33 return m_map.count();
34 34 emit updated();
35 35 }
36 36
37 QString QChartAxisCategories::label(qreal value) const
38 {
39 return m_map.value(value);
40 }
41
37 42 #include "moc_qchartaxiscategories.cpp"
38 43
39 44 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,33 +1,34
1 1 #ifndef QCHARTAXISCATEGORIES_H_
2 2 #define QCHARTAXISCATEGORIES_H_
3 3 #include "qchartglobal.h"
4 4
5 5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 6
7 7 class QTCOMMERCIALCHART_EXPORT QChartAxisCategories : public QObject
8 8 {
9 9 Q_OBJECT
10 10 private:
11 11 QChartAxisCategories();
12 12 public:
13 13 ~QChartAxisCategories();
14 14
15 15 void insert(qreal value,QString label);
16 16 void remove(qreal value);
17 QString label(qreal value) const;
17 18 void clear();
18 19 int count();
19 20
20 21 //internal signal
21 22 signals:
22 23 void updated();
23 24
24 25 private:
25 26 QMap<qreal,QString> m_map;
26 27
27 28 friend class QChartAxis;
28 29 };
29 30
30 31
31 32 QTCOMMERCIALCHART_END_NAMESPACE
32 33
33 34 #endif /* QCHARTAXISCATEGORIES_H_ */
@@ -1,177 +1,177
1 1 #include "barpresenterbase_p.h"
2 2 #include "bar_p.h"
3 3 #include "barvalue_p.h"
4 4 #include "separator_p.h"
5 5 #include "qbarset.h"
6 6 #include "qbarseries.h"
7 7 #include "qchart.h"
8 8 #include "qchartaxis.h"
9 9 #include "qchartaxiscategories.h"
10 10 #include <QDebug>
11 11 #include <QToolTip>
12 12
13 13 QTCOMMERCIALCHART_BEGIN_NAMESPACE
14 14
15 15 BarPresenterBase::BarPresenterBase(QBarSeries *series, QChart *parent)
16 16 : ChartItem(parent)
17 17 ,mLayoutSet(false)
18 18 ,mSeparatorsEnabled(false)
19 19 ,mSeries(series)
20 20 ,mChart(parent)
21 21 {
22 22 connect(series,SIGNAL(showToolTip(QPoint,QString)),this,SLOT(showToolTip(QPoint,QString)));
23 23 initAxisLabels();
24 24 dataChanged();
25 25 }
26 26
27 27 BarPresenterBase::~BarPresenterBase()
28 28 {
29 29 disconnect(this,SLOT(showToolTip(QPoint,QString)));
30 30 }
31 31
32 32 void BarPresenterBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
33 33 {
34 34 if (!mLayoutSet) {
35 35 qDebug() << "BarPresenterBase::paint called without layout set. Aborting.";
36 36 return;
37 37 }
38 38 foreach(QGraphicsItem* i, childItems()) {
39 39 i->paint(painter,option,widget);
40 40 }
41 41 }
42 42
43 43 QRectF BarPresenterBase::boundingRect() const
44 44 {
45 45 return QRectF(0,0,mWidth,mHeight);
46 46 }
47 47
48 48 void BarPresenterBase::dataChanged()
49 49 {
50 50 // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them?
51 51 // Delete old bars
52 52 foreach (QGraphicsItem* item, childItems()) {
53 53 delete item;
54 54 }
55 55
56 56 mBars.clear();
57 57 mSeparators.clear();
58 58 mFloatingValues.clear();
59 59
60 60 // Create new graphic items for bars
61 61 for (int c=0; c<mSeries->categoryCount(); c++) {
62 62 QString category = mSeries->categoryName(c);
63 63 for (int s=0; s<mSeries->barsetCount(); s++) {
64 64 QBarSet *set = mSeries->barsetAt(s);
65 65 Bar *bar = new Bar(category,this);
66 66 childItems().append(bar);
67 67 mBars.append(bar);
68 68 connect(bar,SIGNAL(clicked(QString)),set,SIGNAL(clicked(QString)));
69 69 connect(bar,SIGNAL(rightClicked(QString)),set,SIGNAL(rightClicked(QString)));
70 70 connect(bar,SIGNAL(hoverEntered(QPoint)),set,SLOT(barHoverEnterEvent(QPoint)));
71 71 connect(bar,SIGNAL(hoverLeaved()),set,SLOT(barHoverLeaveEvent()));
72 72 }
73 73 }
74 74
75 75 // Create separators
76 76 int count = mSeries->categoryCount() - 1; // There is one less separator than columns
77 77 for (int i=0; i<count; i++) {
78 78 Separator* sep = new Separator(this);
79 79 sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme
80 80 sep->setVisible(mSeparatorsEnabled);
81 81 childItems().append(sep);
82 82 mSeparators.append(sep);
83 83 }
84 84
85 85 // Create floating values
86 86 for (int category=0; category<mSeries->categoryCount(); category++) {
87 87 for (int s=0; s<mSeries->barsetCount(); s++) {
88 88 QBarSet *set = mSeries->barsetAt(s);
89 89 BarValue *value = new BarValue(*set, this);
90 90 childItems().append(value);
91 91 mFloatingValues.append(value);
92 92 connect(set,SIGNAL(toggleFloatingValues()),value,SLOT(toggleVisible()));
93 93 }
94 94 }
95 95 }
96 96
97 97 void BarPresenterBase::initAxisLabels()
98 98 {
99 99 int count = mSeries->categoryCount();
100 100 if (0 == count) {
101 101 return;
102 102 }
103 count++;
103 104
104 105 mChart->axisX()->setTicksCount(count);
105 106
106 107 qreal min = 0;
107 qreal max = mSeries->categoryCount();
108 qreal max = count;
108 109
109 110 mChart->axisX()->setMin(min);
110 111 mChart->axisX()->setMax(max);
111 qreal step = (max-min)/count;
112 QChartAxisCategories& categories = mChart->axisX()->categories();
113 categories.clear();
114 for (int i=0; i<count; i++) {
115 qDebug() << "initAxisLabels" << min << mSeries->categoryName(i);
116 categories.insert(min,mSeries->categoryName(i));
117 min += step;
112 min++;
113 QChartAxisCategories* categories = mChart->axisX()->categories();
114 categories->clear();
115 for (int i=0; i<count-1; i++) {
116 categories->insert(min,mSeries->categoryName(i));
117 min++;
118 118 }
119 119 mChart->axisX()->setLabelsVisible(true);
120 120 }
121 121
122 122 //handlers
123 123
124 124 void BarPresenterBase::handleModelChanged(int index)
125 125 {
126 126 // qDebug() << "BarPresenterBase::handleModelChanged" << index;
127 127 dataChanged();
128 128 }
129 129
130 130 void BarPresenterBase::handleDomainChanged(const Domain& domain)
131 131 {
132 132 qDebug() << "BarPresenterBase::handleDomainChanged";
133 133 /*
134 134 int count = mSeries->categoryCount();
135 135 if (0 == count) {
136 136 return;
137 137 }
138 138
139 139 // Position labels to domain
140 140 qreal min = domain.minX();
141 141 qreal max = domain.maxX();
142 142 qreal step = (max-min)/count;
143 143 QChartAxisCategories& categories = mChart->axisX()->categories();
144 144 categories.clear();
145 145 for (int i=0; i<count; i++) {
146 146 categories.insert(min,mSeries->categoryName(i));
147 147 min += step;
148 148 }
149 149 */
150 150 }
151 151
152 152 void BarPresenterBase::handleGeometryChanged(const QRectF& rect)
153 153 {
154 154 mWidth = rect.width();
155 155 mHeight = rect.height();
156 156 layoutChanged();
157 157 mLayoutSet = true;
158 158 setPos(rect.topLeft());
159 159 }
160 160
161 161 void BarPresenterBase::showToolTip(QPoint pos, QString tip)
162 162 {
163 163 // TODO: cool tooltip instead of default
164 164 QToolTip::showText(pos,tip);
165 165 }
166 166
167 167 void BarPresenterBase::enableSeparators(bool enabled)
168 168 {
169 169 for (int i=0; i<mSeparators.count(); i++) {
170 170 mSeparators.at(i)->setVisible(enabled);
171 171 }
172 172 mSeparatorsEnabled = enabled;
173 173 }
174 174
175 175 #include "moc_barpresenterbase_p.cpp"
176 176
177 177 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,386 +1,385
1 1 #include "qchart.h"
2 2 #include "qchartaxis.h"
3 3 #include "chartpresenter_p.h"
4 4 #include "chartdataset_p.h"
5 5 #include "charttheme_p.h"
6 6 //series
7 7 #include "qbarseries.h"
8 8 #include "qstackedbarseries.h"
9 9 #include "qpercentbarseries.h"
10 10 #include "qlineseries.h"
11 11 #include "qareaseries.h"
12 12 #include "qpieseries.h"
13 13 #include "qscatterseries.h"
14 14 #include "qsplineseries.h"
15 15 //items
16 16 #include "axisitem_p.h"
17 17 #include "axisanimationitem_p.h"
18 18 #include "areachartitem_p.h"
19 19 #include "barpresenter_p.h"
20 20 #include "stackedbarpresenter_p.h"
21 21 #include "percentbarpresenter_p.h"
22 22 #include "linechartitem_p.h"
23 23 #include "piepresenter_p.h"
24 24 #include "scatterchartitem_p.h"
25 25 #include "splinechartitem_p.h"
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 29 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
30 30 m_chart(chart),
31 31 m_dataset(dataset),
32 32 m_chartTheme(0),
33 33 m_zoomIndex(0),
34 34 m_marginSize(0),
35 35 m_rect(QRectF(QPoint(0,0),m_chart->size())),
36 36 m_options(QChart::NoAnimation)
37 37 {
38 38 createConnections();
39 39 setChartTheme(QChart::ChartThemeDefault);
40 40 }
41 41
42 42 ChartPresenter::~ChartPresenter()
43 43 {
44 44 }
45 45
46 46 void ChartPresenter::createConnections()
47 47 {
48 48 QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged()));
49 49 QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),this,SLOT(handleSeriesAdded(QSeries*,Domain*)));
50 50 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*)));
51 51 QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),this,SLOT(handleAxisAdded(QChartAxis*,Domain*)));
52 52 QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*)));
53 53 }
54 54
55 55
56 56 QRectF ChartPresenter::geometry() const
57 57 {
58 58 return m_rect;
59 59 }
60 60
61 61 void ChartPresenter::handleGeometryChanged()
62 62 {
63 63 QRectF rect(QPoint(0,0),m_chart->size());
64 64 rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize);
65 65
66 66 //rewrite zoom stack
67 67 for(int i=0;i<m_zoomStack.count();i++){
68 68 QRectF r = m_zoomStack[i];
69 69 qreal w = rect.width()/m_rect.width();
70 70 qreal h = rect.height()/m_rect.height();
71 71 QPointF tl = r.topLeft();
72 72 tl.setX(tl.x()*w);
73 73 tl.setY(tl.y()*h);
74 74 QPointF br = r.bottomRight();
75 75 br.setX(br.x()*w);
76 76 br.setY(br.y()*h);
77 77 r.setTopLeft(tl);
78 78 r.setBottomRight(br);
79 79 m_zoomStack[i]=r;
80 80 }
81 81
82 82 m_rect = rect;
83 83 Q_ASSERT(m_rect.isValid());
84 84 emit geometryChanged(m_rect);
85 85 }
86 86
87 87 int ChartPresenter::margin() const
88 88 {
89 89 return m_marginSize;
90 90 }
91 91
92 92 void ChartPresenter::setMargin(int margin)
93 93 {
94 94 m_marginSize = margin;
95 95 }
96 96
97 97 void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain)
98 98 {
99 99
100 100 AxisItem* item ;
101 101
102 102 if(!m_options.testFlag(QChart::GridAxisAnimations))
103 103 {
104 104 item = new AxisItem(axis,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
105 105 }else{
106 106 item = new AxisAnimationItem(axis,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
107 107 }
108 108 if(axis==m_dataset->axisX()){
109 109 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal)),item,SLOT(handleRangeChanged(qreal,qreal)));
110 110 //initialize
111 111 item->handleRangeChanged(domain->minX(),domain->maxX());
112 item->handleTicksCountChanged(4);
113 112 }
114 113 else{
115 114 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal)),item,SLOT(handleRangeChanged(qreal,qreal)));
116 115 //initialize
117 116 item->handleRangeChanged(domain->minY(),domain->maxY());
118 item->handleTicksCountChanged(4);
117
119 118 }
120 119
121 120 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
122 121 //initialize
123 122 item->handleGeometryChanged(m_rect);
124 123 m_chartTheme->decorate(axis,item);
125 124 m_axisItems.insert(axis,item);
126 125 }
127 126
128 127 void ChartPresenter::handleAxisRemoved(QChartAxis* axis)
129 128 {
130 129 AxisItem* item = m_axisItems.take(axis);
131 130 Q_ASSERT(item);
132 131 delete item;
133 132 }
134 133
135 134
136 135 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
137 136 {
138 137 switch(series->type())
139 138 {
140 139 case QSeries::SeriesTypeLine: {
141 140
142 141 QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
143 142 LineChartItem* item;
144 143 if(m_options.testFlag(QChart::SeriesAnimations)){
145 144 item = new LineChartAnimationItem(lineSeries,m_chart);
146 145 }else{
147 146 item = new LineChartItem(lineSeries,m_chart);
148 147 }
149 148 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
150 149 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
151 150 //initialize
152 151 item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
153 152 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
154 153 //decorate
155 154 m_chartTheme->decorate(item,lineSeries,m_chartItems.count());
156 155 m_chartItems.insert(series,item);
157 156 break;
158 157 }
159 158
160 159 case QSeries::SeriesTypeArea: {
161 160
162 161 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
163 162 AreaChartItem* item;
164 163 if(m_options.testFlag(QChart::SeriesAnimations)) {
165 164 item = new AreaChartItem(areaSeries,m_chart);
166 165 }
167 166 else {
168 167 item = new AreaChartItem(areaSeries,m_chart);
169 168 }
170 169 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
171 170 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
172 171 //initialize
173 172 item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
174 173 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
175 174 //decorate
176 175 m_chartTheme->decorate(item,areaSeries,m_chartItems.count());
177 176 m_chartItems.insert(series,item);
178 177 break;
179 178 }
180 179
181 180 case QSeries::SeriesTypeBar: {
182 181 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
183 182 BarPresenter* item = new BarPresenter(barSeries,m_chart);
184 183 m_chartTheme->decorate(item,barSeries,m_chartItems.count());
185 184 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
186 185 // QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
187 186 m_chartItems.insert(series,item);
188 187 // m_axisXItem->setVisible(false);
189 188 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
190 189 break;
191 190 }
192 191
193 192 case QSeries::SeriesTypeStackedBar: {
194 193
195 194 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
196 195 StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart);
197 196 m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count());
198 197 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
199 198 // QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
200 199 m_chartItems.insert(series,item);
201 200 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
202 201 break;
203 202 }
204 203
205 204 case QSeries::SeriesTypePercentBar: {
206 205
207 206 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
208 207 PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart);
209 208 m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count());
210 209 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
211 210 // QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
212 211 m_chartItems.insert(series,item);
213 212 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
214 213 break;
215 214 }
216 215 case QSeries::SeriesTypeScatter: {
217 216 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
218 217 ScatterChartItem *item;
219 218 if(m_options.testFlag(QChart::SeriesAnimations)) {
220 219 item = new ScatterChartAnimationItem(scatterSeries,m_chart);
221 220 } else {
222 221 item = new ScatterChartItem(scatterSeries, m_chart);
223 222 }
224 223 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)),
225 224 item, SLOT(handleGeometryChanged(const QRectF&)));
226 225 QObject::connect(domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),
227 226 item, SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
228 227 //initialize
229 228 if (m_rect.isValid())
230 229 item->handleGeometryChanged(m_rect);
231 230 item->handleDomainChanged(domain->minX(), domain->maxX(), domain->minY(), domain->maxY());
232 231 //decorate
233 232 m_chartTheme->decorate(item, scatterSeries, m_chartItems.count());
234 233 m_chartItems.insert(scatterSeries, item);
235 234
236 235 break;
237 236 }
238 237 case QSeries::SeriesTypePie: {
239 238 QPieSeries *s = qobject_cast<QPieSeries *>(series);
240 239 PiePresenter* pie = new PiePresenter(m_chart, s);
241 240 m_chartTheme->decorate(pie, s, m_chartItems.count());
242 241 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&)));
243 242
244 243 // Hide all from background when there is only piechart
245 244 // TODO: refactor this ugly code... should be one setting for this
246 245 if (m_chartItems.count() == 0) {
247 246 m_chart->axisX()->setAxisVisible(false);
248 247 m_chart->axisY()->setAxisVisible(false);
249 248 m_chart->axisX()->setGridVisible(false);
250 249 m_chart->axisY()->setGridVisible(false);
251 250 m_chart->axisX()->setLabelsVisible(false);
252 251 m_chart->axisY()->setLabelsVisible(false);
253 252 m_chart->axisX()->setShadesVisible(false);
254 253 m_chart->axisY()->setShadesVisible(false);
255 254 m_chart->setChartBackgroundBrush(Qt::transparent);
256 255 }
257 256
258 257 m_chartItems.insert(series, pie);
259 258 pie->handleGeometryChanged(m_rect);
260 259 break;
261 260 }
262 261
263 262 case QSeries::SeriesTypeSpline: {
264 263
265 264 QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(series);
266 265 SplineChartItem* item;
267 266 if(m_options.testFlag(QChart::SeriesAnimations)) {
268 267 item = new SplineChartAnimationItem(splineSeries, m_chart);
269 268 } else {
270 269 item = new SplineChartItem(splineSeries, m_chart);
271 270 }
272 271 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), item, SLOT(handleGeometryChanged(const QRectF&)));
273 272 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
274 273 //initialize
275 274 item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
276 275 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
277 276 //decorate
278 277 m_chartTheme->decorate(item, splineSeries, m_chartItems.count());
279 278 m_chartItems.insert(splineSeries, item);
280 279 break;
281 280 }
282 281 default: {
283 282 qDebug()<< "Series type" << series->type() << "not implemented.";
284 283 break;
285 284 }
286 285 }
287 286
288 287 zoomReset();
289 288 }
290 289
291 290 void ChartPresenter::handleSeriesRemoved(QSeries* series)
292 291 {
293 292 ChartItem* item = m_chartItems.take(series);
294 293 delete item;
295 294 }
296 295
297 296 void ChartPresenter::setChartTheme(QChart::ChartTheme theme)
298 297 {
299 298 delete m_chartTheme;
300 299
301 300 m_chartTheme = ChartTheme::createTheme(theme);
302 301
303 302 m_chartTheme->decorate(m_chart);
304 303 QMapIterator<QSeries*,ChartItem*> i(m_chartItems);
305 304
306 305 int index=0;
307 306 while (i.hasNext()) {
308 307 i.next();
309 308 m_chartTheme->decorate(i.value(),i.key(),index);
310 309 index++;
311 310 }
312 311
313 312 QMapIterator<QChartAxis*,AxisItem*> j(m_axisItems);
314 313 while (j.hasNext()) {
315 314 j.next();
316 315 m_chartTheme->decorate(j.key(),j.value());
317 316 }
318 317 }
319 318
320 319 QChart::ChartTheme ChartPresenter::chartTheme()
321 320 {
322 321 return m_chartTheme->id();
323 322 }
324 323
325 324 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
326 325 {
327 326 if(m_options!=options) {
328 327
329 328 m_options=options;
330 329
331 330 //recreate elements
332 331 QList<QChartAxis*> axisList = m_axisItems.uniqueKeys();
333 332 QList<QSeries*> seriesList = m_chartItems.uniqueKeys();
334 333
335 334 foreach(QChartAxis* axis, axisList) {
336 335 handleAxisRemoved(axis);
337 336 handleAxisAdded(axis,m_dataset->domain(axis));
338 337 }
339 338 foreach(QSeries* series, seriesList) {
340 339 handleSeriesRemoved(series);
341 340 handleSeriesAdded(series,m_dataset->domain(series));
342 341 }
343 342 }
344 343 }
345 344
346 345 void ChartPresenter::zoomIn()
347 346 {
348 347 QRectF rect = geometry();
349 348 rect.setWidth(rect.width()/2);
350 349 rect.setHeight(rect.height()/2);
351 350 rect.moveCenter(geometry().center());
352 351 zoomIn(rect);
353 352 }
354 353
355 354 void ChartPresenter::zoomIn(const QRectF& rect)
356 355 {
357 356 QRectF r = rect.normalized();
358 357 r.translate(-m_marginSize, -m_marginSize);
359 358 m_dataset->zoomInDomain(r,geometry().size());
360 359 m_zoomStack<<r;
361 360 m_zoomIndex++;
362 361 }
363 362
364 363 void ChartPresenter::zoomOut()
365 364 {
366 365 if(m_zoomIndex==0) return;
367 366 m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size());
368 367 m_zoomIndex--;
369 368 m_zoomStack.resize(m_zoomIndex);
370 369 }
371 370
372 371 void ChartPresenter::zoomReset()
373 372 {
374 373 m_zoomIndex=0;
375 374 m_zoomStack.resize(m_zoomIndex);
376 375 }
377 376
378 377 QChart::AnimationOptions ChartPresenter::animationOptions() const
379 378 {
380 379 return m_options;
381 380 }
382 381
383 382
384 383 #include "moc_chartpresenter_p.cpp"
385 384
386 385 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now