##// END OF EJS Templates
review fix: Removed iterator from barseries. Remove const from brush and pen. Renamed setters for tooltip, floating values and separators
sauimone -
r357:82b904eaae07
parent child
Show More
@@ -47,7 +47,7 int main(int argc, char *argv[])
47
47
48 //! [4]
48 //! [4]
49 // Enable some features
49 // Enable some features
50 series->enableToolTip();
50 series->setToolTipEnabled();
51 series->enableFloatingValues();
51 series->enableFloatingValues();
52 //! [4]
52 //! [4]
53
53
@@ -47,7 +47,7 int main(int argc, char *argv[])
47
47
48 //! [4]
48 //! [4]
49 // Enable features
49 // Enable features
50 series->enableToolTip();
50 series->setToolTipEnabled();
51 series->enableFloatingValues();
51 series->enableFloatingValues();
52 //! [4]
52 //! [4]
53
53
@@ -46,7 +46,7 int main(int argc, char *argv[])
46
46
47 //! [4]
47 //! [4]
48 // Enable features
48 // Enable features
49 series->enableToolTip();
49 series->setToolTipEnabled();
50 series->enableFloatingValues();
50 series->enableFloatingValues();
51 //! [4]
51 //! [4]
52
52
@@ -36,24 +36,14 void BarChartModel::removeBarSet(QBarSet *set)
36 }
36 }
37 }
37 }
38
38
39 QBarSet* BarChartModel::nextSet(bool getFirst)
39 QBarSet* BarChartModel::setAt(int index)
40 {
40 {
41 if (getFirst) {
41 return mDataModel.at(index);
42 mCurrentSet = 0;
43 }
44
45 if ((mDataModel.count() <= 0) || (mDataModel.count() <= mCurrentSet)) {
46 return 0;
47 }
48
49 QBarSet* set = mDataModel.at(mCurrentSet);
50 mCurrentSet++;
51 return set;
52 }
42 }
53
43
54 QBarSet* BarChartModel::setAt(int index)
44 QList<QBarSet*> BarChartModel::barSets()
55 {
45 {
56 return mDataModel.at(index);
46 return mDataModel;
57 }
47 }
58
48
59 QList<QString> BarChartModel::legend()
49 QList<QString> BarChartModel::legend()
@@ -22,8 +22,9 public:
22 QBarCategory& category();
22 QBarCategory& category();
23 void addBarSet(QBarSet *set);
23 void addBarSet(QBarSet *set);
24 void removeBarSet(QBarSet *set);
24 void removeBarSet(QBarSet *set);
25 QBarSet* nextSet(bool getFirst);
26 QBarSet *setAt(int index);
25 QBarSet *setAt(int index);
26 QList<QBarSet*> barSets();
27
27 QList<QString> legend();
28 QList<QString> legend();
28
29
29 int countSets(); // Number of sets in model
30 int countSets(); // Number of sets in model
@@ -52,7 +52,7 void BarPresenter::layoutChanged()
52
52
53 // TODO: width settable per bar?
53 // TODO: width settable per bar?
54 bar->resize(mBarDefaultWidth, barHeight);
54 bar->resize(mBarDefaultWidth, barHeight);
55 bar->setBrush(mSeries->setAt(set)->brush());
55 bar->setBrush(mSeries->barsetAt(set)->brush());
56 bar->setPos(xPos, yPos-barHeight);
56 bar->setPos(xPos, yPos-barHeight);
57 itemIndex++;
57 itemIndex++;
58 xPos += mBarDefaultWidth;
58 xPos += mBarDefaultWidth;
@@ -70,7 +70,7 void BarPresenterBase::dataChanged()
70 // Create new graphic items for bars
70 // Create new graphic items for bars
71 for (int c=0; c<mSeries->countCategories(); c++) {
71 for (int c=0; c<mSeries->countCategories(); c++) {
72 for (int s=0; s<mSeries->countSets(); s++) {
72 for (int s=0; s<mSeries->countSets(); s++) {
73 QBarSet *set = mSeries->setAt(s);
73 QBarSet *set = mSeries->barsetAt(s);
74 Bar *bar = new Bar(this);
74 Bar *bar = new Bar(this);
75 childItems().append(bar);
75 childItems().append(bar);
76 mBars.append(bar);
76 mBars.append(bar);
@@ -102,7 +102,7 void BarPresenterBase::dataChanged()
102 // Create floating values
102 // Create floating values
103 for (int category=0; category<mSeries->countCategories(); category++) {
103 for (int category=0; category<mSeries->countCategories(); category++) {
104 for (int s=0; s<mSeries->countSets(); s++) {
104 for (int s=0; s<mSeries->countSets(); s++) {
105 QBarSet *set = mSeries->setAt(s);
105 QBarSet *set = mSeries->barsetAt(s);
106 BarValue *value = new BarValue(*set, this);
106 BarValue *value = new BarValue(*set, this);
107 childItems().append(value);
107 childItems().append(value);
108 mFloatingValues.append(value);
108 mFloatingValues.append(value);
@@ -50,7 +50,7 void PercentBarPresenter::layoutChanged()
50
50
51 // TODO: width settable per bar?
51 // TODO: width settable per bar?
52 bar->resize(mBarDefaultWidth, barHeight);
52 bar->resize(mBarDefaultWidth, barHeight);
53 bar->setBrush(mSeries->setAt(set)->brush());
53 bar->setBrush(mSeries->barsetAt(set)->brush());
54 bar->setPos(xPos, yPos-barHeight);
54 bar->setPos(xPos, yPos-barHeight);
55 itemIndex++;
55 itemIndex++;
56 yPos -= barHeight;
56 yPos -= barHeight;
@@ -17,21 +17,6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
17
17
18 \mainclass
18 \mainclass
19
19
20 Example on how to create category:
21 \snippet ../example/barchart/main.cpp 1
22
23 Example on how to create sets of data:
24 \snippet ../example/barchart/main.cpp 2
25
26 Example on how to add sets to bar chart:
27 \snippet ../example/barchart/main.cpp 3
28
29 Example on how to enable tooltip and floating values:
30 \snippet ../example/barchart/main.cpp 4
31
32 Example on how to create view and apply theme:
33 \snippet ../example/barchart/main.cpp 5
34
35 \sa QBarCategory, QBarSet, QStackedBarSeries, QPercentBarSeries
20 \sa QBarCategory, QBarSet, QStackedBarSeries, QPercentBarSeries
36 */
21 */
37
22
@@ -105,22 +90,17 int QBarSeries::countCategories()
105 }
90 }
106
91
107 /*!
92 /*!
108 Simple iterator for set. Returns pointer to next set in series.
93 Returns a list of sets in series. Keeps ownership of sets.
109 Returns first set, if parameter \a getFirst is true.
110 If series is empty, returns 0.
111 Returns 0 after last set.
112 */
94 */
113 QBarSet* QBarSeries::nextSet(bool getFirst)
95 QList<QBarSet*> QBarSeries::barSets()
114 {
96 {
115 return mModel->nextSet(getFirst);
97 return mModel->barSets();
116 }
98 }
117
99
118 /*!
100 /*!
119 Returns set indexed by \a index. Doesn't check for index bounds.
101 \internal \a index
120 Assumes that \a index is between 0 and number of sets. Use countSets() to get valid index bound.
121 \sa countSets()
122 */
102 */
123 QBarSet* QBarSeries::setAt(int index)
103 QBarSet* QBarSeries::barsetAt(int index)
124 {
104 {
125 return mModel->setAt(index);
105 return mModel->setAt(index);
126 }
106 }
@@ -146,7 +126,7 QString QBarSeries::label(int category)
146 Floating values are bar values, that are displayed on top of each bar.
126 Floating values are bar values, that are displayed on top of each bar.
147 Calling without parameter \a enabled, enables the floating values
127 Calling without parameter \a enabled, enables the floating values
148 */
128 */
149 void QBarSeries::enableFloatingValues(bool enabled)
129 void QBarSeries::setFloatingValuesEnabled(bool enabled)
150 {
130 {
151 if (enabled) {
131 if (enabled) {
152 for (int i=0; i<mModel->countSets(); i++) {
132 for (int i=0; i<mModel->countSets(); i++) {
@@ -166,7 +146,7 void QBarSeries::enableFloatingValues(bool enabled)
166 Tooltip shows the name of set, when mouse is hovering on top of bar.
146 Tooltip shows the name of set, when mouse is hovering on top of bar.
167 Calling without parameter \a enabled, enables the tooltip
147 Calling without parameter \a enabled, enables the tooltip
168 */
148 */
169 void QBarSeries::enableToolTip(bool enabled)
149 void QBarSeries::setToolTipEnabled(bool enabled)
170 {
150 {
171 if (enabled) {
151 if (enabled) {
172 for (int i=0; i<mModel->countSets(); i++) {
152 for (int i=0; i<mModel->countSets(); i++) {
@@ -186,7 +166,7 void QBarSeries::enableToolTip(bool enabled)
186 Separators are visual elements that are drawn between categories.
166 Separators are visual elements that are drawn between categories.
187 Calling without parameter \a enabled, enables the separators
167 Calling without parameter \a enabled, enables the separators
188 */
168 */
189 void QBarSeries::enableSeparators(bool enabled)
169 void QBarSeries::setSeparatorsEnabled(bool enabled)
190 {
170 {
191 emit separatorsEnabled(enabled);
171 emit separatorsEnabled(enabled);
192 }
172 }
@@ -22,8 +22,7 public:
22 void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set
22 void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set
23 int countSets();
23 int countSets();
24 int countCategories();
24 int countCategories();
25 QBarSet* nextSet(bool getFirst=false); // Returns first set, if called with true
25 QList<QBarSet*> barSets();
26 QBarSet *setAt(int index);
27
26
28 QList<QString> legend(); // Returns legend of series (ie. names of all sets in series)
27 QList<QString> legend(); // Returns legend of series (ie. names of all sets in series)
29
28
@@ -31,6 +30,7 public:
31 // TODO: Functions below this are not part of api and will be moved
30 // TODO: Functions below this are not part of api and will be moved
32 // to private implementation, when we start using it
31 // to private implementation, when we start using it
33 // TODO: TO PIMPL --->
32 // TODO: TO PIMPL --->
33 QBarSet *barsetAt(int index);
34 QString label(int category);
34 QString label(int category);
35 qreal min();
35 qreal min();
36 qreal max();
36 qreal max();
@@ -53,9 +53,9 signals:
53 // <--- TO PIMPL
53 // <--- TO PIMPL
54
54
55 public Q_SLOTS:
55 public Q_SLOTS:
56 void enableFloatingValues(bool enabled=true); // enables floating values on top of bars
56 void setFloatingValuesEnabled(bool enabled=true); // enables floating values on top of bars
57 void enableToolTip(bool enabled=true); // enables tooltips
57 void setToolTipEnabled(bool enabled=true); // enables tooltips
58 void enableSeparators(bool enabled=true); // enables separators between categories
58 void setSeparatorsEnabled(bool enabled=true); // enables separators between categories
59
59
60 protected:
60 protected:
61 BarChartModel* mModel;
61 BarChartModel* mModel;
@@ -104,7 +104,7 void QBarSet::setValue(int index, qreal value)
104 /*!
104 /*!
105 Sets pen for set. Bars of this set are drawn using \a pen
105 Sets pen for set. Bars of this set are drawn using \a pen
106 */
106 */
107 void QBarSet::setPen(const QPen& pen)
107 void QBarSet::setPen(QPen pen)
108 {
108 {
109 mPen = pen;
109 mPen = pen;
110 }
110 }
@@ -112,7 +112,7 void QBarSet::setPen(const QPen& pen)
112 /*!
112 /*!
113 Returns pen of the set.
113 Returns pen of the set.
114 */
114 */
115 const QPen& QBarSet::pen() const
115 QPen QBarSet::pen()
116 {
116 {
117 return mPen;
117 return mPen;
118 }
118 }
@@ -120,7 +120,7 const QPen& QBarSet::pen() const
120 /*!
120 /*!
121 Sets brush for the set. Bars of this set are drawn using \a brush
121 Sets brush for the set. Bars of this set are drawn using \a brush
122 */
122 */
123 void QBarSet::setBrush(const QBrush& brush)
123 void QBarSet::setBrush(QBrush brush)
124 {
124 {
125 mBrush = brush;
125 mBrush = brush;
126 }
126 }
@@ -128,7 +128,7 void QBarSet::setBrush(const QBrush& brush)
128 /*!
128 /*!
129 Returns brush of the set.
129 Returns brush of the set.
130 */
130 */
131 const QBrush& QBarSet::brush() const
131 QBrush QBarSet::brush()
132 {
132 {
133 return mBrush;
133 return mBrush;
134 }
134 }
@@ -21,11 +21,11 public:
21 qreal valueAt(int index); // for modifying individual values
21 qreal valueAt(int index); // for modifying individual values
22 void setValue(int index, qreal value); // setter for individual value
22 void setValue(int index, qreal value); // setter for individual value
23
23
24 void setPen(const QPen& pen);
24 void setPen(QPen pen);
25 const QPen& pen() const;
25 QPen pen();
26
26
27 void setBrush(const QBrush& brush);
27 void setBrush(QBrush brush);
28 const QBrush& brush() const;
28 QBrush brush();
29
29
30 Q_SIGNALS:
30 Q_SIGNALS:
31 void clicked(); // Clicked and hover signals exposed to user
31 void clicked(); // Clicked and hover signals exposed to user
@@ -55,7 +55,7 void StackedBarPresenter::layoutChanged()
55 Bar* bar = mBars.at(itemIndex);
55 Bar* bar = mBars.at(itemIndex);
56
56
57 bar->resize(mBarDefaultWidth, barHeight);
57 bar->resize(mBarDefaultWidth, barHeight);
58 bar->setBrush(mSeries->setAt(set)->brush());
58 bar->setBrush(mSeries->barsetAt(set)->brush());
59 bar->setPos(xPos, yPos-barHeight);
59 bar->setPos(xPos, yPos-barHeight);
60 itemIndex++;
60 itemIndex++;
61 yPos -= barHeight;
61 yPos -= barHeight;
@@ -143,22 +143,25 void ChartTheme::decorate(LineChartItem* item, QLineSeries* series,int count)
143
143
144 void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int count)
144 void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int count)
145 {
145 {
146 QList<QBarSet*> sets = series->barSets();
146 for (int i=0; i<series->countSets(); i++) {
147 for (int i=0; i<series->countSets(); i++) {
147 series->nextSet(0==i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
148 sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
148 }
149 }
149 }
150 }
150
151
151 void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count)
152 void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count)
152 {
153 {
154 QList<QBarSet*> sets = series->barSets();
153 for (int i=0; i<series->countSets(); i++) {
155 for (int i=0; i<series->countSets(); i++) {
154 series->nextSet(0==i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
156 sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
155 }
157 }
156 }
158 }
157
159
158 void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count)
160 void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count)
159 {
161 {
162 QList<QBarSet*> sets = series->barSets();
160 for (int i=0; i<series->countSets(); i++) {
163 for (int i=0; i<series->countSets(); i++) {
161 series->nextSet(0==i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
164 sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
162 }
165 }
163 }
166 }
164
167
@@ -272,7 +272,7 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QS
272 series->addBarSet(set);
272 series->addBarSet(set);
273 }
273 }
274 series->enableFloatingValues();
274 series->enableFloatingValues();
275 series->enableToolTip();
275 series->setToolTipEnabled();
276 series->enableSeparators(false);
276 series->enableSeparators(false);
277 m_chartWidget->addSeries(series);
277 m_chartWidget->addSeries(series);
278 setCurrentSeries(series);
278 setCurrentSeries(series);
General Comments 0
You need to be logged in to leave comments. Login now