##// END OF EJS Templates
Documentation for bar charts
sauimone -
r313:625c56c7d323
parent child
Show More
@@ -1,49 +1,51
1 1 #include "qbarcategory.h"
2 2
3 3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4 4
5 5 /*!
6 6 \class QBarCategory
7 \brief QtCommercial chart API.
7 \brief part of QtCommercial chart API.
8 8
9 9 QBarCategory is a container for labels of various bar charts. Before the
10 10 bar chart can be constructed, the categories must be defined. This is done by
11 11 creating a QBarCategory class and appending the labels of categories to it.
12 The QBarCategory is then given to QBarSeries class.
12 The QBarCategory is then given to bar chart series class.
13
14 \sa QBarChartSeries, QStackedBarChartSeries, QPercentBarChartSeries
13 15 */
14 16
15 17 /*!
16 18 Constructs the category container
17 19 */
18 20 QBarCategory::QBarCategory()
19 21 {
20 22 }
21 23
22 24 /*!
23 25 Appends the \a label in the category.
24 26 */
25 27 QBarCategory& QBarCategory::operator << (const QString &label)
26 28 {
27 29 mList.append(label);
28 30 return *this;
29 31 }
30 32
31 33 /*!
32 34 Retrurns number of labels in category
33 35 */
34 36 int QBarCategory::count()
35 37 {
36 38 return mList.count();
37 39 }
38 40
39 41 /*!
40 42 Retruns the label of category defined by index \a category
41 43 */
42 44 QString QBarCategory::label(int category)
43 45 {
44 46 return mList.at(category);
45 47 }
46 48
47 49 // TODO?:
48 50 //#include "moc_qbarcategory.cpp"
49 51 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,128 +1,232
1 1 #include <QDebug>
2 2 #include "qbarchartseries.h"
3 3 #include "qbarcategory.h"
4 4 #include "qbarset.h"
5 5 #include "barchartmodel_p.h"
6 6
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 /*!
11 \class QBarChartSeries
12 \brief part of QtCommercial chart API.
13
14 QBarChartSeries represents a series of data shown as bars. One QBarChartSeries can contain multible
15 QBarSet data sets. QBarChartSeries groups the data from sets to categories, which are defined
16 by QBarCategory class.
17
18 \sa QBarCategory, QBarSet, QStackedBarChartSeries, QPercentBarChartSeries
19 */
20
21 /*!
22 \fn virtual QChartSeriesType QBarChartSeries::type() const
23 \brief Returns type of series.
24 \sa QChartSeries, QChartSeriesType
25 */
26 /*!
27 \fn void QBarChartSeries::changed(int index)
28 \brief INTERNAL \a index
29 */
30 /*!
31 \fn void QBarChartSeries::floatingValuesEnabled(bool enabled)
32 \brief INTERNAL \a enabled
33 */
34 /*!
35 \fn void QBarChartSeries::toolTipEnabled(bool enabled)
36 \brief INTERNAL \a enabled
37 */
38 /*!
39 \fn void QBarChartSeries::separatorsEnabled(bool enabled)
40 \brief INTERNAL \a enabled
41 */
42 /*!
43 \fn void QBarChartSeries::showToolTip(QPoint pos, QString tip)
44 \brief INTERNAL \a pos \a tip
45 */
46
47 /*!
48 Constructs empty QBarChartSeries. Parameter \a category defines the categories for chart.
49 QBarChartSeries is QObject which is a child of a\a parent.
50 */
10 51 QBarChartSeries::QBarChartSeries(QBarCategory *category, QObject *parent)
11 52 : QChartSeries(parent)
12 53 ,mModel(new BarChartModel(category, this))
13 54 {
14 55 }
15 56
57 /*!
58 Adds a set of bars to series. Takes ownership of \a set
59 */
16 60 void QBarChartSeries::addBarSet(QBarSet *set)
17 61 {
18 62 mModel->addBarSet(set);
19 63 }
20 64
65 /*!
66 Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set.
67 */
21 68 void QBarChartSeries::removeBarSet(QBarSet *set)
22 69 {
23 70 mModel->removeBarSet(set);
24 71 }
25 72
73 /*!
74 Returns number of sets in series.
75 */
26 76 int QBarChartSeries::countSets()
27 77 {
28 78 return mModel->countSets();
29 79 }
30 80
81 /*!
82 Simple iterator for set. Returns pointer to next set in series.
83 Returns first set, if \a getFirst is true. If series is empty, returns 0.
84 */
31 85 QBarSet* QBarChartSeries::nextSet(bool getFirst)
32 86 {
33 87 return mModel->nextSet(getFirst);
34 88 }
35 89
90 /*!
91 Returns set indexed by \a index. Doesn't check for index bounds.
92 Assumes that \a index is between 0 and number of sets. Use countSets() to get valid index bound.
93 \sa countSets()
94 */
36 95 QBarSet* QBarChartSeries::setAt(int index)
37 96 {
38 97 return mModel->setAt(index);
39 98 }
40 99
100 /*!
101 Returns legend of series. Legend is a list of set names in series.
102 */
41 103 QList<QString> QBarChartSeries::legend()
42 104 {
43 105 return mModel->legend();
44 106 }
45 107
108 /*!
109 INTERNAL \a category
110 */
46 111 QString QBarChartSeries::label(int category)
47 112 {
48 113 return mModel->label(category);
49 114 }
50 115
116 /*!
117 Enables or disables floating values depending on parameter \a enabled.
118 Floating values are bar values, that are displayed on top of each bar.
119 Calling without parameter \a enabled, enables the floating values
120 */
51 121 void QBarChartSeries::enableFloatingValues(bool enabled)
52 122 {
53 123 if (enabled) {
54 124 for (int i=0; i<mModel->countSets(); i++) {
55 125 QBarSet *set = mModel->setAt(i);
56 126 connect(set,SIGNAL(clicked()),set,SIGNAL(toggleFloatingValues()));
57 127 }
58 128 } else {
59 129 for (int i=0; i<mModel->countSets(); i++) {
60 130 QBarSet *set = mModel->setAt(i);
61 131 disconnect(set,SIGNAL(clicked()),set,SIGNAL(toggleFloatingValues()));
62 132 }
63 133 }
64 134 }
65 135
136 /*!
137 Enables or disables tooltip depending on parameter \a enabled.
138 Tooltip shows the name of set, when mouse is hovering on top of bar.
139 Calling without parameter \a enabled, enables the tooltip
140 */
66 141 void QBarChartSeries::enableToolTip(bool enabled)
67 142 {
68 143 if (enabled) {
69 144 for (int i=0; i<mModel->countSets(); i++) {
70 145 QBarSet *set = mModel->setAt(i);
71 146 connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString)));
72 147 }
73 148 } else {
74 149 for (int i=0; i<mModel->countSets(); i++) {
75 150 QBarSet *set = mModel->setAt(i);
76 151 disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString)));
77 152 }
78 153 }
79 154 }
80 155
156 /*!
157 Enables or disables separators depending on parameter \a enabled.
158 Separators are visual elements that are drawn between categories.
159 Calling without parameter \a enabled, enables the separators
160 */
81 161 void QBarChartSeries::enableSeparators(bool enabled)
82 162 {
83 163 emit separatorsEnabled(enabled);
84 164 }
85 165
166 /*!
167 INTERNAL
168 */
86 169 int QBarChartSeries::countCategories()
87 170 {
88 171 return mModel->countCategories();
89 172 }
90 173
174 /*!
175 INTERNAL
176 */
91 177 qreal QBarChartSeries::min()
92 178 {
93 179 return mModel->min();
94 180 }
95 181
182 /*!
183 INTERNAL
184 */
96 185 qreal QBarChartSeries::max()
97 186 {
98 187 return mModel->max();
99 188 }
100 189
190 /*!
191 INTERNAL \a set \a category
192 */
101 193 qreal QBarChartSeries::valueAt(int set, int category)
102 194 {
103 195 return mModel->valueAt(set,category);
104 196 }
105 197
198 /*!
199 INTERNAL \a set \a category
200 */
106 201 qreal QBarChartSeries::percentageAt(int set, int category)
107 202 {
108 203 return mModel->percentageAt(set,category);
109 204 }
110 205
206 /*!
207 INTERNAL \a category
208 */
111 209 qreal QBarChartSeries::categorySum(int category)
112 210 {
113 211 return mModel->categorySum(category);
114 212 }
115 213
214 /*!
215 INTERNAL
216 */
116 217 qreal QBarChartSeries::maxCategorySum()
117 218 {
118 219 return mModel->maxCategorySum();
119 220 }
120 221
222 /*!
223 INTERNAL
224 */
121 225 BarChartModel& QBarChartSeries::model()
122 226 {
123 227 return *mModel;
124 228 }
125 229
126 230 #include "moc_qbarchartseries.cpp"
127 231
128 232 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,66 +1,66
1 1 #ifndef BARCHARTSERIES_H
2 2 #define BARCHARTSERIES_H
3 3
4 4 #include "qchartseries.h"
5 5
6 6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 7
8 8 class QBarCategory;
9 9 class QBarSet;
10 10 class BarChartModel;
11 11
12 12 // Container for series
13 13 class QTCOMMERCIALCHART_EXPORT QBarChartSeries : public QChartSeries
14 14 {
15 15 Q_OBJECT
16 16 public:
17 17 QBarChartSeries(QBarCategory *category, QObject* parent=0);
18 18
19 19 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeBar; }
20 20
21 21 void addBarSet(QBarSet *set); // Takes ownership of set
22 22 void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set
23 23 int countSets();
24 24 QBarSet* nextSet(bool getFirst=false); // Returns first set, if called with true
25 25 QBarSet *setAt(int index);
26 26
27 27 QList<QString> legend(); // Returns legend of series (ie. names of all sets in series)
28 QString label(int category);
29 28
30 29 public:
31 30 // TODO: Functions below this are not part of api and will be moved
32 31 // to private implementation, when we start using it
33 32 // TODO: TO PIMPL --->
33 QString label(int category);
34 34 int countCategories();
35 35 qreal min();
36 36 qreal max();
37 37 qreal valueAt(int set, int category);
38 38 qreal percentageAt(int set, int category);
39 39 qreal categorySum(int category);
40 40 qreal maxCategorySum();
41 41 BarChartModel& model();
42 42 // <--- TO PIMPL
43 43
44 44 signals:
45 45 void changed(int index);
46 46
47 47 // TODO: internal signals, these to private implementation.
48 48 // TODO: TO PIMPL --->
49 49 void floatingValuesEnabled(bool enabled);
50 50 void toolTipEnabled(bool enabled);
51 51 void separatorsEnabled(bool enabled);
52 52 void showToolTip(QPoint pos, QString tip);
53 53 // <--- TO PIMPL
54 54
55 55 public Q_SLOTS:
56 56 void enableFloatingValues(bool enabled=true); // enables floating values on top of bars
57 57 void enableToolTip(bool enabled=true); // enables tooltips
58 58 void enableSeparators(bool enabled=true); // enables separators between categories
59 59
60 60 protected:
61 61 BarChartModel* mModel;
62 62 };
63 63
64 64 QTCOMMERCIALCHART_END_NAMESPACE
65 65
66 66 #endif // BARCHARTSERIES_H
@@ -1,88 +1,165
1 1 #include "qbarset.h"
2 2 #include <QDebug>
3 3 #include <QToolTip>
4 4
5 5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 6
7 /*!
8 \class QBarSet
9 \brief part of QtCommercial chart API.
10
11 QBarSet represents one set of bars. Set of bars contains one data value for each category.
12 First value of set is assumed to belong to first category, second to second category and so on.
13 If set has fewer values than there are categories, then the missing values are assumed to be
14 at the end of set. For missing values in middle of a set, numerical value of zero is used.
15
16 \sa QBarCategory, QBarChartSeries, QStackedBarChartSeries, QPercentBarChartSeries
17 */
18
19 /*!
20 \fn void QBarSet::clicked()
21 \brief signals that set has been clicked
22 */
23 /*!
24 \fn void QBarSet::hoverEnter(QPoint pos)
25 \brief signals that mouse has entered over the set at position \a pos.
26 */
27 /*!
28 \fn void QBarSet::hoverLeave()
29 \brief signals that mouse has left from the set.
30 */
31 /*!
32 \fn void QBarSet::toggleFloatingValues()
33 \brief INTERNAL
34 */
35 /*!
36 \fn void QBarSet::showToolTip(QPoint pos, QString tip)
37 \brief INTERNAL \a pos \a tip
38 */
39
40
41 /*!
42 Constructs QBarSet with a name of \a name and with parent of \a parent
43 */
7 44 QBarSet::QBarSet(QString name, QObject *parent)
8 45 : QObject(parent)
9 46 ,mName(name)
10 47 {
11 48 }
12 49
50 /*!
51 Sets new \a name for set.
52 */
13 53 void QBarSet::setName(QString name)
14 54 {
15 55 mName = name;
16 56 }
57
58 /*!
59 Returns name of the set.
60 */
17 61 QString QBarSet::name()
18 62 {
19 63 return mName;
20 64 }
21 65
66 /*!
67 Appends new value \a value to the end of set.
68 */
22 69 QBarSet& QBarSet::operator << (const qreal &value)
23 70 {
24 71 mValues.append(value);
25 72 return *this;
26 73 }
27 74
75 /*!
76 Returns count of values in set.
77 */
28 78 int QBarSet::count()
29 79 {
30 80 return mValues.count();
31 81 }
32 82
83 /*!
84 Returns value of set indexed by \a index
85 */
33 86 qreal QBarSet::valueAt(int index)
34 87 {
35 88 return mValues.at(index);
36 89 }
37 90
91 /*!
92 Sets a new value \a value to set, indexed by \a index
93 */
38 94 void QBarSet::setValue(int index, qreal value)
39 95 {
40 96 mValues.replace(index,value);
41 97 }
42 98
99 /*!
100 Sets pen for set. Bars of this set are drawn using \a pen
101 */
43 102 void QBarSet::setPen(const QPen& pen)
44 103 {
45 104 mPen = pen;
46 105 }
47 106
107 /*!
108 Returns pen of the set.
109 */
48 110 const QPen& QBarSet::pen() const
49 111 {
50 112 return mPen;
51 113 }
52 114
115 /*!
116 Sets brush for the set. Bars of this set are drawn using \a brush
117 */
53 118 void QBarSet::setBrush(const QBrush& brush)
54 119 {
55 120 mBrush = brush;
56 121 }
57 122
123 /*!
124 Returns brush of the set.
125 */
58 126 const QBrush& QBarSet::brush() const
59 127 {
60 128 return mBrush;
61 129 }
62 130
131 /*!
132 INTERNAL
133 */
63 134 void QBarSet::barClicked()
64 135 {
65 136 // qDebug() << "QBarset::barClicked" << this;
66 137 // Some bar of this set has been clicked
67 138 // TODO: What happens then?
68 139 emit clicked(); // Notify that set has been clicked
69 140 }
70 141
142 /*!
143 INTERNAL \a pos
144 */
71 145 void QBarSet::barHoverEntered(QPoint pos)
72 146 {
73 147 emit showToolTip(pos, mName);
74 148 emit hoverEnter(pos);
75 149 }
76 150
151 /*!
152 INTERNAL
153 */
77 154 void QBarSet::barHoverLeaved()
78 155 {
79 156 // qDebug() << "QBarset::barHoverLeaved" << this;
80 157 // if (mToolTipEnabled) {
81 158 // TODO: do what?
82 159 // }
83 160 // Emit signal to user of charts
84 161 emit hoverLeave();
85 162 }
86 163
87 164 #include "moc_qbarset.cpp"
88 165 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,13 +1,34
1 1 #include "qpercentbarchartseries.h"
2 2
3 3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4 4
5 /*!
6 \class QPercentBarChartSeries
7 \brief part of QtCommercial chart API.
8
9 QPercentBarChartSeries represents a series of data shown as bars. Each bar of QBarSet is shown as percentage
10 of all bars in category. One QPercentBarChartSeries can contain multible QBarSet data sets.
11 QBarChartSeries groups the data from sets to categories, which are defined by QBarCategory class.
12
13 \sa QBarCategory, QBarSet, QStackedBarChartSeries, QBarChartSeries
14 */
15
16 /*!
17 \fn virtual QChartSeriesType QPercentBarChartSeries::type() const
18 \brief Returns type of series.
19 \sa QChartSeries, QChartSeriesType
20 */
21
22 /*!
23 Constructs empty QPercentBarChartSeries. Parameter \a category defines the categories for chart.
24 QPercentBarChartSeries is QObject which is a child of a\a parent.
25 */
5 26 QPercentBarChartSeries::QPercentBarChartSeries(QBarCategory *category, QObject *parent)
6 27 : QBarChartSeries(category, parent)
7 28 {
8 29 }
9 30
10 31 #include "moc_qpercentbarchartseries.cpp"
11 32
12 33 QTCOMMERCIALCHART_END_NAMESPACE
13 34
@@ -1,13 +1,34
1 1 #include "qstackedbarchartseries.h"
2 2
3 3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4 4
5 /*!
6 \class QStackedBarChartSeries
7 \brief part of QtCommercial chart API.
8
9 QStackedBarChartSeries represents a series of data shown as bars. All bars in same category are
10 stacked on top of each other. One QStackedBarChartSeries can contain multible QBarSet data sets.
11 QStackedBarChartSeries groups the data from sets to categories, which are defined by QBarCategory class.
12
13 \sa QBarCategory, QBarSet, QPercentBarChartSeries, QBarChartSeries
14 */
15
16 /*!
17 \fn virtual QChartSeriesType QStackedBarChartSeries::type() const
18 \brief Returns type of series.
19 \sa QChartSeries, QChartSeriesType
20 */
21
22 /*!
23 Constructs empty QStackedBarChartSeries. Parameter \a category defines the categories for chart.
24 QStackedBarChartSeries is QObject which is a child of a\a parent.
25 */
5 26 QStackedBarChartSeries::QStackedBarChartSeries(QBarCategory *category, QObject *parent)
6 27 : QBarChartSeries(category, parent)
7 28 {
8 29 }
9 30
10 31 #include "moc_qstackedbarchartseries.cpp"
11 32
12 33 QTCOMMERCIALCHART_END_NAMESPACE
13 34
General Comments 0
You need to be logged in to leave comments. Login now