@@ -1,71 +1,69 | |||||
1 | #include <QApplication> |
|
1 | #include <QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <qchartview.h> |
|
3 | #include <qchartview.h> | |
4 | #include <qbarseries.h> |
|
4 | #include <qbarseries.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 | // Create category | |
17 | QBarCategory *category = new QBarCategory; |
|
17 | QBarCategory *category = new QBarCategory; | |
18 | *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] |
|
19 | //! [1] | |
20 |
|
20 | |||
21 | //! [2] |
|
21 | //! [2] | |
22 | // Create some test sets for chat |
|
22 | // Create some test sets for chat | |
23 |
|
23 | |||
24 | QBarSet *set0 = new QBarSet("Bub"); |
|
24 | QBarSet *set0 = new QBarSet("Bub"); | |
25 | QBarSet *set1 = new QBarSet("Bob"); |
|
25 | QBarSet *set1 = new QBarSet("Bob"); | |
26 | QBarSet *set2 = new QBarSet("Guybrush"); |
|
26 | QBarSet *set2 = new QBarSet("Guybrush"); | |
27 | QBarSet *set3 = new QBarSet("Larry"); |
|
27 | QBarSet *set3 = new QBarSet("Larry"); | |
28 | QBarSet *set4 = new QBarSet("Zak"); |
|
28 | QBarSet *set4 = new QBarSet("Zak"); | |
29 |
|
29 | |||
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] |
|
35 | //! [2] | |
36 |
|
36 | |||
37 | //! [3] |
|
37 | //! [3] | |
38 | // Create series and add sets to it |
|
38 | // Create series and add sets to it | |
39 | QBarSeries* series= new QBarSeries(category); |
|
39 | QBarSeries* series= new QBarSeries(category); | |
40 |
|
40 | |||
41 | series->addBarSet(set0); |
|
41 | series->addBarSet(set0); | |
42 | series->addBarSet(set1); |
|
42 | series->addBarSet(set1); | |
43 | series->addBarSet(set2); |
|
43 | series->addBarSet(set2); | |
44 | series->addBarSet(set3); |
|
44 | series->addBarSet(set3); | |
45 | series->addBarSet(set4); |
|
45 | series->addBarSet(set4); | |
46 | //! [3] |
|
46 | //! [3] | |
47 |
|
47 | |||
48 | //! [4] |
|
48 | //! [4] | |
49 | // Enable some features |
|
49 | // Enable some features | |
50 | // series->setToolTipEnabled(); |
|
|||
51 | // series->enableFloatingValues(); |
|
|||
52 | series->setToolTipEnabled(); |
|
50 | series->setToolTipEnabled(); | |
53 | series->setFloatingValuesEnabled(); |
|
51 | series->setFloatingValuesEnabled(); | |
54 | //! [4] |
|
52 | //! [4] | |
55 |
|
53 | |||
56 | //! [5] |
|
54 | //! [5] | |
57 | // Create view for chart and add series to it. Apply theme. |
|
55 | // Create view for chart and add series to it. Apply theme. | |
58 |
|
56 | |||
59 | QChartView* chartView = new QChartView(&window); |
|
57 | QChartView* chartView = new QChartView(&window); | |
60 | chartView->addSeries(series); |
|
58 | chartView->addSeries(series); | |
61 | chartView->setChartTitle("simple stacked barchart"); |
|
59 | chartView->setChartTitle("simple stacked barchart"); | |
62 | chartView->setChartTheme(QChart::ChartThemeIcy); |
|
60 | chartView->setChartTheme(QChart::ChartThemeIcy); | |
63 | //! [5] |
|
61 | //! [5] | |
64 |
|
62 | |||
65 | window.setCentralWidget(chartView); |
|
63 | window.setCentralWidget(chartView); | |
66 | window.resize(600, 300); |
|
64 | window.resize(600, 300); | |
67 | window.show(); |
|
65 | window.show(); | |
68 |
|
66 | |||
69 | return a.exec(); |
|
67 | return a.exec(); | |
70 | } |
|
68 | } | |
71 |
|
69 |
@@ -1,170 +1,167 | |||||
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 |
|
16 | \mainclass | |
17 |
|
17 | |||
18 | Example on how to create sets of data: |
|
|||
19 | \snippet ../example/barchart/main.cpp 2 |
|
|||
20 |
|
||||
21 | \sa QBarCategory, QBarSeries, QStackedBarSeries, QPercentBarSeries |
|
18 | \sa QBarCategory, QBarSeries, QStackedBarSeries, QPercentBarSeries | |
22 | */ |
|
19 | */ | |
23 |
|
20 | |||
24 | /*! |
|
21 | /*! | |
25 | \fn void QBarSet::clicked() |
|
22 | \fn void QBarSet::clicked() | |
26 | \brief signals that set has been clicked |
|
23 | \brief signals that set has been clicked | |
27 | */ |
|
24 | */ | |
28 | /*! |
|
25 | /*! | |
29 | \fn void QBarSet::hoverEnter(QPoint pos) |
|
26 | \fn void QBarSet::hoverEnter(QPoint pos) | |
30 | \brief signals that mouse has entered over the set at position \a pos. |
|
27 | \brief signals that mouse has entered over the set at position \a pos. | |
31 | */ |
|
28 | */ | |
32 | /*! |
|
29 | /*! | |
33 | \fn void QBarSet::hoverLeave() |
|
30 | \fn void QBarSet::hoverLeave() | |
34 | \brief signals that mouse has left from the set. |
|
31 | \brief signals that mouse has left from the set. | |
35 | */ |
|
32 | */ | |
36 | /*! |
|
33 | /*! | |
37 | \fn void QBarSet::toggleFloatingValues() |
|
34 | \fn void QBarSet::toggleFloatingValues() | |
38 | \brief \internal |
|
35 | \brief \internal | |
39 | */ |
|
36 | */ | |
40 | /*! |
|
37 | /*! | |
41 | \fn void QBarSet::showToolTip(QPoint pos, QString tip) |
|
38 | \fn void QBarSet::showToolTip(QPoint pos, QString tip) | |
42 | \brief \internal \a pos \a tip |
|
39 | \brief \internal \a pos \a tip | |
43 | */ |
|
40 | */ | |
44 |
|
41 | |||
45 |
|
42 | |||
46 | /*! |
|
43 | /*! | |
47 | Constructs QBarSet with a name of \a name and with parent of \a parent |
|
44 | Constructs QBarSet with a name of \a name and with parent of \a parent | |
48 | */ |
|
45 | */ | |
49 | QBarSet::QBarSet(QString name, QObject *parent) |
|
46 | QBarSet::QBarSet(QString name, QObject *parent) | |
50 | : QObject(parent) |
|
47 | : QObject(parent) | |
51 | ,mName(name) |
|
48 | ,mName(name) | |
52 | { |
|
49 | { | |
53 | } |
|
50 | } | |
54 |
|
51 | |||
55 | /*! |
|
52 | /*! | |
56 | Sets new \a name for set. |
|
53 | Sets new \a name for set. | |
57 | */ |
|
54 | */ | |
58 | void QBarSet::setName(QString name) |
|
55 | void QBarSet::setName(QString name) | |
59 | { |
|
56 | { | |
60 | mName = name; |
|
57 | mName = name; | |
61 | } |
|
58 | } | |
62 |
|
59 | |||
63 | /*! |
|
60 | /*! | |
64 | Returns name of the set. |
|
61 | Returns name of the set. | |
65 | */ |
|
62 | */ | |
66 | QString QBarSet::name() |
|
63 | QString QBarSet::name() | |
67 | { |
|
64 | { | |
68 | return mName; |
|
65 | return mName; | |
69 | } |
|
66 | } | |
70 |
|
67 | |||
71 | /*! |
|
68 | /*! | |
72 | Appends new value \a value to the end of set. |
|
69 | Appends new value \a value to the end of set. | |
73 | */ |
|
70 | */ | |
74 | QBarSet& QBarSet::operator << (const qreal &value) |
|
71 | QBarSet& QBarSet::operator << (const qreal &value) | |
75 | { |
|
72 | { | |
76 | mValues.append(value); |
|
73 | mValues.append(value); | |
77 | return *this; |
|
74 | return *this; | |
78 | } |
|
75 | } | |
79 |
|
76 | |||
80 | /*! |
|
77 | /*! | |
81 | Returns count of values in set. |
|
78 | Returns count of values in set. | |
82 | */ |
|
79 | */ | |
83 | int QBarSet::count() |
|
80 | int QBarSet::count() | |
84 | { |
|
81 | { | |
85 | return mValues.count(); |
|
82 | return mValues.count(); | |
86 | } |
|
83 | } | |
87 |
|
84 | |||
88 | /*! |
|
85 | /*! | |
89 | Returns value of set indexed by \a index |
|
86 | Returns value of set indexed by \a index | |
90 | */ |
|
87 | */ | |
91 | qreal QBarSet::valueAt(int index) |
|
88 | qreal QBarSet::valueAt(int index) | |
92 | { |
|
89 | { | |
93 | return mValues.at(index); |
|
90 | return mValues.at(index); | |
94 | } |
|
91 | } | |
95 |
|
92 | |||
96 | /*! |
|
93 | /*! | |
97 | Sets a new value \a value to set, indexed by \a index |
|
94 | Sets a new value \a value to set, indexed by \a index | |
98 | */ |
|
95 | */ | |
99 | void QBarSet::setValue(int index, qreal value) |
|
96 | void QBarSet::setValue(int index, qreal value) | |
100 | { |
|
97 | { | |
101 | mValues.replace(index,value); |
|
98 | mValues.replace(index,value); | |
102 | } |
|
99 | } | |
103 |
|
100 | |||
104 | /*! |
|
101 | /*! | |
105 | Sets pen for set. Bars of this set are drawn using \a pen |
|
102 | Sets pen for set. Bars of this set are drawn using \a pen | |
106 | */ |
|
103 | */ | |
107 | void QBarSet::setPen(QPen pen) |
|
104 | void QBarSet::setPen(QPen pen) | |
108 | { |
|
105 | { | |
109 | mPen = pen; |
|
106 | mPen = pen; | |
110 | } |
|
107 | } | |
111 |
|
108 | |||
112 | /*! |
|
109 | /*! | |
113 | Returns pen of the set. |
|
110 | Returns pen of the set. | |
114 | */ |
|
111 | */ | |
115 | QPen QBarSet::pen() |
|
112 | QPen QBarSet::pen() | |
116 | { |
|
113 | { | |
117 | return mPen; |
|
114 | return mPen; | |
118 | } |
|
115 | } | |
119 |
|
116 | |||
120 | /*! |
|
117 | /*! | |
121 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
118 | Sets brush for the set. Bars of this set are drawn using \a brush | |
122 | */ |
|
119 | */ | |
123 | void QBarSet::setBrush(QBrush brush) |
|
120 | void QBarSet::setBrush(QBrush brush) | |
124 | { |
|
121 | { | |
125 | mBrush = brush; |
|
122 | mBrush = brush; | |
126 | } |
|
123 | } | |
127 |
|
124 | |||
128 | /*! |
|
125 | /*! | |
129 | Returns brush of the set. |
|
126 | Returns brush of the set. | |
130 | */ |
|
127 | */ | |
131 | QBrush QBarSet::brush() |
|
128 | QBrush QBarSet::brush() | |
132 | { |
|
129 | { | |
133 | return mBrush; |
|
130 | return mBrush; | |
134 | } |
|
131 | } | |
135 |
|
132 | |||
136 | /*! |
|
133 | /*! | |
137 | \internal |
|
134 | \internal | |
138 | */ |
|
135 | */ | |
139 | void QBarSet::barClicked() |
|
136 | void QBarSet::barClicked() | |
140 | { |
|
137 | { | |
141 | // qDebug() << "QBarset::barClicked" << this; |
|
138 | // qDebug() << "QBarset::barClicked" << this; | |
142 | // Some bar of this set has been clicked |
|
139 | // Some bar of this set has been clicked | |
143 | // TODO: What happens then? |
|
140 | // TODO: What happens then? | |
144 | emit clicked(); // Notify that set has been clicked |
|
141 | emit clicked(); // Notify that set has been clicked | |
145 | } |
|
142 | } | |
146 |
|
143 | |||
147 | /*! |
|
144 | /*! | |
148 | \internal \a pos |
|
145 | \internal \a pos | |
149 | */ |
|
146 | */ | |
150 | void QBarSet::barHoverEntered(QPoint pos) |
|
147 | void QBarSet::barHoverEntered(QPoint pos) | |
151 | { |
|
148 | { | |
152 | emit showToolTip(pos, mName); |
|
149 | emit showToolTip(pos, mName); | |
153 | emit hoverEnter(pos); |
|
150 | emit hoverEnter(pos); | |
154 | } |
|
151 | } | |
155 |
|
152 | |||
156 | /*! |
|
153 | /*! | |
157 | \internal |
|
154 | \internal | |
158 | */ |
|
155 | */ | |
159 | void QBarSet::barHoverLeaved() |
|
156 | void QBarSet::barHoverLeaved() | |
160 | { |
|
157 | { | |
161 | // qDebug() << "QBarset::barHoverLeaved" << this; |
|
158 | // qDebug() << "QBarset::barHoverLeaved" << this; | |
162 | // if (mToolTipEnabled) { |
|
159 | // if (mToolTipEnabled) { | |
163 | // TODO: do what? |
|
160 | // TODO: do what? | |
164 | // } |
|
161 | // } | |
165 | // Emit signal to user of charts |
|
162 | // Emit signal to user of charts | |
166 | emit hoverLeave(); |
|
163 | emit hoverLeave(); | |
167 | } |
|
164 | } | |
168 |
|
165 | |||
169 | #include "moc_qbarset.cpp" |
|
166 | #include "moc_qbarset.cpp" | |
170 | QTCOMMERCIALCHART_END_NAMESPACE |
|
167 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now