@@ -380,16 +380,14 QList<LegendMarker*> QAreaSeriesPrivate::createLegendMarker(QLegend* legend) | |||||
380 | } |
|
380 | } | |
381 |
|
381 | |||
382 |
|
382 | |||
383 | QAbstractAxis* QAreaSeriesPrivate::createAxisX() |
|
383 | QAbstractAxis* QAreaSeriesPrivate::createAxisX(QObject* parent) | |
384 | { |
|
384 | { | |
385 | // TODO: parent? |
|
385 | return new QValuesAxis(parent); | |
386 | return new QValuesAxis(this); |
|
|||
387 | } |
|
386 | } | |
388 |
|
387 | |||
389 | QAbstractAxis* QAreaSeriesPrivate::createAxisY() |
|
388 | QAbstractAxis* QAreaSeriesPrivate::createAxisY(QObject* parent) | |
390 | { |
|
389 | { | |
391 | // TODO: parent? |
|
390 | return new QValuesAxis(parent); | |
392 | return new QValuesAxis(this); |
|
|||
393 | } |
|
391 | } | |
394 |
|
392 | |||
395 | #include "moc_qareaseries.cpp" |
|
393 | #include "moc_qareaseries.cpp" |
@@ -46,8 +46,8 public: | |||||
46 | void scaleDomain(Domain& domain); |
|
46 | void scaleDomain(Domain& domain); | |
47 | Chart* createGraphics(ChartPresenter* presenter); |
|
47 | Chart* createGraphics(ChartPresenter* presenter); | |
48 | QList<LegendMarker*> createLegendMarker(QLegend* legend); |
|
48 | QList<LegendMarker*> createLegendMarker(QLegend* legend); | |
49 | QAbstractAxis* createAxisX(); |
|
49 | QAbstractAxis* createAxisX(QObject* parent = 0); | |
50 | QAbstractAxis* createAxisY(); |
|
50 | QAbstractAxis* createAxisY(QObject* parent = 0); | |
51 |
|
51 | |||
52 | Q_SIGNALS: |
|
52 | Q_SIGNALS: | |
53 | void updated(); |
|
53 | void updated(); |
@@ -123,6 +123,7 protected: | |||||
123 | Q_DISABLE_COPY(QAbstractAxis); |
|
123 | Q_DISABLE_COPY(QAbstractAxis); | |
124 | friend class ChartDataSet; |
|
124 | friend class ChartDataSet; | |
125 | friend class ChartAxis; |
|
125 | friend class ChartAxis; | |
|
126 | friend class ChartPresenter; | |||
126 | }; |
|
127 | }; | |
127 |
|
128 | |||
128 | QTCOMMERCIALCHART_END_NAMESPACE |
|
129 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -34,6 +34,9 | |||||
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
|
37 | class ChartPresenter; | |||
|
38 | class ChartAxis; | |||
|
39 | ||||
37 | class QAbstractAxisPrivate : public QObject |
|
40 | class QAbstractAxisPrivate : public QObject | |
38 | { |
|
41 | { | |
39 | Q_OBJECT |
|
42 | Q_OBJECT | |
@@ -44,13 +47,16 public: | |||||
44 | Q_SIGNALS: |
|
47 | Q_SIGNALS: | |
45 | void updated(); |
|
48 | void updated(); | |
46 |
|
49 | |||
|
50 | public: | |||
|
51 | virtual ChartAxis* createGraphics(ChartPresenter* presenter) = 0; | |||
|
52 | ||||
47 | protected: |
|
53 | protected: | |
48 | virtual void setMin(const QVariant& min) = 0; |
|
54 | virtual void setMin(const QVariant& min) = 0; | |
49 | virtual void setMax(const QVariant& max) = 0; |
|
55 | virtual void setMax(const QVariant& max) = 0; | |
50 | virtual void setRange(const QVariant& min, const QVariant& max) = 0; |
|
56 | virtual void setRange(const QVariant& min, const QVariant& max) = 0; | |
51 | virtual int ticksCount() const = 0; |
|
57 | virtual int ticksCount() const = 0; | |
52 |
|
58 | |||
53 | protected: |
|
59 | public: | |
54 | QAbstractAxis *q_ptr; |
|
60 | QAbstractAxis *q_ptr; | |
55 |
|
61 | |||
56 | bool m_axisVisible; |
|
62 | bool m_axisVisible; |
@@ -20,6 +20,8 | |||||
20 |
|
20 | |||
21 | #include "qcategoriesaxis.h" |
|
21 | #include "qcategoriesaxis.h" | |
22 | #include "qcategoriesaxis_p.h" |
|
22 | #include "qcategoriesaxis_p.h" | |
|
23 | #include "chartaxisx_p.h" | |||
|
24 | #include "chartaxisy_p.h" | |||
23 |
|
25 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
27 | |||
@@ -203,6 +205,17 int QCategoriesAxisPrivate::ticksCount() const | |||||
203 | return m_categories.count()+1; |
|
205 | return m_categories.count()+1; | |
204 | } |
|
206 | } | |
205 |
|
207 | |||
|
208 | ChartAxis* QCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter) | |||
|
209 | { | |||
|
210 | Q_Q( QCategoriesAxis); | |||
|
211 | if(m_orientation == Qt::Vertical){ | |||
|
212 | return new ChartAxisY(q,presenter); | |||
|
213 | }else{ | |||
|
214 | return new ChartAxisX(q,presenter); | |||
|
215 | } | |||
|
216 | ||||
|
217 | } | |||
|
218 | ||||
206 | #include "moc_qcategoriesaxis.cpp" |
|
219 | #include "moc_qcategoriesaxis.cpp" | |
207 | #include "moc_qcategoriesaxis_p.cpp" |
|
220 | #include "moc_qcategoriesaxis_p.cpp" | |
208 |
|
221 |
@@ -43,6 +43,9 public: | |||||
43 | QCategoriesAxisPrivate(QCategoriesAxis *q); |
|
43 | QCategoriesAxisPrivate(QCategoriesAxis *q); | |
44 | ~QCategoriesAxisPrivate(); |
|
44 | ~QCategoriesAxisPrivate(); | |
45 |
|
45 | |||
|
46 | public: | |||
|
47 | ChartAxis* createGraphics(ChartPresenter* presenter); | |||
|
48 | ||||
46 | private: |
|
49 | private: | |
47 | //range handling |
|
50 | //range handling | |
48 | void setMin(const QVariant& min); |
|
51 | void setMin(const QVariant& min); |
@@ -20,6 +20,9 | |||||
20 |
|
20 | |||
21 | #include "qvaluesaxis.h" |
|
21 | #include "qvaluesaxis.h" | |
22 | #include "qvaluesaxis_p.h" |
|
22 | #include "qvaluesaxis_p.h" | |
|
23 | #include "chartaxisx_p.h" | |||
|
24 | #include "chartaxisy_p.h" | |||
|
25 | #include <QDebug> | |||
23 |
|
26 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 | /*! |
|
28 | /*! | |
@@ -245,6 +248,17 int QValuesAxisPrivate::ticksCount() const | |||||
245 | return m_ticksCount; |
|
248 | return m_ticksCount; | |
246 | } |
|
249 | } | |
247 |
|
250 | |||
|
251 | ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter) | |||
|
252 | { | |||
|
253 | Q_Q(QValuesAxis); | |||
|
254 | if(m_orientation == Qt::Vertical){ | |||
|
255 | return new ChartAxisY(q,presenter); | |||
|
256 | }else{ | |||
|
257 | return new ChartAxisX(q,presenter); | |||
|
258 | } | |||
|
259 | ||||
|
260 | } | |||
|
261 | ||||
248 | #include "moc_qvaluesaxis.cpp" |
|
262 | #include "moc_qvaluesaxis.cpp" | |
249 | #include "moc_qvaluesaxis_p.cpp" |
|
263 | #include "moc_qvaluesaxis_p.cpp" | |
250 |
|
264 |
@@ -48,6 +48,9 Q_SIGNALS: | |||||
48 | public Q_SLOTS: |
|
48 | public Q_SLOTS: | |
49 | void handleAxisRangeChanged(qreal min, qreal max,int count); |
|
49 | void handleAxisRangeChanged(qreal min, qreal max,int count); | |
50 |
|
50 | |||
|
51 | public: | |||
|
52 | ChartAxis* createGraphics(ChartPresenter* presenter); | |||
|
53 | ||||
51 | protected: |
|
54 | protected: | |
52 | void setMin(const QVariant& min); |
|
55 | void setMin(const QVariant& min); | |
53 | void setMax(const QVariant& max); |
|
56 | void setMax(const QVariant& max); |
@@ -608,16 +608,14 QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) | |||||
608 | return markers; |
|
608 | return markers; | |
609 | } |
|
609 | } | |
610 |
|
610 | |||
611 | QAbstractAxis* QBarSeriesPrivate::createAxisX() |
|
611 | QAbstractAxis* QBarSeriesPrivate::createAxisX(QObject* parent) | |
612 | { |
|
612 | { | |
613 | // TODO: parent? |
|
613 | return new QValuesAxis(parent); | |
614 | return new QValuesAxis(this); |
|
|||
615 | } |
|
614 | } | |
616 |
|
615 | |||
617 | QAbstractAxis* QBarSeriesPrivate::createAxisY() |
|
616 | QAbstractAxis* QBarSeriesPrivate::createAxisY(QObject* parent) | |
618 | { |
|
617 | { | |
619 | // TODO: parent? |
|
618 | return new QValuesAxis(parent); | |
620 | return new QValuesAxis(this); |
|
|||
621 | } |
|
619 | } | |
622 |
|
620 | |||
623 | bool QBarSeriesPrivate::append(QBarSet *set) |
|
621 | bool QBarSeriesPrivate::append(QBarSet *set) |
@@ -56,8 +56,8 public: | |||||
56 | Chart* createGraphics(ChartPresenter* presenter); |
|
56 | Chart* createGraphics(ChartPresenter* presenter); | |
57 | QList<LegendMarker*> createLegendMarker(QLegend* legend); |
|
57 | QList<LegendMarker*> createLegendMarker(QLegend* legend); | |
58 |
|
58 | |||
59 | QAbstractAxis* createAxisX(); |
|
59 | QAbstractAxis* createAxisX(QObject* parent = 0); | |
60 | QAbstractAxis* createAxisY(); |
|
60 | QAbstractAxis* createAxisY(QObject* parent = 0); | |
61 |
|
61 | |||
62 | bool append(QBarSet *set); |
|
62 | bool append(QBarSet *set); | |
63 | bool remove(QBarSet *set); |
|
63 | bool remove(QBarSet *set); |
@@ -31,19 +31,9 | |||||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | ChartDataSet::ChartDataSet(QChart *parent):QObject(parent), |
|
33 | ChartDataSet::ChartDataSet(QChart *parent):QObject(parent), | |
34 | m_axisX(new QValuesAxis(this)), |
|
34 | m_domainIndex(0) | |
35 | m_axisY(new QValuesAxis(this)), |
|
|||
36 | m_domainIndex(0), |
|
|||
37 | m_axisXInitialized(false), |
|
|||
38 | m_axisYInitialized(false) |
|
|||
39 | { |
|
35 | { | |
40 | //create main domain |
|
36 | ||
41 | Domain* domain = new Domain(m_axisY); |
|
|||
42 | m_axisDomainMap.insert(m_axisY,domain); |
|
|||
43 | QObject::connect(m_axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); |
|
|||
44 | QObject::connect(m_axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); |
|
|||
45 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),m_axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
|||
46 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),m_axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
|||
47 | } |
|
37 | } | |
48 |
|
38 | |||
49 | ChartDataSet::~ChartDataSet() |
|
39 | ChartDataSet::~ChartDataSet() | |
@@ -60,44 +50,33 void ChartDataSet::addSeries(QAbstractSeries* series) | |||||
60 | return; |
|
50 | return; | |
61 | } |
|
51 | } | |
62 |
|
52 | |||
63 | QAbstractAxis* axisX = series->d_ptr->createAxisX(); |
|
53 | QAbstractAxis* axisX = series->d_ptr->createAxisX(this); | |
64 |
QAbstractAxis* axisY = |
|
54 | QAbstractAxis* axisY = series->d_ptr->createAxisY(this); | |
65 |
|
55 | |||
66 | series->setParent(this); // take ownership |
|
56 | series->setParent(this); // take ownership | |
67 | //axisY->setParent(this); // take ownership |
|
|||
68 |
|
57 | |||
69 |
Domain* domain = |
|
58 | Domain* domain = new Domain(series); | |
70 |
|
59 | |||
71 |
if( |
|
60 | if(axisX){ | |
72 | domain = new Domain(axisY); |
|
61 | QObject::connect(axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); | |
|
62 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |||
|
63 | axisX->d_ptr->m_orientation=Qt::Horizontal; | |||
|
64 | emit axisAdded(axisX,domain); | |||
|
65 | m_seriesAxisYMap.insert(series,axisX); | |||
|
66 | } | |||
|
67 | ||||
|
68 | if(axisY){ | |||
73 | QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); |
|
69 | QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); | |
74 | QObject::connect(axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int))); |
|
|||
75 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
70 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
76 | //initialize |
|
71 | axisY->d_ptr->m_orientation=Qt::Vertical; | |
77 | m_axisDomainMap.insert(axisY,domain); |
|
|||
78 | emit axisAdded(axisY,domain); |
|
72 | emit axisAdded(axisY,domain); | |
|
73 | m_seriesAxisYMap.insert(series,axisY); | |||
79 | } |
|
74 | } | |
80 |
|
75 | |||
81 | if(!m_axisXInitialized){ |
|
76 | m_seriesDomainMap.insert(series,domain); | |
82 | m_axisXInitialized=true; |
|
|||
83 | // emit axisAdded(m_axisX,domain); |
|
|||
84 | emit axisAdded(axisX,domain); |
|
|||
85 | } |
|
|||
86 |
|
||||
87 | if(!m_axisYInitialized && axisY==m_axisY){ |
|
|||
88 | m_axisYInitialized=true; |
|
|||
89 | emit axisAdded(m_axisY,domain); |
|
|||
90 | } |
|
|||
91 |
|
77 | |||
92 | series->d_ptr->scaleDomain(*domain); |
|
78 | series->d_ptr->scaleDomain(*domain); | |
93 |
|
79 | |||
94 | if (series->type()== QAbstractSeries::SeriesTypePie && m_seriesAxisXMap.count() == 0) { |
|
|||
95 | axisX->hide(); |
|
|||
96 | axisY->hide(); |
|
|||
97 | } |
|
|||
98 |
|
||||
99 | m_seriesAxisXMap.insert(series,axisY); |
|
|||
100 |
|
||||
101 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
80 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
102 |
|
81 | |||
103 | int key=0; |
|
82 | int key=0; | |
@@ -118,18 +97,23 void ChartDataSet::addSeries(QAbstractSeries* series) | |||||
118 |
|
97 | |||
119 | } |
|
98 | } | |
120 |
|
99 | |||
121 |
|
|
100 | void ChartDataSet::removeSeries(QAbstractSeries* series) | |
122 | { |
|
101 | { | |
123 |
|
|
102 | Domain* domain = m_seriesDomainMap.take(series); | |
124 |
|
103 | |||
125 |
if(! |
|
104 | if(!domain) { | |
126 | qWarning()<<"Can not remove series. Series not found on the chart."; |
|
105 | qWarning()<<"Can not remove series. Series not found on the chart."; | |
127 | return 0; |
|
106 | } | |
|
107 | else { | |||
|
108 | delete domain; | |||
|
109 | domain =0; | |||
128 | } |
|
110 | } | |
129 |
|
111 | |||
130 | emit seriesRemoved(series); |
|
112 | emit seriesRemoved(series); | |
131 |
|
113 | |||
132 |
m_seriesAxisXMap. |
|
114 | QAbstractAxis* axisX = m_seriesAxisXMap.take(series); | |
|
115 | QAbstractAxis* axisY = m_seriesAxisYMap.take(series); | |||
|
116 | ||||
133 | int key = seriesIndex(series); |
|
117 | int key = seriesIndex(series); | |
134 | Q_ASSERT(key!=-1); |
|
118 | Q_ASSERT(key!=-1); | |
135 |
|
119 | |||
@@ -139,77 +123,53 QAbstractAxis* ChartDataSet::removeSeries(QAbstractSeries* series) | |||||
139 | series->d_ptr->m_chart = 0; |
|
123 | series->d_ptr->m_chart = 0; | |
140 | series->d_ptr->m_dataset = 0; |
|
124 | series->d_ptr->m_dataset = 0; | |
141 |
|
125 | |||
142 |
QList<QAbstractAxis*> axes = |
|
126 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); | |
|
127 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); | |||
143 |
|
128 | |||
144 |
int |
|
129 | int x = axesX.indexOf(axisX); | |
|
130 | int y = axesY.indexOf(axisY); | |||
145 |
|
131 | |||
146 |
if( |
|
132 | if(x==-1) { | |
147 | Domain* domain = m_axisDomainMap.take(axis); |
|
133 | emit axisRemoved(axisX); | |
148 |
|
|
134 | delete axisX; | |
149 | if(axis!=m_axisY){ |
|
|||
150 | axis->setParent(0); |
|
|||
151 | delete domain; |
|
|||
152 | }else{ |
|
|||
153 | m_axisYInitialized=false; |
|
|||
154 | m_axisDomainMap.insert(m_axisY,domain); |
|
|||
155 | } |
|
|||
156 | } |
|
135 | } | |
157 |
|
136 | |||
158 | if(m_seriesAxisXMap.values().size()==0) |
|
137 | if(y==-1) { | |
159 | { |
|
138 | emit axisRemoved(axisY); | |
160 | m_axisXInitialized=false; |
|
139 | delete axisY; | |
161 | emit axisRemoved(m_axisX); |
|
|||
162 | } |
|
140 | } | |
163 |
|
||||
164 | return axis; |
|
|||
165 | } |
|
141 | } | |
166 |
|
142 | |||
167 | void ChartDataSet::removeAllSeries() |
|
143 | void ChartDataSet::removeAllSeries() | |
168 | { |
|
144 | { | |
169 |
QList<QAbstractSeries*> series = m_series |
|
145 | QList<QAbstractSeries*> series = m_seriesDomainMap.keys(); | |
170 | QList<QAbstractAxis*> axes; |
|
|||
171 | foreach(QAbstractSeries *s , series) { |
|
146 | foreach(QAbstractSeries *s , series) { | |
172 |
|
|
147 | removeSeries(s); | |
173 | if(axis==m_axisY) continue; |
|
|||
174 | int i = axes.indexOf(axis); |
|
|||
175 | if(i==-1){ |
|
|||
176 | axes<<axis; |
|
|||
177 | } |
|
|||
178 | } |
|
148 | } | |
179 |
|
149 | |||
180 | Q_ASSERT(m_seriesAxisXMap.count()==0); |
|
150 | Q_ASSERT(m_seriesAxisXMap.count()==0); | |
181 |
Q_ASSERT(m_ |
|
151 | Q_ASSERT(m_seriesAxisXMap.count()==0); | |
|
152 | Q_ASSERT(m_seriesDomainMap.count()==0); | |||
182 |
|
153 | |||
183 | qDeleteAll(series); |
|
154 | qDeleteAll(series); | |
184 | qDeleteAll(axes); |
|
|||
185 | } |
|
155 | } | |
186 |
|
156 | |||
187 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) |
|
157 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) | |
188 | { |
|
158 | { | |
189 |
QMapIterator<QAbstract |
|
159 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
190 | //main domain has to be the last one; |
|
|||
191 | Domain *domain = m_axisDomainMap.value(m_axisY); |
|
|||
192 | Q_ASSERT(domain); |
|
|||
193 | while (i.hasNext()) { |
|
160 | while (i.hasNext()) { | |
194 | i.next(); |
|
161 | i.next(); | |
195 | if(i.value()==domain) continue; |
|
|||
196 | i.value()->zoomIn(rect,size); |
|
162 | i.value()->zoomIn(rect,size); | |
197 | } |
|
163 | } | |
198 | domain->zoomIn(rect,size); |
|
|||
199 | } |
|
164 | } | |
200 |
|
165 | |||
201 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) |
|
166 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) | |
202 | { |
|
167 | { | |
203 |
QMapIterator<QAbstract |
|
168 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
204 | //main domain has to be the last one; |
|
|||
205 | Domain *domain = m_axisDomainMap.value(m_axisY); |
|
|||
206 | Q_ASSERT(domain); |
|
|||
207 | while (i.hasNext()) { |
|
169 | while (i.hasNext()) { | |
208 | i.next(); |
|
170 | i.next(); | |
209 | if(i.value()==domain) continue; |
|
|||
210 | i.value()->zoomOut(rect,size); |
|
171 | i.value()->zoomOut(rect,size); | |
211 | } |
|
172 | } | |
212 | domain->zoomOut(rect,size); |
|
|||
213 | } |
|
173 | } | |
214 |
|
174 | |||
215 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) |
|
175 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) | |
@@ -236,14 +196,11 int ChartDataSet::seriesIndex(QAbstractSeries *series) | |||||
236 |
|
196 | |||
237 | QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const |
|
197 | QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const | |
238 | { |
|
198 | { | |
239 | qDebug() << "axisX"; |
|
|||
240 | if (series == 0) return m_axisX; |
|
|||
241 | return m_seriesAxisXMap.value(series); |
|
199 | return m_seriesAxisXMap.value(series); | |
242 | } |
|
200 | } | |
243 |
|
201 | |||
244 | QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const |
|
202 | QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const | |
245 | { |
|
203 | { | |
246 | if(series == 0) return m_axisY; |
|
|||
247 | return m_seriesAxisYMap.value(series); |
|
204 | return m_seriesAxisYMap.value(series); | |
248 | } |
|
205 | } | |
249 |
|
206 | |||
@@ -257,36 +214,13 void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis) | |||||
257 | m_seriesAxisYMap.insert(series,axis); |
|
214 | m_seriesAxisYMap.insert(series,axis); | |
258 | } |
|
215 | } | |
259 |
|
216 | |||
260 | Domain* ChartDataSet::domain(QAbstractSeries *series) const |
|
|||
261 | { |
|
|||
262 | QAbstractAxis* axis = m_seriesAxisXMap.value(series); |
|
|||
263 | if(axis){ |
|
|||
264 | return m_axisDomainMap.value(axis); |
|
|||
265 | }else |
|
|||
266 | return 0; |
|
|||
267 | } |
|
|||
268 |
|
||||
269 | Domain* ChartDataSet::domain(QAbstractAxis* axis) const |
|
|||
270 | { |
|
|||
271 | if(!axis || axis==m_axisX) { |
|
|||
272 | return m_axisDomainMap.value(m_axisY); |
|
|||
273 | } |
|
|||
274 | else { |
|
|||
275 | return m_axisDomainMap.value(axis); |
|
|||
276 | } |
|
|||
277 | } |
|
|||
278 |
|
||||
279 | void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) |
|
217 | void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) | |
280 | { |
|
218 | { | |
281 |
QMapIterator<QAbstract |
|
219 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
282 | //main domain has to be the last one; |
|
|||
283 | Domain *domain = m_axisDomainMap.value(m_axisY); |
|
|||
284 | while (i.hasNext()) { |
|
220 | while (i.hasNext()) { | |
285 | i.next(); |
|
221 | i.next(); | |
286 | if(i.value()==domain) continue; |
|
|||
287 | i.value()->move(dx,dy,size); |
|
222 | i.value()->move(dx,dy,size); | |
288 | } |
|
223 | } | |
289 | domain->move(dx,dy,size); |
|
|||
290 | } |
|
224 | } | |
291 |
|
225 | |||
292 | QList<QAbstractSeries*> ChartDataSet::series() const |
|
226 | QList<QAbstractSeries*> ChartDataSet::series() const |
@@ -46,7 +46,7 public: | |||||
46 | virtual ~ChartDataSet(); |
|
46 | virtual ~ChartDataSet(); | |
47 |
|
47 | |||
48 | void addSeries(QAbstractSeries* series); |
|
48 | void addSeries(QAbstractSeries* series); | |
49 |
|
|
49 | void removeSeries(QAbstractSeries* series); | |
50 | void removeAllSeries(); |
|
50 | void removeAllSeries(); | |
51 | void updateSeries(QAbstractSeries* series); |
|
51 | void updateSeries(QAbstractSeries* series); | |
52 |
|
52 | |||
@@ -57,9 +57,6 public: | |||||
57 | int seriesCount(QAbstractSeries::SeriesType type); |
|
57 | int seriesCount(QAbstractSeries::SeriesType type); | |
58 | int seriesIndex(QAbstractSeries *series); |
|
58 | int seriesIndex(QAbstractSeries *series); | |
59 |
|
59 | |||
60 | Domain* domain(QAbstractSeries* series) const; |
|
|||
61 | Domain* domain(QAbstractAxis* axis) const; |
|
|||
62 |
|
||||
63 | QAbstractAxis* axisX(QAbstractSeries *series) const; |
|
60 | QAbstractAxis* axisX(QAbstractSeries *series) const; | |
64 | QAbstractAxis* axisY(QAbstractSeries *series) const; |
|
61 | QAbstractAxis* axisY(QAbstractSeries *series) const; | |
65 |
|
62 | |||
@@ -82,14 +79,10 private: | |||||
82 | private: |
|
79 | private: | |
83 | QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisXMap; |
|
80 | QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisXMap; | |
84 | QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisYMap; |
|
81 | QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisYMap; | |
85 |
QMap<QAbstract |
|
82 | QMap<QAbstractSeries*, Domain*> m_seriesDomainMap; | |
86 | QMap<int, QAbstractSeries*> m_indexSeriesMap; |
|
83 | QMap<int, QAbstractSeries*> m_indexSeriesMap; | |
87 | QAbstractAxis* m_axisX; |
|
|||
88 | QAbstractAxis* m_axisY; |
|
|||
89 |
|
||||
90 | int m_domainIndex; |
|
84 | int m_domainIndex; | |
91 | bool m_axisXInitialized; |
|
85 | ||
92 | bool m_axisYInitialized; |
|
|||
93 | }; |
|
86 | }; | |
94 |
|
87 | |||
95 | QTCOMMERCIALCHART_END_NAMESPACE |
|
88 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -21,6 +21,7 | |||||
21 | #include "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 | #include "qabstractaxis.h" |
|
23 | #include "qabstractaxis.h" | |
|
24 | #include "qabstractaxis_p.h" | |||
24 | #include "chartdataset_p.h" |
|
25 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
26 | #include "charttheme_p.h" | |
26 | #include "chartanimator_p.h" |
|
27 | #include "chartanimator_p.h" | |
@@ -69,20 +70,15 void ChartPresenter::setGeometry(const QRectF& rect) | |||||
69 |
|
70 | |||
70 | void ChartPresenter::handleAxisAdded(QAbstractAxis* axis,Domain* domain) |
|
71 | void ChartPresenter::handleAxisAdded(QAbstractAxis* axis,Domain* domain) | |
71 | { |
|
72 | { | |
72 | ChartAxis* item; |
|
73 | ChartAxis* item = axis->d_ptr->createGraphics(this); | |
73 |
|
74 | item->setDomain(domain); | ||
74 | if(axis == m_dataset->axisX(0)){ |
|
|||
75 | item = new ChartAxisX(axis,this); |
|
|||
76 | }else{ |
|
|||
77 | item = new ChartAxisY(axis,this); |
|
|||
78 | } |
|
|||
79 |
|
75 | |||
80 | if(m_options.testFlag(QChart::GridAxisAnimations)){ |
|
76 | if(m_options.testFlag(QChart::GridAxisAnimations)){ | |
81 | item->setAnimator(m_animator); |
|
77 | item->setAnimator(m_animator); | |
82 | item->setAnimation(new AxisAnimation(item)); |
|
78 | item->setAnimation(new AxisAnimation(item)); | |
83 | } |
|
79 | } | |
84 |
|
80 | |||
85 | if(axis==m_dataset->axisX(0)){ |
|
81 | if(item->axisType()==ChartAxis::X_AXIS){ | |
86 | m_chartTheme->decorate(axis,true); |
|
82 | m_chartTheme->decorate(axis,true); | |
87 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); |
|
83 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); | |
88 | //initialize |
|
84 | //initialize | |
@@ -115,6 +111,8 void ChartPresenter::handleSeriesAdded(QAbstractSeries* series,Domain* domain) | |||||
115 | { |
|
111 | { | |
116 | Chart *item = series->d_ptr->createGraphics(this); |
|
112 | Chart *item = series->d_ptr->createGraphics(this); | |
117 | Q_ASSERT(item); |
|
113 | Q_ASSERT(item); | |
|
114 | item->setDomain(domain); | |||
|
115 | ||||
118 | QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF))); |
|
116 | QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF))); | |
119 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
117 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
120 | //initialize |
|
118 | //initialize | |
@@ -177,19 +175,23 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |||||
177 |
|
175 | |||
178 | void ChartPresenter::resetAllElements() |
|
176 | void ChartPresenter::resetAllElements() | |
179 | { |
|
177 | { | |
180 |
Q |
|
178 | QMapIterator<QAbstractAxis*, ChartAxis*> i(m_axisItems); | |
181 | QList<QAbstractSeries *> seriesList = m_chartItems.uniqueKeys(); |
|
179 | while (i.hasNext()) { | |
182 |
|
180 | i.next(); | ||
183 | foreach(QAbstractAxis *axis, axisList) { |
|
181 | Domain* domain = i.value()->domain(); | |
184 | handleAxisRemoved(axis); |
|
182 | QAbstractAxis* axis = i.key(); | |
185 |
handleAxis |
|
183 | handleAxisRemoved(axis); | |
186 | } |
|
184 | handleAxisAdded(axis,domain); | |
187 | foreach(QAbstractSeries *series, seriesList) { |
|
|||
188 | handleSeriesRemoved(series); |
|
|||
189 | handleSeriesAdded(series,m_dataset->domain(series)); |
|
|||
190 | // m_dataset->removeSeries(series); |
|
|||
191 | // m_dataset->addSeries(series); |
|
|||
192 | } |
|
185 | } | |
|
186 | ||||
|
187 | QMapIterator<QAbstractSeries*, Chart*> j(m_chartItems); | |||
|
188 | while (j.hasNext()) { | |||
|
189 | j.next(); | |||
|
190 | Domain* domain = j.value()->domain(); | |||
|
191 | QAbstractSeries* series = j.key(); | |||
|
192 | handleSeriesRemoved(series); | |||
|
193 | handleSeriesAdded(series,domain); | |||
|
194 | } | |||
193 | } |
|
195 | } | |
194 |
|
196 | |||
195 | void ChartPresenter::zoomIn(qreal factor) |
|
197 | void ChartPresenter::zoomIn(qreal factor) |
@@ -24,7 +24,6 | |||||
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
27 | #include "qvaluesaxis.h" |
|
|||
28 |
|
27 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
29 | |||
@@ -130,18 +129,6 Chart* QLineSeriesPrivate::createGraphics(ChartPresenter* presenter) | |||||
130 | return line; |
|
129 | return line; | |
131 | } |
|
130 | } | |
132 |
|
131 | |||
133 | QAbstractAxis* QLineSeriesPrivate::createAxisX() |
|
|||
134 | { |
|
|||
135 | // TODO: parent? |
|
|||
136 | return new QValuesAxis(this); |
|
|||
137 | } |
|
|||
138 |
|
||||
139 | QAbstractAxis* QLineSeriesPrivate::createAxisY() |
|
|||
140 | { |
|
|||
141 | // TODO: parent? |
|
|||
142 | return new QValuesAxis(this); |
|
|||
143 | } |
|
|||
144 |
|
||||
145 | #include "moc_qlineseries.cpp" |
|
132 | #include "moc_qlineseries.cpp" | |
146 |
|
133 | |||
147 | QTCOMMERCIALCHART_END_NAMESPACE |
|
134 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -40,8 +40,6 class QLineSeriesPrivate: public QXYSeriesPrivate | |||||
40 | public: |
|
40 | public: | |
41 | QLineSeriesPrivate(QLineSeries* q); |
|
41 | QLineSeriesPrivate(QLineSeries* q); | |
42 | Chart* createGraphics(ChartPresenter* presenter); |
|
42 | Chart* createGraphics(ChartPresenter* presenter); | |
43 | QAbstractAxis* createAxisX(); |
|
|||
44 | QAbstractAxis* createAxisY(); |
|
|||
45 |
|
43 | |||
46 | private: |
|
44 | private: | |
47 | Q_DECLARE_PUBLIC(QLineSeries); |
|
45 | Q_DECLARE_PUBLIC(QLineSeries); |
@@ -755,13 +755,15 QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend) | |||||
755 | return markers; |
|
755 | return markers; | |
756 | } |
|
756 | } | |
757 |
|
757 | |||
758 | QAbstractAxis* QPieSeriesPrivate::createAxisX() |
|
758 | QAbstractAxis* QPieSeriesPrivate::createAxisX(QObject* parent) | |
759 | { |
|
759 | { | |
|
760 | Q_UNUSED(parent); | |||
760 | return 0; |
|
761 | return 0; | |
761 | } |
|
762 | } | |
762 |
|
763 | |||
763 | QAbstractAxis* QPieSeriesPrivate::createAxisY() |
|
764 | QAbstractAxis* QPieSeriesPrivate::createAxisY(QObject* parent) | |
764 | { |
|
765 | { | |
|
766 | Q_UNUSED(parent); | |||
765 | return 0; |
|
767 | return 0; | |
766 | } |
|
768 | } | |
767 |
|
769 |
@@ -47,8 +47,8 public: | |||||
47 | void scaleDomain(Domain& domain); |
|
47 | void scaleDomain(Domain& domain); | |
48 | Chart* createGraphics(ChartPresenter *presenter); |
|
48 | Chart* createGraphics(ChartPresenter *presenter); | |
49 | QList<LegendMarker*> createLegendMarker(QLegend *legend); |
|
49 | QList<LegendMarker*> createLegendMarker(QLegend *legend); | |
50 | QAbstractAxis* createAxisX(); |
|
50 | QAbstractAxis* createAxisX(QObject* parent); | |
51 | QAbstractAxis* createAxisY(); |
|
51 | QAbstractAxis* createAxisY(QObject* parent); | |
52 |
|
52 | |||
53 | void updateDerivativeData(); |
|
53 | void updateDerivativeData(); | |
54 |
|
54 |
@@ -52,8 +52,8 public: | |||||
52 | virtual void scaleDomain(Domain& domain) = 0; |
|
52 | virtual void scaleDomain(Domain& domain) = 0; | |
53 | virtual Chart* createGraphics(ChartPresenter* presenter) = 0; |
|
53 | virtual Chart* createGraphics(ChartPresenter* presenter) = 0; | |
54 | virtual QList<LegendMarker*> createLegendMarker(QLegend* legend) = 0; |
|
54 | virtual QList<LegendMarker*> createLegendMarker(QLegend* legend) = 0; | |
55 | virtual QAbstractAxis* createAxisX() = 0; |
|
55 | virtual QAbstractAxis* createAxisX(QObject* parent) = 0; | |
56 | virtual QAbstractAxis* createAxisY() = 0; |
|
56 | virtual QAbstractAxis* createAxisY(QObject* parent) = 0; | |
57 |
|
57 | |||
58 | protected: |
|
58 | protected: | |
59 | QAbstractSeries *q_ptr; |
|
59 | QAbstractSeries *q_ptr; |
@@ -398,15 +398,11 void QChart::setMarginsMinimum(const QRectF& margins) | |||||
398 |
|
398 | |||
399 | void QChart::setAxisX(QAbstractSeries *series, QAbstractAxis* axis) |
|
399 | void QChart::setAxisX(QAbstractSeries *series, QAbstractAxis* axis) | |
400 | { |
|
400 | { | |
401 | // Q_UNUSED(series); |
|
|||
402 | // Q_UNUSED(axis); |
|
|||
403 | d_ptr->m_dataset->setAxisX(series, axis); |
|
401 | d_ptr->m_dataset->setAxisX(series, axis); | |
404 | } |
|
402 | } | |
405 |
|
403 | |||
406 | void QChart::setAxisY(QAbstractSeries *series, QAbstractAxis* axis) |
|
404 | void QChart::setAxisY(QAbstractSeries *series, QAbstractAxis* axis) | |
407 | { |
|
405 | { | |
408 | // Q_UNUSED(series); |
|
|||
409 | // Q_UNUSED(axis); |
|
|||
410 | d_ptr->m_dataset->setAxisY(series, axis); |
|
406 | d_ptr->m_dataset->setAxisY(series, axis); | |
411 | } |
|
407 | } | |
412 |
|
408 |
@@ -24,7 +24,6 | |||||
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
27 | #include "qvaluesaxis.h" |
|
|||
28 |
|
27 | |||
29 | /*! |
|
28 | /*! | |
30 | \class QScatterSeries |
|
29 | \class QScatterSeries | |
@@ -250,19 +249,6 Chart* QScatterSeriesPrivate::createGraphics(ChartPresenter* presenter) | |||||
250 | return scatter; |
|
249 | return scatter; | |
251 | } |
|
250 | } | |
252 |
|
251 | |||
253 | QAbstractAxis* QScatterSeriesPrivate::createAxisX() |
|
|||
254 | { |
|
|||
255 | // TODO: parent? |
|
|||
256 | return new QValuesAxis(this); |
|
|||
257 | } |
|
|||
258 |
|
||||
259 | QAbstractAxis* QScatterSeriesPrivate::createAxisY() |
|
|||
260 | { |
|
|||
261 | // TODO: parent? |
|
|||
262 | return new QValuesAxis(this); |
|
|||
263 | } |
|
|||
264 |
|
||||
265 |
|
||||
266 | #include "moc_qscatterseries.cpp" |
|
252 | #include "moc_qscatterseries.cpp" | |
267 |
|
253 | |||
268 | QTCOMMERCIALCHART_END_NAMESPACE |
|
254 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -39,8 +39,6 class QScatterSeriesPrivate: public QXYSeriesPrivate | |||||
39 | public: |
|
39 | public: | |
40 | QScatterSeriesPrivate(QScatterSeries* q); |
|
40 | QScatterSeriesPrivate(QScatterSeries* q); | |
41 | Chart* createGraphics(ChartPresenter* presenter); |
|
41 | Chart* createGraphics(ChartPresenter* presenter); | |
42 | QAbstractAxis* createAxisX(); |
|
|||
43 | QAbstractAxis* createAxisY(); |
|
|||
44 |
|
42 | |||
45 | private: |
|
43 | private: | |
46 | QScatterSeries::MarkerShape m_shape; |
|
44 | QScatterSeries::MarkerShape m_shape; |
@@ -22,6 +22,7 | |||||
22 | #include "qxyseries_p.h" |
|
22 | #include "qxyseries_p.h" | |
23 | #include "domain_p.h" |
|
23 | #include "domain_p.h" | |
24 | #include "legendmarker_p.h" |
|
24 | #include "legendmarker_p.h" | |
|
25 | #include "qvaluesaxis.h" | |||
25 |
|
26 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
28 | |||
@@ -434,6 +435,16 QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend) | |||||
434 | return list << new XYLegendMarker(q,legend); |
|
435 | return list << new XYLegendMarker(q,legend); | |
435 | } |
|
436 | } | |
436 |
|
437 | |||
|
438 | QAbstractAxis* QXYSeriesPrivate::createAxisX(QObject* parent) | |||
|
439 | { | |||
|
440 | return new QValuesAxis(parent); | |||
|
441 | } | |||
|
442 | ||||
|
443 | QAbstractAxis* QXYSeriesPrivate::createAxisY(QObject* parent) | |||
|
444 | { | |||
|
445 | return new QValuesAxis(parent); | |||
|
446 | } | |||
|
447 | ||||
437 | #include "moc_qxyseries.cpp" |
|
448 | #include "moc_qxyseries.cpp" | |
438 | #include "moc_qxyseries_p.cpp" |
|
449 | #include "moc_qxyseries_p.cpp" | |
439 |
|
450 |
@@ -35,6 +35,7 | |||||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class QXYSeries; |
|
37 | class QXYSeries; | |
|
38 | class QAbstractAxis; | |||
38 |
|
39 | |||
39 | class QXYSeriesPrivate: public QAbstractSeriesPrivate |
|
40 | class QXYSeriesPrivate: public QAbstractSeriesPrivate | |
40 | { |
|
41 | { | |
@@ -46,6 +47,9 public: | |||||
46 | void scaleDomain(Domain& domain); |
|
47 | void scaleDomain(Domain& domain); | |
47 | QList<LegendMarker*> createLegendMarker(QLegend* legend); |
|
48 | QList<LegendMarker*> createLegendMarker(QLegend* legend); | |
48 |
|
49 | |||
|
50 | QAbstractAxis* createAxisX(QObject* parent); | |||
|
51 | QAbstractAxis* createAxisY(QObject* parent); | |||
|
52 | ||||
49 | Q_SIGNALS: |
|
53 | Q_SIGNALS: | |
50 | void updated(); |
|
54 | void updated(); | |
51 | // void pointReplaced(int index); |
|
55 | // void pointReplaced(int index); |
@@ -33,6 +33,7 | |||||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include "chartitem_p.h" |
|
34 | #include "chartitem_p.h" | |
35 | #include "xyanimation_p.h" |
|
35 | #include "xyanimation_p.h" | |
|
36 | #include "qvaluesaxis.h" | |||
36 | #include <QPen> |
|
37 | #include <QPen> | |
37 |
|
38 | |||
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now