##// END OF EJS Templates
Documentation...
Mika Salmela -
r2517:26c3b5c0ed1d
parent child
Show More
@@ -0,0 +1,38
1 /*!
2 \example examples/boxplotchart
3 \title Box and Whiskers Example
4 \subtitle
5
6 The example shows how to create a box-and-whiskers chart.
7
8 \image examples_barchart.png
9
10 Introduction here
11
12 \snippet ../examples/barchart/main.cpp 1
13
14 YkkοΏ½skohta
15
16 \snippet ../examples/barchart/main.cpp 2
17
18 Kakkoskohta
19
20 \snippet ../examples/barchart/main.cpp 3
21
22 Kolmoskohta
23
24 \snippet ../examples/barchart/main.cpp 4
25
26 Neloskohta
27
28 \snippet ../examples/barchart/main.cpp 5
29
30 Tarkista numerointi. Finally we add the chart onto a view. We also turn on the antialiasing for the chartView.
31
32 \snippet ../examples/barchart/main.cpp 6
33
34 Tarkista numerointi. Chart is ready to be shown. We set the chart to be central widget of the window.
35 We also set the size for the chart window and show it.
36
37 \snippet ../examples/barchart/main.cpp 7
38 */
@@ -1,248 +1,248
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qvbarmodelmapper.h"
21 #include "qvbarmodelmapper.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 /*!
25 /*!
26 \class QVBarModelMapper
26 \class QVBarModelMapper
27 \brief Vertical model mapper for bar series
27 \brief Vertical model mapper for bar series
28 \mainclass
28 \mainclass
29
29
30 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
30 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
31 Vertical model mapper is used to create a connection between QAbstractBarSeries and QAbstractItemModel derived model object.
31 Vertical model mapper is used to create a connection between QAbstractBarSeries and QAbstractItemModel derived model object.
32 Model mapper maintains equal size of all the BarSets.
32 Model mapper maintains equal size of all the BarSets.
33 Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series.
33 Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series.
34 Note: used model has to support adding/removing rows/columns and modifying the data of the cells.
34 Note: used model has to support adding/removing rows/columns and modifying the data of the cells.
35 */
35 */
36 /*!
36 /*!
37 \qmlclass VBarModelMapper
37 \qmlclass VBarModelMapper
38 \mainclass
38 \mainclass
39
39
40 VBarModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source
40 VBarModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source
41 for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data.
41 for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data.
42 VBarModelMapper keeps the series and the model in sync.
42 VBarModelMapper keeps the series and the model in sync.
43
43
44 The following QML example would create a bar series with three bar sets (assuming the
44 The following QML example would create a bar series with three bar sets (assuming the
45 model has at least four columns). Each bar set would contain data starting from row 1. The name of a set would be
45 model has at least four columns). Each bar set would contain data starting from row 1. The name of a set would be
46 defined by the horizontal header (of the column).
46 defined by the horizontal header (of the column).
47 \code
47 \code
48 BarSeries {
48 BarSeries {
49 VBarModelMapper {
49 VBarModelMapper {
50 model: myCustomModel // QAbstractItemModel derived implementation
50 model: myCustomModel // QAbstractItemModel derived implementation
51 firstBarSetColumn: 1
51 firstBarSetColumn: 1
52 lastBarSetColumn: 3
52 lastBarSetColumn: 3
53 firstRow: 1
53 firstRow: 1
54 }
54 }
55 }
55 }
56 \endcode
56 \endcode
57 */
57 */
58
58
59 /*!
59 /*!
60 \property QVBarModelMapper::series
60 \property QVBarModelMapper::series
61 \brief Defines the QPieSeries object that is used by the mapper.
61 \brief Defines the QBarSeries object that is used by the mapper.
62
62
63 All the data in the series is discarded when it is set to the mapper.
63 All the data in the series is discarded when it is set to the mapper.
64 When new series is specified the old series is disconnected (it preserves its data)
64 When new series is specified the old series is disconnected (it preserves its data)
65 */
65 */
66 /*!
66 /*!
67 \qmlproperty AbstractBarSeries VBarModelMapper::series
67 \qmlproperty AbstractBarSeries VBarModelMapper::series
68 Defines the AbstractBarSeries based object that is used by the mapper. All the data in the series is discarded when it is
68 Defines the AbstractBarSeries based object that is used by the mapper. All the data in the series is discarded when it is
69 set to the mapper. When new series is specified the old series is disconnected (it preserves its data).
69 set to the mapper. When new series is specified the old series is disconnected (it preserves its data).
70 */
70 */
71
71
72 /*!
72 /*!
73 \property QVBarModelMapper::model
73 \property QVBarModelMapper::model
74 \brief Defines the model that is used by the mapper.
74 \brief Defines the model that is used by the mapper.
75 */
75 */
76 /*!
76 /*!
77 \qmlproperty SomeModel VBarModelMapper::model
77 \qmlproperty SomeModel VBarModelMapper::model
78 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
78 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
79 QML as shown in \l {QML Custom Model} demo application. Note: the model has to support adding/removing rows/columns
79 QML as shown in \l {QML Custom Model} demo application. Note: the model has to support adding/removing rows/columns
80 and modifying the data of the cells.
80 and modifying the data of the cells.
81 */
81 */
82
82
83 /*!
83 /*!
84 \property QVBarModelMapper::firstBarSetColumn
84 \property QVBarModelMapper::firstBarSetColumn
85 \brief Defines which column of the model is used as the data source for the first bar set
85 \brief Defines which column of the model is used as the data source for the first bar set
86 Default value is: -1 (invalid mapping)
86 Default value is: -1 (invalid mapping)
87 */
87 */
88 /*!
88 /*!
89 \qmlproperty int VBarModelMapper::firstBarSetColumn
89 \qmlproperty int VBarModelMapper::firstBarSetColumn
90 Defines which column of the model is used as the data source for the first bar set. Default value
90 Defines which column of the model is used as the data source for the first bar set. Default value
91 is: -1 (invalid mapping).
91 is: -1 (invalid mapping).
92 */
92 */
93
93
94 /*!
94 /*!
95 \property QVBarModelMapper::lastBarSetColumn
95 \property QVBarModelMapper::lastBarSetColumn
96 \brief Defines which column of the model is used as the data source for the last bar set
96 \brief Defines which column of the model is used as the data source for the last bar set
97 Default value is: -1 (invalid mapping)
97 Default value is: -1 (invalid mapping)
98 */
98 */
99 /*!
99 /*!
100 \qmlproperty int VBarModelMapper::lastBarSetColumn
100 \qmlproperty int VBarModelMapper::lastBarSetColumn
101 Defines which column of the model is used as the data source for the last bar set. Default
101 Defines which column of the model is used as the data source for the last bar set. Default
102 value is: -1 (invalid mapping).
102 value is: -1 (invalid mapping).
103 */
103 */
104
104
105 /*!
105 /*!
106 \property QVBarModelMapper::firstRow
106 \property QVBarModelMapper::firstRow
107 \brief Defines which row of the model contains the first values of the QBarSets in the series.
107 \brief Defines which row of the model contains the first values of the QBarSets in the series.
108 Minimal and default value is: 0
108 Minimal and default value is: 0
109 */
109 */
110 /*!
110 /*!
111 \qmlproperty int VBarModelMapper::firstRow
111 \qmlproperty int VBarModelMapper::firstRow
112 Defines which row of the model contains the first values of the QBarSets in the series.
112 Defines which row of the model contains the first values of the QBarSets in the series.
113 The default value is 0.
113 The default value is 0.
114 */
114 */
115
115
116 /*!
116 /*!
117 \property QVBarModelMapper::rowCount
117 \property QVBarModelMapper::rowCount
118 \brief Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries
118 \brief Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries
119 Minimal and default value is: -1 (count limited by the number of rows in the model)
119 Minimal and default value is: -1 (count limited by the number of rows in the model)
120 */
120 */
121 /*!
121 /*!
122 \qmlproperty int VBarModelMapper::rowCount
122 \qmlproperty int VBarModelMapper::rowCount
123 Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries. The default value is
123 Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries. The default value is
124 -1 (count limited by the number of rows in the model)
124 -1 (count limited by the number of rows in the model)
125 */
125 */
126
126
127 /*!
127 /*!
128 \fn void QVBarModelMapper::seriesReplaced()
128 \fn void QVBarModelMapper::seriesReplaced()
129
129
130 Emitted when the series to which mapper is connected to has changed.
130 Emitted when the series to which mapper is connected to has changed.
131 */
131 */
132
132
133 /*!
133 /*!
134 \fn void QVBarModelMapper::modelReplaced()
134 \fn void QVBarModelMapper::modelReplaced()
135
135
136 Emitted when the model to which mapper is connected to has changed.
136 Emitted when the model to which mapper is connected to has changed.
137 */
137 */
138
138
139 /*!
139 /*!
140 \fn void QVBarModelMapper::firstBarSetColumnChanged()
140 \fn void QVBarModelMapper::firstBarSetColumnChanged()
141 Emitted when the firstBarSetColumn has changed.
141 Emitted when the firstBarSetColumn has changed.
142 */
142 */
143
143
144 /*!
144 /*!
145 \fn void QVBarModelMapper::lastBarSetColumnChanged()
145 \fn void QVBarModelMapper::lastBarSetColumnChanged()
146 Emitted when the lastBarSetColumn has changed.
146 Emitted when the lastBarSetColumn has changed.
147 */
147 */
148
148
149 /*!
149 /*!
150 \fn void QVBarModelMapper::firstRowChanged()
150 \fn void QVBarModelMapper::firstRowChanged()
151 Emitted when the firstRow has changed.
151 Emitted when the firstRow has changed.
152 */
152 */
153
153
154 /*!
154 /*!
155 \fn void QVBarModelMapper::rowCountChanged()
155 \fn void QVBarModelMapper::rowCountChanged()
156 Emitted when the rowCount has changed.
156 Emitted when the rowCount has changed.
157 */
157 */
158
158
159 /*!
159 /*!
160 Constructs a mapper object which is a child of \a parent.
160 Constructs a mapper object which is a child of \a parent.
161 */
161 */
162 QVBarModelMapper::QVBarModelMapper(QObject *parent) :
162 QVBarModelMapper::QVBarModelMapper(QObject *parent) :
163 QBarModelMapper(parent)
163 QBarModelMapper(parent)
164 {
164 {
165 QBarModelMapper::setOrientation(Qt::Vertical);
165 QBarModelMapper::setOrientation(Qt::Vertical);
166 }
166 }
167
167
168 QAbstractItemModel *QVBarModelMapper::model() const
168 QAbstractItemModel *QVBarModelMapper::model() const
169 {
169 {
170 return QBarModelMapper::model();
170 return QBarModelMapper::model();
171 }
171 }
172
172
173 void QVBarModelMapper::setModel(QAbstractItemModel *model)
173 void QVBarModelMapper::setModel(QAbstractItemModel *model)
174 {
174 {
175 if (model != QBarModelMapper::model()) {
175 if (model != QBarModelMapper::model()) {
176 QBarModelMapper::setModel(model);
176 QBarModelMapper::setModel(model);
177 emit modelReplaced();
177 emit modelReplaced();
178 }
178 }
179 }
179 }
180
180
181 QAbstractBarSeries *QVBarModelMapper::series() const
181 QAbstractBarSeries *QVBarModelMapper::series() const
182 {
182 {
183 return QBarModelMapper::series();
183 return QBarModelMapper::series();
184 }
184 }
185
185
186 void QVBarModelMapper::setSeries(QAbstractBarSeries *series)
186 void QVBarModelMapper::setSeries(QAbstractBarSeries *series)
187 {
187 {
188 if (series != QBarModelMapper::series()) {
188 if (series != QBarModelMapper::series()) {
189 QBarModelMapper::setSeries(series);
189 QBarModelMapper::setSeries(series);
190 emit seriesReplaced();
190 emit seriesReplaced();
191 }
191 }
192 }
192 }
193
193
194 int QVBarModelMapper::firstBarSetColumn() const
194 int QVBarModelMapper::firstBarSetColumn() const
195 {
195 {
196 return QBarModelMapper::firstBarSetSection();
196 return QBarModelMapper::firstBarSetSection();
197 }
197 }
198
198
199 void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn)
199 void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn)
200 {
200 {
201 if (firstBarSetColumn != firstBarSetSection()) {
201 if (firstBarSetColumn != firstBarSetSection()) {
202 QBarModelMapper::setFirstBarSetSection(firstBarSetColumn);
202 QBarModelMapper::setFirstBarSetSection(firstBarSetColumn);
203 emit firstBarSetColumnChanged();
203 emit firstBarSetColumnChanged();
204 }
204 }
205 }
205 }
206
206
207 int QVBarModelMapper::lastBarSetColumn() const
207 int QVBarModelMapper::lastBarSetColumn() const
208 {
208 {
209 return QBarModelMapper::lastBarSetSection();
209 return QBarModelMapper::lastBarSetSection();
210 }
210 }
211
211
212 void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn)
212 void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn)
213 {
213 {
214 if (lastBarSetColumn != lastBarSetSection()) {
214 if (lastBarSetColumn != lastBarSetSection()) {
215 QBarModelMapper::setLastBarSetSection(lastBarSetColumn);
215 QBarModelMapper::setLastBarSetSection(lastBarSetColumn);
216 emit lastBarSetColumnChanged();
216 emit lastBarSetColumnChanged();
217 }
217 }
218 }
218 }
219
219
220 int QVBarModelMapper::firstRow() const
220 int QVBarModelMapper::firstRow() const
221 {
221 {
222 return QBarModelMapper::first();
222 return QBarModelMapper::first();
223 }
223 }
224
224
225 void QVBarModelMapper::setFirstRow(int firstRow)
225 void QVBarModelMapper::setFirstRow(int firstRow)
226 {
226 {
227 if (firstRow != first()) {
227 if (firstRow != first()) {
228 QBarModelMapper::setFirst(firstRow);
228 QBarModelMapper::setFirst(firstRow);
229 emit firstRowChanged();
229 emit firstRowChanged();
230 }
230 }
231 }
231 }
232
232
233 int QVBarModelMapper::rowCount() const
233 int QVBarModelMapper::rowCount() const
234 {
234 {
235 return QBarModelMapper::count();
235 return QBarModelMapper::count();
236 }
236 }
237
237
238 void QVBarModelMapper::setRowCount(int rowCount)
238 void QVBarModelMapper::setRowCount(int rowCount)
239 {
239 {
240 if (rowCount != count()) {
240 if (rowCount != count()) {
241 QBarModelMapper::setCount(rowCount);
241 QBarModelMapper::setCount(rowCount);
242 emit rowCountChanged();
242 emit rowCountChanged();
243 }
243 }
244 }
244 }
245
245
246 #include "moc_qvbarmodelmapper.cpp"
246 #include "moc_qvbarmodelmapper.cpp"
247
247
248 QTCOMMERCIALCHART_END_NAMESPACE
248 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,223 +1,227
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "boxplotchartitem_p.h"
21 #include "boxplotchartitem_p.h"
22 #include "qboxplotseries_p.h"
22 #include "qboxplotseries_p.h"
23 #include "bar_p.h"
23 #include "bar_p.h"
24 #include "qboxset_p.h"
24 #include "qboxset_p.h"
25 #include "qabstractbarseries_p.h"
25 #include "qabstractbarseries_p.h"
26 #include "qboxset.h"
26 #include "qboxset.h"
27 #include "boxwhiskers_p.h"
27 #include "boxwhiskers_p.h"
28 #include <QPainter>
28 #include <QPainter>
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 BoxPlotChartItem::BoxPlotChartItem(QBoxPlotSeries *series, QGraphicsItem* item) :
32 BoxPlotChartItem::BoxPlotChartItem(QBoxPlotSeries *series, QGraphicsItem* item) :
33 ChartItem(series->d_func(), item),
33 ChartItem(series->d_func(), item),
34 m_series(series),
34 m_series(series),
35 m_animation(0),
35 m_animation(0),
36 m_animate(0)
36 m_animate(0)
37 {
37 {
38 connect(series, SIGNAL(boxsetsRemoved(QList<QBoxSet*>)), this, SLOT(handleBoxsetRemove(QList<QBoxSet*>)));
38 connect(series, SIGNAL(boxsetsRemoved(QList<QBoxSet*>)), this, SLOT(handleBoxsetRemove(QList<QBoxSet*>)));
39 connect(series->d_func(), SIGNAL(restructuredBoxes()), this, SLOT(handleDataStructureChanged()));
39 connect(series->d_func(), SIGNAL(restructuredBoxes()), this, SLOT(handleDataStructureChanged()));
40 connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged()));
40 connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged()));
41 connect(series->d_func(), SIGNAL(updatedBoxes()), this, SLOT(handleUpdatedBars()));
41 connect(series->d_func(), SIGNAL(updatedBoxes()), this, SLOT(handleUpdatedBars()));
42 connect(series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdatedBars()));
42 connect(series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdatedBars()));
43 // QBoxPlotSeriesPrivate calls handleDataStructureChanged(), don't do it here
43 // QBoxPlotSeriesPrivate calls handleDataStructureChanged(), don't do it here
44 setZValue(ChartPresenter::BoxPlotSeriesZValue);
44 setZValue(ChartPresenter::BoxPlotSeriesZValue);
45 }
45 }
46
46
47 BoxPlotChartItem::~BoxPlotChartItem()
47 BoxPlotChartItem::~BoxPlotChartItem()
48 {
48 {
49 qDebug() << "BoxPlotChartItem::~BoxPlotChartItem() " << m_seriesIndex;
49 qDebug() << "BoxPlotChartItem::~BoxPlotChartItem() " << m_seriesIndex;
50 }
50 }
51
51
52 void BoxPlotChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
52 void BoxPlotChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
53 {
53 {
54 Q_UNUSED(painter);
54 Q_UNUSED(painter);
55 Q_UNUSED(option);
55 Q_UNUSED(option);
56 Q_UNUSED(widget);
56 Q_UNUSED(widget);
57
57
58 //painter->setClipRect(QRectF(QPointF(0,0),domain()->size()));
58 //painter->setClipRect(QRectF(QPointF(0,0),domain()->size()));
59
59
60 //qDebug() << "ALERT EMPTY: BoxPlotChartItem::paint";
60 //qDebug() << "ALERT EMPTY: BoxPlotChartItem::paint";
61 }
61 }
62
62
63 void BoxPlotChartItem::setAnimation(BoxPlotAnimation *animation)
63 void BoxPlotChartItem::setAnimation(BoxPlotAnimation *animation)
64 {
64 {
65 //qDebug() << "BoxPlotChartItem::setAnimation :" << animation;
65 //qDebug() << "BoxPlotChartItem::setAnimation :" << animation;
66
66
67 m_animation = animation;
67 m_animation = animation;
68 if (m_animation) {
68 if (m_animation) {
69 foreach (BoxWhiskers *item, m_boxTable.values()) {
69 foreach (BoxWhiskers *item, m_boxTable.values()) {
70 m_animation->addBox(item);
70 m_animation->addBox(item);
71 }
71 }
72 handleDomainUpdated();
72 handleDomainUpdated();
73 }
73 }
74 }
74 }
75
75
76 void BoxPlotChartItem::handleDataStructureChanged()
76 void BoxPlotChartItem::handleDataStructureChanged()
77 {
77 {
78 qDebug() << "BoxPlotChartItem::handleDataStructureChanged()";
78 qDebug() << "BoxPlotChartItem::handleDataStructureChanged()";
79
79
80 int setCount = m_series->count();
80 int setCount = m_series->count();
81
81
82 for (int s = 0; s < setCount; s++) {
82 for (int s = 0; s < setCount; s++) {
83 QBoxSet *set = m_series->d_func()->boxsetAt(s);
83 QBoxSet *set = m_series->d_func()->boxsetAt(s);
84
84
85 BoxWhiskers *boxWhiskersItem = m_boxTable.value(set);
85 BoxWhiskers *box = m_boxTable.value(set);
86 if (boxWhiskersItem == 0) {
86 if (!box) {
87 // Item is not yet created, make a box and add it to hash table
87 // Item is not yet created, make a box and add it to hash table
88 boxWhiskersItem = new BoxWhiskers(domain(), this);
88 box = new BoxWhiskers(set, domain(), this);
89 m_boxTable.insert(set, boxWhiskersItem);
89 m_boxTable.insert(set, box);
90 connect(box, SIGNAL(clicked(QBoxSet *)), m_series, SIGNAL(clicked(QBoxSet*)));
91 connect(box, SIGNAL(hovered(bool,QBoxSet*)), m_series, SIGNAL(hovered(bool,QBoxSet*)));
92 connect(box, SIGNAL(clicked(QBoxSet*)), set, SIGNAL(clicked()));
93 connect(box, SIGNAL(hovered(bool,QBoxSet*)), set, SIGNAL(hovered(bool)));
90
94
91 // Set the decorative issues for the newly created box
95 // Set the decorative issues for the newly created box
92 boxWhiskersItem->setBrush(m_series->brush());
96 box->setBrush(m_series->brush());
93 boxWhiskersItem->setPen(m_series->pen());
97 box->setPen(m_series->pen());
94 }
98 }
95 updateBoxGeometry(boxWhiskersItem, s);
99 updateBoxGeometry(box, s);
96
100
97 boxWhiskersItem->updateGeometry();
101 box->updateGeometry();
98
102
99 if (m_animation)
103 if (m_animation)
100 m_animation->addBox(boxWhiskersItem);
104 m_animation->addBox(box);
101 }
105 }
102
106
103 //
107 //
104 handleDomainUpdated();
108 handleDomainUpdated();
105 }
109 }
106
110
107 void BoxPlotChartItem::handleUpdatedBars()
111 void BoxPlotChartItem::handleUpdatedBars()
108 {
112 {
109 qDebug() << "BoxPlotChartItem::handleUpdatedBars()";
113 qDebug() << "BoxPlotChartItem::handleUpdatedBars()";
110
114
111 foreach (BoxWhiskers *item, m_boxTable.values()) {
115 foreach (BoxWhiskers *item, m_boxTable.values()) {
112 item->setBrush(m_series->brush());
116 item->setBrush(m_series->brush());
113 item->setPen(m_series->pen());
117 item->setPen(m_series->pen());
114 }
118 }
115 // Override with QBoxSet specific settings
119 // Override with QBoxSet specific settings
116 foreach (QBoxSet *set, m_boxTable.keys()) {
120 foreach (QBoxSet *set, m_boxTable.keys()) {
117 if (set->brush().style() != Qt::NoBrush)
121 if (set->brush().style() != Qt::NoBrush)
118 m_boxTable.value(set)->setBrush(set->brush());
122 m_boxTable.value(set)->setBrush(set->brush());
119 if (set->pen().style() != Qt::NoPen)
123 if (set->pen().style() != Qt::NoPen)
120 m_boxTable.value(set)->setPen(set->pen());
124 m_boxTable.value(set)->setPen(set->pen());
121 }
125 }
122 }
126 }
123
127
124 void BoxPlotChartItem::handleBoxsetRemove(QList<QBoxSet*> barSets)
128 void BoxPlotChartItem::handleBoxsetRemove(QList<QBoxSet*> barSets)
125 {
129 {
126 //qDebug() << "BoxPlotChartItem::handleBarsetRemove";
130 //qDebug() << "BoxPlotChartItem::handleBarsetRemove";
127
131
128 foreach (QBoxSet *set, barSets) {
132 foreach (QBoxSet *set, barSets) {
129 BoxWhiskers *boxItem = m_boxTable.value(set);
133 BoxWhiskers *boxItem = m_boxTable.value(set);
130 m_boxTable.remove(set);
134 m_boxTable.remove(set);
131 delete boxItem;
135 delete boxItem;
132 }
136 }
133
137
134 // We trust that series emits the restructuredBars, which handles restructuring
138 // We trust that series emits the restructuredBars, which handles restructuring
135 }
139 }
136
140
137 void BoxPlotChartItem::handleDomainUpdated()
141 void BoxPlotChartItem::handleDomainUpdated()
138 {
142 {
139 //qDebug() << "BoxPlotChartItem::handleDomainUpdated() domain()->size() = " << domain()->size();
143 //qDebug() << "BoxPlotChartItem::handleDomainUpdated() domain()->size() = " << domain()->size();
140
144
141 if ((domain()->size().width() <= 0) || (domain()->size().height() <= 0))
145 if ((domain()->size().width() <= 0) || (domain()->size().height() <= 0))
142 return;
146 return;
143
147
144 // Set my bounding rect to same as domain size
148 // Set my bounding rect to same as domain size
145 m_boundingRect.setRect(0.0, 0.0, domain()->size().width(), domain()->size().height());
149 m_boundingRect.setRect(0.0, 0.0, domain()->size().width(), domain()->size().height());
146
150
147 foreach (BoxWhiskers *item, m_boxTable.values()) {
151 foreach (BoxWhiskers *item, m_boxTable.values()) {
148 // Update the domain size for each BoxWhisker item
152 // Update the domain size for each BoxWhisker item
149 item->setDomainSize(domain()->size());
153 item->setDomainSize(domain()->size());
150
154
151 // If the animation is set, start the animation for each BoxWhisker item
155 // If the animation is set, start the animation for each BoxWhisker item
152 if (m_animation) {
156 if (m_animation) {
153 presenter()->startAnimation(m_animation->boxAnimation(item));
157 presenter()->startAnimation(m_animation->boxAnimation(item));
154 }
158 }
155 }
159 }
156 }
160 }
157
161
158 void BoxPlotChartItem::handleLayoutChanged()
162 void BoxPlotChartItem::handleLayoutChanged()
159 {
163 {
160 qDebug() << "BoxPlotChartItem::handleLayoutChanged";
164 qDebug() << "BoxPlotChartItem::handleLayoutChanged";
161
165
162 foreach (BoxWhiskers *item, m_boxTable.values()) {
166 foreach (BoxWhiskers *item, m_boxTable.values()) {
163 if (m_animation)
167 if (m_animation)
164 m_animation->setAnimationStart(item);
168 m_animation->setAnimationStart(item);
165
169
166 bool dirty = updateBoxGeometry(item, item->m_data.m_index);
170 bool dirty = updateBoxGeometry(item, item->m_data.m_index);
167 if (dirty && m_animation)
171 if (dirty && m_animation)
168 presenter()->startAnimation(m_animation->boxChangeAnimation(item));
172 presenter()->startAnimation(m_animation->boxChangeAnimation(item));
169 else
173 else
170 item->updateGeometry();
174 item->updateGeometry();
171 }
175 }
172 }
176 }
173
177
174 QRectF BoxPlotChartItem::boundingRect() const
178 QRectF BoxPlotChartItem::boundingRect() const
175 {
179 {
176 return m_boundingRect;
180 return m_boundingRect;
177 }
181 }
178
182
179 void BoxPlotChartItem::initializeLayout()
183 void BoxPlotChartItem::initializeLayout()
180 {
184 {
181 qDebug() << "ALERT EMPTY: BoxPlotChartItem::initializeLayout";
185 qDebug() << "ALERT EMPTY: BoxPlotChartItem::initializeLayout";
182 }
186 }
183
187
184 QVector<QRectF> BoxPlotChartItem::calculateLayout()
188 QVector<QRectF> BoxPlotChartItem::calculateLayout()
185 {
189 {
186 qDebug() << "ALERT EMPTY: BoxPlotChartItem::calculateLayout()";
190 qDebug() << "ALERT EMPTY: BoxPlotChartItem::calculateLayout()";
187
191
188 return QVector<QRectF>();
192 return QVector<QRectF>();
189 }
193 }
190
194
191 bool BoxPlotChartItem::updateBoxGeometry(BoxWhiskers *box, int index)
195 bool BoxPlotChartItem::updateBoxGeometry(BoxWhiskers *box, int index)
192 {
196 {
193 bool changed = false;
197 bool changed = false;
194
198
195 QBoxSet *set = m_series->d_func()->boxsetAt(index);
199 QBoxSet *set = m_series->d_func()->boxsetAt(index);
196 BoxWhiskersData &data = box->m_data;
200 BoxWhiskersData &data = box->m_data;
197
201
198 if ((data.m_lowerExtreme != set->at(0)) || (data.m_lowerQuartile != set->at(1)) ||
202 if ((data.m_lowerExtreme != set->at(0)) || (data.m_lowerQuartile != set->at(1)) ||
199 (data.m_median != set->at(2)) || (data.m_upperQuartile != set->at(3)) || (data.m_upperExtreme != set->at(4)))
203 (data.m_median != set->at(2)) || (data.m_upperQuartile != set->at(3)) || (data.m_upperExtreme != set->at(4)))
200 changed = true;
204 changed = true;
201
205
202 data.m_lowerExtreme = set->at(0);
206 data.m_lowerExtreme = set->at(0);
203 data.m_lowerQuartile = set->at(1);
207 data.m_lowerQuartile = set->at(1);
204 data.m_median = set->at(2);
208 data.m_median = set->at(2);
205 data.m_upperQuartile = set->at(3);
209 data.m_upperQuartile = set->at(3);
206 data.m_upperExtreme = set->at(4);
210 data.m_upperExtreme = set->at(4);
207 data.m_index = index;
211 data.m_index = index;
208 data.m_boxItems = m_series->count();
212 data.m_boxItems = m_series->count();
209
213
210 data.m_maxX = domain()->maxX();
214 data.m_maxX = domain()->maxX();
211 data.m_minX = domain()->minX();
215 data.m_minX = domain()->minX();
212 data.m_maxY = domain()->maxY();
216 data.m_maxY = domain()->maxY();
213 data.m_minY = domain()->minY();
217 data.m_minY = domain()->minY();
214
218
215 data.m_seriesIndex = m_seriesIndex;
219 data.m_seriesIndex = m_seriesIndex;
216 data.m_seriesCount = m_seriesCount;
220 data.m_seriesCount = m_seriesCount;
217
221
218 return changed;
222 return changed;
219 }
223 }
220
224
221 #include "moc_boxplotchartitem_p.cpp"
225 #include "moc_boxplotchartitem_p.cpp"
222
226
223 QTCOMMERCIALCHART_END_NAMESPACE
227 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,191 +1,190
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "boxwhiskers_p.h"
21 #include "boxwhiskers_p.h"
22 #include <QPainter>
22 #include <QPainter>
23 #include <QDebug>
24 #include <QWidget>
23 #include <QWidget>
25
24
25 #include <QDebug>
26
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
28
28 BoxWhiskers::BoxWhiskers(AbstractDomain *domain, QGraphicsObject *parent) :
29 BoxWhiskers::BoxWhiskers(QBoxSet *set, AbstractDomain *domain, QGraphicsObject *parent) :
29 QGraphicsObject(parent),
30 QGraphicsObject(parent),
31 m_boxSet(set),
30 m_domain(domain)
32 m_domain(domain)
31 {
33 {
32 //qDebug() << "BoxWhiskers::BoxWhiskers()";
34 setAcceptHoverEvents(true);
35 setAcceptedMouseButtons(Qt::MouseButtonMask);
33 }
36 }
34
37
35 BoxWhiskers::~BoxWhiskers()
38 BoxWhiskers::~BoxWhiskers()
36 {
39 {
37 //qDebug() << "BoxWhiskers::~BoxWhiskers()";
38 }
40 }
39
41
40 void BoxWhiskers::mousePressEvent(QGraphicsSceneMouseEvent *event)
42 void BoxWhiskers::mousePressEvent(QGraphicsSceneMouseEvent *event)
41 {
43 {
42 Q_UNUSED(event)
44 Q_UNUSED(event)
43
45 emit clicked(m_boxSet);
44 qDebug() << "BoxWhiskers::mousePressEvent";
45 }
46 }
46
47
47 void BoxWhiskers::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
48 void BoxWhiskers::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
48 {
49 {
49 Q_UNUSED(event)
50 Q_UNUSED(event)
50
51 emit hovered(true, m_boxSet);
51 qDebug() << "BoxWhiskers::hoverEnterEvent";
52 }
52 }
53
53
54 void BoxWhiskers::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
54 void BoxWhiskers::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
55 {
55 {
56 Q_UNUSED(event)
56 Q_UNUSED(event)
57
57 emit hovered(false, m_boxSet);
58 qDebug() << "BoxWhiskers::hoverLeaveEvent";
59 }
58 }
60
59
61 void BoxWhiskers::setBrush(const QBrush &brush)
60 void BoxWhiskers::setBrush(const QBrush &brush)
62 {
61 {
63 m_brush = brush;
62 m_brush = brush;
64 update();
63 update();
65 }
64 }
66
65
67 void BoxWhiskers::setPen(const QPen &pen)
66 void BoxWhiskers::setPen(const QPen &pen)
68 {
67 {
69 m_pen = pen;
68 m_pen = pen;
70 update();
69 update();
71 }
70 }
72
71
73 void BoxWhiskers::setLayout(const BoxWhiskersData &data)
72 void BoxWhiskers::setLayout(const BoxWhiskersData &data)
74 {
73 {
75 m_data = data;
74 m_data = data;
76
75
77 updateGeometry();
76 updateGeometry();
78 update();
77 update();
79 }
78 }
80
79
81
80
82 QSizeF BoxWhiskers::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
81 QSizeF BoxWhiskers::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
83 {
82 {
84 //Q_UNUSED(which)
83 //Q_UNUSED(which)
85 Q_UNUSED(constraint)
84 Q_UNUSED(constraint)
86
85
87 qDebug() << "BoxWhiskers::sizeHint, which = " << which;
86 qDebug() << "BoxWhiskers::sizeHint, which = " << which;
88
87
89 return QSizeF();
88 return QSizeF();
90 }
89 }
91
90
92 void BoxWhiskers::setGeometry(const QRectF &rect) // TODO: Unused?
91 void BoxWhiskers::setGeometry(const QRectF &rect) // TODO: Unused?
93 {
92 {
94 Q_UNUSED(rect)
93 Q_UNUSED(rect)
95
94
96 qDebug() << "BoxWhiskers::setGeometry";
95 qDebug() << "BoxWhiskers::setGeometry";
97 }
96 }
98
97
99 void BoxWhiskers::setDomainSize(const QSizeF &size)
98 void BoxWhiskers::setDomainSize(const QSizeF &size)
100 {
99 {
101 m_domainSize = size;
100 m_domainSize = size;
102
101
103 updateBoundingRect();
102 updateBoundingRect();
104 }
103 }
105
104
106 QRectF BoxWhiskers::boundingRect() const
105 QRectF BoxWhiskers::boundingRect() const
107 {
106 {
108 return m_boundingRect;
107 return m_boundingRect;
109 }
108 }
110
109
111 void BoxWhiskers::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
110 void BoxWhiskers::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
112 {
111 {
113 Q_UNUSED(option)
112 Q_UNUSED(option)
114 Q_UNUSED(widget)
113 Q_UNUSED(widget)
115 //Q_UNUSED(painter)
114 //Q_UNUSED(painter)
116
115
117 //painter->save();
116 //painter->save();
118 //painter->setClipRect(parentItem()->boundingRect());
117 //painter->setClipRect(parentItem()->boundingRect());
119 painter->setPen(m_pen);
118 painter->setPen(m_pen);
120 painter->setBrush(m_brush);
119 painter->setBrush(m_brush);
121 qreal spanY = m_data.m_maxY - m_data.m_minY;
120 qreal spanY = m_data.m_maxY - m_data.m_minY;
122 //painter->setClipRect(parentItem()->boundingRect());
121 //painter->setClipRect(parentItem()->boundingRect());
123 painter->scale(m_domainSize.width() / m_data.m_boxItems, m_domainSize.height() / spanY);
122 painter->scale(m_domainSize.width() / m_data.m_boxItems, m_domainSize.height() / spanY);
124 painter->drawPath(m_boxPath);
123 painter->drawPath(m_boxPath);
125 //painter->restore();
124 //painter->restore();
126 }
125 }
127
126
128 void BoxWhiskers::updateGeometry()
127 void BoxWhiskers::updateGeometry()
129 {
128 {
130 prepareGeometryChange();
129 prepareGeometryChange();
131
130
132 QPainterPath path;
131 QPainterPath path;
133
132
134 qreal columnWidth = 1.0 / m_data.m_seriesCount;
133 qreal columnWidth = 1.0 / m_data.m_seriesCount;
135 qreal left = 0.25 * columnWidth + columnWidth * m_data.m_seriesIndex;
134 qreal left = 0.25 * columnWidth + columnWidth * m_data.m_seriesIndex;
136 qreal right = 0.75 * columnWidth + columnWidth * m_data.m_seriesIndex;
135 qreal right = 0.75 * columnWidth + columnWidth * m_data.m_seriesIndex;
137 qreal middle = 0.5 * columnWidth + columnWidth * m_data.m_seriesIndex;
136 qreal middle = 0.5 * columnWidth + columnWidth * m_data.m_seriesIndex;
138
137
139 //whisker = 0.35 0.75
138 //whisker = 0.35 0.75
140
139
141 // Upper whisker
140 // Upper whisker
142 path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_upperExtreme);
141 path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_upperExtreme);
143 path.lineTo(right + m_data.m_index, m_data.m_maxY - m_data.m_upperExtreme);
142 path.lineTo(right + m_data.m_index, m_data.m_maxY - m_data.m_upperExtreme);
144 path.moveTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_upperExtreme);
143 path.moveTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_upperExtreme);
145 path.lineTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_upperQuartile);
144 path.lineTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_upperQuartile);
146 path.closeSubpath();
145 path.closeSubpath();
147
146
148 // Middle Box
147 // Middle Box
149 path.addRect(left + m_data.m_index, m_data.m_maxY - m_data.m_upperQuartile,
148 path.addRect(left + m_data.m_index, m_data.m_maxY - m_data.m_upperQuartile,
150 0.5 * columnWidth, m_data.m_upperQuartile - m_data.m_lowerQuartile);
149 0.5 * columnWidth, m_data.m_upperQuartile - m_data.m_lowerQuartile);
151
150
152 // Median/mean line
151 // Median/mean line
153 path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_median);
152 path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_median);
154 path.lineTo(right + m_data.m_index, m_data.m_maxY - m_data.m_median);
153 path.lineTo(right + m_data.m_index, m_data.m_maxY - m_data.m_median);
155
154
156 // Lower whisker
155 // Lower whisker
157 path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_lowerExtreme);
156 path.moveTo(left + m_data.m_index, m_data.m_maxY - m_data.m_lowerExtreme);
158 path.lineTo(right + m_data.m_index, m_data.m_maxY - m_data.m_lowerExtreme);
157 path.lineTo(right + m_data.m_index, m_data.m_maxY - m_data.m_lowerExtreme);
159 path.moveTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_lowerExtreme);
158 path.moveTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_lowerExtreme);
160 path.lineTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_lowerQuartile);
159 path.lineTo(middle + m_data.m_index, m_data.m_maxY - m_data.m_lowerQuartile);
161 path.closeSubpath();
160 path.closeSubpath();
162
161
163 m_boxPath = path;
162 m_boxPath = path;
164
163
165 updateBoundingRect();
164 updateBoundingRect();
166
165
167 // qreal scaleY = m_domainSize.height() / (m_data.m_maxY - m_data.m_minY);
166 // qreal scaleY = m_domainSize.height() / (m_data.m_maxY - m_data.m_minY);
168 // qreal scaleX = m_domainSize.width() / m_data.m_boxItems;
167 // qreal scaleX = m_domainSize.width() / m_data.m_boxItems;
169 // QRectF br = path.boundingRect();
168 // QRectF br = path.boundingRect();
170 // m_boundingRect = QRectF( br.x() * scaleX, br.y() * scaleY, br.width() * scaleX, br.height() * scaleY);
169 // m_boundingRect = QRectF( br.x() * scaleX, br.y() * scaleY, br.width() * scaleX, br.height() * scaleY);
171
170
172 if (m_data.m_index == 5) {
171 if (m_data.m_index == 5) {
173 //qDebug() << "myValue = " << myValue;
172 //qDebug() << "myValue = " << myValue;
174 //qDebug() << "m_data.m_upperExtreme" << m_data.m_upperExtreme;
173 //qDebug() << "m_data.m_upperExtreme" << m_data.m_upperExtreme;
175 //qDebug() << "m_boundingRect = " << m_boundingRect;
174 //qDebug() << "m_boundingRect = " << m_boundingRect;
176 // qDebug() << "x = " << m_boundingRect.x() << ", y = " << m_boundingRect.y() << ", width = "
175 // qDebug() << "x = " << m_boundingRect.x() << ", y = " << m_boundingRect.y() << ", width = "
177 // << m_boundingRect.width() << ", height = " << m_boundingRect.height();
176 // << m_boundingRect.width() << ", height = " << m_boundingRect.height();
178 }
177 }
179 }
178 }
180
179
181 void BoxWhiskers::updateBoundingRect()
180 void BoxWhiskers::updateBoundingRect()
182 {
181 {
183 qreal scaleY = m_domainSize.height() / (m_data.m_maxY - m_data.m_minY);
182 qreal scaleY = m_domainSize.height() / (m_data.m_maxY - m_data.m_minY);
184 qreal scaleX = m_domainSize.width() / m_data.m_boxItems;
183 qreal scaleX = m_domainSize.width() / m_data.m_boxItems;
185 QRectF br = m_boxPath.boundingRect();
184 QRectF br = m_boxPath.boundingRect();
186 m_boundingRect = QRectF( br.x() * scaleX, br.y() * scaleY, br.width() * scaleX, br.height() * scaleY);
185 m_boundingRect = QRectF( br.x() * scaleX, br.y() * scaleY, br.width() * scaleX, br.height() * scaleY);
187 }
186 }
188
187
189 #include "moc_boxwhiskers_p.cpp"
188 #include "moc_boxwhiskers_p.cpp"
190
189
191 QTCOMMERCIALCHART_END_NAMESPACE
190 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,96 +1,97
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef BOXWHISKERS_H
30 #ifndef BOXWHISKERS_H
31 #define BOXWHISKERS_H
31 #define BOXWHISKERS_H
32
32
33 #include "boxwhiskersdata_p.h"
33 #include "boxwhiskersdata_p.h"
34 #include "qchartglobal.h"
34 #include "qchartglobal.h"
35 #include "qbarset.h"
36 #include "abstractdomain_p.h"
35 #include "abstractdomain_p.h"
36 #include <QBoxSet>
37 #include <QGraphicsRectItem>
37 #include <QGraphicsRectItem>
38 #include <QGraphicsLineItem>
38 #include <QGraphicsLineItem>
39 #include <QGraphicsLayoutItem>
39 #include <QGraphicsLayoutItem>
40 #include <QPainterPath>
40 #include <QPainterPath>
41
41
42 QTCOMMERCIALCHART_BEGIN_NAMESPACE
42 QTCOMMERCIALCHART_BEGIN_NAMESPACE
43
43
44 class QBarSet;
44 class QBarSet;
45
45
46 class BoxWhiskers : public QGraphicsObject/*, public QGraphicsLayoutItem*/
46 class BoxWhiskers : public QGraphicsObject/*, public QGraphicsLayoutItem*/
47 {
47 {
48 Q_OBJECT
48 Q_OBJECT
49 //Q_INTERFACES(QGraphicsLayoutItem)
49 //Q_INTERFACES(QGraphicsLayoutItem)
50 public:
50 public:
51 BoxWhiskers(AbstractDomain *domain, QGraphicsObject *parent);
51 BoxWhiskers(QBoxSet *set, AbstractDomain *domain, QGraphicsObject *parent);
52 ~BoxWhiskers();
52 ~BoxWhiskers();
53
53
54 void setBrush(const QBrush &brush);
54 void setBrush(const QBrush &brush);
55 void setPen(const QPen &pen);
55 void setPen(const QPen &pen);
56 void setLayout(const BoxWhiskersData &data);
56 void setLayout(const BoxWhiskersData &data);
57 void setDomainSize(const QSizeF &size);
57 void setDomainSize(const QSizeF &size);
58
58
59 void mousePressEvent(QGraphicsSceneMouseEvent *event);
59 void mousePressEvent(QGraphicsSceneMouseEvent *event);
60 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
60 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
61 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
61 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
62
62
63 QRectF boundingRect() const;
63 QRectF boundingRect() const;
64 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
64 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
65
65
66 // From QGraphicsLayoutItem // TODO tarkista nοΏ½mοΏ½ jollei ole QGraphicsLayoutItem
66 // From QGraphicsLayoutItem // TODO tarkista nοΏ½mοΏ½ jollei ole QGraphicsLayoutItem
67 void updateGeometry();
67 void updateGeometry();
68 protected:
68 protected:
69 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
69 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
70 void setGeometry(const QRectF &rect);
70 void setGeometry(const QRectF &rect);
71
71
72 private:
72 private:
73 void updateBoundingRect();
73 void updateBoundingRect();
74
74
75 Q_SIGNALS:
75 Q_SIGNALS:
76 void clicked(int index, QBarSet *barset);
76 void clicked(QBoxSet *boxset);
77 void hovered(bool status, QBarSet *barset);
77 void hovered(bool status, QBoxSet *boxset);
78
78
79 private:
79 private:
80 friend class BoxPlotChartItem;
80 friend class BoxPlotChartItem;
81 friend class BoxPlotAnimation;
81 friend class BoxPlotAnimation;
82
82
83 QBoxSet *m_boxSet;
83 AbstractDomain *m_domain;
84 AbstractDomain *m_domain;
84 QPainterPath m_boxPath;
85 QPainterPath m_boxPath;
85 QRectF m_boundingRect;
86 QRectF m_boundingRect;
86 bool m_hovering;
87 bool m_hovering;
87 bool m_validData;
88 bool m_validData;
88 QBrush m_brush;
89 QBrush m_brush;
89 QPen m_pen;
90 QPen m_pen;
90 BoxWhiskersData m_data;
91 BoxWhiskersData m_data;
91 QSizeF m_domainSize;
92 QSizeF m_domainSize;
92 };
93 };
93
94
94 QTCOMMERCIALCHART_END_NAMESPACE
95 QTCOMMERCIALCHART_END_NAMESPACE
95
96
96 #endif // BOXWHISKERS_H
97 #endif // BOXWHISKERS_H
@@ -1,581 +1,618
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qboxplotseries.h"
21 #include "qboxplotseries.h"
22 #include "qboxplotseries_p.h"
22 #include "qboxplotseries_p.h"
23 #include "qboxplotlegendmarker.h"
23 #include "qboxplotlegendmarker.h"
24 #include "qbarcategoryaxis.h"
24 #include "qbarcategoryaxis.h"
25 #include "boxplotchartitem_p.h"
25 #include "boxplotchartitem_p.h"
26 #include "chartdataset_p.h"
26 #include "chartdataset_p.h"
27 #include "charttheme_p.h"
27 #include "charttheme_p.h"
28 #include "qvalueaxis.h"
28 #include "qvalueaxis.h"
29 #include "charttheme_p.h"
29 #include "charttheme_p.h"
30 #include "boxplotanimation_p.h"
30 #include "boxplotanimation_p.h"
31 #include "qchart_p.h"
31 #include "qchart_p.h"
32 #include "qboxset.h"
32 #include "qboxset.h"
33 #include "qboxset_p.h"
33 #include "qboxset_p.h"
34
34
35 #include <QDebug>
35 #include <QDebug>
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
38
39 /*!
39 /*!
40 \class QBoxPlotSeries
40 \class QBoxPlotSeries
41 \brief Series for creating stacked bar chart
41 \brief Series for creating box-and-whiskers chart
42 \mainclass
42 \mainclass
43
43
44 QBoxPlotSeries represents a series of data shown as bars. The purpose of this class is to draw bars
44 QBoxPlotSeries represents a series of data shown as box-and-whisker bars. The purpose of this class is to act as
45 as stacks, where bars in same category are stacked on top of each other.
45 a container for single box-and-whisker items. Each item is drawn to own slot. If chart includes multiple QBoxPlotSeries
46 QBoxPlotSeries groups the data from sets to categories, which are defined by QStringList.
46 items with the same index are drawn to same slot.
47
47
48 See the \l {BoxPlotChart Example} {stacked bar chart example} to learn how to create a stacked bar chart.
48 See the \l {Box and Whiskers Example} {box-and-whiskers chart example} to learn how to create a box-and-whiskers chart.
49 \image examples_boxplotchart.png
49 \image examples_boxplotchart.png
50
50
51 \sa QBoxSet, QPercentBarSeries, QAbstractBarSeries
51 \sa QBoxSet
52 */
52 */
53
53
54 /*!
54 /*!
55 \qmlclass BoxPlotSeries QBoxPlotSeries
55 \qmlclass BoxPlotSeries QBoxPlotSeries
56 \inherits AbstractBarSeries
56 \inherits AbstractBarSeries
57
57
58 The following QML shows how to create a simple stacked bar chart:
58 The following QML shows how to create a simple box-and-whiskers chart:
59 \snippet ../demos/qmlchart/qml/qmlchart/View7.qml 1
59 \snippet ../examples/qmlboxplot/qml/qmlboxplot/main.qml 1
60 \beginfloatleft
60 \beginfloatleft
61 \image demos_qmlchart7.png
61 \image demos_qmlchart7.png
62 \endfloat
62 \endfloat
63 \clearfloat
63 \clearfloat
64 */
64 */
65
65
66 /*!
66 /*!
67 \fn QBoxPlotSeries::boxsetsAdded(QList<QBoxSet *> sets)
68 \brief Signal is emitted when a new \a sets of box-and-whiskers data is added to the series.
69 */
70
71 /*!
72 \fn QBoxPlotSeries::boxsetsRemoved(QList<QBoxSet *> sets)
73 \brief Signal is emitted when \a sets of box-and-whiskers data is removed from the series.
74 */
75
76 /*!
77 \fn QBoxPlotSeries::clicked(QBoxSet *boxset)
78 \brief Signal is emitted when the user clicks the \a boxset on the chart.
79 */
80
81 /*!
82 \fn QBoxPlotSeries::hovered(bool status, QBoxSet *boxset)
83 \brief Signal is emitted when there is change in hover \a status over \a boxset.
84 */
85
86 /*!
87 \fn QBoxPlotSeries::countChanged()
88 \brief Signal is emitted when there is change in count of box-and-whiskers items in the series.
89 */
90
91 /*!
67 Constructs empty QBoxPlotSeries.
92 Constructs empty QBoxPlotSeries.
68 QBoxPlotSeries is QObject which is a child of a \a parent.
93 QBoxPlotSeries is QObject which is a child of a \a parent.
69 */
94 */
70 QBoxPlotSeries::QBoxPlotSeries(QObject *parent)
95 QBoxPlotSeries::QBoxPlotSeries(QObject *parent)
71 : QAbstractSeries(*new QBoxPlotSeriesPrivate(this), parent)
96 : QAbstractSeries(*new QBoxPlotSeriesPrivate(this), parent)
72 {
97 {
73 }
98 }
74
99
75 /*!
100 /*!
76 Destructor. Removes series from chart.
101 Destructor. Removes series from chart.
77 */
102 */
78 QBoxPlotSeries::~QBoxPlotSeries()
103 QBoxPlotSeries::~QBoxPlotSeries()
79 {
104 {
80 qDebug() << "QBoxPlotSeries::~QBoxPlotSeries";
105 qDebug() << "QBoxPlotSeries::~QBoxPlotSeries";
81
106
82 Q_D(QBoxPlotSeries);
107 Q_D(QBoxPlotSeries);
83 if (d->m_chart)
108 if (d->m_chart)
84 d->m_chart->removeSeries(this);
109 d->m_chart->removeSeries(this);
85 }
110 }
86
111
87 /*!
112 /*!
88 Adds a single box and whiskers item to series. Takes ownership of \a the box. If the box is null or is already in series, it won't be appended.
113 Adds a single box and whiskers set to series. Takes ownership of the \a set. If the set is null or is already in series, it won't be appended.
89 Returns true, if appending succeeded.
114 Returns true, if appending succeeded.
90 */
115 */
91 bool QBoxPlotSeries::append(QBoxSet *set)
116 bool QBoxPlotSeries::append(QBoxSet *set)
92 {
117 {
93 Q_D(QBoxPlotSeries);
118 Q_D(QBoxPlotSeries);
94
119
95 bool success = d->append(set);
120 bool success = d->append(set);
96 if (success) {
121 if (success) {
97 QList<QBoxSet *> sets;
122 QList<QBoxSet *> sets;
98 sets.append(set);
123 sets.append(set);
99 set->setParent(this);
124 set->setParent(this);
100 emit boxsetsAdded(sets);
125 emit boxsetsAdded(sets);
101 emit countChanged();
126 emit countChanged();
102 }
127 }
103 return success;
128 return success;
104 }
129 }
105
130
106 /*!
131 /*!
107 Removes boxset from the series. Releases ownership of the \a set. Deletes the set, if remove
132 Removes boxset from the series. Releases ownership of the \a set. Deletes the set, if remove
108 was successful.
133 was successful.
109 Returns true, if the set was removed.
134 Returns true, if the set was removed.
110 */
135 */
111 bool QBoxPlotSeries::remove(QBoxSet *set)
136 bool QBoxPlotSeries::remove(QBoxSet *set)
112 {
137 {
113 Q_D(QBoxPlotSeries);
138 Q_D(QBoxPlotSeries);
114 bool success = d->remove(set);
139 bool success = d->remove(set);
115 if (success) {
140 if (success) {
116 QList<QBoxSet *> sets;
141 QList<QBoxSet *> sets;
117 sets.append(set);
142 sets.append(set);
118 set->setParent(0);
143 set->setParent(0);
119 emit boxsetsRemoved(sets);
144 emit boxsetsRemoved(sets);
120 emit countChanged();
145 emit countChanged();
121 delete set;
146 delete set;
122 set = 0;
147 set = 0;
123 }
148 }
124 return success;
149 return success;
125 }
150 }
126
151
127 /*!
152 /*!
128 Takes a single \a set from the series. Does not delete the boxset object.
153 Takes a single \a set from the series. Does not delete the boxset object.
129
154
130 NOTE: The series remains as the boxset's parent object. You must set the
155 NOTE: The series remains as the boxset's parent object. You must set the
131 parent object to take full ownership.
156 parent object to take full ownership.
132
157
133 Returns true if take was successful.
158 Returns true if take was successful.
134 */
159 */
135 bool QBoxPlotSeries::take(QBoxSet *set)
160 bool QBoxPlotSeries::take(QBoxSet *set)
136 {
161 {
137 Q_D(QBoxPlotSeries);
162 Q_D(QBoxPlotSeries);
138
163
139 bool success = d->remove(set);
164 bool success = d->remove(set);
140 if (success) {
165 if (success) {
141 QList<QBoxSet *> sets;
166 QList<QBoxSet *> sets;
142 sets.append(set);
167 sets.append(set);
143 emit boxsetsRemoved(sets);
168 emit boxsetsRemoved(sets);
144 emit countChanged();
169 emit countChanged();
145 }
170 }
146 return success;
171 return success;
147 }
172 }
148
173
149 /*!
174 /*!
150 Adds a list of boxsets to series. Takes ownership of the \a sets.
175 Adds a list of boxsets to series. Takes ownership of the \a sets.
151 Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series,
176 Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series,
152 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
177 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
153 and function returns false.
178 and function returns false.
154 */
179 */
155 bool QBoxPlotSeries::append(QList<QBoxSet *> sets)
180 bool QBoxPlotSeries::append(QList<QBoxSet *> sets)
156 {
181 {
157 Q_D(QBoxPlotSeries);
182 Q_D(QBoxPlotSeries);
158 bool success = d->append(sets);
183 bool success = d->append(sets);
159 if (success) {
184 if (success) {
160 emit boxsetsAdded(sets);
185 emit boxsetsAdded(sets);
161 emit countChanged();
186 emit countChanged();
162 }
187 }
163 return success;
188 return success;
164 }
189 }
165
190
166 /*!
191 /*!
167 Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
192 Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
168 Returns true, if inserting succeeded.
193 Returns true, if inserting succeeded.
169
194
170 */
195 */
171 bool QBoxPlotSeries::insert(int index, QBoxSet *set)
196 bool QBoxPlotSeries::insert(int index, QBoxSet *set)
172 {
197 {
173 Q_D(QBoxPlotSeries);
198 Q_D(QBoxPlotSeries);
174 bool success = d->insert(index, set);
199 bool success = d->insert(index, set);
175 if (success) {
200 if (success) {
176 QList<QBoxSet *> sets;
201 QList<QBoxSet *> sets;
177 sets.append(set);
202 sets.append(set);
178 emit boxsetsAdded(sets);
203 emit boxsetsAdded(sets);
179 emit countChanged();
204 emit countChanged();
180 }
205 }
181 return success;
206 return success;
182 }
207 }
183
208
184 /*!
209 /*!
185 Removes all boxsets from the series. Deletes removed sets.
210 Removes all boxsets from the series. Deletes removed sets.
186 */
211 */
187 void QBoxPlotSeries::clear()
212 void QBoxPlotSeries::clear()
188 {
213 {
189 Q_D(QBoxPlotSeries);
214 Q_D(QBoxPlotSeries);
190 QList<QBoxSet *> sets = boxSets();
215 QList<QBoxSet *> sets = boxSets();
191 bool success = d->remove(sets);
216 bool success = d->remove(sets);
192 if (success) {
217 if (success) {
193 emit boxsetsRemoved(sets);
218 emit boxsetsRemoved(sets);
194 emit countChanged();
219 emit countChanged();
195 foreach (QBoxSet *set, sets)
220 foreach (QBoxSet *set, sets)
196 delete set;
221 delete set;
197 }
222 }
198 }
223 }
199
224
200 /*!
225 /*!
201 Returns number of sets in series.
226 Returns number of sets in series.
202 */
227 */
203 int QBoxPlotSeries::count() const
228 int QBoxPlotSeries::count() const
204 {
229 {
205 Q_D(const QBoxPlotSeries);
230 Q_D(const QBoxPlotSeries);
206 return d->m_boxSets.count();
231 return d->m_boxSets.count();
207 }
232 }
208
233
209 /*!
234 /*!
210 Returns a list of sets in series. Keeps ownership of sets.
235 Returns a list of sets in series. Keeps ownership of sets.
211 */
236 */
212 QList<QBoxSet *> QBoxPlotSeries::boxSets() const
237 QList<QBoxSet *> QBoxPlotSeries::boxSets() const
213 {
238 {
214 Q_D(const QBoxPlotSeries);
239 Q_D(const QBoxPlotSeries);
215 return d->m_boxSets;
240 return d->m_boxSets;
216 }
241 }
217
242
218 /*!
243 /*!
219 Returns QChartSeries::SeriesTypeBoxPlot.
244 Returns QChartSeries::SeriesTypeBoxPlot.
220 */
245 */
221 QAbstractSeries::SeriesType QBoxPlotSeries::type() const
246 QAbstractSeries::SeriesType QBoxPlotSeries::type() const
222 {
247 {
223 return QAbstractSeries::SeriesTypeBoxPlot;
248 return QAbstractSeries::SeriesTypeBoxPlot;
224 }
249 }
225
250
251 /*!
252 Sets brush for the series. Box-and-whiskers items are drawn using \a brush
253 */
226 void QBoxPlotSeries::setBrush(const QBrush &brush)
254 void QBoxPlotSeries::setBrush(const QBrush &brush)
227 {
255 {
228 Q_D(QBoxPlotSeries);
256 Q_D(QBoxPlotSeries);
229
257
230 if (d->m_brush != brush) {
258 if (d->m_brush != brush) {
231 d->m_brush = brush;
259 d->m_brush = brush;
232 emit d->updated();
260 emit d->updated();
233 }
261 }
234 }
262 }
235
263
264 /*!
265 Returns brush of the series.
266 */
236 QBrush QBoxPlotSeries::brush() const
267 QBrush QBoxPlotSeries::brush() const
237 {
268 {
238 Q_D(const QBoxPlotSeries);
269 Q_D(const QBoxPlotSeries);
239
270
240 return d->m_brush;
271 return d->m_brush;
241 }
272 }
242
273
274 /*!
275 Sets pen for the series. Box-and-whiskers items are drawn using \a pen
276 */
243 void QBoxPlotSeries::setPen(const QPen &pen)
277 void QBoxPlotSeries::setPen(const QPen &pen)
244 {
278 {
245 Q_D(QBoxPlotSeries);
279 Q_D(QBoxPlotSeries);
246
280
247 if (d->m_pen != pen) {
281 if (d->m_pen != pen) {
248 d->m_pen = pen;
282 d->m_pen = pen;
249 emit d->updated();
283 emit d->updated();
250 }
284 }
251 }
285 }
252
286
287 /*!
288 Returns the pen of this series.
289 */
253 QPen QBoxPlotSeries::pen() const
290 QPen QBoxPlotSeries::pen() const
254 {
291 {
255 Q_D(const QBoxPlotSeries);
292 Q_D(const QBoxPlotSeries);
256
293
257 return d->m_pen;
294 return d->m_pen;
258 }
295 }
259
296
260 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
297 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
261
298
262 QBoxPlotSeriesPrivate::QBoxPlotSeriesPrivate(QBoxPlotSeries *q)
299 QBoxPlotSeriesPrivate::QBoxPlotSeriesPrivate(QBoxPlotSeries *q)
263 : QAbstractSeriesPrivate(q),
300 : QAbstractSeriesPrivate(q),
264 m_pen(QPen(Qt::NoPen)),
301 m_pen(QPen(Qt::NoPen)),
265 m_brush(QBrush(Qt::NoBrush))
302 m_brush(QBrush(Qt::NoBrush))
266 {
303 {
267 }
304 }
268
305
269 QBoxPlotSeriesPrivate::~QBoxPlotSeriesPrivate()
306 QBoxPlotSeriesPrivate::~QBoxPlotSeriesPrivate()
270 {
307 {
271 qDebug() << "QBoxPlotSeriesPrivate::~QBoxPlotSeriesPrivate()";
308 qDebug() << "QBoxPlotSeriesPrivate::~QBoxPlotSeriesPrivate()";
272 disconnect(this, 0, 0, 0);
309 disconnect(this, 0, 0, 0);
273 }
310 }
274
311
275 void QBoxPlotSeriesPrivate::initializeDomain()
312 void QBoxPlotSeriesPrivate::initializeDomain()
276 {
313 {
277 qreal minX(domain()->minX());
314 qreal minX(domain()->minX());
278 qreal minY(domain()->minY());
315 qreal minY(domain()->minY());
279 qreal maxX(domain()->maxX());
316 qreal maxX(domain()->maxX());
280 qreal maxY(domain()->maxY());
317 qreal maxY(domain()->maxY());
281
318
282 qreal x = m_boxSets.count();
319 qreal x = m_boxSets.count();
283 minX = qMin(minX, - (qreal)0.5);
320 minX = qMin(minX, - (qreal)0.5);
284 minY = qMin(minY, bottom());
321 minY = qMin(minY, bottom());
285 maxX = qMax(maxX, x - (qreal)0.5);
322 maxX = qMax(maxX, x - (qreal)0.5);
286 maxY = qMax(maxY, max());
323 maxY = qMax(maxY, max());
287
324
288 domain()->setRange(minX, maxX, minY, maxY);
325 domain()->setRange(minX, maxX, minY, maxY);
289 }
326 }
290
327
291 void QBoxPlotSeriesPrivate::initializeAxes()
328 void QBoxPlotSeriesPrivate::initializeAxes()
292 {
329 {
293 foreach (QAbstractAxis* axis, m_axes) {
330 foreach (QAbstractAxis* axis, m_axes) {
294 if (axis->type() == QAbstractAxis::AxisTypeBarCategory) {
331 if (axis->type() == QAbstractAxis::AxisTypeBarCategory) {
295 if (axis->orientation() == Qt::Horizontal)
332 if (axis->orientation() == Qt::Horizontal)
296 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
333 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
297 else
334 else
298 qDebug() << "ALERT: QBoxPlotSeriesPrivate::initializeAxes implement #1";
335 qDebug() << "ALERT: QBoxPlotSeriesPrivate::initializeAxes implement #1";
299 }
336 }
300 }
337 }
301 }
338 }
302
339
303 QAbstractAxis::AxisType QBoxPlotSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
340 QAbstractAxis::AxisType QBoxPlotSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
304 {
341 {
305 if (orientation == Qt::Horizontal)
342 if (orientation == Qt::Horizontal)
306 return QAbstractAxis::AxisTypeBarCategory;
343 return QAbstractAxis::AxisTypeBarCategory;
307
344
308 return QAbstractAxis::AxisTypeValue;
345 return QAbstractAxis::AxisTypeValue;
309 }
346 }
310
347
311 QAbstractAxis* QBoxPlotSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
348 QAbstractAxis* QBoxPlotSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
312 {
349 {
313 Q_UNUSED(orientation);
350 Q_UNUSED(orientation);
314 // This is not implemented even in barseries, keep in touch if something needs this
351 // This is not implemented even in barseries, keep in touch if something needs this
315 qDebug() << "ALERT: QBoxPlotSeriesPrivate::createDefaultAxis implement";
352 qDebug() << "ALERT: QBoxPlotSeriesPrivate::createDefaultAxis implement";
316 return 0;
353 return 0;
317 }
354 }
318
355
319 void QBoxPlotSeriesPrivate::populateCategories(QBarCategoryAxis *axis)
356 void QBoxPlotSeriesPrivate::populateCategories(QBarCategoryAxis *axis)
320 {
357 {
321 QStringList categories;
358 QStringList categories;
322 if (axis->categories().isEmpty()) {
359 if (axis->categories().isEmpty()) {
323 for (int i(1); i < m_boxSets.count() + 1; i++) {
360 for (int i(1); i < m_boxSets.count() + 1; i++) {
324 QBoxSet *set = m_boxSets.at(i - 1);
361 QBoxSet *set = m_boxSets.at(i - 1);
325 if (set->label().isEmpty())
362 if (set->label().isEmpty())
326 categories << QString::number(i);
363 categories << QString::number(i);
327 else
364 else
328 categories << set->label();
365 categories << set->label();
329 }
366 }
330 axis->append(categories);
367 axis->append(categories);
331 }
368 }
332 }
369 }
333
370
334 void QBoxPlotSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
371 void QBoxPlotSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
335 {
372 {
336 Q_Q(QBoxPlotSeries);
373 Q_Q(QBoxPlotSeries);
337
374
338 BoxPlotChartItem *boxPlot = new BoxPlotChartItem(q,parent);
375 BoxPlotChartItem *boxPlot = new BoxPlotChartItem(q,parent);
339 m_item.reset(boxPlot);
376 m_item.reset(boxPlot);
340 QAbstractSeriesPrivate::initializeGraphics(parent);
377 QAbstractSeriesPrivate::initializeGraphics(parent);
341
378
342 if (m_chart) {
379 if (m_chart) {
343 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesChange(QAbstractSeries*)) );
380 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesChange(QAbstractSeries*)) );
344 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SLOT(handleSeriesRemove(QAbstractSeries*)) );
381 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SLOT(handleSeriesRemove(QAbstractSeries*)) );
345
382
346 QList<QAbstractSeries *> serieses = m_chart->series();
383 QList<QAbstractSeries *> serieses = m_chart->series();
347
384
348 // Tries to find this series from the Chart's list of serieses and deduce the index
385 // Tries to find this series from the Chart's list of serieses and deduce the index
349 int index = 0;
386 int index = 0;
350 foreach (QAbstractSeries *s, serieses) {
387 foreach (QAbstractSeries *s, serieses) {
351 if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) {
388 if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) {
352 if (q == static_cast<QBoxPlotSeries *>(s)) {
389 if (q == static_cast<QBoxPlotSeries *>(s)) {
353 boxPlot->m_seriesIndex = index;
390 boxPlot->m_seriesIndex = index;
354 m_index = index;
391 m_index = index;
355 }
392 }
356 index++;
393 index++;
357 }
394 }
358 }
395 }
359 boxPlot->m_seriesCount = index;
396 boxPlot->m_seriesCount = index;
360 }
397 }
361
398
362 // Make BoxPlotChartItem to instantiate box & whisker items
399 // Make BoxPlotChartItem to instantiate box & whisker items
363 boxPlot->handleDataStructureChanged();
400 boxPlot->handleDataStructureChanged();
364 }
401 }
365
402
366 void QBoxPlotSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
403 void QBoxPlotSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
367 {
404 {
368 Q_Q(QBoxPlotSeries);
405 Q_Q(QBoxPlotSeries);
369 qDebug() << "QBoxPlotSeriesPrivate::initializeTheme";
406 qDebug() << "QBoxPlotSeriesPrivate::initializeTheme";
370
407
371 const QList<QGradient> gradients = theme->seriesGradients();
408 const QList<QGradient> gradients = theme->seriesGradients();
372
409
373 if (forced || m_brush == QBrush(Qt::NoBrush)) {
410 if (forced || m_brush == QBrush(Qt::NoBrush)) {
374 QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.5);
411 QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.5);
375 q->setBrush(brushColor);
412 q->setBrush(brushColor);
376 }
413 }
377
414
378 if (forced || m_pen == QPen(Qt::NoPen)) {
415 if (forced || m_pen == QPen(Qt::NoPen)) {
379 QPen pen = theme->outlinePen();
416 QPen pen = theme->outlinePen();
380 pen.setCosmetic(true);
417 pen.setCosmetic(true);
381 q->setPen(pen);
418 q->setPen(pen);
382 }
419 }
383 }
420 }
384
421
385 void QBoxPlotSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options)
422 void QBoxPlotSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options)
386 {
423 {
387 BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data());
424 BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data());
388 Q_ASSERT(item);
425 Q_ASSERT(item);
389 if (options.testFlag(QChart::SeriesAnimations)) {
426 if (options.testFlag(QChart::SeriesAnimations)) {
390 item->setAnimation(new BoxPlotAnimation(item));
427 item->setAnimation(new BoxPlotAnimation(item));
391 }else{
428 }else{
392 item->setAnimation((BoxPlotAnimation *)0);
429 item->setAnimation((BoxPlotAnimation *)0);
393 }
430 }
394 QAbstractSeriesPrivate::initializeAnimations(options);
431 QAbstractSeriesPrivate::initializeAnimations(options);
395 }
432 }
396
433
397 QList<QLegendMarker*> QBoxPlotSeriesPrivate::createLegendMarkers(QLegend *legend)
434 QList<QLegendMarker*> QBoxPlotSeriesPrivate::createLegendMarkers(QLegend *legend)
398 {
435 {
399 Q_Q(QBoxPlotSeries);
436 Q_Q(QBoxPlotSeries);
400 QList<QLegendMarker*> list;
437 QList<QLegendMarker*> list;
401 return list << new QBoxPlotLegendMarker(q, legend);
438 return list << new QBoxPlotLegendMarker(q, legend);
402 }
439 }
403
440
404 void QBoxPlotSeriesPrivate::handleSeriesRemove(QAbstractSeries *series)
441 void QBoxPlotSeriesPrivate::handleSeriesRemove(QAbstractSeries *series)
405 {
442 {
406 qDebug() << "QBoxPlotSeriesPrivate::handleSeriesRemove";
443 qDebug() << "QBoxPlotSeriesPrivate::handleSeriesRemove";
407 Q_Q(QBoxPlotSeries);
444 Q_Q(QBoxPlotSeries);
408
445
409 QBoxPlotSeries *removedSeries = static_cast<QBoxPlotSeries *>(series);
446 QBoxPlotSeries *removedSeries = static_cast<QBoxPlotSeries *>(series);
410 QObject::disconnect(m_chart->d_ptr->m_dataset, 0, removedSeries->d_func(), 0);
447 QObject::disconnect(m_chart->d_ptr->m_dataset, 0, removedSeries->d_func(), 0);
411
448
412 // Test if series removed is me, then don't do anything
449 // Test if series removed is me, then don't do anything
413 if (q != removedSeries) {
450 if (q != removedSeries) {
414 BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data());
451 BoxPlotChartItem *item = static_cast<BoxPlotChartItem *>(m_item.data());
415 if (item) {
452 if (item) {
416 item->m_seriesCount = item->m_seriesCount - 1;
453 item->m_seriesCount = item->m_seriesCount - 1;
417 if (removedSeries->d_func()->m_index < m_index) {
454 if (removedSeries->d_func()->m_index < m_index) {
418 m_index--;
455 m_index--;
419 item->m_seriesIndex = m_index;
456 item->m_seriesIndex = m_index;
420 }
457 }
421
458
422 item->handleDataStructureChanged();
459 item->handleDataStructureChanged();
423 }
460 }
424 }
461 }
425 }
462 }
426
463
427 void QBoxPlotSeriesPrivate::handleSeriesChange(QAbstractSeries *series)
464 void QBoxPlotSeriesPrivate::handleSeriesChange(QAbstractSeries *series)
428 {
465 {
429 Q_UNUSED(series);
466 Q_UNUSED(series);
430
467
431 Q_Q(QBoxPlotSeries);
468 Q_Q(QBoxPlotSeries);
432
469
433 BoxPlotChartItem *boxPlot = static_cast<BoxPlotChartItem *>(m_item.data());
470 BoxPlotChartItem *boxPlot = static_cast<BoxPlotChartItem *>(m_item.data());
434
471
435 if (m_chart) {
472 if (m_chart) {
436 QList<QAbstractSeries *> serieses = m_chart->series();
473 QList<QAbstractSeries *> serieses = m_chart->series();
437
474
438 // Tries to find this series from the Chart's list of serieses and deduce the index
475 // Tries to find this series from the Chart's list of serieses and deduce the index
439 int index = 0;
476 int index = 0;
440 foreach (QAbstractSeries *s, serieses) {
477 foreach (QAbstractSeries *s, serieses) {
441 if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) {
478 if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) {
442 if (q == static_cast<QBoxPlotSeries *>(s)) {
479 if (q == static_cast<QBoxPlotSeries *>(s)) {
443 boxPlot->m_seriesIndex = index;
480 boxPlot->m_seriesIndex = index;
444 m_index = index;
481 m_index = index;
445 }
482 }
446 index++;
483 index++;
447 }
484 }
448 }
485 }
449 boxPlot->m_seriesCount = index;
486 boxPlot->m_seriesCount = index;
450 }
487 }
451
488
452 boxPlot->handleDataStructureChanged();
489 boxPlot->handleDataStructureChanged();
453 }
490 }
454
491
455 bool QBoxPlotSeriesPrivate::append(QBoxSet *set)
492 bool QBoxPlotSeriesPrivate::append(QBoxSet *set)
456 {
493 {
457 if ((m_boxSets.contains(set)) || (set == 0))
494 if ((m_boxSets.contains(set)) || (set == 0))
458 return false; // Fail if set is already in list or set is null.
495 return false; // Fail if set is already in list or set is null.
459
496
460 m_boxSets.append(set);
497 m_boxSets.append(set);
461 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
498 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
462 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
499 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
463 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
500 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
464
501
465 emit restructuredBoxes(); // this notifies boxplotchartitem
502 emit restructuredBoxes(); // this notifies boxplotchartitem
466 return true;
503 return true;
467 }
504 }
468
505
469 bool QBoxPlotSeriesPrivate::remove(QBoxSet *set)
506 bool QBoxPlotSeriesPrivate::remove(QBoxSet *set)
470 {
507 {
471 if (!m_boxSets.contains(set))
508 if (!m_boxSets.contains(set))
472 return false; // Fail if set is not in list
509 return false; // Fail if set is not in list
473
510
474 m_boxSets.removeOne(set);
511 m_boxSets.removeOne(set);
475 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
512 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
476 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
513 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
477 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
514 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
478
515
479 emit restructuredBoxes(); // this notifies boxplotchartitem
516 emit restructuredBoxes(); // this notifies boxplotchartitem
480 return true;
517 return true;
481 }
518 }
482
519
483 bool QBoxPlotSeriesPrivate::append(QList<QBoxSet * > sets)
520 bool QBoxPlotSeriesPrivate::append(QList<QBoxSet * > sets)
484 {
521 {
485 foreach (QBoxSet *set, sets) {
522 foreach (QBoxSet *set, sets) {
486 if ((set == 0) || (m_boxSets.contains(set)))
523 if ((set == 0) || (m_boxSets.contains(set)))
487 return false; // Fail if any of the sets is null or is already appended.
524 return false; // Fail if any of the sets is null or is already appended.
488 if (sets.count(set) != 1)
525 if (sets.count(set) != 1)
489 return false; // Also fail if same set is more than once in given list.
526 return false; // Also fail if same set is more than once in given list.
490 }
527 }
491
528
492 foreach (QBoxSet *set, sets) {
529 foreach (QBoxSet *set, sets) {
493 m_boxSets.append(set);
530 m_boxSets.append(set);
494 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
531 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
495 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
532 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
496 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
533 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
497 }
534 }
498
535
499 emit restructuredBoxes(); // this notifies boxplotchartitem
536 emit restructuredBoxes(); // this notifies boxplotchartitem
500 return true;
537 return true;
501 }
538 }
502
539
503 bool QBoxPlotSeriesPrivate::remove(QList<QBoxSet * > sets)
540 bool QBoxPlotSeriesPrivate::remove(QList<QBoxSet * > sets)
504 {
541 {
505 if (sets.count() == 0)
542 if (sets.count() == 0)
506 return false;
543 return false;
507
544
508 foreach (QBoxSet *set, sets) {
545 foreach (QBoxSet *set, sets) {
509 if ((set == 0) || (!m_boxSets.contains(set)))
546 if ((set == 0) || (!m_boxSets.contains(set)))
510 return false; // Fail if any of the sets is null or is not in series
547 return false; // Fail if any of the sets is null or is not in series
511 if (sets.count(set) != 1)
548 if (sets.count(set) != 1)
512 return false; // Also fail if same set is more than once in given list.
549 return false; // Also fail if same set is more than once in given list.
513 }
550 }
514
551
515 foreach (QBoxSet *set, sets) {
552 foreach (QBoxSet *set, sets) {
516 m_boxSets.removeOne(set);
553 m_boxSets.removeOne(set);
517 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
554 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
518 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
555 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
519 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
556 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
520 }
557 }
521
558
522 emit restructuredBoxes(); // this notifies boxplotchartitem
559 emit restructuredBoxes(); // this notifies boxplotchartitem
523
560
524 return true;
561 return true;
525 }
562 }
526
563
527 bool QBoxPlotSeriesPrivate::insert(int index, QBoxSet *set)
564 bool QBoxPlotSeriesPrivate::insert(int index, QBoxSet *set)
528 {
565 {
529 if ((m_boxSets.contains(set)) || (set == 0))
566 if ((m_boxSets.contains(set)) || (set == 0))
530 return false; // Fail if set is already in list or set is null.
567 return false; // Fail if set is already in list or set is null.
531
568
532 m_boxSets.insert(index, set);
569 m_boxSets.insert(index, set);
533 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
570 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
534 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
571 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes()));
535 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
572 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes()));
536
573
537 emit restructuredBoxes(); // this notifies boxplotchartitem
574 emit restructuredBoxes(); // this notifies boxplotchartitem
538 return true;
575 return true;
539 }
576 }
540
577
541 QBoxSet *QBoxPlotSeriesPrivate::boxsetAt(int index)
578 QBoxSet *QBoxPlotSeriesPrivate::boxsetAt(int index)
542 {
579 {
543 return m_boxSets.at(index);
580 return m_boxSets.at(index);
544 }
581 }
545
582
546 qreal QBoxPlotSeriesPrivate::bottom()
583 qreal QBoxPlotSeriesPrivate::bottom()
547 {
584 {
548 // Returns bottom of all boxes
585 // Returns bottom of all boxes
549 qreal bottom(0);
586 qreal bottom(0);
550 foreach (QBoxSet *set, m_boxSets) {
587 foreach (QBoxSet *set, m_boxSets) {
551 for (int i = 0; i < set->count(); i++) {
588 for (int i = 0; i < set->count(); i++) {
552 if (set->at(i) < bottom)
589 if (set->at(i) < bottom)
553 bottom = set->at(i);
590 bottom = set->at(i);
554 }
591 }
555 }
592 }
556
593
557 return bottom;
594 return bottom;
558 }
595 }
559
596
560 qreal QBoxPlotSeriesPrivate::max()
597 qreal QBoxPlotSeriesPrivate::max()
561 {
598 {
562 if (m_boxSets.count() <= 0)
599 if (m_boxSets.count() <= 0)
563 return 0;
600 return 0;
564
601
565 qreal max = INT_MIN;
602 qreal max = INT_MIN;
566
603
567 foreach (QBoxSet *set, m_boxSets) {
604 foreach (QBoxSet *set, m_boxSets) {
568 for (int i = 0; i < set->count(); i++) {
605 for (int i = 0; i < set->count(); i++) {
569 if (set->at(i) > max)
606 if (set->at(i) > max)
570 max = set->at(i);
607 max = set->at(i);
571 }
608 }
572 }
609 }
573
610
574 return max;
611 return max;
575 }
612 }
576
613
577 #include "moc_qboxplotseries.cpp"
614 #include "moc_qboxplotseries.cpp"
578 #include "moc_qboxplotseries_p.cpp"
615 #include "moc_qboxplotseries_p.cpp"
579
616
580 QTCOMMERCIALCHART_END_NAMESPACE
617 QTCOMMERCIALCHART_END_NAMESPACE
581
618
@@ -1,78 +1,72
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QBOXPLOTSERIES_H
21 #ifndef QBOXPLOTSERIES_H
22 #define QBOXPLOTSERIES_H
22 #define QBOXPLOTSERIES_H
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <qboxset.h>
25 #include <qboxset.h>
26 //#include <qabstractbarseries.h>
27 #include <qabstractseries.h>
26 #include <qabstractseries.h>
28
27
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
29
31 class QBoxPlotSeriesPrivate;
30 class QBoxPlotSeriesPrivate;
32 //class QBarSet;
33
31
34 class QTCOMMERCIALCHART_EXPORT QBoxPlotSeries : public QAbstractSeries
32 class QTCOMMERCIALCHART_EXPORT QBoxPlotSeries : public QAbstractSeries
35 {
33 {
36 Q_OBJECT
34 Q_OBJECT
37 public:
35 public:
38 explicit QBoxPlotSeries(QObject *parent = 0);
36 explicit QBoxPlotSeries(QObject *parent = 0);
39 ~QBoxPlotSeries();
37 ~QBoxPlotSeries();
40
38
41 bool append(QBoxSet *box);
39 bool append(QBoxSet *box);
42 bool remove(QBoxSet *box);
40 bool remove(QBoxSet *box);
43 bool take(QBoxSet *box);
41 bool take(QBoxSet *box);
44 bool append(QList<QBoxSet *> boxes);
42 bool append(QList<QBoxSet *> boxes);
45 bool insert(int index, QBoxSet *box);
43 bool insert(int index, QBoxSet *box);
46 int count() const;
44 int count() const;
47 QList<QBoxSet *> boxSets() const;
45 QList<QBoxSet *> boxSets() const;
48 void clear();
46 void clear();
49
47
50 void setLabelsVisible(bool visible = true);
51 bool isLabelsVisible() const;
52
53 QAbstractSeries::SeriesType type() const;
48 QAbstractSeries::SeriesType type() const;
54
49
55 void setBrush(const QBrush &brush);
50 void setBrush(const QBrush &brush);
56 QBrush brush() const;
51 QBrush brush() const;
57 void setPen(const QPen &pen);
52 void setPen(const QPen &pen);
58 QPen pen() const;
53 QPen pen() const;
59
54
60 Q_SIGNALS:
55 Q_SIGNALS:
61 void clicked(int index, QBoxSet *boxset);
56 void clicked(QBoxSet *boxset);
62 void hovered(bool status, QBoxSet *boxset);
57 void hovered(bool status, QBoxSet *boxset);
63 void countChanged();
58 void countChanged();
64 void labelsVisibleChanged();
65
59
66 void boxsetsAdded(QList<QBoxSet *> sets);
60 void boxsetsAdded(QList<QBoxSet *> sets);
67 void boxsetsRemoved(QList<QBoxSet *> sets);
61 void boxsetsRemoved(QList<QBoxSet *> sets);
68
62
69 private:
63 private:
70 Q_DECLARE_PRIVATE(QBoxPlotSeries)
64 Q_DECLARE_PRIVATE(QBoxPlotSeries)
71 Q_DISABLE_COPY(QBoxPlotSeries)
65 Q_DISABLE_COPY(QBoxPlotSeries)
72 friend class BoxPlotChartItem;
66 friend class BoxPlotChartItem;
73 friend class QBoxPlotLegendMarkerPrivate;
67 friend class QBoxPlotLegendMarkerPrivate;
74 };
68 };
75
69
76 QTCOMMERCIALCHART_END_NAMESPACE
70 QTCOMMERCIALCHART_END_NAMESPACE
77
71
78 #endif // QBOXPLOTSERIES_H
72 #endif // QBOXPLOTSERIES_H
@@ -1,395 +1,493
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qboxset.h"
21 #include "qboxset.h"
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
25 #include <QDebug> //TODO: remove on release
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 /*!
29 /*!
30 Constructs QBoxSet with parent of \a parent
30 \class QBoxSet
31 \brief Building block for box-and-whiskers chart
32
33 QBoxSet represents one box-and-whiskers item. It takes fives values to create a graphical representation
34 of range and three medians. There's two type of methods to give the values. The first one is with constructor
35 or append type of methods (append and operator <<). In these the values have to be given in order lower extreme,
36 lower quartile, median, upper quartile and upper extre. Second method is to create an empty QBoxSet instance and
37 give the values using own methods.
38
39 \mainclass
40
41 \sa QBoxPlotSeries
42 */
43 /*!
44 \qmlclass BoxSet QBoxSet
45
46 BoxSet represents one box-and-whiskers item. It takes fives values to create a graphical representation
47 of range and three medians. There's two type of methods to give the values. The first one is with constructor
48 or append type of methods (append and operator <<). In these the values have to be given in order lower extreme,
49 lower quartile, median, upper quartile and upper extre. Second method is to create an empty BoxSet instance and
50 give the values using own methods.
51 \sa BoxPlotSeries
52 */
53
54 /*!
55 \property QBoxSet::pen
56 \brief Defines the pen used by the box-and-whiskers set.
57 */
58
59 /*!
60 \property QBoxSet::brush
61 \brief Defines the brush used by the box-and-whiskers set.
62 */
63
64 /*!
65 \property QBoxSet::color
66 The fill (brush) color of the box-and-whiskers set.
67 */
68
69 /*!
70 \property QBoxSet::borderColor
71 The line (pen) color of the box-and-whiskers set.
72 */
73
74 /*!
75 \fn void QBoxSet::clicked()
76 The signal is emitted if the user clicks with a mouse on top of box-and-whisker item.
77 */
78
79 /*!
80 \fn void QBoxSet::hovered(bool status)
81
82 The signal is emitted if mouse is hovered on top of box-and-whisker item.
83 Parameter \a status is true, if mouse entered on top of item, false if mouse left from top of item.
84 */
85
86 /*!
87 \fn void QBoxSet::penChanged()
88 This signal is emitted when the pen of the box-and-whisker item has changed.
89 \sa pen
90 */
91
92 /*!
93 \fn void QBoxSet::brushChanged()
94 This signal is emitted when the brush of the box-and-whisker item has changed.
95 \sa brush
96 */
97
98 /*!
99 \fn void QBoxSet::colorChanged(QColor)
100 This signal is emitted when the fill (brush) color of the box-and-whisker item has changed to \a color.
101 */
102
103 /*!
104 \fn void QBoxSet::valuesAdded(int index, int count)
105 This signal is emitted when new values have been added to the box-and-whisker item.
106 Parameter \a index indicates the position of the first inserted value.
107 Parameter \a count is the number of inserted values.
108 \sa append(), insert()
109 */
110
111 /*!
112 \fn void QBoxSet::valueChanged(int index)
113 This signal is emitted values the value in the box-and-whisker item has been modified.
114 Parameter \a index indicates the position of the modified value.
115 \sa at()
116 */
117
118 /*!
119 \fn void QBoxSet::borderColorChanged(QColor)
120 This signal is emitted when the line (pen) color of the box-and-whisker item has changed to \a color.
121 */
122
123 /*!
124 Constructs QBoxSet with optional \a label and parent of \a parent
31 */
125 */
32 QBoxSet::QBoxSet(const QString label, QObject *parent)
126 QBoxSet::QBoxSet(const QString label, QObject *parent)
33 : QObject(parent),
127 : QObject(parent),
34 d_ptr(new QBoxSetPrivate(label, this))
128 d_ptr(new QBoxSetPrivate(label, this))
35 {
129 {
36 }
130 }
37
131
38 QBoxSet::QBoxSet(qreal value1, qreal value2, qreal value3, qreal value4, qreal value5, const QString label, QObject *parent)
132 /*!
133 Constructs QBoxSet with given ordered values. \a le for lower extreme, \a lq for lower quartile, \a m for median,
134 \a uq for upper quartile and \a ue for upper quartile. \a label and \a parent are optional.
135 */
136 QBoxSet::QBoxSet(const qreal le, const qreal lq, const qreal m, const qreal uq, const qreal ue, const QString label = "", QObject *parent)
39 : QObject(parent),
137 : QObject(parent),
40 d_ptr(new QBoxSetPrivate(label, this))
138 d_ptr(new QBoxSetPrivate(label, this))
41 {
139 {
42 d_ptr->append(value1);
140 d_ptr->append(le);
43 d_ptr->append(value2);
141 d_ptr->append(lq);
44 d_ptr->append(value3);
142 d_ptr->append(m);
45 d_ptr->append(value4);
143 d_ptr->append(uq);
46 d_ptr->append(value5);
144 d_ptr->append(ue);
47 }
145 }
48
146
49 /*!
147 /*!
50 Destroys the boxset
148 Destroys the boxset
51 */
149 */
52 QBoxSet::~QBoxSet()
150 QBoxSet::~QBoxSet()
53 {
151 {
54 // NOTE: d_ptr destroyed by QObject
152 // NOTE: d_ptr destroyed by QObject
55 }
153 }
56
154
57 /*!
155 /*!
58 Appends new value \a value to the end of set.
156 Appends new value \a value to the end of set.
59 */
157 */
60 void QBoxSet::append(const qreal value)
158 void QBoxSet::append(const qreal value)
61 {
159 {
62 //int index = d_ptr->m_values.count();
160 //int index = d_ptr->m_values.count();
63 d_ptr->append(value);
161 d_ptr->append(value);
64
162
65 emit valuesAdded(d_ptr->m_valuesCount, 1);
163 emit valuesAdded(d_ptr->m_valuesCount, 1);
66 }
164 }
67
165
68 /*!
166 /*!
69 Appends a list of reals to set. Works like append with single real value. The \a values in list
167 Appends a list of reals to set. Works like append with single real value. The \a values in list
70 are appended to end of boxset
168 are appended to end of boxset
71 \sa append()
169 \sa append()
72 */
170 */
73 void QBoxSet::append(const QList<qreal> &values)
171 void QBoxSet::append(const QList<qreal> &values)
74 {
172 {
75 //int index = d_ptr->m_values.count();
173 //int index = d_ptr->m_values.count();
76 d_ptr->append(values);
174 d_ptr->append(values);
77 emit valuesAdded(d_ptr->m_valuesCount, values.count());
175 emit valuesAdded(d_ptr->m_valuesCount, values.count());
78 }
176 }
79
177
80 /*!
178 /*!
81 Sets new value \a value as the lower extreme for the set.
179 Sets new value \a value as the lower extreme for the set.
82 */
180 */
83 void QBoxSet::setLowerExtreme(const qreal value)
181 void QBoxSet::setLowerExtreme(const qreal value)
84 {
182 {
85 d_ptr->replace(QBoxSetPrivate::PosLowerExtreme, value);
183 d_ptr->replace(QBoxSetPrivate::PosLowerExtreme, value);
86 emit d_ptr->restructuredBox();
184 emit d_ptr->restructuredBox();
87 emit valueChanged(QBoxSetPrivate::PosLowerExtreme);
185 emit valueChanged(QBoxSetPrivate::PosLowerExtreme);
88 }
186 }
89
187
90 /*!
188 /*!
91 Returns the lower extreme value of the set.
189 Returns the lower extreme value of the set.
92 */
190 */
93 qreal QBoxSet::lowerExtreme()
191 qreal QBoxSet::lowerExtreme()
94 {
192 {
95 return d_ptr->m_values[QBoxSetPrivate::PosLowerExtreme];
193 return d_ptr->m_values[QBoxSetPrivate::PosLowerExtreme];
96 }
194 }
97
195
98 /*!
196 /*!
99 Sets new value \a value as the lower quartile for the set.
197 Sets new value \a value as the lower quartile for the set.
100 */
198 */
101 void QBoxSet::setLowerQuartile(const qreal value)
199 void QBoxSet::setLowerQuartile(const qreal value)
102 {
200 {
103 d_ptr->replace(QBoxSetPrivate::PosLowerQuartile, value);
201 d_ptr->replace(QBoxSetPrivate::PosLowerQuartile, value);
104 emit d_ptr->restructuredBox();
202 emit d_ptr->restructuredBox();
105 emit valueChanged(QBoxSetPrivate::PosLowerQuartile);
203 emit valueChanged(QBoxSetPrivate::PosLowerQuartile);
106 }
204 }
107
205
108 /*!
206 /*!
109 Returns the lower quartile value of the set.
207 Returns the lower quartile value of the set.
110 */
208 */
111 qreal QBoxSet::lowerQuartile()
209 qreal QBoxSet::lowerQuartile()
112 {
210 {
113 return d_ptr->m_values[QBoxSetPrivate::PosLowerQuartile];
211 return d_ptr->m_values[QBoxSetPrivate::PosLowerQuartile];
114 }
212 }
115
213
116 /*!
214 /*!
117 Sets new value \a value as the median for the set.
215 Sets new value \a value as the median for the set.
118 */
216 */
119 void QBoxSet::setMedian(const qreal value)
217 void QBoxSet::setMedian(const qreal value)
120 {
218 {
121 d_ptr->replace(QBoxSetPrivate::PosMedian, value);
219 d_ptr->replace(QBoxSetPrivate::PosMedian, value);
122 emit d_ptr->restructuredBox();
220 emit d_ptr->restructuredBox();
123 emit valueChanged(QBoxSetPrivate::PosMedian);
221 emit valueChanged(QBoxSetPrivate::PosMedian);
124 }
222 }
125
223
126 /*!
224 /*!
127 Returns the median value of the set.
225 Returns the median value of the set.
128 */
226 */
129 qreal QBoxSet::median()
227 qreal QBoxSet::median()
130 {
228 {
131 return d_ptr->m_values[QBoxSetPrivate::PosMedian];
229 return d_ptr->m_values[QBoxSetPrivate::PosMedian];
132 }
230 }
133
231
134 /*!
232 /*!
135 Sets new value \a value as the upper quartile for the set.
233 Sets new value \a value as the upper quartile for the set.
136 */
234 */
137 void QBoxSet::setUpperQuartile(const qreal value)
235 void QBoxSet::setUpperQuartile(const qreal value)
138 {
236 {
139 d_ptr->replace(QBoxSetPrivate::PosUpperQuartile, value);
237 d_ptr->replace(QBoxSetPrivate::PosUpperQuartile, value);
140 emit d_ptr->restructuredBox();
238 emit d_ptr->restructuredBox();
141 emit valueChanged(QBoxSetPrivate::PosUpperQuartile);
239 emit valueChanged(QBoxSetPrivate::PosUpperQuartile);
142 }
240 }
143
241
144 /*!
242 /*!
145 Returns the upper quartile value of the set.
243 Returns the upper quartile value of the set.
146 */
244 */
147 qreal QBoxSet::upperQuartile()
245 qreal QBoxSet::upperQuartile()
148 {
246 {
149 return d_ptr->m_values[QBoxSetPrivate::PosUpperQuartile];
247 return d_ptr->m_values[QBoxSetPrivate::PosUpperQuartile];
150 }
248 }
151
249
152 /*!
250 /*!
153 Sets new value \a value as the upper extreme for the set.
251 Sets new value \a value as the upper extreme for the set.
154 */
252 */
155 void QBoxSet::setUpperExtreme(const qreal value)
253 void QBoxSet::setUpperExtreme(const qreal value)
156 {
254 {
157 d_ptr->replace(QBoxSetPrivate::PosUpperExtreme, value);
255 d_ptr->replace(QBoxSetPrivate::PosUpperExtreme, value);
158 emit d_ptr->restructuredBox();
256 emit d_ptr->restructuredBox();
159 emit valueChanged(QBoxSetPrivate::PosUpperExtreme);
257 emit valueChanged(QBoxSetPrivate::PosUpperExtreme);
160 }
258 }
161
259
162 /*!
260 /*!
163 Returns the upper extreme value of the set.
261 Returns the upper extreme value of the set.
164 */
262 */
165 qreal QBoxSet::upperExtreme()
263 qreal QBoxSet::upperExtreme()
166 {
264 {
167 return d_ptr->m_values[QBoxSetPrivate::PosUpperExtreme];
265 return d_ptr->m_values[QBoxSetPrivate::PosUpperExtreme];
168 }
266 }
169
267
170 /*!
268 /*!
171 Sets new \a label for set.
269 Sets new \a label for set.
172 */
270 */
173 void QBoxSet::setLabel(const QString label)
271 void QBoxSet::setLabel(const QString label)
174 {
272 {
175 d_ptr->m_label = label;
273 d_ptr->m_label = label;
176 }
274 }
177
275
178 /*!
276 /*!
179 Returns label of the set.
277 Returns label of the set.
180 */
278 */
181 QString QBoxSet::label() const
279 QString QBoxSet::label() const
182 {
280 {
183 return d_ptr->m_label;
281 return d_ptr->m_label;
184 }
282 }
185
283
186 /*!
284 /*!
187 Convenience operator. Same as append, with real \a value.
285 Convenience operator. Same as append, with real \a value.
188 \sa append()
286 \sa append()
189 */
287 */
190 QBoxSet &QBoxSet::operator << (const qreal &value)
288 QBoxSet &QBoxSet::operator << (const qreal &value)
191 {
289 {
192 append(value);
290 append(value);
193 return *this;
291 return *this;
194 }
292 }
195
293
196 /*!
294 /*!
197 Inserts new \a value on the \a index position.
295 Inserts new \a value on the \a index position.
198 The value that is currently at this postion is moved to postion index + 1
296 The value that is currently at this postion is moved to postion index + 1
199 */
297 */
200 void QBoxSet::insert(const int index, const qreal value)
298 void QBoxSet::insert(const int index, const qreal value)
201 {
299 {
202 d_ptr->insert(index, value);
300 d_ptr->insert(index, value);
203 emit valuesAdded(index, 1);
301 emit valuesAdded(index, 1);
204 }
302 }
205
303
206 /*!
304 /*!
207 Sets a new value \a value to set, indexed by \a index
305 Sets a new value \a value to set, indexed by \a index
208 */
306 */
209 void QBoxSet::replace(const int index, const qreal value)
307 void QBoxSet::replace(const int index, const qreal value)
210 {
308 {
211 if (index >= 0 && index < 5) {
309 if (index >= 0 && index < 5) {
212 d_ptr->replace(index, value);
310 d_ptr->replace(index, value);
213 emit valueChanged(index);
311 emit valueChanged(index);
214 }
312 }
215 }
313 }
216
314
217
315
218 /*!
316 /*!
219 Returns value of set indexed by \a index.
317 Returns value of set indexed by \a index.
220 If the index is out of bounds 0.0 is returned.
318 If the index is out of bounds 0.0 is returned.
221 */
319 */
222 qreal QBoxSet::at(const int index) const
320 qreal QBoxSet::at(const int index) const
223 {
321 {
224 if (index < 0 || index >= 5)
322 if (index < 0 || index >= 5)
225 return 0;
323 return 0;
226 return d_ptr->m_values[index];
324 return d_ptr->m_values[index];
227 }
325 }
228
326
229 /*!
327 /*!
230 Returns value of set indexed by \a index.
328 Returns value of set indexed by \a index.
231 If the index is out of bounds 0.0 is returned.
329 If the index is out of bounds 0.0 is returned.
232 */
330 */
233 qreal QBoxSet::operator [](const int index) const
331 qreal QBoxSet::operator [](const int index) const
234 {
332 {
235 return at(index);
333 return at(index);
236 }
334 }
237
335
238 /*!
336 /*!
239 Returns count of values in set.
337 Returns count of values in set.
240 */
338 */
241 int QBoxSet::count() const
339 int QBoxSet::count() const
242 {
340 {
243 return d_ptr->m_valuesCount;
341 return d_ptr->m_valuesCount;
244 }
342 }
245
343
246 /*!
344 /*!
247 Sets pen for set. Boxes of this set are drawn using \a pen
345 Sets pen for set. Boxes of this set are drawn using \a pen
248 */
346 */
249 void QBoxSet::setPen(const QPen &pen)
347 void QBoxSet::setPen(const QPen &pen)
250 {
348 {
251 if (d_ptr->m_pen != pen) {
349 if (d_ptr->m_pen != pen) {
252 d_ptr->m_pen = pen;
350 d_ptr->m_pen = pen;
253 emit d_ptr->updatedBox();
351 emit d_ptr->updatedBox();
254 emit penChanged();
352 emit penChanged();
255 }
353 }
256 }
354 }
257
355
258 /*!
356 /*!
259 Returns pen of the set.
357 Returns pen of the set.
260 */
358 */
261 QPen QBoxSet::pen() const
359 QPen QBoxSet::pen() const
262 {
360 {
263 return d_ptr->m_pen;
361 return d_ptr->m_pen;
264 }
362 }
265
363
266 /*!
364 /*!
267 Sets brush for the set. Boxes of this set are drawn using \a brush
365 Sets brush for the set. Boxes of this set are drawn using \a brush
268 */
366 */
269 void QBoxSet::setBrush(const QBrush &brush)
367 void QBoxSet::setBrush(const QBrush &brush)
270 {
368 {
271 if (d_ptr->m_brush != brush) {
369 if (d_ptr->m_brush != brush) {
272 d_ptr->m_brush = brush;
370 d_ptr->m_brush = brush;
273 emit d_ptr->updatedBox();
371 emit d_ptr->updatedBox();
274 emit brushChanged();
372 emit brushChanged();
275 }
373 }
276 }
374 }
277
375
278 /*!
376 /*!
279 Returns brush of the set.
377 Returns brush of the set.
280 */
378 */
281 QBrush QBoxSet::brush() const
379 QBrush QBoxSet::brush() const
282 {
380 {
283 return d_ptr->m_brush;
381 return d_ptr->m_brush;
284 }
382 }
285
383
286 /*!
384 /*!
287 Returns the color of the brush of boxset.
385 Returns the color of the brush of boxset.
288 */
386 */
289 QColor QBoxSet::color()
387 QColor QBoxSet::color()
290 {
388 {
291 return brush().color();
389 return brush().color();
292 }
390 }
293
391
294 /*!
392 /*!
295 Sets the \a color of brush for this boxset
393 Sets the \a color of brush for this boxset
296 */
394 */
297 void QBoxSet::setColor(QColor color)
395 void QBoxSet::setColor(QColor color)
298 {
396 {
299 QBrush b = brush();
397 QBrush b = brush();
300 if ((b.color() != color) || (b.style() == Qt::NoBrush)) {
398 if ((b.color() != color) || (b.style() == Qt::NoBrush)) {
301 b.setColor(color);
399 b.setColor(color);
302 if (b.style() == Qt::NoBrush) {
400 if (b.style() == Qt::NoBrush) {
303 // Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush)
401 // Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush)
304 // This prevents theme to override color defined in QML side:
402 // This prevents theme to override color defined in QML side:
305 // BoxSet { label: "Bob"; color:"red"; values: [1,2,3] }
403 // BoxSet { label: "Bob"; color:"red"; values: [1,2,3] }
306 // The color must be obeyed, since user wanted it.
404 // The color must be obeyed, since user wanted it.
307 b.setStyle(Qt::SolidPattern);
405 b.setStyle(Qt::SolidPattern);
308 }
406 }
309 setBrush(b);
407 setBrush(b);
310 emit colorChanged(color);
408 emit colorChanged(color);
311 }
409 }
312 }
410 }
313
411
314 /*!
412 /*!
315 Returns the color of pen of this boxset
413 Returns the color of pen of this boxset
316 */
414 */
317 QColor QBoxSet::borderColor()
415 QColor QBoxSet::borderColor()
318 {
416 {
319 return pen().color();
417 return pen().color();
320 }
418 }
321
419
322 /*!
420 /*!
323 Sets the color of pen for this boxset
421 Sets the color of pen for this boxset
324 */
422 */
325 void QBoxSet::setBorderColor(QColor color)
423 void QBoxSet::setBorderColor(QColor color)
326 {
424 {
327 QPen p = pen();
425 QPen p = pen();
328 if (p.color() != color) {
426 if (p.color() != color) {
329 p.setColor(color);
427 p.setColor(color);
330 setPen(p);
428 setPen(p);
331 emit borderColorChanged(color);
429 emit borderColorChanged(color);
332 }
430 }
333 }
431 }
334
432
335 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
433 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
336
434
337 QBoxSetPrivate::QBoxSetPrivate(const QString label, QBoxSet *parent) : QObject(parent),
435 QBoxSetPrivate::QBoxSetPrivate(const QString label, QBoxSet *parent) : QObject(parent),
338 q_ptr(parent),
436 q_ptr(parent),
339 m_label(label),
437 m_label(label),
340 m_valuesCount(5),
438 m_valuesCount(5),
341 m_appendCount(0),
439 m_appendCount(0),
342 m_pen(QPen(Qt::NoPen)),
440 m_pen(QPen(Qt::NoPen)),
343 m_brush(QBrush(Qt::NoBrush))
441 m_brush(QBrush(Qt::NoBrush))
344 {
442 {
345 m_values = new qreal[m_valuesCount];
443 m_values = new qreal[m_valuesCount];
346 }
444 }
347
445
348 QBoxSetPrivate::~QBoxSetPrivate()
446 QBoxSetPrivate::~QBoxSetPrivate()
349 {
447 {
350 }
448 }
351
449
352 void QBoxSetPrivate::append(qreal value)
450 void QBoxSetPrivate::append(qreal value)
353 {
451 {
354 if (isValidValue(value) && m_appendCount < m_valuesCount) {
452 if (isValidValue(value) && m_appendCount < m_valuesCount) {
355 m_values[m_appendCount++] = value;
453 m_values[m_appendCount++] = value;
356 emit restructuredBox();
454 emit restructuredBox();
357 }
455 }
358 }
456 }
359
457
360 void QBoxSetPrivate::append(QList<qreal> values)
458 void QBoxSetPrivate::append(QList<qreal> values)
361 {
459 {
362 for (int i = 0; i < values.count(); i++) {
460 for (int i = 0; i < values.count(); i++) {
363 if (isValidValue(values.at(i)) && m_appendCount < m_valuesCount)
461 if (isValidValue(values.at(i)) && m_appendCount < m_valuesCount)
364 m_values[m_appendCount++] = values.at(i);
462 m_values[m_appendCount++] = values.at(i);
365 }
463 }
366 emit restructuredBox();
464 emit restructuredBox();
367 }
465 }
368
466
369 void QBoxSetPrivate::insert(const int index, const qreal value)
467 void QBoxSetPrivate::insert(const int index, const qreal value)
370 {
468 {
371 if (isValidValue(value)) {
469 if (isValidValue(value)) {
372 for (int i = 4; i > index; i--)
470 for (int i = 4; i > index; i--)
373 m_values[i] = m_values[i - 1];
471 m_values[i] = m_values[i - 1];
374 m_values[index] = value;
472 m_values[index] = value;
375 emit restructuredBox();
473 emit restructuredBox();
376 }
474 }
377 }
475 }
378
476
379 void QBoxSetPrivate::replace(const int index, const qreal value)
477 void QBoxSetPrivate::replace(const int index, const qreal value)
380 {
478 {
381 m_values[index] = value;
479 m_values[index] = value;
382 emit updatedLayout();
480 emit updatedLayout();
383 }
481 }
384
482
385 qreal QBoxSetPrivate::value(const int index)
483 qreal QBoxSetPrivate::value(const int index)
386 {
484 {
387 if (index < 0 || index >= m_valuesCount)
485 if (index < 0 || index >= m_valuesCount)
388 return 0;
486 return 0;
389 return m_values[index];
487 return m_values[index];
390 }
488 }
391
489
392 #include "moc_qboxset.cpp"
490 #include "moc_qboxset.cpp"
393 #include "moc_qboxset_p.cpp"
491 #include "moc_qboxset_p.cpp"
394
492
395 QTCOMMERCIALCHART_END_NAMESPACE
493 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,107 +1,105
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QBOXSET_H
21 #ifndef QBOXSET_H
22 #define QBOXSET_H
22 #define QBOXSET_H
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <QPen>
25 #include <QPen>
26 #include <QBrush>
26 #include <QBrush>
27 #include <QFont>
27 #include <QFont>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 class QBoxSetPrivate;
30 class QBoxSetPrivate;
31
31
32 class QTCOMMERCIALCHART_EXPORT QBoxSet : public QObject
32 class QTCOMMERCIALCHART_EXPORT QBoxSet : public QObject
33 {
33 {
34 Q_OBJECT
34 Q_OBJECT
35 Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged)
35 Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged)
36 Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged)
36 Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged)
37 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
37 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
38 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
38 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
39
39
40 public:
40 public:
41 explicit QBoxSet(const QString label = "", QObject *parent = 0);
41 explicit QBoxSet(const QString label = "", QObject *parent = 0);
42 explicit QBoxSet(const qreal value1, const qreal value2, const qreal value3, const qreal value4, const qreal value5, const QString label = "", QObject *parent = 0);
42 explicit QBoxSet(const qreal le, const qreal lq, const qreal m, const qreal uq, const qreal ue, const QString label = "", QObject *parent = 0);
43 virtual ~QBoxSet();
43 virtual ~QBoxSet();
44
44
45 void append(const qreal value);
45 void append(const qreal value);
46 void append(const QList<qreal> &values);
46 void append(const QList<qreal> &values);
47
47
48 void setLowerExtreme(const qreal value);
48 void setLowerExtreme(const qreal value);
49 qreal lowerExtreme();
49 qreal lowerExtreme();
50 void setLowerQuartile(const qreal value);
50 void setLowerQuartile(const qreal value);
51 qreal lowerQuartile();
51 qreal lowerQuartile();
52 void setMedian(const qreal value);
52 void setMedian(const qreal value);
53 qreal median();
53 qreal median();
54 void setUpperQuartile(const qreal value);
54 void setUpperQuartile(const qreal value);
55 qreal upperQuartile();
55 qreal upperQuartile();
56 void setUpperExtreme(const qreal value);
56 void setUpperExtreme(const qreal value);
57 qreal upperExtreme();
57 qreal upperExtreme();
58
58
59 void setLabel(const QString label);
59 void setLabel(const QString label);
60 QString label() const;
60 QString label() const;
61
61
62 QBoxSet &operator << (const qreal &value);
62 QBoxSet &operator << (const qreal &value);
63
63
64 void insert(const int index, const qreal value);
64 void insert(const int index, const qreal value);
65 void remove(const int index, const int count = 1);
66 void replace(const int index, const qreal value);
65 void replace(const int index, const qreal value);
67 qreal at(const int index) const;
66 qreal at(const int index) const;
68 qreal operator [](const int index) const;
67 qreal operator [](const int index) const;
69 int count() const;
68 int count() const;
70
69
71 void setPen(const QPen &pen);
70 void setPen(const QPen &pen);
72 QPen pen() const;
71 QPen pen() const;
73
72
74 void setBrush(const QBrush &brush);
73 void setBrush(const QBrush &brush);
75 QBrush brush() const;
74 QBrush brush() const;
76
75
77 QColor color();
76 QColor color();
78 void setColor(QColor color);
77 void setColor(QColor color);
79
78
80 QColor borderColor();
79 QColor borderColor();
81 void setBorderColor(QColor color);
80 void setBorderColor(QColor color);
82
81
83
82
84 Q_SIGNALS:
83 Q_SIGNALS:
85 void clicked(int index);
84 void clicked();
86 void hovered(bool status);
85 void hovered(bool status);
87 void penChanged();
86 void penChanged();
88 void brushChanged();
87 void brushChanged();
89 void colorChanged(QColor color);
88 void colorChanged(QColor color);
90 void borderColorChanged(QColor color);
89 void borderColorChanged(QColor color);
91
90
92 void valuesAdded(int index, int count);
91 void valuesAdded(int index, int count);
93 void valuesRemoved(int index, int count);
94 void valueChanged(int index);
92 void valueChanged(int index);
95
93
96 private:
94 private:
97 QScopedPointer<QBoxSetPrivate> d_ptr;
95 QScopedPointer<QBoxSetPrivate> d_ptr;
98 Q_DISABLE_COPY(QBoxSet)
96 Q_DISABLE_COPY(QBoxSet)
99 friend class BarLegendMarker;
97 friend class BarLegendMarker;
100 friend class BarChartItem;
98 friend class BarChartItem;
101 friend class BoxPlotChartItem;
99 friend class BoxPlotChartItem;
102 friend class QBoxPlotSeriesPrivate;
100 friend class QBoxPlotSeriesPrivate;
103 };
101 };
104
102
105 QTCOMMERCIALCHART_END_NAMESPACE
103 QTCOMMERCIALCHART_END_NAMESPACE
106
104
107 #endif // QBOXSET_H
105 #endif // QBOXSET_H
@@ -1,249 +1,249
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qvboxplotmodelmapper.h"
21 #include "qvboxplotmodelmapper.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 /*!
25 /*!
26 \class QVBoxPlotModelMapper
26 \class QVBoxPlotModelMapper
27 \brief Vertical model mapper for bar series
27 \brief Vertical model mapper for bar series
28 \mainclass
28 \mainclass
29
29
30 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
30 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
31 Vertical model mapper is used to create a connection between QAbstractBarSeries and QAbstractItemModel derived model object.
31 Vertical model mapper is used to create a connection between QBoxPlotSeries and QAbstractItemModel derived model object.
32 Model mapper maintains equal size of all the BarSets.
32 Model mapper maintains equal size of all the BarSets.
33 Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series.
34 Note: used model has to support adding/removing rows/columns and modifying the data of the cells.
33 Note: used model has to support adding/removing rows/columns and modifying the data of the cells.
35 */
34 */
36 /*!
35 /*!
37 \qmlclass VBarModelMapper
36 \qmlclass VBoxPlotModelMapper
38 \mainclass
37 \mainclass
39
38
40 VBarModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source
39 VBoxPlotModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source
41 for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data.
40 for any box-and-whiskers series. It is possible to use both QAbstractItemModel and box-and-whiskers series data API to
42 VBarModelMapper keeps the series and the model in sync.
41 manipulate data.
42 VBoxPlotModelMapper keeps the series and the model in sync.
43
43
44 The following QML example would create a bar series with three bar sets (assuming the
44 The following QML example would create a box-and-whiskers series with three box sets (assuming the
45 model has at least four columns). Each bar set would contain data starting from row 1. The name of a set would be
45 model has at least four columns). Each box set would contain data starting from row 1. The name of a set would be
46 defined by the horizontal header (of the column).
46 defined by the horizontal header (of the column).
47 \code
47 \code
48 BarSeries {
48 BarSeries {
49 VBarModelMapper {
49 VBarModelMapper {
50 model: myCustomModel // QAbstractItemModel derived implementation
50 model: myCustomModel // QAbstractItemModel derived implementation
51 firstBarSetColumn: 1
51 firstBarSetColumn: 1
52 lastBarSetColumn: 3
52 lastBarSetColumn: 3
53 firstRow: 1
53 firstRow: 1
54 }
54 }
55 }
55 }
56 \endcode
56 \endcode
57 */
57 */
58
58
59 /*!
59 /*!
60 \property QVBoxPlotModelMapper::series
60 \property QVBoxPlotModelMapper::series
61 \brief Defines the QPieSeries object that is used by the mapper.
61 \brief Defines the QBoxPlotSeries object that is used by the mapper.
62
62
63 All the data in the series is discarded when it is set to the mapper.
63 All the data in the series is discarded when it is set to the mapper.
64 When new series is specified the old series is disconnected (it preserves its data)
64 When new series is specified the old series is disconnected (it preserves its data)
65 */
65 */
66 /*!
66 /*!
67 \qmlproperty AbstractBarSeries VBarModelMapper::series
67 \qmlproperty AbstractBarSeries VBarModelMapper::series
68 Defines the AbstractBarSeries based object that is used by the mapper. All the data in the series is discarded when it is
68 Defines the AbstractBarSeries based object that is used by the mapper. All the data in the series is discarded when it is
69 set to the mapper. When new series is specified the old series is disconnected (it preserves its data).
69 set to the mapper. When new series is specified the old series is disconnected (it preserves its data).
70 */
70 */
71
71
72 /*!
72 /*!
73 \property QVBoxPlotModelMapper::model
73 \property QVBoxPlotModelMapper::model
74 \brief Defines the model that is used by the mapper.
74 \brief Defines the model that is used by the mapper.
75 */
75 */
76 /*!
76 /*!
77 \qmlproperty SomeModel VBarModelMapper::model
77 \qmlproperty SomeModel VBarModelMapper::model
78 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
78 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
79 QML as shown in \l {QML Custom Model} demo application. Note: the model has to support adding/removing rows/columns
79 QML as shown in \l {QML Custom Model} demo application. Note: the model has to support adding/removing rows/columns
80 and modifying the data of the cells.
80 and modifying the data of the cells.
81 */
81 */
82
82
83 /*!
83 /*!
84 \property QVBoxPlotModelMapper::firstBarSetColumn
84 \property QVBoxPlotModelMapper::firstBoxSetColumn
85 \brief Defines which column of the model is used as the data source for the first bar set
85 \brief Defines which column of the model is used as the data source for the first box-and-whiskers set
86 Default value is: -1 (invalid mapping)
86 Default value is: -1 (invalid mapping)
87 */
87 */
88 /*!
88 /*!
89 \qmlproperty int VBarModelMapper::firstBarSetColumn
89 \qmlproperty int VBarModelMapper::firstBoxSetColumn
90 Defines which column of the model is used as the data source for the first bar set. Default value
90 Defines which column of the model is used as the data source for the first box-and-whiskers set. Default value
91 is: -1 (invalid mapping).
91 is: -1 (invalid mapping).
92 */
92 */
93
93
94 /*!
94 /*!
95 \property QVBoxPlotModelMapper::lastBarSetColumn
95 \property QVBoxPlotModelMapper::lastBoxSetColumn
96 \brief Defines which column of the model is used as the data source for the last bar set
96 \brief Defines which column of the model is used as the data source for the last box-and-whiskers set
97 Default value is: -1 (invalid mapping)
97 Default value is: -1 (invalid mapping)
98 */
98 */
99 /*!
99 /*!
100 \qmlproperty int VBarModelMapper::lastBarSetColumn
100 \qmlproperty int VBarModelMapper::lastBoxSetColumn
101 Defines which column of the model is used as the data source for the last bar set. Default
101 Defines which column of the model is used as the data source for the last box-and-whiskers set. Default
102 value is: -1 (invalid mapping).
102 value is: -1 (invalid mapping).
103 */
103 */
104
104
105 /*!
105 /*!
106 \property QVBoxPlotModelMapper::firstRow
106 \property QVBoxPlotModelMapper::firstRow
107 \brief Defines which row of the model contains the first values of the QBarSets in the series.
107 \brief Defines which row of the model contains the first values of the QBoxSets in the series.
108 Minimal and default value is: 0
108 Minimal and default value is: 0
109 */
109 */
110 /*!
110 /*!
111 \qmlproperty int VBarModelMapper::firstRow
111 \qmlproperty int VBoxPlotModelMapper::firstRow
112 Defines which row of the model contains the first values of the QBarSets in the series.
112 Defines which row of the model contains the first values of the QBoxSets in the series.
113 The default value is 0.
113 The default value is 0.
114 */
114 */
115
115
116 /*!
116 /*!
117 \property QVBoxPlotModelMapper::rowCount
117 \property QVBoxPlotModelMapper::rowCount
118 \brief Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries
118 \brief Defines the number of rows of the model that are mapped as the data for QBoxPlotSeries
119 Minimal and default value is: -1 (count limited by the number of rows in the model)
119 Minimal and default value is: -1 (count limited by the number of rows in the model)
120 */
120 */
121 /*!
121 /*!
122 \qmlproperty int VBarModelMapper::rowCount
122 \qmlproperty int VBoxModelMapper::rowCount
123 Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries. The default value is
123 Defines the number of rows of the model that are mapped as the data for QBoxPlotSeries. The default value is
124 -1 (count limited by the number of rows in the model)
124 -1 (count limited by the number of rows in the model)
125 */
125 */
126
126
127 /*!
127 /*!
128 \fn void QVBoxPlotModelMapper::seriesReplaced()
128 \fn void QVBoxPlotModelMapper::seriesReplaced()
129
129
130 Emitted when the series to which mapper is connected to has changed.
130 Emitted when the series to which mapper is connected to has changed.
131 */
131 */
132
132
133 /*!
133 /*!
134 \fn void QVBoxPlotModelMapper::modelReplaced()
134 \fn void QVBoxPlotModelMapper::modelReplaced()
135
135
136 Emitted when the model to which mapper is connected to has changed.
136 Emitted when the model to which mapper is connected to has changed.
137 */
137 */
138
138
139 /*!
139 /*!
140 \fn void QVBoxPlotModelMapper::firstBarSetColumnChanged()
140 \fn void QVBoxPlotModelMapper::firstBoxSetColumnChanged()
141 Emitted when the firstBarSetColumn has changed.
141 Emitted when the firstBoxSetColumn has changed.
142 */
142 */
143
143
144 /*!
144 /*!
145 \fn void QVBoxPlotModelMapper::lastBarSetColumnChanged()
145 \fn void QVBoxPlotModelMapper::lastBoxSetColumnChanged()
146 Emitted when the lastBarSetColumn has changed.
146 Emitted when the lastBoxSetColumn has changed.
147 */
147 */
148
148
149 /*!
149 /*!
150 \fn void QVBoxPlotModelMapper::firstRowChanged()
150 \fn void QVBoxPlotModelMapper::firstRowChanged()
151 Emitted when the firstRow has changed.
151 Emitted when the firstRow has changed.
152 */
152 */
153
153
154 /*!
154 /*!
155 \fn void QVBoxPlotModelMapper::rowCountChanged()
155 \fn void QVBoxPlotModelMapper::rowCountChanged()
156 Emitted when the rowCount has changed.
156 Emitted when the rowCount has changed.
157 */
157 */
158
158
159 /*!
159 /*!
160 Constructs a mapper object which is a child of \a parent.
160 Constructs a mapper object which is a child of \a parent.
161 */
161 */
162 QVBoxPlotModelMapper::QVBoxPlotModelMapper(QObject *parent) :
162 QVBoxPlotModelMapper::QVBoxPlotModelMapper(QObject *parent) :
163 QBoxPlotModelMapper(parent)
163 QBoxPlotModelMapper(parent)
164 {
164 {
165 QBoxPlotModelMapper::setOrientation(Qt::Vertical);
165 QBoxPlotModelMapper::setOrientation(Qt::Vertical);
166 }
166 }
167
167
168 QAbstractItemModel *QVBoxPlotModelMapper::model() const
168 QAbstractItemModel *QVBoxPlotModelMapper::model() const
169 {
169 {
170 return QBoxPlotModelMapper::model();
170 return QBoxPlotModelMapper::model();
171 }
171 }
172
172
173 void QVBoxPlotModelMapper::setModel(QAbstractItemModel *model)
173 void QVBoxPlotModelMapper::setModel(QAbstractItemModel *model)
174 {
174 {
175 if (model != QBoxPlotModelMapper::model()) {
175 if (model != QBoxPlotModelMapper::model()) {
176 QBoxPlotModelMapper::setModel(model);
176 QBoxPlotModelMapper::setModel(model);
177 emit modelReplaced();
177 emit modelReplaced();
178 }
178 }
179 }
179 }
180
180
181 QBoxPlotSeries *QVBoxPlotModelMapper::series() const
181 QBoxPlotSeries *QVBoxPlotModelMapper::series() const
182 {
182 {
183 return QBoxPlotModelMapper::series();
183 return QBoxPlotModelMapper::series();
184 }
184 }
185
185
186 void QVBoxPlotModelMapper::setSeries(QBoxPlotSeries *series)
186 void QVBoxPlotModelMapper::setSeries(QBoxPlotSeries *series)
187 {
187 {
188 if (series != QBoxPlotModelMapper::series()) {
188 if (series != QBoxPlotModelMapper::series()) {
189 QBoxPlotModelMapper::setSeries(series);
189 QBoxPlotModelMapper::setSeries(series);
190 emit seriesReplaced();
190 emit seriesReplaced();
191 }
191 }
192 }
192 }
193
193
194 int QVBoxPlotModelMapper::firstBoxSetColumn() const
194 int QVBoxPlotModelMapper::firstBoxSetColumn() const
195 {
195 {
196 return QBoxPlotModelMapper::firstBoxSetSection();
196 return QBoxPlotModelMapper::firstBoxSetSection();
197 }
197 }
198
198
199 void QVBoxPlotModelMapper::setFirstBoxSetColumn(int firstBoxSetColumn)
199 void QVBoxPlotModelMapper::setFirstBoxSetColumn(int firstBoxSetColumn)
200 {
200 {
201 if (firstBoxSetColumn != firstBoxSetSection()) {
201 if (firstBoxSetColumn != firstBoxSetSection()) {
202 QBoxPlotModelMapper::setFirstBoxSetSection(firstBoxSetColumn);
202 QBoxPlotModelMapper::setFirstBoxSetSection(firstBoxSetColumn);
203 emit firstBoxSetColumnChanged();
203 emit firstBoxSetColumnChanged();
204 }
204 }
205 }
205 }
206
206
207 int QVBoxPlotModelMapper::lastBoxSetColumn() const
207 int QVBoxPlotModelMapper::lastBoxSetColumn() const
208 {
208 {
209 return QBoxPlotModelMapper::lastBoxSetSection();
209 return QBoxPlotModelMapper::lastBoxSetSection();
210 }
210 }
211
211
212 void QVBoxPlotModelMapper::setLastBoxSetColumn(int lastBoxSetColumn)
212 void QVBoxPlotModelMapper::setLastBoxSetColumn(int lastBoxSetColumn)
213 {
213 {
214 if (lastBoxSetColumn != lastBoxSetSection()) {
214 if (lastBoxSetColumn != lastBoxSetSection()) {
215 QBoxPlotModelMapper::setLastBoxSetSection(lastBoxSetColumn);
215 QBoxPlotModelMapper::setLastBoxSetSection(lastBoxSetColumn);
216 emit lastBoxSetColumnChanged();
216 emit lastBoxSetColumnChanged();
217 }
217 }
218 }
218 }
219
219
220 int QVBoxPlotModelMapper::firstRow() const
220 int QVBoxPlotModelMapper::firstRow() const
221 {
221 {
222 return QBoxPlotModelMapper::first();
222 return QBoxPlotModelMapper::first();
223 }
223 }
224
224
225 void QVBoxPlotModelMapper::setFirstRow(int firstRow)
225 void QVBoxPlotModelMapper::setFirstRow(int firstRow)
226 {
226 {
227 if (firstRow != first()) {
227 if (firstRow != first()) {
228 QBoxPlotModelMapper::setFirst(firstRow);
228 QBoxPlotModelMapper::setFirst(firstRow);
229 emit firstRowChanged();
229 emit firstRowChanged();
230 }
230 }
231 }
231 }
232
232
233 int QVBoxPlotModelMapper::rowCount() const
233 int QVBoxPlotModelMapper::rowCount() const
234 {
234 {
235 return QBoxPlotModelMapper::count();
235 return QBoxPlotModelMapper::count();
236 }
236 }
237
237
238 void QVBoxPlotModelMapper::setRowCount(int rowCount)
238 void QVBoxPlotModelMapper::setRowCount(int rowCount)
239 {
239 {
240 if (rowCount != count()) {
240 if (rowCount != count()) {
241 QBoxPlotModelMapper::setCount(rowCount);
241 QBoxPlotModelMapper::setCount(rowCount);
242 emit rowCountChanged();
242 emit rowCountChanged();
243 }
243 }
244 }
244 }
245
245
246 #include "moc_qvboxplotmodelmapper.cpp"
246 #include "moc_qvboxplotmodelmapper.cpp"
247
247
248 QTCOMMERCIALCHART_END_NAMESPACE
248 QTCOMMERCIALCHART_END_NAMESPACE
249
249
@@ -1,292 +1,293
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qlegendmarker.h"
21 #include "qlegendmarker.h"
22 #include "qlegendmarker_p.h"
22 #include "qlegendmarker_p.h"
23 #include "legendmarkeritem_p.h"
23 #include "legendmarkeritem_p.h"
24 #include "qlegend.h"
24 #include "qlegend.h"
25 #include "qlegend_p.h"
25 #include "qlegend_p.h"
26 #include "legendlayout_p.h"
26 #include "legendlayout_p.h"
27 #include <QFontMetrics>
27 #include <QFontMetrics>
28 #include <QGraphicsSceneEvent>
28 #include <QGraphicsSceneEvent>
29 #include <QAbstractSeries>
29 #include <QAbstractSeries>
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 /*!
33 /*!
34 \class QLegendMarker
34 \class QLegendMarker
35 \brief LegendMarker object
35 \brief LegendMarker object
36 \mainclass
36 \mainclass
37
37
38 QLegendMarker is abstract object that can be used to access markers inside QLegend. Legend marker consists of two
38 QLegendMarker is abstract object that can be used to access markers inside QLegend. Legend marker consists of two
39 items: The colored box, which reflects the color of series and label, which is the name of series (or label of slice/barset
39 items: The colored box, which reflects the color of series and label, which is the name of series (or label of slice/barset
40 in case of pie or bar series)
40 in case of pie or bar series)
41 The QLegendMarker is always related to one series.
41 The QLegendMarker is always related to one series.
42
42
43 \image examples_percentbarchart_legend.png
43 \image examples_percentbarchart_legend.png
44
44
45 \sa QLegend
45 \sa QLegend
46 */
46 */
47 /*!
47 /*!
48 \enum QLegendMarker::LegendMarkerType
48 \enum QLegendMarker::LegendMarkerType
49
49
50 The type of the legendmarker object.
50 The type of the legendmarker object.
51
51
52 \value LegendMarkerTypeArea
52 \value LegendMarkerTypeArea
53 \value LegendMarkerTypeBar
53 \value LegendMarkerTypeBar
54 \value LegendMarkerTypePie
54 \value LegendMarkerTypePie
55 \value LegendMarkerTypeXY
55 \value LegendMarkerTypeXY
56 \value LegendMarkerTypeBoxPlot
56 */
57 */
57
58
58 /*!
59 /*!
59 \fn virtual LegendMarkerType QLegendMarker::type() = 0;
60 \fn virtual LegendMarkerType QLegendMarker::type() = 0;
60 Returns the type of legendmarker. Type depends of the related series. LegendMarkerTypeXY is used for all QXYSeries derived
61 Returns the type of legendmarker. Type depends of the related series. LegendMarkerTypeXY is used for all QXYSeries derived
61 classes.
62 classes.
62 */
63 */
63
64
64 /*!
65 /*!
65 \fn virtual QAbstractSeries* QLegendMarker::series() = 0;
66 \fn virtual QAbstractSeries* QLegendMarker::series() = 0;
66 Returns pointer to series, which is related to this marker. Marker is always related to some series.
67 Returns pointer to series, which is related to this marker. Marker is always related to some series.
67 */
68 */
68
69
69 /*!
70 /*!
70 \fn void QLegendMarker::clicked();
71 \fn void QLegendMarker::clicked();
71 This signal is emitted, when marker is clicked with mouse.
72 This signal is emitted, when marker is clicked with mouse.
72 */
73 */
73
74
74 /*!
75 /*!
75 \fn void QLegendMarker::hovered(bool status);
76 \fn void QLegendMarker::hovered(bool status);
76 This signal is emitted, when mouse is hovered over marker. \a status is true, when mouse enters the marker
77 This signal is emitted, when mouse is hovered over marker. \a status is true, when mouse enters the marker
77 and false when it leaves the marker.
78 and false when it leaves the marker.
78 */
79 */
79
80
80 /*!
81 /*!
81 \fn void QLegendMarker::labelChanged()
82 \fn void QLegendMarker::labelChanged()
82 This signal is emitted when the label of the legend marker has changed.
83 This signal is emitted when the label of the legend marker has changed.
83 */
84 */
84
85
85 /*!
86 /*!
86 \fn void QLegendMarker::labelBrushChanged()
87 \fn void QLegendMarker::labelBrushChanged()
87 This signal is emitted when the label brush of the legend marker has changed.
88 This signal is emitted when the label brush of the legend marker has changed.
88 */
89 */
89
90
90 /*!
91 /*!
91 \fn void QLegendMarker::fontChanged()
92 \fn void QLegendMarker::fontChanged()
92 This signal is emitted when the (label) font of the legend marker has changed.
93 This signal is emitted when the (label) font of the legend marker has changed.
93 */
94 */
94
95
95 /*!
96 /*!
96 \fn void QLegendMarker::penChanged()
97 \fn void QLegendMarker::penChanged()
97 This signal is emitted when the pen of the legend marker has changed.
98 This signal is emitted when the pen of the legend marker has changed.
98 */
99 */
99
100
100 /*!
101 /*!
101 \fn void QLegendMarker::brushChanged()
102 \fn void QLegendMarker::brushChanged()
102 This signal is emitted when the brush of the legend marker has changed.
103 This signal is emitted when the brush of the legend marker has changed.
103 */
104 */
104
105
105 /*!
106 /*!
106 \fn void QLegendMarker::visibleChanged()
107 \fn void QLegendMarker::visibleChanged()
107 This signal is emitted when the visibility of the legend marker has changed.
108 This signal is emitted when the visibility of the legend marker has changed.
108 */
109 */
109
110
110 /*!
111 /*!
111 \property QLegendMarker::label
112 \property QLegendMarker::label
112 Label of the marker. This is the text that is shown in legend.
113 Label of the marker. This is the text that is shown in legend.
113 */
114 */
114
115
115 /*!
116 /*!
116 \property QLegendMarker::labelBrush
117 \property QLegendMarker::labelBrush
117 Brush of the label
118 Brush of the label
118 */
119 */
119
120
120 /*!
121 /*!
121 \property QLegendMarker::font
122 \property QLegendMarker::font
122 Font of the label
123 Font of the label
123 */
124 */
124
125
125 /*!
126 /*!
126 \property QLegendMarker::pen
127 \property QLegendMarker::pen
127 Pen of the marker. This is the outline of the colored square.
128 Pen of the marker. This is the outline of the colored square.
128 */
129 */
129
130
130 /*!
131 /*!
131 \property QLegendMarker::brush
132 \property QLegendMarker::brush
132 Brush of the marker. This is the inside of the colored square.
133 Brush of the marker. This is the inside of the colored square.
133 */
134 */
134
135
135 /*!
136 /*!
136 \property QLegendMarker::visible
137 \property QLegendMarker::visible
137 Visibility of the legend marker. Affects label and the colored square.
138 Visibility of the legend marker. Affects label and the colored square.
138 */
139 */
139
140
140
141
141 /*!
142 /*!
142 \internal
143 \internal
143 */
144 */
144 QLegendMarker::QLegendMarker(QLegendMarkerPrivate &d, QObject *parent) :
145 QLegendMarker::QLegendMarker(QLegendMarkerPrivate &d, QObject *parent) :
145 QObject(parent),
146 QObject(parent),
146 d_ptr(&d)
147 d_ptr(&d)
147 {
148 {
148 d_ptr->m_item->setVisible(d_ptr->series()->isVisible());
149 d_ptr->m_item->setVisible(d_ptr->series()->isVisible());
149 }
150 }
150
151
151 /*!
152 /*!
152 Destructor of marker
153 Destructor of marker
153 */
154 */
154 QLegendMarker::~QLegendMarker()
155 QLegendMarker::~QLegendMarker()
155 {
156 {
156 }
157 }
157
158
158 /*!
159 /*!
159 Returns the label of the marker.
160 Returns the label of the marker.
160 */
161 */
161 QString QLegendMarker::label() const
162 QString QLegendMarker::label() const
162 {
163 {
163 return d_ptr->m_item->label();
164 return d_ptr->m_item->label();
164 }
165 }
165
166
166 /*!
167 /*!
167 Sets the \a label of marker. Note that changing name of series will also change label of its marker.
168 Sets the \a label of marker. Note that changing name of series will also change label of its marker.
168 */
169 */
169 void QLegendMarker::setLabel(const QString &label)
170 void QLegendMarker::setLabel(const QString &label)
170 {
171 {
171 if (label.isEmpty()) {
172 if (label.isEmpty()) {
172 d_ptr->m_customLabel = false;
173 d_ptr->m_customLabel = false;
173 } else {
174 } else {
174 d_ptr->m_customLabel = true;
175 d_ptr->m_customLabel = true;
175 d_ptr->m_item->setLabel(label);
176 d_ptr->m_item->setLabel(label);
176 }
177 }
177 }
178 }
178 /*!
179 /*!
179 Returns the brush which is used to draw label.
180 Returns the brush which is used to draw label.
180 */
181 */
181 QBrush QLegendMarker::labelBrush() const
182 QBrush QLegendMarker::labelBrush() const
182 {
183 {
183 return d_ptr->m_item->labelBrush();
184 return d_ptr->m_item->labelBrush();
184 }
185 }
185
186
186 /*!
187 /*!
187 Sets the \a brush of label
188 Sets the \a brush of label
188 */
189 */
189 void QLegendMarker::setLabelBrush(const QBrush &brush)
190 void QLegendMarker::setLabelBrush(const QBrush &brush)
190 {
191 {
191 d_ptr->m_item->setLabelBrush(brush);
192 d_ptr->m_item->setLabelBrush(brush);
192 }
193 }
193
194
194 /*!
195 /*!
195 Retuns the font of label
196 Retuns the font of label
196 */
197 */
197 QFont QLegendMarker::font() const
198 QFont QLegendMarker::font() const
198 {
199 {
199 return d_ptr->m_item->font();
200 return d_ptr->m_item->font();
200 }
201 }
201
202
202 /*!
203 /*!
203 Sets the \a font of label
204 Sets the \a font of label
204 */
205 */
205 void QLegendMarker::setFont(const QFont &font)
206 void QLegendMarker::setFont(const QFont &font)
206 {
207 {
207 d_ptr->m_item->setFont(font);
208 d_ptr->m_item->setFont(font);
208 }
209 }
209
210
210 /*!
211 /*!
211 Returns the pen of marker item
212 Returns the pen of marker item
212 */
213 */
213 QPen QLegendMarker::pen() const
214 QPen QLegendMarker::pen() const
214 {
215 {
215 return d_ptr->m_item->pen();
216 return d_ptr->m_item->pen();
216 }
217 }
217
218
218 /*!
219 /*!
219 Sets the \a pen of marker item
220 Sets the \a pen of marker item
220 */
221 */
221 void QLegendMarker::setPen(const QPen &pen)
222 void QLegendMarker::setPen(const QPen &pen)
222 {
223 {
223 if (pen == QPen(Qt::NoPen)) {
224 if (pen == QPen(Qt::NoPen)) {
224 d_ptr->m_customPen = false;
225 d_ptr->m_customPen = false;
225 } else {
226 } else {
226 d_ptr->m_customPen = true;
227 d_ptr->m_customPen = true;
227 d_ptr->m_item->setPen(pen);
228 d_ptr->m_item->setPen(pen);
228 }
229 }
229 }
230 }
230
231
231 /*!
232 /*!
232 Returns the brush of marker item
233 Returns the brush of marker item
233 */
234 */
234 QBrush QLegendMarker::brush() const
235 QBrush QLegendMarker::brush() const
235 {
236 {
236 return d_ptr->m_item->brush();
237 return d_ptr->m_item->brush();
237 }
238 }
238
239
239 /*!
240 /*!
240 Sets the \a brush of marker item. Note that changing color of the series also changes this.
241 Sets the \a brush of marker item. Note that changing color of the series also changes this.
241 */
242 */
242 void QLegendMarker::setBrush(const QBrush &brush)
243 void QLegendMarker::setBrush(const QBrush &brush)
243 {
244 {
244 if (brush == QBrush(Qt::NoBrush)) {
245 if (brush == QBrush(Qt::NoBrush)) {
245 d_ptr->m_customBrush = false;
246 d_ptr->m_customBrush = false;
246 } else {
247 } else {
247 d_ptr->m_customBrush = true;
248 d_ptr->m_customBrush = true;
248 d_ptr->m_item->setBrush(brush);
249 d_ptr->m_item->setBrush(brush);
249 }
250 }
250 }
251 }
251
252
252 /*!
253 /*!
253 Returns visibility of the marker
254 Returns visibility of the marker
254 */
255 */
255 bool QLegendMarker::isVisible() const
256 bool QLegendMarker::isVisible() const
256 {
257 {
257 return d_ptr->m_item->isVisible();
258 return d_ptr->m_item->isVisible();
258 }
259 }
259
260
260 /*!
261 /*!
261 Sets markers visibility to \a visible
262 Sets markers visibility to \a visible
262 */
263 */
263 void QLegendMarker::setVisible(bool visible)
264 void QLegendMarker::setVisible(bool visible)
264 {
265 {
265 d_ptr->m_item->setVisible(visible);
266 d_ptr->m_item->setVisible(visible);
266 }
267 }
267
268
268 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
269 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
269 QLegendMarkerPrivate::QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend) :
270 QLegendMarkerPrivate::QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend) :
270 m_legend(legend),
271 m_legend(legend),
271 m_customLabel(false),
272 m_customLabel(false),
272 m_customBrush(false),
273 m_customBrush(false),
273 m_customPen(false),
274 m_customPen(false),
274 q_ptr(q)
275 q_ptr(q)
275 {
276 {
276 m_item = new LegendMarkerItem(this);
277 m_item = new LegendMarkerItem(this);
277 }
278 }
278
279
279 QLegendMarkerPrivate::~QLegendMarkerPrivate()
280 QLegendMarkerPrivate::~QLegendMarkerPrivate()
280 {
281 {
281 delete m_item;
282 delete m_item;
282 }
283 }
283
284
284 void QLegendMarkerPrivate::invalidateLegend()
285 void QLegendMarkerPrivate::invalidateLegend()
285 {
286 {
286 m_legend->d_ptr->m_layout->invalidate();
287 m_legend->d_ptr->m_layout->invalidate();
287 }
288 }
288
289
289 #include "moc_qlegendmarker.cpp"
290 #include "moc_qlegendmarker.cpp"
290 #include "moc_qlegendmarker_p.cpp"
291 #include "moc_qlegendmarker_p.cpp"
291
292
292 QTCOMMERCIALCHART_END_NAMESPACE
293 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,314 +1,315
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qabstractseries.h"
21 #include "qabstractseries.h"
22 #include "qabstractseries_p.h"
22 #include "qabstractseries_p.h"
23 #include "chartdataset_p.h"
23 #include "chartdataset_p.h"
24 #include "qchart.h"
24 #include "qchart.h"
25 #include "qchart_p.h"
25 #include "qchart_p.h"
26 #include "chartitem_p.h"
26 #include "chartitem_p.h"
27 #include "xydomain_p.h"
27 #include "xydomain_p.h"
28 #include "xlogydomain_p.h"
28 #include "xlogydomain_p.h"
29 #include "logxydomain_p.h"
29 #include "logxydomain_p.h"
30 #include "logxlogydomain_p.h"
30 #include "logxlogydomain_p.h"
31
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
34 /*!
34 /*!
35 \class QAbstractSeries
35 \class QAbstractSeries
36 \brief Base class for all QtCommercial Chart series.
36 \brief Base class for all QtCommercial Chart series.
37 \mainclass
37 \mainclass
38
38
39 Usually you use the series type specific inherited classes instead of the base class.
39 Usually you use the series type specific inherited classes instead of the base class.
40 \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QAbstractBarSeries, QStackedBarSeries,
40 \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QAbstractBarSeries, QStackedBarSeries,
41 QPercentBarSeries, QPieSeries
41 QPercentBarSeries, QPieSeries
42 */
42 */
43 /*!
43 /*!
44 \qmlclass AbstractSeries
44 \qmlclass AbstractSeries
45 AbstractSeries is the base class for all series.
45 AbstractSeries is the base class for all series.
46 The class cannot be instantiated by the user.
46 The class cannot be instantiated by the user.
47 */
47 */
48
48
49 /*!
49 /*!
50 \enum QAbstractSeries::SeriesType
50 \enum QAbstractSeries::SeriesType
51
51
52 The type of the series object.
52 The type of the series object.
53
53
54 \value SeriesTypeLine
54 \value SeriesTypeLine
55 \value SeriesTypeArea
55 \value SeriesTypeArea
56 \value SeriesTypeBar
56 \value SeriesTypeBar
57 \value SeriesTypeStackedBar
57 \value SeriesTypeStackedBar
58 \value SeriesTypePercentBar
58 \value SeriesTypePercentBar
59 \value SeriesTypePie
59 \value SeriesTypePie
60 \value SeriesTypeScatter
60 \value SeriesTypeScatter
61 \value SeriesTypeSpline
61 \value SeriesTypeSpline
62 \value SeriesTypeHorizontalBar
62 \value SeriesTypeHorizontalBar
63 \value SeriesTypeHorizontalStackedBar
63 \value SeriesTypeHorizontalStackedBar
64 \value SeriesTypeHorizontalPercentBar
64 \value SeriesTypeHorizontalPercentBar
65 \value SeriesTypeBoxPlot
65 */
66 */
66
67
67 /*!
68 /*!
68 \property QAbstractSeries::type
69 \property QAbstractSeries::type
69 The type of the series.
70 The type of the series.
70 */
71 */
71 /*!
72 /*!
72 \qmlproperty ChartView.SeriesType AbstractSeries::type
73 \qmlproperty ChartView.SeriesType AbstractSeries::type
73 The type of the series.
74 The type of the series.
74 */
75 */
75
76
76 /*!
77 /*!
77 \property QAbstractSeries::name
78 \property QAbstractSeries::name
78 \brief name of the series property. The name is shown in legend for QXYSeries.
79 \brief name of the series property. The name is shown in legend for QXYSeries.
79 */
80 */
80 /*!
81 /*!
81 \qmlproperty string AbstractSeries::name
82 \qmlproperty string AbstractSeries::name
82 Name of the series. The name is shown in legend for QXYSeries.
83 Name of the series. The name is shown in legend for QXYSeries.
83 */
84 */
84
85
85 /*!
86 /*!
86 \fn void QAbstractSeries::nameChanged()
87 \fn void QAbstractSeries::nameChanged()
87 This signal is emitted when the series name changes.
88 This signal is emitted when the series name changes.
88 */
89 */
89 /*!
90 /*!
90 \qmlsignal AbstractSeries::onNameChanged()
91 \qmlsignal AbstractSeries::onNameChanged()
91 This signal is emitted when the series name changes.
92 This signal is emitted when the series name changes.
92 */
93 */
93
94
94 /*!
95 /*!
95 \property QAbstractSeries::visible
96 \property QAbstractSeries::visible
96 \brief whether the series is visible or not; true by default.
97 \brief whether the series is visible or not; true by default.
97 */
98 */
98 /*!
99 /*!
99 \qmlproperty bool AbstractSeries::visible
100 \qmlproperty bool AbstractSeries::visible
100 Visibility of the series. True by default.
101 Visibility of the series. True by default.
101 */
102 */
102
103
103 /*!
104 /*!
104 \fn void QAbstractSeries::visibleChanged()
105 \fn void QAbstractSeries::visibleChanged()
105 Emitted when the series visibility changes.
106 Emitted when the series visibility changes.
106 */
107 */
107 /*!
108 /*!
108 \qmlsignal AbstractSeries::onVisibleChanged()
109 \qmlsignal AbstractSeries::onVisibleChanged()
109 Emitted when the series visibility changes.
110 Emitted when the series visibility changes.
110 */
111 */
111
112
112 /*!
113 /*!
113 \property QAbstractSeries::opacity
114 \property QAbstractSeries::opacity
114 \brief The opacity of the series.
115 \brief The opacity of the series.
115 By default the opacity is 1.0. The valid values range from 0.0 (transparent) to 1.0 (opaque).
116 By default the opacity is 1.0. The valid values range from 0.0 (transparent) to 1.0 (opaque).
116 */
117 */
117 /*!
118 /*!
118 \qmlproperty real AbstractSeries::opacity
119 \qmlproperty real AbstractSeries::opacity
119 The opacity of the series. By default the opacity is 1.0.
120 The opacity of the series. By default the opacity is 1.0.
120 The valid values range from 0.0 (transparent) to 1.0 (opaque).
121 The valid values range from 0.0 (transparent) to 1.0 (opaque).
121 */
122 */
122
123
123 /*!
124 /*!
124 \fn void QAbstractSeries::opacityChanged()
125 \fn void QAbstractSeries::opacityChanged()
125 Emitted when the opacity of the series changes.
126 Emitted when the opacity of the series changes.
126 */
127 */
127 /*!
128 /*!
128 \qmlsignal AbstractSeries::onOpacityChanged()
129 \qmlsignal AbstractSeries::onOpacityChanged()
129 Emitted when the opacity of the series changes.
130 Emitted when the opacity of the series changes.
130 */
131 */
131
132
132 /*!
133 /*!
133 \internal
134 \internal
134 \brief Constructs ChartSeries object with \a parent.
135 \brief Constructs ChartSeries object with \a parent.
135 */
136 */
136 QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) :
137 QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) :
137 QObject(parent),
138 QObject(parent),
138 d_ptr(&d)
139 d_ptr(&d)
139 {
140 {
140 }
141 }
141
142
142 /*!
143 /*!
143 \brief Virtual destructor for the chart series.
144 \brief Virtual destructor for the chart series.
144 */
145 */
145 QAbstractSeries::~QAbstractSeries()
146 QAbstractSeries::~QAbstractSeries()
146 {
147 {
147 if (d_ptr->m_chart)
148 if (d_ptr->m_chart)
148 qFatal("Still binded series detected !");
149 qFatal("Still binded series detected !");
149 }
150 }
150
151
151 void QAbstractSeries::setName(const QString &name)
152 void QAbstractSeries::setName(const QString &name)
152 {
153 {
153 if (name != d_ptr->m_name) {
154 if (name != d_ptr->m_name) {
154 d_ptr->m_name = name;
155 d_ptr->m_name = name;
155 emit nameChanged();
156 emit nameChanged();
156 }
157 }
157 }
158 }
158
159
159 QString QAbstractSeries::name() const
160 QString QAbstractSeries::name() const
160 {
161 {
161 return d_ptr->m_name;
162 return d_ptr->m_name;
162 }
163 }
163
164
164 /*!
165 /*!
165 Sets the visibility of series to \a visible
166 Sets the visibility of series to \a visible
166 */
167 */
167 void QAbstractSeries::setVisible(bool visible)
168 void QAbstractSeries::setVisible(bool visible)
168 {
169 {
169 if (visible != d_ptr->m_visible) {
170 if (visible != d_ptr->m_visible) {
170 d_ptr->m_visible = visible;
171 d_ptr->m_visible = visible;
171 emit visibleChanged();
172 emit visibleChanged();
172 }
173 }
173 }
174 }
174
175
175 /*!
176 /*!
176 Returns the visibility of series
177 Returns the visibility of series
177 */
178 */
178 bool QAbstractSeries::isVisible() const
179 bool QAbstractSeries::isVisible() const
179 {
180 {
180 return d_ptr->m_visible;
181 return d_ptr->m_visible;
181 }
182 }
182
183
183 qreal QAbstractSeries::opacity() const
184 qreal QAbstractSeries::opacity() const
184 {
185 {
185 return d_ptr->m_opacity;
186 return d_ptr->m_opacity;
186 }
187 }
187
188
188 void QAbstractSeries::setOpacity(qreal opacity)
189 void QAbstractSeries::setOpacity(qreal opacity)
189 {
190 {
190 if (opacity != d_ptr->m_opacity) {
191 if (opacity != d_ptr->m_opacity) {
191 d_ptr->m_opacity = opacity;
192 d_ptr->m_opacity = opacity;
192 emit opacityChanged();
193 emit opacityChanged();
193 }
194 }
194 }
195 }
195
196
196 /*!
197 /*!
197 \brief Returns the chart where series belongs to.
198 \brief Returns the chart where series belongs to.
198
199
199 Set automatically when the series is added to the chart
200 Set automatically when the series is added to the chart
200 and unset when the series is removed from the chart.
201 and unset when the series is removed from the chart.
201 */
202 */
202 QChart *QAbstractSeries::chart() const
203 QChart *QAbstractSeries::chart() const
203 {
204 {
204 return d_ptr->m_chart;
205 return d_ptr->m_chart;
205 }
206 }
206
207
207 /*!
208 /*!
208 \brief Sets the visibility of the series to true
209 \brief Sets the visibility of the series to true
209
210
210 \sa setVisible(), isVisible()
211 \sa setVisible(), isVisible()
211 */
212 */
212 void QAbstractSeries::show()
213 void QAbstractSeries::show()
213 {
214 {
214 setVisible(true);
215 setVisible(true);
215 }
216 }
216
217
217 /*!
218 /*!
218 \brief Sets the visibility of the series to false
219 \brief Sets the visibility of the series to false
219
220
220 \sa setVisible(), isVisible()
221 \sa setVisible(), isVisible()
221 */
222 */
222 void QAbstractSeries::hide()
223 void QAbstractSeries::hide()
223 {
224 {
224 setVisible(false);
225 setVisible(false);
225 }
226 }
226
227
227 /*!
228 /*!
228 Attach \a axis to the series.
229 Attach \a axis to the series.
229 \return true if the axis was attached successfully, false otherwise.
230 \return true if the axis was attached successfully, false otherwise.
230 \sa QChart::addAxis(), QChart::createDefaultAxes()
231 \sa QChart::addAxis(), QChart::createDefaultAxes()
231 */
232 */
232 bool QAbstractSeries::attachAxis(QAbstractAxis* axis)
233 bool QAbstractSeries::attachAxis(QAbstractAxis* axis)
233 {
234 {
234 if(d_ptr->m_chart) {
235 if(d_ptr->m_chart) {
235 return d_ptr->m_chart->d_ptr->m_dataset->attachAxis(this, axis);
236 return d_ptr->m_chart->d_ptr->m_dataset->attachAxis(this, axis);
236 } else {
237 } else {
237 qWarning()<<"Series not in the chart. Please addSeries to chart first.";
238 qWarning()<<"Series not in the chart. Please addSeries to chart first.";
238 return false;
239 return false;
239 }
240 }
240 }
241 }
241
242
242 /*!
243 /*!
243 Detach \a axis from the series.
244 Detach \a axis from the series.
244 \return true if the axis was detached successfully, false otherwise.
245 \return true if the axis was detached successfully, false otherwise.
245 \sa QChart::removeAxis()
246 \sa QChart::removeAxis()
246 */
247 */
247 bool QAbstractSeries::detachAxis(QAbstractAxis* axis)
248 bool QAbstractSeries::detachAxis(QAbstractAxis* axis)
248 {
249 {
249 if(d_ptr->m_chart) {
250 if(d_ptr->m_chart) {
250 return d_ptr->m_chart->d_ptr->m_dataset->detachAxis(this, axis);
251 return d_ptr->m_chart->d_ptr->m_dataset->detachAxis(this, axis);
251 }
252 }
252 else {
253 else {
253 qWarning()<<"Series not in the chart. Please addSeries to chart first.";
254 qWarning()<<"Series not in the chart. Please addSeries to chart first.";
254 return false;
255 return false;
255 }
256 }
256 }
257 }
257
258
258 /*!
259 /*!
259 Returns the list of axes attached to the series. Usually there is an x-axis and a y-axis attached to a series, except
260 Returns the list of axes attached to the series. Usually there is an x-axis and a y-axis attached to a series, except
260 in case of a QPieSeries, which does not have any axes attached.
261 in case of a QPieSeries, which does not have any axes attached.
261 \sa attachAxis(), detachAxis()
262 \sa attachAxis(), detachAxis()
262 */
263 */
263 QList<QAbstractAxis*> QAbstractSeries::attachedAxes()
264 QList<QAbstractAxis*> QAbstractSeries::attachedAxes()
264 {
265 {
265 return d_ptr->m_axes;
266 return d_ptr->m_axes;
266 }
267 }
267
268
268 ///////////////////////////////////////////////////////////////////////////////////////////////////
269 ///////////////////////////////////////////////////////////////////////////////////////////////////
269
270
270 QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries *q)
271 QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries *q)
271 : q_ptr(q),
272 : q_ptr(q),
272 m_chart(0),
273 m_chart(0),
273 m_item(0),
274 m_item(0),
274 m_domain(new XYDomain()),
275 m_domain(new XYDomain()),
275 m_visible(true),
276 m_visible(true),
276 m_opacity(1.0)
277 m_opacity(1.0)
277 {
278 {
278 }
279 }
279
280
280 QAbstractSeriesPrivate::~QAbstractSeriesPrivate()
281 QAbstractSeriesPrivate::~QAbstractSeriesPrivate()
281 {
282 {
282 }
283 }
283
284
284 void QAbstractSeriesPrivate::setDomain(AbstractDomain* domain)
285 void QAbstractSeriesPrivate::setDomain(AbstractDomain* domain)
285 {
286 {
286 Q_ASSERT(domain);
287 Q_ASSERT(domain);
287 if(m_domain.data()!=domain) {
288 if(m_domain.data()!=domain) {
288 if(!m_item.isNull()) QObject::disconnect(m_domain.data(), SIGNAL(updated()), m_item.data(), SLOT(handleDomainUpdated()));
289 if(!m_item.isNull()) QObject::disconnect(m_domain.data(), SIGNAL(updated()), m_item.data(), SLOT(handleDomainUpdated()));
289 m_domain.reset(domain);
290 m_domain.reset(domain);
290 if(!m_item.isNull()) {
291 if(!m_item.isNull()) {
291 QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated()));
292 QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated()));
292 m_item->handleDomainUpdated();
293 m_item->handleDomainUpdated();
293 }
294 }
294 }
295 }
295 }
296 }
296
297
297 void QAbstractSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
298 void QAbstractSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
298 {
299 {
299 Q_ASSERT(!m_item.isNull());
300 Q_ASSERT(!m_item.isNull());
300 Q_UNUSED(parent);
301 Q_UNUSED(parent);
301 QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated()));
302 QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated()));
302 }
303 }
303
304
304 void QAbstractSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
305 void QAbstractSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
305 {
306 {
306 Q_UNUSED(options);
307 Q_UNUSED(options);
307 }
308 }
308
309
309 #include "moc_qabstractseries.cpp"
310 #include "moc_qabstractseries.cpp"
310 #include "moc_qabstractseries_p.cpp"
311 #include "moc_qabstractseries_p.cpp"
311
312
312 QTCOMMERCIALCHART_END_NAMESPACE
313 QTCOMMERCIALCHART_END_NAMESPACE
313
314
314
315
@@ -1,358 +1,389
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "mainwidget.h"
21 #include "mainwidget.h"
22 #include "customtablemodel.h"
22 #include "customtablemodel.h"
23 #include <QVBoxPlotModelMapper>
23 #include <QVBoxPlotModelMapper>
24 #include <QTableView>
24 #include <QTableView>
25 #include <QHeaderView>
25 #include <QHeaderView>
26 #include <QChartView>
26 #include <QChartView>
27 #include <QBoxPlotSeries>
27 #include <QBoxPlotSeries>
28 #include <QBoxSet>
28 #include <QBoxSet>
29 #include <QLegend>
29 #include <QLegend>
30 #include <QBarCategoryAxis>
30 #include <QBarCategoryAxis>
31 #include <QBrush>
31 #include <QBrush>
32 #include <QColor>
32 #include <QColor>
33 #include <QPushButton>
33 #include <QPushButton>
34 #include <QComboBox>
34 #include <QComboBox>
35 #include <QSpinBox>
35 #include <QSpinBox>
36 #include <QCheckBox>
36 #include <QCheckBox>
37 #include <QGridLayout>
37 #include <QGridLayout>
38 #include <QHBoxLayout>
38 #include <QHBoxLayout>
39 #include <QLabel>
39 #include <QLabel>
40 #include <QSpacerItem>
40 #include <QSpacerItem>
41 #include <QMessageBox>
41 #include <QMessageBox>
42 #include <cmath>
42 #include <cmath>
43 #include <QDebug>
43 #include <QDebug>
44 #include <QStandardItemModel>
44 #include <QStandardItemModel>
45 #include <QBarCategoryAxis>
45 #include <QBarCategoryAxis>
46
46
47
47
48 QTCOMMERCIALCHART_USE_NAMESPACE
48 QTCOMMERCIALCHART_USE_NAMESPACE
49
49
50 QString addCategories[] = {"Jul", "Aug", "Sep", "Nov", "Dec"};
50 QString addCategories[] = {"Jul", "Aug", "Sep", "Nov", "Dec"};
51
51
52 MainWidget::MainWidget(QWidget *parent) :
52 MainWidget::MainWidget(QWidget *parent) :
53 QWidget(parent),
53 QWidget(parent),
54 m_chart(0),
54 m_chart(0),
55 rowPos(0),
55 rowPos(0),
56 nSeries(0),
56 nSeries(0),
57 nNewBoxes(0)
57 nNewBoxes(0)
58 {
58 {
59 m_chart = new QChart();
59 m_chart = new QChart();
60
60
61 // Grid layout for the controls for configuring the chart widget
61 // Grid layout for the controls for configuring the chart widget
62 QGridLayout *grid = new QGridLayout();
62 QGridLayout *grid = new QGridLayout();
63
63
64 // Create add a series button
64 // Create add a series button
65 QPushButton *addSeriesButton = new QPushButton("Add a series");
65 QPushButton *addSeriesButton = new QPushButton("Add a series");
66 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
66 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
67 grid->addWidget(addSeriesButton, rowPos++, 1);
67 grid->addWidget(addSeriesButton, rowPos++, 1);
68
68
69 // Create remove a series button
69 // Create remove a series button
70 QPushButton *removeSeriesButton = new QPushButton("Remove a series");
70 QPushButton *removeSeriesButton = new QPushButton("Remove a series");
71 connect(removeSeriesButton, SIGNAL(clicked()), this, SLOT(removeSeries()));
71 connect(removeSeriesButton, SIGNAL(clicked()), this, SLOT(removeSeries()));
72 grid->addWidget(removeSeriesButton, rowPos++, 1);
72 grid->addWidget(removeSeriesButton, rowPos++, 1);
73
73
74 // Create add a single box button
74 // Create add a single box button
75 QPushButton *addBoxButton = new QPushButton("Add a box");
75 QPushButton *addBoxButton = new QPushButton("Add a box");
76 connect(addBoxButton, SIGNAL(clicked()), this, SLOT(addBox()));
76 connect(addBoxButton, SIGNAL(clicked()), this, SLOT(addBox()));
77 grid->addWidget(addBoxButton, rowPos++, 1);
77 grid->addWidget(addBoxButton, rowPos++, 1);
78
78
79 // Create insert a box button
79 // Create insert a box button
80 QPushButton *insertBoxButton = new QPushButton("Insert a box");
80 QPushButton *insertBoxButton = new QPushButton("Insert a box");
81 connect(insertBoxButton, SIGNAL(clicked()), this, SLOT(insertBox()));
81 connect(insertBoxButton, SIGNAL(clicked()), this, SLOT(insertBox()));
82 grid->addWidget(insertBoxButton, rowPos++, 1);
82 grid->addWidget(insertBoxButton, rowPos++, 1);
83
83
84 // Create add a single box button
84 // Create add a single box button
85 QPushButton *removeBoxButton = new QPushButton("Remove a box");
85 QPushButton *removeBoxButton = new QPushButton("Remove a box");
86 connect(removeBoxButton, SIGNAL(clicked()), this, SLOT(removeBox()));
86 connect(removeBoxButton, SIGNAL(clicked()), this, SLOT(removeBox()));
87 grid->addWidget(removeBoxButton, rowPos++, 1);
87 grid->addWidget(removeBoxButton, rowPos++, 1);
88
88
89 // Create clear button
89 // Create clear button
90 QPushButton *clearButton = new QPushButton("Clear");
90 QPushButton *clearButton = new QPushButton("Clear");
91 connect(clearButton, SIGNAL(clicked()), this, SLOT(clear()));
91 connect(clearButton, SIGNAL(clicked()), this, SLOT(clear()));
92 grid->addWidget(clearButton, rowPos++, 1);
92 grid->addWidget(clearButton, rowPos++, 1);
93
93
94 // Create set brush button
94 // Create set brush button
95 QPushButton *setBrushButton = new QPushButton("Set brush");
95 QPushButton *setBrushButton = new QPushButton("Set brush");
96 connect(setBrushButton, SIGNAL(clicked()), this, SLOT(setBrush()));
96 connect(setBrushButton, SIGNAL(clicked()), this, SLOT(setBrush()));
97 grid->addWidget(setBrushButton, rowPos++, 1);
97 grid->addWidget(setBrushButton, rowPos++, 1);
98
98
99 initThemeCombo(grid);
99 initThemeCombo(grid);
100 initCheckboxes(grid);
100 initCheckboxes(grid);
101
101
102 m_model = new CustomTableModel;
102 m_model = new CustomTableModel;
103 QTableView *tableView = new QTableView;
103 QTableView *tableView = new QTableView;
104 tableView->setModel(m_model);
104 tableView->setModel(m_model);
105 tableView->setMaximumWidth(200);
105 tableView->setMaximumWidth(200);
106 grid->addWidget(tableView, rowPos++, 0, 3, 2, Qt::AlignLeft);
106 grid->addWidget(tableView, rowPos++, 0, 3, 2, Qt::AlignLeft);
107 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
107 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
108 tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
108 tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
109 tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
109 tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
110 #else
110 #else
111 tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
111 tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
112 tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
112 tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
113 #endif
113 #endif
114
114
115 // add row with empty label to make all the other rows static
115 // add row with empty label to make all the other rows static
116 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
116 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
117 grid->setRowStretch(grid->rowCount() - 1, 1);
117 grid->setRowStretch(grid->rowCount() - 1, 1);
118
118
119 // Create chart view with the chart
119 // Create chart view with the chart
120 m_chartView = new QChartView(m_chart, this);
120 m_chartView = new QChartView(m_chart, this);
121 //m_chartView->setRubberBand(QChartView::HorizonalRubberBand);
121 //m_chartView->setRubberBand(QChartView::HorizonalRubberBand);
122
122
123 // Another grid layout as a main layout
123 // Another grid layout as a main layout
124 QGridLayout *mainLayout = new QGridLayout();
124 QGridLayout *mainLayout = new QGridLayout();
125 mainLayout->addLayout(grid, 0, 0);
125 mainLayout->addLayout(grid, 0, 0);
126 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
126 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
127 setLayout(mainLayout);
127 setLayout(mainLayout);
128
128
129 legendToggled(false);
129 legendToggled(false);
130 animationToggled(false);
130 animationToggled(false);
131 }
131 }
132
132
133 // Combo box for selecting theme
133 // Combo box for selecting theme
134 void MainWidget::initThemeCombo(QGridLayout *grid)
134 void MainWidget::initThemeCombo(QGridLayout *grid)
135 {
135 {
136 QComboBox *chartTheme = new QComboBox();
136 QComboBox *chartTheme = new QComboBox();
137 chartTheme->addItem("Default");
137 chartTheme->addItem("Default");
138 chartTheme->addItem("Light");
138 chartTheme->addItem("Light");
139 chartTheme->addItem("Blue Cerulean");
139 chartTheme->addItem("Blue Cerulean");
140 chartTheme->addItem("Dark");
140 chartTheme->addItem("Dark");
141 chartTheme->addItem("Brown Sand");
141 chartTheme->addItem("Brown Sand");
142 chartTheme->addItem("Blue NCS");
142 chartTheme->addItem("Blue NCS");
143 chartTheme->addItem("High Contrast");
143 chartTheme->addItem("High Contrast");
144 chartTheme->addItem("Blue Icy");
144 chartTheme->addItem("Blue Icy");
145 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
145 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
146 this, SLOT(changeChartTheme(int)));
146 this, SLOT(changeChartTheme(int)));
147 grid->addWidget(new QLabel("Chart theme:"), rowPos, 0);
147 grid->addWidget(new QLabel("Chart theme:"), rowPos, 0);
148 grid->addWidget(chartTheme, rowPos++, 1);
148 grid->addWidget(chartTheme, rowPos++, 1);
149 }
149 }
150
150
151 // Different check boxes for customizing chart
151 // Different check boxes for customizing chart
152 void MainWidget::initCheckboxes(QGridLayout *grid)
152 void MainWidget::initCheckboxes(QGridLayout *grid)
153 {
153 {
154 QCheckBox *animationCheckBox = new QCheckBox("Animation");
154 QCheckBox *animationCheckBox = new QCheckBox("Animation");
155 connect(animationCheckBox, SIGNAL(toggled(bool)), this, SLOT(animationToggled(bool)));
155 connect(animationCheckBox, SIGNAL(toggled(bool)), this, SLOT(animationToggled(bool)));
156 animationCheckBox->setChecked(false);
156 animationCheckBox->setChecked(false);
157 grid->addWidget(animationCheckBox, rowPos++, 0);
157 grid->addWidget(animationCheckBox, rowPos++, 0);
158
158
159 QCheckBox *legendCheckBox = new QCheckBox("Legend");
159 QCheckBox *legendCheckBox = new QCheckBox("Legend");
160 connect(legendCheckBox, SIGNAL(toggled(bool)), this, SLOT(legendToggled(bool)));
160 connect(legendCheckBox, SIGNAL(toggled(bool)), this, SLOT(legendToggled(bool)));
161 legendCheckBox->setChecked(false);
161 legendCheckBox->setChecked(false);
162 grid->addWidget(legendCheckBox, rowPos++, 0);
162 grid->addWidget(legendCheckBox, rowPos++, 0);
163
163
164 QCheckBox *titleCheckBox = new QCheckBox("Title");
164 QCheckBox *titleCheckBox = new QCheckBox("Title");
165 connect(titleCheckBox, SIGNAL(toggled(bool)), this, SLOT(titleToggled(bool)));
165 connect(titleCheckBox, SIGNAL(toggled(bool)), this, SLOT(titleToggled(bool)));
166 titleCheckBox->setChecked(false);
166 titleCheckBox->setChecked(false);
167 grid->addWidget(titleCheckBox, rowPos++, 0);
167 grid->addWidget(titleCheckBox, rowPos++, 0);
168
168
169 QCheckBox *modelMapperCheckBox = new QCheckBox("Use model mapper");
169 QCheckBox *modelMapperCheckBox = new QCheckBox("Use model mapper");
170 connect(modelMapperCheckBox, SIGNAL(toggled(bool)), this, SLOT(modelMapperToggled(bool)));
170 connect(modelMapperCheckBox, SIGNAL(toggled(bool)), this, SLOT(modelMapperToggled(bool)));
171 modelMapperCheckBox->setChecked(false);
171 modelMapperCheckBox->setChecked(false);
172 grid->addWidget(modelMapperCheckBox, rowPos++, 0);
172 grid->addWidget(modelMapperCheckBox, rowPos++, 0);
173
173
174 }
174 }
175
175
176 void MainWidget::addSeries()
176 void MainWidget::addSeries()
177 {
177 {
178 qDebug() << "BoxPlotTester::MainWidget::addSeries()";
178 qDebug() << "BoxPlotTester::MainWidget::addSeries()";
179
179
180 if (nSeries > 9)
180 if (nSeries > 9)
181 return;
181 return;
182
182
183 // Initial data
183 // Initial data
184 //![1]
184 //![1]
185 QBoxSet *set0 = new QBoxSet();
185 QBoxSet *set0 = new QBoxSet();
186 QBoxSet *set1 = new QBoxSet();
186 QBoxSet *set1 = new QBoxSet();
187 QBoxSet *set2 = new QBoxSet();
187 QBoxSet *set2 = new QBoxSet();
188 QBoxSet *set3 = new QBoxSet();
188 QBoxSet *set3 = new QBoxSet();
189 QBoxSet *set4 = new QBoxSet();
189 QBoxSet *set4 = new QBoxSet();
190 QBoxSet *set5 = new QBoxSet();
190 QBoxSet *set5 = new QBoxSet();
191
191
192 // low bot med top upp
192 // low bot med top upp
193 *set0 << 3 << 4 << 4.4 << 6 << 7;
193 *set0 << 3 << 4 << 4.4 << 6 << 7;
194 *set1 << 5 << 6 << 7.5 << 8 << 12;
194 *set1 << 5 << 6 << 7.5 << 8 << 12;
195 *set2 << 3 << 5 << 5.7 << 8 << 9;
195 *set2 << 3 << 5 << 5.7 << 8 << 9;
196 *set3 << 5 << 6 << 6.8 << 7 << 8;
196 *set3 << 5 << 6 << 6.8 << 7 << 8;
197 *set4 << 4 << 5 << 5.2 << 6 << 7;
197 *set4 << 4 << 5 << 5.2 << 6 << 7;
198 *set5 << 4 << 7 << 8.2 << 9 << 10;
198 *set5 << 4 << 7 << 8.2 << 9 << 10;
199
199
200 m_series[nSeries] = new QBoxPlotSeries();
200 m_series[nSeries] = new QBoxPlotSeries();
201 m_series[nSeries]->append(set0);
201 m_series[nSeries]->append(set0);
202 m_series[nSeries]->append(set1);
202 m_series[nSeries]->append(set1);
203 m_series[nSeries]->append(set2);
203 m_series[nSeries]->append(set2);
204 m_series[nSeries]->append(set3);
204 m_series[nSeries]->append(set3);
205 m_series[nSeries]->append(set4);
205 m_series[nSeries]->append(set4);
206 m_series[nSeries]->append(set5);
206 m_series[nSeries]->append(set5);
207 m_series[nSeries]->setName("Box & Whiskers");
207 m_series[nSeries]->setName("Box & Whiskers");
208
208
209 connect(m_series[nSeries], SIGNAL(clicked(QBoxSet*)), this, SLOT(boxClicked(QBoxSet*)));
210 connect(m_series[nSeries], SIGNAL(hovered(bool, QBoxSet*)), this, SLOT(boxHovered(bool, QBoxSet*)));
211 connect(set1, SIGNAL(clicked()), this, SLOT(singleBoxClicked()));
212 connect(set2, SIGNAL(hovered(bool)), this, SLOT(singleBoxHovered(bool)));
213
209 m_chart->addSeries(m_series[nSeries]);
214 m_chart->addSeries(m_series[nSeries]);
210
215
211 if (nSeries == 0) {
216 if (nSeries == 0) {
212 QStringList categories;
217 QStringList categories;
213 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
218 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
214 m_axis = new QBarCategoryAxis();
219 m_axis = new QBarCategoryAxis();
215 m_axis->append(categories);
220 m_axis->append(categories);
216 m_chart->createDefaultAxes();
221 m_chart->createDefaultAxes();
217 m_chart->setAxisX(m_axis, m_series[nSeries]);
222 m_chart->setAxisX(m_axis, m_series[nSeries]);
218 }
223 }
219
224
220 nSeries++;
225 nSeries++;
221 }
226 }
222
227
223 void MainWidget::removeSeries()
228 void MainWidget::removeSeries()
224 {
229 {
225 qDebug() << "BoxPlotTester::MainWidget::removeSeries()";
230 qDebug() << "BoxPlotTester::MainWidget::removeSeries()";
226
231
227 if (nSeries > 0) {
232 if (nSeries > 0) {
228 nSeries--;
233 nSeries--;
229 m_chart->removeSeries(m_series[nSeries]);
234 m_chart->removeSeries(m_series[nSeries]);
230 delete m_series[nSeries];
235 delete m_series[nSeries];
231 } else {
236 } else {
232 qDebug() << "Create a series first";
237 qDebug() << "Create a series first";
233 }
238 }
234 }
239 }
235
240
236 void MainWidget::addBox()
241 void MainWidget::addBox()
237 {
242 {
238 qDebug() << "BoxPlotTester::MainWidget::addBox()";
243 qDebug() << "BoxPlotTester::MainWidget::addBox()";
239
244
240 if (nSeries > 0) {
245 if (nSeries > 0) {
241 QBoxSet *newSet = new QBoxSet();
246 QBoxSet *newSet = new QBoxSet();
242 *newSet << 5 << 6 << 6.8 << 7 << 8;
247 *newSet << 5 << 6 << 6.8 << 7 << 8;
243
248
244 m_series[0]->append(newSet);
249 m_series[0]->append(newSet);
245
250
246 m_axis->append(addCategories[nNewBoxes]);
251 m_axis->append(addCategories[nNewBoxes]);
247
252
248 nNewBoxes++;
253 nNewBoxes++;
249 }
254 }
250 }
255 }
251
256
252 void MainWidget::insertBox()
257 void MainWidget::insertBox()
253 {
258 {
254 qDebug() << "BoxPlotTester::MainWidget::insertBox()";
259 qDebug() << "BoxPlotTester::MainWidget::insertBox()";
255
260
256 if (nSeries > 0) {
261 if (nSeries > 0) {
257 QBoxSet *newSet = new QBoxSet();
262 QBoxSet *newSet = new QBoxSet();
258 *newSet << 2 << 6 << 6.8 << 7 << 10;
263 *newSet << 2 << 6 << 6.8 << 7 << 10;
259
264
260 m_series[0]->insert(1, newSet);
265 m_series[0]->insert(1, newSet);
261
266
262 m_axis->append(addCategories[nNewBoxes]);
267 m_axis->append(addCategories[nNewBoxes]);
263
268
264 nNewBoxes++;
269 nNewBoxes++;
265 }
270 }
266 }
271 }
267
272
268 void MainWidget::removeBox()
273 void MainWidget::removeBox()
269 {
274 {
270 qDebug() << "BoxPlotTester::MainWidget::removeBox";
275 qDebug() << "BoxPlotTester::MainWidget::removeBox";
271
276
272 if (nSeries > 0) {
277 if (nSeries > 0) {
273 QList<QBoxSet *> sets = m_series[0]->boxSets();
278 QList<QBoxSet *> sets = m_series[0]->boxSets();
274 m_series[0]->remove(sets.at(m_series[0]->count() - 3));
279 m_series[0]->remove(sets.at(m_series[0]->count() - 3));
275 } else {
280 } else {
276 qDebug() << "Create a series first";
281 qDebug() << "Create a series first";
277 }
282 }
278 }
283 }
279
284
280 void MainWidget::clear()
285 void MainWidget::clear()
281 {
286 {
282 qDebug() << "BoxPlotTester::MainWidget::clear";
287 qDebug() << "BoxPlotTester::MainWidget::clear";
283
288
284 if (nSeries > 0) {
289 if (nSeries > 0) {
285 m_series[0]->clear();
290 m_series[0]->clear();
286 } else {
291 } else {
287 qDebug() << "Create a series first";
292 qDebug() << "Create a series first";
288 }
293 }
289 }
294 }
290
295
291 void MainWidget::setBrush()
296 void MainWidget::setBrush()
292 {
297 {
293 qDebug() << "BoxPlotTester::MainWidget::setBrush";
298 qDebug() << "BoxPlotTester::MainWidget::setBrush";
294
299
295 if (nSeries > 0) {
300 if (nSeries > 0) {
296 QList<QBoxSet *> sets = m_series[0]->boxSets();
301 QList<QBoxSet *> sets = m_series[0]->boxSets();
297 sets.at(1)->setBrush(QBrush(QColor(Qt::yellow)));
302 sets.at(1)->setBrush(QBrush(QColor(Qt::yellow)));
298 } else {
303 } else {
299 qDebug() << "Create a series first";
304 qDebug() << "Create a series first";
300 }
305 }
301 }
306 }
302
307
303 void MainWidget::animationToggled(bool enabled)
308 void MainWidget::animationToggled(bool enabled)
304 {
309 {
305 qDebug() << "BoxPlotTester::Animation toggled to " << enabled;
310 qDebug() << "BoxPlotTester::Animation toggled to " << enabled;
306 if (enabled)
311 if (enabled)
307 m_chart->setAnimationOptions(QChart::SeriesAnimations);
312 m_chart->setAnimationOptions(QChart::SeriesAnimations);
308 else
313 else
309 m_chart->setAnimationOptions(QChart::NoAnimation);
314 m_chart->setAnimationOptions(QChart::NoAnimation);
310 }
315 }
311
316
312 void MainWidget::legendToggled(bool enabled)
317 void MainWidget::legendToggled(bool enabled)
313 {
318 {
314 qDebug() << "BoxPlotTester::Legend toggled to " << enabled;
319 qDebug() << "BoxPlotTester::Legend toggled to " << enabled;
315 m_chart->legend()->setVisible(enabled);
320 m_chart->legend()->setVisible(enabled);
316 if (enabled)
321 if (enabled)
317 m_chart->legend()->setAlignment(Qt::AlignBottom);
322 m_chart->legend()->setAlignment(Qt::AlignBottom);
318 }
323 }
319
324
320 void MainWidget::titleToggled(bool enabled)
325 void MainWidget::titleToggled(bool enabled)
321 {
326 {
322 qDebug() << "BoxPlotTester::Title toggled to " << enabled;
327 qDebug() << "BoxPlotTester::Title toggled to " << enabled;
323 if (enabled)
328 if (enabled)
324 m_chart->setTitle("Simple boxplotchart example");
329 m_chart->setTitle("Simple boxplotchart example");
325 else
330 else
326 m_chart->setTitle("");
331 m_chart->setTitle("");
327 }
332 }
328
333
329 void MainWidget::modelMapperToggled(bool enabled)
334 void MainWidget::modelMapperToggled(bool enabled)
330 {
335 {
331 if (enabled) {
336 if (enabled) {
332 m_series[nSeries] = new QBoxPlotSeries();
337 m_series[nSeries] = new QBoxPlotSeries();
333
338
334 int first = 0;
339 int first = 0;
335 int count = 5;
340 int count = 5;
336 QVBoxPlotModelMapper *mapper = new QVBoxPlotModelMapper(this);
341 QVBoxPlotModelMapper *mapper = new QVBoxPlotModelMapper(this);
337 mapper->setFirstBoxSetColumn(0);
342 mapper->setFirstBoxSetColumn(0);
338 mapper->setLastBoxSetColumn(5);
343 mapper->setLastBoxSetColumn(5);
339 mapper->setFirstRow(first);
344 mapper->setFirstRow(first);
340 mapper->setRowCount(count);
345 mapper->setRowCount(count);
341 mapper->setSeries(m_series[nSeries]);
346 mapper->setSeries(m_series[nSeries]);
342 mapper->setModel(m_model);
347 mapper->setModel(m_model);
343 m_chart->addSeries(m_series[nSeries]);
348 m_chart->addSeries(m_series[nSeries]);
344
349
345 nSeries++;
350 nSeries++;
346 } else {
351 } else {
347 removeSeries();
352 removeSeries();
348 }
353 }
349 }
354 }
350
355
351 void MainWidget::changeChartTheme(int themeIndex)
356 void MainWidget::changeChartTheme(int themeIndex)
352 {
357 {
353 qDebug() << "BoxPlotTester::changeChartTheme: " << themeIndex;
358 qDebug() << "BoxPlotTester::changeChartTheme: " << themeIndex;
354 if (themeIndex == 0)
359 if (themeIndex == 0)
355 m_chart->setTheme(QChart::ChartThemeLight);
360 m_chart->setTheme(QChart::ChartThemeLight);
356 else
361 else
357 m_chart->setTheme((QChart::ChartTheme) (themeIndex - 1));
362 m_chart->setTheme((QChart::ChartTheme) (themeIndex - 1));
358 }
363 }
364
365 void MainWidget::boxClicked(QBoxSet *set)
366 {
367 qDebug() << "boxClicked, median = " << set->median();
368 }
369
370 void MainWidget::boxHovered(bool state, QBoxSet *set)
371 {
372 if (state)
373 qDebug() << "box median " << set->median() << " hover started";
374 else
375 qDebug() << "box median " << set->median() << " hover ended";
376 }
377
378 void MainWidget::singleBoxClicked()
379 {
380 qDebug() << "singleBoxClicked";
381 }
382
383 void MainWidget::singleBoxHovered(bool state)
384 {
385 if (state)
386 qDebug() << "single box hover started";
387 else
388 qDebug() << "single box hover ended";
389 }
@@ -1,74 +1,79
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef MAINWIDGET_H
21 #ifndef MAINWIDGET_H
22 #define MAINWIDGET_H
22 #define MAINWIDGET_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "qchart.h"
25 #include "qchart.h"
26 #include "qchartview.h"
26 #include "qchartview.h"
27 #include "customtablemodel.h"
27 #include "customtablemodel.h"
28 #include <QWidget>
28 #include <QWidget>
29 #include <QBoxPlotSeries>
29 #include <QBoxPlotSeries>
30 #include <QBarCategoryAxis>
30 #include <QBarCategoryAxis>
31 #include <QBoxSet>
31
32
32 class QGridLayout;
33 class QGridLayout;
33
34
34 QTCOMMERCIALCHART_USE_NAMESPACE
35 QTCOMMERCIALCHART_USE_NAMESPACE
35
36
36 class MainWidget : public QWidget
37 class MainWidget : public QWidget
37 {
38 {
38 Q_OBJECT
39 Q_OBJECT
39 public:
40 public:
40 explicit MainWidget(QWidget *parent = 0);
41 explicit MainWidget(QWidget *parent = 0);
41
42
42 signals:
43 signals:
43
44
44 private:
45 private:
45 void initThemeCombo(QGridLayout *grid);
46 void initThemeCombo(QGridLayout *grid);
46 void initCheckboxes(QGridLayout *grid);
47 void initCheckboxes(QGridLayout *grid);
47
48
48 private slots:
49 private slots:
49 void addSeries();
50 void addSeries();
50 void removeSeries();
51 void removeSeries();
51 void addBox();
52 void addBox();
52 void insertBox();
53 void insertBox();
53 void removeBox();
54 void removeBox();
54 void clear();
55 void clear();
55 void setBrush();
56 void setBrush();
56 void animationToggled(bool enabled);
57 void animationToggled(bool enabled);
57 void legendToggled(bool enabled);
58 void legendToggled(bool enabled);
58 void titleToggled(bool enabled);
59 void titleToggled(bool enabled);
59 void modelMapperToggled(bool enabled);
60 void modelMapperToggled(bool enabled);
60 void changeChartTheme(int themeIndex);
61 void changeChartTheme(int themeIndex);
62 void boxClicked(QBoxSet *set);
63 void boxHovered(bool state, QBoxSet *set);
64 void singleBoxClicked();
65 void singleBoxHovered(bool state);
61
66
62 private:
67 private:
63 QChart *m_chart;
68 QChart *m_chart;
64 QChartView *m_chartView;
69 QChartView *m_chartView;
65 QGridLayout *m_scatterLayout;
70 QGridLayout *m_scatterLayout;
66 QBarCategoryAxis *m_axis;
71 QBarCategoryAxis *m_axis;
67 CustomTableModel *m_model;
72 CustomTableModel *m_model;
68 int rowPos;
73 int rowPos;
69 int nSeries;
74 int nSeries;
70 int nNewBoxes;
75 int nNewBoxes;
71 QBoxPlotSeries *m_series[10];
76 QBoxPlotSeries *m_series[10];
72 };
77 };
73
78
74 #endif // MAINWIDGET_H
79 #endif // MAINWIDGET_H
General Comments 0
You need to be logged in to leave comments. Login now