##// END OF EJS Templates
Refactors chartitem...
Michal Klocek -
r677:2b967c4f6e8e
parent child
Show More
@@ -11,7 +11,6 int main(int argc, char *argv[])
11 QApplication a(argc, argv);
11 QApplication a(argc, argv);
12
12
13 //![1]
13 //![1]
14
15 QLineSeries* series0 = new QLineSeries();
14 QLineSeries* series0 = new QLineSeries();
16 QPen blue(Qt::blue);
15 QPen blue(Qt::blue);
17 blue.setWidth(3);
16 blue.setWidth(3);
@@ -6,7 +6,7 Q_DECLARE_METATYPE(QVector<qreal>)
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
7
8
8
9 AxisAnimation::AxisAnimation(AxisItem *axis): ChartAnimation(axis),
9 AxisAnimation::AxisAnimation(Axis *axis): ChartAnimation(axis),
10 m_axis(axis)
10 m_axis(axis)
11 {
11 {
12 }
12 }
@@ -10,13 +10,13 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 class AxisAnimation: public ChartAnimation
10 class AxisAnimation: public ChartAnimation
11 {
11 {
12 public:
12 public:
13 AxisAnimation(AxisItem *axis);
13 AxisAnimation(Axis *axis);
14 ~AxisAnimation();
14 ~AxisAnimation();
15 protected:
15 protected:
16 virtual QVariant interpolated (const QVariant & from, const QVariant & to, qreal progress ) const;
16 virtual QVariant interpolated (const QVariant & from, const QVariant & to, qreal progress ) const;
17 virtual void updateCurrentValue (const QVariant & value );
17 virtual void updateCurrentValue (const QVariant & value );
18 private:
18 private:
19 AxisItem* m_axis;
19 Axis* m_axis;
20 };
20 };
21
21
22 QTCOMMERCIALCHART_END_NAMESPACE
22 QTCOMMERCIALCHART_END_NAMESPACE
@@ -26,7 +26,7 ChartAnimator::~ChartAnimator()
26 {
26 {
27 }
27 }
28
28
29 void ChartAnimator::addAnimation(AxisItem* item)
29 void ChartAnimator::addAnimation(Axis* item)
30 {
30 {
31 ChartAnimation* animation = m_animations.value(item);
31 ChartAnimation* animation = m_animations.value(item);
32
32
@@ -99,13 +99,13 void ChartAnimator::addAnimation(BarChartItem* item)
99 }
99 }
100
100
101
101
102 void ChartAnimator::removeAnimation(ChartItem* item)
102 void ChartAnimator::removeAnimation(Chart* item)
103 {
103 {
104 item->setAnimator(0);
104 item->setAnimator(0);
105 m_animations.remove(item);
105 m_animations.remove(item);
106 }
106 }
107
107
108 void ChartAnimator::updateLayout(AxisItem* item , QVector<qreal>& newLayout)
108 void ChartAnimator::updateLayout(Axis* item , QVector<qreal>& newLayout)
109 {
109 {
110 AxisAnimation* animation = static_cast<AxisAnimation*>(m_animations.value(item));
110 AxisAnimation* animation = static_cast<AxisAnimation*>(m_animations.value(item));
111
111
@@ -123,13 +123,13 void ChartAnimator::updateLayout(AxisItem* item , QVector<qreal>& newLayout)
123
123
124 for(int i=0,j=oldLayout.count()-1;i<(oldLayout.count()+1)/2;i++,j--)
124 for(int i=0,j=oldLayout.count()-1;i<(oldLayout.count()+1)/2;i++,j--)
125 {
125 {
126 oldLayout[i]= item->axisType()==AxisItem::X_AXIS?rect.left():rect.bottom();
126 oldLayout[i]= item->axisType()==Axis::X_AXIS?rect.left():rect.bottom();
127 oldLayout[j]= item->axisType()==AxisItem::X_AXIS?rect.right():rect.top();
127 oldLayout[j]= item->axisType()==Axis::X_AXIS?rect.right():rect.top();
128 }
128 }
129 }
129 }
130 break;
130 break;
131 case ZoomInState: {
131 case ZoomInState: {
132 int index = qMin(oldLayout.count()*(item->axisType()==AxisItem::X_AXIS?m_point.x():(1 -m_point.y())),newLayout.count()-1.0);
132 int index = qMin(oldLayout.count()*(item->axisType()==Axis::X_AXIS?m_point.x():(1 -m_point.y())),newLayout.count()-1.0);
133 oldLayout.resize(newLayout.count());
133 oldLayout.resize(newLayout.count());
134
134
135 for(int i=0;i<oldLayout.count();i++)
135 for(int i=0;i<oldLayout.count();i++)
@@ -163,7 +163,7 void ChartAnimator::updateLayout(AxisItem* item , QVector<qreal>& newLayout)
163 QRectF rect = item->geometry();
163 QRectF rect = item->geometry();
164 for(int i=0, j=oldLayout.count()-1;i<oldLayout.count();i++,j--)
164 for(int i=0, j=oldLayout.count()-1;i<oldLayout.count();i++,j--)
165 {
165 {
166 oldLayout[i]= item->axisType()==AxisItem::X_AXIS?rect.left():rect.top();
166 oldLayout[i]= item->axisType()==Axis::X_AXIS?rect.left():rect.top();
167 }
167 }
168 }
168 }
169 break;
169 break;
@@ -9,7 +9,7
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 class ChartItem;
11 class ChartItem;
12 class AxisItem;
12 class Axis;
13 class AreaChartItem;
13 class AreaChartItem;
14 class SplineChartItem;
14 class SplineChartItem;
15 class ScatterChartItem;
15 class ScatterChartItem;
@@ -19,23 +19,24 class XYChartItem;
19 class ChartAnimator : public QObject {
19 class ChartAnimator : public QObject {
20
20
21 public:
21 public:
22 //TODO: this should be flags in case of two state at the time
23 enum State{ShowState, ScrollUpState, ScrollDownState, ScrollLeftState,ScrollRightState,ZoomInState,ZoomOutState};
22 enum State{ShowState, ScrollUpState, ScrollDownState, ScrollLeftState,ScrollRightState,ZoomInState,ZoomOutState};
23 Q_DECLARE_FLAGS(States, State);
24
24 ChartAnimator(QObject *parent = 0);
25 ChartAnimator(QObject *parent = 0);
25 virtual ~ChartAnimator();
26 virtual ~ChartAnimator();
26
27
27 void addAnimation(AxisItem* item);
28 void addAnimation(Axis* item);
28 void addAnimation(PieChartItem* item);
29 void addAnimation(PieChartItem* item);
29 void addAnimation(ScatterChartItem* item);
30 void addAnimation(ScatterChartItem* item);
30 void addAnimation(LineChartItem* item);
31 void addAnimation(LineChartItem* item);
31 void addAnimation(SplineChartItem* item);
32 void addAnimation(SplineChartItem* item);
32 void addAnimation(BarChartItem* item);
33 void addAnimation(BarChartItem* item);
33 void removeAnimation(ChartItem* item);
34 void removeAnimation(Chart* item);
34
35
35 void animationStarted();
36 void animationStarted();
36 void updateLayout(XYChartItem* item, QVector<QPointF>& oldLayout,QVector<QPointF>& newLayout,int index);
37 void updateLayout(XYChartItem* item, QVector<QPointF>& oldLayout,QVector<QPointF>& newLayout,int index);
37 void updateLayout(SplineChartItem* item, QVector<QPointF>& oldPoints , QVector<QPointF>& newPoints, QVector<QPointF>& oldControlPoints, QVector<QPointF>& newContorlPoints,int index);
38 void updateLayout(SplineChartItem* item, QVector<QPointF>& oldPoints , QVector<QPointF>& newPoints, QVector<QPointF>& oldControlPoints, QVector<QPointF>& newContorlPoints,int index);
38 void updateLayout(AxisItem* item, QVector<qreal>& layout);
39 void updateLayout(Axis* item, QVector<qreal>& layout);
39
40
40 void addAnimation(PieChartItem* item, QPieSlice *slice, const PieSliceData &sliceData, bool isEmpty);
41 void addAnimation(PieChartItem* item, QPieSlice *slice, const PieSliceData &sliceData, bool isEmpty);
41 void removeAnimation(PieChartItem* item, QPieSlice *slice);
42 void removeAnimation(PieChartItem* item, QPieSlice *slice);
@@ -47,7 +48,7 public:
47 void setState(State state,const QPointF& point = QPointF());
48 void setState(State state,const QPointF& point = QPointF());
48
49
49 private:
50 private:
50 QMap<ChartItem*,ChartAnimation*> m_animations;
51 QMap<Chart*,ChartAnimation*> m_animations;
51 State m_state;
52 State m_state;
52 QPointF m_point;
53 QPointF m_point;
53 };
54 };
@@ -69,7 +69,7 QVariant XYAnimation::interpolated(const QVariant &start, const QVariant & end,
69 }
69 }
70 break;
70 break;
71 default:
71 default:
72 qWarning()<<"Unknow type of animation";
72 qWarning()<<"Unknown type of animation";
73 break;
73 break;
74 }
74 }
75
75
@@ -10,16 +10,16 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 //TODO: optimize : remove points which are not visible
11 //TODO: optimize : remove points which are not visible
12
12
13 AreaChartItem::AreaChartItem(QAreaSeries* areaSeries,QGraphicsItem *parent):ChartItem(parent),
13 AreaChartItem::AreaChartItem(QAreaSeries* areaSeries,ChartPresenter *presenter):Chart(presenter),QGraphicsItem(presenter->rootItem()),
14 m_series(areaSeries),
14 m_series(areaSeries),
15 m_upper(0),
15 m_upper(0),
16 m_lower(0),
16 m_lower(0),
17 m_pointsVisible(false)
17 m_pointsVisible(false)
18 {
18 {
19 setZValue(ChartPresenter::LineChartZValue);
19 setZValue(ChartPresenter::LineChartZValue);
20 m_upper = new AreaBoundItem(this,m_series->upperSeries());
20 m_upper = new AreaBoundItem(this,m_series->upperSeries(),presenter);
21 if(m_series->lowerSeries()){
21 if(m_series->lowerSeries()){
22 m_lower = new AreaBoundItem(this,m_series->lowerSeries());
22 m_lower = new AreaBoundItem(this,m_series->lowerSeries(),presenter);
23 }
23 }
24
24
25 QObject::connect(areaSeries,SIGNAL(updated()),this,SLOT(handleUpdated()));
25 QObject::connect(areaSeries,SIGNAL(updated()),this,SLOT(handleUpdated()));
@@ -10,11 +10,11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 class QAreaSeries;
10 class QAreaSeries;
11 class AreaChartItem;
11 class AreaChartItem;
12
12
13 class AreaChartItem : public QObject ,public ChartItem
13 class AreaChartItem : public Chart, public QGraphicsItem
14 {
14 {
15 Q_OBJECT
15 Q_OBJECT
16 public:
16 public:
17 AreaChartItem(QAreaSeries* areaSeries, QGraphicsItem *parent = 0);
17 AreaChartItem(QAreaSeries* areaSeries, ChartPresenter *presenter);
18 ~ AreaChartItem();
18 ~ AreaChartItem();
19
19
20 //from QGraphicsItem
20 //from QGraphicsItem
@@ -55,7 +55,7 private:
55 class AreaBoundItem : public LineChartItem
55 class AreaBoundItem : public LineChartItem
56 {
56 {
57 public:
57 public:
58 AreaBoundItem(AreaChartItem* item,QLineSeries* lineSeries):LineChartItem(lineSeries),
58 AreaBoundItem(AreaChartItem* item,QLineSeries* lineSeries,ChartPresenter *presenter):LineChartItem(lineSeries,presenter),
59 m_item(item){};
59 m_item(item){};
60
60
61 ~AreaBoundItem(){};
61 ~AreaBoundItem(){};
@@ -9,25 +9,25 static int label_padding = 5;
9
9
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11
11
12 AxisItem::AxisItem(QChartAxis* axis,ChartPresenter* presenter,AxisType type,QGraphicsItem* parent) :
12 Axis::Axis(QChartAxis* axis,ChartPresenter* presenter,AxisType type) :
13 ChartItem(parent),
13 Chart(presenter),
14 m_presenter(presenter),
15 m_chartAxis(axis),
14 m_chartAxis(axis),
16 m_type(type),
15 m_type(type),
17 m_labelsAngle(0),
16 m_labelsAngle(0),
18 m_grid(parent),
17 m_grid(presenter->rootItem()),
19 m_shades(parent),
18 m_shades(presenter->rootItem()),
20 m_labels(parent),
19 m_labels(presenter->rootItem()),
21 m_axis(parent),
20 m_axis(presenter->rootItem()),
22 m_min(0),
21 m_min(0),
23 m_max(0),
22 m_max(0),
24 m_ticksCount(0)
23 m_ticksCount(0)
25 {
24 {
26 //initial initialization
25 //initial initialization
27 m_axis.setZValue(ChartPresenter::AxisZValue);
26 m_axis.setZValue(ChartPresenter::AxisZValue);
27 m_axis.setHandlesChildEvents(false);
28
28 m_shades.setZValue(ChartPresenter::ShadesZValue);
29 m_shades.setZValue(ChartPresenter::ShadesZValue);
29 m_grid.setZValue(ChartPresenter::GridZValue);
30 m_grid.setZValue(ChartPresenter::GridZValue);
30 setFlags(QGraphicsItem::ItemHasNoContents);
31
31
32 QObject::connect(m_chartAxis,SIGNAL(updated()),this,SLOT(handleAxisUpdated()));
32 QObject::connect(m_chartAxis,SIGNAL(updated()),this,SLOT(handleAxisUpdated()));
33 QObject::connect(m_chartAxis->categories(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated()));
33 QObject::connect(m_chartAxis->categories(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated()));
@@ -35,20 +35,15 m_ticksCount(0)
35 handleAxisUpdated();
35 handleAxisUpdated();
36 }
36 }
37
37
38 AxisItem::~AxisItem()
38 Axis::~Axis()
39 {
40 }
41
42 QRectF AxisItem::boundingRect() const
43 {
39 {
44 return QRectF();
45 }
40 }
46
41
47 void AxisItem::createItems(int count)
42 void Axis::createItems(int count)
48 {
43 {
49
44
50 if(m_axis.children().size()==0)
45 if(m_axis.children().size()==0)
51 m_axis.addToGroup(new QGraphicsLineItem());
46 m_axis.addToGroup(new AxisItem(this));
52 for (int i = 0; i < count; ++i) {
47 for (int i = 0; i < count; ++i) {
53 m_grid.addToGroup(new QGraphicsLineItem());
48 m_grid.addToGroup(new QGraphicsLineItem());
54 m_labels.addToGroup(new QGraphicsSimpleTextItem());
49 m_labels.addToGroup(new QGraphicsSimpleTextItem());
@@ -57,7 +52,7 void AxisItem::createItems(int count)
57 }
52 }
58 }
53 }
59
54
60 void AxisItem::deleteItems(int count)
55 void Axis::deleteItems(int count)
61 {
56 {
62 QList<QGraphicsItem *> lines = m_grid.childItems();
57 QList<QGraphicsItem *> lines = m_grid.childItems();
63 QList<QGraphicsItem *> labels = m_labels.childItems();
58 QList<QGraphicsItem *> labels = m_labels.childItems();
@@ -72,15 +67,15 void AxisItem::deleteItems(int count)
72 }
67 }
73 }
68 }
74
69
75 void AxisItem::updateLayout(QVector<qreal>& layout)
70 void Axis::updateLayout(QVector<qreal>& layout)
76 {
71 {
77 if(m_animator){
72 if(animator()){
78 m_animator->updateLayout(this,layout);
73 animator()->updateLayout(this,layout);
79 }
74 }
80 else setLayout(layout);
75 else setLayout(layout);
81 }
76 }
82
77
83 QStringList AxisItem::createLabels(int ticks, qreal min, qreal max) const
78 QStringList Axis::createLabels(int ticks, qreal min, qreal max) const
84 {
79 {
85 Q_ASSERT(max>=min);
80 Q_ASSERT(max>=min);
86 Q_ASSERT(ticks>0);
81 Q_ASSERT(ticks>0);
@@ -103,47 +98,47 QStringList AxisItem::createLabels(int ticks, qreal min, qreal max) const
103 return labels;
98 return labels;
104 }
99 }
105
100
106 void AxisItem::setAxisOpacity(qreal opacity)
101 void Axis::setAxisOpacity(qreal opacity)
107 {
102 {
108 m_axis.setOpacity(opacity);
103 m_axis.setOpacity(opacity);
109 }
104 }
110
105
111 qreal AxisItem::axisOpacity() const
106 qreal Axis::axisOpacity() const
112 {
107 {
113 return m_axis.opacity();
108 return m_axis.opacity();
114 }
109 }
115
110
116 void AxisItem::setGridOpacity(qreal opacity)
111 void Axis::setGridOpacity(qreal opacity)
117 {
112 {
118 m_grid.setOpacity(opacity);
113 m_grid.setOpacity(opacity);
119 }
114 }
120
115
121 qreal AxisItem::gridOpacity() const
116 qreal Axis::gridOpacity() const
122 {
117 {
123 return m_grid.opacity();
118 return m_grid.opacity();
124 }
119 }
125
120
126 void AxisItem::setLabelsOpacity(qreal opacity)
121 void Axis::setLabelsOpacity(qreal opacity)
127 {
122 {
128 m_labels.setOpacity(opacity);
123 m_labels.setOpacity(opacity);
129 }
124 }
130
125
131 qreal AxisItem::labelsOpacity() const
126 qreal Axis::labelsOpacity() const
132 {
127 {
133 return m_labels.opacity();
128 return m_labels.opacity();
134 }
129 }
135
130
136 void AxisItem::setShadesOpacity(qreal opacity)
131 void Axis::setShadesOpacity(qreal opacity)
137 {
132 {
138 m_shades.setOpacity(opacity);
133 m_shades.setOpacity(opacity);
139 }
134 }
140
135
141 qreal AxisItem::shadesOpacity() const
136 qreal Axis::shadesOpacity() const
142 {
137 {
143 return m_shades.opacity();
138 return m_shades.opacity();
144 }
139 }
145
140
146 void AxisItem::setLabelsAngle(int angle)
141 void Axis::setLabelsAngle(int angle)
147 {
142 {
148 foreach(QGraphicsItem* item , m_labels.childItems()) {
143 foreach(QGraphicsItem* item , m_labels.childItems()) {
149 QPointF center = item->boundingRect().center();
144 QPointF center = item->boundingRect().center();
@@ -153,56 +148,56 void AxisItem::setLabelsAngle(int angle)
153 m_labelsAngle=angle;
148 m_labelsAngle=angle;
154 }
149 }
155
150
156 void AxisItem::setLabelsPen(const QPen& pen)
151 void Axis::setLabelsPen(const QPen& pen)
157 {
152 {
158 foreach(QGraphicsItem* item , m_labels.childItems()) {
153 foreach(QGraphicsItem* item , m_labels.childItems()) {
159 static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen);
154 static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen);
160 }
155 }
161 }
156 }
162
157
163 void AxisItem::setLabelsBrush(const QBrush& brush)
158 void Axis::setLabelsBrush(const QBrush& brush)
164 {
159 {
165 foreach(QGraphicsItem* item , m_labels.childItems()) {
160 foreach(QGraphicsItem* item , m_labels.childItems()) {
166 static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush);
161 static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush);
167 }
162 }
168 }
163 }
169
164
170 void AxisItem::setLabelsFont(const QFont& font)
165 void Axis::setLabelsFont(const QFont& font)
171 {
166 {
172 foreach(QGraphicsItem* item , m_labels.childItems()) {
167 foreach(QGraphicsItem* item , m_labels.childItems()) {
173 static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font);
168 static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font);
174 }
169 }
175 }
170 }
176
171
177 void AxisItem::setShadesBrush(const QBrush& brush)
172 void Axis::setShadesBrush(const QBrush& brush)
178 {
173 {
179 foreach(QGraphicsItem* item , m_shades.childItems()) {
174 foreach(QGraphicsItem* item , m_shades.childItems()) {
180 static_cast<QGraphicsRectItem*>(item)->setBrush(brush);
175 static_cast<QGraphicsRectItem*>(item)->setBrush(brush);
181 }
176 }
182 }
177 }
183
178
184 void AxisItem::setShadesPen(const QPen& pen)
179 void Axis::setShadesPen(const QPen& pen)
185 {
180 {
186 foreach(QGraphicsItem* item , m_shades.childItems()) {
181 foreach(QGraphicsItem* item , m_shades.childItems()) {
187 static_cast<QGraphicsRectItem*>(item)->setPen(pen);
182 static_cast<QGraphicsRectItem*>(item)->setPen(pen);
188 }
183 }
189 }
184 }
190
185
191 void AxisItem::setAxisPen(const QPen& pen)
186 void Axis::setAxisPen(const QPen& pen)
192 {
187 {
193 foreach(QGraphicsItem* item , m_axis.childItems()) {
188 foreach(QGraphicsItem* item , m_axis.childItems()) {
194 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
189 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
195 }
190 }
196 }
191 }
197
192
198 void AxisItem::setGridPen(const QPen& pen)
193 void Axis::setGridPen(const QPen& pen)
199 {
194 {
200 foreach(QGraphicsItem* item , m_grid.childItems()) {
195 foreach(QGraphicsItem* item , m_grid.childItems()) {
201 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
196 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
202 }
197 }
203 }
198 }
204
199
205 QVector<qreal> AxisItem::calculateLayout() const
200 QVector<qreal> Axis::calculateLayout() const
206 {
201 {
207 Q_ASSERT(m_ticksCount>=2);
202 Q_ASSERT(m_ticksCount>=2);
208
203
@@ -233,7 +228,7 QVector<qreal> AxisItem::calculateLayout() const
233 return points;
228 return points;
234 }
229 }
235
230
236 void AxisItem::setLayout(QVector<qreal>& layout)
231 void Axis::setLayout(QVector<qreal>& layout)
237 {
232 {
238 int diff = m_layoutVector.size() - layout.size();
233 int diff = m_layoutVector.size() - layout.size();
239
234
@@ -311,20 +306,20 void AxisItem::setLayout(QVector<qreal>& layout)
311 m_layoutVector=layout;
306 m_layoutVector=layout;
312 }
307 }
313
308
314 bool AxisItem::isEmpty()
309 bool Axis::isEmpty()
315 {
310 {
316 return m_rect.isEmpty() || m_min==m_max || m_ticksCount==0;
311 return m_rect.isEmpty() || m_min==m_max || m_ticksCount==0;
317 }
312 }
318
313
319 //handlers
314 //handlers
320
315
321 void AxisItem::handleAxisCategoriesUpdated()
316 void Axis::handleAxisCategoriesUpdated()
322 {
317 {
323 if(isEmpty()) return;
318 if(isEmpty()) return;
324 updateLayout(m_layoutVector);
319 updateLayout(m_layoutVector);
325 }
320 }
326
321
327 void AxisItem::handleAxisUpdated()
322 void Axis::handleAxisUpdated()
328 {
323 {
329
324
330 if(isEmpty()) return;
325 if(isEmpty()) return;
@@ -369,7 +364,7 void AxisItem::handleAxisUpdated()
369
364
370 }
365 }
371
366
372 void AxisItem::handleRangeChanged(qreal min, qreal max,int tickCount)
367 void Axis::handleRangeChanged(qreal min, qreal max,int tickCount)
373 {
368 {
374 if(min==max || tickCount<2) return;
369 if(min==max || tickCount<2) return;
375
370
@@ -383,7 +378,7 void AxisItem::handleRangeChanged(qreal min, qreal max,int tickCount)
383
378
384 }
379 }
385
380
386 void AxisItem::handleGeometryChanged(const QRectF& rect)
381 void Axis::handleGeometryChanged(const QRectF& rect)
387 {
382 {
388 m_rect = rect;
383 m_rect = rect;
389 if(isEmpty()) return;
384 if(isEmpty()) return;
@@ -391,13 +386,9 void AxisItem::handleGeometryChanged(const QRectF& rect)
391 updateLayout(layout);
386 updateLayout(layout);
392 }
387 }
393
388
394 //painter
389 void Axis::axisSelected()
395
396 void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
397 {
390 {
398 Q_UNUSED(painter)
391 qDebug()<<"TODO axis clicked";
399 Q_UNUSED(option)
400 Q_UNUSED(widget)
401 }
392 }
402
393
403 //TODO "nice numbers algorithm"
394 //TODO "nice numbers algorithm"
@@ -2,7 +2,7
2 #define AXISITEM_H_
2 #define AXISITEM_H_
3
3
4 #include "domain_p.h"
4 #include "domain_p.h"
5 #include "chartitem_p.h"
5 #include "chart_p.h"
6 #include <QGraphicsItem>
6 #include <QGraphicsItem>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -10,18 +10,14 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 class QChartAxis;
10 class QChartAxis;
11 class ChartPresenter;
11 class ChartPresenter;
12
12
13 class AxisItem : public QObject, public ChartItem
13 class Axis : public Chart
14 {
14 {
15 Q_OBJECT
15 Q_OBJECT
16 public:
16 public:
17 enum AxisType{X_AXIS,Y_AXIS};
17 enum AxisType{X_AXIS,Y_AXIS};
18
18
19 AxisItem(QChartAxis* axis,ChartPresenter* presenter,AxisType type = X_AXIS,QGraphicsItem* parent = 0);
19 Axis(QChartAxis* axis,ChartPresenter* presenter,AxisType type = X_AXIS);
20 ~AxisItem();
20 ~Axis();
21
22 //from QGraphicsItem
23 QRectF boundingRect() const;
24 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
25
21
26 AxisType axisType() const {return m_type;};
22 AxisType axisType() const {return m_type;};
27
23
@@ -70,9 +66,9 private:
70 void setLayout(QVector<qreal>& layout);
66 void setLayout(QVector<qreal>& layout);
71
67
72 QStringList createLabels(int ticks, qreal min, qreal max) const;
68 QStringList createLabels(int ticks, qreal min, qreal max) const;
69 void axisSelected();
73
70
74 private:
71 private:
75 ChartPresenter* m_presenter;
76 QChartAxis* m_chartAxis;
72 QChartAxis* m_chartAxis;
77 AxisType m_type;
73 AxisType m_type;
78 QRectF m_rect;
74 QRectF m_rect;
@@ -88,6 +84,36 private:
88 qreal m_zoomFactor;
84 qreal m_zoomFactor;
89
85
90 friend class AxisAnimation;
86 friend class AxisAnimation;
87 friend class AxisItem;
88
89 };
90
91 class AxisItem: public QGraphicsLineItem
92 {
93 public:
94
95 AxisItem(Axis* axis,QGraphicsItem* parent=0):QGraphicsLineItem(parent),m_axis(axis){};
96
97 protected:
98 void mousePressEvent(QGraphicsSceneMouseEvent *event)
99 {
100 Q_UNUSED(event)
101 m_axis->axisSelected();
102 }
103
104 QRectF boundingRect() const
105 {
106 return QGraphicsLineItem::boundingRect().adjusted(0,0,m_axis->axisType()!=Axis::X_AXIS?10:0,m_axis->axisType()!=Axis::Y_AXIS?10:0);
107 }
108
109 QPainterPath shape() const
110 {
111 QPainterPath path;
112 path.addRect(boundingRect());
113 return path;
114 }
115 private:
116 Axis* m_axis;
91
117
92 };
118 };
93
119
@@ -13,13 +13,12
13
13
14 QTCOMMERCIALCHART_BEGIN_NAMESPACE
14 QTCOMMERCIALCHART_BEGIN_NAMESPACE
15
15
16 BarChartItem::BarChartItem(QBarSeries *series, QChart *parent) :
16 BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) :
17 ChartItem(parent),
17 ChartItem(presenter),
18 mHeight(0),
18 mHeight(0),
19 mWidth(0),
19 mWidth(0),
20 mLayoutSet(false),
20 mLayoutSet(false),
21 mSeries(series),
21 mSeries(series)
22 mChart(parent)
23 {
22 {
24 connect(series,SIGNAL(showToolTip(QPoint,QString)),this,SLOT(showToolTip(QPoint,QString)));
23 connect(series,SIGNAL(showToolTip(QPoint,QString)),this,SLOT(showToolTip(QPoint,QString)));
25 connect(series, SIGNAL(updatedBars()), this, SLOT(layoutChanged()));
24 connect(series, SIGNAL(updatedBars()), this, SLOT(layoutChanged()));
@@ -20,9 +20,12 class BarChartItem : public QObject, public ChartItem
20 {
20 {
21 Q_OBJECT
21 Q_OBJECT
22 public:
22 public:
23 BarChartItem(QBarSeries *series, QChart *parent = 0);
23 BarChartItem(QBarSeries *series, ChartPresenter *presenter);
24 virtual ~BarChartItem();
24 virtual ~BarChartItem();
25
25
26 // Common implemantation of different presenters. Not to be instantiated.
27 // TODO: combine this with BarPresenter and derive other presenters from it?
28
26 public:
29 public:
27 // From QGraphicsItem
30 // From QGraphicsItem
28 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
31 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
@@ -68,7 +71,6 protected:
68 QBarSeries* mSeries;
71 QBarSeries* mSeries;
69 QList<Bar*> mBars;
72 QList<Bar*> mBars;
70 QList<BarValue*> mFloatingValues;
73 QList<BarValue*> mFloatingValues;
71 QChart* mChart;
72 };
74 };
73
75
74 QTCOMMERCIALCHART_END_NAMESPACE
76 QTCOMMERCIALCHART_END_NAMESPACE
@@ -6,9 +6,8
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9
9 PercentBarChartItem::PercentBarChartItem(QBarSeries *series, ChartPresenter* presenter) :
10 PercentBarChartItem::PercentBarChartItem(QBarSeries *series, QChart *parent) :
10 BarChartItem(series, presenter)
11 BarChartItem(series, parent)
12 {
11 {
13 }
12 }
14
13
@@ -5,7 +5,7
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6
6
7 Separator::Separator(QGraphicsItem *parent)
7 Separator::Separator(QGraphicsItem *parent)
8 : ChartItem(parent)
8 : QGraphicsItem(parent)
9 {
9 {
10 }
10 }
11
11
@@ -5,7 +5,7
5
5
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
7
8 class Separator : public ChartItem
8 class Separator : public QGraphicsItem
9 {
9 {
10 public:
10 public:
11 Separator(QGraphicsItem *parent = 0);
11 Separator(QGraphicsItem *parent = 0);
@@ -6,8 +6,8
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 StackedBarChartItem::StackedBarChartItem(QBarSeries *series, QChart *parent) :
9 StackedBarChartItem::StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter) :
10 BarChartItem(series,parent)
10 BarChartItem(series,presenter)
11 {
11 {
12 }
12 }
13
13
@@ -1,31 +1,17
1 #ifndef CHARTITEM_H_
1 #ifndef CHARTITEM_H_
2 #define CHARTITEM_H_
2 #define CHARTITEM_H_
3
3
4 #include "domain_p.h"
4 #include "chart_p.h"
5 #include "chartpresenter_p.h"
5 #include <QGraphicsItem>
6 #include <QGraphicsItem>
6
7
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
9
9 class ChartAnimator;
10 class ChartItem : public QGraphicsItem, public Chart
10
11 class ChartItem : public QGraphicsItem
12 {
11 {
13 enum ChartItemTypes{ AXIS_ITEM = UserType+1, XYLINE_ITEM};
12 enum ChartItemTypes{ AXIS_ITEM = UserType+1, XYLINE_ITEM};
14 public:
13 public:
15 ChartItem(QGraphicsItem* parent = 0):QGraphicsItem(parent),
14 ChartItem(ChartPresenter *presenter):QGraphicsItem(presenter->rootItem()),Chart(presenter){};
16 m_animator(0){};
17 //TODO make pure
18 virtual void handleGeometryChanged(const QRectF&){};
19 virtual void handleDomainChanged(qreal,qreal,qreal,qreal){};
20
21 void setAnimator(ChartAnimator* animator){
22 m_animator=animator;
23 }
24
25 virtual ~ChartItem(){};
26
27 protected:
28 ChartAnimator* m_animator;
29 };
15 };
30
16
31 QTCOMMERCIALCHART_END_NAMESPACE
17 QTCOMMERCIALCHART_END_NAMESPACE
@@ -88,7 +88,7 void ChartPresenter::handleGeometryChanged()
88
88
89 void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain)
89 void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain)
90 {
90 {
91 AxisItem* item = new AxisItem(axis,this,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
91 Axis* item = new Axis(axis,this,axis==m_dataset->axisX()?Axis::X_AXIS : Axis::Y_AXIS);
92
92
93 if(m_options.testFlag(QChart::GridAxisAnimations)){
93 if(m_options.testFlag(QChart::GridAxisAnimations)){
94 m_animator->addAnimation(item);
94 m_animator->addAnimation(item);
@@ -116,7 +116,7 void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain)
116
116
117 void ChartPresenter::handleAxisRemoved(QChartAxis* axis)
117 void ChartPresenter::handleAxisRemoved(QChartAxis* axis)
118 {
118 {
119 AxisItem* item = m_axisItems.take(axis);
119 Axis* item = m_axisItems.take(axis);
120 Q_ASSERT(item);
120 Q_ASSERT(item);
121 if(m_animator) m_animator->removeAnimation(item);
121 if(m_animator) m_animator->removeAnimation(item);
122 delete item;
122 delete item;
@@ -125,14 +125,14 void ChartPresenter::handleAxisRemoved(QChartAxis* axis)
125
125
126 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
126 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
127 {
127 {
128 ChartItem *item = 0 ;
128 Chart *item = 0 ;
129
129
130 switch(series->type())
130 switch(series->type())
131 {
131 {
132 case QSeries::SeriesTypeLine: {
132 case QSeries::SeriesTypeLine: {
133
133
134 QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
134 QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
135 LineChartItem* line = new LineChartItem(lineSeries,m_chart);
135 LineChartItem* line = new LineChartItem(lineSeries,this);
136 if(m_options.testFlag(QChart::SeriesAnimations)) {
136 if(m_options.testFlag(QChart::SeriesAnimations)) {
137 m_animator->addAnimation(line);
137 m_animator->addAnimation(line);
138 }
138 }
@@ -146,7 +146,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
146 case QSeries::SeriesTypeArea: {
146 case QSeries::SeriesTypeArea: {
147
147
148 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
148 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
149 AreaChartItem* area = new AreaChartItem(areaSeries,m_chart);
149 AreaChartItem* area = new AreaChartItem(areaSeries,this);
150 if(m_options.testFlag(QChart::SeriesAnimations)) {
150 if(m_options.testFlag(QChart::SeriesAnimations)) {
151 m_animator->addAnimation(area->upperLineItem());
151 m_animator->addAnimation(area->upperLineItem());
152 if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem());
152 if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem());
@@ -160,7 +160,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
160
160
161 case QSeries::SeriesTypeBar: {
161 case QSeries::SeriesTypeBar: {
162 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
162 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
163 BarChartItem* bar = new BarChartItem(barSeries,m_chart);
163 BarChartItem* bar = new BarChartItem(barSeries,this);
164 if(m_options.testFlag(QChart::SeriesAnimations)) {
164 if(m_options.testFlag(QChart::SeriesAnimations)) {
165 m_animator->addAnimation(bar);
165 m_animator->addAnimation(bar);
166 }
166 }
@@ -173,7 +173,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
173
173
174 case QSeries::SeriesTypeStackedBar: {
174 case QSeries::SeriesTypeStackedBar: {
175 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
175 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
176 StackedBarChartItem* bar = new StackedBarChartItem(stackedBarSeries,m_chart);
176 StackedBarChartItem* bar = new StackedBarChartItem(stackedBarSeries,this);
177 if(m_options.testFlag(QChart::SeriesAnimations)) {
177 if(m_options.testFlag(QChart::SeriesAnimations)) {
178 m_animator->addAnimation(bar);
178 m_animator->addAnimation(bar);
179 }
179 }
@@ -186,7 +186,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
186
186
187 case QSeries::SeriesTypePercentBar: {
187 case QSeries::SeriesTypePercentBar: {
188 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
188 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
189 PercentBarChartItem* bar = new PercentBarChartItem(percentBarSeries,m_chart);
189 PercentBarChartItem* bar = new PercentBarChartItem(percentBarSeries,this);
190 if(m_options.testFlag(QChart::SeriesAnimations)) {
190 if(m_options.testFlag(QChart::SeriesAnimations)) {
191 m_animator->addAnimation(bar);
191 m_animator->addAnimation(bar);
192 }
192 }
@@ -199,7 +199,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
199
199
200 case QSeries::SeriesTypeScatter: {
200 case QSeries::SeriesTypeScatter: {
201 QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series);
201 QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series);
202 ScatterChartItem *scatter = new ScatterChartItem(scatterSeries, m_chart);
202 ScatterChartItem *scatter = new ScatterChartItem(scatterSeries,this);
203 if(m_options.testFlag(QChart::SeriesAnimations)) {
203 if(m_options.testFlag(QChart::SeriesAnimations)) {
204 m_animator->addAnimation(scatter);
204 m_animator->addAnimation(scatter);
205 }
205 }
@@ -212,7 +212,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
212
212
213 case QSeries::SeriesTypePie: {
213 case QSeries::SeriesTypePie: {
214 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
214 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
215 PieChartItem* pie = new PieChartItem(pieSeries, this, m_chart);
215 PieChartItem* pie = new PieChartItem(pieSeries, this);
216 if(m_options.testFlag(QChart::SeriesAnimations)) {
216 if(m_options.testFlag(QChart::SeriesAnimations)) {
217 m_animator->addAnimation(pie);
217 m_animator->addAnimation(pie);
218 }
218 }
@@ -231,7 +231,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
231
231
232 case QSeries::SeriesTypeSpline: {
232 case QSeries::SeriesTypeSpline: {
233 QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series);
233 QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series);
234 SplineChartItem* spline = new SplineChartItem(splineSeries, m_chart);
234 SplineChartItem* spline = new SplineChartItem(splineSeries, this);
235 if(m_options.testFlag(QChart::SeriesAnimations)) {
235 if(m_options.testFlag(QChart::SeriesAnimations)) {
236 m_animator->addAnimation(spline);
236 m_animator->addAnimation(spline);
237 }
237 }
@@ -256,7 +256,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
256
256
257 void ChartPresenter::handleSeriesRemoved(QSeries* series)
257 void ChartPresenter::handleSeriesRemoved(QSeries* series)
258 {
258 {
259 ChartItem* item = m_chartItems.take(series);
259 Chart* item = m_chartItems.take(series);
260 Q_ASSERT(item);
260 Q_ASSERT(item);
261 if(m_animator) {
261 if(m_animator) {
262 //small hack to handle area animations
262 //small hack to handle area animations
@@ -8,11 +8,11
8
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 class ChartItem;
11 class Chart;
12 class QSeries;
12 class QSeries;
13 class ChartDataSet;
13 class ChartDataSet;
14 class Domain;
14 class Domain;
15 class AxisItem;
15 class Axis;
16 class ChartTheme;
16 class ChartTheme;
17 class ChartAnimator;
17 class ChartAnimator;
18
18
@@ -50,6 +50,8 public:
50 void setAnimationOptions(QChart::AnimationOptions options);
50 void setAnimationOptions(QChart::AnimationOptions options);
51 QChart::AnimationOptions animationOptions() const;
51 QChart::AnimationOptions animationOptions() const;
52
52
53 QGraphicsItem* rootItem() const {return m_chart;};
54
53 void zoomIn();
55 void zoomIn();
54 void zoomIn(const QRectF& rect);
56 void zoomIn(const QRectF& rect);
55 void zoomOut();
57 void zoomOut();
@@ -76,8 +78,8 private:
76 ChartDataSet* m_dataset;
78 ChartDataSet* m_dataset;
77 ChartTheme *m_chartTheme;
79 ChartTheme *m_chartTheme;
78 int m_zoomIndex;
80 int m_zoomIndex;
79 QMap<QSeries*,ChartItem*> m_chartItems;
81 QMap<QSeries*,Chart*> m_chartItems;
80 QMap<QChartAxis*,AxisItem*> m_axisItems;
82 QMap<QChartAxis*,Axis*> m_axisItems;
81 QVector<QRectF> m_zoomStack;
83 QVector<QRectF> m_zoomStack;
82 QRectF m_rect;
84 QRectF m_rect;
83 QChart::AnimationOptions m_options;
85 QChart::AnimationOptions m_options;
@@ -8,7 +8,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 //TODO: optimize : remove points which are not visible
9 //TODO: optimize : remove points which are not visible
10
10
11 LineChartItem::LineChartItem(QLineSeries* series,QGraphicsItem *parent):XYChartItem(series,parent),
11 LineChartItem::LineChartItem(QLineSeries* series,ChartPresenter *presenter):XYChartItem(series,presenter),
12 m_series(series),
12 m_series(series),
13 m_pointsVisible(false)
13 m_pointsVisible(false)
14 {
14 {
@@ -8,12 +8,13
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class QLineSeries;
10 class QLineSeries;
11 class ChartPresenter;
11
12
12 class LineChartItem : public XYChartItem
13 class LineChartItem : public XYChartItem
13 {
14 {
14 Q_OBJECT
15 Q_OBJECT
15 public:
16 public:
16 explicit LineChartItem(QLineSeries* series,QGraphicsItem *parent = 0);
17 explicit LineChartItem(QLineSeries* series,ChartPresenter *presenter);
17 ~ LineChartItem(){};
18 ~ LineChartItem(){};
18
19
19 //from QGraphicsItem
20 //from QGraphicsItem
@@ -12,10 +12,9
12
12
13 QTCOMMERCIALCHART_BEGIN_NAMESPACE
13 QTCOMMERCIALCHART_BEGIN_NAMESPACE
14
14
15 PieChartItem::PieChartItem(QPieSeries *series, ChartPresenter *presenter, QGraphicsItem *parent)
15 PieChartItem::PieChartItem(QPieSeries *series, ChartPresenter* presenter)
16 :ChartItem(parent),
16 :ChartItem(presenter),
17 m_series(series),
17 m_series(series)
18 m_presenter(presenter)
19 {
18 {
20 Q_ASSERT(series);
19 Q_ASSERT(series);
21 connect(series, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleSlicesAdded(QList<QPieSlice*>)));
20 connect(series, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleSlicesAdded(QList<QPieSlice*>)));
@@ -52,7 +51,7 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices)
52 {
51 {
53 bool isEmpty = m_slices.isEmpty();
52 bool isEmpty = m_slices.isEmpty();
54
53
55 m_presenter->theme()->decorate(m_series, m_presenter->dataSet()->seriesIndex(m_series));
54 presenter()->theme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
56
55
57 foreach (QPieSlice *s, slices) {
56 foreach (QPieSlice *s, slices) {
58 PieSliceItem* item = new PieSliceItem(this);
57 PieSliceItem* item = new PieSliceItem(this);
@@ -73,11 +72,11 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices)
73
72
74 void PieChartItem::handleSlicesRemoved(QList<QPieSlice*> slices)
73 void PieChartItem::handleSlicesRemoved(QList<QPieSlice*> slices)
75 {
74 {
76 m_presenter->theme()->decorate(m_series, m_presenter->dataSet()->seriesIndex(m_series));
75 presenter()->theme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
77
76
78 foreach (QPieSlice *s, slices) {
77 foreach (QPieSlice *s, slices) {
79 if (m_animator)
78 if (animator())
80 m_animator->removeAnimation(this, s);
79 animator()->removeAnimation(this, s);
81 else
80 else
82 destroySlice(s);
81 destroySlice(s);
83 }
82 }
@@ -148,8 +147,8 PieLayout PieChartItem::calculateLayout()
148
147
149 void PieChartItem::applyLayout(const PieLayout &layout)
148 void PieChartItem::applyLayout(const PieLayout &layout)
150 {
149 {
151 if (m_animator)
150 if (animator())
152 m_animator->updateLayout(this, layout);
151 animator()->updateLayout(this, layout);
153 else
152 else
154 setLayout(layout);
153 setLayout(layout);
155 }
154 }
@@ -12,13 +12,13 class ChartPresenter;
12
12
13 typedef QHash<QPieSlice*, PieSliceData> PieLayout;
13 typedef QHash<QPieSlice*, PieSliceData> PieLayout;
14
14
15 class PieChartItem : public QObject, public ChartItem
15 class PieChartItem : public ChartItem
16 {
16 {
17 Q_OBJECT
17 Q_OBJECT
18
18
19 public:
19 public:
20 // TODO: use a generic data class instead of x and y
20 // TODO: use a generic data class instead of x and y
21 PieChartItem(QPieSeries *series, ChartPresenter *presenter, QGraphicsItem *parent);
21 PieChartItem(QPieSeries *series, ChartPresenter *presenter);
22 ~PieChartItem();
22 ~PieChartItem();
23
23
24 public: // from QGraphicsItem
24 public: // from QGraphicsItem
@@ -51,7 +51,6 private:
51 QRectF m_rect;
51 QRectF m_rect;
52 QPointF m_pieCenter;
52 QPointF m_pieCenter;
53 qreal m_pieRadius;
53 qreal m_pieRadius;
54 ChartPresenter *m_presenter;
55 };
54 };
56
55
57 QTCOMMERCIALCHART_END_NAMESPACE
56 QTCOMMERCIALCHART_END_NAMESPACE
@@ -11,7 +11,7 class QGraphicsSceneResizeEvent;
11
11
12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
13
13
14 class AxisItem;
14 class Axis;
15 class QSeries;
15 class QSeries;
16 class PlotDomain;
16 class PlotDomain;
17 class BarChartItem;
17 class BarChartItem;
@@ -6,17 +6,14
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 ScatterChartItem::ScatterChartItem(QScatterSeries *series, QGraphicsItem *parent) :
9 ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter) :
10 XYChartItem(series,parent),
10 XYChartItem(series,presenter),
11 m_series(series),
11 m_series(series),
12 m_items(this),
12 m_items(this),
13 m_shape(QScatterSeries::MarkerShapeRectangle),
13 m_shape(QScatterSeries::MarkerShapeRectangle),
14 m_size(15)
14 m_size(15)
15
15
16 {
16 {
17 Q_ASSERT(parent);
18 Q_ASSERT(series);
19
20 QObject::connect(m_series,SIGNAL(updated()), this, SLOT(handleUpdated()));
17 QObject::connect(m_series,SIGNAL(updated()), this, SLOT(handleUpdated()));
21
18
22 setZValue(ChartPresenter::ScatterSeriesZValue);
19 setZValue(ChartPresenter::ScatterSeriesZValue);
@@ -15,7 +15,7 class ScatterChartItem : public XYChartItem
15 {
15 {
16 Q_OBJECT
16 Q_OBJECT
17 public:
17 public:
18 explicit ScatterChartItem(QScatterSeries *series, QGraphicsItem *parent = 0);
18 explicit ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter);
19
19
20 public:
20 public:
21 //from QGraphicsItem
21 //from QGraphicsItem
@@ -5,8 +5,8
5
5
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
7
8 SplineChartItem::SplineChartItem(QSplineSeries* series, QGraphicsItem *parent) :
8 SplineChartItem::SplineChartItem(QSplineSeries* series, ChartPresenter *presenter) :
9 XYChartItem(series, parent),
9 XYChartItem(series, presenter),
10 m_series(series),
10 m_series(series),
11 m_pointsVisible(false)
11 m_pointsVisible(false)
12 {
12 {
@@ -42,8 +42,8 void SplineChartItem::updateLayout(QVector<QPointF>& oldPoints,QVector<QPointF>&
42 return;
42 return;
43 }
43 }
44
44
45 if(m_animator){
45 if(animator()){
46 m_animator->updateLayout(this,oldPoints,newPoints,m_controlPoints,controlPoints,index);
46 animator()->updateLayout(this,oldPoints,newPoints,m_controlPoints,controlPoints,index);
47 }else{
47 }else{
48 setLayout(newPoints,controlPoints);
48 setLayout(newPoints,controlPoints);
49 }
49 }
@@ -12,7 +12,7 class SplineChartItem : public XYChartItem
12 {
12 {
13 Q_OBJECT
13 Q_OBJECT
14 public:
14 public:
15 SplineChartItem(QSplineSeries* series, QGraphicsItem *parent = 0);
15 SplineChartItem(QSplineSeries* series, ChartPresenter *presenter);
16
16
17 //from QGraphicsItem
17 //from QGraphicsItem
18 QRectF boundingRect() const;
18 QRectF boundingRect() const;
@@ -17,7 +17,8 SOURCES += \
17 qseries.cpp \
17 qseries.cpp \
18 qlegend.cpp \
18 qlegend.cpp \
19 legendmarker.cpp \
19 legendmarker.cpp \
20 chartbackground.cpp
20 chartbackground.cpp \
21 chart.cpp
21 PRIVATE_HEADERS += \
22 PRIVATE_HEADERS += \
22 chartdataset_p.h \
23 chartdataset_p.h \
23 chartitem_p.h \
24 chartitem_p.h \
@@ -25,7 +26,8 PRIVATE_HEADERS += \
25 charttheme_p.h \
26 charttheme_p.h \
26 domain_p.h \
27 domain_p.h \
27 legendmarker_p.h \
28 legendmarker_p.h \
28 chartbackground_p.h
29 chartbackground_p.h \
30 chart_p.h
29 PUBLIC_HEADERS += \
31 PUBLIC_HEADERS += \
30 qchart.h \
32 qchart.h \
31 qchartglobal.h \
33 qchartglobal.h \
@@ -10,7 +10,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 //TODO: optimize : remove points which are not visible
11 //TODO: optimize : remove points which are not visible
12
12
13 XYChartItem::XYChartItem(QXYSeries* series, QGraphicsItem *parent):ChartItem(parent),
13 XYChartItem::XYChartItem(QXYSeries* series, ChartPresenter *presenter):ChartItem(presenter),
14 m_minX(0),
14 m_minX(0),
15 m_maxX(0),
15 m_maxX(0),
16 m_minY(0),
16 m_minY(0),
@@ -68,8 +68,8 QPointF XYChartItem::calculateDomainPoint(const QPointF& point) const
68
68
69 void XYChartItem::updateLayout(QVector<QPointF>& oldPoints,QVector<QPointF>& newPoints,int index)
69 void XYChartItem::updateLayout(QVector<QPointF>& oldPoints,QVector<QPointF>& newPoints,int index)
70 {
70 {
71 if(m_animator){
71 if(animator()){
72 m_animator->updateLayout(this,oldPoints,newPoints,index);
72 animator()->updateLayout(this,oldPoints,newPoints,index);
73 }else{
73 }else{
74 setLayout(newPoints);
74 setLayout(newPoints);
75 }
75 }
@@ -10,16 +10,17 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 class ChartPresenter;
10 class ChartPresenter;
11 class QXYSeries;
11 class QXYSeries;
12
12
13 class XYChartItem : public QObject , public ChartItem
13 class XYChartItem : public ChartItem
14 {
14 {
15 Q_OBJECT
15 Q_OBJECT
16 public:
16 public:
17 explicit XYChartItem(QXYSeries* series, QGraphicsItem *parent = 0);
17 explicit XYChartItem(QXYSeries* series, ChartPresenter *presenter);
18 ~ XYChartItem(){};
18 ~ XYChartItem(){};
19
19
20 QVector<QPointF> points() const {return m_points;}
20 QVector<QPointF> points() const {return m_points;}
21 QRectF clipRect() const { return m_clipRect;}
21 QRectF clipRect() const { return m_clipRect;}
22
22
23
23 public slots:
24 public slots:
24 void handlePointAdded(int index);
25 void handlePointAdded(int index);
25 void handlePointRemoved(int index);
26 void handlePointRemoved(int index);
@@ -31,8 +32,10 signals:
31 void clicked(const QPointF& point);
32 void clicked(const QPointF& point);
32
33
33 protected:
34 protected:
35
34 virtual void setLayout(QVector<QPointF>& points);
36 virtual void setLayout(QVector<QPointF>& points);
35 virtual void updateLayout(QVector<QPointF>& oldPoints,QVector<QPointF>& newPoints,int index = 0);
37 virtual void updateLayout(QVector<QPointF>& oldPoints,QVector<QPointF>& newPoints,int index = 0);
38
36 QPointF calculateGeometryPoint(const QPointF& point) const;
39 QPointF calculateGeometryPoint(const QPointF& point) const;
37 QPointF calculateGeometryPoint(int index) const;
40 QPointF calculateGeometryPoint(int index) const;
38 QPointF calculateDomainPoint(const QPointF& point) const;
41 QPointF calculateDomainPoint(const QPointF& point) const;
General Comments 0
You need to be logged in to leave comments. Login now