##// END OF EJS Templates
barchart mvp model integrating
sauimone -
r160:f044c4ee95db
parent child
Show More
@@ -1,99 +1,99
1 #include <limits.h>
1 #include <limits.h>
2 #include "barchartmodel_p.h"
2 #include "barchartmodel_p.h"
3
3
4 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5
5
6 BarChartModel::BarChartModel(QObject *parent) :
6 BarChartModel::BarChartModel(QObject *parent) :
7 QObject(parent)
7 QObject(parent)
8 {
8 {
9 }
9 }
10
10
11 void BarChartModel::addSeries(BarChartSeriesBase& series)
11 void BarChartModel::addSeries(BarChartSeriesBase& series)
12 {
12 {
13 mSeries.append(&series);
13 mSeries.append(&series);
14 emit modelUpdated();
14 emit modelUpdated();
15 }
15 }
16
16
17 void BarChartModel::removeSeries(BarChartSeriesBase& series)
17 void BarChartModel::removeSeries(BarChartSeriesBase& series)
18 {
18 {
19 int i = mSeries.indexOf(&series);
19 int i = mSeries.indexOf(&series);
20 if (-1 == i) {
20 if (-1 == i) {
21 return;
21 return;
22 }
22 }
23 mSeries.removeAt(i);
23 mSeries.removeAt(i);
24 emit modelUpdated();
24 emit modelUpdated();
25 }
25 }
26
26
27 int BarChartModel::countSeries()
27 int BarChartModel::countSeries()
28 {
28 {
29 return mSeries.count();
29 return mSeries.count();
30 }
30 }
31
31
32 int BarChartModel::countItemsInSeries()
32 int BarChartModel::countItemsInSeries()
33 {
33 {
34 int count(0);
34 int count(0);
35 for (int i=0; i<mSeries.count(); i++){
35 for (int i=0; i<mSeries.count(); i++){
36 // TODO: can we assume that all series have same number of items? If not. then which items are empty.
36 // TODO: can we assume that all series have same number of values? If not. then which values are empty?
37 int temp = mSeries.at(i)->countItems();
37 int temp = mSeries.at(i)->countValues();
38 if (temp > count) {
38 if (temp > count) {
39 count = temp;
39 count = temp;
40 }
40 }
41 }
41 }
42 return count;
42 return count;
43 }
43 }
44
44
45 int BarChartModel::countTotalItems()
45 int BarChartModel::countTotalItems()
46 {
46 {
47 int total = mSeries.count() * countItemsInSeries();
47 int total = mSeries.count() * countItemsInSeries();
48 return total;
48 return total;
49 }
49 }
50
50
51 int BarChartModel::min()
51 int BarChartModel::min()
52 {
52 {
53 Q_ASSERT(mSeries.count() > 0);
53 Q_ASSERT(mSeries.count() > 0);
54 // TODO: make min and max members and update them when data changes.
54 // TODO: make min and max members and update them when data changes.
55 // This is slower since they are checked every time, even if data is same since previous call.
55 // This is slower since they are checked every time, even if data is same since previous call.
56 int min = INT_MAX;
56 int min = INT_MAX;
57
57
58 for (int i=0; i <mSeries.count(); i++) {
58 for (int i=0; i <mSeries.count(); i++) {
59 int temp = mSeries.at(i)->min();
59 int temp = mSeries.at(i)->min();
60 if (temp < min) {
60 if (temp < min) {
61 min = temp;
61 min = temp;
62 }
62 }
63 }
63 }
64 return min;
64 return min;
65 }
65 }
66
66
67 int BarChartModel::max()
67 int BarChartModel::max()
68 {
68 {
69 Q_ASSERT(mSeries.count() > 0);
69 Q_ASSERT(mSeries.count() > 0);
70
70
71 // TODO: make min and max members and update them when data changes.
71 // TODO: make min and max members and update them when data changes.
72 // This is slower since they are checked every time, even if data is same since previous call.
72 // This is slower since they are checked every time, even if data is same since previous call.
73 int max = INT_MIN;
73 int max = INT_MIN;
74
74
75 for (int i=0; i <mSeries.count(); i++) {
75 for (int i=0; i <mSeries.count(); i++) {
76 int temp = mSeries.at(i)->min();
76 int temp = mSeries.at(i)->min();
77 if (temp > max) {
77 if (temp > max) {
78 max = temp;
78 max = temp;
79 }
79 }
80 }
80 }
81 return max;
81 return max;
82 }
82 }
83
83
84 qreal BarChartModel::valueAt(int series, int item)
84 qreal BarChartModel::valueAt(int series, int item)
85 {
85 {
86 if ((series < 0) || (series >= mSeries.count())) {
86 if ((series < 0) || (series >= mSeries.count())) {
87 // No series, no value.
87 // No series, no value.
88 return 0;
88 return 0;
89 } else if ((item < 0) || (item >= mSeries.at(series)->countItems())) {
89 } else if ((item < 0) || (item >= mSeries.at(series)->countValues())) {
90 // No item, no value.
90 // No item, no value.
91 return 0;
91 return 0;
92 }
92 }
93
93
94 return mSeries.at(series)->valueAt(item);
94 return mSeries.at(series)->valueAt(item);
95 }
95 }
96
96
97 #include "moc_barchartmodel_p.cpp"
97 #include "moc_barchartmodel_p.cpp"
98
98
99 QTCOMMERCIALCHART_END_NAMESPACE
99 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,158 +1,158
1 #include <limits.h>
1 #include <limits.h>
2 #include <QDebug>
2 #include <QDebug>
3 #include "barchartseriesbase.h"
3 #include "barchartseriesbase.h"
4 #include "bargroup.h"
4 #include "bargroup.h"
5
5
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
7
8 BarChartSeriesBase::BarChartSeriesBase(QObject *parent)
8 BarChartSeriesBase::BarChartSeriesBase(QObject *parent)
9 : QChartSeries(parent)
9 : QChartSeries(parent)
10 ,mData(0)
10 ,mData(0)
11 {
11 {
12 }
12 }
13 /*
13 /*
14 bool BarChartSeriesBase::setModel(QAbstractItemModel* model)
14 bool BarChartSeriesBase::setModel(QAbstractItemModel* model)
15 {
15 {
16 mModel = model;
16 mModel = model;
17 return true;
17 return true;
18 }
18 }
19 */
19 */
20 bool BarChartSeriesBase::setData(QList<qreal>& data)
20 bool BarChartSeriesBase::setData(QList<qreal>& data)
21 {
21 {
22 mData = &data;
22 mData = &data;
23 return true;
23 return true;
24 }
24 }
25 /*
25 /*
26 int BarChartSeriesBase::min()
26 int BarChartSeriesBase::min()
27 {
27 {
28 Q_ASSERT(mModel->rowCount() > 0);
28 Q_ASSERT(mModel->rowCount() > 0);
29 Q_ASSERT(mModel->columnCount() > 0);
29 Q_ASSERT(mModel->columnCount() > 0);
30
30
31 // TODO: make min and max members and update them when data changes.
31 // TODO: make min and max members and update them when data changes.
32 // This is slower since they are checked every time, even if data is same since previous call.
32 // This is slower since they are checked every time, even if data is same since previous call.
33 int min = INT_MAX;
33 int min = INT_MAX;
34
34
35 for (int i=0; i <mModel->rowCount(); i++) {
35 for (int i=0; i <mModel->rowCount(); i++) {
36 for(int j=0; j<mModel->columnCount(); j++) {
36 for(int j=0; j<mModel->columnCount(); j++) {
37 int temp = mModel->data(mModel->index(i,j)).toInt();
37 int temp = mModel->data(mModel->index(i,j)).toInt();
38 if (temp < min) {
38 if (temp < min) {
39 min = temp;
39 min = temp;
40 }
40 }
41 }
41 }
42 }
42 }
43 return min;
43 return min;
44 }
44 }
45
45
46 int BarChartSeriesBase::max()
46 int BarChartSeriesBase::max()
47 {
47 {
48 Q_ASSERT(mModel->rowCount() > 0);
48 Q_ASSERT(mModel->rowCount() > 0);
49 Q_ASSERT(mModel->columnCount() > 0);
49 Q_ASSERT(mModel->columnCount() > 0);
50
50
51 // TODO: make min and max members and update them when data changes.
51 // TODO: make min and max members and update them when data changes.
52 // This is slower since they are checked every time, even if data is same since previous call.
52 // This is slower since they are checked every time, even if data is same since previous call.
53 int max = INT_MIN;
53 int max = INT_MIN;
54
54
55 for (int i=0; i <mModel->rowCount(); i++) {
55 for (int i=0; i <mModel->rowCount(); i++) {
56 for(int j=0; j<mModel->columnCount(); j++) {
56 for(int j=0; j<mModel->columnCount(); j++) {
57 int temp = mModel->data(mModel->index(i,j)).toInt();
57 int temp = mModel->data(mModel->index(i,j)).toInt();
58 if (temp > max) {
58 if (temp > max) {
59 max = temp;
59 max = temp;
60 }
60 }
61 }
61 }
62 }
62 }
63 return max;
63 return max;
64 }
64 }
65
65
66 int BarChartSeriesBase::maxColumnSum()
66 int BarChartSeriesBase::maxColumnSum()
67 {
67 {
68 Q_ASSERT(mModel->rowCount() > 0);
68 Q_ASSERT(mModel->rowCount() > 0);
69 Q_ASSERT(mModel->columnCount() > 0);
69 Q_ASSERT(mModel->columnCount() > 0);
70
70
71 int max = INT_MIN;
71 int max = INT_MIN;
72
72
73 for (int col=0; col <mModel->columnCount(); col++) {
73 for (int col=0; col <mModel->columnCount(); col++) {
74 int sum = columnSum(col);
74 int sum = columnSum(col);
75 if (sum > max) {
75 if (sum > max) {
76 max = sum;
76 max = sum;
77 }
77 }
78 }
78 }
79 return max;
79 return max;
80 }
80 }
81
81
82 int BarChartSeriesBase::countRows()
82 int BarChartSeriesBase::countRows()
83 {
83 {
84 return mModel->rowCount();
84 return mModel->rowCount();
85 }
85 }
86
86
87 int BarChartSeriesBase::countColumns()
87 int BarChartSeriesBase::countColumns()
88 {
88 {
89 return mModel->columnCount();
89 return mModel->columnCount();
90 }
90 }
91
91
92 int BarChartSeriesBase::countTotalItems()
92 int BarChartSeriesBase::countTotalItems()
93 {
93 {
94 return mModel->rowCount() * mModel->columnCount();
94 return mModel->rowCount() * mModel->columnCount();
95 }
95 }
96
96
97 int BarChartSeriesBase::valueAt(int row, int column)
97 int BarChartSeriesBase::valueAt(int row, int column)
98 {
98 {
99 QModelIndex index = mModel->index(row,column);
99 QModelIndex index = mModel->index(row,column);
100 return mModel->data(index).toInt();
100 return mModel->data(index).toInt();
101 }
101 }
102
102
103 int BarChartSeriesBase::columnSum(int column)
103 int BarChartSeriesBase::columnSum(int column)
104 {
104 {
105 int sum(0);
105 int sum(0);
106 int count = mModel->rowCount();
106 int count = mModel->rowCount();
107
107
108 for (int row = 0; row < count; row++) {
108 for (int row = 0; row < count; row++) {
109 sum += mModel->data(mModel->index(row,column)).toInt();
109 sum += mModel->data(mModel->index(row,column)).toInt();
110 }
110 }
111 return sum;
111 return sum;
112 }
112 }
113 */
113 */
114 qreal BarChartSeriesBase::min()
114 qreal BarChartSeriesBase::min()
115 {
115 {
116 Q_ASSERT(mData != 0);
116 Q_ASSERT(mData != 0);
117
117
118 int count = mData->count();
118 int count = mData->count();
119 int min = INT_MAX;
119 int min = INT_MAX;
120
120
121 for (int i=0; i<count; i++) {
121 for (int i=0; i<count; i++) {
122 if (mData->at(i) < min) {
122 if (mData->at(i) < min) {
123 min = mData->at(i);
123 min = mData->at(i);
124 }
124 }
125 }
125 }
126 return min;
126 return min;
127 }
127 }
128
128
129 qreal BarChartSeriesBase::max()
129 qreal BarChartSeriesBase::max()
130 {
130 {
131 Q_ASSERT(mData != 0);
131 Q_ASSERT(mData != 0);
132
132
133 int count = mData->count();
133 int count = mData->count();
134 int max = INT_MIN;
134 int max = INT_MIN;
135
135
136 for (int i=0; i<count; i++) {
136 for (int i=0; i<count; i++) {
137 if (mData->at(i) > max) {
137 if (mData->at(i) > max) {
138 max = mData->at(i);
138 max = mData->at(i);
139 }
139 }
140 }
140 }
141 return max;
141 return max;
142 }
142 }
143
143
144 int BarChartSeriesBase::countItems()
144 int BarChartSeriesBase::countValues()
145 {
145 {
146 Q_ASSERT(mData != 0);
146 Q_ASSERT(mData != 0);
147 return mData->count();
147 return mData->count();
148 }
148 }
149
149
150 qreal BarChartSeriesBase::valueAt(int item)
150 qreal BarChartSeriesBase::valueAt(int item)
151 {
151 {
152 Q_ASSERT(mData != 0);
152 Q_ASSERT(mData != 0);
153 return mData->at(item);
153 return mData->at(item);
154 }
154 }
155
155
156 #include "moc_barchartseriesbase.cpp"
156 #include "moc_barchartseriesbase.cpp"
157
157
158 QTCOMMERCIALCHART_END_NAMESPACE
158 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,58 +1,58
1 #ifndef BARCHARTSERIESBASE_H
1 #ifndef BARCHARTSERIESBASE_H
2 #define BARCHARTSERIESBASE_H
2 #define BARCHARTSERIESBASE_H
3
3
4 #include <QList>
4 #include <QList>
5 #include <QAbstractItemModel>
5 #include <QAbstractItemModel>
6 #include "qchartseries.h"
6 #include "qchartseries.h"
7 #include "qchartglobal.h"
7 #include "qchartglobal.h"
8
8
9 class BarGroupBase;
9 class BarGroupBase;
10
10
11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12
12
13 // Container for series
13 // Container for series
14 class QTCOMMERCIALCHART_EXPORT BarChartSeriesBase : public QChartSeries
14 class QTCOMMERCIALCHART_EXPORT BarChartSeriesBase : public QChartSeries
15 {
15 {
16 Q_OBJECT
16 Q_OBJECT
17 protected:
17 protected:
18 BarChartSeriesBase(QObject* parent=0);
18 BarChartSeriesBase(QObject* parent=0);
19
19
20 public:
20 public:
21 // from QChartSeries
21 // from QChartSeries
22 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeInvalid; }
22 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeInvalid; }
23
23
24 // TODO: Better data model?
24 // TODO: Better data model?
25 // virtual bool setModel(QAbstractItemModel* model);
25 // virtual bool setModel(QAbstractItemModel* model);
26 virtual bool setData(QList<qreal>& data);
26 virtual bool setData(QList<qreal>& data);
27
27
28 // Methods to find out minimum and maximum values of data
28 // Methods to find out minimum and maximum values of data
29 // int min(); // TODO: remove
29 // int min(); // TODO: remove
30 // int max(); // TODO: remove
30 // int max(); // TODO: remove
31 // int maxColumnSum(); // TODO: move to model. returns maximum sum of items in all columns.
31 // int maxColumnSum(); // TODO: move to model. returns maximum sum of items in all columns.
32
32
33 // int countRows(); // TODO: remove.
33 // int countRows(); // TODO: remove.
34 // int countColumns(); // TODO: remove. Count items in one series.
34 // int countColumns(); // TODO: remove. Count items in one series.
35 // int countTotalItems(); // TODO: move to model
35 // int countTotalItems(); // TODO: move to model
36 // int valueAt(int row, int column); // TODO: move to model
36 // int valueAt(int row, int column); // TODO: move to model
37
37
38 // int columnSum(int column); // TODO: move to model
38 // int columnSum(int column); // TODO: move to model
39
39
40 qreal min();
40 qreal min();
41 qreal max();
41 qreal max();
42 int countItems();
42 int countValues();
43 qreal valueAt(int item);
43 qreal valueAt(int item);
44
44
45 public Q_SLOTS:
45 public Q_SLOTS:
46
46
47 private:
47 private:
48
48
49 QAbstractItemModel* mModel;
49 QAbstractItemModel* mModel;
50 BarGroupBase* mBarGroup;
50 BarGroupBase* mBarGroup;
51
51
52 QList<qreal>* mData;
52 QList<qreal>* mData;
53
53
54 };
54 };
55
55
56 QTCOMMERCIALCHART_END_NAMESPACE
56 QTCOMMERCIALCHART_END_NAMESPACE
57
57
58 #endif // BARCHARTSERIESBASE_H
58 #endif // BARCHARTSERIESBASE_H
@@ -1,160 +1,165
1 #include "chartdataset_p.h"
1 #include "chartdataset_p.h"
2 //series
2 //series
3 #include "qlinechartseries.h"
3 #include "qlinechartseries.h"
4 #include "barchartseries.h"
4 #include "barchartseries.h"
5 #include "stackedbarchartseries.h"
5 #include "stackedbarchartseries.h"
6 #include "percentbarchartseries.h"
6 #include "percentbarchartseries.h"
7 #include "qpieseries.h"
7 #include "qpieseries.h"
8 #include "qscatterseries.h"
8 #include "qscatterseries.h"
9
9
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11
11
12 ChartDataSet::ChartDataSet(QObject *parent):QObject(parent)
12 ChartDataSet::ChartDataSet(QObject *parent):QObject(parent)
13 {
13 {
14 Domain domain;
14 Domain domain;
15 m_domains<<domain;
15 m_domains<<domain;
16 }
16 }
17
17
18 ChartDataSet::~ChartDataSet()
18 ChartDataSet::~ChartDataSet()
19 {
19 {
20 // TODO Auto-generated destructor stub
20 // TODO Auto-generated destructor stub
21 }
21 }
22
22
23 const Domain& ChartDataSet::domain() const
23 const Domain& ChartDataSet::domain() const
24 {
24 {
25 return m_domains[m_domainIndex];
25 return m_domains[m_domainIndex];
26 }
26 }
27
27
28 void ChartDataSet::addSeries(QChartSeries* series)
28 void ChartDataSet::addSeries(QChartSeries* series)
29 {
29 {
30 // TODO: we should check the series not already added
30 // TODO: we should check the series not already added
31 m_chartSeries << series;
31 m_chartSeries << series;
32 m_domainIndex = 0;
32 m_domainIndex = 0;
33 m_domains.resize(1);
33 m_domains.resize(1);
34
34
35 Domain& domain = m_domains[m_domainIndex];
35 Domain& domain = m_domains[m_domainIndex];
36
36
37 switch(series->type())
37 switch(series->type())
38 {
38 {
39 case QChartSeries::SeriesTypeLine: {
39 case QChartSeries::SeriesTypeLine: {
40
40
41 QLineChartSeries* xyseries = static_cast<QLineChartSeries*>(series);
41 QLineChartSeries* xyseries = static_cast<QLineChartSeries*>(series);
42
42
43 for (int i = 0; i < xyseries->count(); i++)
43 for (int i = 0; i < xyseries->count(); i++)
44 {
44 {
45 qreal x = xyseries->x(i);
45 qreal x = xyseries->x(i);
46 qreal y = xyseries->y(i);
46 qreal y = xyseries->y(i);
47 domain.m_minX = qMin(domain.m_minX,x);
47 domain.m_minX = qMin(domain.m_minX,x);
48 domain.m_minY = qMin(domain.m_minY,y);
48 domain.m_minY = qMin(domain.m_minY,y);
49 domain.m_maxX = qMax(domain.m_maxX,x);
49 domain.m_maxX = qMax(domain.m_maxX,x);
50 domain.m_maxY = qMax(domain.m_maxY,y);
50 domain.m_maxY = qMax(domain.m_maxY,y);
51 }
51 }
52 break;
52 break;
53 }
53 }
54 case QChartSeries::SeriesTypeBar: {
54 case QChartSeries::SeriesTypeBar: {
55
55
56 BarChartSeries* barSeries = static_cast<BarChartSeries*>(series);
56 BarChartSeries* barSeries = static_cast<BarChartSeries*>(series);
57 qreal x = barSeries->countColumns();
57 qreal x = barSeries->countValues();
58 qreal y = barSeries->max();
58 qreal y = barSeries->max();
59 domain.m_minX = qMin(domain.m_minX,x);
59 domain.m_minX = qMin(domain.m_minX,x);
60 domain.m_minY = qMin(domain.m_minY,y);
60 domain.m_minY = qMin(domain.m_minY,y);
61 domain.m_maxX = qMax(domain.m_maxX,x);
61 domain.m_maxX = qMax(domain.m_maxX,x);
62 domain.m_maxY = qMax(domain.m_maxY,y);
62 domain.m_maxY = qMax(domain.m_maxY,y);
63
63 }
64 }
64 break;
65 break;
65 case QChartSeries::SeriesTypeStackedBar: {
66 case QChartSeries::SeriesTypeStackedBar: {
66
67
67 StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series);
68 StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series);
69 /*
68 qreal x = stackedBarSeries->countColumns();
70 qreal x = stackedBarSeries->countColumns();
69 qreal y = stackedBarSeries->maxColumnSum();
71 qreal y = stackedBarSeries->maxColumnSum();
70 domain.m_minX = qMin(domain.m_minX,x);
72 domain.m_minX = qMin(domain.m_minX,x);
71 domain.m_minY = qMin(domain.m_minY,y);
73 domain.m_minY = qMin(domain.m_minY,y);
72 domain.m_maxX = qMax(domain.m_maxX,x);
74 domain.m_maxX = qMax(domain.m_maxX,x);
73 domain.m_maxY = qMax(domain.m_maxY,y);
75 domain.m_maxY = qMax(domain.m_maxY,y);
76 */
74 }
77 }
75 break;
78 break;
76 case QChartSeries::SeriesTypePercentBar: {
79 case QChartSeries::SeriesTypePercentBar: {
77
80
78 PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series);
81 PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series);
82 /*
79 qreal x = percentBarSeries->countColumns();
83 qreal x = percentBarSeries->countColumns();
80 domain.m_minX = qMin(domain.m_minX,x);
84 domain.m_minX = qMin(domain.m_minX,x);
81 domain.m_minY = 0;
85 domain.m_minY = 0;
82 domain.m_maxX = qMax(domain.m_maxX,x);
86 domain.m_maxX = qMax(domain.m_maxX,x);
83 domain.m_maxY = 100;
87 domain.m_maxY = 100;
88 */
84 }
89 }
85 break;
90 break;
86
91
87 case QChartSeries::SeriesTypePie: {
92 case QChartSeries::SeriesTypePie: {
88 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
93 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
89 // TODO: domain stuff
94 // TODO: domain stuff
90 break;
95 break;
91 }
96 }
92
97
93 case QChartSeries::SeriesTypeScatter: {
98 case QChartSeries::SeriesTypeScatter: {
94 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
99 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
95 Q_ASSERT(scatterSeries);
100 Q_ASSERT(scatterSeries);
96 foreach (QPointF point, scatterSeries->data()) {
101 foreach (QPointF point, scatterSeries->data()) {
97 domain.m_minX = qMin(domain.m_minX, point.x());
102 domain.m_minX = qMin(domain.m_minX, point.x());
98 domain.m_maxX = qMax(domain.m_maxX, point.x());
103 domain.m_maxX = qMax(domain.m_maxX, point.x());
99 domain.m_minY = qMin(domain.m_minY, point.y());
104 domain.m_minY = qMin(domain.m_minY, point.y());
100 domain.m_maxY = qMax(domain.m_maxY, point.y());
105 domain.m_maxY = qMax(domain.m_maxY, point.y());
101 }
106 }
102 break;
107 break;
103 }
108 }
104
109
105 default: {
110 default: {
106 qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported";
111 qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported";
107 return;
112 return;
108 break;
113 break;
109 }
114 }
110
115
111 }
116 }
112
117
113 emit seriesAdded(series);
118 emit seriesAdded(series);
114 emit domainChanged(domain);
119 emit domainChanged(domain);
115 }
120 }
116
121
117 bool ChartDataSet::nextDomain()
122 bool ChartDataSet::nextDomain()
118 {
123 {
119 if (m_domainIndex < m_domains.count() - 1) {
124 if (m_domainIndex < m_domains.count() - 1) {
120 m_domainIndex++;
125 m_domainIndex++;
121 emit domainChanged(m_domains[m_domainIndex]);
126 emit domainChanged(m_domains[m_domainIndex]);
122 return true;
127 return true;
123 }
128 }
124 else {
129 else {
125 return false;
130 return false;
126 }
131 }
127 }
132 }
128
133
129 bool ChartDataSet::previousDomain()
134 bool ChartDataSet::previousDomain()
130 {
135 {
131 if (m_domainIndex > 0) {
136 if (m_domainIndex > 0) {
132 m_domainIndex--;
137 m_domainIndex--;
133 emit domainChanged(m_domains[m_domainIndex]);
138 emit domainChanged(m_domains[m_domainIndex]);
134 return true;
139 return true;
135 }
140 }
136 else {
141 else {
137 return false;
142 return false;
138 }
143 }
139 }
144 }
140
145
141 void ChartDataSet::clearDomains()
146 void ChartDataSet::clearDomains()
142 {
147 {
143 if (m_domainIndex > 0) {
148 if (m_domainIndex > 0) {
144 m_domainIndex = 0;
149 m_domainIndex = 0;
145 emit domainChanged(m_domains[m_domainIndex]);
150 emit domainChanged(m_domains[m_domainIndex]);
146 }
151 }
147 }
152 }
148
153
149 void ChartDataSet::addDomain(const Domain& domain)
154 void ChartDataSet::addDomain(const Domain& domain)
150 {
155 {
151 m_domains.resize(m_domainIndex + 1);
156 m_domains.resize(m_domainIndex + 1);
152 m_domains << domain;
157 m_domains << domain;
153 m_domainIndex++;
158 m_domainIndex++;
154
159
155 emit domainChanged(domain);
160 emit domainChanged(domain);
156 }
161 }
157
162
158 #include "moc_chartdataset_p.cpp"
163 #include "moc_chartdataset_p.cpp"
159
164
160 QTCOMMERCIALCHART_END_NAMESPACE
165 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now