##// END OF EJS Templates
updated documentation and examples for barcharts
sauimone -
r325:043a715b3681
parent child
Show More
@@ -1,59 +1,69
1 #include <QApplication>
1 #include <QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <qchartview.h>
3 #include <qchartview.h>
4 #include <qbarchartseries.h>
4 #include <qbarchartseries.h>
5 #include <qbarset.h>
5 #include <qbarset.h>
6 #include <qbarcategory.h>
6 #include <qbarcategory.h>
7
7
8 QTCOMMERCIALCHART_USE_NAMESPACE
8 QTCOMMERCIALCHART_USE_NAMESPACE
9
9
10 int main(int argc, char *argv[])
10 int main(int argc, char *argv[])
11 {
11 {
12 QApplication a(argc, argv);
12 QApplication a(argc, argv);
13 QMainWindow window;
13 QMainWindow window;
14
14
15 //! [1]
15 //! [1]
16 // Create category
16 QBarCategory *category = new QBarCategory;
17 QBarCategory *category = new QBarCategory;
17 *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
18 *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
18 //! [1]
19 //! [1]
19
20
20 //! [2]
21 //! [2]
21 QBarChartSeries* series= new QBarChartSeries(category);
22 // Create some test sets for chat
22
23
23 QBarSet *set0 = new QBarSet("Bub");
24 QBarSet *set0 = new QBarSet("Bub");
24 QBarSet *set1 = new QBarSet("Bob");
25 QBarSet *set1 = new QBarSet("Bob");
25 QBarSet *set2 = new QBarSet("Guybrush");
26 QBarSet *set2 = new QBarSet("Guybrush");
26 QBarSet *set3 = new QBarSet("Larry");
27 QBarSet *set3 = new QBarSet("Larry");
27 QBarSet *set4 = new QBarSet("Zak");
28 QBarSet *set4 = new QBarSet("Zak");
28
29
29 // Create some test data to chart
30 *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12;
30 *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12;
31 *set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2;
31 *set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2;
32 *set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5;
32 *set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5;
33 *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7;
33 *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7;
34 *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6;
34 *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6;
35 //! [2]
36
37 //! [3]
38 // Create series and add sets to it
39 QBarChartSeries* series= new QBarChartSeries(category);
35
40
36 series->addBarSet(set0);
41 series->addBarSet(set0);
37 series->addBarSet(set1);
42 series->addBarSet(set1);
38 series->addBarSet(set2);
43 series->addBarSet(set2);
39 series->addBarSet(set3);
44 series->addBarSet(set3);
40 series->addBarSet(set4);
45 series->addBarSet(set4);
41 //! [2]
42
43 //! [3]
46 //! [3]
47
48 //! [4]
49 // Enable some features
44 series->enableToolTip();
50 series->enableToolTip();
45 series->enableFloatingValues();
51 series->enableFloatingValues();
46 //! [3]
52 //! [4]
53
54 //! [5]
55 // Create view for chart and add series to it. Apply theme.
47
56
48 QChartView* chartView = new QChartView(&window);
57 QChartView* chartView = new QChartView(&window);
49 chartView->addSeries(series);
58 chartView->addSeries(series);
50 chartView->setChartTitle("simple stacked barchart");
59 chartView->setChartTitle("simple stacked barchart");
51 chartView->setChartTheme(QChart::ChartThemeIcy);
60 chartView->setChartTheme(QChart::ChartThemeIcy);
61 //! [5]
52
62
53 window.setCentralWidget(chartView);
63 window.setCentralWidget(chartView);
54 window.resize(600, 300);
64 window.resize(600, 300);
55 window.show();
65 window.show();
56
66
57 return a.exec();
67 return a.exec();
58 }
68 }
59
69
@@ -1,56 +1,69
1 #include <QApplication>
1 #include <QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <QStandardItemModel>
3 #include <QStandardItemModel>
4 #include <qpercentbarchartseries.h>
4 #include <qpercentbarchartseries.h>
5 #include <qbarcategory.h>
5 #include <qbarcategory.h>
6 #include <qchartview.h>
6 #include <qchartview.h>
7 #include <qbarset.h>
7 #include <qbarset.h>
8
8
9 QTCOMMERCIALCHART_USE_NAMESPACE
9 QTCOMMERCIALCHART_USE_NAMESPACE
10
10
11 int main(int argc, char *argv[])
11 int main(int argc, char *argv[])
12 {
12 {
13 QApplication a(argc, argv);
13 QApplication a(argc, argv);
14 QMainWindow window;
14 QMainWindow window;
15
15
16 //! [1]
17 // Create category
16 QBarCategory *category = new QBarCategory;
18 QBarCategory *category = new QBarCategory;
17 *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
19 *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
18
19 //! [1]
20 //! [1]
20 QPercentBarChartSeries* series = new QPercentBarChartSeries(category);
21
21
22 //! [2]
23 // Create some test sets for chat
22 QBarSet *set0 = new QBarSet("Bub");
24 QBarSet *set0 = new QBarSet("Bub");
23 QBarSet *set1 = new QBarSet("Bob");
25 QBarSet *set1 = new QBarSet("Bob");
24 QBarSet *set2 = new QBarSet("Guybrush");
26 QBarSet *set2 = new QBarSet("Guybrush");
25 QBarSet *set3 = new QBarSet("Larry");
27 QBarSet *set3 = new QBarSet("Larry");
26 QBarSet *set4 = new QBarSet("Zak");
28 QBarSet *set4 = new QBarSet("Zak");
27
29
28 // Create some test data to chart
29 *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12;
30 *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12;
30 *set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2;
31 *set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2;
31 *set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5;
32 *set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5;
32 *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7;
33 *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7;
33 *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6;
34 *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6;
35 //! [2]
36
37 //! [3]
38 // Create series and add sets to it
39 QPercentBarChartSeries* series = new QPercentBarChartSeries(category);
34
40
35 series->addBarSet(set0);
41 series->addBarSet(set0);
36 series->addBarSet(set1);
42 series->addBarSet(set1);
37 series->addBarSet(set2);
43 series->addBarSet(set2);
38 series->addBarSet(set3);
44 series->addBarSet(set3);
39 series->addBarSet(set4);
45 series->addBarSet(set4);
40 //! [1]
46 //! [3]
41
47
48 //! [4]
49 // Enable features
42 series->enableToolTip();
50 series->enableToolTip();
43 series->enableFloatingValues();
51 series->enableFloatingValues();
52 //! [4]
53
54 //! [5]
55 // Create view for chart and add series to it. Apply theme.
44
56
45 QChartView* chartView = new QChartView(&window);
57 QChartView* chartView = new QChartView(&window);
46 chartView->addSeries(series);
58 chartView->addSeries(series);
47 chartView->setChartTitle("simple percent barchart");
59 chartView->setChartTitle("simple percent barchart");
48 chartView->setChartTheme(QChart::ChartThemeIcy);
60 chartView->setChartTheme(QChart::ChartThemeIcy);
61 //! [5]
49
62
50 window.setCentralWidget(chartView);
63 window.setCentralWidget(chartView);
51 window.resize(400, 300);
64 window.resize(400, 300);
52 window.show();
65 window.show();
53
66
54 return a.exec();
67 return a.exec();
55 }
68 }
56
69
@@ -1,55 +1,68
1 #include <QApplication>
1 #include <QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <qchartview.h>
3 #include <qchartview.h>
4 #include <qstackedbarchartseries.h>
4 #include <qstackedbarchartseries.h>
5 #include <qbarset.h>
5 #include <qbarset.h>
6 #include <qbarcategory.h>
6 #include <qbarcategory.h>
7
7
8 QTCOMMERCIALCHART_USE_NAMESPACE
8 QTCOMMERCIALCHART_USE_NAMESPACE
9
9
10 int main(int argc, char *argv[])
10 int main(int argc, char *argv[])
11 {
11 {
12 QApplication a(argc, argv);
12 QApplication a(argc, argv);
13 QMainWindow window;
13 QMainWindow window;
14
14
15 //! [1]
15 //! [1]
16 // Create category
16 QBarCategory *category = new QBarCategory;
17 QBarCategory *category = new QBarCategory;
17 *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
18 *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
19 //! [1]
18
20
19 QStackedBarChartSeries* series = new QStackedBarChartSeries(category);
21 //! [2]
20
22 // Create some test sets for chat
21 QBarSet *set0 = new QBarSet("Bub");
23 QBarSet *set0 = new QBarSet("Bub");
22 QBarSet *set1 = new QBarSet("Bob");
24 QBarSet *set1 = new QBarSet("Bob");
23 QBarSet *set2 = new QBarSet("Guybrush");
25 QBarSet *set2 = new QBarSet("Guybrush");
24 QBarSet *set3 = new QBarSet("Larry");
26 QBarSet *set3 = new QBarSet("Larry");
25 QBarSet *set4 = new QBarSet("Zak");
27 QBarSet *set4 = new QBarSet("Zak");
26
28
27 // Create some test data to chart
28 *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12;
29 *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12;
29 *set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2;
30 *set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2;
30 *set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5;
31 *set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5;
31 *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7;
32 *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7;
32 *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6;
33 *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6;
34 //! [2]
35
36 //! [3]
37 // Create series and add sets to it
38 QStackedBarChartSeries* series = new QStackedBarChartSeries(category);
33
39
34 series->addBarSet(set0);
40 series->addBarSet(set0);
35 series->addBarSet(set1);
41 series->addBarSet(set1);
36 series->addBarSet(set2);
42 series->addBarSet(set2);
37 series->addBarSet(set3);
43 series->addBarSet(set3);
38 series->addBarSet(set4);
44 series->addBarSet(set4);
45 //! [3]
39
46
47 //! [4]
48 // Enable features
40 series->enableToolTip();
49 series->enableToolTip();
41 series->enableFloatingValues();
50 series->enableFloatingValues();
42 //! [1]
51 //! [4]
52
53 //! [5]
54 // Create view for chart and add series to it. Apply theme.
43
55
44 QChartView* chartView = new QChartView(&window);
56 QChartView* chartView = new QChartView(&window);
45 chartView->addSeries(series);
57 chartView->addSeries(series);
46 chartView->setChartTitle("simple stacked barchart");
58 chartView->setChartTitle("simple stacked barchart");
47 chartView->setChartTheme(QChart::ChartThemeIcy);
59 chartView->setChartTheme(QChart::ChartThemeIcy);
60 //! [5]
48
61
49 window.setCentralWidget(chartView);
62 window.setCentralWidget(chartView);
50 window.resize(400, 300);
63 window.resize(400, 300);
51 window.show();
64 window.show();
52
65
53 return a.exec();
66 return a.exec();
54 }
67 }
55
68
@@ -1,244 +1,252
1 #include <QDebug>
1 #include <QDebug>
2 #include "qbarchartseries.h"
2 #include "qbarchartseries.h"
3 #include "qbarcategory.h"
3 #include "qbarcategory.h"
4 #include "qbarset.h"
4 #include "qbarset.h"
5 #include "barchartmodel_p.h"
5 #include "barchartmodel_p.h"
6
6
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 /*!
10 /*!
11 \class QBarChartSeries
11 \class QBarChartSeries
12 \brief part of QtCommercial chart API.
12 \brief part of QtCommercial chart API.
13
13
14 QBarChartSeries represents a series of data shown as bars. One QBarChartSeries can contain multible
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
15 QBarSet data sets. QBarChartSeries groups the data from sets to categories, which are defined
16 by QBarCategory class.
16 by QBarCategory class.
17
17
18 \mainclass
18 \mainclass
19
19
20 Example on how to add sets to bar chart:
20 Example on how to create category:
21 \snippet ../example/barchart/main.cpp 1
22
23 Example on how to create sets of data:
21 \snippet ../example/barchart/main.cpp 2
24 \snippet ../example/barchart/main.cpp 2
22
25
26 Example on how to add sets to bar chart:
27 \snippet ../example/barchart/main.cpp 3
23
28
24 Example on how to enable tooltip and floating values:
29 Example on how to enable tooltip and floating values:
25 \snippet ../example/barchart/main.cpp 3
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
26
34
27 \sa QBarCategory, QBarSet, QStackedBarChartSeries, QPercentBarChartSeries
35 \sa QBarCategory, QBarSet, QStackedBarChartSeries, QPercentBarChartSeries
28 */
36 */
29
37
30 /*!
38 /*!
31 \fn virtual QChartSeriesType QBarChartSeries::type() const
39 \fn virtual QChartSeriesType QBarChartSeries::type() const
32 \brief Returns type of series.
40 \brief Returns type of series.
33 \sa QChartSeries, QChartSeriesType
41 \sa QChartSeries, QChartSeriesType
34 */
42 */
35 /*!
43 /*!
36 \fn void QBarChartSeries::changed(int index)
44 \fn void QBarChartSeries::changed(int index)
37 \brief \internal \a index
45 \brief \internal \a index
38 */
46 */
39 /*!
47 /*!
40 \fn void QBarChartSeries::floatingValuesEnabled(bool enabled)
48 \fn void QBarChartSeries::floatingValuesEnabled(bool enabled)
41 \brief \internal \a enabled
49 \brief \internal \a enabled
42 */
50 */
43 /*!
51 /*!
44 \fn void QBarChartSeries::toolTipEnabled(bool enabled)
52 \fn void QBarChartSeries::toolTipEnabled(bool enabled)
45 \brief \internal \a enabled
53 \brief \internal \a enabled
46 */
54 */
47 /*!
55 /*!
48 \fn void QBarChartSeries::separatorsEnabled(bool enabled)
56 \fn void QBarChartSeries::separatorsEnabled(bool enabled)
49 \brief \internal \a enabled
57 \brief \internal \a enabled
50 */
58 */
51 /*!
59 /*!
52 \fn void QBarChartSeries::showToolTip(QPoint pos, QString tip)
60 \fn void QBarChartSeries::showToolTip(QPoint pos, QString tip)
53 \brief \internal \a pos \a tip
61 \brief \internal \a pos \a tip
54 */
62 */
55
63
56 /*!
64 /*!
57 Constructs empty QBarChartSeries. Parameter \a category defines the categories for chart.
65 Constructs empty QBarChartSeries. Parameter \a category defines the categories for chart.
58 Takes ownership of \a category.
66 Takes ownership of \a category.
59 QBarChartSeries is QObject which is a child of a \a parent.
67 QBarChartSeries is QObject which is a child of a \a parent.
60 */
68 */
61 QBarChartSeries::QBarChartSeries(QBarCategory *category, QObject *parent)
69 QBarChartSeries::QBarChartSeries(QBarCategory *category, QObject *parent)
62 : QChartSeries(parent)
70 : QChartSeries(parent)
63 ,mModel(new BarChartModel(category, this))
71 ,mModel(new BarChartModel(category, this))
64 {
72 {
65 }
73 }
66
74
67 /*!
75 /*!
68 Adds a set of bars to series. Takes ownership of \a set
76 Adds a set of bars to series. Takes ownership of \a set
69 */
77 */
70 void QBarChartSeries::addBarSet(QBarSet *set)
78 void QBarChartSeries::addBarSet(QBarSet *set)
71 {
79 {
72 mModel->addBarSet(set);
80 mModel->addBarSet(set);
73 }
81 }
74
82
75 /*!
83 /*!
76 Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set.
84 Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set.
77 */
85 */
78 void QBarChartSeries::removeBarSet(QBarSet *set)
86 void QBarChartSeries::removeBarSet(QBarSet *set)
79 {
87 {
80 mModel->removeBarSet(set);
88 mModel->removeBarSet(set);
81 }
89 }
82
90
83 /*!
91 /*!
84 Returns number of sets in series.
92 Returns number of sets in series.
85 */
93 */
86 int QBarChartSeries::countSets()
94 int QBarChartSeries::countSets()
87 {
95 {
88 return mModel->countSets();
96 return mModel->countSets();
89 }
97 }
90
98
91 /*!
99 /*!
92 Returns number of categories in series
100 Returns number of categories in series
93 */
101 */
94 int QBarChartSeries::countCategories()
102 int QBarChartSeries::countCategories()
95 {
103 {
96 return mModel->countCategories();
104 return mModel->countCategories();
97 }
105 }
98
106
99 /*!
107 /*!
100 Simple iterator for set. Returns pointer to next set in series.
108 Simple iterator for set. Returns pointer to next set in series.
101 Returns first set, if parameter \a getFirst is true.
109 Returns first set, if parameter \a getFirst is true.
102 If series is empty, returns 0.
110 If series is empty, returns 0.
103 Returns 0 after last set.
111 Returns 0 after last set.
104 */
112 */
105 QBarSet* QBarChartSeries::nextSet(bool getFirst)
113 QBarSet* QBarChartSeries::nextSet(bool getFirst)
106 {
114 {
107 return mModel->nextSet(getFirst);
115 return mModel->nextSet(getFirst);
108 }
116 }
109
117
110 /*!
118 /*!
111 Returns set indexed by \a index. Doesn't check for index bounds.
119 Returns set indexed by \a index. Doesn't check for index bounds.
112 Assumes that \a index is between 0 and number of sets. Use countSets() to get valid index bound.
120 Assumes that \a index is between 0 and number of sets. Use countSets() to get valid index bound.
113 \sa countSets()
121 \sa countSets()
114 */
122 */
115 QBarSet* QBarChartSeries::setAt(int index)
123 QBarSet* QBarChartSeries::setAt(int index)
116 {
124 {
117 return mModel->setAt(index);
125 return mModel->setAt(index);
118 }
126 }
119
127
120 /*!
128 /*!
121 Returns legend of series. Legend is a list of set names in series.
129 Returns legend of series. Legend is a list of set names in series.
122 */
130 */
123 QList<QString> QBarChartSeries::legend()
131 QList<QString> QBarChartSeries::legend()
124 {
132 {
125 return mModel->legend();
133 return mModel->legend();
126 }
134 }
127
135
128 /*!
136 /*!
129 \internal \a category
137 \internal \a category
130 */
138 */
131 QString QBarChartSeries::label(int category)
139 QString QBarChartSeries::label(int category)
132 {
140 {
133 return mModel->label(category);
141 return mModel->label(category);
134 }
142 }
135
143
136 /*!
144 /*!
137 Enables or disables floating values depending on parameter \a enabled.
145 Enables or disables floating values depending on parameter \a enabled.
138 Floating values are bar values, that are displayed on top of each bar.
146 Floating values are bar values, that are displayed on top of each bar.
139 Calling without parameter \a enabled, enables the floating values
147 Calling without parameter \a enabled, enables the floating values
140 */
148 */
141 void QBarChartSeries::enableFloatingValues(bool enabled)
149 void QBarChartSeries::enableFloatingValues(bool enabled)
142 {
150 {
143 if (enabled) {
151 if (enabled) {
144 for (int i=0; i<mModel->countSets(); i++) {
152 for (int i=0; i<mModel->countSets(); i++) {
145 QBarSet *set = mModel->setAt(i);
153 QBarSet *set = mModel->setAt(i);
146 connect(set,SIGNAL(clicked()),set,SIGNAL(toggleFloatingValues()));
154 connect(set,SIGNAL(clicked()),set,SIGNAL(toggleFloatingValues()));
147 }
155 }
148 } else {
156 } else {
149 for (int i=0; i<mModel->countSets(); i++) {
157 for (int i=0; i<mModel->countSets(); i++) {
150 QBarSet *set = mModel->setAt(i);
158 QBarSet *set = mModel->setAt(i);
151 disconnect(set,SIGNAL(clicked()),set,SIGNAL(toggleFloatingValues()));
159 disconnect(set,SIGNAL(clicked()),set,SIGNAL(toggleFloatingValues()));
152 }
160 }
153 }
161 }
154 }
162 }
155
163
156 /*!
164 /*!
157 Enables or disables tooltip depending on parameter \a enabled.
165 Enables or disables tooltip depending on parameter \a enabled.
158 Tooltip shows the name of set, when mouse is hovering on top of bar.
166 Tooltip shows the name of set, when mouse is hovering on top of bar.
159 Calling without parameter \a enabled, enables the tooltip
167 Calling without parameter \a enabled, enables the tooltip
160 */
168 */
161 void QBarChartSeries::enableToolTip(bool enabled)
169 void QBarChartSeries::enableToolTip(bool enabled)
162 {
170 {
163 if (enabled) {
171 if (enabled) {
164 for (int i=0; i<mModel->countSets(); i++) {
172 for (int i=0; i<mModel->countSets(); i++) {
165 QBarSet *set = mModel->setAt(i);
173 QBarSet *set = mModel->setAt(i);
166 connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString)));
174 connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString)));
167 }
175 }
168 } else {
176 } else {
169 for (int i=0; i<mModel->countSets(); i++) {
177 for (int i=0; i<mModel->countSets(); i++) {
170 QBarSet *set = mModel->setAt(i);
178 QBarSet *set = mModel->setAt(i);
171 disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString)));
179 disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString)));
172 }
180 }
173 }
181 }
174 }
182 }
175
183
176 /*!
184 /*!
177 Enables or disables separators depending on parameter \a enabled.
185 Enables or disables separators depending on parameter \a enabled.
178 Separators are visual elements that are drawn between categories.
186 Separators are visual elements that are drawn between categories.
179 Calling without parameter \a enabled, enables the separators
187 Calling without parameter \a enabled, enables the separators
180 */
188 */
181 void QBarChartSeries::enableSeparators(bool enabled)
189 void QBarChartSeries::enableSeparators(bool enabled)
182 {
190 {
183 emit separatorsEnabled(enabled);
191 emit separatorsEnabled(enabled);
184 }
192 }
185
193
186 /*!
194 /*!
187 \internal
195 \internal
188 */
196 */
189 qreal QBarChartSeries::min()
197 qreal QBarChartSeries::min()
190 {
198 {
191 return mModel->min();
199 return mModel->min();
192 }
200 }
193
201
194 /*!
202 /*!
195 \internal
203 \internal
196 */
204 */
197 qreal QBarChartSeries::max()
205 qreal QBarChartSeries::max()
198 {
206 {
199 return mModel->max();
207 return mModel->max();
200 }
208 }
201
209
202 /*!
210 /*!
203 \internal \a set \a category
211 \internal \a set \a category
204 */
212 */
205 qreal QBarChartSeries::valueAt(int set, int category)
213 qreal QBarChartSeries::valueAt(int set, int category)
206 {
214 {
207 return mModel->valueAt(set,category);
215 return mModel->valueAt(set,category);
208 }
216 }
209
217
210 /*!
218 /*!
211 \internal \a set \a category
219 \internal \a set \a category
212 */
220 */
213 qreal QBarChartSeries::percentageAt(int set, int category)
221 qreal QBarChartSeries::percentageAt(int set, int category)
214 {
222 {
215 return mModel->percentageAt(set,category);
223 return mModel->percentageAt(set,category);
216 }
224 }
217
225
218 /*!
226 /*!
219 \internal \a category
227 \internal \a category
220 */
228 */
221 qreal QBarChartSeries::categorySum(int category)
229 qreal QBarChartSeries::categorySum(int category)
222 {
230 {
223 return mModel->categorySum(category);
231 return mModel->categorySum(category);
224 }
232 }
225
233
226 /*!
234 /*!
227 \internal
235 \internal
228 */
236 */
229 qreal QBarChartSeries::maxCategorySum()
237 qreal QBarChartSeries::maxCategorySum()
230 {
238 {
231 return mModel->maxCategorySum();
239 return mModel->maxCategorySum();
232 }
240 }
233
241
234 /*!
242 /*!
235 \internal
243 \internal
236 */
244 */
237 BarChartModel& QBarChartSeries::model()
245 BarChartModel& QBarChartSeries::model()
238 {
246 {
239 return *mModel;
247 return *mModel;
240 }
248 }
241
249
242 #include "moc_qbarchartseries.cpp"
250 #include "moc_qbarchartseries.cpp"
243
251
244 QTCOMMERCIALCHART_END_NAMESPACE
252 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,165 +1,170
1 #include "qbarset.h"
1 #include "qbarset.h"
2 #include <QDebug>
2 #include <QDebug>
3 #include <QToolTip>
3 #include <QToolTip>
4
4
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6
6
7 /*!
7 /*!
8 \class QBarSet
8 \class QBarSet
9 \brief part of QtCommercial chart API.
9 \brief part of QtCommercial chart API.
10
10
11 QBarSet represents one set of bars. Set of bars contains one data value for each category.
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.
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
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.
14 at the end of set. For missing values in middle of a set, numerical value of zero is used.
15
15
16 \mainclass
17
18 Example on how to create sets of data:
19 \snippet ../example/barchart/main.cpp 2
20
16 \sa QBarCategory, QBarChartSeries, QStackedBarChartSeries, QPercentBarChartSeries
21 \sa QBarCategory, QBarChartSeries, QStackedBarChartSeries, QPercentBarChartSeries
17 */
22 */
18
23
19 /*!
24 /*!
20 \fn void QBarSet::clicked()
25 \fn void QBarSet::clicked()
21 \brief signals that set has been clicked
26 \brief signals that set has been clicked
22 */
27 */
23 /*!
28 /*!
24 \fn void QBarSet::hoverEnter(QPoint pos)
29 \fn void QBarSet::hoverEnter(QPoint pos)
25 \brief signals that mouse has entered over the set at position \a pos.
30 \brief signals that mouse has entered over the set at position \a pos.
26 */
31 */
27 /*!
32 /*!
28 \fn void QBarSet::hoverLeave()
33 \fn void QBarSet::hoverLeave()
29 \brief signals that mouse has left from the set.
34 \brief signals that mouse has left from the set.
30 */
35 */
31 /*!
36 /*!
32 \fn void QBarSet::toggleFloatingValues()
37 \fn void QBarSet::toggleFloatingValues()
33 \brief \internal
38 \brief \internal
34 */
39 */
35 /*!
40 /*!
36 \fn void QBarSet::showToolTip(QPoint pos, QString tip)
41 \fn void QBarSet::showToolTip(QPoint pos, QString tip)
37 \brief \internal \a pos \a tip
42 \brief \internal \a pos \a tip
38 */
43 */
39
44
40
45
41 /*!
46 /*!
42 Constructs QBarSet with a name of \a name and with parent of \a parent
47 Constructs QBarSet with a name of \a name and with parent of \a parent
43 */
48 */
44 QBarSet::QBarSet(QString name, QObject *parent)
49 QBarSet::QBarSet(QString name, QObject *parent)
45 : QObject(parent)
50 : QObject(parent)
46 ,mName(name)
51 ,mName(name)
47 {
52 {
48 }
53 }
49
54
50 /*!
55 /*!
51 Sets new \a name for set.
56 Sets new \a name for set.
52 */
57 */
53 void QBarSet::setName(QString name)
58 void QBarSet::setName(QString name)
54 {
59 {
55 mName = name;
60 mName = name;
56 }
61 }
57
62
58 /*!
63 /*!
59 Returns name of the set.
64 Returns name of the set.
60 */
65 */
61 QString QBarSet::name()
66 QString QBarSet::name()
62 {
67 {
63 return mName;
68 return mName;
64 }
69 }
65
70
66 /*!
71 /*!
67 Appends new value \a value to the end of set.
72 Appends new value \a value to the end of set.
68 */
73 */
69 QBarSet& QBarSet::operator << (const qreal &value)
74 QBarSet& QBarSet::operator << (const qreal &value)
70 {
75 {
71 mValues.append(value);
76 mValues.append(value);
72 return *this;
77 return *this;
73 }
78 }
74
79
75 /*!
80 /*!
76 Returns count of values in set.
81 Returns count of values in set.
77 */
82 */
78 int QBarSet::count()
83 int QBarSet::count()
79 {
84 {
80 return mValues.count();
85 return mValues.count();
81 }
86 }
82
87
83 /*!
88 /*!
84 Returns value of set indexed by \a index
89 Returns value of set indexed by \a index
85 */
90 */
86 qreal QBarSet::valueAt(int index)
91 qreal QBarSet::valueAt(int index)
87 {
92 {
88 return mValues.at(index);
93 return mValues.at(index);
89 }
94 }
90
95
91 /*!
96 /*!
92 Sets a new value \a value to set, indexed by \a index
97 Sets a new value \a value to set, indexed by \a index
93 */
98 */
94 void QBarSet::setValue(int index, qreal value)
99 void QBarSet::setValue(int index, qreal value)
95 {
100 {
96 mValues.replace(index,value);
101 mValues.replace(index,value);
97 }
102 }
98
103
99 /*!
104 /*!
100 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
101 */
106 */
102 void QBarSet::setPen(const QPen& pen)
107 void QBarSet::setPen(const QPen& pen)
103 {
108 {
104 mPen = pen;
109 mPen = pen;
105 }
110 }
106
111
107 /*!
112 /*!
108 Returns pen of the set.
113 Returns pen of the set.
109 */
114 */
110 const QPen& QBarSet::pen() const
115 const QPen& QBarSet::pen() const
111 {
116 {
112 return mPen;
117 return mPen;
113 }
118 }
114
119
115 /*!
120 /*!
116 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
117 */
122 */
118 void QBarSet::setBrush(const QBrush& brush)
123 void QBarSet::setBrush(const QBrush& brush)
119 {
124 {
120 mBrush = brush;
125 mBrush = brush;
121 }
126 }
122
127
123 /*!
128 /*!
124 Returns brush of the set.
129 Returns brush of the set.
125 */
130 */
126 const QBrush& QBarSet::brush() const
131 const QBrush& QBarSet::brush() const
127 {
132 {
128 return mBrush;
133 return mBrush;
129 }
134 }
130
135
131 /*!
136 /*!
132 \internal
137 \internal
133 */
138 */
134 void QBarSet::barClicked()
139 void QBarSet::barClicked()
135 {
140 {
136 // qDebug() << "QBarset::barClicked" << this;
141 // qDebug() << "QBarset::barClicked" << this;
137 // Some bar of this set has been clicked
142 // Some bar of this set has been clicked
138 // TODO: What happens then?
143 // TODO: What happens then?
139 emit clicked(); // Notify that set has been clicked
144 emit clicked(); // Notify that set has been clicked
140 }
145 }
141
146
142 /*!
147 /*!
143 \internal \a pos
148 \internal \a pos
144 */
149 */
145 void QBarSet::barHoverEntered(QPoint pos)
150 void QBarSet::barHoverEntered(QPoint pos)
146 {
151 {
147 emit showToolTip(pos, mName);
152 emit showToolTip(pos, mName);
148 emit hoverEnter(pos);
153 emit hoverEnter(pos);
149 }
154 }
150
155
151 /*!
156 /*!
152 \internal
157 \internal
153 */
158 */
154 void QBarSet::barHoverLeaved()
159 void QBarSet::barHoverLeaved()
155 {
160 {
156 // qDebug() << "QBarset::barHoverLeaved" << this;
161 // qDebug() << "QBarset::barHoverLeaved" << this;
157 // if (mToolTipEnabled) {
162 // if (mToolTipEnabled) {
158 // TODO: do what?
163 // TODO: do what?
159 // }
164 // }
160 // Emit signal to user of charts
165 // Emit signal to user of charts
161 emit hoverLeave();
166 emit hoverLeave();
162 }
167 }
163
168
164 #include "moc_qbarset.cpp"
169 #include "moc_qbarset.cpp"
165 QTCOMMERCIALCHART_END_NAMESPACE
170 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,39 +1,51
1 #include "qpercentbarchartseries.h"
1 #include "qpercentbarchartseries.h"
2
2
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
4
5 /*!
5 /*!
6 \class QPercentBarChartSeries
6 \class QPercentBarChartSeries
7 \brief part of QtCommercial chart API.
7 \brief part of QtCommercial chart API.
8
8
9 QPercentBarChartSeries represents a series of data shown as bars. Each bar of QBarSet is shown as percentage
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.
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.
11 QBarChartSeries groups the data from sets to categories, which are defined by QBarCategory class.
12
12
13 \mainclass
13 \mainclass
14
14
15 Example on using QPercentBarChartSeries
15 Example on how to create category:
16 \snippet ../example/percentbarchart/main.cpp 1
16 \snippet ../example/barchart/main.cpp 1
17
18 Example on how to create sets of data:
19 \snippet ../example/barchart/main.cpp 2
20
21 Example on how to add sets to bar chart:
22 \snippet ../example/barchart/main.cpp 3
23
24 Example on how to enable tooltip and floating values:
25 \snippet ../example/barchart/main.cpp 4
26
27 Example on how to create view and apply theme:
28 \snippet ../example/barchart/main.cpp 5
17
29
18 \sa QBarCategory, QBarSet, QStackedBarChartSeries, QBarChartSeries
30 \sa QBarCategory, QBarSet, QStackedBarChartSeries, QBarChartSeries
19 */
31 */
20
32
21 /*!
33 /*!
22 \fn virtual QChartSeriesType QPercentBarChartSeries::type() const
34 \fn virtual QChartSeriesType QPercentBarChartSeries::type() const
23 \brief Returns type of series.
35 \brief Returns type of series.
24 \sa QChartSeries, QChartSeriesType
36 \sa QChartSeries, QChartSeriesType
25 */
37 */
26
38
27 /*!
39 /*!
28 Constructs empty QPercentBarChartSeries. Parameter \a category defines the categories for chart.
40 Constructs empty QPercentBarChartSeries. Parameter \a category defines the categories for chart.
29 QPercentBarChartSeries is QObject which is a child of a \a parent.
41 QPercentBarChartSeries is QObject which is a child of a \a parent.
30 */
42 */
31 QPercentBarChartSeries::QPercentBarChartSeries(QBarCategory *category, QObject *parent)
43 QPercentBarChartSeries::QPercentBarChartSeries(QBarCategory *category, QObject *parent)
32 : QBarChartSeries(category, parent)
44 : QBarChartSeries(category, parent)
33 {
45 {
34 }
46 }
35
47
36 #include "moc_qpercentbarchartseries.cpp"
48 #include "moc_qpercentbarchartseries.cpp"
37
49
38 QTCOMMERCIALCHART_END_NAMESPACE
50 QTCOMMERCIALCHART_END_NAMESPACE
39
51
@@ -1,39 +1,51
1 #include "qstackedbarchartseries.h"
1 #include "qstackedbarchartseries.h"
2
2
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
4
5 /*!
5 /*!
6 \class QStackedBarChartSeries
6 \class QStackedBarChartSeries
7 \brief part of QtCommercial chart API.
7 \brief part of QtCommercial chart API.
8
8
9 QStackedBarChartSeries represents a series of data shown as bars. All bars in same category are
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.
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.
11 QStackedBarChartSeries groups the data from sets to categories, which are defined by QBarCategory class.
12
12
13 \mainclass
13 \mainclass
14
14
15 Example on using QStackedBarChartSeries
15 Example on how to create category:
16 \snippet ../example/stackedbarchart/main.cpp 1
16 \snippet ../example/barchart/main.cpp 1
17
18 Example on how to create sets of data:
19 \snippet ../example/barchart/main.cpp 2
20
21 Example on how to add sets to bar chart:
22 \snippet ../example/barchart/main.cpp 3
23
24 Example on how to enable tooltip and floating values:
25 \snippet ../example/barchart/main.cpp 4
26
27 Example on how to create view and apply theme:
28 \snippet ../example/barchart/main.cpp 5
17
29
18 \sa QBarCategory, QBarSet, QPercentBarChartSeries, QBarChartSeries
30 \sa QBarCategory, QBarSet, QPercentBarChartSeries, QBarChartSeries
19 */
31 */
20
32
21 /*!
33 /*!
22 \fn virtual QChartSeriesType QStackedBarChartSeries::type() const
34 \fn virtual QChartSeriesType QStackedBarChartSeries::type() const
23 \brief Returns type of series.
35 \brief Returns type of series.
24 \sa QChartSeries, QChartSeriesType
36 \sa QChartSeries, QChartSeriesType
25 */
37 */
26
38
27 /*!
39 /*!
28 Constructs empty QStackedBarChartSeries. Parameter \a category defines the categories for chart.
40 Constructs empty QStackedBarChartSeries. Parameter \a category defines the categories for chart.
29 QStackedBarChartSeries is QObject which is a child of a \a parent.
41 QStackedBarChartSeries is QObject which is a child of a \a parent.
30 */
42 */
31 QStackedBarChartSeries::QStackedBarChartSeries(QBarCategory *category, QObject *parent)
43 QStackedBarChartSeries::QStackedBarChartSeries(QBarCategory *category, QObject *parent)
32 : QBarChartSeries(category, parent)
44 : QBarChartSeries(category, parent)
33 {
45 {
34 }
46 }
35
47
36 #include "moc_qstackedbarchartseries.cpp"
48 #include "moc_qstackedbarchartseries.cpp"
37
49
38 QTCOMMERCIALCHART_END_NAMESPACE
50 QTCOMMERCIALCHART_END_NAMESPACE
39
51
General Comments 0
You need to be logged in to leave comments. Login now