@@ -1,54 +1,54 | |||||
1 | #include "qchartaxiscategories.h" |
|
1 | #include "qchartaxiscategories.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | QChartAxisCategories::QChartAxisCategories() |
|
5 | QChartAxisCategories::QChartAxisCategories() | |
6 | { |
|
6 | { | |
7 | // TODO Auto-generated constructor stub |
|
7 | // TODO Auto-generated constructor stub | |
8 |
|
8 | |||
9 | } |
|
9 | } | |
10 |
|
10 | |||
11 | QChartAxisCategories::~QChartAxisCategories() |
|
11 | QChartAxisCategories::~QChartAxisCategories() | |
12 | { |
|
12 | { | |
13 | // TODO Auto-generated destructor stub |
|
13 | // TODO Auto-generated destructor stub | |
14 | } |
|
14 | } | |
15 |
|
15 | |||
16 |
void QChartAxisCategories::insert(QBarCategor |
|
16 | void QChartAxisCategories::insert(const QBarCategories& categories) | |
17 | { |
|
17 | { | |
18 | int i=1; |
|
18 | int i=1; | |
19 |
foreach(QString string , categor |
|
19 | foreach(QString string , categories){ | |
20 | m_map.insert(i,string); |
|
20 | m_map.insert(i,string); | |
21 | i++; |
|
21 | i++; | |
22 | } |
|
22 | } | |
23 | emit updated(); |
|
23 | emit updated(); | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | void QChartAxisCategories::insert(qreal value,QString label) |
|
26 | void QChartAxisCategories::insert(qreal value,QString label) | |
27 | { |
|
27 | { | |
28 | m_map.insert(value,label); |
|
28 | m_map.insert(value,label); | |
29 | emit updated(); |
|
29 | emit updated(); | |
30 | } |
|
30 | } | |
31 | void QChartAxisCategories::remove(qreal value) |
|
31 | void QChartAxisCategories::remove(qreal value) | |
32 | { |
|
32 | { | |
33 | m_map.remove(value); |
|
33 | m_map.remove(value); | |
34 | emit updated(); |
|
34 | emit updated(); | |
35 | } |
|
35 | } | |
36 | void QChartAxisCategories::clear() |
|
36 | void QChartAxisCategories::clear() | |
37 | { |
|
37 | { | |
38 | m_map.clear(); |
|
38 | m_map.clear(); | |
39 | emit updated(); |
|
39 | emit updated(); | |
40 | } |
|
40 | } | |
41 | int QChartAxisCategories::count() |
|
41 | int QChartAxisCategories::count() | |
42 | { |
|
42 | { | |
43 | return m_map.count(); |
|
43 | return m_map.count(); | |
44 | emit updated(); |
|
44 | emit updated(); | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | QString QChartAxisCategories::label(qreal value) const |
|
47 | QString QChartAxisCategories::label(qreal value) const | |
48 | { |
|
48 | { | |
49 | return m_map.value(value); |
|
49 | return m_map.value(value); | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | #include "moc_qchartaxiscategories.cpp" |
|
52 | #include "moc_qchartaxiscategories.cpp" | |
53 |
|
53 | |||
54 | QTCOMMERCIALCHART_END_NAMESPACE |
|
54 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,37 +1,37 | |||||
1 | #ifndef QCHARTAXISCATEGORIES_H_ |
|
1 | #ifndef QCHARTAXISCATEGORIES_H_ | |
2 | #define QCHARTAXISCATEGORIES_H_ |
|
2 | #define QCHARTAXISCATEGORIES_H_ | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <qbarseries.h> |
|
5 | #include <qbarseries.h> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | class QTCOMMERCIALCHART_EXPORT QChartAxisCategories : public QObject |
|
9 | class QTCOMMERCIALCHART_EXPORT QChartAxisCategories : public QObject | |
10 | { |
|
10 | { | |
11 | Q_OBJECT |
|
11 | Q_OBJECT | |
12 | private: |
|
12 | private: | |
13 | QChartAxisCategories(); |
|
13 | QChartAxisCategories(); | |
14 | public: |
|
14 | public: | |
15 | ~QChartAxisCategories(); |
|
15 | ~QChartAxisCategories(); | |
16 |
|
16 | |||
17 |
void insert(QBarCategor |
|
17 | void insert(const QBarCategories& category); | |
18 | void insert(qreal value,QString label); |
|
18 | void insert(qreal value,QString label); | |
19 | void remove(qreal value); |
|
19 | void remove(qreal value); | |
20 | QString label(qreal value) const; |
|
20 | QString label(qreal value) const; | |
21 | void clear(); |
|
21 | void clear(); | |
22 | int count(); |
|
22 | int count(); | |
23 |
|
23 | |||
24 | //internal signal |
|
24 | //internal signal | |
25 | signals: |
|
25 | signals: | |
26 | void updated(); |
|
26 | void updated(); | |
27 |
|
27 | |||
28 | private: |
|
28 | private: | |
29 | QMap<qreal,QString> m_map; |
|
29 | QMap<qreal,QString> m_map; | |
30 |
|
30 | |||
31 | friend class QChartAxis; |
|
31 | friend class QChartAxis; | |
32 | }; |
|
32 | }; | |
33 |
|
33 | |||
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_END_NAMESPACE |
|
35 | QTCOMMERCIALCHART_END_NAMESPACE | |
36 |
|
36 | |||
37 | #endif /* QCHARTAXISCATEGORIES_H_ */ |
|
37 | #endif /* QCHARTAXISCATEGORIES_H_ */ |
@@ -1,370 +1,380 | |||||
1 | #include <QDebug> |
|
1 | #include <QDebug> | |
2 | #include "qbarseries.h" |
|
2 | #include "qbarseries.h" | |
3 | #include "qbarset.h" |
|
3 | #include "qbarset.h" | |
4 | #include "barchartmodel_p.h" |
|
4 | #include "barchartmodel_p.h" | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | /*! |
|
8 | /*! | |
9 | \class QBarSeries |
|
9 | \class QBarSeries | |
10 | \brief part of QtCommercial chart API. |
|
10 | \brief part of QtCommercial chart API. | |
11 |
|
11 | |||
12 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible |
|
12 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible | |
13 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined |
|
13 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined | |
14 | by QStringList. |
|
14 | by QStringList. | |
15 |
|
15 | |||
16 | \mainclass |
|
16 | \mainclass | |
17 |
|
17 | |||
18 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
18 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
19 | */ |
|
19 | */ | |
20 |
|
20 | |||
21 | /*! |
|
21 | /*! | |
22 | \fn virtual QSeriesType QBarSeries::type() const |
|
22 | \fn virtual QSeriesType QBarSeries::type() const | |
23 | \brief Returns type of series. |
|
23 | \brief Returns type of series. | |
24 | \sa QSeries, QSeriesType |
|
24 | \sa QSeries, QSeriesType | |
25 | */ |
|
25 | */ | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) |
|
28 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) | |
29 | \brief \internal \a pos \a tip |
|
29 | \brief \internal \a pos \a tip | |
30 | */ |
|
30 | */ | |
31 |
|
31 | |||
32 | /*! |
|
32 | /*! | |
33 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. |
|
33 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. | |
34 | QBarSeries is QObject which is a child of a \a parent. |
|
34 | QBarSeries is QObject which is a child of a \a parent. | |
35 | */ |
|
35 | */ | |
36 |
QBarSeries::QBarSeries(Q |
|
36 | QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) | |
37 | : QSeries(parent) |
|
37 | : QSeries(parent) | |
38 | ,mModel(new BarChartModel(categories, this)) |
|
38 | ,mModel(new BarChartModel(categories, this)) | |
39 | { |
|
39 | { | |
40 | m_model = NULL; |
|
40 | m_model = NULL; | |
41 | m_mapCategories = -1; |
|
41 | m_mapCategories = -1; | |
42 | m_mapBarBottom = -1; |
|
42 | m_mapBarBottom = -1; | |
43 | m_mapBarTop = -1; |
|
43 | m_mapBarTop = -1; | |
44 | m_mapOrientation = Qt::Vertical; |
|
44 | m_mapOrientation = Qt::Vertical; | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | /*! |
|
47 | /*! | |
48 | Adds a set of bars to series. Takes ownership of \a set. |
|
48 | Adds a set of bars to series. Takes ownership of \a set. | |
49 | Connects the clicked(QString) and rightClicked(QString) signals |
|
49 | Connects the clicked(QString) and rightClicked(QString) signals | |
50 | of \a set to this series |
|
50 | of \a set to this series | |
51 | */ |
|
51 | */ | |
52 | void QBarSeries::addBarSet(QBarSet *set) |
|
52 | void QBarSeries::addBarSet(QBarSet *set) | |
53 | { |
|
53 | { | |
54 | mModel->addBarSet(set); |
|
54 | mModel->addBarSet(set); | |
55 | connect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); |
|
55 | connect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); | |
56 | connect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); |
|
56 | connect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); | |
57 | connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); |
|
57 | connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); | |
58 | emit updatedBars(); |
|
58 | emit updatedBars(); | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | /*! |
|
61 | /*! | |
62 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. |
|
62 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. | |
63 | Disconnects the clicked(QString) and rightClicked(QString) signals |
|
63 | Disconnects the clicked(QString) and rightClicked(QString) signals | |
64 | of \a set from this series |
|
64 | of \a set from this series | |
65 | */ |
|
65 | */ | |
66 | void QBarSeries::removeBarSet(QBarSet *set) |
|
66 | void QBarSeries::removeBarSet(QBarSet *set) | |
67 | { |
|
67 | { | |
68 | disconnect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); |
|
68 | disconnect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); | |
69 | disconnect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); |
|
69 | disconnect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); | |
70 | mModel->removeBarSet(set); |
|
70 | mModel->removeBarSet(set); | |
71 | emit updatedBars(); |
|
71 | emit updatedBars(); | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | void QBarSeries::insertBarSet(int i, QBarSet *set) |
|
74 | void QBarSeries::insertBarSet(int i, QBarSet *set) | |
75 | { |
|
75 | { | |
76 | mModel->insertBarSet(i, set); |
|
76 | mModel->insertBarSet(i, set); | |
77 | // emit barsetChanged(); |
|
77 | // emit barsetChanged(); | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | void QBarSeries::insertCategory(int i, QString category) |
|
80 | void QBarSeries::insertCategory(int i, QString category) | |
81 | { |
|
81 | { | |
82 | mModel->insertCategory(i, category); |
|
82 | mModel->insertCategory(i, category); | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | void QBarSeries::removeCategory(int i) |
|
85 | void QBarSeries::removeCategory(int i) | |
86 | { |
|
86 | { | |
87 | mModel->removeCategory(i); |
|
87 | mModel->removeCategory(i); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | /*! |
|
90 | /*! | |
91 | Returns number of sets in series. |
|
91 | Returns number of sets in series. | |
92 | */ |
|
92 | */ | |
93 | int QBarSeries::barsetCount() |
|
93 | int QBarSeries::barsetCount() | |
94 | { |
|
94 | { | |
95 | // if(m_model) |
|
95 | // if(m_model) | |
96 | // return m_mapBarTop - m_mapBarBottom; |
|
96 | // return m_mapBarTop - m_mapBarBottom; | |
97 | // else |
|
97 | // else | |
98 | return mModel->barsetCount(); |
|
98 | return mModel->barsetCount(); | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | /*! |
|
101 | /*! | |
102 | Returns number of categories in series |
|
102 | Returns number of categories in series | |
103 | */ |
|
103 | */ | |
104 | int QBarSeries::categoryCount() |
|
104 | int QBarSeries::categoryCount() | |
105 | { |
|
105 | { | |
106 | return mModel->categoryCount(); |
|
106 | return mModel->categoryCount(); | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | /*! |
|
109 | /*! | |
110 | Returns a list of sets in series. Keeps ownership of sets. |
|
110 | Returns a list of sets in series. Keeps ownership of sets. | |
111 | */ |
|
111 | */ | |
112 | QList<QBarSet*> QBarSeries::barSets() |
|
112 | QList<QBarSet*> QBarSeries::barSets() | |
113 | { |
|
113 | { | |
114 | return mModel->barSets(); |
|
114 | return mModel->barSets(); | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | /*! |
|
117 | /*! | |
118 | \internal \a index |
|
118 | \internal \a index | |
119 | */ |
|
119 | */ | |
120 | QBarSet* QBarSeries::barsetAt(int index) |
|
120 | QBarSet* QBarSeries::barsetAt(int index) | |
121 | { |
|
121 | { | |
122 | return mModel->setAt(index); |
|
122 | return mModel->setAt(index); | |
123 | } |
|
123 | } | |
124 |
|
124 | |||
125 | /*! |
|
125 | /*! | |
126 | \internal \a category |
|
126 | \internal \a category | |
127 | */ |
|
127 | */ | |
128 | QString QBarSeries::categoryName(int category) |
|
128 | QString QBarSeries::categoryName(int category) | |
129 | { |
|
129 | { | |
130 | return mModel->categoryName(category); |
|
130 | return mModel->categoryName(category); | |
131 | } |
|
131 | } | |
132 |
|
132 | |||
133 | /*! |
|
133 | /*! | |
134 | Enables or disables tooltip depending on parameter \a enabled. |
|
134 | Enables or disables tooltip depending on parameter \a enabled. | |
135 | Tooltip shows the name of set, when mouse is hovering on top of bar. |
|
135 | Tooltip shows the name of set, when mouse is hovering on top of bar. | |
136 | Calling without parameter \a enabled, enables the tooltip |
|
136 | Calling without parameter \a enabled, enables the tooltip | |
137 | */ |
|
137 | */ | |
138 | void QBarSeries::setToolTipEnabled(bool enabled) |
|
138 | void QBarSeries::setToolTipEnabled(bool enabled) | |
139 | { |
|
139 | { | |
140 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. |
|
140 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. | |
141 | if (enabled) { |
|
141 | if (enabled) { | |
142 | for (int i=0; i<mModel->barsetCount(); i++) { |
|
142 | for (int i=0; i<mModel->barsetCount(); i++) { | |
143 | QBarSet *set = mModel->setAt(i); |
|
143 | QBarSet *set = mModel->setAt(i); | |
144 | connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); |
|
144 | connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); | |
145 | } |
|
145 | } | |
146 | } else { |
|
146 | } else { | |
147 | for (int i=0; i<mModel->barsetCount(); i++) { |
|
147 | for (int i=0; i<mModel->barsetCount(); i++) { | |
148 | QBarSet *set = mModel->setAt(i); |
|
148 | QBarSet *set = mModel->setAt(i); | |
149 | disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); |
|
149 | disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); | |
150 | } |
|
150 | } | |
151 | } |
|
151 | } | |
152 | } |
|
152 | } | |
153 |
|
153 | |||
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | \internal \a category |
|
156 | \internal \a category | |
157 | */ |
|
157 | */ | |
158 | void QBarSeries::barsetClicked(QString category) |
|
158 | void QBarSeries::barsetClicked(QString category) | |
159 | { |
|
159 | { | |
160 | emit clicked(qobject_cast<QBarSet*>(sender()), category); |
|
160 | emit clicked(qobject_cast<QBarSet*>(sender()), category); | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | /*! |
|
163 | /*! | |
164 | \internal \a category |
|
164 | \internal \a category | |
165 | */ |
|
165 | */ | |
166 | void QBarSeries::barsetRightClicked(QString category) |
|
166 | void QBarSeries::barsetRightClicked(QString category) | |
167 | { |
|
167 | { | |
168 | emit rightClicked(qobject_cast<QBarSet*>(sender()), category); |
|
168 | emit rightClicked(qobject_cast<QBarSet*>(sender()), category); | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 |
|
171 | |||
172 | /*! |
|
172 | /*! | |
173 | \internal |
|
173 | \internal | |
174 | */ |
|
174 | */ | |
175 | qreal QBarSeries::min() |
|
175 | qreal QBarSeries::min() | |
176 | { |
|
176 | { | |
177 | return mModel->min(); |
|
177 | return mModel->min(); | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 | /*! |
|
180 | /*! | |
181 | \internal |
|
181 | \internal | |
182 | */ |
|
182 | */ | |
183 | qreal QBarSeries::max() |
|
183 | qreal QBarSeries::max() | |
184 | { |
|
184 | { | |
185 | return mModel->max(); |
|
185 | return mModel->max(); | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | /*! |
|
188 | /*! | |
189 | \internal \a set \a category |
|
189 | \internal \a set \a category | |
190 | */ |
|
190 | */ | |
191 | qreal QBarSeries::valueAt(int set, int category) |
|
191 | qreal QBarSeries::valueAt(int set, int category) | |
192 | { |
|
192 | { | |
193 | return mModel->valueAt(set,category); |
|
193 | return mModel->valueAt(set,category); | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | /*! |
|
196 | /*! | |
197 | \internal \a set \a category |
|
197 | \internal \a set \a category | |
198 | */ |
|
198 | */ | |
199 | qreal QBarSeries::percentageAt(int set, int category) |
|
199 | qreal QBarSeries::percentageAt(int set, int category) | |
200 | { |
|
200 | { | |
201 | return mModel->percentageAt(set,category); |
|
201 | return mModel->percentageAt(set,category); | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | /*! |
|
204 | /*! | |
205 | \internal \a category |
|
205 | \internal \a category | |
206 | */ |
|
206 | */ | |
207 | qreal QBarSeries::categorySum(int category) |
|
207 | qreal QBarSeries::categorySum(int category) | |
208 | { |
|
208 | { | |
209 | return mModel->categorySum(category); |
|
209 | return mModel->categorySum(category); | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | /*! |
|
212 | /*! | |
213 | \internal |
|
213 | \internal | |
214 | */ |
|
214 | */ | |
215 | qreal QBarSeries::maxCategorySum() |
|
215 | qreal QBarSeries::maxCategorySum() | |
216 | { |
|
216 | { | |
217 | return mModel->maxCategorySum(); |
|
217 | return mModel->maxCategorySum(); | |
218 | } |
|
218 | } | |
219 |
|
219 | |||
220 | /*! |
|
220 | /*! | |
221 | \internal |
|
221 | \internal | |
222 | */ |
|
222 | */ | |
223 | BarChartModel& QBarSeries::model() |
|
223 | BarChartModel& QBarSeries::model() | |
224 | { |
|
224 | { | |
225 | return *mModel; |
|
225 | return *mModel; | |
226 | } |
|
226 | } | |
227 |
|
227 | |||
228 | bool QBarSeries::setModel(QAbstractItemModel* model) |
|
228 | bool QBarSeries::setModel(QAbstractItemModel* model) | |
229 | { |
|
229 | { | |
230 | // disconnect signals from old model |
|
230 | // disconnect signals from old model | |
231 | if(m_model) |
|
231 | if(m_model) | |
232 | { |
|
232 | { | |
233 | disconnect(m_model, 0, this, 0); |
|
233 | disconnect(m_model, 0, this, 0); | |
234 | m_mapCategories = -1; |
|
234 | m_mapCategories = -1; | |
235 | m_mapBarBottom = -1; |
|
235 | m_mapBarBottom = -1; | |
236 | m_mapBarTop = -1; |
|
236 | m_mapBarTop = -1; | |
237 | m_mapOrientation = Qt::Vertical; |
|
237 | m_mapOrientation = Qt::Vertical; | |
238 | } |
|
238 | } | |
239 |
|
239 | |||
240 | // set new model |
|
240 | // set new model | |
241 | if(model) |
|
241 | if(model) | |
242 | { |
|
242 | { | |
243 | m_model = model; |
|
243 | m_model = model; | |
244 | return true; |
|
244 | return true; | |
245 | } |
|
245 | } | |
246 | else |
|
246 | else | |
247 | { |
|
247 | { | |
248 | m_model = NULL; |
|
248 | m_model = NULL; | |
249 | return false; |
|
249 | return false; | |
250 | } |
|
250 | } | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | // TODO |
|
253 | // TODO | |
254 | void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) |
|
254 | void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |
255 | { |
|
255 | { | |
256 | if (m_model == NULL) |
|
256 | if (m_model == NULL) | |
257 | return; |
|
257 | return; | |
258 | m_mapCategories = categories; |
|
258 | m_mapCategories = categories; | |
259 | m_mapBarBottom = bottomBoundry; |
|
259 | m_mapBarBottom = bottomBoundry; | |
260 | m_mapBarTop = topBoundry; |
|
260 | m_mapBarTop = topBoundry; | |
261 | m_mapOrientation = orientation; |
|
261 | m_mapOrientation = orientation; | |
262 |
|
262 | |||
263 | // connect the signals |
|
263 | // connect the signals | |
264 | if (m_mapOrientation == Qt::Vertical) |
|
264 | if (m_mapOrientation == Qt::Vertical) | |
265 | { |
|
265 | { | |
266 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
266 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
267 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
267 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
268 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
268 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
269 | } |
|
269 | } | |
270 | else |
|
270 | else | |
271 | { |
|
271 | { | |
272 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
272 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
273 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
273 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
274 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
274 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
275 | } |
|
275 | } | |
276 |
|
276 | |||
277 |
|
277 | |||
278 | // create the initial bars |
|
278 | // create the initial bars | |
279 | delete mModel; |
|
279 | delete mModel; | |
280 | if (m_mapOrientation == Qt::Vertical) |
|
280 | if (m_mapOrientation == Qt::Vertical) | |
281 | { |
|
281 | { | |
282 | QStringList categories; |
|
282 | QStringList categories; | |
283 | for (int k = 0; k < m_model->rowCount(); k++) |
|
283 | for (int k = 0; k < m_model->rowCount(); k++) | |
284 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); |
|
284 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); | |
285 | mModel = new BarChartModel(categories, this); |
|
285 | mModel = new BarChartModel(categories, this); | |
286 |
|
286 | |||
287 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) |
|
287 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) | |
288 | { |
|
288 | { | |
289 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); |
|
289 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); | |
290 | for(int m = 0; m < m_model->rowCount(); m++) |
|
290 | for(int m = 0; m < m_model->rowCount(); m++) | |
291 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); |
|
291 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
292 | addBarSet(barSet); |
|
292 | addBarSet(barSet); | |
293 | } |
|
293 | } | |
294 | } |
|
294 | } | |
295 | else |
|
295 | else | |
296 | { |
|
296 | { | |
297 | QStringList categories; |
|
297 | QStringList categories; | |
298 | for (int k = 0; k < m_model->columnCount(); k++) |
|
298 | for (int k = 0; k < m_model->columnCount(); k++) | |
299 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); |
|
299 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |
300 | mModel = new BarChartModel(categories, this); |
|
300 | mModel = new BarChartModel(categories, this); | |
301 |
|
301 | |||
302 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) |
|
302 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) | |
303 | { |
|
303 | { | |
304 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); |
|
304 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); | |
305 | for(int m = 0; m < m_model->columnCount(); m++) |
|
305 | for(int m = 0; m < m_model->columnCount(); m++) | |
306 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); |
|
306 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
307 | addBarSet(barSet); |
|
307 | addBarSet(barSet); | |
308 | } |
|
308 | } | |
309 | } |
|
309 | } | |
310 | } |
|
310 | } | |
311 |
|
311 | |||
312 | void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
312 | void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
313 | { |
|
313 | { | |
314 | Q_UNUSED(bottomRight) |
|
314 | Q_UNUSED(bottomRight) | |
315 |
|
315 | |||
316 | if (m_mapOrientation == Qt::Vertical) |
|
316 | if (m_mapOrientation == Qt::Vertical) | |
317 | { |
|
317 | { | |
318 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop) |
|
318 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop) | |
319 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
319 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
320 | // else if (topLeft.column() == m_mapCategories) |
|
320 | // else if (topLeft.column() == m_mapCategories) | |
321 | // slices().at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
321 | // slices().at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
322 | } |
|
322 | } | |
323 | else |
|
323 | else | |
324 | { |
|
324 | { | |
325 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop) |
|
325 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop) | |
326 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
326 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
327 | // else if (topLeft.row() == m_mapCategories) |
|
327 | // else if (topLeft.row() == m_mapCategories) | |
328 | // slices().at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
328 | // slices().at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
329 | } |
|
329 | } | |
330 | } |
|
330 | } | |
331 |
|
331 | |||
332 | void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) |
|
332 | void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) | |
333 | { |
|
333 | { | |
334 | if (m_mapOrientation == Qt::Vertical) |
|
334 | if (m_mapOrientation == Qt::Vertical) | |
335 | { |
|
335 | { | |
336 | insertCategory(start, QString("Row: %1").arg(start + 1)); |
|
336 | insertCategory(start, QString("Row: %1").arg(start + 1)); | |
337 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) |
|
337 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |
338 | { |
|
338 | { | |
339 | barsetAt(i)->insertValue(start, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); |
|
339 | barsetAt(i)->insertValue(start, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); | |
340 | } |
|
340 | } | |
341 | } |
|
341 | } | |
342 | else |
|
342 | else | |
343 | { |
|
343 | { | |
344 | insertCategory(start, QString("Column: %1").arg(start + 1)); |
|
344 | insertCategory(start, QString("Column: %1").arg(start + 1)); | |
345 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) |
|
345 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |
346 | { |
|
346 | { | |
347 | barsetAt(i)->insertValue(start, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); |
|
347 | barsetAt(i)->insertValue(start, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); | |
348 | } |
|
348 | } | |
349 | } |
|
349 | } | |
350 | emit restructuredBar(1); |
|
350 | emit restructuredBar(1); | |
351 | } |
|
351 | } | |
352 |
|
352 | |||
353 | void QBarSeries::modelDataRemoved(QModelIndex /*parent*/, int start, int /*end*/) |
|
353 | void QBarSeries::modelDataRemoved(QModelIndex /*parent*/, int start, int /*end*/) | |
354 | { |
|
354 | { | |
355 | removeCategory(start); |
|
355 | removeCategory(start); | |
356 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) |
|
356 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |
357 | { |
|
357 | { | |
358 | barsetAt(i)->removeValue(start); |
|
358 | barsetAt(i)->removeValue(start); | |
359 | } |
|
359 | } | |
360 | emit restructuredBar(1); |
|
360 | emit restructuredBar(1); | |
361 | } |
|
361 | } | |
362 |
|
362 | |||
363 | void QBarSeries::barsetChanged() |
|
363 | void QBarSeries::barsetChanged() | |
364 | { |
|
364 | { | |
365 | emit updatedBars(); |
|
365 | emit updatedBars(); | |
366 | } |
|
366 | } | |
367 |
|
367 | |||
|
368 | QBarCategories QBarSeries::categories() const | |||
|
369 | { | |||
|
370 | QBarCategories categories; | |||
|
371 | int count = mModel->categoryCount(); | |||
|
372 | for (int i=1; i<=count; i++) { | |||
|
373 | categories.insert(i, mModel->categoryName(i-1)); | |||
|
374 | } | |||
|
375 | return categories; | |||
|
376 | } | |||
|
377 | ||||
368 | #include "moc_qbarseries.cpp" |
|
378 | #include "moc_qbarseries.cpp" | |
369 |
|
379 | |||
370 | QTCOMMERCIALCHART_END_NAMESPACE |
|
380 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,93 +1,95 | |||||
1 | #ifndef BARSERIES_H |
|
1 | #ifndef BARSERIES_H | |
2 | #define BARSERIES_H |
|
2 | #define BARSERIES_H | |
3 |
|
3 | |||
4 | #include <qseries.h> |
|
4 | #include <qseries.h> | |
5 | #include <QStringList> |
|
5 | #include <QStringList> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 |
typedef QStringList QBarCategor |
|
9 | typedef QStringList QBarCategories; | |
10 |
|
10 | |||
11 | class QBarSet; |
|
11 | class QBarSet; | |
12 | class BarChartModel; |
|
12 | class BarChartModel; | |
13 | class BarCategory; |
|
13 | class BarCategory; | |
14 |
|
14 | |||
15 | // Container for series |
|
15 | // Container for series | |
16 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries |
|
16 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries | |
17 | { |
|
17 | { | |
18 | Q_OBJECT |
|
18 | Q_OBJECT | |
19 | public: |
|
19 | public: | |
20 | QBarSeries(QStringList categories, QObject* parent=0); |
|
20 | QBarSeries(QStringList categories, QObject* parent=0); | |
21 |
|
21 | |||
22 | virtual QSeriesType type() const { return QSeries::SeriesTypeBar; } |
|
22 | virtual QSeriesType type() const { return QSeries::SeriesTypeBar; } | |
23 |
|
23 | |||
24 | void addBarSet(QBarSet *set); // Takes ownership of set |
|
24 | void addBarSet(QBarSet *set); // Takes ownership of set | |
25 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set |
|
25 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set | |
26 | void insertBarSet(int i, QBarSet *set); |
|
26 | void insertBarSet(int i, QBarSet *set); | |
27 | void insertCategory(int i, QString category); |
|
27 | void insertCategory(int i, QString category); | |
28 | void removeCategory(int i); |
|
28 | void removeCategory(int i); | |
29 | int barsetCount(); |
|
29 | int barsetCount(); | |
30 | int categoryCount(); |
|
30 | int categoryCount(); | |
31 | QList<QBarSet*> barSets(); |
|
31 | QList<QBarSet*> barSets(); | |
|
32 | QBarCategories categories() const; | |||
|
33 | ||||
32 |
|
34 | |||
33 | bool setModel(QAbstractItemModel* model); |
|
35 | bool setModel(QAbstractItemModel* model); | |
34 | QAbstractItemModel* modelExt() {return m_model;} |
|
36 | QAbstractItemModel* modelExt() {return m_model;} | |
35 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); |
|
37 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); | |
36 |
|
38 | |||
37 | public: |
|
39 | public: | |
38 | // TODO: Functions below this are not part of api and will be moved |
|
40 | // TODO: Functions below this are not part of api and will be moved | |
39 | // to private implementation, when we start using it |
|
41 | // to private implementation, when we start using it | |
40 | // TODO: TO PIMPL ---> |
|
42 | // TODO: TO PIMPL ---> | |
41 | QBarSet* barsetAt(int index); |
|
43 | QBarSet* barsetAt(int index); | |
42 | QString categoryName(int category); |
|
44 | QString categoryName(int category); | |
43 | qreal min(); |
|
45 | qreal min(); | |
44 | qreal max(); |
|
46 | qreal max(); | |
45 | qreal valueAt(int set, int category); |
|
47 | qreal valueAt(int set, int category); | |
46 | qreal percentageAt(int set, int category); |
|
48 | qreal percentageAt(int set, int category); | |
47 | qreal categorySum(int category); |
|
49 | qreal categorySum(int category); | |
48 | qreal maxCategorySum(); |
|
50 | qreal maxCategorySum(); | |
49 | BarChartModel& model(); |
|
51 | BarChartModel& model(); | |
50 | // <--- TO PIMPL |
|
52 | // <--- TO PIMPL | |
51 |
|
53 | |||
52 | signals: |
|
54 | signals: | |
53 | //void changed(int index); |
|
55 | //void changed(int index); | |
54 | void clicked(QBarSet* barset, QString category); // Up to user of api, what to do with these signals |
|
56 | void clicked(QBarSet* barset, QString category); // Up to user of api, what to do with these signals | |
55 | void rightClicked(QBarSet* barset, QString category); |
|
57 | void rightClicked(QBarSet* barset, QString category); | |
56 |
|
58 | |||
57 | // |
|
59 | // | |
58 | void updatedBars(); |
|
60 | void updatedBars(); | |
59 | void restructuredBar(int); |
|
61 | void restructuredBar(int); | |
60 |
|
62 | |||
61 | // TODO: internal signals, these to private implementation. |
|
63 | // TODO: internal signals, these to private implementation. | |
62 | // TODO: TO PIMPL ---> |
|
64 | // TODO: TO PIMPL ---> | |
63 | void showToolTip(QPoint pos, QString tip); |
|
65 | void showToolTip(QPoint pos, QString tip); | |
64 | // <--- TO PIMPL |
|
66 | // <--- TO PIMPL | |
65 |
|
67 | |||
66 | public Q_SLOTS: |
|
68 | public Q_SLOTS: | |
67 | void setToolTipEnabled(bool enabled=true); // enables tooltips |
|
69 | void setToolTipEnabled(bool enabled=true); // enables tooltips | |
68 |
|
70 | |||
69 | // TODO: TO PIMPL ---> |
|
71 | // TODO: TO PIMPL ---> | |
70 | void barsetClicked(QString category); |
|
72 | void barsetClicked(QString category); | |
71 | void barsetRightClicked(QString category); |
|
73 | void barsetRightClicked(QString category); | |
72 | // <--- TO PIMPL |
|
74 | // <--- TO PIMPL | |
73 |
|
75 | |||
74 | private Q_SLOTS: |
|
76 | private Q_SLOTS: | |
75 | // slots for updating bars when data in model changes |
|
77 | // slots for updating bars when data in model changes | |
76 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
|
78 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
77 | void modelDataAdded(QModelIndex parent, int start, int end); |
|
79 | void modelDataAdded(QModelIndex parent, int start, int end); | |
78 | void modelDataRemoved(QModelIndex parent, int start, int end); |
|
80 | void modelDataRemoved(QModelIndex parent, int start, int end); | |
79 | void barsetChanged(); |
|
81 | void barsetChanged(); | |
80 |
|
82 | |||
81 | protected: |
|
83 | protected: | |
82 | BarChartModel* mModel; |
|
84 | BarChartModel* mModel; | |
83 |
|
85 | |||
84 | // QAbstractItemModel* m_model; |
|
86 | // QAbstractItemModel* m_model; | |
85 | int m_mapCategories; |
|
87 | int m_mapCategories; | |
86 | int m_mapBarBottom; |
|
88 | int m_mapBarBottom; | |
87 | int m_mapBarTop; |
|
89 | int m_mapBarTop; | |
88 | Qt::Orientation m_mapOrientation; |
|
90 | Qt::Orientation m_mapOrientation; | |
89 | }; |
|
91 | }; | |
90 |
|
92 | |||
91 | QTCOMMERCIALCHART_END_NAMESPACE |
|
93 | QTCOMMERCIALCHART_END_NAMESPACE | |
92 |
|
94 | |||
93 | #endif // BARSERIES_H |
|
95 | #endif // BARSERIES_H |
@@ -1,334 +1,331 | |||||
1 | #include "chartdataset_p.h" |
|
1 | #include "chartdataset_p.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | //series |
|
3 | //series | |
4 | #include "qlineseries.h" |
|
4 | #include "qlineseries.h" | |
5 | #include "qareaseries.h" |
|
5 | #include "qareaseries.h" | |
6 | #include "qbarseries.h" |
|
6 | #include "qbarseries.h" | |
7 | #include "qstackedbarseries.h" |
|
7 | #include "qstackedbarseries.h" | |
8 | #include "qpercentbarseries.h" |
|
8 | #include "qpercentbarseries.h" | |
9 | #include "qpieseries.h" |
|
9 | #include "qpieseries.h" | |
10 | #include "qscatterseries.h" |
|
10 | #include "qscatterseries.h" | |
11 | #include "qsplineseries.h" |
|
11 | #include "qsplineseries.h" | |
12 |
|
12 | |||
13 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
13 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
14 |
|
14 | |||
15 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), |
|
15 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), | |
16 | m_axisX(new QChartAxis(this)), |
|
16 | m_axisX(new QChartAxis(this)), | |
17 | m_axisY(new QChartAxis(this)), |
|
17 | m_axisY(new QChartAxis(this)), | |
18 | m_domainIndex(0), |
|
18 | m_domainIndex(0), | |
19 | m_axisXInitialized(false) |
|
19 | m_axisXInitialized(false) | |
20 | { |
|
20 | { | |
21 | } |
|
21 | } | |
22 |
|
22 | |||
23 | ChartDataSet::~ChartDataSet() |
|
23 | ChartDataSet::~ChartDataSet() | |
24 | { |
|
24 | { | |
25 | } |
|
25 | } | |
26 |
|
26 | |||
27 | void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) |
|
27 | void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) | |
28 | { |
|
28 | { | |
29 | if(axisY==0) axisY = m_axisY; |
|
29 | if(axisY==0) axisY = m_axisY; | |
30 |
|
30 | |||
31 | QChartAxis* axis = m_seriesAxisMap.value(series); |
|
31 | QChartAxis* axis = m_seriesAxisMap.value(series); | |
32 |
|
32 | |||
33 | if(axis) { |
|
33 | if(axis) { | |
34 | qWarning() << "Can not add series. Series already on the chart"; |
|
34 | qWarning() << "Can not add series. Series already on the chart"; | |
35 | return; |
|
35 | return; | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | if(!series->parent()){ |
|
38 | if(!series->parent()){ | |
39 | series->setParent(this); // take ownership |
|
39 | series->setParent(this); // take ownership | |
40 | }; |
|
40 | }; | |
41 |
|
41 | |||
42 | if(!axisY->parent()){ |
|
42 | if(!axisY->parent()){ | |
43 | axisY->setParent(this); // take ownership |
|
43 | axisY->setParent(this); // take ownership | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | Domain* domain = m_axisDomainMap.value(axisY); |
|
46 | Domain* domain = m_axisDomainMap.value(axisY); | |
47 |
|
47 | |||
48 | if(!domain) { |
|
48 | if(!domain) { | |
49 | domain = new Domain(); |
|
49 | domain = new Domain(); | |
50 | QObject::connect(axisY,SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); |
|
50 | QObject::connect(axisY,SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); | |
51 | QObject::connect(axisX(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); |
|
51 | QObject::connect(axisX(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); | |
52 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY,SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
52 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY,SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
53 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axisX(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
53 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axisX(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
54 | //initialize |
|
54 | //initialize | |
55 | m_axisDomainMap.insert(axisY,domain); |
|
55 | m_axisDomainMap.insert(axisY,domain); | |
56 | emit axisAdded(axisY,domain); |
|
56 | emit axisAdded(axisY,domain); | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | if(!m_axisXInitialized){ |
|
59 | if(!m_axisXInitialized){ | |
60 | emit axisAdded(axisX(),domain); |
|
60 | emit axisAdded(axisX(),domain); | |
61 | m_axisXInitialized=true; |
|
61 | m_axisXInitialized=true; | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | calculateDomain(series,domain); |
|
64 | calculateDomain(series,domain); | |
65 |
|
65 | |||
66 | m_seriesAxisMap.insert(series,axisY); |
|
66 | m_seriesAxisMap.insert(series,axisY); | |
67 | emit seriesAdded(series,domain); |
|
67 | emit seriesAdded(series,domain); | |
68 |
|
68 | |||
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | void ChartDataSet::removeSeries(QSeries* series) |
|
71 | void ChartDataSet::removeSeries(QSeries* series) | |
72 | { |
|
72 | { | |
73 |
|
73 | |||
74 | QChartAxis* axis = m_seriesAxisMap.value(series); |
|
74 | QChartAxis* axis = m_seriesAxisMap.value(series); | |
75 |
|
75 | |||
76 | if(!axis){ |
|
76 | if(!axis){ | |
77 | qWarning()<<"Can not remove series. Series not found on the chart."; |
|
77 | qWarning()<<"Can not remove series. Series not found on the chart."; | |
78 | return; |
|
78 | return; | |
79 | } |
|
79 | } | |
80 | emit seriesRemoved(series); |
|
80 | emit seriesRemoved(series); | |
81 | m_seriesAxisMap.remove(series); |
|
81 | m_seriesAxisMap.remove(series); | |
82 |
|
82 | |||
83 | if(series->parent()==this){ |
|
83 | if(series->parent()==this){ | |
84 | delete series; |
|
84 | delete series; | |
85 | series=0; |
|
85 | series=0; | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | QList<QChartAxis*> axes = m_seriesAxisMap.values(); |
|
88 | QList<QChartAxis*> axes = m_seriesAxisMap.values(); | |
89 |
|
89 | |||
90 | int i = axes.indexOf(axis); |
|
90 | int i = axes.indexOf(axis); | |
91 |
|
91 | |||
92 | if(i==-1){ |
|
92 | if(i==-1){ | |
93 | Domain* domain = m_axisDomainMap.take(axis); |
|
93 | Domain* domain = m_axisDomainMap.take(axis); | |
94 | emit axisRemoved(axis); |
|
94 | emit axisRemoved(axis); | |
95 | if(axis!=axisY()){ |
|
95 | if(axis!=axisY()){ | |
96 | if(axis->parent()==this){ |
|
96 | if(axis->parent()==this){ | |
97 | delete axis; |
|
97 | delete axis; | |
98 | axis=0; |
|
98 | axis=0; | |
99 | } |
|
99 | } | |
100 | } |
|
100 | } | |
101 | delete domain; |
|
101 | delete domain; | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | if(m_seriesAxisMap.values().size()==0) |
|
104 | if(m_seriesAxisMap.values().size()==0) | |
105 | { |
|
105 | { | |
106 | m_axisXInitialized=false; |
|
106 | m_axisXInitialized=false; | |
107 | emit axisRemoved(axisX()); |
|
107 | emit axisRemoved(axisX()); | |
108 | } |
|
108 | } | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | void ChartDataSet::removeAllSeries() |
|
111 | void ChartDataSet::removeAllSeries() | |
112 | { |
|
112 | { | |
113 |
|
113 | |||
114 | QList<QSeries*> series = m_seriesAxisMap.keys(); |
|
114 | QList<QSeries*> series = m_seriesAxisMap.keys(); | |
115 |
|
115 | |||
116 | foreach(QSeries* s , series) { |
|
116 | foreach(QSeries* s , series) { | |
117 | removeSeries(s); |
|
117 | removeSeries(s); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | Q_ASSERT(m_seriesAxisMap.count()==0); |
|
120 | Q_ASSERT(m_seriesAxisMap.count()==0); | |
121 | Q_ASSERT(m_axisDomainMap.count()==0); |
|
121 | Q_ASSERT(m_axisDomainMap.count()==0); | |
122 |
|
122 | |||
123 | } |
|
123 | } | |
124 |
|
124 | |||
125 | //to be removed with PIMPL |
|
125 | //to be removed with PIMPL | |
126 | void ChartDataSet::calculateDomain(QSeries* series,Domain* domain) |
|
126 | void ChartDataSet::calculateDomain(QSeries* series,Domain* domain) | |
127 | { |
|
127 | { | |
128 | qreal minX(domain->minX()); |
|
128 | qreal minX(domain->minX()); | |
129 | qreal minY(domain->minY()); |
|
129 | qreal minY(domain->minY()); | |
130 | qreal maxX(domain->maxX()); |
|
130 | qreal maxX(domain->maxX()); | |
131 | qreal maxY(domain->maxY()); |
|
131 | qreal maxY(domain->maxY()); | |
132 | int tickXCount(domain->tickXCount()); |
|
132 | int tickXCount(domain->tickXCount()); | |
133 | int tickYCount(domain->tickYCount()); |
|
133 | int tickYCount(domain->tickYCount()); | |
134 |
|
134 | |||
135 |
|
135 | |||
136 | switch(series->type()) |
|
136 | switch(series->type()) | |
137 | { |
|
137 | { | |
138 | case QSeries::SeriesTypeLine: |
|
138 | case QSeries::SeriesTypeLine: | |
139 | case QSeries::SeriesTypeSpline: |
|
139 | case QSeries::SeriesTypeSpline: | |
140 | case QSeries::SeriesTypeScatter: |
|
140 | case QSeries::SeriesTypeScatter: | |
141 | { |
|
141 | { | |
142 |
|
142 | |||
143 | QXYSeries* xySeries = static_cast<QXYSeries*>(series); |
|
143 | QXYSeries* xySeries = static_cast<QXYSeries*>(series); | |
144 |
|
144 | |||
145 | for (int i = 0; i < xySeries->count(); i++) |
|
145 | for (int i = 0; i < xySeries->count(); i++) | |
146 | { |
|
146 | { | |
147 | qreal x = xySeries->x(i); |
|
147 | qreal x = xySeries->x(i); | |
148 | qreal y = xySeries->y(i); |
|
148 | qreal y = xySeries->y(i); | |
149 | minX = qMin(minX, x); |
|
149 | minX = qMin(minX, x); | |
150 | minY = qMin(minY, y); |
|
150 | minY = qMin(minY, y); | |
151 | maxX = qMax(maxX, x); |
|
151 | maxX = qMax(maxX, x); | |
152 | maxY = qMax(maxY, y); |
|
152 | maxY = qMax(maxY, y); | |
153 | } |
|
153 | } | |
154 | break; |
|
154 | break; | |
155 | } |
|
155 | } | |
156 | case QSeries::SeriesTypeArea: { |
|
156 | case QSeries::SeriesTypeArea: { | |
157 |
|
157 | |||
158 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); |
|
158 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); | |
159 | QLineSeries* upperSeries = areaSeries->upperSeries(); |
|
159 | QLineSeries* upperSeries = areaSeries->upperSeries(); | |
160 | QLineSeries* lowerSeries = areaSeries->lowerSeries(); |
|
160 | QLineSeries* lowerSeries = areaSeries->lowerSeries(); | |
161 |
|
161 | |||
162 | for (int i = 0; i < upperSeries->count(); i++) |
|
162 | for (int i = 0; i < upperSeries->count(); i++) | |
163 | { |
|
163 | { | |
164 | qreal x = upperSeries->x(i); |
|
164 | qreal x = upperSeries->x(i); | |
165 | qreal y = upperSeries->y(i); |
|
165 | qreal y = upperSeries->y(i); | |
166 | minX = qMin(minX, x); |
|
166 | minX = qMin(minX, x); | |
167 | minY = qMin(minY, y); |
|
167 | minY = qMin(minY, y); | |
168 | maxX = qMax(maxX, x); |
|
168 | maxX = qMax(maxX, x); | |
169 | maxY = qMax(maxY, y); |
|
169 | maxY = qMax(maxY, y); | |
170 | } |
|
170 | } | |
171 | if(lowerSeries) { |
|
171 | if(lowerSeries) { | |
172 | for (int i = 0; i < lowerSeries->count(); i++) |
|
172 | for (int i = 0; i < lowerSeries->count(); i++) | |
173 | { |
|
173 | { | |
174 | qreal x = lowerSeries->x(i); |
|
174 | qreal x = lowerSeries->x(i); | |
175 | qreal y = lowerSeries->y(i); |
|
175 | qreal y = lowerSeries->y(i); | |
176 | minX = qMin(minX, x); |
|
176 | minX = qMin(minX, x); | |
177 | minY = qMin(minY, y); |
|
177 | minY = qMin(minY, y); | |
178 | maxX = qMax(maxX, x); |
|
178 | maxX = qMax(maxX, x); | |
179 | maxY = qMax(maxY, y); |
|
179 | maxY = qMax(maxY, y); | |
180 | }} |
|
180 | }} | |
181 | break; |
|
181 | break; | |
182 | } |
|
182 | } | |
183 | case QSeries::SeriesTypeBar: { |
|
183 | case QSeries::SeriesTypeBar: { | |
184 |
|
184 | |||
185 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
185 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); | |
186 | qreal x = barSeries->categoryCount(); |
|
186 | qreal x = barSeries->categoryCount(); | |
187 | qreal y = barSeries->max(); |
|
187 | qreal y = barSeries->max(); | |
188 | minX = qMin(minX, x); |
|
188 | minX = qMin(minX, x); | |
189 | minY = qMin(minY, y); |
|
189 | minY = qMin(minY, y); | |
190 | maxX = qMax(maxX, x); |
|
190 | maxX = qMax(maxX, x); | |
191 | maxY = qMax(maxY, y); |
|
191 | maxY = qMax(maxY, y); | |
192 | tickXCount = x+1; |
|
192 | tickXCount = x+1; | |
193 | setupCategories(barSeries); |
|
193 | setupCategories(barSeries); | |
194 | break; |
|
194 | break; | |
195 | } |
|
195 | } | |
196 | case QSeries::SeriesTypeStackedBar: { |
|
196 | case QSeries::SeriesTypeStackedBar: { | |
197 |
|
197 | |||
198 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
198 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); | |
199 | qreal x = stackedBarSeries->categoryCount(); |
|
199 | qreal x = stackedBarSeries->categoryCount(); | |
200 | qreal y = stackedBarSeries->maxCategorySum(); |
|
200 | qreal y = stackedBarSeries->maxCategorySum(); | |
201 | minX = qMin(minX, x); |
|
201 | minX = qMin(minX, x); | |
202 | minY = qMin(minY, y); |
|
202 | minY = qMin(minY, y); | |
203 | maxX = qMax(maxX, x); |
|
203 | maxX = qMax(maxX, x); | |
204 | maxY = qMax(maxY, y); |
|
204 | maxY = qMax(maxY, y); | |
205 | tickXCount = x+1; |
|
205 | tickXCount = x+1; | |
206 | setupCategories(stackedBarSeries); |
|
206 | setupCategories(stackedBarSeries); | |
207 | break; |
|
207 | break; | |
208 | } |
|
208 | } | |
209 | case QSeries::SeriesTypePercentBar: { |
|
209 | case QSeries::SeriesTypePercentBar: { | |
210 |
|
210 | |||
211 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
211 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); | |
212 | qreal x = percentBarSeries->categoryCount(); |
|
212 | qreal x = percentBarSeries->categoryCount(); | |
213 | minX = qMin(minX, x); |
|
213 | minX = qMin(minX, x); | |
214 | maxX = qMax(maxX, x); |
|
214 | maxX = qMax(maxX, x); | |
215 | minY = 0; |
|
215 | minY = 0; | |
216 | maxY = 100; |
|
216 | maxY = 100; | |
217 | setupCategories(percentBarSeries); |
|
217 | setupCategories(percentBarSeries); | |
218 | break; |
|
218 | break; | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | case QSeries::SeriesTypePie: { |
|
221 | case QSeries::SeriesTypePie: { | |
222 | //QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
222 | //QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
223 | // TODO: domain stuff |
|
223 | // TODO: domain stuff | |
224 | break; |
|
224 | break; | |
225 | } |
|
225 | } | |
226 |
|
226 | |||
227 |
|
227 | |||
228 | default: { |
|
228 | default: { | |
229 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; |
|
229 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; | |
230 | return; |
|
230 | return; | |
231 | break; |
|
231 | break; | |
232 | } |
|
232 | } | |
233 |
|
233 | |||
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | domain->setRangeX(minX,maxX,tickXCount); |
|
236 | domain->setRangeX(minX,maxX,tickXCount); | |
237 | domain->setRangeY(minY,maxY,tickYCount); |
|
237 | domain->setRangeY(minY,maxY,tickYCount); | |
238 | } |
|
238 | } | |
239 |
|
239 | |||
240 |
|
240 | |||
241 | void ChartDataSet::setupCategories(QBarSeries* series) |
|
241 | void ChartDataSet::setupCategories(QBarSeries* series) | |
242 | { |
|
242 | { | |
243 | int count = series->categoryCount(); |
|
|||
244 | QChartAxisCategories* categories = axisX()->categories(); |
|
243 | QChartAxisCategories* categories = axisX()->categories(); | |
245 | categories->clear(); |
|
244 | categories->clear(); | |
246 | for (int i=1; i<=count; i++) { |
|
245 | categories->insert(series->categories()); | |
247 | categories->insert(i,series->categoryName(i-1)); |
|
|||
248 | } |
|
|||
249 | } |
|
246 | } | |
250 |
|
247 | |||
251 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) |
|
248 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) | |
252 | { |
|
249 | { | |
253 | QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap); |
|
250 | QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap); | |
254 | while (i.hasNext()) { |
|
251 | while (i.hasNext()) { | |
255 | i.next(); |
|
252 | i.next(); | |
256 | i.value()->zoomIn(rect,size); |
|
253 | i.value()->zoomIn(rect,size); | |
257 | } |
|
254 | } | |
258 | } |
|
255 | } | |
259 |
|
256 | |||
260 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) |
|
257 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) | |
261 | { |
|
258 | { | |
262 | QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap); |
|
259 | QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap); | |
263 | while (i.hasNext()) { |
|
260 | while (i.hasNext()) { | |
264 | i.next(); |
|
261 | i.next(); | |
265 | i.value()->zoomOut(rect,size); |
|
262 | i.value()->zoomOut(rect,size); | |
266 | } |
|
263 | } | |
267 | } |
|
264 | } | |
268 |
|
265 | |||
269 | int ChartDataSet::seriesCount(QSeries::QSeriesType type) |
|
266 | int ChartDataSet::seriesCount(QSeries::QSeriesType type) | |
270 | { |
|
267 | { | |
271 | int count=0; |
|
268 | int count=0; | |
272 | QMapIterator<QSeries*, QChartAxis*> i( m_seriesAxisMap); |
|
269 | QMapIterator<QSeries*, QChartAxis*> i( m_seriesAxisMap); | |
273 | while (i.hasNext()) { |
|
270 | while (i.hasNext()) { | |
274 | i.next(); |
|
271 | i.next(); | |
275 | if(i.key()->type()==type) count++; |
|
272 | if(i.key()->type()==type) count++; | |
276 | } |
|
273 | } | |
277 | return count; |
|
274 | return count; | |
278 | } |
|
275 | } | |
279 |
|
276 | |||
280 | int ChartDataSet::seriesIndex(QSeries *series) |
|
277 | int ChartDataSet::seriesIndex(QSeries *series) | |
281 | { |
|
278 | { | |
282 | int count(-1); |
|
279 | int count(-1); | |
283 | QMapIterator<QSeries*, QChartAxis*> i(m_seriesAxisMap); |
|
280 | QMapIterator<QSeries*, QChartAxis*> i(m_seriesAxisMap); | |
284 | while (i.hasNext()) { |
|
281 | while (i.hasNext()) { | |
285 | i.next(); |
|
282 | i.next(); | |
286 | count++; |
|
283 | count++; | |
287 | if (i.key() == series) |
|
284 | if (i.key() == series) | |
288 | return count; |
|
285 | return count; | |
289 | } |
|
286 | } | |
290 | return count; |
|
287 | return count; | |
291 | } |
|
288 | } | |
292 |
|
289 | |||
293 | QChartAxis* ChartDataSet::axisY(QSeries* series) const |
|
290 | QChartAxis* ChartDataSet::axisY(QSeries* series) const | |
294 | { |
|
291 | { | |
295 | if(series == 0) return m_axisY; |
|
292 | if(series == 0) return m_axisY; | |
296 | return m_seriesAxisMap.value(series); |
|
293 | return m_seriesAxisMap.value(series); | |
297 | } |
|
294 | } | |
298 |
|
295 | |||
299 | Domain* ChartDataSet::domain(QSeries* series) const |
|
296 | Domain* ChartDataSet::domain(QSeries* series) const | |
300 | { |
|
297 | { | |
301 | QChartAxis* axis = m_seriesAxisMap.value(series); |
|
298 | QChartAxis* axis = m_seriesAxisMap.value(series); | |
302 | if(axis){ |
|
299 | if(axis){ | |
303 | return m_axisDomainMap.value(axis); |
|
300 | return m_axisDomainMap.value(axis); | |
304 | }else |
|
301 | }else | |
305 | return 0; |
|
302 | return 0; | |
306 | } |
|
303 | } | |
307 |
|
304 | |||
308 | Domain* ChartDataSet::domain(QChartAxis* axis) const |
|
305 | Domain* ChartDataSet::domain(QChartAxis* axis) const | |
309 | { |
|
306 | { | |
310 | if(axis==axisX()) { |
|
307 | if(axis==axisX()) { | |
311 | return m_axisDomainMap.value(axisY()); |
|
308 | return m_axisDomainMap.value(axisY()); | |
312 | } |
|
309 | } | |
313 | else { |
|
310 | else { | |
314 | return m_axisDomainMap.value(axis); |
|
311 | return m_axisDomainMap.value(axis); | |
315 | } |
|
312 | } | |
316 | } |
|
313 | } | |
317 |
|
314 | |||
318 | QChartAxis* ChartDataSet::axis(QSeries* series) const |
|
315 | QChartAxis* ChartDataSet::axis(QSeries* series) const | |
319 | { |
|
316 | { | |
320 | return m_seriesAxisMap.value(series); |
|
317 | return m_seriesAxisMap.value(series); | |
321 | } |
|
318 | } | |
322 |
|
319 | |||
323 | void ChartDataSet::scrollDomain(int dx,int dy,const QSizeF& size) |
|
320 | void ChartDataSet::scrollDomain(int dx,int dy,const QSizeF& size) | |
324 | { |
|
321 | { | |
325 | QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap); |
|
322 | QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap); | |
326 | while (i.hasNext()) { |
|
323 | while (i.hasNext()) { | |
327 | i.next(); |
|
324 | i.next(); | |
328 | i.value()->move(dx,dy,size); |
|
325 | i.value()->move(dx,dy,size); | |
329 | } |
|
326 | } | |
330 | } |
|
327 | } | |
331 |
|
328 | |||
332 | #include "moc_chartdataset_p.cpp" |
|
329 | #include "moc_chartdataset_p.cpp" | |
333 |
|
330 | |||
334 | QTCOMMERCIALCHART_END_NAMESPACE |
|
331 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now