##// END OF EJS Templates
QBoxSet changed from list to table mode. New example for file reading....
Mika Salmela -
r2508:25def4b65f99
parent child
Show More
@@ -0,0 +1,59
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "boxdatareader.h"
22
23 #include <QDebug>
24
25 BoxDataReader::BoxDataReader(QIODevice *fileHandle) :
26 QTextStream(fileHandle)
27 {
28 }
29
30 QBoxSet* BoxDataReader::readBox()
31 {
32 QString line = readLine();
33 if (line.startsWith("#"))
34 return 0;
35
36 QStringList strList = line.split(" ", QString::SkipEmptyParts);
37 QList<qreal> sortedList;
38 foreach (QString str, strList) {
39 sortedList.append(str.toDouble());
40 }
41
42 qSort(sortedList.begin(), sortedList.end());
43 qDebug() << "sortedList = " << sortedList;
44
45 int count = sortedList.count();
46 int median = (int)(count / 2);
47 int lowerQ = (int)(median / 2);
48 int upperQ = median + lowerQ + 1;
49
50 QBoxSet *box = new QBoxSet();
51 box->setLowerExtreme(sortedList.at(0));
52 box->setLowerQuartile(sortedList.at(lowerQ));
53 box->setMedian(sortedList.at(median));
54 box->setUpperQuartile(sortedList.at(upperQ));
55 box->setUpperExtreme(sortedList.last());
56
57 return box;
58 }
59
@@ -0,0 +1,41
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #ifndef BOXDATAREADER_H
22 #define BOXDATAREADER_H
23
24 #include <QTextStream>
25 #include <QBoxSet>
26
27 QTCOMMERCIALCHART_USE_NAMESPACE
28
29 class BoxDataReader : public QTextStream
30 {
31 public:
32 explicit BoxDataReader(QIODevice *fileHandle);
33 QBoxSet* readBox();
34
35 protected:
36 qreal findMedian(int begin, int end);
37
38 private:
39 };
40
41 #endif // BOXDATAREADER_H
@@ -0,0 +1,5
1 <RCC>
2 <qresource prefix="/">
3 <file alias="stock">stock_data.txt</file>
4 </qresource>
5 </RCC>
@@ -0,0 +1,5
1 1.0 1.2 2.0 2.4 2.5 3.0 3.5 3.7 4.0 4.7 5.0
2 4.6 4.7 5.2 7.3 8.4 8.8 9.1 8.3 7.4 6.4 5.3
3 3.5 7.2 5.4 6.3 7.4 8.3 8.8 3.3 5.4 5.7 3.9
4 #0 1 2 3 4 5 6 7 8 9 10
5 # * * *
@@ -1,6 +1,13
1 1 !include( ../examples.pri ) {
2 2 error( "Couldn't find the examples.pri file!" )
3 3 }
4 4
5 5 TARGET = boxplotchart
6 SOURCES += main.cpp
6 SOURCES += main.cpp \
7 boxdatareader.cpp
8
9 RESOURCES += \
10 boxplotdata.qrc
11
12 HEADERS += \
13 boxdatareader.h
@@ -1,151 +1,126
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QApplication>
22 22 #include <QMainWindow>
23 23 #include <QChartView>
24 24 #include <QBoxPlotSeries>
25 25 #include <QBoxSet>
26 26 #include <QLegend>
27 27 #include <QBarCategoryAxis>
28 28 #include <QLineSeries>
29 29 #include <QScatterSeries>
30 #include <QTextStream>
30 31
31 32 #include <QBrush>
32 33 #include <QColor>
33 34
35 #include "boxdatareader.h"
36
37 #include <QDebug>
38
34 39 QTCOMMERCIALCHART_USE_NAMESPACE
35 40
36 41 int main(int argc, char *argv[])
37 42 {
38 43 QApplication a(argc, argv);
39
40 //![1]
41 QBoxSet *set0 = new QBoxSet();
42 QBoxSet *set1 = new QBoxSet();
43 QBoxSet *set2 = new QBoxSet();
44 QBoxSet *set3 = new QBoxSet();
45 QBoxSet *set4 = new QBoxSet();
46 QBoxSet *set5 = new QBoxSet();
47 QBoxSet *set6 = new QBoxSet();
48 QBoxSet *set7 = new QBoxSet();
49 QBoxSet *set8 = new QBoxSet();
50 QBoxSet *set9 = new QBoxSet();
51 QBoxSet *set10 = new QBoxSet();
52 QBoxSet *set11 = new QBoxSet();
53
54 // low bot med top upp
55 *set0 << 3 << 4 << 4.4 << 6 << 7;
56 *set1 << 5 << 6 << 7.5 << 8 << 12;
57 *set2 << 3 << 5 << 5.7 << 8 << 9;
58 *set3 << 5 << 6 << 6.8 << 7 << 8;
59 *set4 << 4 << 5 << 5.2 << 6 << 7;
60 *set5 << 4 << 7 << 8.2 << 9 << 10;
61 *set6 << 2.5 << 5 << 5.4 << 6 << 7;
62 *set7 << 5 << 6.3 << 7.5 << 8 << 12;
63 *set8 << 2.6 << 5.1 << 5.7 << 8 << 9;
64 *set9 << 3.1 << 5.8 << 6.8 << 7 << 8;
65 *set10 << 4.2 << 5 << 5.8 << 6 << 7;
66 *set11 << 4.7 << 7 << 8.2 << 9 << 10;
67
68 44 //![1]
69 45
70 46 //![2]
71 47 QBoxPlotSeries *series = new QBoxPlotSeries();
72 series->append(set0);
73 series->append(set1);
74 series->append(set2);
75 series->append(set3);
76 series->append(set4);
77 series->append(set5);
78 series->append(set6);
79 series->append(set7);
80 series->append(set8);
81 series->append(set9);
82 series->append(set10);
83 series->append(set11);
84 48 series->setName("Box & Whiskers");
85 49 //![2]
86 50
87 QLineSeries *lineSeries = new QLineSeries();
88 lineSeries->append(0, 4.4);
89 lineSeries->append(1, 7.5);
90 lineSeries->append(2, 5.7);
91 lineSeries->append(3, 6.8);
92 lineSeries->append(4, 5.2);
93 lineSeries->append(5, 8.2);
94 lineSeries->append(6, 5.4);
95 lineSeries->append(7, 7.5);
96 lineSeries->append(8, 5.7);
97 lineSeries->append(9, 6.8);
98 lineSeries->append(10, 5.2);
99 lineSeries->append(11, 8.2);
100 lineSeries->setName("Medians");
101
102 QScatterSeries *scatterSeries = new QScatterSeries();
103 scatterSeries->setName("Outliers");
104 scatterSeries->setMarkerShape(QScatterSeries::MarkerShapeCircle);
105 scatterSeries->setMarkerSize(7.0);
106 scatterSeries->setBrush(QBrush(Qt::white));
107 scatterSeries->setPen(QPen(Qt::black, 1.0));
108 scatterSeries->append(1, 4);
109 scatterSeries->append(1, 4.1);
110 scatterSeries->append(1, 4.2);
111 scatterSeries->append(1, 4.3);
112 *scatterSeries << QPointF(3, 8.5) << QPointF(3, 8.6);
51 QFile stockData(":stock");
52 if (!stockData.open(QIODevice::ReadOnly | QIODevice::Text)) {
53 return 1;
54 }
55
56 BoxDataReader dataReader(&stockData);
57 while (!dataReader.atEnd()) {
58 QBoxSet *set = dataReader.readBox();
59 if (set)
60 series->append(set);
61 }
62
63 // QTextStream stream(&stockData);
64 // while (!stream.atEnd()) {
65 // QString line = stream.readLine();
66 // if (line.startsWith("#"))
67 // continue;
68 // QStringList strList = line.split(" ", QString::SkipEmptyParts);
69 // QList<qreal> realList;
70 // foreach (QString str, strList) {
71 // realList.append(str.toDouble());
72 // }
73
74 // qSort(realList.begin(), realList.end());
75
76 // int count = realList.count();
77 // int median = (int)(count / 2);
78 // int lowerQ = (int)(median / 2);
79 // int upperQ = median + lowerQ + 1;
80 // QBoxSet *set = new QBoxSet();
81
82 // set->setLowerExtreme(realList.at(0));
83 // set->setLowerQuartile(realList.at(lowerQ));
84 // set->setMedian(realList.at(median));
85 // set->setUpperQuartile(realList.at(upperQ));
86 // set->setUpperExtreme(realList.last());
87
88 // series->append(set);
89 // }
113 90
114 91 //![3]
115 92 QChart *chart = new QChart();
116 93 chart->addSeries(series);
117 chart->addSeries(lineSeries);
118 chart->addSeries(scatterSeries);
119 94 chart->setTitle("Simple boxplotchart example");
120 95 chart->setAnimationOptions(QChart::SeriesAnimations);
121 96 //![3]
122 97
123 98 //![4]
124 QStringList categories;
125 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
99 //QStringList categories;
100 //categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
126 101 QBarCategoryAxis *axis = new QBarCategoryAxis();
127 axis->append(categories);
102 //axis->append(categories);
128 103 chart->createDefaultAxes();
129 104 chart->setAxisX(axis, series);
130 105 //![4]
131 106
132 107 //![5]
133 108 chart->legend()->setVisible(true);
134 109 chart->legend()->setAlignment(Qt::AlignBottom);
135 110 //![5]
136 111
137 112 //![6]
138 113 QChartView *chartView = new QChartView(chart);
139 114 chartView->setRenderHint(QPainter::Antialiasing);
140 115 //![6]
141 116
142 117 //![7]
143 118 QMainWindow window;
144 119 window.setCentralWidget(chartView);
145 120 window.resize(600, 400);
146 121 window.show();
147 122 //![7]
148 123
149 124 return a.exec();
150 125 }
151 126
@@ -1,397 +1,378
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2013 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qboxset.h"
22 22 #include "qboxset_p.h"
23 23 #include "charthelpers_p.h"
24 24
25 #include <QDebug> //TODO: remove on release
26
25 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 28
27 29 /*!
28 30 Constructs QBoxSet with parent of \a parent
29 31 */
30 32 QBoxSet::QBoxSet(QObject *parent)
31 33 : QObject(parent),
32 34 d_ptr(new QBoxSetPrivate(this))
33 35 {
34 36 }
35 37
36 38 QBoxSet::QBoxSet(qreal value1, qreal value2, qreal value3, qreal value4, qreal value5, QObject *parent)
37 39 : QObject(parent),
38 40 d_ptr(new QBoxSetPrivate(this))
39 41 {
40 42 d_ptr->append(value1);
41 43 d_ptr->append(value2);
42 44 d_ptr->append(value3);
43 45 d_ptr->append(value4);
44 46 d_ptr->append(value5);
45 47 }
46 48
47 49 /*!
48 50 Destroys the boxset
49 51 */
50 52 QBoxSet::~QBoxSet()
51 53 {
52 54 // NOTE: d_ptr destroyed by QObject
53 55 }
54 56
55 57 /*!
56 58 Appends new value \a value to the end of set.
57 59 */
58 60 void QBoxSet::append(const qreal value)
59 61 {
60 int index = d_ptr->m_values.count();
62 //int index = d_ptr->m_values.count();
61 63 d_ptr->append(value);
62 64
63 emit valuesAdded(index, 1);
65 emit valuesAdded(d_ptr->m_valuesCount, 1);
64 66 }
65 67
66 68 /*!
67 69 Appends a list of reals to set. Works like append with single real value. The \a values in list
68 70 are appended to end of boxset
69 71 \sa append()
70 72 */
71 73 void QBoxSet::append(const QList<qreal> &values)
72 74 {
73 int index = d_ptr->m_values.count();
75 //int index = d_ptr->m_values.count();
74 76 d_ptr->append(values);
75 emit valuesAdded(index, values.count());
77 emit valuesAdded(d_ptr->m_valuesCount, values.count());
76 78 }
77 79
78 80 /*!
79 81 Sets new value \a value as the lower extreme for the set.
80 82 */
81 83 void QBoxSet::setLowerExtreme(const qreal value)
82 84 {
83 85 d_ptr->replace(QBoxSetPrivate::PosLowerExtreme, value);
86 emit d_ptr->restructuredBox();
84 87 emit valueChanged(QBoxSetPrivate::PosLowerExtreme);
85 88 }
86 89
87 90 /*!
88 91 Returns the lower extreme value of the set.
89 92 */
90 93 qreal QBoxSet::lowerExtreme()
91 94 {
92 return d_ptr->m_values.at(QBoxSetPrivate::PosLowerExtreme);
95 return d_ptr->m_values[QBoxSetPrivate::PosLowerExtreme];
93 96 }
94 97
95 98 /*!
96 99 Sets new value \a value as the lower quartile for the set.
97 100 */
98 101 void QBoxSet::setLowerQuartile(const qreal value)
99 102 {
100 103 d_ptr->replace(QBoxSetPrivate::PosLowerQuartile, value);
104 emit d_ptr->restructuredBox();
101 105 emit valueChanged(QBoxSetPrivate::PosLowerQuartile);
102 106 }
103 107
104 108 /*!
105 109 Returns the lower quartile value of the set.
106 110 */
107 111 qreal QBoxSet::lowerQuartile()
108 112 {
109 return d_ptr->m_values.at(QBoxSetPrivate::PosLowerQuartile);
113 return d_ptr->m_values[QBoxSetPrivate::PosLowerQuartile];
110 114 }
111 115
112 116 /*!
113 117 Sets new value \a value as the median for the set.
114 118 */
115 119 void QBoxSet::setMedian(const qreal value)
116 120 {
117 121 d_ptr->replace(QBoxSetPrivate::PosMedian, value);
122 emit d_ptr->restructuredBox();
118 123 emit valueChanged(QBoxSetPrivate::PosMedian);
119 124 }
120 125
121 126 /*!
122 127 Returns the median value of the set.
123 128 */
124 129 qreal QBoxSet::median()
125 130 {
126 return d_ptr->m_values.at(QBoxSetPrivate::PosMedian);
131 return d_ptr->m_values[QBoxSetPrivate::PosMedian];
127 132 }
128 133
129 134 /*!
130 135 Sets new value \a value as the upper quartile for the set.
131 136 */
132 137 void QBoxSet::setUpperQuartile(const qreal value)
133 138 {
134 139 d_ptr->replace(QBoxSetPrivate::PosUpperQuartile, value);
140 emit d_ptr->restructuredBox();
135 141 emit valueChanged(QBoxSetPrivate::PosUpperQuartile);
136 142 }
137 143
138 144 /*!
139 145 Returns the upper quartile value of the set.
140 146 */
141 147 qreal QBoxSet::upperQuartile()
142 148 {
143 return d_ptr->m_values.at(QBoxSetPrivate::PosUpperQuartile);
149 return d_ptr->m_values[QBoxSetPrivate::PosUpperQuartile];
144 150 }
145 151
146 152 /*!
147 153 Sets new value \a value as the upper extreme for the set.
148 154 */
149 155 void QBoxSet::setUpperExtreme(const qreal value)
150 156 {
151 d_ptr->replace(QBoxSetPrivate::PosUpperQuartile, value);
152 emit valueChanged(QBoxSetPrivate::PosUpperQuartile);
157 d_ptr->replace(QBoxSetPrivate::PosUpperExtreme, value);
158 emit d_ptr->restructuredBox();
159 emit valueChanged(QBoxSetPrivate::PosUpperExtreme);
153 160 }
154 161
155 162 /*!
156 163 Returns the upper extreme value of the set.
157 164 */
158 165 qreal QBoxSet::upperExtreme()
159 166 {
160 return d_ptr->m_values.at(QBoxSetPrivate::PosUpperExtreme);
167 return d_ptr->m_values[QBoxSetPrivate::PosUpperExtreme];
161 168 }
162 169
163 170 /*!
164 171 Convenience operator. Same as append, with real \a value.
165 172 \sa append()
166 173 */
167 174 QBoxSet &QBoxSet::operator << (const qreal &value)
168 175 {
169 176 append(value);
170 177 return *this;
171 178 }
172 179
173 180 /*!
174 181 Inserts new \a value on the \a index position.
175 182 The value that is currently at this postion is moved to postion index + 1
176 \sa remove()
177 183 */
178 184 void QBoxSet::insert(const int index, const qreal value)
179 185 {
180 186 d_ptr->insert(index, value);
181 187 emit valuesAdded(index, 1);
182 188 }
183 189
184 190 /*!
185 Removes \a count number of values from the set starting at \a index.
186 \sa insert()
187 */
188 void QBoxSet::remove(const int index, const int count)
189 {
190 int removedCount = d_ptr->remove(index, count);
191 if (removedCount > 0)
192 emit valuesRemoved(index, removedCount);
193 return;
194 }
195
196 /*!
197 191 Sets a new value \a value to set, indexed by \a index
198 192 */
199 193 void QBoxSet::replace(const int index, const qreal value)
200 194 {
201 if (index >= 0 && index < d_ptr->m_values.count()) {
195 if (index >= 0 && index < 5) {
202 196 d_ptr->replace(index, value);
203 197 emit valueChanged(index);
204 198 }
205 199 }
206 200
207 201
208 202 /*!
209 203 Returns value of set indexed by \a index.
210 204 If the index is out of bounds 0.0 is returned.
211 205 */
212 206 qreal QBoxSet::at(const int index) const
213 207 {
214 if (index < 0 || index >= d_ptr->m_values.count())
208 if (index < 0 || index >= 5)
215 209 return 0;
216 return d_ptr->m_values.at(index);
210 return d_ptr->m_values[index];
217 211 }
218 212
219 213 /*!
220 214 Returns value of set indexed by \a index.
221 215 If the index is out of bounds 0.0 is returned.
222 216 */
223 217 qreal QBoxSet::operator [](const int index) const
224 218 {
225 219 return at(index);
226 220 }
227 221
228 222 /*!
229 223 Returns count of values in set.
230 224 */
231 225 int QBoxSet::count() const
232 226 {
233 return d_ptr->m_values.count();
227 return d_ptr->m_valuesCount;
234 228 }
235 229
236 230 /*!
237 231 Sets pen for set. Boxes of this set are drawn using \a pen
238 232 */
239 233 void QBoxSet::setPen(const QPen &pen)
240 234 {
241 235 if (d_ptr->m_pen != pen) {
242 236 d_ptr->m_pen = pen;
243 237 emit d_ptr->updatedBox();
244 238 emit penChanged();
245 239 }
246 240 }
247 241
248 242 /*!
249 243 Returns pen of the set.
250 244 */
251 245 QPen QBoxSet::pen() const
252 246 {
253 247 return d_ptr->m_pen;
254 248 }
255 249
256 250 /*!
257 251 Sets brush for the set. Boxes of this set are drawn using \a brush
258 252 */
259 253 void QBoxSet::setBrush(const QBrush &brush)
260 254 {
261 255 if (d_ptr->m_brush != brush) {
262 256 d_ptr->m_brush = brush;
263 257 emit d_ptr->updatedBox();
264 258 emit brushChanged();
265 259 }
266 260 }
267 261
268 262 /*!
269 263 Returns brush of the set.
270 264 */
271 265 QBrush QBoxSet::brush() const
272 266 {
273 267 return d_ptr->m_brush;
274 268 }
275 269
276 270 /*!
277 271 Returns the color of the brush of boxset.
278 272 */
279 273 QColor QBoxSet::color()
280 274 {
281 275 return brush().color();
282 276 }
283 277
284 278 /*!
285 279 Sets the \a color of brush for this boxset
286 280 */
287 281 void QBoxSet::setColor(QColor color)
288 282 {
289 283 QBrush b = brush();
290 284 if ((b.color() != color) || (b.style() == Qt::NoBrush)) {
291 285 b.setColor(color);
292 286 if (b.style() == Qt::NoBrush) {
293 287 // Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush)
294 288 // This prevents theme to override color defined in QML side:
295 289 // BoxSet { label: "Bob"; color:"red"; values: [1,2,3] }
296 290 // The color must be obeyed, since user wanted it.
297 291 b.setStyle(Qt::SolidPattern);
298 292 }
299 293 setBrush(b);
300 294 emit colorChanged(color);
301 295 }
302 296 }
303 297
304 298 /*!
305 299 Returns the color of pen of this boxset
306 300 */
307 301 QColor QBoxSet::borderColor()
308 302 {
309 303 return pen().color();
310 304 }
311 305
312 306 /*!
313 307 Sets the color of pen for this boxset
314 308 */
315 309 void QBoxSet::setBorderColor(QColor color)
316 310 {
317 311 QPen p = pen();
318 312 if (p.color() != color) {
319 313 p.setColor(color);
320 314 setPen(p);
321 315 emit borderColorChanged(color);
322 316 }
323 317 }
324 318
325 319 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
326 320
327 321 QBoxSetPrivate::QBoxSetPrivate(QBoxSet *parent) : QObject(parent),
328 322 q_ptr(parent),
323 m_valuesCount(5),
324 m_appendCount(0),
329 325 m_pen(QPen(Qt::NoPen)),
330 326 m_brush(QBrush(Qt::NoBrush))
331 327 {
328 m_values = new qreal[m_valuesCount];
332 329 }
333 330
334 331 QBoxSetPrivate::~QBoxSetPrivate()
335 332 {
336 333 }
337 334
338 335 void QBoxSetPrivate::append(qreal value)
339 336 {
340 if (isValidValue(value)) {
341 m_values.append(value);
337 if (isValidValue(value) && m_appendCount < m_valuesCount) {
338 m_values[m_appendCount++] = value;
342 339 emit restructuredBox();
343 340 }
344 341 }
345 342
346 343 void QBoxSetPrivate::append(QList<qreal> values)
347 344 {
348 345 for (int i = 0; i < values.count(); i++) {
349 if (isValidValue(values.at(i)))
350 m_values.append(values.at(i));
346 if (isValidValue(values.at(i)) && m_appendCount < m_valuesCount)
347 m_values[m_appendCount++] = values.at(i);
351 348 }
352 349 emit restructuredBox();
353 350 }
354 351
355 352 void QBoxSetPrivate::insert(const int index, const qreal value)
356 353 {
357 354 if (isValidValue(value)) {
358 m_values.insert(index, value);
355 for (int i = 4; i > index; i--)
356 m_values[i] = m_values[i - 1];
357 m_values[index] = value;
359 358 emit restructuredBox();
360 359 }
361 360 }
362 361
363 int QBoxSetPrivate::remove(const int index, const int count)
364 {
365 int removeCount = count;
366
367 if ((index < 0) || (m_values.count() == 0))
368 return 0; // Invalid index or not values in list, remove nothing.
369 else if ((index + count) > m_values.count())
370 removeCount = m_values.count() - index; // Trying to remove more items than list has. Limit amount to be removed.
371
372 int c = 0;
373 while (c < removeCount) {
374 m_values.removeAt(index);
375 c++;
376 }
377 emit restructuredBox();
378 return removeCount;
379 }
380
381 362 void QBoxSetPrivate::replace(const int index, const qreal value)
382 363 {
383 m_values.replace(index, value);
364 m_values[index] = value;
384 365 emit updatedLayout();
385 366 }
386 367
387 368 qreal QBoxSetPrivate::value(const int index)
388 369 {
389 if (index < 0 || index >= m_values.count())
370 if (index < 0 || index >= m_valuesCount)
390 371 return 0;
391 return m_values.at(index);
372 return m_values[index];
392 373 }
393 374
394 375 #include "moc_qboxset.cpp"
395 376 #include "moc_qboxset_p.cpp"
396 377
397 378 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,87 +1,90
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2013 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QBOXSET_P_H
31 31 #define QBOXSET_P_H
32 32
33 33 #include "qboxset.h"
34 34 #include <QMap>
35 35 #include <QPen>
36 36 #include <QBrush>
37 37 #include <QFont>
38 38
39 39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40 40
41 41 class QBoxSetPrivate : public QObject
42 42 {
43 43 Q_OBJECT
44 44
45 45 public:
46 46 enum DataPositions {
47 47 PosLowerExtreme,
48 48 PosLowerQuartile,
49 49 PosMedian,
50 50 PosUpperQuartile,
51 51 PosUpperExtreme
52 52 };
53 53
54 54 public:
55 55 QBoxSetPrivate(QBoxSet *parent);
56 56 ~QBoxSetPrivate();
57 57
58 58 void append(qreal value);
59 59 void append(QList<qreal> values);
60 60
61 61 void insert(const int index, const qreal value);
62 62 int remove(const int index, const int count);
63 63
64 64 void replace(const int index, const qreal value);
65 65
66 66 qreal value(const int index);
67 67
68 68 Q_SIGNALS:
69 69 void restructuredBox();
70 70 void updatedBox();
71 71 void updatedLayout();
72 72
73 73 public:
74 74 QBoxSet * const q_ptr;
75 75 //QString m_label;
76 QList<qreal> m_values;
76 //QList<qreal> m_values;
77 const int m_valuesCount;
78 qreal *m_values;
79 int m_appendCount;
77 80 QPen m_pen;
78 81 QBrush m_brush;
79 82 QBrush m_labelBrush;
80 83 QFont m_labelFont;
81 84
82 85 friend class QBoxSet;
83 86 };
84 87
85 88 QTCOMMERCIALCHART_END_NAMESPACE
86 89
87 90 #endif // QBOXSET_P_H
General Comments 0
You need to be logged in to leave comments. Login now