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