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