##// END OF EJS Templates
Fix vs2010 build
Jani Honkonen -
r605:c0502398e154
parent child
Show More
@@ -1,241 +1,242
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(QStringList categories, QObject *parent)
36 QBarSeries::QBarSeries(QStringList 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 }
44 }
45
45
46 /*!
46 /*!
47 Adds a set of bars to series. Takes ownership of \a set.
47 Adds a set of bars to series. Takes ownership of \a set.
48 Connects the clicked(QString) and rightClicked(QString) signals
48 Connects the clicked(QString) and rightClicked(QString) signals
49 of \a set to this series
49 of \a set to this series
50 */
50 */
51 void QBarSeries::addBarSet(QBarSet *set)
51 void QBarSeries::addBarSet(QBarSet *set)
52 {
52 {
53 mModel->addBarSet(set);
53 mModel->addBarSet(set);
54 connect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString)));
54 connect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString)));
55 connect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString)));
55 connect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString)));
56 }
56 }
57
57
58 /*!
58 /*!
59 Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set.
59 Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set.
60 Disconnects the clicked(QString) and rightClicked(QString) signals
60 Disconnects the clicked(QString) and rightClicked(QString) signals
61 of \a set from this series
61 of \a set from this series
62 */
62 */
63 void QBarSeries::removeBarSet(QBarSet *set)
63 void QBarSeries::removeBarSet(QBarSet *set)
64 {
64 {
65 disconnect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString)));
65 disconnect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString)));
66 disconnect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString)));
66 disconnect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString)));
67 mModel->removeBarSet(set);
67 mModel->removeBarSet(set);
68 }
68 }
69
69
70 /*!
70 /*!
71 Returns number of sets in series.
71 Returns number of sets in series.
72 */
72 */
73 int QBarSeries::barsetCount()
73 int QBarSeries::barsetCount()
74 {
74 {
75 if(m_model)
75 if(m_model)
76 return m_mapBarTop - m_mapBarBottom;
76 return m_mapBarTop - m_mapBarBottom;
77 else
77 else
78 return mModel->barsetCount();
78 return mModel->barsetCount();
79 }
79 }
80
80
81 /*!
81 /*!
82 Returns number of categories in series
82 Returns number of categories in series
83 */
83 */
84 int QBarSeries::categoryCount()
84 int QBarSeries::categoryCount()
85 {
85 {
86 return mModel->categoryCount();
86 return mModel->categoryCount();
87 }
87 }
88
88
89 /*!
89 /*!
90 Returns a list of sets in series. Keeps ownership of sets.
90 Returns a list of sets in series. Keeps ownership of sets.
91 */
91 */
92 QList<QBarSet*> QBarSeries::barSets()
92 QList<QBarSet*> QBarSeries::barSets()
93 {
93 {
94 return mModel->barSets();
94 return mModel->barSets();
95 }
95 }
96
96
97 /*!
97 /*!
98 \internal \a index
98 \internal \a index
99 */
99 */
100 QBarSet* QBarSeries::barsetAt(int index)
100 QBarSet* QBarSeries::barsetAt(int index)
101 {
101 {
102 return mModel->setAt(index);
102 return mModel->setAt(index);
103 }
103 }
104
104
105 /*!
105 /*!
106 \internal \a category
106 \internal \a category
107 */
107 */
108 QString QBarSeries::categoryName(int category)
108 QString QBarSeries::categoryName(int category)
109 {
109 {
110 return mModel->categoryName(category);
110 return mModel->categoryName(category);
111 }
111 }
112
112
113 /*!
113 /*!
114 Enables or disables tooltip depending on parameter \a enabled.
114 Enables or disables tooltip depending on parameter \a enabled.
115 Tooltip shows the name of set, when mouse is hovering on top of bar.
115 Tooltip shows the name of set, when mouse is hovering on top of bar.
116 Calling without parameter \a enabled, enables the tooltip
116 Calling without parameter \a enabled, enables the tooltip
117 */
117 */
118 void QBarSeries::setToolTipEnabled(bool enabled)
118 void QBarSeries::setToolTipEnabled(bool enabled)
119 {
119 {
120 // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled.
120 // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled.
121 if (enabled) {
121 if (enabled) {
122 for (int i=0; i<mModel->barsetCount(); i++) {
122 for (int i=0; i<mModel->barsetCount(); i++) {
123 QBarSet *set = mModel->setAt(i);
123 QBarSet *set = mModel->setAt(i);
124 connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString)));
124 connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString)));
125 }
125 }
126 } else {
126 } else {
127 for (int i=0; i<mModel->barsetCount(); i++) {
127 for (int i=0; i<mModel->barsetCount(); i++) {
128 QBarSet *set = mModel->setAt(i);
128 QBarSet *set = mModel->setAt(i);
129 disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString)));
129 disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString)));
130 }
130 }
131 }
131 }
132 }
132 }
133
133
134 /*!
134 /*!
135 Enables or disables separators depending on parameter \a enabled.
135 Enables or disables separators depending on parameter \a enabled.
136 Separators are visual elements that are drawn between categories.
136 Separators are visual elements that are drawn between categories.
137 Calling without parameter \a enabled, enables the separators
137 Calling without parameter \a enabled, enables the separators
138 */
138 */
139 void QBarSeries::setSeparatorsVisible(bool visible)
139 void QBarSeries::setSeparatorsVisible(bool visible)
140 {
140 {
141 mSeparatorsVisible = visible;
141 mSeparatorsVisible = visible;
142 emit enableSeparators(visible);
142 emit enableSeparators(visible);
143 }
143 }
144
144
145
145
146 /*!
146 /*!
147 \internal \a category
147 \internal \a category
148 */
148 */
149 void QBarSeries::barsetClicked(QString category)
149 void QBarSeries::barsetClicked(QString category)
150 {
150 {
151 emit clicked(qobject_cast<QBarSet*>(sender()), category);
151 emit clicked(qobject_cast<QBarSet*>(sender()), category);
152 }
152 }
153
153
154 /*!
154 /*!
155 \internal \a category
155 \internal \a category
156 */
156 */
157 void QBarSeries::barsetRightClicked(QString category)
157 void QBarSeries::barsetRightClicked(QString category)
158 {
158 {
159 emit rightClicked(qobject_cast<QBarSet*>(sender()), category);
159 emit rightClicked(qobject_cast<QBarSet*>(sender()), category);
160 }
160 }
161
161
162
162
163 /*!
163 /*!
164 \internal
164 \internal
165 */
165 */
166 qreal QBarSeries::min()
166 qreal QBarSeries::min()
167 {
167 {
168 return mModel->min();
168 return mModel->min();
169 }
169 }
170
170
171 /*!
171 /*!
172 \internal
172 \internal
173 */
173 */
174 qreal QBarSeries::max()
174 qreal QBarSeries::max()
175 {
175 {
176 return mModel->max();
176 return mModel->max();
177 }
177 }
178
178
179 /*!
179 /*!
180 \internal \a set \a category
180 \internal \a set \a category
181 */
181 */
182 qreal QBarSeries::valueAt(int set, int category)
182 qreal QBarSeries::valueAt(int set, int category)
183 {
183 {
184 return mModel->valueAt(set,category);
184 return mModel->valueAt(set,category);
185 }
185 }
186
186
187 /*!
187 /*!
188 \internal \a set \a category
188 \internal \a set \a category
189 */
189 */
190 qreal QBarSeries::percentageAt(int set, int category)
190 qreal QBarSeries::percentageAt(int set, int category)
191 {
191 {
192 return mModel->percentageAt(set,category);
192 return mModel->percentageAt(set,category);
193 }
193 }
194
194
195 /*!
195 /*!
196 \internal \a category
196 \internal \a category
197 */
197 */
198 qreal QBarSeries::categorySum(int category)
198 qreal QBarSeries::categorySum(int category)
199 {
199 {
200 return mModel->categorySum(category);
200 return mModel->categorySum(category);
201 }
201 }
202
202
203 /*!
203 /*!
204 \internal
204 \internal
205 */
205 */
206 qreal QBarSeries::maxCategorySum()
206 qreal QBarSeries::maxCategorySum()
207 {
207 {
208 return mModel->maxCategorySum();
208 return mModel->maxCategorySum();
209 }
209 }
210
210
211 /*!
211 /*!
212 \internal
212 \internal
213 */
213 */
214 BarChartModel& QBarSeries::model()
214 BarChartModel& QBarSeries::model()
215 {
215 {
216 return *mModel;
216 return *mModel;
217 }
217 }
218
218
219 bool QBarSeries::separatorsVisible()
219 bool QBarSeries::separatorsVisible()
220 {
220 {
221 return mSeparatorsVisible;
221 return mSeparatorsVisible;
222 }
222 }
223
223
224 bool QBarSeries::setModel(QAbstractItemModel* model)
224 bool QBarSeries::setModel(QAbstractItemModel* model)
225 {
225 {
226 m_model = model;
226 m_model = model;
227 return true;
227 }
228 }
228
229
229 void QBarSeries::setModelMappingCategories(int modelColumn)
230 void QBarSeries::setModelMappingCategories(int modelColumn)
230 {
231 {
231 //
232 //
232 }
233 }
233
234
234 void QBarSeries::setModelMappingBarRange(int bottomBoundry, int topBoundry)
235 void QBarSeries::setModelMappingBarRange(int bottomBoundry, int topBoundry)
235 {
236 {
236 //
237 //
237 }
238 }
238
239
239 #include "moc_qbarseries.cpp"
240 #include "moc_qbarseries.cpp"
240
241
241 QTCOMMERCIALCHART_END_NAMESPACE
242 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,634 +1,636
1 #include "qpieseries.h"
1 #include "qpieseries.h"
2 #include "qpieslice.h"
2 #include "qpieslice.h"
3 #include <QDebug>
3 #include <QDebug>
4
4
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6
6
7
7
8 /*!
8 /*!
9 \class QPieSeries::ChangeSet
9 \class QPieSeries::ChangeSet
10 \brief Defines the changes in the series.
10 \brief Defines the changes in the series.
11
11
12 Contains the changes that have occurred in the series. Lists of added, changed and removed slices.
12 Contains the changes that have occurred in the series. Lists of added, changed and removed slices.
13
13
14 \sa QPieSeries::changed()
14 \sa QPieSeries::changed()
15 */
15 */
16
16
17 /*!
17 /*!
18 \internal
18 \internal
19 */
19 */
20 void QPieSeries::ChangeSet::appendAdded(QPieSlice* slice)
20 void QPieSeries::ChangeSet::appendAdded(QPieSlice* slice)
21 {
21 {
22 if (!m_added.contains(slice))
22 if (!m_added.contains(slice))
23 m_added << slice;
23 m_added << slice;
24 }
24 }
25
25
26 /*!
26 /*!
27 \internal
27 \internal
28 */
28 */
29 void QPieSeries::ChangeSet::appendAdded(QList<QPieSlice*> slices)
29 void QPieSeries::ChangeSet::appendAdded(QList<QPieSlice*> slices)
30 {
30 {
31 foreach (QPieSlice* s, slices)
31 foreach (QPieSlice* s, slices)
32 appendAdded(s);
32 appendAdded(s);
33 }
33 }
34
34
35 /*!
35 /*!
36 \internal
36 \internal
37 */
37 */
38 void QPieSeries::ChangeSet::appendChanged(QPieSlice* slice)
38 void QPieSeries::ChangeSet::appendChanged(QPieSlice* slice)
39 {
39 {
40 if (!m_changed.contains(slice))
40 if (!m_changed.contains(slice))
41 m_changed << slice;
41 m_changed << slice;
42 }
42 }
43
43
44 /*!
44 /*!
45 \internal
45 \internal
46 */
46 */
47 void QPieSeries::ChangeSet::appendRemoved(QPieSlice* slice)
47 void QPieSeries::ChangeSet::appendRemoved(QPieSlice* slice)
48 {
48 {
49 if (!m_removed.contains(slice))
49 if (!m_removed.contains(slice))
50 m_removed << slice;
50 m_removed << slice;
51 }
51 }
52
52
53 /*!
53 /*!
54 Returns a list of slices that have been added to the series.
54 Returns a list of slices that have been added to the series.
55 \sa QPieSeries::changed()
55 \sa QPieSeries::changed()
56 */
56 */
57 QList<QPieSlice*> QPieSeries::ChangeSet::added() const
57 QList<QPieSlice*> QPieSeries::ChangeSet::added() const
58 {
58 {
59 return m_added;
59 return m_added;
60 }
60 }
61
61
62 /*!
62 /*!
63 Returns a list of slices that have been changed in the series.
63 Returns a list of slices that have been changed in the series.
64 \sa QPieSeries::changed()
64 \sa QPieSeries::changed()
65 */
65 */
66 QList<QPieSlice*> QPieSeries::ChangeSet::changed() const
66 QList<QPieSlice*> QPieSeries::ChangeSet::changed() const
67 {
67 {
68 return m_changed;
68 return m_changed;
69 }
69 }
70
70
71 /*!
71 /*!
72 Returns a list of slices that have been removed from the series.
72 Returns a list of slices that have been removed from the series.
73 \sa QPieSeries::changed()
73 \sa QPieSeries::changed()
74 */
74 */
75 QList<QPieSlice*> QPieSeries::ChangeSet::removed() const
75 QList<QPieSlice*> QPieSeries::ChangeSet::removed() const
76 {
76 {
77 return m_removed;
77 return m_removed;
78 }
78 }
79
79
80
80
81 /*!
81 /*!
82 Returns true if there are no added/changed or removed slices in the change set.
82 Returns true if there are no added/changed or removed slices in the change set.
83 */
83 */
84 bool QPieSeries::ChangeSet::isEmpty() const
84 bool QPieSeries::ChangeSet::isEmpty() const
85 {
85 {
86 if (m_added.count() || m_changed.count() || m_removed.count())
86 if (m_added.count() || m_changed.count() || m_removed.count())
87 return false;
87 return false;
88 return true;
88 return true;
89 }
89 }
90
90
91 /*!
91 /*!
92 \class QPieSeries
92 \class QPieSeries
93 \brief Pie series API for QtCommercial Charts
93 \brief Pie series API for QtCommercial Charts
94
94
95 The pie series defines a pie chart which consists of pie slices which are QPieSlice objects.
95 The pie series defines a pie chart which consists of pie slices which are QPieSlice objects.
96 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
96 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
97 The actual slice size is determined by that relative value.
97 The actual slice size is determined by that relative value.
98
98
99 By default the pie is defined as a full pie but it can be a partial pie.
99 By default the pie is defined as a full pie but it can be a partial pie.
100 This can be done by setting a starting angle and angle span to the series.
100 This can be done by setting a starting angle and angle span to the series.
101 */
101 */
102
102
103 /*!
103 /*!
104 Constructs a series object which is a child of \a parent.
104 Constructs a series object which is a child of \a parent.
105 */
105 */
106 QPieSeries::QPieSeries(QObject *parent) :
106 QPieSeries::QPieSeries(QObject *parent) :
107 QSeries(parent),
107 QSeries(parent),
108 m_pieRelativeHorPos(0.5),
108 m_pieRelativeHorPos(0.5),
109 m_pieRelativeVerPos(0.5),
109 m_pieRelativeVerPos(0.5),
110 m_pieRelativeSize(0.7),
110 m_pieRelativeSize(0.7),
111 m_pieStartAngle(0),
111 m_pieStartAngle(0),
112 m_pieEndAngle(360),
112 m_pieEndAngle(360),
113 m_total(0)
113 m_total(0)
114 {
114 {
115
115
116 }
116 }
117
117
118 /*!
118 /*!
119 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
119 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
120 */
120 */
121 QPieSeries::~QPieSeries()
121 QPieSeries::~QPieSeries()
122 {
122 {
123
123
124 }
124 }
125
125
126 /*!
126 /*!
127 Returns QChartSeries::SeriesTypePie.
127 Returns QChartSeries::SeriesTypePie.
128 */
128 */
129 QSeries::QSeriesType QPieSeries::type() const
129 QSeries::QSeriesType QPieSeries::type() const
130 {
130 {
131 return QSeries::SeriesTypePie;
131 return QSeries::SeriesTypePie;
132 }
132 }
133
133
134 /*!
134 /*!
135 Sets an array of \a slices to the series replacing the existing slices.
135 Sets an array of \a slices to the series replacing the existing slices.
136 Slice ownership is passed to the series.
136 Slice ownership is passed to the series.
137 */
137 */
138 void QPieSeries::replace(QList<QPieSlice*> slices)
138 void QPieSeries::replace(QList<QPieSlice*> slices)
139 {
139 {
140 clear();
140 clear();
141 add(slices);
141 add(slices);
142 }
142 }
143
143
144 /*!
144 /*!
145 Adds an array of \a slices to the series.
145 Adds an array of \a slices to the series.
146 Slice ownership is passed to the series.
146 Slice ownership is passed to the series.
147 */
147 */
148 void QPieSeries::add(QList<QPieSlice*> slices)
148 void QPieSeries::add(QList<QPieSlice*> slices)
149 {
149 {
150 foreach (QPieSlice* s, slices) {
150 foreach (QPieSlice* s, slices) {
151 s->setParent(this);
151 s->setParent(this);
152 m_slices << s;
152 m_slices << s;
153 }
153 }
154
154
155 updateDerivativeData();
155 updateDerivativeData();
156
156
157 foreach (QPieSlice* s, slices) {
157 foreach (QPieSlice* s, slices) {
158 connect(s, SIGNAL(changed()), this, SLOT(sliceChanged()));
158 connect(s, SIGNAL(changed()), this, SLOT(sliceChanged()));
159 connect(s, SIGNAL(clicked()), this, SLOT(sliceClicked()));
159 connect(s, SIGNAL(clicked()), this, SLOT(sliceClicked()));
160 connect(s, SIGNAL(hoverEnter()), this, SLOT(sliceHoverEnter()));
160 connect(s, SIGNAL(hoverEnter()), this, SLOT(sliceHoverEnter()));
161 connect(s, SIGNAL(hoverLeave()), this, SLOT(sliceHoverLeave()));
161 connect(s, SIGNAL(hoverLeave()), this, SLOT(sliceHoverLeave()));
162 }
162 }
163
163
164 emit changed();
164 emit changed();
165 }
165 }
166
166
167 /*!
167 /*!
168 Adds a single \a slice to the series.
168 Adds a single \a slice to the series.
169 Slice ownership is passed to the series.
169 Slice ownership is passed to the series.
170 */
170 */
171 void QPieSeries::add(QPieSlice* slice)
171 void QPieSeries::add(QPieSlice* slice)
172 {
172 {
173 add(QList<QPieSlice*>() << slice);
173 add(QList<QPieSlice*>() << slice);
174 }
174 }
175
175
176 /*!
176 /*!
177 Adds a single \a slice to the series and returns a reference to the series.
177 Adds a single \a slice to the series and returns a reference to the series.
178 Slice ownership is passed to the series.
178 Slice ownership is passed to the series.
179 */
179 */
180 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
180 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
181 {
181 {
182 add(slice);
182 add(slice);
183 return *this;
183 return *this;
184 }
184 }
185
185
186
186
187 /*!
187 /*!
188 Adds a single slice to the series with give \a value and \a name.
188 Adds a single slice to the series with give \a value and \a name.
189 Slice ownership is passed to the series.
189 Slice ownership is passed to the series.
190 */
190 */
191 QPieSlice* QPieSeries::add(qreal value, QString name)
191 QPieSlice* QPieSeries::add(qreal value, QString name)
192 {
192 {
193 QPieSlice* slice = new QPieSlice(value, name);
193 QPieSlice* slice = new QPieSlice(value, name);
194 add(slice);
194 add(slice);
195 return slice;
195 return slice;
196 }
196 }
197
197
198 void QPieSeries::insert(int i, QPieSlice* slice)
198 void QPieSeries::insert(int i, QPieSlice* slice)
199 {
199 {
200 Q_ASSERT(i <= m_slices.count());
200 Q_ASSERT(i <= m_slices.count());
201 slice->setParent(this);
201 slice->setParent(this);
202 m_slices.insert(i, slice);
202 m_slices.insert(i, slice);
203
203
204 updateDerivativeData();
204 updateDerivativeData();
205
205
206 connect(slice, SIGNAL(changed()), this, SLOT(sliceChanged()));
206 connect(slice, SIGNAL(changed()), this, SLOT(sliceChanged()));
207 connect(slice, SIGNAL(clicked()), this, SLOT(sliceClicked()));
207 connect(slice, SIGNAL(clicked()), this, SLOT(sliceClicked()));
208 connect(slice, SIGNAL(hoverEnter()), this, SLOT(sliceHoverEnter()));
208 connect(slice, SIGNAL(hoverEnter()), this, SLOT(sliceHoverEnter()));
209 connect(slice, SIGNAL(hoverLeave()), this, SLOT(sliceHoverLeave()));
209 connect(slice, SIGNAL(hoverLeave()), this, SLOT(sliceHoverLeave()));
210
210
211 emit changed();
211 emit changed();
212 }
212 }
213
213
214 /*!
214 /*!
215 Removes a single \a slice from the series and deletes the slice.
215 Removes a single \a slice from the series and deletes the slice.
216
216
217 Do not reference this pointer after this call.
217 Do not reference this pointer after this call.
218 */
218 */
219 void QPieSeries::remove(QPieSlice* slice)
219 void QPieSeries::remove(QPieSlice* slice)
220 {
220 {
221 if (!m_slices.removeOne(slice)) {
221 if (!m_slices.removeOne(slice)) {
222 Q_ASSERT(0); // TODO: how should this be reported?
222 Q_ASSERT(0); // TODO: how should this be reported?
223 return;
223 return;
224 }
224 }
225 emit changed();
225 emit changed();
226
226
227 updateDerivativeData();
227 updateDerivativeData();
228
228
229 delete slice;
229 delete slice;
230 slice = NULL;
230 slice = NULL;
231 }
231 }
232
232
233 /*!
233 /*!
234 Clears all slices from the series.
234 Clears all slices from the series.
235 */
235 */
236 void QPieSeries::clear()
236 void QPieSeries::clear()
237 {
237 {
238 if (m_slices.count() == 0)
238 if (m_slices.count() == 0)
239 return;
239 return;
240
240
241 foreach (QPieSlice* s, m_slices) {
241 foreach (QPieSlice* s, m_slices) {
242 m_slices.removeOne(s);
242 m_slices.removeOne(s);
243 delete s;
243 delete s;
244 }
244 }
245
245
246 emit changed();
246 emit changed();
247
247
248 updateDerivativeData();
248 updateDerivativeData();
249 }
249 }
250
250
251 /*!
251 /*!
252 Counts the number of the slices in this series.
252 Counts the number of the slices in this series.
253 */
253 */
254 int QPieSeries::count() const
254 int QPieSeries::count() const
255 {
255 {
256 return m_slices.count();
256 return m_slices.count();
257 }
257 }
258
258
259 /*!
259 /*!
260 Returns a list of slices that belong to this series.
260 Returns a list of slices that belong to this series.
261 */
261 */
262 QList<QPieSlice*> QPieSeries::slices() const
262 QList<QPieSlice*> QPieSeries::slices() const
263 {
263 {
264 return m_slices;
264 return m_slices;
265 }
265 }
266
266
267 /*!
267 /*!
268 Sets the center position of the pie by \a relativeHorizontalPosition and \a relativeVerticalPosition.
268 Sets the center position of the pie by \a relativeHorizontalPosition and \a relativeVerticalPosition.
269
269
270 The factors are relative to the chart rectangle where:
270 The factors are relative to the chart rectangle where:
271
271
272 \a relativeHorizontalPosition 0.0 means the absolute left.
272 \a relativeHorizontalPosition 0.0 means the absolute left.
273 \a relativeHorizontalPosition 1.0 means the absolute right.
273 \a relativeHorizontalPosition 1.0 means the absolute right.
274 \a relativeVerticalPosition 0.0 means the absolute top.
274 \a relativeVerticalPosition 0.0 means the absolute top.
275 \a relativeVerticalPosition 1.0 means the absolute bottom.
275 \a relativeVerticalPosition 1.0 means the absolute bottom.
276
276
277 By default both values are 0.5 which puts the pie in the middle of the chart rectangle.
277 By default both values are 0.5 which puts the pie in the middle of the chart rectangle.
278
278
279 \sa pieHorizontalPosition(), pieVerticalPosition(), setPieSize()
279 \sa pieHorizontalPosition(), pieVerticalPosition(), setPieSize()
280 */
280 */
281 void QPieSeries::setPiePosition(qreal relativeHorizontalPosition, qreal relativeVerticalPosition)
281 void QPieSeries::setPiePosition(qreal relativeHorizontalPosition, qreal relativeVerticalPosition)
282 {
282 {
283 if (relativeHorizontalPosition < 0.0 || relativeHorizontalPosition > 1.0 ||
283 if (relativeHorizontalPosition < 0.0 || relativeHorizontalPosition > 1.0 ||
284 relativeVerticalPosition < 0.0 || relativeVerticalPosition > 1.0)
284 relativeVerticalPosition < 0.0 || relativeVerticalPosition > 1.0)
285 return;
285 return;
286
286
287 if (m_pieRelativeHorPos != relativeHorizontalPosition || m_pieRelativeVerPos != relativeVerticalPosition) {
287 if (m_pieRelativeHorPos != relativeHorizontalPosition || m_pieRelativeVerPos != relativeVerticalPosition) {
288 m_pieRelativeHorPos = relativeHorizontalPosition;
288 m_pieRelativeHorPos = relativeHorizontalPosition;
289 m_pieRelativeVerPos = relativeVerticalPosition;
289 m_pieRelativeVerPos = relativeVerticalPosition;
290 emit changed();
290 emit changed();
291 }
291 }
292 }
292 }
293
293
294 /*!
294 /*!
295 Gets the horizontal position of the pie.
295 Gets the horizontal position of the pie.
296
296
297 The returned value is relative to the chart rectangle where:
297 The returned value is relative to the chart rectangle where:
298
298
299 0.0 means the absolute left.
299 0.0 means the absolute left.
300 1.0 means the absolute right.
300 1.0 means the absolute right.
301
301
302 By default it is 0.5 which puts the pie in the horizontal middle of the chart rectangle.
302 By default it is 0.5 which puts the pie in the horizontal middle of the chart rectangle.
303
303
304 \sa setPiePosition(), pieVerticalPosition(), setPieSize()
304 \sa setPiePosition(), pieVerticalPosition(), setPieSize()
305 */
305 */
306 qreal QPieSeries::pieHorizontalPosition() const
306 qreal QPieSeries::pieHorizontalPosition() const
307 {
307 {
308 return m_pieRelativeHorPos;
308 return m_pieRelativeHorPos;
309 }
309 }
310
310
311 /*!
311 /*!
312 Gets the vertical position position of the pie.
312 Gets the vertical position position of the pie.
313
313
314 The returned value is relative to the chart rectangle where:
314 The returned value is relative to the chart rectangle where:
315
315
316 0.0 means the absolute top.
316 0.0 means the absolute top.
317 1.0 means the absolute bottom.
317 1.0 means the absolute bottom.
318
318
319 By default it is 0.5 which puts the pie in the vertical middle of the chart rectangle.
319 By default it is 0.5 which puts the pie in the vertical middle of the chart rectangle.
320
320
321 \sa setPiePosition(), pieHorizontalPosition(), setPieSize()
321 \sa setPiePosition(), pieHorizontalPosition(), setPieSize()
322 */
322 */
323 qreal QPieSeries::pieVerticalPosition() const
323 qreal QPieSeries::pieVerticalPosition() const
324 {
324 {
325 return m_pieRelativeVerPos;
325 return m_pieRelativeVerPos;
326 }
326 }
327
327
328 /*!
328 /*!
329 Sets the relative size of the pie.
329 Sets the relative size of the pie.
330
330
331 The \a relativeSize is defined so that the 1.0 is the maximum that can fit the given chart rectangle.
331 The \a relativeSize is defined so that the 1.0 is the maximum that can fit the given chart rectangle.
332
332
333 Default value is 0.7.
333 Default value is 0.7.
334
334
335 \sa pieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition()
335 \sa pieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition()
336 */
336 */
337 void QPieSeries::setPieSize(qreal relativeSize)
337 void QPieSeries::setPieSize(qreal relativeSize)
338 {
338 {
339 if (relativeSize < 0.0 || relativeSize > 1.0)
339 if (relativeSize < 0.0 || relativeSize > 1.0)
340 return;
340 return;
341
341
342 if (m_pieRelativeSize != relativeSize) {
342 if (m_pieRelativeSize != relativeSize) {
343 m_pieRelativeSize = relativeSize;
343 m_pieRelativeSize = relativeSize;
344 emit changed();
344 emit changed();
345 }
345 }
346 }
346 }
347
347
348 /*!
348 /*!
349 Gets the relative size of the pie.
349 Gets the relative size of the pie.
350
350
351 The size is defined so that the 1.0 is the maximum that can fit the given chart rectangle.
351 The size is defined so that the 1.0 is the maximum that can fit the given chart rectangle.
352
352
353 Default value is 0.7.
353 Default value is 0.7.
354
354
355 \sa setPieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition()
355 \sa setPieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition()
356 */
356 */
357 qreal QPieSeries::pieSize() const
357 qreal QPieSeries::pieSize() const
358 {
358 {
359 return m_pieRelativeSize;
359 return m_pieRelativeSize;
360 }
360 }
361
361
362
362
363 /*!
363 /*!
364 Sets the end angle of the pie.
364 Sets the end angle of the pie.
365
365
366 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
366 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
367
367
368 \a angle must be less than pie end angle. Default value is 0.
368 \a angle must be less than pie end angle. Default value is 0.
369
369
370 \sa pieStartAngle(), pieEndAngle(), setPieEndAngle()
370 \sa pieStartAngle(), pieEndAngle(), setPieEndAngle()
371 */
371 */
372 void QPieSeries::setPieStartAngle(qreal angle)
372 void QPieSeries::setPieStartAngle(qreal angle)
373 {
373 {
374 if (angle >= 0 && angle <= 360 && angle != m_pieStartAngle && angle <= m_pieEndAngle) {
374 if (angle >= 0 && angle <= 360 && angle != m_pieStartAngle && angle <= m_pieEndAngle) {
375 m_pieStartAngle = angle;
375 m_pieStartAngle = angle;
376 updateDerivativeData();
376 updateDerivativeData();
377 }
377 }
378 }
378 }
379
379
380 /*!
380 /*!
381 Gets the start angle of the pie.
381 Gets the start angle of the pie.
382
382
383 Full pie is 360 degrees where 0 degrees is at 12 a'clock. Default value is 360.
383 Full pie is 360 degrees where 0 degrees is at 12 a'clock. Default value is 360.
384
384
385 \sa setPieStartAngle(), pieEndAngle(), setPieEndAngle()
385 \sa setPieStartAngle(), pieEndAngle(), setPieEndAngle()
386 */
386 */
387 qreal QPieSeries::pieStartAngle() const
387 qreal QPieSeries::pieStartAngle() const
388 {
388 {
389 return m_pieStartAngle;
389 return m_pieStartAngle;
390 }
390 }
391
391
392 /*!
392 /*!
393 Sets the end angle of the pie.
393 Sets the end angle of the pie.
394
394
395 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
395 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
396
396
397 \a angle must be greater than start angle.
397 \a angle must be greater than start angle.
398
398
399 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
399 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
400 */
400 */
401 void QPieSeries::setPieEndAngle(qreal angle)
401 void QPieSeries::setPieEndAngle(qreal angle)
402 {
402 {
403 if (angle >= 0 && angle <= 360 && angle != m_pieEndAngle && angle >= m_pieStartAngle) {
403 if (angle >= 0 && angle <= 360 && angle != m_pieEndAngle && angle >= m_pieStartAngle) {
404 m_pieEndAngle = angle;
404 m_pieEndAngle = angle;
405 updateDerivativeData();
405 updateDerivativeData();
406 }
406 }
407 }
407 }
408
408
409 /*!
409 /*!
410 Returns the end angle of the pie.
410 Returns the end angle of the pie.
411
411
412 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
412 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
413
413
414 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
414 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
415 */
415 */
416 qreal QPieSeries::pieEndAngle() const
416 qreal QPieSeries::pieEndAngle() const
417 {
417 {
418 return m_pieEndAngle;
418 return m_pieEndAngle;
419 }
419 }
420
420
421 /*!
421 /*!
422 Sets the all the slice labels \a visible or invisible.
422 Sets the all the slice labels \a visible or invisible.
423
423
424 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
424 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
425 */
425 */
426 void QPieSeries::setLabelsVisible(bool visible)
426 void QPieSeries::setLabelsVisible(bool visible)
427 {
427 {
428 foreach (QPieSlice* s, m_slices)
428 foreach (QPieSlice* s, m_slices)
429 s->setLabelVisible(visible);
429 s->setLabelVisible(visible);
430 }
430 }
431
431
432 /*!
432 /*!
433 Returns the sum of all slice values in this series.
433 Returns the sum of all slice values in this series.
434
434
435 \sa QPieSlice::value(), QPieSlice::setValue()
435 \sa QPieSlice::value(), QPieSlice::setValue()
436 */
436 */
437 qreal QPieSeries::total() const
437 qreal QPieSeries::total() const
438 {
438 {
439 return m_total;
439 return m_total;
440 }
440 }
441
441
442 /*!
442 /*!
443 \fn void QPieSeries::changed()
443 \fn void QPieSeries::changed()
444
444
445 This signal emitted when something has changed in the series.
445 This signal emitted when something has changed in the series.
446
446
447 \sa QPieSeries::ChangeSet, QPieSlice::changed()
447 \sa QPieSeries::ChangeSet, QPieSlice::changed()
448 */
448 */
449
449
450 /*!
450 /*!
451 \fn void QPieSeries::clicked(QPieSlice* slice)
451 \fn void QPieSeries::clicked(QPieSlice* slice)
452
452
453 This signal is emitted when a \a slice has been clicked.
453 This signal is emitted when a \a slice has been clicked.
454
454
455 \sa QPieSlice::clicked()
455 \sa QPieSlice::clicked()
456 */
456 */
457
457
458 /*!
458 /*!
459 \fn void QPieSeries::hoverEnter(QPieSlice* slice)
459 \fn void QPieSeries::hoverEnter(QPieSlice* slice)
460
460
461 This signal is emitted when user has hovered over a \a slice.
461 This signal is emitted when user has hovered over a \a slice.
462
462
463 \sa QPieSlice::hoverEnter()
463 \sa QPieSlice::hoverEnter()
464 */
464 */
465
465
466 /*!
466 /*!
467 \fn void QPieSeries::hoverLeave(QPieSlice* slice)
467 \fn void QPieSeries::hoverLeave(QPieSlice* slice)
468
468
469 This signal is emitted when user has hovered away from a \a slice.
469 This signal is emitted when user has hovered away from a \a slice.
470
470
471 \sa QPieSlice::hoverLeave()
471 \sa QPieSlice::hoverLeave()
472 */
472 */
473
473
474 void QPieSeries::sliceChanged()
474 void QPieSeries::sliceChanged()
475 {
475 {
476 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
476 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
477 Q_ASSERT(m_slices.contains(slice));
477 Q_ASSERT(m_slices.contains(slice));
478 updateDerivativeData();
478 updateDerivativeData();
479 }
479 }
480
480
481 void QPieSeries::sliceClicked()
481 void QPieSeries::sliceClicked()
482 {
482 {
483 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
483 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
484 Q_ASSERT(m_slices.contains(slice));
484 Q_ASSERT(m_slices.contains(slice));
485 emit clicked(slice);
485 emit clicked(slice);
486 }
486 }
487
487
488 void QPieSeries::sliceHoverEnter()
488 void QPieSeries::sliceHoverEnter()
489 {
489 {
490 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
490 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
491 Q_ASSERT(m_slices.contains(slice));
491 Q_ASSERT(m_slices.contains(slice));
492 emit hoverEnter(slice);
492 emit hoverEnter(slice);
493 }
493 }
494
494
495 void QPieSeries::sliceHoverLeave()
495 void QPieSeries::sliceHoverLeave()
496 {
496 {
497 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
497 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
498 Q_ASSERT(m_slices.contains(slice));
498 Q_ASSERT(m_slices.contains(slice));
499 emit hoverLeave(slice);
499 emit hoverLeave(slice);
500 }
500 }
501
501
502 void QPieSeries::updateDerivativeData()
502 void QPieSeries::updateDerivativeData()
503 {
503 {
504 m_total = 0;
504 m_total = 0;
505
505
506 // nothing to do?
506 // nothing to do?
507 if (m_slices.count() == 0)
507 if (m_slices.count() == 0)
508 return;
508 return;
509
509
510 // calculate total
510 // calculate total
511 foreach (QPieSlice* s, m_slices)
511 foreach (QPieSlice* s, m_slices)
512 m_total += s->value();
512 m_total += s->value();
513
513
514 // we must have some values
514 // we must have some values
515 if (m_total == 0) {
515 if (m_total == 0) {
516 qDebug() << "QPieSeries::updateDerivativeData() total == 0";
516 qDebug() << "QPieSeries::updateDerivativeData() total == 0";
517 Q_ASSERT(m_total > 0); // TODO: is this the correct way to handle this?
517 Q_ASSERT(m_total > 0); // TODO: is this the correct way to handle this?
518 }
518 }
519
519
520 // update slice attributes
520 // update slice attributes
521 qreal sliceAngle = m_pieStartAngle;
521 qreal sliceAngle = m_pieStartAngle;
522 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
522 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
523 foreach (QPieSlice* s, m_slices) {
523 foreach (QPieSlice* s, m_slices) {
524
524
525 bool changed = false;
525 bool changed = false;
526
526
527 qreal percentage = s->value() / m_total;
527 qreal percentage = s->value() / m_total;
528 if (s->m_percentage != percentage) {
528 if (s->m_percentage != percentage) {
529 s->m_percentage = percentage;
529 s->m_percentage = percentage;
530 changed = true;
530 changed = true;
531 }
531 }
532
532
533 qreal sliceSpan = pieSpan * percentage;
533 qreal sliceSpan = pieSpan * percentage;
534 if (s->m_angleSpan != sliceSpan) {
534 if (s->m_angleSpan != sliceSpan) {
535 s->m_angleSpan = sliceSpan;
535 s->m_angleSpan = sliceSpan;
536 changed = true;
536 changed = true;
537 }
537 }
538
538
539 if (s->m_startAngle != sliceAngle) {
539 if (s->m_startAngle != sliceAngle) {
540 s->m_startAngle = sliceAngle;
540 s->m_startAngle = sliceAngle;
541 changed = true;
541 changed = true;
542 }
542 }
543 sliceAngle += sliceSpan;
543 sliceAngle += sliceSpan;
544
544
545 if (changed)
545 if (changed)
546 emit s->changed();
546 emit s->changed();
547 }
547 }
548 }
548 }
549
549
550 bool QPieSeries::setModel(QAbstractItemModel* model)
550 bool QPieSeries::setModel(QAbstractItemModel* model)
551 {
551 {
552 // disconnect signals from old model
552 // disconnect signals from old model
553 if(m_model)
553 if(m_model)
554 {
554 {
555 disconnect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), 0, 0);
555 disconnect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), 0, 0);
556 disconnect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), 0, 0);
556 disconnect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), 0, 0);
557 disconnect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), 0, 0);
557 disconnect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), 0, 0);
558 }
558 }
559
559
560 // set new model if not NULL and connect necessary signals from it
560 // set new model if not NULL and connect necessary signals from it
561 if(model)
561 if(model)
562 {
562 {
563 m_model = model;
563 m_model = model;
564 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
564 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
565 connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
565 connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
566 connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int)));
566 connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int)));
567 }
567 }
568
569 return true;
568 }
570 }
569
571
570 void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation)
572 void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation)
571 {
573 {
572 m_mapValues = modelValuesLine;
574 m_mapValues = modelValuesLine;
573 m_mapLabels = modelLabelsLine;
575 m_mapLabels = modelLabelsLine;
574 m_mapOrientation = orientation;
576 m_mapOrientation = orientation;
575
577
576 if (m_model == NULL)
578 if (m_model == NULL)
577 return;
579 return;
578
580
579 if (m_mapOrientation == Qt::Vertical)
581 if (m_mapOrientation == Qt::Vertical)
580 for (int i = 0; i < m_model->rowCount(); i++)
582 for (int i = 0; i < m_model->rowCount(); i++)
581 add(m_model->data(m_model->index(i, m_mapValues), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(i, m_mapLabels), Qt::DisplayRole).toString());
583 add(m_model->data(m_model->index(i, m_mapValues), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(i, m_mapLabels), Qt::DisplayRole).toString());
582 else
584 else
583 for (int i = 0; i < m_model->columnCount(); i++)
585 for (int i = 0; i < m_model->columnCount(); i++)
584 add(m_model->data(m_model->index(m_mapValues, i), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(m_mapLabels, i), Qt::DisplayRole).toString());
586 add(m_model->data(m_model->index(m_mapValues, i), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(m_mapLabels, i), Qt::DisplayRole).toString());
585
587
586
588
587 }
589 }
588
590
589 void QPieSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
591 void QPieSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
590 {
592 {
591 if (m_mapOrientation == Qt::Vertical)
593 if (m_mapOrientation == Qt::Vertical)
592 {
594 {
593 // slices().at(topLeft.row())->setValue(m_model->data(m_model->index(topLeft.row(), topLeft.column()), Qt::DisplayRole).toDouble());
595 // slices().at(topLeft.row())->setValue(m_model->data(m_model->index(topLeft.row(), topLeft.column()), Qt::DisplayRole).toDouble());
594 if (topLeft.column() == m_mapValues)
596 if (topLeft.column() == m_mapValues)
595 slices().at(topLeft.row())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble());
597 slices().at(topLeft.row())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble());
596 else if (topLeft.column() == m_mapLabels)
598 else if (topLeft.column() == m_mapLabels)
597 slices().at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString());
599 slices().at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString());
598 }
600 }
599 else
601 else
600 {
602 {
601 // slices().at(topLeft.column())->setValue(m_model->data(m_model->index(topLeft.row(), topLeft.column()), Qt::DisplayRole).toDouble());
603 // slices().at(topLeft.column())->setValue(m_model->data(m_model->index(topLeft.row(), topLeft.column()), Qt::DisplayRole).toDouble());
602 if (topLeft.column() == m_mapValues)
604 if (topLeft.column() == m_mapValues)
603 slices().at(topLeft.column())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble());
605 slices().at(topLeft.column())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble());
604 else if (topLeft.column() == m_mapLabels)
606 else if (topLeft.column() == m_mapLabels)
605 slices().at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString());
607 slices().at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString());
606 }
608 }
607 }
609 }
608
610
609 void QPieSeries::modelDataAdded(QModelIndex parent, int start, int end)
611 void QPieSeries::modelDataAdded(QModelIndex parent, int start, int end)
610 {
612 {
611 QPieSlice* newSlice = new QPieSlice;
613 QPieSlice* newSlice = new QPieSlice;
612 newSlice->setLabelVisible(true);
614 newSlice->setLabelVisible(true);
613 if (m_mapOrientation == Qt::Vertical)
615 if (m_mapOrientation == Qt::Vertical)
614 {
616 {
615 newSlice->setValue(m_model->data(m_model->index(start, m_mapValues), Qt::DisplayRole).toDouble());
617 newSlice->setValue(m_model->data(m_model->index(start, m_mapValues), Qt::DisplayRole).toDouble());
616 newSlice->setLabel(m_model->data(m_model->index(start, m_mapLabels), Qt::DisplayRole).toString());
618 newSlice->setLabel(m_model->data(m_model->index(start, m_mapLabels), Qt::DisplayRole).toString());
617 }
619 }
618 else
620 else
619 {
621 {
620 newSlice->setValue(m_model->data(m_model->index(m_mapValues, start), Qt::DisplayRole).toDouble());
622 newSlice->setValue(m_model->data(m_model->index(m_mapValues, start), Qt::DisplayRole).toDouble());
621 newSlice->setLabel(m_model->data(m_model->index(m_mapLabels, start), Qt::DisplayRole).toString());
623 newSlice->setLabel(m_model->data(m_model->index(m_mapLabels, start), Qt::DisplayRole).toString());
622 }
624 }
623
625
624 insert(start, newSlice);
626 insert(start, newSlice);
625 }
627 }
626
628
627 void QPieSeries::modelDataRemoved(QModelIndex parent, int start, int end)
629 void QPieSeries::modelDataRemoved(QModelIndex parent, int start, int end)
628 {
630 {
629 remove(slices().at(start));
631 remove(slices().at(start));
630 }
632 }
631
633
632 #include "moc_qpieseries.cpp"
634 #include "moc_qpieseries.cpp"
633
635
634 QTCOMMERCIALCHART_END_NAMESPACE
636 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,154 +1,155
1 #include "qsplineseries.h"
1 #include "qsplineseries.h"
2
2
3 /*!
3 /*!
4 \class QSplineSeries
4 \class QSplineSeries
5 \brief Series type used to store data needed to draw a spline.
5 \brief Series type used to store data needed to draw a spline.
6
6
7 QSplineSeries stores the data points along with the segment control points needed by QPainterPath to draw spline
7 QSplineSeries stores the data points along with the segment control points needed by QPainterPath to draw spline
8 Control points are automatically calculated when data changes. The algorithm computes the points so that the normal spline can be drawn.
8 Control points are automatically calculated when data changes. The algorithm computes the points so that the normal spline can be drawn.
9 */
9 */
10
10
11 /*!
11 /*!
12 \fn QSeriesType QSplineSeries::type() const
12 \fn QSeriesType QSplineSeries::type() const
13 Returns the type of the series
13 Returns the type of the series
14 */
14 */
15
15
16 /*!
16 /*!
17 \fn QSeriesType QSplineSeries::controlPoint(int index) const
17 \fn QSeriesType QSplineSeries::controlPoint(int index) const
18 Returns the control point specified by \a index
18 Returns the control point specified by \a index
19 */
19 */
20
20
21 QTCOMMERCIALCHART_BEGIN_NAMESPACE
21 QTCOMMERCIALCHART_BEGIN_NAMESPACE
22
22
23 /*!
23 /*!
24 Constructs empty series object which is a child of \a parent.
24 Constructs empty series object which is a child of \a parent.
25 When series object is added to QChartView or QChart instance then the ownerships is transfered.
25 When series object is added to QChartView or QChart instance then the ownerships is transfered.
26 */
26 */
27
27
28 QSplineSeries::QSplineSeries(QObject *parent) :
28 QSplineSeries::QSplineSeries(QObject *parent) :
29 QLineSeries(parent)
29 QLineSeries(parent)
30 {
30 {
31 connect(this,SIGNAL(pointAdded(int)), this, SLOT(updateControlPoints()));
31 connect(this,SIGNAL(pointAdded(int)), this, SLOT(updateControlPoints()));
32 connect(this,SIGNAL(pointRemoved(int)), this, SLOT(updateControlPoints()));
32 connect(this,SIGNAL(pointRemoved(int)), this, SLOT(updateControlPoints()));
33 connect(this,SIGNAL(pointReplaced(int)), this, SLOT(updateControlPoints()));
33 connect(this,SIGNAL(pointReplaced(int)), this, SLOT(updateControlPoints()));
34 }
34 }
35
35
36 /*!
36 /*!
37 \internal
37 \internal
38 Calculates control points which are needed by QPainterPath.cubicTo function to draw the cubic Bezier cureve between two points.
38 Calculates control points which are needed by QPainterPath.cubicTo function to draw the cubic Bezier cureve between two points.
39 */
39 */
40 void QSplineSeries::calculateControlPoints()
40 void QSplineSeries::calculateControlPoints()
41 {
41 {
42
42
43 // Based on http://www.codeproject.com/Articles/31859/Draw-a-Smooth-Curve-through-a-Set-of-2D-Points-wit
43 // Based on http://www.codeproject.com/Articles/31859/Draw-a-Smooth-Curve-through-a-Set-of-2D-Points-wit
44 // CPOL License
44 // CPOL License
45
45
46 int n = count() - 1;
46 int n = count() - 1;
47 if (n == 1)
47 if (n == 1)
48 { // Special case: Bezier curve should be a straight line.
48 { // Special case: Bezier curve should be a straight line.
49 // firstControlPoints = new Point[1];
49 // firstControlPoints = new Point[1];
50 // 3P1 = 2P0 + P3
50 // 3P1 = 2P0 + P3
51 m_controlPoints.append(QPointF((2 * x(0) + x(1)) / 3, (2 * y(0) + y(1)) / 3));
51 m_controlPoints.append(QPointF((2 * x(0) + x(1)) / 3, (2 * y(0) + y(1)) / 3));
52
52
53 // P2 = 2P1 P0
53 // P2 = 2P1 P0
54 m_controlPoints.append(QPointF(2 * m_controlPoints[0].x() - x(0), 2 * m_controlPoints[0].y() - y(0)));
54 m_controlPoints.append(QPointF(2 * m_controlPoints[0].x() - x(0), 2 * m_controlPoints[0].y() - y(0)));
55 return;
55 return;
56 }
56 }
57
57
58 // Calculate first Bezier control points
58 // Calculate first Bezier control points
59 // Right hand side vector
59 // Right hand side vector
60 // Set of equations for P0 to Pn points.
60 // Set of equations for P0 to Pn points.
61 //
61 //
62 // | 2 1 0 0 ... 0 0 0 ... 0 0 0 | | P1_1 | | P0 + 2 * P1 |
62 // | 2 1 0 0 ... 0 0 0 ... 0 0 0 | | P1_1 | | P0 + 2 * P1 |
63 // | 1 4 1 0 ... 0 0 0 ... 0 0 0 | | P1_2 | | 4 * P1 + 2 * P2 |
63 // | 1 4 1 0 ... 0 0 0 ... 0 0 0 | | P1_2 | | 4 * P1 + 2 * P2 |
64 // | 0 1 4 1 ... 0 0 0 ... 0 0 0 | | P1_3 | | 4 * P2 + 2 * P3 |
64 // | 0 1 4 1 ... 0 0 0 ... 0 0 0 | | P1_3 | | 4 * P2 + 2 * P3 |
65 // | . . . . . . . . . . . . | | ... | | ... |
65 // | . . . . . . . . . . . . | | ... | | ... |
66 // | 0 0 0 0 ... 1 4 1 ... 0 0 0 | * | P1_i | = | 4 * P(i-1) + 2 * Pi |
66 // | 0 0 0 0 ... 1 4 1 ... 0 0 0 | * | P1_i | = | 4 * P(i-1) + 2 * Pi |
67 // | . . . . . . . . . . . . | | ... | | ... |
67 // | . . . . . . . . . . . . | | ... | | ... |
68 // | 0 0 0 0 0 0 0 0 ... 1 4 1 | | P1_(n-1)| | 4 * P(n-2) + 2 * P(n-1) |
68 // | 0 0 0 0 0 0 0 0 ... 1 4 1 | | P1_(n-1)| | 4 * P(n-2) + 2 * P(n-1) |
69 // | 0 0 0 0 0 0 0 0 ... 0 2 7 | | P1_n | | 8 * P(n-1) + Pn |
69 // | 0 0 0 0 0 0 0 0 ... 0 2 7 | | P1_n | | 8 * P(n-1) + Pn |
70 //
70 //
71 QList<qreal> rhs;
71 QList<qreal> rhs;
72 rhs.append(x(0) + 2 * x(1));
72 rhs.append(x(0) + 2 * x(1));
73
73
74 // Set right hand side X values
74 // Set right hand side X values
75 for (int i = 1; i < n - 1; ++i)
75 for (int i = 1; i < n - 1; ++i)
76 rhs.append(4 * x(i) + 2 * x(i + 1));
76 rhs.append(4 * x(i) + 2 * x(i + 1));
77
77
78 rhs.append((8 * x(n - 1) + x(n)) / 2.0);
78 rhs.append((8 * x(n - 1) + x(n)) / 2.0);
79 // Get first control points X-values
79 // Get first control points X-values
80 QList<qreal> xControl = getFirstControlPoints(rhs);
80 QList<qreal> xControl = getFirstControlPoints(rhs);
81 rhs[0] = y(0) + 2 * y(1);
81 rhs[0] = y(0) + 2 * y(1);
82
82
83 // Set right hand side Y values
83 // Set right hand side Y values
84 for (int i = 1; i < n - 1; ++i)
84 for (int i = 1; i < n - 1; ++i)
85 rhs[i] = 4 * y(i) + 2 * y(i + 1);
85 rhs[i] = 4 * y(i) + 2 * y(i + 1);
86
86
87 rhs[n - 1] = (8 * y(n - 1) + y(n)) / 2.0;
87 rhs[n - 1] = (8 * y(n - 1) + y(n)) / 2.0;
88 // Get first control points Y-values
88 // Get first control points Y-values
89 QList<qreal> yControl = getFirstControlPoints(rhs);
89 QList<qreal> yControl = getFirstControlPoints(rhs);
90
90
91 // Fill output arrays.
91 // Fill output arrays.
92 for (int i = 0; i < n; ++i)
92 for (int i = 0; i < n; ++i)
93 {
93 {
94 // First control point
94 // First control point
95 m_controlPoints.append(QPointF(xControl[i], yControl[i]));
95 m_controlPoints.append(QPointF(xControl[i], yControl[i]));
96 // Second control point
96 // Second control point
97 if (i < n - 1)
97 if (i < n - 1)
98 m_controlPoints.append(QPointF(2 * x(i + 1) - xControl[i + 1], 2 * y(i + 1) - yControl[i + 1]));
98 m_controlPoints.append(QPointF(2 * x(i + 1) - xControl[i + 1], 2 * y(i + 1) - yControl[i + 1]));
99 else
99 else
100 m_controlPoints.append(QPointF((x(n) + xControl[n - 1]) / 2, (y(n) + yControl[n - 1]) / 2));
100 m_controlPoints.append(QPointF((x(n) + xControl[n - 1]) / 2, (y(n) + yControl[n - 1]) / 2));
101 }
101 }
102 }
102 }
103
103
104 /*!
104 /*!
105 \internal
105 \internal
106 */
106 */
107 QList<qreal> QSplineSeries::getFirstControlPoints(QList<qreal> rhs)
107 QList<qreal> QSplineSeries::getFirstControlPoints(QList<qreal> rhs)
108 {
108 {
109 QList<qreal> x; // Solution vector.
109 QList<qreal> x; // Solution vector.
110 QList<qreal> tmp; // Temp workspace.
110 QList<qreal> tmp; // Temp workspace.
111
111
112 qreal b = 2.0;
112 qreal b = 2.0;
113 x.append(rhs[0] / b);
113 x.append(rhs[0] / b);
114 tmp.append(0);
114 tmp.append(0);
115 for (int i = 1; i < rhs.size(); i++) // Decomposition and forward substitution.
115 for (int i = 1; i < rhs.size(); i++) // Decomposition and forward substitution.
116 {
116 {
117 tmp.append(1 / b);
117 tmp.append(1 / b);
118 b = (i < rhs.size() - 1 ? 4.0 : 3.5) - tmp[i];
118 b = (i < rhs.size() - 1 ? 4.0 : 3.5) - tmp[i];
119 x.append((rhs[i] - x[i - 1]) / b);
119 x.append((rhs[i] - x[i - 1]) / b);
120 }
120 }
121 for (int i = 1; i < rhs.size(); i++)
121 for (int i = 1; i < rhs.size(); i++)
122 x[rhs.size() - i - 1] -= tmp[rhs.size() - i] * x[rhs.size() - i]; // Backsubstitution.
122 x[rhs.size() - i - 1] -= tmp[rhs.size() - i] * x[rhs.size() - i]; // Backsubstitution.
123
123
124 return x;
124 return x;
125 }
125 }
126
126
127 /*!
127 /*!
128 \internal
128 \internal
129 Updates the control points, besed on currently avaiable knots.
129 Updates the control points, besed on currently avaiable knots.
130 */
130 */
131 void QSplineSeries::updateControlPoints()
131 void QSplineSeries::updateControlPoints()
132 {
132 {
133 if(count() > 1)
133 if(count() > 1)
134 {
134 {
135 m_controlPoints.clear();
135 m_controlPoints.clear();
136 calculateControlPoints();
136 calculateControlPoints();
137 }
137 }
138 }
138 }
139
139
140 bool QSplineSeries::setModel(QAbstractItemModel* model)
140 bool QSplineSeries::setModel(QAbstractItemModel* model)
141 {
141 {
142 QXYSeries::setModel(model);
142 QXYSeries::setModel(model);
143 // calculateControlPoints();
143 // calculateControlPoints();
144 return true;
144 }
145 }
145
146
146 void QSplineSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation)
147 void QSplineSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation)
147 {
148 {
148 QLineSeries::setModelMapping(modelX, modelY, orientation);
149 QLineSeries::setModelMapping(modelX, modelY, orientation);
149 calculateControlPoints();
150 calculateControlPoints();
150 }
151 }
151
152
152 #include "moc_qsplineseries.cpp"
153 #include "moc_qsplineseries.cpp"
153
154
154 QTCOMMERCIALCHART_END_NAMESPACE
155 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,131 +1,132
1 !include( ../common.pri ):error( Couldn't find the common.pri file! )
1 !include( ../common.pri ):error( Couldn't find the common.pri file! )
2 TARGET = QtCommercialChart
2 TARGET = QtCommercialChart
3 DESTDIR = $$CHART_BUILD_LIB_DIR
3 DESTDIR = $$CHART_BUILD_LIB_DIR
4 TEMPLATE = lib
4 TEMPLATE = lib
5 QT += core \
5 QT += core \
6 gui
6 gui
7 win32: LIBS += User32.lib
7 CONFIG += debug_and_release
8 CONFIG += debug_and_release
8 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
9 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
9 SOURCES += \
10 SOURCES += \
10 chartdataset.cpp \
11 chartdataset.cpp \
11 chartpresenter.cpp \
12 chartpresenter.cpp \
12 charttheme.cpp \
13 charttheme.cpp \
13 domain.cpp \
14 domain.cpp \
14 qchart.cpp \
15 qchart.cpp \
15 qchartview.cpp \
16 qchartview.cpp \
16 qseries.cpp \
17 qseries.cpp \
17 qlegend.cpp \
18 qlegend.cpp \
18 legendmarker.cpp
19 legendmarker.cpp
19 PRIVATE_HEADERS += \
20 PRIVATE_HEADERS += \
20 chartdataset_p.h \
21 chartdataset_p.h \
21 chartitem_p.h \
22 chartitem_p.h \
22 chartpresenter_p.h \
23 chartpresenter_p.h \
23 charttheme_p.h \
24 charttheme_p.h \
24 domain_p.h \
25 domain_p.h \
25 legendmarker_p.h
26 legendmarker_p.h
26 PUBLIC_HEADERS += \
27 PUBLIC_HEADERS += \
27 qchart.h \
28 qchart.h \
28 qchartglobal.h \
29 qchartglobal.h \
29 qseries.h \
30 qseries.h \
30 qchartview.h \
31 qchartview.h \
31 qlegend.h
32 qlegend.h
32
33
33 include(animations/animations.pri)
34 include(animations/animations.pri)
34 include(axis/axis.pri)
35 include(axis/axis.pri)
35 include(xychart/xychart.pri)
36 include(xychart/xychart.pri)
36 include(linechart/linechart.pri)
37 include(linechart/linechart.pri)
37 include(areachart/areachart.pri)
38 include(areachart/areachart.pri)
38 include(barchart/barchart.pri)
39 include(barchart/barchart.pri)
39 include(piechart/piechart.pri)
40 include(piechart/piechart.pri)
40 include(scatterseries/scatter.pri)
41 include(scatterseries/scatter.pri)
41 include(splinechart/splinechart.pri)
42 include(splinechart/splinechart.pri)
42
43
43 THEMES += themes/chartthemedefault_p.h \
44 THEMES += themes/chartthemedefault_p.h \
44 themes/chartthemeicy_p.h \
45 themes/chartthemeicy_p.h \
45 themes/chartthemegrayscale_p.h \
46 themes/chartthemegrayscale_p.h \
46 themes/chartthemescientific_p.h \
47 themes/chartthemescientific_p.h \
47 themes/chartthemevanilla_p.h \
48 themes/chartthemevanilla_p.h \
48 themes/chartthemebluecerulean_p.h \
49 themes/chartthemebluecerulean_p.h \
49 themes/chartthemelight_p.h
50 themes/chartthemelight_p.h
50
51
51 HEADERS += $$PUBLIC_HEADERS
52 HEADERS += $$PUBLIC_HEADERS
52 HEADERS += $$PRIVATE_HEADERS
53 HEADERS += $$PRIVATE_HEADERS
53 HEADERS += $$THEMES
54 HEADERS += $$THEMES
54 INCLUDEPATH += linechart \
55 INCLUDEPATH += linechart \
55 barchart \
56 barchart \
56 themes \
57 themes \
57 .
58 .
58 OBJECTS_DIR = $$CHART_BUILD_DIR/lib
59 OBJECTS_DIR = $$CHART_BUILD_DIR/lib
59 MOC_DIR = $$CHART_BUILD_DIR/lib
60 MOC_DIR = $$CHART_BUILD_DIR/lib
60 UI_DIR = $$CHART_BUILD_DIR/lib
61 UI_DIR = $$CHART_BUILD_DIR/lib
61 RCC_DIR = $$CHART_BUILD_DIR/lib
62 RCC_DIR = $$CHART_BUILD_DIR/lib
62 DEFINES += QTCOMMERCIALCHART_LIBRARY
63 DEFINES += QTCOMMERCIALCHART_LIBRARY
63
64
64 #qt public headers
65 #qt public headers
65 #this is very primitive and lame parser , TODO: make perl script insted
66 #this is very primitive and lame parser , TODO: make perl script insted
66 !exists($$CHART_BUILD_PUBLIC_HEADER_DIR)
67 !exists($$CHART_BUILD_PUBLIC_HEADER_DIR)
67 {
68 {
68 system($$QMAKE_MKDIR $$CHART_BUILD_PUBLIC_HEADER_DIR)
69 system($$QMAKE_MKDIR $$CHART_BUILD_PUBLIC_HEADER_DIR)
69 }
70 }
70
71
71 for(file, PUBLIC_HEADERS) {
72 for(file, PUBLIC_HEADERS) {
72 name = $$split(file,'/')
73 name = $$split(file,'/')
73 name = $$last(name)
74 name = $$last(name)
74 class = "$$cat($$file)"
75 class = "$$cat($$file)"
75 class = $$find(class,class)
76 class = $$find(class,class)
76 !isEmpty(class){
77 !isEmpty(class){
77 class = $$split(class,QTCOMMERCIALCHART_EXPORT)
78 class = $$split(class,QTCOMMERCIALCHART_EXPORT)
78 class = $$member(class,1)
79 class = $$member(class,1)
79 class = $$split(class,' ')
80 class = $$split(class,' ')
80 class = $$replace(class,' ','')
81 class = $$replace(class,' ','')
81 class = $$member(class,0)
82 class = $$member(class,0)
82 command = "echo \"$${LITERAL_HASH}include \\\"$$name\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class"
83 command = "echo $${LITERAL_HASH}include \"$$name\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class"
83 PUBLIC_QT_HEADERS += $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class
84 PUBLIC_QT_HEADERS += $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class
84 system($$command)
85 system($$command)
85 }
86 }
86 }
87 }
87
88
88 public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart
89 public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart
89 public_headers.files = $$PUBLIC_HEADERS $$PUBLIC_QT_HEADERS
90 public_headers.files = $$PUBLIC_HEADERS $$PUBLIC_QT_HEADERS
90
91
91 target.path = $$[QT_INSTALL_LIBS]
92 target.path = $$[QT_INSTALL_LIBS]
92 INSTALLS += target public_headers
93 INSTALLS += target public_headers
93
94
94 install_build_public_headers.name = build_public_headers
95 install_build_public_headers.name = build_public_headers
95 install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h
96 install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h
96 install_build_public_headers.input = PUBLIC_HEADERS
97 install_build_public_headers.input = PUBLIC_HEADERS
97 install_build_public_headers.commands = $$QMAKE_COPY \
98 install_build_public_headers.commands = $$QMAKE_COPY \
98 ${QMAKE_FILE_NAME} \
99 ${QMAKE_FILE_NAME} \
99 $$CHART_BUILD_PUBLIC_HEADER_DIR
100 $$CHART_BUILD_PUBLIC_HEADER_DIR
100 install_build_public_headers.CONFIG += target_predeps \
101 install_build_public_headers.CONFIG += target_predeps \
101 no_link
102 no_link
102
103
103 install_build_private_headers.name = buld_private_headers
104 install_build_private_headers.name = buld_private_headers
104 install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h
105 install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h
105 install_build_private_headers.input = PRIVATE_HEADERS
106 install_build_private_headers.input = PRIVATE_HEADERS
106 install_build_private_headers.commands = $$QMAKE_COPY \
107 install_build_private_headers.commands = $$QMAKE_COPY \
107 ${QMAKE_FILE_NAME} \
108 ${QMAKE_FILE_NAME} \
108 $$CHART_BUILD_PRIVATE_HEADER_DIR
109 $$CHART_BUILD_PRIVATE_HEADER_DIR
109 install_build_private_headers.CONFIG += target_predeps \
110 install_build_private_headers.CONFIG += target_predeps \
110 no_link
111 no_link
111
112
112 QMAKE_EXTRA_COMPILERS += install_build_public_headers \
113 QMAKE_EXTRA_COMPILERS += install_build_public_headers \
113 install_build_private_headers \
114 install_build_private_headers \
114
115
115 chartversion.target = qchartversion_p.h
116 chartversion.target = qchartversion_p.h
116 chartversion.commands = @echo \
117 chartversion.commands = @echo \
117 "build_time" \
118 "build_time" \
118 > \
119 > \
119 $$chartversion.target;
120 $$chartversion.target;
120 chartversion.depends = $$HEADERS \
121 chartversion.depends = $$HEADERS \
121 $$SOURCES
122 $$SOURCES
122 PRE_TARGETDEPS += qchartversion_p.h
123 PRE_TARGETDEPS += qchartversion_p.h
123 QMAKE_CLEAN += qchartversion_p.h
124 QMAKE_CLEAN += qchartversion_p.h
124 QMAKE_EXTRA_TARGETS += chartversion
125 QMAKE_EXTRA_TARGETS += chartversion
125 unix:QMAKE_DISTCLEAN += -r \
126 unix:QMAKE_DISTCLEAN += -r \
126 $$CHART_BUILD_HEADER_DIR \
127 $$CHART_BUILD_HEADER_DIR \
127 $$CHART_BUILD_LIB_DIR
128 $$CHART_BUILD_LIB_DIR
128 win32:QMAKE_DISTCLEAN += /Q \
129 win32:QMAKE_DISTCLEAN += /Q \
129 $$CHART_BUILD_HEADER_DIR \
130 $$CHART_BUILD_HEADER_DIR \
130 $$CHART_BUILD_LIB_DIR
131 $$CHART_BUILD_LIB_DIR
131
132
@@ -1,310 +1,311
1 #include "qxyseries.h"
1 #include "qxyseries.h"
2
2
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
4
5 /*!
5 /*!
6 \class QXYSeries
6 \class QXYSeries
7 \brief The QXYSeries class is a base class for line, spline and scatter series.
7 \brief The QXYSeries class is a base class for line, spline and scatter series.
8 */
8 */
9
9
10 /*!
10 /*!
11 \fn QPen QXYSeries::pen() const
11 \fn QPen QXYSeries::pen() const
12 \brief Returns pen used to draw points for series.
12 \brief Returns pen used to draw points for series.
13 \sa setPen()
13 \sa setPen()
14 */
14 */
15
15
16 /*!
16 /*!
17 \fn QBrush QXYSeries::brush() const
17 \fn QBrush QXYSeries::brush() const
18 \brief Returns brush used to draw points for series.
18 \brief Returns brush used to draw points for series.
19 \sa setBrush()
19 \sa setBrush()
20 */
20 */
21
21
22 /*!
22 /*!
23 \fn void QXYSeries::clicked(const QPointF& point)
23 \fn void QXYSeries::clicked(const QPointF& point)
24 \brief Signal is emitted when user clicks the \a point on chart.
24 \brief Signal is emitted when user clicks the \a point on chart.
25 */
25 */
26
26
27 /*!
27 /*!
28 \fn void QXYSeries::pointReplaced(int index)
28 \fn void QXYSeries::pointReplaced(int index)
29 \brief \internal \a index
29 \brief \internal \a index
30 */
30 */
31
31
32 /*!
32 /*!
33 \fn void QXYSeries::pointAdded(int index)
33 \fn void QXYSeries::pointAdded(int index)
34 \brief \internal \a index
34 \brief \internal \a index
35 */
35 */
36
36
37 /*!
37 /*!
38 \fn void QXYSeries::pointRemoved(int index)
38 \fn void QXYSeries::pointRemoved(int index)
39 \brief \internal \a index
39 \brief \internal \a index
40 */
40 */
41
41
42 /*!
42 /*!
43 \fn void QXYSeries::updated()
43 \fn void QXYSeries::updated()
44 \brief \internal
44 \brief \internal
45 */
45 */
46
46
47 /*!
47 /*!
48 Constructs empty series object which is a child of \a parent.
48 Constructs empty series object which is a child of \a parent.
49 When series object is added to QChartView or QChart instance ownerships is transfered.
49 When series object is added to QChartView or QChart instance ownerships is transfered.
50 */
50 */
51 QXYSeries::QXYSeries(QObject* parent):QSeries(parent)
51 QXYSeries::QXYSeries(QObject* parent):QSeries(parent)
52 {
52 {
53 m_mapX = -1;
53 m_mapX = -1;
54 m_mapY = -1;
54 m_mapY = -1;
55 m_mapOrientation = Qt::Vertical;
55 m_mapOrientation = Qt::Vertical;
56 // m_mapYOrientation = Qt::Vertical;
56 // m_mapYOrientation = Qt::Vertical;
57 }
57 }
58 /*!
58 /*!
59 Destroys the object. Series added to QChartView or QChart instances are owned by those,
59 Destroys the object. Series added to QChartView or QChart instances are owned by those,
60 and are deleted when mentioned object are destroyed.
60 and are deleted when mentioned object are destroyed.
61 */
61 */
62 QXYSeries::~QXYSeries()
62 QXYSeries::~QXYSeries()
63 {
63 {
64 }
64 }
65
65
66 /*!
66 /*!
67 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
67 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
68 */
68 */
69 void QXYSeries::add(qreal x,qreal y)
69 void QXYSeries::add(qreal x,qreal y)
70 {
70 {
71 Q_ASSERT(m_x.size() == m_y.size());
71 Q_ASSERT(m_x.size() == m_y.size());
72 m_x<<x;
72 m_x<<x;
73 m_y<<y;
73 m_y<<y;
74 emit pointAdded(m_x.size()-1);
74 emit pointAdded(m_x.size()-1);
75 }
75 }
76
76
77 /*!
77 /*!
78 This is an overloaded function.
78 This is an overloaded function.
79 Adds data \a point to the series. Points are connected with lines on the chart.
79 Adds data \a point to the series. Points are connected with lines on the chart.
80 */
80 */
81 void QXYSeries::add(const QPointF& point)
81 void QXYSeries::add(const QPointF& point)
82 {
82 {
83 add(point.x(),point.y());
83 add(point.x(),point.y());
84 }
84 }
85
85
86 /*!
86 /*!
87 This is an overloaded function.
87 This is an overloaded function.
88 Adds list of data \a points to the series. Points are connected with lines on the chart.
88 Adds list of data \a points to the series. Points are connected with lines on the chart.
89 */
89 */
90 void QXYSeries::add(const QList<QPointF> points)
90 void QXYSeries::add(const QList<QPointF> points)
91 {
91 {
92 foreach(const QPointF& point , points) {
92 foreach(const QPointF& point , points) {
93 add(point.x(),point.y());
93 add(point.x(),point.y());
94 }
94 }
95 }
95 }
96
96
97 /*!
97 /*!
98 Modifies \a y value for given \a x a value.
98 Modifies \a y value for given \a x a value.
99 */
99 */
100 void QXYSeries::replace(qreal x,qreal y)
100 void QXYSeries::replace(qreal x,qreal y)
101 {
101 {
102 int index = m_x.indexOf(x);
102 int index = m_x.indexOf(x);
103 m_x[index]=x;
103 m_x[index]=x;
104 m_y[index]=y;
104 m_y[index]=y;
105 emit pointReplaced(index);
105 emit pointReplaced(index);
106 }
106 }
107
107
108 /*!
108 /*!
109 This is an overloaded function.
109 This is an overloaded function.
110 Replaces current y value of for given \a point x value with \a point y value.
110 Replaces current y value of for given \a point x value with \a point y value.
111 */
111 */
112 void QXYSeries::replace(const QPointF& point)
112 void QXYSeries::replace(const QPointF& point)
113 {
113 {
114 replace(point.x(),point.y());
114 replace(point.x(),point.y());
115 }
115 }
116
116
117 /*!
117 /*!
118 Removes current \a x and \a y value.
118 Removes current \a x and \a y value.
119 */
119 */
120 void QXYSeries::remove(qreal x,qreal y)
120 void QXYSeries::remove(qreal x,qreal y)
121 {
121 {
122 int index =-1;
122 int index =-1;
123 do{
123 do{
124 index = m_x.indexOf(x,index+1);
124 index = m_x.indexOf(x,index+1);
125 }while(index !=-1 && m_y.at(index)!=y);
125 }while(index !=-1 && m_y.at(index)!=y);
126
126
127 if(index==-1) return;
127 if(index==-1) return;
128
128
129 m_x.remove(index);
129 m_x.remove(index);
130 m_y.remove(index);
130 m_y.remove(index);
131 emit pointRemoved(index);
131 emit pointRemoved(index);
132 }
132 }
133
133
134 /*!
134 /*!
135 Removes current \a point x value. Note \a point y value is ignored.
135 Removes current \a point x value. Note \a point y value is ignored.
136 */
136 */
137 void QXYSeries::remove(const QPointF& point)
137 void QXYSeries::remove(const QPointF& point)
138 {
138 {
139 remove(point.x(),point.y());
139 remove(point.x(),point.y());
140 }
140 }
141
141
142 /*!
142 /*!
143 Removes all data points from the series.
143 Removes all data points from the series.
144 */
144 */
145 void QXYSeries::removeAll()
145 void QXYSeries::removeAll()
146 {
146 {
147 m_x.clear();
147 m_x.clear();
148 m_y.clear();
148 m_y.clear();
149 }
149 }
150
150
151 /*!
151 /*!
152 \internal \a pos
152 \internal \a pos
153 */
153 */
154 qreal QXYSeries::x(int pos) const
154 qreal QXYSeries::x(int pos) const
155 {
155 {
156 if (m_model)
156 if (m_model)
157 if (m_mapOrientation == Qt::Vertical)
157 if (m_mapOrientation == Qt::Vertical)
158 // consecutive data is read from model's column
158 // consecutive data is read from model's column
159 return m_model->data(m_model->index(pos, m_mapX), Qt::DisplayRole).toDouble();
159 return m_model->data(m_model->index(pos, m_mapX), Qt::DisplayRole).toDouble();
160 else
160 else
161 // consecutive data is read from model's row
161 // consecutive data is read from model's row
162 return m_model->data(m_model->index(m_mapX, pos), Qt::DisplayRole).toDouble();
162 return m_model->data(m_model->index(m_mapX, pos), Qt::DisplayRole).toDouble();
163 else
163 else
164 // model is not specified, return the data from series' internal data store
164 // model is not specified, return the data from series' internal data store
165 return m_x.at(pos);
165 return m_x.at(pos);
166 }
166 }
167
167
168 /*!
168 /*!
169 \internal \a pos
169 \internal \a pos
170 */
170 */
171 qreal QXYSeries::y(int pos) const
171 qreal QXYSeries::y(int pos) const
172 {
172 {
173 if (m_model)
173 if (m_model)
174 if (m_mapOrientation == Qt::Vertical)
174 if (m_mapOrientation == Qt::Vertical)
175 // consecutive data is read from model's column
175 // consecutive data is read from model's column
176 return m_model->data(m_model->index(pos, m_mapY), Qt::DisplayRole).toDouble();
176 return m_model->data(m_model->index(pos, m_mapY), Qt::DisplayRole).toDouble();
177 else
177 else
178 // consecutive data is read from model's row
178 // consecutive data is read from model's row
179 return m_model->data(m_model->index(m_mapY, pos), Qt::DisplayRole).toDouble();
179 return m_model->data(m_model->index(m_mapY, pos), Qt::DisplayRole).toDouble();
180 else
180 else
181 // model is not specified, return the data from series' internal data store
181 // model is not specified, return the data from series' internal data store
182 return m_y.at(pos);
182 return m_y.at(pos);
183 }
183 }
184
184
185 /*!
185 /*!
186 Returns number of data points within series.
186 Returns number of data points within series.
187 */
187 */
188 int QXYSeries::count() const
188 int QXYSeries::count() const
189 {
189 {
190 Q_ASSERT(m_x.size() == m_y.size());
190 Q_ASSERT(m_x.size() == m_y.size());
191
191
192 if (m_model)
192 if (m_model)
193 if (m_mapOrientation == Qt::Vertical)
193 if (m_mapOrientation == Qt::Vertical)
194 // data is in a column, so return the number of items in single column
194 // data is in a column, so return the number of items in single column
195 return m_model->rowCount();
195 return m_model->rowCount();
196 else
196 else
197 // data is in a row, so return the number of items in single row
197 // data is in a row, so return the number of items in single row
198 m_model->columnCount();
198 m_model->columnCount();
199 else
199 else
200 // model is not specified, return the number of points in the series internal data store
200 // model is not specified, return the number of points in the series internal data store
201 return m_x.size();
201 return m_x.size();
202 }
202 }
203
203
204 /*!
204 /*!
205 Returns the data points of the series.
205 Returns the data points of the series.
206 */
206 */
207 QList<QPointF> QXYSeries::data()
207 QList<QPointF> QXYSeries::data()
208 {
208 {
209 QList<QPointF> data;
209 QList<QPointF> data;
210 for (int i(0); i < m_x.count() && i < m_y.count(); i++)
210 for (int i(0); i < m_x.count() && i < m_y.count(); i++)
211 data.append(QPointF(m_x.at(i), m_y.at(i)));
211 data.append(QPointF(m_x.at(i), m_y.at(i)));
212 return data;
212 return data;
213 }
213 }
214
214
215
215
216 /*!
216 /*!
217 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
217 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
218 pen from chart theme is used.
218 pen from chart theme is used.
219 \sa QChart::setChartTheme()
219 \sa QChart::setChartTheme()
220 */
220 */
221 void QXYSeries::setPen(const QPen& pen)
221 void QXYSeries::setPen(const QPen& pen)
222 {
222 {
223 if(pen!=m_pen){
223 if(pen!=m_pen){
224 m_pen=pen;
224 m_pen=pen;
225 emit updated();
225 emit updated();
226 }
226 }
227 }
227 }
228
228
229 /*!
229 /*!
230 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
230 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
231 from chart theme setting is used.
231 from chart theme setting is used.
232 \sa QChart::setChartTheme()
232 \sa QChart::setChartTheme()
233 */
233 */
234
234
235 void QXYSeries::setBrush(const QBrush& brush)
235 void QXYSeries::setBrush(const QBrush& brush)
236 {
236 {
237 if(brush!=m_brush){
237 if(brush!=m_brush){
238 m_brush=brush;
238 m_brush=brush;
239 emit updated();
239 emit updated();
240 }
240 }
241 }
241 }
242
242
243
243
244 /*!
244 /*!
245 Stream operator for adding a data \a point to the series.
245 Stream operator for adding a data \a point to the series.
246 \sa add()
246 \sa add()
247 */
247 */
248
248
249 QXYSeries& QXYSeries::operator<< (const QPointF &point)
249 QXYSeries& QXYSeries::operator<< (const QPointF &point)
250 {
250 {
251 add(point);
251 add(point);
252 return *this;
252 return *this;
253 }
253 }
254
254
255
255
256 /*!
256 /*!
257 Stream operator for adding a list of \a points to the series.
257 Stream operator for adding a list of \a points to the series.
258 \sa add()
258 \sa add()
259 */
259 */
260
260
261 QXYSeries& QXYSeries::operator<< (const QList<QPointF> points)
261 QXYSeries& QXYSeries::operator<< (const QList<QPointF> points)
262 {
262 {
263 add(points);
263 add(points);
264 return *this;
264 return *this;
265 }
265 }
266
266
267
267
268 void QXYSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
268 void QXYSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
269 {
269 {
270 if (m_mapOrientation == Qt::Vertical)
270 if (m_mapOrientation == Qt::Vertical)
271 emit pointReplaced(topLeft.row());
271 emit pointReplaced(topLeft.row());
272 else
272 else
273 emit pointReplaced(topLeft.column());
273 emit pointReplaced(topLeft.column());
274 }
274 }
275
275
276 void QXYSeries::modelDataAdded(QModelIndex parent, int start, int end)
276 void QXYSeries::modelDataAdded(QModelIndex parent, int start, int end)
277 {
277 {
278 emit pointAdded(start);
278 emit pointAdded(start);
279 }
279 }
280
280
281 void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end)
281 void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end)
282 {
282 {
283 emit pointRemoved(start);
283 emit pointRemoved(start);
284 }
284 }
285
285
286 bool QXYSeries::setModel(QAbstractItemModel* model) {
286 bool QXYSeries::setModel(QAbstractItemModel* model) {
287 m_model = model;
287 m_model = model;
288 // for (int i = 0; i < m_model->rowCount(); i++)
288 // for (int i = 0; i < m_model->rowCount(); i++)
289 // emit pointAdded(i);
289 // emit pointAdded(i);
290 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
290 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
291 connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
291 connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
292 connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int)));
292 connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int)));
293 return true;
293 }
294 }
294
295
295 void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation)
296 void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation)
296 {
297 {
297 m_mapX = modelX;
298 m_mapX = modelX;
298 m_mapY = modelY;
299 m_mapY = modelY;
299 m_mapOrientation = orientation;
300 m_mapOrientation = orientation;
300 }
301 }
301
302
302 //void QXYSeries::setModelMappingY(int modelLineIndex, Qt::Orientation orientation)
303 //void QXYSeries::setModelMappingY(int modelLineIndex, Qt::Orientation orientation)
303 //{
304 //{
304 // m_mapY = modelLineIndex;
305 // m_mapY = modelLineIndex;
305 // m_mapYOrientation = orientation;
306 // m_mapYOrientation = orientation;
306 //}
307 //}
307
308
308 #include "moc_qxyseries.cpp"
309 #include "moc_qxyseries.cpp"
309
310
310 QTCOMMERCIALCHART_END_NAMESPACE
311 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now