|
@@
-1,642
+1,636
|
|
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 "qbarseries.h"
|
|
21
|
#include "qbarseries.h"
|
|
22
|
#include "qbarseries_p.h"
|
|
22
|
#include "qbarseries_p.h"
|
|
23
|
#include "qbarset.h"
|
|
23
|
#include "qbarset.h"
|
|
24
|
#include "qbarset_p.h"
|
|
24
|
#include "qbarset_p.h"
|
|
25
|
#include "domain_p.h"
|
|
25
|
#include "domain_p.h"
|
|
26
|
#include "legendmarker_p.h"
|
|
26
|
#include "legendmarker_p.h"
|
|
27
|
#include "chartdataset_p.h"
|
|
27
|
#include "chartdataset_p.h"
|
|
28
|
#include "charttheme_p.h"
|
|
28
|
#include "charttheme_p.h"
|
|
29
|
#include "chartanimator_p.h"
|
|
29
|
#include "chartanimator_p.h"
|
|
30
|
|
|
30
|
|
|
31
|
QTCOMMERCIALCHART_BEGIN_NAMESPACE
|
|
31
|
QTCOMMERCIALCHART_BEGIN_NAMESPACE
|
|
32
|
|
|
32
|
|
|
33
|
/*!
|
|
33
|
/*!
|
|
34
|
\class QBarSeries
|
|
34
|
\class QBarSeries
|
|
35
|
\brief part of QtCommercial chart API.
|
|
35
|
\brief part of QtCommercial chart API.
|
|
36
|
\mainclass
|
|
36
|
\mainclass
|
|
37
|
|
|
37
|
|
|
38
|
QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
|
|
38
|
QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
|
|
39
|
the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
|
|
39
|
the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
|
|
40
|
and y-value is the height of the bar. The category names are ignored with this series and x-axis
|
|
40
|
and y-value is the height of the bar. The category names are ignored with this series and x-axis
|
|
41
|
shows the x-values.
|
|
41
|
shows the x-values.
|
|
42
|
|
|
42
|
|
|
43
|
See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
|
|
43
|
See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
|
|
44
|
\image examples_barchart.png
|
|
44
|
\image examples_barchart.png
|
|
45
|
|
|
45
|
|
|
46
|
\sa QBarSet, QStackedBarSeries, QPercentBarSeries
|
|
46
|
\sa QBarSet, QStackedBarSeries, QPercentBarSeries
|
|
47
|
*/
|
|
47
|
*/
|
|
48
|
|
|
48
|
|
|
49
|
/*!
|
|
49
|
/*!
|
|
50
|
\property QBarSeries::barWidth
|
|
50
|
\property QBarSeries::barWidth
|
|
51
|
\brief The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
|
|
51
|
\brief The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
|
|
52
|
is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
|
|
52
|
is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
|
|
53
|
is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
|
|
53
|
is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
|
|
54
|
Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. This is
|
|
54
|
Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. This is
|
|
55
|
because with grouped series it is more logical to set width of whole group and let the chart calculate correct
|
|
55
|
because with grouped series it is more logical to set width of whole group and let the chart calculate correct
|
|
56
|
width for bar.
|
|
56
|
width for bar.
|
|
57
|
\sa QGroupedBarSeries
|
|
57
|
\sa QGroupedBarSeries
|
|
58
|
*/
|
|
58
|
*/
|
|
59
|
|
|
59
|
|
|
60
|
/*!
|
|
60
|
/*!
|
|
61
|
\property QBarSeries::count
|
|
61
|
\property QBarSeries::count
|
|
62
|
\brief Holds the number of sets in series.
|
|
62
|
\brief Holds the number of sets in series.
|
|
63
|
*/
|
|
63
|
*/
|
|
64
|
|
|
64
|
|
|
65
|
/*!
|
|
65
|
/*!
|
|
66
|
\property QBarSeries::labelsVisible
|
|
66
|
\property QBarSeries::labelsVisible
|
|
67
|
\brief Defines the visibility of the labels in series
|
|
67
|
\brief Defines the visibility of the labels in series
|
|
68
|
*/
|
|
68
|
*/
|
|
69
|
|
|
69
|
|
|
70
|
/*!
|
|
70
|
/*!
|
|
71
|
\fn void QBarSeries::clicked(QBarSet *barset, int index)
|
|
71
|
\fn void QBarSeries::clicked(QBarSet *barset, int index)
|
|
72
|
|
|
72
|
|
|
73
|
The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
|
|
73
|
The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
|
|
74
|
Clicked bar inside set is indexed by \a index
|
|
74
|
Clicked bar inside set is indexed by \a index
|
|
75
|
*/
|
|
75
|
*/
|
|
76
|
|
|
76
|
|
|
77
|
/*!
|
|
77
|
/*!
|
|
78
|
\fn void QBarSeries::hovered(QBarSet* barset, bool status)
|
|
78
|
\fn void QBarSeries::hovered(QBarSet* barset, bool status)
|
|
79
|
|
|
79
|
|
|
80
|
The signal is emitted if mouse is hovered on top of series.
|
|
80
|
The signal is emitted if mouse is hovered on top of series.
|
|
81
|
Parameter \a barset is the pointer of barset, where hover happened.
|
|
81
|
Parameter \a barset is the pointer of barset, where hover happened.
|
|
82
|
Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
|
|
82
|
Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
|
|
83
|
*/
|
|
83
|
*/
|
|
84
|
/*!
|
|
|
|
|
85
|
\fn void QBarSeries::barWidthChanged(qreal)
|
|
|
|
|
86
|
|
|
|
|
|
87
|
This signal is emitted when bar width has been changed to \a width.
|
|
|
|
|
88
|
*/
|
|
|
|
|
89
|
|
|
84
|
|
|
90
|
/*!
|
|
85
|
/*!
|
|
91
|
\fn void QBarSeries::countChanged()
|
|
86
|
\fn void QBarSeries::countChanged()
|
|
92
|
|
|
87
|
|
|
93
|
This signal is emitted when barset count has been changed, for example by append or remove.
|
|
88
|
This signal is emitted when barset count has been changed, for example by append or remove.
|
|
94
|
*/
|
|
89
|
*/
|
|
95
|
|
|
90
|
|
|
96
|
/*!
|
|
91
|
/*!
|
|
97
|
\fn void QBarSeries::labelsVisibleChanged()
|
|
92
|
\fn void QBarSeries::labelsVisibleChanged()
|
|
98
|
|
|
93
|
|
|
99
|
This signal is emitted when labels visibility have changed.
|
|
94
|
This signal is emitted when labels visibility have changed.
|
|
100
|
|
|
95
|
|
|
101
|
\sa isLabelsVisible(), setLabelsVisible()
|
|
96
|
\sa isLabelsVisible(), setLabelsVisible()
|
|
102
|
*/
|
|
97
|
*/
|
|
103
|
|
|
98
|
|
|
104
|
/*!
|
|
99
|
/*!
|
|
105
|
\fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets)
|
|
100
|
\fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets)
|
|
106
|
|
|
101
|
|
|
107
|
This signal is emitted when \a sets have been added to the series.
|
|
102
|
This signal is emitted when \a sets have been added to the series.
|
|
108
|
|
|
103
|
|
|
109
|
\sa append(), insert()
|
|
104
|
\sa append(), insert()
|
|
110
|
*/
|
|
105
|
*/
|
|
111
|
|
|
106
|
|
|
112
|
/*!
|
|
107
|
/*!
|
|
113
|
\fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets)
|
|
108
|
\fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets)
|
|
114
|
|
|
109
|
|
|
115
|
This signal is emitted when \a sets have been removed from the series.
|
|
110
|
This signal is emitted when \a sets have been removed from the series.
|
|
116
|
|
|
111
|
|
|
117
|
\sa remove()
|
|
112
|
\sa remove()
|
|
118
|
*/
|
|
113
|
*/
|
|
119
|
|
|
114
|
|
|
120
|
/*!
|
|
115
|
/*!
|
|
121
|
Constructs empty QBarSeries.
|
|
116
|
Constructs empty QBarSeries.
|
|
122
|
QBarSeries is QObject which is a child of a \a parent.
|
|
117
|
QBarSeries is QObject which is a child of a \a parent.
|
|
123
|
*/
|
|
118
|
*/
|
|
124
|
QBarSeries::QBarSeries(QObject *parent) :
|
|
119
|
QBarSeries::QBarSeries(QObject *parent) :
|
|
125
|
QAbstractSeries(*new QBarSeriesPrivate(this),parent)
|
|
120
|
QAbstractSeries(*new QBarSeriesPrivate(this),parent)
|
|
126
|
{
|
|
121
|
{
|
|
127
|
}
|
|
122
|
}
|
|
128
|
|
|
123
|
|
|
129
|
/*!
|
|
124
|
/*!
|
|
130
|
Destructs barseries and owned barsets.
|
|
125
|
Destructs barseries and owned barsets.
|
|
131
|
*/
|
|
126
|
*/
|
|
132
|
QBarSeries::~QBarSeries()
|
|
127
|
QBarSeries::~QBarSeries()
|
|
133
|
{
|
|
128
|
{
|
|
134
|
Q_D(QBarSeries);
|
|
129
|
Q_D(QBarSeries);
|
|
135
|
if(d->m_dataset){
|
|
130
|
if(d->m_dataset){
|
|
136
|
d->m_dataset->removeSeries(this);
|
|
131
|
d->m_dataset->removeSeries(this);
|
|
137
|
}
|
|
132
|
}
|
|
138
|
}
|
|
133
|
}
|
|
139
|
|
|
134
|
|
|
140
|
/*!
|
|
135
|
/*!
|
|
141
|
\internal
|
|
136
|
\internal
|
|
142
|
*/
|
|
137
|
*/
|
|
143
|
QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) :
|
|
138
|
QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) :
|
|
144
|
QAbstractSeries(d,parent)
|
|
139
|
QAbstractSeries(d,parent)
|
|
145
|
{
|
|
140
|
{
|
|
146
|
}
|
|
141
|
}
|
|
147
|
|
|
142
|
|
|
148
|
/*!
|
|
143
|
/*!
|
|
149
|
Returns the type of series. Derived classes override this.
|
|
144
|
Returns the type of series. Derived classes override this.
|
|
150
|
*/
|
|
145
|
*/
|
|
151
|
QAbstractSeries::SeriesType QBarSeries::type() const
|
|
146
|
QAbstractSeries::SeriesType QBarSeries::type() const
|
|
152
|
{
|
|
147
|
{
|
|
153
|
return QAbstractSeries::SeriesTypeBar;
|
|
148
|
return QAbstractSeries::SeriesTypeBar;
|
|
154
|
}
|
|
149
|
}
|
|
155
|
|
|
150
|
|
|
156
|
void QBarSeries::setBarWidth(qreal width)
|
|
151
|
void QBarSeries::setBarWidth(qreal width)
|
|
157
|
{
|
|
152
|
{
|
|
158
|
Q_D(QBarSeries);
|
|
153
|
Q_D(QBarSeries);
|
|
159
|
d->setBarWidth(width);
|
|
154
|
d->setBarWidth(width);
|
|
160
|
emit barWidthChanged(width);
|
|
|
|
|
161
|
}
|
|
155
|
}
|
|
162
|
|
|
156
|
|
|
163
|
qreal QBarSeries::barWidth() const
|
|
157
|
qreal QBarSeries::barWidth() const
|
|
164
|
{
|
|
158
|
{
|
|
165
|
Q_D(const QBarSeries);
|
|
159
|
Q_D(const QBarSeries);
|
|
166
|
return d->barWidth();
|
|
160
|
return d->barWidth();
|
|
167
|
}
|
|
161
|
}
|
|
168
|
|
|
162
|
|
|
169
|
/*!
|
|
163
|
/*!
|
|
170
|
Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
|
|
164
|
Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
|
|
171
|
Returns true, if appending succeeded.
|
|
165
|
Returns true, if appending succeeded.
|
|
172
|
*/
|
|
166
|
*/
|
|
173
|
bool QBarSeries::append(QBarSet *set)
|
|
167
|
bool QBarSeries::append(QBarSet *set)
|
|
174
|
{
|
|
168
|
{
|
|
175
|
Q_D(QBarSeries);
|
|
169
|
Q_D(QBarSeries);
|
|
176
|
bool success = d->append(set);
|
|
170
|
bool success = d->append(set);
|
|
177
|
if (success) {
|
|
171
|
if (success) {
|
|
178
|
QList<QBarSet*> sets;
|
|
172
|
QList<QBarSet*> sets;
|
|
179
|
sets.append(set);
|
|
173
|
sets.append(set);
|
|
180
|
emit barsetsAdded(sets);
|
|
174
|
emit barsetsAdded(sets);
|
|
181
|
emit countChanged();
|
|
175
|
emit countChanged();
|
|
182
|
}
|
|
176
|
}
|
|
183
|
return success;
|
|
177
|
return success;
|
|
184
|
}
|
|
178
|
}
|
|
185
|
|
|
179
|
|
|
186
|
/*!
|
|
180
|
/*!
|
|
187
|
Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
|
|
181
|
Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
|
|
188
|
Returns true, if set was removed.
|
|
182
|
Returns true, if set was removed.
|
|
189
|
*/
|
|
183
|
*/
|
|
190
|
bool QBarSeries::remove(QBarSet *set)
|
|
184
|
bool QBarSeries::remove(QBarSet *set)
|
|
191
|
{
|
|
185
|
{
|
|
192
|
Q_D(QBarSeries);
|
|
186
|
Q_D(QBarSeries);
|
|
193
|
bool success = d->remove(set);
|
|
187
|
bool success = d->remove(set);
|
|
194
|
if (success) {
|
|
188
|
if (success) {
|
|
195
|
QList<QBarSet*> sets;
|
|
189
|
QList<QBarSet*> sets;
|
|
196
|
sets.append(set);
|
|
190
|
sets.append(set);
|
|
197
|
emit barsetsRemoved(sets);
|
|
191
|
emit barsetsRemoved(sets);
|
|
198
|
emit countChanged();
|
|
192
|
emit countChanged();
|
|
199
|
}
|
|
193
|
}
|
|
200
|
return success;
|
|
194
|
return success;
|
|
201
|
}
|
|
195
|
}
|
|
202
|
|
|
196
|
|
|
203
|
/*!
|
|
197
|
/*!
|
|
204
|
Adds a list of barsets to series. Takes ownership of \a sets.
|
|
198
|
Adds a list of barsets to series. Takes ownership of \a sets.
|
|
205
|
Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
|
|
199
|
Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
|
|
206
|
nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
|
|
200
|
nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
|
|
207
|
and function returns false.
|
|
201
|
and function returns false.
|
|
208
|
*/
|
|
202
|
*/
|
|
209
|
bool QBarSeries::append(QList<QBarSet* > sets)
|
|
203
|
bool QBarSeries::append(QList<QBarSet* > sets)
|
|
210
|
{
|
|
204
|
{
|
|
211
|
Q_D(QBarSeries);
|
|
205
|
Q_D(QBarSeries);
|
|
212
|
bool success = d->append(sets);
|
|
206
|
bool success = d->append(sets);
|
|
213
|
if (success) {
|
|
207
|
if (success) {
|
|
214
|
emit barsetsAdded(sets);
|
|
208
|
emit barsetsAdded(sets);
|
|
215
|
emit countChanged();
|
|
209
|
emit countChanged();
|
|
216
|
}
|
|
210
|
}
|
|
217
|
return success;
|
|
211
|
return success;
|
|
218
|
}
|
|
212
|
}
|
|
219
|
|
|
213
|
|
|
220
|
/*!
|
|
214
|
/*!
|
|
221
|
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.
|
|
215
|
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.
|
|
222
|
Returns true, if inserting succeeded.
|
|
216
|
Returns true, if inserting succeeded.
|
|
223
|
|
|
217
|
|
|
224
|
*/
|
|
218
|
*/
|
|
225
|
bool QBarSeries::insert(int index, QBarSet *set)
|
|
219
|
bool QBarSeries::insert(int index, QBarSet *set)
|
|
226
|
{
|
|
220
|
{
|
|
227
|
Q_D(QBarSeries);
|
|
221
|
Q_D(QBarSeries);
|
|
228
|
bool success = d->insert(index, set);
|
|
222
|
bool success = d->insert(index, set);
|
|
229
|
if (success) {
|
|
223
|
if (success) {
|
|
230
|
QList<QBarSet*> sets;
|
|
224
|
QList<QBarSet*> sets;
|
|
231
|
sets.append(set);
|
|
225
|
sets.append(set);
|
|
232
|
emit barsetsAdded(sets);
|
|
226
|
emit barsetsAdded(sets);
|
|
233
|
emit countChanged();
|
|
227
|
emit countChanged();
|
|
234
|
}
|
|
228
|
}
|
|
235
|
return success;
|
|
229
|
return success;
|
|
236
|
}
|
|
230
|
}
|
|
237
|
|
|
231
|
|
|
238
|
/*!
|
|
232
|
/*!
|
|
239
|
Removes all of the bar sets from the series
|
|
233
|
Removes all of the bar sets from the series
|
|
240
|
*/
|
|
234
|
*/
|
|
241
|
void QBarSeries::clear()
|
|
235
|
void QBarSeries::clear()
|
|
242
|
{
|
|
236
|
{
|
|
243
|
Q_D(QBarSeries);
|
|
237
|
Q_D(QBarSeries);
|
|
244
|
QList<QBarSet *> sets = barSets();
|
|
238
|
QList<QBarSet *> sets = barSets();
|
|
245
|
bool success = d->remove(sets);
|
|
239
|
bool success = d->remove(sets);
|
|
246
|
if (success) {
|
|
240
|
if (success) {
|
|
247
|
emit barsetsRemoved(sets);
|
|
241
|
emit barsetsRemoved(sets);
|
|
248
|
emit countChanged();
|
|
242
|
emit countChanged();
|
|
249
|
}
|
|
243
|
}
|
|
250
|
}
|
|
244
|
}
|
|
251
|
|
|
245
|
|
|
252
|
/*!
|
|
246
|
/*!
|
|
253
|
Returns number of sets in series.
|
|
247
|
Returns number of sets in series.
|
|
254
|
*/
|
|
248
|
*/
|
|
255
|
int QBarSeries::count() const
|
|
249
|
int QBarSeries::count() const
|
|
256
|
{
|
|
250
|
{
|
|
257
|
Q_D(const QBarSeries);
|
|
251
|
Q_D(const QBarSeries);
|
|
258
|
return d->m_barSets.count();
|
|
252
|
return d->m_barSets.count();
|
|
259
|
}
|
|
253
|
}
|
|
260
|
|
|
254
|
|
|
261
|
/*!
|
|
255
|
/*!
|
|
262
|
Returns a list of sets in series. Keeps ownership of sets.
|
|
256
|
Returns a list of sets in series. Keeps ownership of sets.
|
|
263
|
*/
|
|
257
|
*/
|
|
264
|
QList<QBarSet*> QBarSeries::barSets() const
|
|
258
|
QList<QBarSet*> QBarSeries::barSets() const
|
|
265
|
{
|
|
259
|
{
|
|
266
|
Q_D(const QBarSeries);
|
|
260
|
Q_D(const QBarSeries);
|
|
267
|
return d->m_barSets;
|
|
261
|
return d->m_barSets;
|
|
268
|
}
|
|
262
|
}
|
|
269
|
|
|
263
|
|
|
270
|
/*!
|
|
264
|
/*!
|
|
271
|
Sets the visibility of labels in series to \a visible
|
|
265
|
Sets the visibility of labels in series to \a visible
|
|
272
|
*/
|
|
266
|
*/
|
|
273
|
void QBarSeries::setLabelsVisible(bool visible)
|
|
267
|
void QBarSeries::setLabelsVisible(bool visible)
|
|
274
|
{
|
|
268
|
{
|
|
275
|
Q_D(QBarSeries);
|
|
269
|
Q_D(QBarSeries);
|
|
276
|
if (d->m_labelsVisible != visible) {
|
|
270
|
if (d->m_labelsVisible != visible) {
|
|
277
|
d->setLabelsVisible(visible);
|
|
271
|
d->setLabelsVisible(visible);
|
|
278
|
emit labelsVisibleChanged();
|
|
272
|
emit labelsVisibleChanged();
|
|
279
|
}
|
|
273
|
}
|
|
280
|
}
|
|
274
|
}
|
|
281
|
|
|
275
|
|
|
282
|
/*!
|
|
276
|
/*!
|
|
283
|
Returns the visibility of labels
|
|
277
|
Returns the visibility of labels
|
|
284
|
*/
|
|
278
|
*/
|
|
285
|
bool QBarSeries::isLabelsVisible() const
|
|
279
|
bool QBarSeries::isLabelsVisible() const
|
|
286
|
{
|
|
280
|
{
|
|
287
|
Q_D(const QBarSeries);
|
|
281
|
Q_D(const QBarSeries);
|
|
288
|
return d->m_labelsVisible;
|
|
282
|
return d->m_labelsVisible;
|
|
289
|
}
|
|
283
|
}
|
|
290
|
|
|
284
|
|
|
291
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
285
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
292
|
|
|
286
|
|
|
293
|
QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
|
|
287
|
QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
|
|
294
|
QAbstractSeriesPrivate(q),
|
|
288
|
QAbstractSeriesPrivate(q),
|
|
295
|
m_barWidth(0.5), // Default value is 50% of category width
|
|
289
|
m_barWidth(0.5), // Default value is 50% of category width
|
|
296
|
m_labelsVisible(false),
|
|
290
|
m_labelsVisible(false),
|
|
297
|
m_visible(true)
|
|
291
|
m_visible(true)
|
|
298
|
{
|
|
292
|
{
|
|
299
|
}
|
|
293
|
}
|
|
300
|
|
|
294
|
|
|
301
|
int QBarSeriesPrivate::categoryCount() const
|
|
295
|
int QBarSeriesPrivate::categoryCount() const
|
|
302
|
{
|
|
296
|
{
|
|
303
|
// No categories defined. return count of longest set.
|
|
297
|
// No categories defined. return count of longest set.
|
|
304
|
int count = 0;
|
|
298
|
int count = 0;
|
|
305
|
for (int i=0; i<m_barSets.count(); i++) {
|
|
299
|
for (int i=0; i<m_barSets.count(); i++) {
|
|
306
|
if (m_barSets.at(i)->count() > count) {
|
|
300
|
if (m_barSets.at(i)->count() > count) {
|
|
307
|
count = m_barSets.at(i)->count();
|
|
301
|
count = m_barSets.at(i)->count();
|
|
308
|
}
|
|
302
|
}
|
|
309
|
}
|
|
303
|
}
|
|
310
|
|
|
304
|
|
|
311
|
return count;
|
|
305
|
return count;
|
|
312
|
}
|
|
306
|
}
|
|
313
|
|
|
307
|
|
|
314
|
void QBarSeriesPrivate::setBarWidth(qreal width)
|
|
308
|
void QBarSeriesPrivate::setBarWidth(qreal width)
|
|
315
|
{
|
|
309
|
{
|
|
316
|
if (width < 0.0) {
|
|
310
|
if (width < 0.0) {
|
|
317
|
width = 0.0;
|
|
311
|
width = 0.0;
|
|
318
|
}
|
|
312
|
}
|
|
319
|
m_barWidth = width;
|
|
313
|
m_barWidth = width;
|
|
320
|
emit updatedBars();
|
|
314
|
emit updatedBars();
|
|
321
|
}
|
|
315
|
}
|
|
322
|
|
|
316
|
|
|
323
|
qreal QBarSeriesPrivate::barWidth() const
|
|
317
|
qreal QBarSeriesPrivate::barWidth() const
|
|
324
|
{
|
|
318
|
{
|
|
325
|
return m_barWidth;
|
|
319
|
return m_barWidth;
|
|
326
|
}
|
|
320
|
}
|
|
327
|
|
|
321
|
|
|
328
|
QBarSet* QBarSeriesPrivate::barsetAt(int index)
|
|
322
|
QBarSet* QBarSeriesPrivate::barsetAt(int index)
|
|
329
|
{
|
|
323
|
{
|
|
330
|
return m_barSets.at(index);
|
|
324
|
return m_barSets.at(index);
|
|
331
|
}
|
|
325
|
}
|
|
332
|
|
|
326
|
|
|
333
|
void QBarSeriesPrivate::setVisible(bool visible)
|
|
327
|
void QBarSeriesPrivate::setVisible(bool visible)
|
|
334
|
{
|
|
328
|
{
|
|
335
|
m_visible = visible;
|
|
329
|
m_visible = visible;
|
|
336
|
emit updatedBars();
|
|
330
|
emit updatedBars();
|
|
337
|
}
|
|
331
|
}
|
|
338
|
|
|
332
|
|
|
339
|
void QBarSeriesPrivate::setLabelsVisible(bool visible)
|
|
333
|
void QBarSeriesPrivate::setLabelsVisible(bool visible)
|
|
340
|
{
|
|
334
|
{
|
|
341
|
m_labelsVisible = visible;
|
|
335
|
m_labelsVisible = visible;
|
|
342
|
emit labelsVisibleChanged(visible);
|
|
336
|
emit labelsVisibleChanged(visible);
|
|
343
|
}
|
|
337
|
}
|
|
344
|
|
|
338
|
|
|
345
|
qreal QBarSeriesPrivate::min()
|
|
339
|
qreal QBarSeriesPrivate::min()
|
|
346
|
{
|
|
340
|
{
|
|
347
|
if (m_barSets.count() <= 0) {
|
|
341
|
if (m_barSets.count() <= 0) {
|
|
348
|
return 0;
|
|
342
|
return 0;
|
|
349
|
}
|
|
343
|
}
|
|
350
|
qreal min = INT_MAX;
|
|
344
|
qreal min = INT_MAX;
|
|
351
|
|
|
345
|
|
|
352
|
for (int i = 0; i < m_barSets.count(); i++) {
|
|
346
|
for (int i = 0; i < m_barSets.count(); i++) {
|
|
353
|
int categoryCount = m_barSets.at(i)->count();
|
|
347
|
int categoryCount = m_barSets.at(i)->count();
|
|
354
|
for (int j = 0; j < categoryCount; j++) {
|
|
348
|
for (int j = 0; j < categoryCount; j++) {
|
|
355
|
qreal temp = m_barSets.at(i)->at(j).y();
|
|
349
|
qreal temp = m_barSets.at(i)->at(j).y();
|
|
356
|
if (temp < min)
|
|
350
|
if (temp < min)
|
|
357
|
min = temp;
|
|
351
|
min = temp;
|
|
358
|
}
|
|
352
|
}
|
|
359
|
}
|
|
353
|
}
|
|
360
|
return min;
|
|
354
|
return min;
|
|
361
|
}
|
|
355
|
}
|
|
362
|
|
|
356
|
|
|
363
|
qreal QBarSeriesPrivate::max()
|
|
357
|
qreal QBarSeriesPrivate::max()
|
|
364
|
{
|
|
358
|
{
|
|
365
|
if (m_barSets.count() <= 0) {
|
|
359
|
if (m_barSets.count() <= 0) {
|
|
366
|
return 0;
|
|
360
|
return 0;
|
|
367
|
}
|
|
361
|
}
|
|
368
|
qreal max = INT_MIN;
|
|
362
|
qreal max = INT_MIN;
|
|
369
|
|
|
363
|
|
|
370
|
for (int i = 0; i < m_barSets.count(); i++) {
|
|
364
|
for (int i = 0; i < m_barSets.count(); i++) {
|
|
371
|
int categoryCount = m_barSets.at(i)->count();
|
|
365
|
int categoryCount = m_barSets.at(i)->count();
|
|
372
|
for (int j = 0; j < categoryCount; j++) {
|
|
366
|
for (int j = 0; j < categoryCount; j++) {
|
|
373
|
qreal temp = m_barSets.at(i)->at(j).y();
|
|
367
|
qreal temp = m_barSets.at(i)->at(j).y();
|
|
374
|
if (temp > max)
|
|
368
|
if (temp > max)
|
|
375
|
max = temp;
|
|
369
|
max = temp;
|
|
376
|
}
|
|
370
|
}
|
|
377
|
}
|
|
371
|
}
|
|
378
|
|
|
372
|
|
|
379
|
return max;
|
|
373
|
return max;
|
|
380
|
}
|
|
374
|
}
|
|
381
|
|
|
375
|
|
|
382
|
qreal QBarSeriesPrivate::valueAt(int set, int category)
|
|
376
|
qreal QBarSeriesPrivate::valueAt(int set, int category)
|
|
383
|
{
|
|
377
|
{
|
|
384
|
if ((set < 0) || (set >= m_barSets.count())) {
|
|
378
|
if ((set < 0) || (set >= m_barSets.count())) {
|
|
385
|
// No set, no value.
|
|
379
|
// No set, no value.
|
|
386
|
return 0;
|
|
380
|
return 0;
|
|
387
|
} else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
|
|
381
|
} else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
|
|
388
|
// No category, no value.
|
|
382
|
// No category, no value.
|
|
389
|
return 0;
|
|
383
|
return 0;
|
|
390
|
}
|
|
384
|
}
|
|
391
|
|
|
385
|
|
|
392
|
return m_barSets.at(set)->at(category).y();
|
|
386
|
return m_barSets.at(set)->at(category).y();
|
|
393
|
}
|
|
387
|
}
|
|
394
|
|
|
388
|
|
|
395
|
qreal QBarSeriesPrivate::percentageAt(int set, int category)
|
|
389
|
qreal QBarSeriesPrivate::percentageAt(int set, int category)
|
|
396
|
{
|
|
390
|
{
|
|
397
|
if ((set < 0) || (set >= m_barSets.count())) {
|
|
391
|
if ((set < 0) || (set >= m_barSets.count())) {
|
|
398
|
// No set, no value.
|
|
392
|
// No set, no value.
|
|
399
|
return 0;
|
|
393
|
return 0;
|
|
400
|
} else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
|
|
394
|
} else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
|
|
401
|
// No category, no value.
|
|
395
|
// No category, no value.
|
|
402
|
return 0;
|
|
396
|
return 0;
|
|
403
|
}
|
|
397
|
}
|
|
404
|
|
|
398
|
|
|
405
|
qreal value = m_barSets.at(set)->at(category).y();
|
|
399
|
qreal value = m_barSets.at(set)->at(category).y();
|
|
406
|
qreal sum = categorySum(category);
|
|
400
|
qreal sum = categorySum(category);
|
|
407
|
if ( qFuzzyIsNull(sum) ) {
|
|
401
|
if ( qFuzzyIsNull(sum) ) {
|
|
408
|
return 0;
|
|
402
|
return 0;
|
|
409
|
}
|
|
403
|
}
|
|
410
|
|
|
404
|
|
|
411
|
return value / sum;
|
|
405
|
return value / sum;
|
|
412
|
}
|
|
406
|
}
|
|
413
|
|
|
407
|
|
|
414
|
qreal QBarSeriesPrivate::categorySum(int category)
|
|
408
|
qreal QBarSeriesPrivate::categorySum(int category)
|
|
415
|
{
|
|
409
|
{
|
|
416
|
qreal sum(0);
|
|
410
|
qreal sum(0);
|
|
417
|
int count = m_barSets.count(); // Count sets
|
|
411
|
int count = m_barSets.count(); // Count sets
|
|
418
|
for (int set = 0; set < count; set++) {
|
|
412
|
for (int set = 0; set < count; set++) {
|
|
419
|
if (category < m_barSets.at(set)->count())
|
|
413
|
if (category < m_barSets.at(set)->count())
|
|
420
|
sum += m_barSets.at(set)->at(category).y();
|
|
414
|
sum += m_barSets.at(set)->at(category).y();
|
|
421
|
}
|
|
415
|
}
|
|
422
|
return sum;
|
|
416
|
return sum;
|
|
423
|
}
|
|
417
|
}
|
|
424
|
|
|
418
|
|
|
425
|
qreal QBarSeriesPrivate::absoluteCategorySum(int category)
|
|
419
|
qreal QBarSeriesPrivate::absoluteCategorySum(int category)
|
|
426
|
{
|
|
420
|
{
|
|
427
|
qreal sum(0);
|
|
421
|
qreal sum(0);
|
|
428
|
int count = m_barSets.count(); // Count sets
|
|
422
|
int count = m_barSets.count(); // Count sets
|
|
429
|
for (int set = 0; set < count; set++) {
|
|
423
|
for (int set = 0; set < count; set++) {
|
|
430
|
if (category < m_barSets.at(set)->count())
|
|
424
|
if (category < m_barSets.at(set)->count())
|
|
431
|
sum += qAbs(m_barSets.at(set)->at(category).y());
|
|
425
|
sum += qAbs(m_barSets.at(set)->at(category).y());
|
|
432
|
}
|
|
426
|
}
|
|
433
|
return sum;
|
|
427
|
return sum;
|
|
434
|
}
|
|
428
|
}
|
|
435
|
|
|
429
|
|
|
436
|
qreal QBarSeriesPrivate::maxCategorySum()
|
|
430
|
qreal QBarSeriesPrivate::maxCategorySum()
|
|
437
|
{
|
|
431
|
{
|
|
438
|
qreal max = INT_MIN;
|
|
432
|
qreal max = INT_MIN;
|
|
439
|
int count = categoryCount();
|
|
433
|
int count = categoryCount();
|
|
440
|
for (int i = 0; i < count; i++) {
|
|
434
|
for (int i = 0; i < count; i++) {
|
|
441
|
qreal sum = categorySum(i);
|
|
435
|
qreal sum = categorySum(i);
|
|
442
|
if (sum > max)
|
|
436
|
if (sum > max)
|
|
443
|
max = sum;
|
|
437
|
max = sum;
|
|
444
|
}
|
|
438
|
}
|
|
445
|
return max;
|
|
439
|
return max;
|
|
446
|
}
|
|
440
|
}
|
|
447
|
|
|
441
|
|
|
448
|
qreal QBarSeriesPrivate::minX()
|
|
442
|
qreal QBarSeriesPrivate::minX()
|
|
449
|
{
|
|
443
|
{
|
|
450
|
if (m_barSets.count() <= 0) {
|
|
444
|
if (m_barSets.count() <= 0) {
|
|
451
|
return 0;
|
|
445
|
return 0;
|
|
452
|
}
|
|
446
|
}
|
|
453
|
qreal min = INT_MAX;
|
|
447
|
qreal min = INT_MAX;
|
|
454
|
|
|
448
|
|
|
455
|
for (int i = 0; i < m_barSets.count(); i++) {
|
|
449
|
for (int i = 0; i < m_barSets.count(); i++) {
|
|
456
|
int categoryCount = m_barSets.at(i)->count();
|
|
450
|
int categoryCount = m_barSets.at(i)->count();
|
|
457
|
for (int j = 0; j < categoryCount; j++) {
|
|
451
|
for (int j = 0; j < categoryCount; j++) {
|
|
458
|
qreal temp = m_barSets.at(i)->at(j).x();
|
|
452
|
qreal temp = m_barSets.at(i)->at(j).x();
|
|
459
|
if (temp < min)
|
|
453
|
if (temp < min)
|
|
460
|
min = temp;
|
|
454
|
min = temp;
|
|
461
|
}
|
|
455
|
}
|
|
462
|
}
|
|
456
|
}
|
|
463
|
return min;
|
|
457
|
return min;
|
|
464
|
}
|
|
458
|
}
|
|
465
|
|
|
459
|
|
|
466
|
qreal QBarSeriesPrivate::maxX()
|
|
460
|
qreal QBarSeriesPrivate::maxX()
|
|
467
|
{
|
|
461
|
{
|
|
468
|
if (m_barSets.count() <= 0) {
|
|
462
|
if (m_barSets.count() <= 0) {
|
|
469
|
return 0;
|
|
463
|
return 0;
|
|
470
|
}
|
|
464
|
}
|
|
471
|
qreal max = INT_MIN;
|
|
465
|
qreal max = INT_MIN;
|
|
472
|
|
|
466
|
|
|
473
|
for (int i = 0; i < m_barSets.count(); i++) {
|
|
467
|
for (int i = 0; i < m_barSets.count(); i++) {
|
|
474
|
int categoryCount = m_barSets.at(i)->count();
|
|
468
|
int categoryCount = m_barSets.at(i)->count();
|
|
475
|
for (int j = 0; j < categoryCount; j++) {
|
|
469
|
for (int j = 0; j < categoryCount; j++) {
|
|
476
|
qreal temp = m_barSets.at(i)->at(j).x();
|
|
470
|
qreal temp = m_barSets.at(i)->at(j).x();
|
|
477
|
if (temp > max)
|
|
471
|
if (temp > max)
|
|
478
|
max = temp;
|
|
472
|
max = temp;
|
|
479
|
}
|
|
473
|
}
|
|
480
|
}
|
|
474
|
}
|
|
481
|
|
|
475
|
|
|
482
|
return max;
|
|
476
|
return max;
|
|
483
|
}
|
|
477
|
}
|
|
484
|
|
|
478
|
|
|
485
|
|
|
479
|
|
|
486
|
void QBarSeriesPrivate::scaleDomain(Domain& domain)
|
|
480
|
void QBarSeriesPrivate::scaleDomain(Domain& domain)
|
|
487
|
{
|
|
481
|
{
|
|
488
|
qreal minX(domain.minX());
|
|
482
|
qreal minX(domain.minX());
|
|
489
|
qreal minY(domain.minY());
|
|
483
|
qreal minY(domain.minY());
|
|
490
|
qreal maxX(domain.maxX());
|
|
484
|
qreal maxX(domain.maxX());
|
|
491
|
qreal maxY(domain.maxY());
|
|
485
|
qreal maxY(domain.maxY());
|
|
492
|
int tickXCount(domain.tickXCount());
|
|
486
|
int tickXCount(domain.tickXCount());
|
|
493
|
int tickYCount(domain.tickYCount());
|
|
487
|
int tickYCount(domain.tickYCount());
|
|
494
|
|
|
488
|
|
|
495
|
qreal seriesMinX = this->minX();
|
|
489
|
qreal seriesMinX = this->minX();
|
|
496
|
qreal seriesMaxX = this->maxX();
|
|
490
|
qreal seriesMaxX = this->maxX();
|
|
497
|
qreal y = max();
|
|
491
|
qreal y = max();
|
|
498
|
minX = qMin(minX, seriesMinX - 0.5);
|
|
492
|
minX = qMin(minX, seriesMinX - 0.5);
|
|
499
|
minY = qMin(minY, y);
|
|
493
|
minY = qMin(minY, y);
|
|
500
|
maxX = qMax(maxX, seriesMaxX + 0.5);
|
|
494
|
maxX = qMax(maxX, seriesMaxX + 0.5);
|
|
501
|
maxY = qMax(maxY, y);
|
|
495
|
maxY = qMax(maxY, y);
|
|
502
|
tickXCount = categoryCount()+1;
|
|
496
|
tickXCount = categoryCount()+1;
|
|
503
|
|
|
497
|
|
|
504
|
domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
|
|
498
|
domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
|
|
505
|
}
|
|
499
|
}
|
|
506
|
|
|
500
|
|
|
507
|
Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
|
|
501
|
Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
|
|
508
|
{
|
|
502
|
{
|
|
509
|
Q_Q(QBarSeries);
|
|
503
|
Q_Q(QBarSeries);
|
|
510
|
|
|
504
|
|
|
511
|
BarChartItem* bar = new BarChartItem(q,presenter);
|
|
505
|
BarChartItem* bar = new BarChartItem(q,presenter);
|
|
512
|
if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
|
|
506
|
if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
|
|
513
|
presenter->animator()->addAnimation(bar);
|
|
507
|
presenter->animator()->addAnimation(bar);
|
|
514
|
}
|
|
508
|
}
|
|
515
|
presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
|
|
509
|
presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
|
|
516
|
return bar;
|
|
510
|
return bar;
|
|
517
|
|
|
511
|
|
|
518
|
}
|
|
512
|
}
|
|
519
|
|
|
513
|
|
|
520
|
QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
|
|
514
|
QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
|
|
521
|
{
|
|
515
|
{
|
|
522
|
Q_Q(QBarSeries);
|
|
516
|
Q_Q(QBarSeries);
|
|
523
|
QList<LegendMarker*> markers;
|
|
517
|
QList<LegendMarker*> markers;
|
|
524
|
foreach(QBarSet* set, q->barSets()) {
|
|
518
|
foreach(QBarSet* set, q->barSets()) {
|
|
525
|
BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
|
|
519
|
BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
|
|
526
|
markers << marker;
|
|
520
|
markers << marker;
|
|
527
|
}
|
|
521
|
}
|
|
528
|
|
|
522
|
|
|
529
|
return markers;
|
|
523
|
return markers;
|
|
530
|
}
|
|
524
|
}
|
|
531
|
|
|
525
|
|
|
532
|
bool QBarSeriesPrivate::append(QBarSet *set)
|
|
526
|
bool QBarSeriesPrivate::append(QBarSet *set)
|
|
533
|
{
|
|
527
|
{
|
|
534
|
Q_Q(QBarSeries);
|
|
528
|
Q_Q(QBarSeries);
|
|
535
|
if ((m_barSets.contains(set)) || (set == 0)) {
|
|
529
|
if ((m_barSets.contains(set)) || (set == 0)) {
|
|
536
|
// Fail if set is already in list or set is null.
|
|
530
|
// Fail if set is already in list or set is null.
|
|
537
|
return false;
|
|
531
|
return false;
|
|
538
|
}
|
|
532
|
}
|
|
539
|
m_barSets.append(set);
|
|
533
|
m_barSets.append(set);
|
|
540
|
QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
|
|
534
|
QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
|
|
541
|
QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
|
|
535
|
QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
|
|
542
|
emit restructuredBars(); // this notifies barchartitem
|
|
536
|
emit restructuredBars(); // this notifies barchartitem
|
|
543
|
if (m_dataset) {
|
|
537
|
if (m_dataset) {
|
|
544
|
m_dataset->updateSeries(q); // this notifies legend
|
|
538
|
m_dataset->updateSeries(q); // this notifies legend
|
|
545
|
}
|
|
539
|
}
|
|
546
|
return true;
|
|
540
|
return true;
|
|
547
|
}
|
|
541
|
}
|
|
548
|
|
|
542
|
|
|
549
|
bool QBarSeriesPrivate::remove(QBarSet *set)
|
|
543
|
bool QBarSeriesPrivate::remove(QBarSet *set)
|
|
550
|
{
|
|
544
|
{
|
|
551
|
Q_Q(QBarSeries);
|
|
545
|
Q_Q(QBarSeries);
|
|
552
|
if (!m_barSets.contains(set)) {
|
|
546
|
if (!m_barSets.contains(set)) {
|
|
553
|
// Fail if set is not in list
|
|
547
|
// Fail if set is not in list
|
|
554
|
return false;
|
|
548
|
return false;
|
|
555
|
}
|
|
549
|
}
|
|
556
|
m_barSets.removeOne(set);
|
|
550
|
m_barSets.removeOne(set);
|
|
557
|
QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
|
|
551
|
QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
|
|
558
|
QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
|
|
552
|
QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
|
|
559
|
emit restructuredBars(); // this notifies barchartitem
|
|
553
|
emit restructuredBars(); // this notifies barchartitem
|
|
560
|
if (m_dataset) {
|
|
554
|
if (m_dataset) {
|
|
561
|
m_dataset->updateSeries(q); // this notifies legend
|
|
555
|
m_dataset->updateSeries(q); // this notifies legend
|
|
562
|
}
|
|
556
|
}
|
|
563
|
return true;
|
|
557
|
return true;
|
|
564
|
}
|
|
558
|
}
|
|
565
|
|
|
559
|
|
|
566
|
bool QBarSeriesPrivate::append(QList<QBarSet* > sets)
|
|
560
|
bool QBarSeriesPrivate::append(QList<QBarSet* > sets)
|
|
567
|
{
|
|
561
|
{
|
|
568
|
Q_Q(QBarSeries);
|
|
562
|
Q_Q(QBarSeries);
|
|
569
|
foreach (QBarSet* set, sets) {
|
|
563
|
foreach (QBarSet* set, sets) {
|
|
570
|
if ((set == 0) || (m_barSets.contains(set))) {
|
|
564
|
if ((set == 0) || (m_barSets.contains(set))) {
|
|
571
|
// Fail if any of the sets is null or is already appended.
|
|
565
|
// Fail if any of the sets is null or is already appended.
|
|
572
|
return false;
|
|
566
|
return false;
|
|
573
|
}
|
|
567
|
}
|
|
574
|
if (sets.count(set) != 1) {
|
|
568
|
if (sets.count(set) != 1) {
|
|
575
|
// Also fail if same set is more than once in given list.
|
|
569
|
// Also fail if same set is more than once in given list.
|
|
576
|
return false;
|
|
570
|
return false;
|
|
577
|
}
|
|
571
|
}
|
|
578
|
}
|
|
572
|
}
|
|
579
|
|
|
573
|
|
|
580
|
foreach (QBarSet* set, sets) {
|
|
574
|
foreach (QBarSet* set, sets) {
|
|
581
|
m_barSets.append(set);
|
|
575
|
m_barSets.append(set);
|
|
582
|
QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
|
|
576
|
QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
|
|
583
|
QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
|
|
577
|
QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
|
|
584
|
}
|
|
578
|
}
|
|
585
|
emit restructuredBars(); // this notifies barchartitem
|
|
579
|
emit restructuredBars(); // this notifies barchartitem
|
|
586
|
if (m_dataset) {
|
|
580
|
if (m_dataset) {
|
|
587
|
m_dataset->updateSeries(q); // this notifies legend
|
|
581
|
m_dataset->updateSeries(q); // this notifies legend
|
|
588
|
}
|
|
582
|
}
|
|
589
|
return true;
|
|
583
|
return true;
|
|
590
|
}
|
|
584
|
}
|
|
591
|
|
|
585
|
|
|
592
|
bool QBarSeriesPrivate::remove(QList<QBarSet* > sets)
|
|
586
|
bool QBarSeriesPrivate::remove(QList<QBarSet* > sets)
|
|
593
|
{
|
|
587
|
{
|
|
594
|
Q_Q(QBarSeries);
|
|
588
|
Q_Q(QBarSeries);
|
|
595
|
if (sets.count() == 0) {
|
|
589
|
if (sets.count() == 0) {
|
|
596
|
return false;
|
|
590
|
return false;
|
|
597
|
}
|
|
591
|
}
|
|
598
|
foreach (QBarSet* set, sets) {
|
|
592
|
foreach (QBarSet* set, sets) {
|
|
599
|
if ((set == 0) || (!m_barSets.contains(set))) {
|
|
593
|
if ((set == 0) || (!m_barSets.contains(set))) {
|
|
600
|
// Fail if any of the sets is null or is not in series
|
|
594
|
// Fail if any of the sets is null or is not in series
|
|
601
|
return false;
|
|
595
|
return false;
|
|
602
|
}
|
|
596
|
}
|
|
603
|
if (sets.count(set) != 1) {
|
|
597
|
if (sets.count(set) != 1) {
|
|
604
|
// Also fail if same set is more than once in given list.
|
|
598
|
// Also fail if same set is more than once in given list.
|
|
605
|
return false;
|
|
599
|
return false;
|
|
606
|
}
|
|
600
|
}
|
|
607
|
}
|
|
601
|
}
|
|
608
|
|
|
602
|
|
|
609
|
foreach (QBarSet* set, sets) {
|
|
603
|
foreach (QBarSet* set, sets) {
|
|
610
|
m_barSets.removeOne(set);
|
|
604
|
m_barSets.removeOne(set);
|
|
611
|
QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
|
|
605
|
QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
|
|
612
|
QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
|
|
606
|
QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
|
|
613
|
}
|
|
607
|
}
|
|
614
|
|
|
608
|
|
|
615
|
emit restructuredBars(); // this notifies barchartitem
|
|
609
|
emit restructuredBars(); // this notifies barchartitem
|
|
616
|
if (m_dataset) {
|
|
610
|
if (m_dataset) {
|
|
617
|
m_dataset->updateSeries(q); // this notifies legend
|
|
611
|
m_dataset->updateSeries(q); // this notifies legend
|
|
618
|
}
|
|
612
|
}
|
|
619
|
return true;
|
|
613
|
return true;
|
|
620
|
}
|
|
614
|
}
|
|
621
|
|
|
615
|
|
|
622
|
bool QBarSeriesPrivate::insert(int index, QBarSet *set)
|
|
616
|
bool QBarSeriesPrivate::insert(int index, QBarSet *set)
|
|
623
|
{
|
|
617
|
{
|
|
624
|
Q_Q(QBarSeries);
|
|
618
|
Q_Q(QBarSeries);
|
|
625
|
if ((m_barSets.contains(set)) || (set == 0)) {
|
|
619
|
if ((m_barSets.contains(set)) || (set == 0)) {
|
|
626
|
// Fail if set is already in list or set is null.
|
|
620
|
// Fail if set is already in list or set is null.
|
|
627
|
return false;
|
|
621
|
return false;
|
|
628
|
}
|
|
622
|
}
|
|
629
|
m_barSets.insert(index, set);
|
|
623
|
m_barSets.insert(index, set);
|
|
630
|
QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
|
|
624
|
QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
|
|
631
|
QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
|
|
625
|
QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
|
|
632
|
emit restructuredBars(); // this notifies barchartitem
|
|
626
|
emit restructuredBars(); // this notifies barchartitem
|
|
633
|
if (m_dataset) {
|
|
627
|
if (m_dataset) {
|
|
634
|
m_dataset->updateSeries(q); // this notifies legend
|
|
628
|
m_dataset->updateSeries(q); // this notifies legend
|
|
635
|
}
|
|
629
|
}
|
|
636
|
return true;
|
|
630
|
return true;
|
|
637
|
}
|
|
631
|
}
|
|
638
|
|
|
632
|
|
|
639
|
#include "moc_qbarseries.cpp"
|
|
633
|
#include "moc_qbarseries.cpp"
|
|
640
|
#include "moc_qbarseries_p.cpp"
|
|
634
|
#include "moc_qbarseries_p.cpp"
|
|
641
|
|
|
635
|
|
|
642
|
QTCOMMERCIALCHART_END_NAMESPACE
|
|
636
|
QTCOMMERCIALCHART_END_NAMESPACE
|