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