@@ -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 | # * * * |
@@ -3,4 +3,11 | |||||
3 | } |
|
3 | } | |
4 |
|
4 | |||
5 | TARGET = boxplotchart |
|
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 |
@@ -27,104 +27,79 | |||||
27 | #include <QBarCategoryAxis> |
|
27 | #include <QBarCategoryAxis> | |
28 | #include <QLineSeries> |
|
28 | #include <QLineSeries> | |
29 | #include <QScatterSeries> |
|
29 | #include <QScatterSeries> | |
|
30 | #include <QTextStream> | |||
30 |
|
31 | |||
31 | #include <QBrush> |
|
32 | #include <QBrush> | |
32 | #include <QColor> |
|
33 | #include <QColor> | |
33 |
|
34 | |||
|
35 | #include "boxdatareader.h" | |||
|
36 | ||||
|
37 | #include <QDebug> | |||
|
38 | ||||
34 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
39 | QTCOMMERCIALCHART_USE_NAMESPACE | |
35 |
|
40 | |||
36 | int main(int argc, char *argv[]) |
|
41 | int main(int argc, char *argv[]) | |
37 | { |
|
42 | { | |
38 | QApplication a(argc, argv); |
|
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 | //![1] |
|
44 | //![1] | |
69 |
|
45 | |||
70 | //![2] |
|
46 | //![2] | |
71 | QBoxPlotSeries *series = new QBoxPlotSeries(); |
|
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 | series->setName("Box & Whiskers"); |
|
48 | series->setName("Box & Whiskers"); | |
85 | //![2] |
|
49 | //![2] | |
86 |
|
50 | |||
87 | QLineSeries *lineSeries = new QLineSeries(); |
|
51 | QFile stockData(":stock"); | |
88 | lineSeries->append(0, 4.4); |
|
52 | if (!stockData.open(QIODevice::ReadOnly | QIODevice::Text)) { | |
89 | lineSeries->append(1, 7.5); |
|
53 | return 1; | |
90 | lineSeries->append(2, 5.7); |
|
54 | } | |
91 | lineSeries->append(3, 6.8); |
|
55 | ||
92 | lineSeries->append(4, 5.2); |
|
56 | BoxDataReader dataReader(&stockData); | |
93 | lineSeries->append(5, 8.2); |
|
57 | while (!dataReader.atEnd()) { | |
94 | lineSeries->append(6, 5.4); |
|
58 | QBoxSet *set = dataReader.readBox(); | |
95 | lineSeries->append(7, 7.5); |
|
59 | if (set) | |
96 |
|
|
60 | series->append(set); | |
97 | lineSeries->append(9, 6.8); |
|
61 | } | |
98 | lineSeries->append(10, 5.2); |
|
62 | ||
99 | lineSeries->append(11, 8.2); |
|
63 | // QTextStream stream(&stockData); | |
100 | lineSeries->setName("Medians"); |
|
64 | // while (!stream.atEnd()) { | |
101 |
|
65 | // QString line = stream.readLine(); | ||
102 | QScatterSeries *scatterSeries = new QScatterSeries(); |
|
66 | // if (line.startsWith("#")) | |
103 | scatterSeries->setName("Outliers"); |
|
67 | // continue; | |
104 | scatterSeries->setMarkerShape(QScatterSeries::MarkerShapeCircle); |
|
68 | // QStringList strList = line.split(" ", QString::SkipEmptyParts); | |
105 | scatterSeries->setMarkerSize(7.0); |
|
69 | // QList<qreal> realList; | |
106 | scatterSeries->setBrush(QBrush(Qt::white)); |
|
70 | // foreach (QString str, strList) { | |
107 | scatterSeries->setPen(QPen(Qt::black, 1.0)); |
|
71 | // realList.append(str.toDouble()); | |
108 | scatterSeries->append(1, 4); |
|
72 | // } | |
109 | scatterSeries->append(1, 4.1); |
|
73 | ||
110 | scatterSeries->append(1, 4.2); |
|
74 | // qSort(realList.begin(), realList.end()); | |
111 | scatterSeries->append(1, 4.3); |
|
75 | ||
112 | *scatterSeries << QPointF(3, 8.5) << QPointF(3, 8.6); |
|
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 | //![3] |
|
91 | //![3] | |
115 | QChart *chart = new QChart(); |
|
92 | QChart *chart = new QChart(); | |
116 | chart->addSeries(series); |
|
93 | chart->addSeries(series); | |
117 | chart->addSeries(lineSeries); |
|
|||
118 | chart->addSeries(scatterSeries); |
|
|||
119 | chart->setTitle("Simple boxplotchart example"); |
|
94 | chart->setTitle("Simple boxplotchart example"); | |
120 | chart->setAnimationOptions(QChart::SeriesAnimations); |
|
95 | chart->setAnimationOptions(QChart::SeriesAnimations); | |
121 | //![3] |
|
96 | //![3] | |
122 |
|
97 | |||
123 | //![4] |
|
98 | //![4] | |
124 | QStringList categories; |
|
99 | //QStringList categories; | |
125 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; |
|
100 | //categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; | |
126 | QBarCategoryAxis *axis = new QBarCategoryAxis(); |
|
101 | QBarCategoryAxis *axis = new QBarCategoryAxis(); | |
127 | axis->append(categories); |
|
102 | //axis->append(categories); | |
128 | chart->createDefaultAxes(); |
|
103 | chart->createDefaultAxes(); | |
129 | chart->setAxisX(axis, series); |
|
104 | chart->setAxisX(axis, series); | |
130 | //![4] |
|
105 | //![4] |
@@ -22,6 +22,8 | |||||
22 | #include "qboxset_p.h" |
|
22 | #include "qboxset_p.h" | |
23 | #include "charthelpers_p.h" |
|
23 | #include "charthelpers_p.h" | |
24 |
|
24 | |||
|
25 | #include <QDebug> //TODO: remove on release | |||
|
26 | ||||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
28 | |||
27 | /*! |
|
29 | /*! | |
@@ -57,10 +59,10 QBoxSet::~QBoxSet() | |||||
57 | */ |
|
59 | */ | |
58 | void QBoxSet::append(const qreal value) |
|
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 | d_ptr->append(value); |
|
63 | d_ptr->append(value); | |
62 |
|
64 | |||
63 |
emit valuesAdded( |
|
65 | emit valuesAdded(d_ptr->m_valuesCount, 1); | |
64 | } |
|
66 | } | |
65 |
|
67 | |||
66 | /*! |
|
68 | /*! | |
@@ -70,9 +72,9 void QBoxSet::append(const qreal value) | |||||
70 | */ |
|
72 | */ | |
71 | void QBoxSet::append(const QList<qreal> &values) |
|
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 | d_ptr->append(values); |
|
76 | d_ptr->append(values); | |
75 |
emit valuesAdded( |
|
77 | emit valuesAdded(d_ptr->m_valuesCount, values.count()); | |
76 | } |
|
78 | } | |
77 |
|
79 | |||
78 | /*! |
|
80 | /*! | |
@@ -81,6 +83,7 void QBoxSet::append(const QList<qreal> &values) | |||||
81 | void QBoxSet::setLowerExtreme(const qreal value) |
|
83 | void QBoxSet::setLowerExtreme(const qreal value) | |
82 | { |
|
84 | { | |
83 | d_ptr->replace(QBoxSetPrivate::PosLowerExtreme, value); |
|
85 | d_ptr->replace(QBoxSetPrivate::PosLowerExtreme, value); | |
|
86 | emit d_ptr->restructuredBox(); | |||
84 | emit valueChanged(QBoxSetPrivate::PosLowerExtreme); |
|
87 | emit valueChanged(QBoxSetPrivate::PosLowerExtreme); | |
85 | } |
|
88 | } | |
86 |
|
89 | |||
@@ -89,7 +92,7 void QBoxSet::setLowerExtreme(const qreal value) | |||||
89 | */ |
|
92 | */ | |
90 | qreal QBoxSet::lowerExtreme() |
|
93 | qreal QBoxSet::lowerExtreme() | |
91 | { |
|
94 | { | |
92 |
return d_ptr->m_values |
|
95 | return d_ptr->m_values[QBoxSetPrivate::PosLowerExtreme]; | |
93 | } |
|
96 | } | |
94 |
|
97 | |||
95 | /*! |
|
98 | /*! | |
@@ -98,6 +101,7 qreal QBoxSet::lowerExtreme() | |||||
98 | void QBoxSet::setLowerQuartile(const qreal value) |
|
101 | void QBoxSet::setLowerQuartile(const qreal value) | |
99 | { |
|
102 | { | |
100 | d_ptr->replace(QBoxSetPrivate::PosLowerQuartile, value); |
|
103 | d_ptr->replace(QBoxSetPrivate::PosLowerQuartile, value); | |
|
104 | emit d_ptr->restructuredBox(); | |||
101 | emit valueChanged(QBoxSetPrivate::PosLowerQuartile); |
|
105 | emit valueChanged(QBoxSetPrivate::PosLowerQuartile); | |
102 | } |
|
106 | } | |
103 |
|
107 | |||
@@ -106,7 +110,7 void QBoxSet::setLowerQuartile(const qreal value) | |||||
106 | */ |
|
110 | */ | |
107 | qreal QBoxSet::lowerQuartile() |
|
111 | qreal QBoxSet::lowerQuartile() | |
108 | { |
|
112 | { | |
109 |
return d_ptr->m_values |
|
113 | return d_ptr->m_values[QBoxSetPrivate::PosLowerQuartile]; | |
110 | } |
|
114 | } | |
111 |
|
115 | |||
112 | /*! |
|
116 | /*! | |
@@ -115,6 +119,7 qreal QBoxSet::lowerQuartile() | |||||
115 | void QBoxSet::setMedian(const qreal value) |
|
119 | void QBoxSet::setMedian(const qreal value) | |
116 | { |
|
120 | { | |
117 | d_ptr->replace(QBoxSetPrivate::PosMedian, value); |
|
121 | d_ptr->replace(QBoxSetPrivate::PosMedian, value); | |
|
122 | emit d_ptr->restructuredBox(); | |||
118 | emit valueChanged(QBoxSetPrivate::PosMedian); |
|
123 | emit valueChanged(QBoxSetPrivate::PosMedian); | |
119 | } |
|
124 | } | |
120 |
|
125 | |||
@@ -123,7 +128,7 void QBoxSet::setMedian(const qreal value) | |||||
123 | */ |
|
128 | */ | |
124 | qreal QBoxSet::median() |
|
129 | qreal QBoxSet::median() | |
125 | { |
|
130 | { | |
126 |
return d_ptr->m_values |
|
131 | return d_ptr->m_values[QBoxSetPrivate::PosMedian]; | |
127 | } |
|
132 | } | |
128 |
|
133 | |||
129 | /*! |
|
134 | /*! | |
@@ -132,6 +137,7 qreal QBoxSet::median() | |||||
132 | void QBoxSet::setUpperQuartile(const qreal value) |
|
137 | void QBoxSet::setUpperQuartile(const qreal value) | |
133 | { |
|
138 | { | |
134 | d_ptr->replace(QBoxSetPrivate::PosUpperQuartile, value); |
|
139 | d_ptr->replace(QBoxSetPrivate::PosUpperQuartile, value); | |
|
140 | emit d_ptr->restructuredBox(); | |||
135 | emit valueChanged(QBoxSetPrivate::PosUpperQuartile); |
|
141 | emit valueChanged(QBoxSetPrivate::PosUpperQuartile); | |
136 | } |
|
142 | } | |
137 |
|
143 | |||
@@ -140,7 +146,7 void QBoxSet::setUpperQuartile(const qreal value) | |||||
140 | */ |
|
146 | */ | |
141 | qreal QBoxSet::upperQuartile() |
|
147 | qreal QBoxSet::upperQuartile() | |
142 | { |
|
148 | { | |
143 |
return d_ptr->m_values |
|
149 | return d_ptr->m_values[QBoxSetPrivate::PosUpperQuartile]; | |
144 | } |
|
150 | } | |
145 |
|
151 | |||
146 | /*! |
|
152 | /*! | |
@@ -148,8 +154,9 qreal QBoxSet::upperQuartile() | |||||
148 | */ |
|
154 | */ | |
149 | void QBoxSet::setUpperExtreme(const qreal value) |
|
155 | void QBoxSet::setUpperExtreme(const qreal value) | |
150 | { |
|
156 | { | |
151 |
d_ptr->replace(QBoxSetPrivate::PosUpper |
|
157 | d_ptr->replace(QBoxSetPrivate::PosUpperExtreme, value); | |
152 | emit valueChanged(QBoxSetPrivate::PosUpperQuartile); |
|
158 | emit d_ptr->restructuredBox(); | |
|
159 | emit valueChanged(QBoxSetPrivate::PosUpperExtreme); | |||
153 | } |
|
160 | } | |
154 |
|
161 | |||
155 | /*! |
|
162 | /*! | |
@@ -157,7 +164,7 void QBoxSet::setUpperExtreme(const qreal value) | |||||
157 | */ |
|
164 | */ | |
158 | qreal QBoxSet::upperExtreme() |
|
165 | qreal QBoxSet::upperExtreme() | |
159 | { |
|
166 | { | |
160 |
return d_ptr->m_values |
|
167 | return d_ptr->m_values[QBoxSetPrivate::PosUpperExtreme]; | |
161 | } |
|
168 | } | |
162 |
|
169 | |||
163 | /*! |
|
170 | /*! | |
@@ -173,7 +180,6 QBoxSet &QBoxSet::operator << (const qreal &value) | |||||
173 | /*! |
|
180 | /*! | |
174 | Inserts new \a value on the \a index position. |
|
181 | Inserts new \a value on the \a index position. | |
175 | The value that is currently at this postion is moved to postion index + 1 |
|
182 | The value that is currently at this postion is moved to postion index + 1 | |
176 | \sa remove() |
|
|||
177 | */ |
|
183 | */ | |
178 | void QBoxSet::insert(const int index, const qreal value) |
|
184 | void QBoxSet::insert(const int index, const qreal value) | |
179 | { |
|
185 | { | |
@@ -182,23 +188,11 void QBoxSet::insert(const int index, const qreal value) | |||||
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 | Sets a new value \a value to set, indexed by \a index |
|
191 | Sets a new value \a value to set, indexed by \a index | |
198 | */ |
|
192 | */ | |
199 | void QBoxSet::replace(const int index, const qreal value) |
|
193 | void QBoxSet::replace(const int index, const qreal value) | |
200 | { |
|
194 | { | |
201 |
if (index >= 0 && index < |
|
195 | if (index >= 0 && index < 5) { | |
202 | d_ptr->replace(index, value); |
|
196 | d_ptr->replace(index, value); | |
203 | emit valueChanged(index); |
|
197 | emit valueChanged(index); | |
204 | } |
|
198 | } | |
@@ -211,9 +205,9 void QBoxSet::replace(const int index, const qreal value) | |||||
211 | */ |
|
205 | */ | |
212 | qreal QBoxSet::at(const int index) const |
|
206 | qreal QBoxSet::at(const int index) const | |
213 | { |
|
207 | { | |
214 |
if (index < 0 || index >= |
|
208 | if (index < 0 || index >= 5) | |
215 | return 0; |
|
209 | return 0; | |
216 |
return d_ptr->m_values |
|
210 | return d_ptr->m_values[index]; | |
217 | } |
|
211 | } | |
218 |
|
212 | |||
219 | /*! |
|
213 | /*! | |
@@ -230,7 +224,7 qreal QBoxSet::operator [](const int index) const | |||||
230 | */ |
|
224 | */ | |
231 | int QBoxSet::count() const |
|
225 | int QBoxSet::count() const | |
232 | { |
|
226 | { | |
233 |
return d_ptr->m_values |
|
227 | return d_ptr->m_valuesCount; | |
234 | } |
|
228 | } | |
235 |
|
229 | |||
236 | /*! |
|
230 | /*! | |
@@ -326,9 +320,12 void QBoxSet::setBorderColor(QColor color) | |||||
326 |
|
320 | |||
327 | QBoxSetPrivate::QBoxSetPrivate(QBoxSet *parent) : QObject(parent), |
|
321 | QBoxSetPrivate::QBoxSetPrivate(QBoxSet *parent) : QObject(parent), | |
328 | q_ptr(parent), |
|
322 | q_ptr(parent), | |
|
323 | m_valuesCount(5), | |||
|
324 | m_appendCount(0), | |||
329 | m_pen(QPen(Qt::NoPen)), |
|
325 | m_pen(QPen(Qt::NoPen)), | |
330 | m_brush(QBrush(Qt::NoBrush)) |
|
326 | m_brush(QBrush(Qt::NoBrush)) | |
331 | { |
|
327 | { | |
|
328 | m_values = new qreal[m_valuesCount]; | |||
332 | } |
|
329 | } | |
333 |
|
330 | |||
334 | QBoxSetPrivate::~QBoxSetPrivate() |
|
331 | QBoxSetPrivate::~QBoxSetPrivate() | |
@@ -337,8 +334,8 QBoxSetPrivate::~QBoxSetPrivate() | |||||
337 |
|
334 | |||
338 | void QBoxSetPrivate::append(qreal value) |
|
335 | void QBoxSetPrivate::append(qreal value) | |
339 | { |
|
336 | { | |
340 | if (isValidValue(value)) { |
|
337 | if (isValidValue(value) && m_appendCount < m_valuesCount) { | |
341 |
m_values |
|
338 | m_values[m_appendCount++] = value; | |
342 | emit restructuredBox(); |
|
339 | emit restructuredBox(); | |
343 | } |
|
340 | } | |
344 | } |
|
341 | } | |
@@ -346,8 +343,8 void QBoxSetPrivate::append(qreal value) | |||||
346 | void QBoxSetPrivate::append(QList<qreal> values) |
|
343 | void QBoxSetPrivate::append(QList<qreal> values) | |
347 | { |
|
344 | { | |
348 | for (int i = 0; i < values.count(); i++) { |
|
345 | for (int i = 0; i < values.count(); i++) { | |
349 | if (isValidValue(values.at(i))) |
|
346 | if (isValidValue(values.at(i)) && m_appendCount < m_valuesCount) | |
350 |
m_values |
|
347 | m_values[m_appendCount++] = values.at(i); | |
351 | } |
|
348 | } | |
352 | emit restructuredBox(); |
|
349 | emit restructuredBox(); | |
353 | } |
|
350 | } | |
@@ -355,40 +352,24 void QBoxSetPrivate::append(QList<qreal> values) | |||||
355 | void QBoxSetPrivate::insert(const int index, const qreal value) |
|
352 | void QBoxSetPrivate::insert(const int index, const qreal value) | |
356 | { |
|
353 | { | |
357 | if (isValidValue(value)) { |
|
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 | emit restructuredBox(); |
|
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 | void QBoxSetPrivate::replace(const int index, const qreal value) |
|
362 | void QBoxSetPrivate::replace(const int index, const qreal value) | |
382 | { |
|
363 | { | |
383 |
m_values |
|
364 | m_values[index] = value; | |
384 | emit updatedLayout(); |
|
365 | emit updatedLayout(); | |
385 | } |
|
366 | } | |
386 |
|
367 | |||
387 | qreal QBoxSetPrivate::value(const int index) |
|
368 | qreal QBoxSetPrivate::value(const int index) | |
388 | { |
|
369 | { | |
389 |
if (index < 0 || index >= m_values |
|
370 | if (index < 0 || index >= m_valuesCount) | |
390 | return 0; |
|
371 | return 0; | |
391 |
return m_values |
|
372 | return m_values[index]; | |
392 | } |
|
373 | } | |
393 |
|
374 | |||
394 | #include "moc_qboxset.cpp" |
|
375 | #include "moc_qboxset.cpp" |
@@ -73,7 +73,10 Q_SIGNALS: | |||||
73 | public: |
|
73 | public: | |
74 | QBoxSet * const q_ptr; |
|
74 | QBoxSet * const q_ptr; | |
75 | //QString m_label; |
|
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 | QPen m_pen; |
|
80 | QPen m_pen; | |
78 | QBrush m_brush; |
|
81 | QBrush m_brush; | |
79 | QBrush m_labelBrush; |
|
82 | QBrush m_labelBrush; |
General Comments 0
You need to be logged in to leave comments.
Login now