##// END OF EJS Templates
Adds createDefaultAxes logic
Michal Klocek -
r1588:8cb4c015734a
parent child
Show More
@@ -251,9 +251,8 QChart* ThemeWidget::createLineChart() const
251 series->setName(name + QString::number(nameIndex));
251 series->setName(name + QString::number(nameIndex));
252 nameIndex++;
252 nameIndex++;
253 chart->addSeries(series);
253 chart->addSeries(series);
254 chart->createDefaultAxes();
255
256 }
254 }
255 chart->createDefaultAxes();
257
256
258 return chart;
257 return chart;
259 }
258 }
@@ -298,8 +297,8 QChart* ThemeWidget::createSplineChart() const
298 series->setName(name + QString::number(nameIndex));
297 series->setName(name + QString::number(nameIndex));
299 nameIndex++;
298 nameIndex++;
300 chart->addSeries(series);
299 chart->addSeries(series);
301 chart->createDefaultAxes();
302 }
300 }
301 chart->createDefaultAxes();
303 return chart;
302 return chart;
304 }
303 }
305
304
@@ -318,8 +317,8 QChart* ThemeWidget::createScatterChart() const
318 series->setName(name + QString::number(nameIndex));
317 series->setName(name + QString::number(nameIndex));
319 nameIndex++;
318 nameIndex++;
320 chart->addSeries(series);
319 chart->addSeries(series);
321 chart->createDefaultAxes();
322 }
320 }
321 chart->createDefaultAxes();
323 return chart;
322 return chart;
324 }
323 }
325
324
@@ -380,14 +380,24 QList<LegendMarker*> QAreaSeriesPrivate::createLegendMarker(QLegend* legend)
380 }
380 }
381
381
382
382
383 QAbstractAxis* QAreaSeriesPrivate::createAxisX(QObject* parent)
383 void QAreaSeriesPrivate::initializeAxisX(QAbstractAxis* axis)
384 {
384 {
385 return new QValuesAxis(parent);
385 Q_UNUSED(axis);
386 }
386 }
387
387
388 QAbstractAxis* QAreaSeriesPrivate::createAxisY(QObject* parent)
388 void QAreaSeriesPrivate::initializeAxisY(QAbstractAxis* axis)
389 {
389 {
390 return new QValuesAxis(parent);
390 Q_UNUSED(axis);
391 }
392
393 QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisXType() const
394 {
395 return QAbstractAxis::AxisTypeValues;
396 }
397
398 QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisYType() const
399 {
400 return QAbstractAxis::AxisTypeValues;
391 }
401 }
392
402
393 #include "moc_qareaseries.cpp"
403 #include "moc_qareaseries.cpp"
@@ -46,8 +46,10 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(QObject* parent = 0);
49 void initializeAxisX(QAbstractAxis* axis);
50 QAbstractAxis* createAxisY(QObject* parent = 0);
50 void initializeAxisY(QAbstractAxis* axis);
51 QAbstractAxis::AxisType defaultAxisXType() const;
52 QAbstractAxis::AxisType defaultAxisYType() const;
51
53
52 Q_SIGNALS:
54 Q_SIGNALS:
53 void updated();
55 void updated();
@@ -48,10 +48,13 class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject
48 public:
48 public:
49
49
50 enum AxisType {
50 enum AxisType {
51 AxisTypeValues,
51 AxisTypeNoAxis = 0x0,
52 AxisTypeCategories
52 AxisTypeValues = 0x1,
53 AxisTypeCategories = 0x2
53 };
54 };
54
55
56 Q_DECLARE_FLAGS(AxisTypes, AxisType)
57
55 protected:
58 protected:
56 explicit QAbstractAxis(QAbstractAxisPrivate &d,QObject *parent = 0);
59 explicit QAbstractAxis(QAbstractAxisPrivate &d,QObject *parent = 0);
57
60
@@ -49,7 +49,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
49 */
49 */
50 /*!
50 /*!
51 \qmlclass BarSeries QAbstractBarSeries
51 \qmlclass BarSeries QAbstractBarSeries
52 \inherits AbstractSeries
52 \inherits QAbstractSeries
53
53
54 The following QML shows how to create a simple bar chart:
54 The following QML shows how to create a simple bar chart:
55 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
55 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
@@ -601,16 +601,6 QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* lege
601 return markers;
601 return markers;
602 }
602 }
603
603
604 QAbstractAxis* QAbstractBarSeriesPrivate::createAxisX(QObject* parent)
605 {
606 return new QCategoriesAxis(parent);
607 }
608
609 QAbstractAxis* QAbstractBarSeriesPrivate::createAxisY(QObject* parent)
610 {
611 return new QValuesAxis(parent);
612 }
613
614 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
604 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
615 {
605 {
616 Q_Q(QAbstractBarSeries);
606 Q_Q(QAbstractBarSeries);
@@ -718,7 +708,28 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
718 return true;
708 return true;
719 }
709 }
720
710
711 void QAbstractBarSeriesPrivate::initializeAxisX(QAbstractAxis* axis)
712 {
713 Q_UNUSED(axis);
714 }
715
716 void QAbstractBarSeriesPrivate::initializeAxisY(QAbstractAxis* axis)
717 {
718 Q_UNUSED(axis)
719 }
720
721 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisXType() const
722 {
723 return QAbstractAxis::AxisTypeCategories;
724 }
725
726 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisYType() const
727 {
728 return QAbstractAxis::AxisTypeValues;
729 }
730
721 #include "moc_qabstractbarseries.cpp"
731 #include "moc_qabstractbarseries.cpp"
722 #include "moc_qabstractbarseries_p.cpp"
732 #include "moc_qabstractbarseries_p.cpp"
723
733
734
724 QTCOMMERCIALCHART_END_NAMESPACE
735 QTCOMMERCIALCHART_END_NAMESPACE
@@ -56,8 +56,10 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(QObject* parent = 0);
59 void initializeAxisX(QAbstractAxis* axis);
60 QAbstractAxis* createAxisY(QObject* parent = 0);
60 void initializeAxisY(QAbstractAxis* axis);
61 QAbstractAxis::AxisType defaultAxisXType() const;
62 QAbstractAxis::AxisType defaultAxisYType() const;
61
63
62 bool append(QBarSet *set);
64 bool append(QBarSet *set);
63 bool remove(QBarSet *set);
65 bool remove(QBarSet *set);
@@ -45,7 +45,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
45 */
45 */
46 /*!
46 /*!
47 \qmlclass PercentBarSeries QPercentBarSeries
47 \qmlclass PercentBarSeries QPercentBarSeries
48 \inherits BarSeries
48 \inherits QAbstractBarSeries
49
49
50 The following QML shows how to create a simple percent bar chart:
50 The following QML shows how to create a simple percent bar chart:
51 \snippet ../demos/qmlchart/qml/qmlchart/View9.qml 1
51 \snippet ../demos/qmlchart/qml/qmlchart/View9.qml 1
@@ -21,6 +21,7
21 #include "chartdataset_p.h"
21 #include "chartdataset_p.h"
22 #include "qchart.h"
22 #include "qchart.h"
23 #include "qvaluesaxis.h"
23 #include "qvaluesaxis.h"
24 #include "qcategoriesaxis.h"
24 #include "qvaluesaxis_p.h"
25 #include "qvaluesaxis_p.h"
25 #include "qabstractseries_p.h"
26 #include "qabstractseries_p.h"
26 #include "qabstractbarseries.h"
27 #include "qabstractbarseries.h"
@@ -80,42 +81,114 void ChartDataSet::addSeries(QAbstractSeries* series)
80
81
81 void ChartDataSet::createDefaultAxes()
82 void ChartDataSet::createDefaultAxes()
82 {
83 {
83 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
84
84
85 if(m_seriesDomainMap.isEmpty()) return;
86
87 QAbstractAxis::AxisTypes typeX(0);
88 QAbstractAxis::AxisTypes typeY(0);
89
90 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
85 while (i.hasNext()) {
91 while (i.hasNext()) {
86 i.next();
92 i.next();
93 removeAxes(i.key());
94 }
87
95
88 if(!m_seriesAxisXMap.value(i.key()))
96 i.toFront();
89 {
90
97
91 QAbstractAxis* axisX = i.key()->d_ptr->createAxisX(this);
98 while (i.hasNext()) {
99 i.next();
100 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
101 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
102 if(axisX) typeX&=axisX->type();
103 else typeX|=i.key()->d_ptr->defaultAxisXType();
104 if(axisY) typeY&=axisY->type();
105 else typeY|=i.key()->d_ptr->defaultAxisYType();
106 }
92
107
93 if(axisX) {
94 QObject::connect(axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),i.value(),SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
95 QObject::connect(i.value(),SIGNAL(rangeXChanged(qreal,qreal,int)),axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
96 axisX->d_ptr->m_orientation=Qt::Horizontal;
97 emit axisAdded(axisX,i.value());
98 m_seriesAxisXMap.insert(i.key(),axisX);
99 }
100
108
109 if(typeX.testFlag(QAbstractAxis::AxisTypeValues) && typeX.testFlag(QAbstractAxis::AxisTypeCategories))
110 {
111 i.toFront();
112 while (i.hasNext()) {
113 i.next();
114 QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisXType());
115 i.key()->d_ptr->initializeAxisX(axis);
116 addAxisX(axis,i.key());
117 emit axisAdded(axis,i.value());
101 }
118 }
102
119
103 if(!m_seriesAxisYMap.value(i.key()))
120 }else if(!typeY.testFlag(QAbstractAxis::AxisTypeNoAxis)){
104 {
121 QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(typeX)));
105 QAbstractAxis* axisY = i.key()->d_ptr->createAxisY(this);
122 i.toFront();
106
123 while (i.hasNext()) {
107 if(axisY) {
124 i.next();
108 QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),i.value(),SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
125 i.key()->d_ptr->initializeAxisX(axis);
109 QObject::connect(i.value(),SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
126 addAxisX(axis,i.key());
110 axisY->d_ptr->m_orientation=Qt::Vertical;
127 }
111 emit axisAdded(axisY,i.value());
128 emit axisAdded(axis,i.value());
112 m_seriesAxisYMap.insert(i.key(),axisY);
129
113 }
130 }
131
132 if(typeY.testFlag(QAbstractAxis::AxisTypeValues) && typeY.testFlag(QAbstractAxis::AxisTypeCategories))
133 {
134 i.toFront();
135 while (i.hasNext()) {
136 i.next();
137 QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisYType());
138 i.key()->d_ptr->initializeAxisY(axis);
139 addAxisY(axis,i.key());
140 emit axisAdded(axis,i.value());
114 }
141 }
142
143 }else if(!typeY.testFlag(QAbstractAxis::AxisTypeNoAxis)){
144 QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(typeY)));
145 i.toFront();
146 while (i.hasNext()) {
147 i.next();
148 i.key()->d_ptr->initializeAxisY(axis);
149 addAxisY(axis,i.key());
150 }
151 emit axisAdded(axis,i.value());
152
115 }
153 }
116 }
154 }
117
155
118
156
157 QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type)
158 {
159 QAbstractAxis* axis =0;
160
161 switch(type) {
162 case QAbstractAxis::AxisTypeValues:
163 axis = new QValuesAxis(this);
164 break;
165 case QAbstractAxis::AxisTypeCategories:
166 axis = new QCategoriesAxis(this);
167 break;
168 default:
169 axis = 0;
170 break;
171 }
172
173 return axis;
174 }
175
176 void ChartDataSet::addAxisX(QAbstractAxis* axis,QAbstractSeries* series) {
177 Domain* domain = m_seriesDomainMap.value(series);
178 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
179 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
180 axis->d_ptr->m_orientation=Qt::Horizontal;
181 m_seriesAxisXMap.insert(series,axis);
182 }
183
184 void ChartDataSet::addAxisY(QAbstractAxis* axis,QAbstractSeries* series) {
185 Domain* domain = m_seriesDomainMap.value(series);
186 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
187 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
188 axis->d_ptr->m_orientation=Qt::Vertical;
189 m_seriesAxisYMap.insert(series,axis);
190 }
191
119 void ChartDataSet::removeSeries(QAbstractSeries* series)
192 void ChartDataSet::removeSeries(QAbstractSeries* series)
120 {
193 {
121 Domain* domain = m_seriesDomainMap.take(series);
194 Domain* domain = m_seriesDomainMap.take(series);
@@ -138,6 +211,11 void ChartDataSet::removeSeries(QAbstractSeries* series)
138 series->d_ptr->m_chart = 0;
211 series->d_ptr->m_chart = 0;
139 series->d_ptr->m_dataset = 0;
212 series->d_ptr->m_dataset = 0;
140
213
214 removeAxes(series);
215 }
216
217 void ChartDataSet::removeAxes(QAbstractSeries* series)
218 {
141 QAbstractAxis* axisX = m_seriesAxisXMap.take(series);
219 QAbstractAxis* axisX = m_seriesAxisXMap.take(series);
142
220
143 if(axisX) {
221 if(axisX) {
@@ -32,6 +32,7
32
32
33 #include "qabstractseries.h"
33 #include "qabstractseries.h"
34 #include "domain_p.h"
34 #include "domain_p.h"
35 #include "qabstractaxis_p.h"
35 #include <QVector>
36 #include <QVector>
36
37
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -76,8 +77,11 Q_SIGNALS:
76 void axisRemoved(QAbstractAxis* axis);
77 void axisRemoved(QAbstractAxis* axis);
77
78
78 private:
79 private:
79 QStringList createLabels(QAbstractAxis* axis,qreal min, qreal max);
80 void calculateDomain(QAbstractSeries* series,Domain* domain);
80 void calculateDomain(QAbstractSeries* series,Domain* domain);
81 QAbstractAxis* createAxis(QAbstractAxis::AxisType type);
82 void addAxisX(QAbstractAxis* axis,QAbstractSeries* series);
83 void addAxisY(QAbstractAxis* axis,QAbstractSeries* series);
84 void removeAxes(QAbstractSeries* series);
81
85
82 private:
86 private:
83 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisXMap;
87 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisXMap;
@@ -755,16 +755,24 QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend)
755 return markers;
755 return markers;
756 }
756 }
757
757
758 QAbstractAxis* QPieSeriesPrivate::createAxisX(QObject* parent)
758 void QPieSeriesPrivate::initializeAxisX(QAbstractAxis* axis)
759 {
759 {
760 Q_UNUSED(parent);
760 Q_UNUSED(axis);
761 return 0;
762 }
761 }
763
762
764 QAbstractAxis* QPieSeriesPrivate::createAxisY(QObject* parent)
763 void QPieSeriesPrivate::initializeAxisY(QAbstractAxis* axis)
765 {
764 {
766 Q_UNUSED(parent);
765 Q_UNUSED(axis);
767 return 0;
766 }
767
768 QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisXType() const
769 {
770 return QAbstractAxis::AxisTypeNoAxis;
771 }
772
773 QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisYType() const
774 {
775 return QAbstractAxis::AxisTypeNoAxis;
768 }
776 }
769
777
770 #include "moc_qpieseries.cpp"
778 #include "moc_qpieseries.cpp"
@@ -47,8 +47,10 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(QObject* parent);
50 void initializeAxisX(QAbstractAxis* axis);
51 QAbstractAxis* createAxisY(QObject* parent);
51 void initializeAxisY(QAbstractAxis* axis);
52 QAbstractAxis::AxisType defaultAxisXType() const;
53 QAbstractAxis::AxisType defaultAxisYType() const;
52
54
53 void updateDerivativeData();
55 void updateDerivativeData();
54
56
@@ -22,6 +22,7
22 #define QABSTRACTSERIES_H
22 #define QABSTRACTSERIES_H
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <qabstractaxis.h>
25 #include <QObject>
26 #include <QObject>
26 #include <QPen>
27 #include <QPen>
27
28
@@ -57,6 +58,7 protected:
57 public:
58 public:
58 ~QAbstractSeries();
59 ~QAbstractSeries();
59 virtual SeriesType type() const = 0;
60 virtual SeriesType type() const = 0;
61
60 void setName(const QString& name);
62 void setName(const QString& name);
61 QString name() const;
63 QString name() const;
62 void setVisible(bool visible = true);
64 void setVisible(bool visible = true);
@@ -52,8 +52,10 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(QObject* parent) = 0;
55 virtual void initializeAxisX(QAbstractAxis* axis) = 0;
56 virtual QAbstractAxis* createAxisY(QObject* parent) = 0;
56 virtual void initializeAxisY(QAbstractAxis* axis) = 0;
57 virtual QAbstractAxis::AxisType defaultAxisXType() const = 0;
58 virtual QAbstractAxis::AxisType defaultAxisYType() const = 0;
57
59
58 protected:
60 protected:
59 QAbstractSeries *q_ptr;
61 QAbstractSeries *q_ptr;
@@ -435,14 +435,24 QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend)
435 return list << new XYLegendMarker(q,legend);
435 return list << new XYLegendMarker(q,legend);
436 }
436 }
437
437
438 QAbstractAxis* QXYSeriesPrivate::createAxisX(QObject* parent)
438 void QXYSeriesPrivate::initializeAxisX(QAbstractAxis* axis)
439 {
439 {
440 return new QValuesAxis(parent);
440 Q_UNUSED(axis);
441 }
441 }
442
442
443 QAbstractAxis* QXYSeriesPrivate::createAxisY(QObject* parent)
443 void QXYSeriesPrivate::initializeAxisY(QAbstractAxis* axis)
444 {
444 {
445 return new QValuesAxis(parent);
445 Q_UNUSED(axis);
446 }
447
448 QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisXType() const
449 {
450 return QAbstractAxis::AxisTypeValues;
451 }
452
453 QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisYType() const
454 {
455 return QAbstractAxis::AxisTypeValues;
446 }
456 }
447
457
448 #include "moc_qxyseries.cpp"
458 #include "moc_qxyseries.cpp"
@@ -47,8 +47,10 public:
47 void scaleDomain(Domain& domain);
47 void scaleDomain(Domain& domain);
48 QList<LegendMarker*> createLegendMarker(QLegend* legend);
48 QList<LegendMarker*> createLegendMarker(QLegend* legend);
49
49
50 QAbstractAxis* createAxisX(QObject* parent);
50 void initializeAxisX(QAbstractAxis* axis);
51 QAbstractAxis* createAxisY(QObject* parent);
51 void initializeAxisY(QAbstractAxis* axis);
52 QAbstractAxis::AxisType defaultAxisXType() const;
53 QAbstractAxis::AxisType defaultAxisYType() const;
52
54
53 Q_SIGNALS:
55 Q_SIGNALS:
54 void updated();
56 void updated();
@@ -541,6 +541,8 void tst_ChartDataSet::zoomInDomain()
541 */
541 */
542 m_dataset->createDefaultAxes();
542 m_dataset->createDefaultAxes();
543
543
544
545
544 QList<QSignalSpy*> spyList;
546 QList<QSignalSpy*> spyList;
545
547
546 foreach(QAbstractSeries* series, seriesList) {
548 foreach(QAbstractSeries* series, seriesList) {
General Comments 0
You need to be logged in to leave comments. Login now