|
@@
-1,811
+1,811
|
|
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 "barchartmodel_p.h"
|
|
25
|
#include "barchartmodel_p.h"
|
|
26
|
#include "domain_p.h"
|
|
26
|
#include "domain_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
|
#include <QAbstractItemModel>
|
|
31
|
#include <QAbstractItemModel>
|
|
32
|
#include <QModelIndex>
|
|
32
|
#include <QModelIndex>
|
|
33
|
|
|
33
|
|
|
34
|
QTCOMMERCIALCHART_BEGIN_NAMESPACE
|
|
34
|
QTCOMMERCIALCHART_BEGIN_NAMESPACE
|
|
35
|
|
|
35
|
|
|
36
|
/*!
|
|
36
|
/*!
|
|
37
|
\class QBarSeries
|
|
37
|
\class QBarSeries
|
|
38
|
\brief part of QtCommercial chart API.
|
|
38
|
\brief part of QtCommercial chart API.
|
|
39
|
|
|
39
|
|
|
40
|
QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible
|
|
40
|
QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible
|
|
41
|
QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined
|
|
41
|
QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined
|
|
42
|
by QStringList.
|
|
42
|
by QStringList.
|
|
43
|
|
|
43
|
|
|
44
|
\mainclass
|
|
44
|
\mainclass
|
|
45
|
|
|
45
|
|
|
46
|
\sa QBarSet, QStackedBarSeries, QPercentBarSeries
|
|
46
|
\sa QBarSet, QStackedBarSeries, QPercentBarSeries
|
|
47
|
*/
|
|
47
|
*/
|
|
48
|
|
|
48
|
|
|
49
|
/*!
|
|
49
|
/*!
|
|
50
|
\fn virtual QSeriesType QBarSeries::type() const
|
|
50
|
\fn virtual QSeriesType QBarSeries::type() const
|
|
51
|
\brief Returns type of series.
|
|
51
|
\brief Returns type of series.
|
|
52
|
\sa QSeries, QSeriesType
|
|
52
|
\sa QSeries, QSeriesType
|
|
53
|
*/
|
|
53
|
*/
|
|
54
|
|
|
54
|
|
|
55
|
/*!
|
|
55
|
/*!
|
|
56
|
\fn void QBarSeries::showToolTip(QPoint pos, QString tip)
|
|
56
|
\fn void QBarSeries::showToolTip(QPoint pos, QString tip)
|
|
57
|
\brief \internal \a pos \a tip
|
|
57
|
\brief \internal \a pos \a tip
|
|
58
|
*/
|
|
58
|
*/
|
|
59
|
|
|
59
|
|
|
60
|
/*!
|
|
60
|
/*!
|
|
61
|
Constructs empty QBarSeries. Parameter \a categories defines the categories for chart.
|
|
61
|
Constructs empty QBarSeries. Parameter \a categories defines the categories for chart.
|
|
62
|
QBarSeries is QObject which is a child of a \a parent.
|
|
62
|
QBarSeries is QObject which is a child of a \a parent.
|
|
63
|
*/
|
|
63
|
*/
|
|
64
|
|
|
64
|
|
|
65
|
QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(*new QBarSeriesPrivate(categories, this),parent)
|
|
65
|
QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(*new QBarSeriesPrivate(categories, this),parent)
|
|
66
|
{
|
|
66
|
{
|
|
67
|
|
|
67
|
|
|
68
|
}
|
|
68
|
}
|
|
69
|
|
|
69
|
|
|
70
|
QBarSeries::QBarSeries(QBarSeriesPrivate &d,QObject *parent) : QSeries(d,parent)
|
|
70
|
QBarSeries::QBarSeries(QBarSeriesPrivate &d,QObject *parent) : QSeries(d,parent)
|
|
71
|
{
|
|
71
|
{
|
|
72
|
|
|
72
|
|
|
73
|
}
|
|
73
|
}
|
|
74
|
|
|
74
|
|
|
75
|
QSeries::QSeriesType QBarSeries::type() const
|
|
75
|
QSeries::QSeriesType QBarSeries::type() const
|
|
76
|
{
|
|
76
|
{
|
|
77
|
return QSeries::SeriesTypeBar;
|
|
77
|
return QSeries::SeriesTypeBar;
|
|
78
|
}
|
|
78
|
}
|
|
79
|
|
|
79
|
|
|
80
|
/*!
|
|
80
|
/*!
|
|
81
|
Adds a set of bars to series. Takes ownership of \a set.
|
|
81
|
Adds a set of bars to series. Takes ownership of \a set.
|
|
82
|
Connects the clicked(QString, Qt::MouseButtons) signal
|
|
82
|
Connects the clicked(QString, Qt::MouseButtons) signal
|
|
83
|
of \a set to this series
|
|
83
|
of \a set to this series
|
|
84
|
*/
|
|
84
|
*/
|
|
85
|
void QBarSeries::appendBarSet(QBarSet *set)
|
|
85
|
void QBarSeries::appendBarSet(QBarSet *set)
|
|
86
|
{
|
|
86
|
{
|
|
87
|
Q_D(QBarSeries);
|
|
87
|
Q_D(QBarSeries);
|
|
88
|
d->m_internalModel->appendBarSet(set);
|
|
88
|
d->m_internalModel->appendBarSet(set);
|
|
89
|
QObject::connect(set->d_ptr.data(), SIGNAL(clicked(QString,Qt::MouseButtons)), d, SLOT(barsetClicked(QString,Qt::MouseButtons)));
|
|
89
|
QObject::connect(set->d_ptr.data(), SIGNAL(clicked(QString,Qt::MouseButtons)), d, SLOT(barsetClicked(QString,Qt::MouseButtons)));
|
|
90
|
QObject::connect(set->d_ptr.data(), SIGNAL(valueChanged()), d, SLOT(barsetChanged()));
|
|
90
|
QObject::connect(set->d_ptr.data(), SIGNAL(valueChanged()), d, SLOT(barsetChanged()));
|
|
91
|
emit d->restructuredBars();
|
|
91
|
emit d->restructuredBars();
|
|
92
|
}
|
|
92
|
}
|
|
93
|
|
|
93
|
|
|
94
|
/*!
|
|
94
|
/*!
|
|
95
|
Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set.
|
|
95
|
Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set.
|
|
96
|
Disconnects the clicked(QString, Qt::MouseButtons) signal
|
|
96
|
Disconnects the clicked(QString, Qt::MouseButtons) signal
|
|
97
|
of \a set from this series
|
|
97
|
of \a set from this series
|
|
98
|
*/
|
|
98
|
*/
|
|
99
|
void QBarSeries::removeBarSet(QBarSet *set)
|
|
99
|
void QBarSeries::removeBarSet(QBarSet *set)
|
|
100
|
{
|
|
100
|
{
|
|
101
|
Q_D(QBarSeries);
|
|
101
|
Q_D(QBarSeries);
|
|
102
|
QObject::disconnect(set->d_ptr.data(), SIGNAL(clicked(QString,Qt::MouseButtons)), d, SLOT(barsetClicked(QString,Qt::MouseButtons)));
|
|
102
|
QObject::disconnect(set->d_ptr.data(), SIGNAL(clicked(QString,Qt::MouseButtons)), d, SLOT(barsetClicked(QString,Qt::MouseButtons)));
|
|
103
|
d->m_internalModel->removeBarSet(set);
|
|
103
|
d->m_internalModel->removeBarSet(set);
|
|
104
|
emit d->restructuredBars();
|
|
104
|
emit d->restructuredBars();
|
|
105
|
}
|
|
105
|
}
|
|
106
|
|
|
106
|
|
|
107
|
/*!
|
|
107
|
/*!
|
|
108
|
Adds a list of barsets to series. Takes ownership of \a sets.
|
|
108
|
Adds a list of barsets to series. Takes ownership of \a sets.
|
|
109
|
Connects the clicked(QString, Qt::MouseButtons) signals
|
|
109
|
Connects the clicked(QString, Qt::MouseButtons) signals
|
|
110
|
of \a sets to this series
|
|
110
|
of \a sets to this series
|
|
111
|
*/
|
|
111
|
*/
|
|
112
|
void QBarSeries::appendBarSets(QList<QBarSet* > sets)
|
|
112
|
void QBarSeries::appendBarSets(QList<QBarSet* > sets)
|
|
113
|
{
|
|
113
|
{
|
|
114
|
Q_D(QBarSeries);
|
|
114
|
Q_D(QBarSeries);
|
|
115
|
foreach (QBarSet* barset, sets) {
|
|
115
|
foreach (QBarSet* barset, sets) {
|
|
116
|
d->m_internalModel->appendBarSet(barset);
|
|
116
|
d->m_internalModel->appendBarSet(barset);
|
|
117
|
QObject::connect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons)));
|
|
117
|
QObject::connect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons)));
|
|
118
|
QObject::connect(barset, SIGNAL(valueChanged()), this, SLOT(barsetChanged()));
|
|
118
|
QObject::connect(barset, SIGNAL(valueChanged()), this, SLOT(barsetChanged()));
|
|
119
|
}
|
|
119
|
}
|
|
120
|
emit d->restructuredBars();
|
|
120
|
emit d->restructuredBars();
|
|
121
|
|
|
121
|
|
|
122
|
}
|
|
122
|
}
|
|
123
|
|
|
123
|
|
|
124
|
/*!
|
|
124
|
/*!
|
|
125
|
Removes a list of barsets from series. Releases ownership of \a sets. Doesnt delete \a sets.
|
|
125
|
Removes a list of barsets from series. Releases ownership of \a sets. Doesnt delete \a sets.
|
|
126
|
Disconnects the clicked(QString, Qt::MouseButtons) signal
|
|
126
|
Disconnects the clicked(QString, Qt::MouseButtons) signal
|
|
127
|
of \a sets from this series
|
|
127
|
of \a sets from this series
|
|
128
|
*/
|
|
128
|
*/
|
|
129
|
void QBarSeries::removeBarSets(QList<QBarSet* > sets)
|
|
129
|
void QBarSeries::removeBarSets(QList<QBarSet* > sets)
|
|
130
|
{
|
|
130
|
{
|
|
131
|
Q_D(QBarSeries);
|
|
131
|
Q_D(QBarSeries);
|
|
132
|
|
|
132
|
|
|
133
|
foreach (QBarSet* barset, sets) {
|
|
133
|
foreach (QBarSet* barset, sets) {
|
|
134
|
QObject::disconnect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons)));
|
|
134
|
QObject::disconnect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons)));
|
|
135
|
d->m_internalModel->removeBarSet(barset);
|
|
135
|
d->m_internalModel->removeBarSet(barset);
|
|
136
|
}
|
|
136
|
}
|
|
137
|
emit d->restructuredBars();
|
|
137
|
emit d->restructuredBars();
|
|
138
|
}
|
|
138
|
}
|
|
139
|
|
|
139
|
|
|
140
|
/*!
|
|
140
|
/*!
|
|
141
|
Inserts new \a set on the \a i position.
|
|
141
|
Inserts new \a set on the \a i position.
|
|
142
|
The barset that is currently at this postion is moved to postion i + 1
|
|
142
|
The barset that is currently at this postion is moved to postion i + 1
|
|
143
|
*/
|
|
143
|
*/
|
|
144
|
void QBarSeries::insertBarSet(int i, QBarSet *set)
|
|
144
|
void QBarSeries::insertBarSet(int i, QBarSet *set)
|
|
145
|
{
|
|
145
|
{
|
|
146
|
Q_D(QBarSeries);
|
|
146
|
Q_D(QBarSeries);
|
|
147
|
d->m_internalModel->insertBarSet(i, set);
|
|
147
|
d->m_internalModel->insertBarSet(i, set);
|
|
148
|
emit d->barsetChanged();
|
|
148
|
emit d->barsetChanged();
|
|
149
|
}
|
|
149
|
}
|
|
150
|
|
|
150
|
|
|
151
|
/*!
|
|
151
|
/*!
|
|
152
|
Inserts new \a category on the \a i position.
|
|
152
|
Inserts new \a category on the \a i position.
|
|
153
|
The category that is currently at this postion is moved to postion i + 1
|
|
153
|
The category that is currently at this postion is moved to postion i + 1
|
|
154
|
\sa removeCategory()
|
|
154
|
\sa removeCategory()
|
|
155
|
*/
|
|
155
|
*/
|
|
156
|
void QBarSeries::insertCategory(int i, QString category)
|
|
156
|
void QBarSeries::insertCategory(int i, QString category)
|
|
157
|
{
|
|
157
|
{
|
|
158
|
Q_D(QBarSeries);
|
|
158
|
Q_D(QBarSeries);
|
|
159
|
d->m_internalModel->insertCategory(i, category);
|
|
159
|
d->m_internalModel->insertCategory(i, category);
|
|
160
|
}
|
|
160
|
}
|
|
161
|
|
|
161
|
|
|
162
|
/*!
|
|
162
|
/*!
|
|
163
|
Removes the category specified by \a i
|
|
163
|
Removes the category specified by \a i
|
|
164
|
\sa insertCategory()
|
|
164
|
\sa insertCategory()
|
|
165
|
*/
|
|
165
|
*/
|
|
166
|
void QBarSeries::removeCategory(int i)
|
|
166
|
void QBarSeries::removeCategory(int i)
|
|
167
|
{
|
|
167
|
{
|
|
168
|
Q_D(QBarSeries);
|
|
168
|
Q_D(QBarSeries);
|
|
169
|
d->m_internalModel->removeCategory(i);
|
|
169
|
d->m_internalModel->removeCategory(i);
|
|
170
|
}
|
|
170
|
}
|
|
171
|
|
|
171
|
|
|
172
|
/*!
|
|
172
|
/*!
|
|
173
|
Returns number of sets in series.
|
|
173
|
Returns number of sets in series.
|
|
174
|
*/
|
|
174
|
*/
|
|
175
|
int QBarSeries::barsetCount() const
|
|
175
|
int QBarSeries::barsetCount() const
|
|
176
|
{
|
|
176
|
{
|
|
177
|
Q_D(const QBarSeries);
|
|
177
|
Q_D(const QBarSeries);
|
|
178
|
/*
|
|
178
|
/*
|
|
179
|
// if(m_model)
|
|
179
|
// if(m_model)
|
|
180
|
// return m_mapBarTop - m_mapBarBottom;
|
|
180
|
// return m_mapBarTop - m_mapBarBottom;
|
|
181
|
// else
|
|
181
|
// else
|
|
182
|
|
|
182
|
|
|
183
|
*/
|
|
183
|
*/
|
|
184
|
return d->m_internalModel->barsetCount();
|
|
184
|
return d->m_internalModel->barsetCount();
|
|
185
|
}
|
|
185
|
}
|
|
186
|
|
|
186
|
|
|
187
|
/*!
|
|
187
|
/*!
|
|
188
|
Returns number of categories in series
|
|
188
|
Returns number of categories in series
|
|
189
|
*/
|
|
189
|
*/
|
|
190
|
int QBarSeries::categoryCount() const
|
|
190
|
int QBarSeries::categoryCount() const
|
|
191
|
{
|
|
191
|
{
|
|
192
|
Q_D(const QBarSeries);
|
|
192
|
Q_D(const QBarSeries);
|
|
193
|
return d->m_internalModel->categoryCount();
|
|
193
|
return d->m_internalModel->categoryCount();
|
|
194
|
}
|
|
194
|
}
|
|
195
|
|
|
195
|
|
|
196
|
/*!
|
|
196
|
/*!
|
|
197
|
Returns a list of sets in series. Keeps ownership of sets.
|
|
197
|
Returns a list of sets in series. Keeps ownership of sets.
|
|
198
|
*/
|
|
198
|
*/
|
|
199
|
QList<QBarSet*> QBarSeries::barSets() const
|
|
199
|
QList<QBarSet*> QBarSeries::barSets() const
|
|
200
|
{
|
|
200
|
{
|
|
201
|
Q_D(const QBarSeries);
|
|
201
|
Q_D(const QBarSeries);
|
|
202
|
return d->m_internalModel->barSets();
|
|
202
|
return d->m_internalModel->barSets();
|
|
203
|
}
|
|
203
|
}
|
|
204
|
|
|
204
|
|
|
205
|
/*!
|
|
205
|
/*!
|
|
206
|
\internal \a index
|
|
206
|
\internal \a index
|
|
207
|
*/
|
|
207
|
*/
|
|
208
|
QBarSet* QBarSeries::barsetAt(int index)
|
|
208
|
QBarSet* QBarSeries::barsetAt(int index)
|
|
209
|
{
|
|
209
|
{
|
|
210
|
Q_D(QBarSeries);
|
|
210
|
Q_D(QBarSeries);
|
|
211
|
return d->barsetAt(index);
|
|
211
|
return d->barsetAt(index);
|
|
212
|
// return m_internalModel->barsetAt(index);
|
|
212
|
// return m_internalModel->barsetAt(index);
|
|
213
|
}
|
|
213
|
}
|
|
214
|
|
|
214
|
|
|
215
|
/*!
|
|
215
|
/*!
|
|
216
|
\internal \a category
|
|
216
|
\internal \a category
|
|
217
|
*/
|
|
217
|
*/
|
|
218
|
QString QBarSeries::categoryName(int category)
|
|
218
|
QString QBarSeries::categoryName(int category)
|
|
219
|
{
|
|
219
|
{
|
|
220
|
Q_D(QBarSeries);
|
|
220
|
Q_D(QBarSeries);
|
|
221
|
return d->categoryName(category);
|
|
221
|
return d->categoryName(category);
|
|
222
|
// return m_internalModel->categoryName(category);
|
|
222
|
// return m_internalModel->categoryName(category);
|
|
223
|
}
|
|
223
|
}
|
|
224
|
|
|
224
|
|
|
225
|
/*!
|
|
225
|
/*!
|
|
226
|
Enables or disables tooltip depending on parameter \a enabled.
|
|
226
|
Enables or disables tooltip depending on parameter \a enabled.
|
|
227
|
Tooltip shows the name of set, when mouse is hovering on top of bar.
|
|
227
|
Tooltip shows the name of set, when mouse is hovering on top of bar.
|
|
228
|
Calling without parameter \a enabled, enables the tooltip
|
|
228
|
Calling without parameter \a enabled, enables the tooltip
|
|
229
|
*/
|
|
229
|
*/
|
|
230
|
void QBarSeries::setToolTipEnabled(bool enabled)
|
|
230
|
void QBarSeries::setToolTipEnabled(bool enabled)
|
|
231
|
{
|
|
231
|
{
|
|
232
|
Q_D(QBarSeries);
|
|
232
|
Q_D(QBarSeries);
|
|
233
|
d->setToolTipEnabled(enabled);
|
|
233
|
d->setToolTipEnabled(enabled);
|
|
234
|
/*
|
|
234
|
/*
|
|
235
|
// TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled.
|
|
235
|
// TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled.
|
|
236
|
if (enabled) {
|
|
236
|
if (enabled) {
|
|
237
|
for (int i=0; i<m_internalModel->barsetCount(); i++) {
|
|
237
|
for (int i=0; i<m_internalModel->barsetCount(); i++) {
|
|
238
|
QBarSet *set = m_internalModel->barsetAt(i);
|
|
238
|
QBarSet *set = m_internalModel->barsetAt(i);
|
|
239
|
connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString)));
|
|
239
|
connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString)));
|
|
240
|
}
|
|
240
|
}
|
|
241
|
} else {
|
|
241
|
} else {
|
|
242
|
for (int i=0; i<m_internalModel->barsetCount(); i++) {
|
|
242
|
for (int i=0; i<m_internalModel->barsetCount(); i++) {
|
|
243
|
QBarSet *set = m_internalModel->barsetAt(i);
|
|
243
|
QBarSet *set = m_internalModel->barsetAt(i);
|
|
244
|
disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString)));
|
|
244
|
disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString)));
|
|
245
|
}
|
|
245
|
}
|
|
246
|
}
|
|
246
|
}
|
|
247
|
*/
|
|
247
|
*/
|
|
248
|
}
|
|
248
|
}
|
|
249
|
|
|
249
|
|
|
250
|
|
|
250
|
|
|
251
|
/*!
|
|
251
|
/*!
|
|
252
|
\internal \a category
|
|
252
|
\internal \a category
|
|
253
|
*/
|
|
253
|
*/
|
|
254
|
void QBarSeries::barsetClicked(QString category, Qt::MouseButtons button)
|
|
254
|
void QBarSeries::barsetClicked(QString category, Qt::MouseButtons button)
|
|
255
|
{
|
|
255
|
{
|
|
256
|
Q_D(QBarSeries);
|
|
256
|
Q_D(QBarSeries);
|
|
257
|
d->barsetClicked(category,button);
|
|
257
|
d->barsetClicked(category,button);
|
|
258
|
// emit clicked(qobject_cast<QBarSet*>(sender()), category, button);
|
|
258
|
// emit clicked(qobject_cast<QBarSet*>(sender()), category, button);
|
|
259
|
}
|
|
259
|
}
|
|
260
|
|
|
260
|
|
|
261
|
/*!
|
|
261
|
/*!
|
|
262
|
\internal
|
|
262
|
\internal
|
|
263
|
*/
|
|
263
|
*/
|
|
264
|
qreal QBarSeries::min()
|
|
264
|
qreal QBarSeries::min()
|
|
265
|
{
|
|
265
|
{
|
|
266
|
Q_D(QBarSeries);
|
|
266
|
Q_D(QBarSeries);
|
|
267
|
return d->min();
|
|
267
|
return d->min();
|
|
268
|
//return m_internalModel->min();
|
|
268
|
//return m_internalModel->min();
|
|
269
|
}
|
|
269
|
}
|
|
270
|
|
|
270
|
|
|
271
|
/*!
|
|
271
|
/*!
|
|
272
|
\internal
|
|
272
|
\internal
|
|
273
|
*/
|
|
273
|
*/
|
|
274
|
qreal QBarSeries::max()
|
|
274
|
qreal QBarSeries::max()
|
|
275
|
{
|
|
275
|
{
|
|
276
|
Q_D(QBarSeries);
|
|
276
|
Q_D(QBarSeries);
|
|
277
|
return d->max();
|
|
277
|
return d->max();
|
|
278
|
// return m_internalModel->max();
|
|
278
|
// return m_internalModel->max();
|
|
279
|
}
|
|
279
|
}
|
|
280
|
|
|
280
|
|
|
281
|
/*!
|
|
281
|
/*!
|
|
282
|
\internal \a set \a category
|
|
282
|
\internal \a set \a category
|
|
283
|
*/
|
|
283
|
*/
|
|
284
|
qreal QBarSeries::valueAt(int set, int category)
|
|
284
|
qreal QBarSeries::valueAt(int set, int category)
|
|
285
|
{
|
|
285
|
{
|
|
286
|
Q_D(QBarSeries);
|
|
286
|
Q_D(QBarSeries);
|
|
287
|
return d->valueAt(set,category);
|
|
287
|
return d->valueAt(set,category);
|
|
288
|
// return m_internalModel->valueAt(set, category);
|
|
288
|
// return m_internalModel->valueAt(set, category);
|
|
289
|
}
|
|
289
|
}
|
|
290
|
|
|
290
|
|
|
291
|
/*!
|
|
291
|
/*!
|
|
292
|
\internal \a set \a category
|
|
292
|
\internal \a set \a category
|
|
293
|
*/
|
|
293
|
*/
|
|
294
|
qreal QBarSeries::percentageAt(int set, int category)
|
|
294
|
qreal QBarSeries::percentageAt(int set, int category)
|
|
295
|
{
|
|
295
|
{
|
|
296
|
Q_D(QBarSeries);
|
|
296
|
Q_D(QBarSeries);
|
|
297
|
return d->percentageAt(set,category);
|
|
297
|
return d->percentageAt(set,category);
|
|
298
|
// return m_internalModel->percentageAt(set, category);
|
|
298
|
// return m_internalModel->percentageAt(set, category);
|
|
299
|
}
|
|
299
|
}
|
|
300
|
|
|
300
|
|
|
301
|
/*!
|
|
301
|
/*!
|
|
302
|
\internal \a category
|
|
302
|
\internal \a category
|
|
303
|
*/
|
|
303
|
*/
|
|
304
|
qreal QBarSeries::categorySum(int category)
|
|
304
|
qreal QBarSeries::categorySum(int category)
|
|
305
|
{
|
|
305
|
{
|
|
306
|
Q_D(QBarSeries);
|
|
306
|
Q_D(QBarSeries);
|
|
307
|
return d->categorySum(category);
|
|
307
|
return d->categorySum(category);
|
|
308
|
// return m_internalModel->categorySum(category);
|
|
308
|
// return m_internalModel->categorySum(category);
|
|
309
|
}
|
|
309
|
}
|
|
310
|
|
|
310
|
|
|
311
|
/*!
|
|
311
|
/*!
|
|
312
|
\internal \a category
|
|
312
|
\internal \a category
|
|
313
|
*/
|
|
313
|
*/
|
|
314
|
qreal QBarSeries::absoluteCategorySum(int category)
|
|
314
|
qreal QBarSeries::absoluteCategorySum(int category)
|
|
315
|
{
|
|
315
|
{
|
|
316
|
Q_D(QBarSeries);
|
|
316
|
Q_D(QBarSeries);
|
|
317
|
return d->absoluteCategorySum(category);
|
|
317
|
return d->absoluteCategorySum(category);
|
|
318
|
// return m_internalModel->absoluteCategorySum(category);
|
|
318
|
// return m_internalModel->absoluteCategorySum(category);
|
|
319
|
}
|
|
319
|
}
|
|
320
|
|
|
320
|
|
|
321
|
/*!
|
|
321
|
/*!
|
|
322
|
\internal
|
|
322
|
\internal
|
|
323
|
*/
|
|
323
|
*/
|
|
324
|
qreal QBarSeries::maxCategorySum()
|
|
324
|
qreal QBarSeries::maxCategorySum()
|
|
325
|
{
|
|
325
|
{
|
|
326
|
Q_D(QBarSeries);
|
|
326
|
Q_D(QBarSeries);
|
|
327
|
return d->maxCategorySum();
|
|
327
|
return d->maxCategorySum();
|
|
328
|
// return m_internalModel->maxCategorySum();
|
|
328
|
// return m_internalModel->maxCategorySum();
|
|
329
|
}
|
|
329
|
}
|
|
330
|
|
|
330
|
|
|
331
|
/*!
|
|
331
|
/*!
|
|
332
|
\internal
|
|
332
|
\internal
|
|
333
|
*/
|
|
333
|
*/
|
|
334
|
BarChartModel& QBarSeries::modelInternal()
|
|
334
|
BarChartModel& QBarSeries::modelInternal()
|
|
335
|
{
|
|
335
|
{
|
|
336
|
Q_D(QBarSeries);
|
|
336
|
Q_D(QBarSeries);
|
|
337
|
return d->modelInternal();
|
|
337
|
return d->modelInternal();
|
|
338
|
// return *m_internalModel;
|
|
338
|
// return *m_internalModel;
|
|
339
|
}
|
|
339
|
}
|
|
340
|
|
|
340
|
|
|
341
|
/*!
|
|
341
|
/*!
|
|
342
|
\fn bool QBarSeries::setModel(QAbstractItemModel *model)
|
|
342
|
\fn bool QBarSeries::setModel(QAbstractItemModel *model)
|
|
343
|
Sets the \a model to be used as a data source
|
|
343
|
Sets the \a model to be used as a data source
|
|
344
|
*/
|
|
344
|
*/
|
|
345
|
bool QBarSeries::setModel(QAbstractItemModel *model)
|
|
345
|
bool QBarSeries::setModel(QAbstractItemModel *model)
|
|
346
|
{
|
|
346
|
{
|
|
347
|
Q_D(QBarSeries);
|
|
347
|
Q_D(QBarSeries);
|
|
348
|
return d->setModel(model);
|
|
348
|
return d->setModel(model);
|
|
349
|
/*
|
|
349
|
/*
|
|
350
|
// disconnect signals from old model
|
|
350
|
// disconnect signals from old model
|
|
351
|
if(m_model)
|
|
351
|
if(m_model)
|
|
352
|
{
|
|
352
|
{
|
|
353
|
disconnect(m_model, 0, this, 0);
|
|
353
|
disconnect(m_model, 0, this, 0);
|
|
354
|
m_mapCategories = -1;
|
|
354
|
m_mapCategories = -1;
|
|
355
|
m_mapBarBottom = -1;
|
|
355
|
m_mapBarBottom = -1;
|
|
356
|
m_mapBarTop = -1;
|
|
356
|
m_mapBarTop = -1;
|
|
357
|
m_mapFirst = 0;
|
|
357
|
m_mapFirst = 0;
|
|
358
|
m_mapCount = 0;
|
|
358
|
m_mapCount = 0;
|
|
359
|
m_mapOrientation = Qt::Vertical;
|
|
359
|
m_mapOrientation = Qt::Vertical;
|
|
360
|
}
|
|
360
|
}
|
|
361
|
|
|
361
|
|
|
362
|
// set new model
|
|
362
|
// set new model
|
|
363
|
if(model)
|
|
363
|
if(model)
|
|
364
|
{
|
|
364
|
{
|
|
365
|
m_model = model;
|
|
365
|
m_model = model;
|
|
366
|
return true;
|
|
366
|
return true;
|
|
367
|
}
|
|
367
|
}
|
|
368
|
else
|
|
368
|
else
|
|
369
|
{
|
|
369
|
{
|
|
370
|
m_model = 0;
|
|
370
|
m_model = 0;
|
|
371
|
return false;
|
|
371
|
return false;
|
|
372
|
}
|
|
372
|
}
|
|
373
|
*/
|
|
373
|
*/
|
|
374
|
}
|
|
374
|
}
|
|
375
|
|
|
375
|
|
|
376
|
/*!
|
|
376
|
/*!
|
|
377
|
\fn bool QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation)
|
|
377
|
\fn bool QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation)
|
|
378
|
Sets column/row specified by \a categories to be used as a list of bar series categories.
|
|
378
|
Sets column/row specified by \a categories to be used as a list of bar series categories.
|
|
379
|
Parameter \a bottomBoundry indicates the column/row where the first bar set is located in the model.
|
|
379
|
Parameter \a bottomBoundry indicates the column/row where the first bar set is located in the model.
|
|
380
|
Parameter \a topBoundry indicates the column/row where the last bar set is located in the model.
|
|
380
|
Parameter \a topBoundry indicates the column/row where the last bar set is located in the model.
|
|
381
|
All the columns/rows inbetween those two values are also used as data for bar sets.
|
|
381
|
All the columns/rows inbetween those two values are also used as data for bar sets.
|
|
382
|
The \a orientation paramater specifies whether the data is in columns or in rows.
|
|
382
|
The \a orientation paramater specifies whether the data is in columns or in rows.
|
|
383
|
*/
|
|
383
|
*/
|
|
384
|
void QBarSeries::setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation)
|
|
384
|
void QBarSeries::setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation)
|
|
385
|
{
|
|
385
|
{
|
|
386
|
Q_D(QBarSeries);
|
|
386
|
Q_D(QBarSeries);
|
|
387
|
d->setModelMapping(categories,bottomBoundary,topBoundary,orientation);
|
|
387
|
d->setModelMapping(categories,bottomBoundary,topBoundary,orientation);
|
|
388
|
/*
|
|
388
|
/*
|
|
389
|
if (!m_model)
|
|
389
|
if (!m_model)
|
|
390
|
return;
|
|
390
|
return;
|
|
391
|
|
|
391
|
|
|
392
|
m_mapCategories = categories;
|
|
392
|
m_mapCategories = categories;
|
|
393
|
m_mapBarBottom = bottomBoundry;
|
|
393
|
m_mapBarBottom = bottomBoundry;
|
|
394
|
m_mapBarTop = topBoundry;
|
|
394
|
m_mapBarTop = topBoundry;
|
|
395
|
// m_mapFirst = 1;
|
|
395
|
// m_mapFirst = 1;
|
|
396
|
m_mapOrientation = orientation;
|
|
396
|
m_mapOrientation = orientation;
|
|
397
|
|
|
397
|
|
|
398
|
// connect the signals
|
|
398
|
// connect the signals
|
|
399
|
if (m_mapOrientation == Qt::Vertical) {
|
|
399
|
if (m_mapOrientation == Qt::Vertical) {
|
|
400
|
m_mapCount = m_model->rowCount() - m_mapFirst;
|
|
400
|
m_mapCount = m_model->rowCount() - m_mapFirst;
|
|
401
|
connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
|
401
|
connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
|
402
|
this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
|
|
402
|
this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
|
|
403
|
connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)),
|
|
403
|
connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)),
|
|
404
|
this, SLOT(modelDataAdded(QModelIndex,int,int)));
|
|
404
|
this, SLOT(modelDataAdded(QModelIndex,int,int)));
|
|
405
|
connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)),
|
|
405
|
connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)),
|
|
406
|
this, SLOT(modelDataRemoved(QModelIndex,int,int)));
|
|
406
|
this, SLOT(modelDataRemoved(QModelIndex,int,int)));
|
|
407
|
} else {
|
|
407
|
} else {
|
|
408
|
m_mapCount = m_model->columnCount() - m_mapFirst;
|
|
408
|
m_mapCount = m_model->columnCount() - m_mapFirst;
|
|
409
|
connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
|
409
|
connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
|
410
|
this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
|
|
410
|
this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
|
|
411
|
connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)),
|
|
411
|
connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)),
|
|
412
|
this, SLOT(modelDataAdded(QModelIndex,int,int)));
|
|
412
|
this, SLOT(modelDataAdded(QModelIndex,int,int)));
|
|
413
|
connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)),
|
|
413
|
connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)),
|
|
414
|
this, SLOT(modelDataRemoved(QModelIndex,int,int)));
|
|
414
|
this, SLOT(modelDataRemoved(QModelIndex,int,int)));
|
|
415
|
}
|
|
415
|
}
|
|
416
|
|
|
416
|
|
|
417
|
// create the initial bars
|
|
417
|
// create the initial bars
|
|
418
|
delete m_internalModel;
|
|
418
|
delete m_internalModel;
|
|
419
|
if (m_mapOrientation == Qt::Vertical) {
|
|
419
|
if (m_mapOrientation == Qt::Vertical) {
|
|
420
|
QStringList categories;
|
|
420
|
QStringList categories;
|
|
421
|
for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
|
|
421
|
for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
|
|
422
|
categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString();
|
|
422
|
categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString();
|
|
423
|
m_internalModel = new BarChartModel(categories, this);
|
|
423
|
m_internalModel = new BarChartModel(categories, this);
|
|
424
|
|
|
424
|
|
|
425
|
for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
|
|
425
|
for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
|
|
426
|
QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1));
|
|
426
|
QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1));
|
|
427
|
for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++)
|
|
427
|
for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++)
|
|
428
|
*barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble();
|
|
428
|
*barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble();
|
|
429
|
appendBarSet(barSet);
|
|
429
|
appendBarSet(barSet);
|
|
430
|
}
|
|
430
|
}
|
|
431
|
} else {
|
|
431
|
} else {
|
|
432
|
QStringList categories;
|
|
432
|
QStringList categories;
|
|
433
|
for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
|
|
433
|
for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
|
|
434
|
categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString();
|
|
434
|
categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString();
|
|
435
|
m_internalModel = new BarChartModel(categories, this);
|
|
435
|
m_internalModel = new BarChartModel(categories, this);
|
|
436
|
|
|
436
|
|
|
437
|
for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
|
|
437
|
for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
|
|
438
|
QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1));
|
|
438
|
QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1));
|
|
439
|
for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++)
|
|
439
|
for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++)
|
|
440
|
*barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble();
|
|
440
|
*barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble();
|
|
441
|
appendBarSet(barSet);
|
|
441
|
appendBarSet(barSet);
|
|
442
|
}
|
|
442
|
}
|
|
443
|
}
|
|
443
|
}
|
|
444
|
*/
|
|
444
|
*/
|
|
445
|
}
|
|
445
|
}
|
|
446
|
|
|
446
|
|
|
447
|
/*!
|
|
447
|
/*!
|
|
448
|
\internal
|
|
448
|
\internal
|
|
449
|
*/
|
|
449
|
*/
|
|
450
|
void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
|
|
450
|
void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
|
|
451
|
{
|
|
451
|
{
|
|
452
|
Q_D(QBarSeries);
|
|
452
|
Q_D(QBarSeries);
|
|
453
|
d->modelUpdated(topLeft,bottomRight);
|
|
453
|
d->modelUpdated(topLeft,bottomRight);
|
|
454
|
/*
|
|
454
|
/*
|
|
455
|
Q_UNUSED(bottomRight)
|
|
455
|
Q_UNUSED(bottomRight)
|
|
456
|
|
|
456
|
|
|
457
|
if (m_mapOrientation == Qt::Vertical)
|
|
457
|
if (m_mapOrientation == Qt::Vertical)
|
|
458
|
{
|
|
458
|
{
|
|
459
|
// model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
|
|
459
|
// model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
|
|
460
|
if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount)
|
|
460
|
if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount)
|
|
461
|
barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
|
|
461
|
barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
|
|
462
|
}
|
|
462
|
}
|
|
463
|
else
|
|
463
|
else
|
|
464
|
{
|
|
464
|
{
|
|
465
|
// model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
|
|
465
|
// model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
|
|
466
|
if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount)
|
|
466
|
if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount)
|
|
467
|
barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
|
|
467
|
barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
|
|
468
|
}
|
|
468
|
}
|
|
469
|
*/
|
|
469
|
*/
|
|
470
|
}
|
|
470
|
}
|
|
471
|
|
|
471
|
|
|
472
|
/*!
|
|
472
|
/*!
|
|
473
|
\internal
|
|
473
|
\internal
|
|
474
|
*/
|
|
474
|
*/
|
|
475
|
void QBarSeries::modelDataAdded(QModelIndex parent, int start, int end)
|
|
475
|
void QBarSeries::modelDataAdded(QModelIndex parent, int start, int end)
|
|
476
|
{
|
|
476
|
{
|
|
477
|
Q_D(QBarSeries);
|
|
477
|
Q_D(QBarSeries);
|
|
478
|
d->modelDataAdded(parent,start,end);
|
|
478
|
d->modelDataAdded(parent,start,end);
|
|
479
|
/*
|
|
479
|
/*
|
|
480
|
if (m_mapOrientation == Qt::Vertical) {
|
|
480
|
if (m_mapOrientation == Qt::Vertical) {
|
|
481
|
insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1));
|
|
481
|
insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1));
|
|
482
|
for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) {
|
|
482
|
for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) {
|
|
483
|
barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble());
|
|
483
|
barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble());
|
|
484
|
}
|
|
484
|
}
|
|
485
|
} else {
|
|
485
|
} else {
|
|
486
|
insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1));
|
|
486
|
insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1));
|
|
487
|
for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) {
|
|
487
|
for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) {
|
|
488
|
barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble());
|
|
488
|
barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble());
|
|
489
|
}
|
|
489
|
}
|
|
490
|
}
|
|
490
|
}
|
|
491
|
emit restructuredBars();
|
|
491
|
emit restructuredBars();
|
|
492
|
*/
|
|
492
|
*/
|
|
493
|
}
|
|
493
|
}
|
|
494
|
|
|
494
|
|
|
495
|
/*!
|
|
495
|
/*!
|
|
496
|
\internal
|
|
496
|
\internal
|
|
497
|
*/
|
|
497
|
*/
|
|
498
|
void QBarSeries::modelDataRemoved(QModelIndex parent, int start, int end)
|
|
498
|
void QBarSeries::modelDataRemoved(QModelIndex parent, int start, int end)
|
|
499
|
{
|
|
499
|
{
|
|
500
|
Q_D(QBarSeries);
|
|
500
|
Q_D(QBarSeries);
|
|
501
|
d->modelDataRemoved(parent,start,end);
|
|
501
|
d->modelDataRemoved(parent,start,end);
|
|
502
|
/*
|
|
502
|
/*
|
|
503
|
Q_UNUSED(parent)
|
|
503
|
Q_UNUSED(parent)
|
|
504
|
Q_UNUSED(end)
|
|
504
|
Q_UNUSED(end)
|
|
505
|
|
|
505
|
|
|
506
|
removeCategory(start - m_mapFirst);
|
|
506
|
removeCategory(start - m_mapFirst);
|
|
507
|
for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++)
|
|
507
|
for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++)
|
|
508
|
{
|
|
508
|
{
|
|
509
|
barsetAt(i)->removeValue(start - m_mapFirst);
|
|
509
|
barsetAt(i)->removeValue(start - m_mapFirst);
|
|
510
|
}
|
|
510
|
}
|
|
511
|
emit restructuredBars();
|
|
511
|
emit restructuredBars();
|
|
512
|
*/
|
|
512
|
*/
|
|
513
|
}
|
|
513
|
}
|
|
514
|
|
|
514
|
|
|
515
|
void QBarSeries::barsetChanged()
|
|
515
|
void QBarSeries::barsetChanged()
|
|
516
|
{
|
|
516
|
{
|
|
517
|
Q_D(QBarSeries);
|
|
517
|
Q_D(QBarSeries);
|
|
518
|
d->barsetChanged();
|
|
518
|
d->barsetChanged();
|
|
519
|
// emit updatedBars();
|
|
519
|
// emit updatedBars();
|
|
520
|
}
|
|
520
|
}
|
|
521
|
|
|
521
|
|
|
522
|
QBarCategories QBarSeries::categories() const
|
|
522
|
QBarCategories QBarSeries::categories() const
|
|
523
|
{
|
|
523
|
{
|
|
524
|
Q_D(const QBarSeries);
|
|
524
|
Q_D(const QBarSeries);
|
|
525
|
|
|
525
|
|
|
526
|
QBarCategories categories;
|
|
526
|
QBarCategories categories;
|
|
527
|
int count = d->m_internalModel->categoryCount();
|
|
527
|
int count = d->m_internalModel->categoryCount();
|
|
528
|
for (int i=1; i <= count; i++) {
|
|
528
|
for (int i=1; i <= count; i++) {
|
|
529
|
categories.insert(i, d->m_internalModel->categoryName(i - 1));
|
|
529
|
categories.insert(i, d->m_internalModel->categoryName(i - 1));
|
|
530
|
}
|
|
530
|
}
|
|
531
|
return categories;
|
|
531
|
return categories;
|
|
532
|
|
|
532
|
|
|
533
|
}
|
|
533
|
}
|
|
534
|
|
|
534
|
|
|
535
|
/*!
|
|
535
|
/*!
|
|
536
|
Sets the visibility of labels in series to \a visible
|
|
536
|
Sets the visibility of labels in series to \a visible
|
|
537
|
*/
|
|
537
|
*/
|
|
538
|
void QBarSeries::setLabelsVisible(bool visible)
|
|
538
|
void QBarSeries::setLabelsVisible(bool visible)
|
|
539
|
{
|
|
539
|
{
|
|
540
|
foreach (QBarSet* s, barSets()) {
|
|
540
|
foreach (QBarSet* s, barSets()) {
|
|
541
|
s->setLabelsVisible(visible);
|
|
541
|
s->setLabelsVisible(visible);
|
|
542
|
}
|
|
542
|
}
|
|
543
|
}
|
|
543
|
}
|
|
544
|
|
|
544
|
|
|
545
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
545
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
546
|
|
|
546
|
|
|
547
|
QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *q) : QSeriesPrivate(q),
|
|
547
|
QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *q) : QSeriesPrivate(q),
|
|
548
|
m_internalModel(new BarChartModel(categories,this)),
|
|
548
|
m_internalModel(new BarChartModel(categories,this)),
|
|
549
|
m_model(0),
|
|
549
|
m_model(0),
|
|
550
|
m_mapCategories(-1),
|
|
550
|
m_mapCategories(-1),
|
|
551
|
m_mapBarBottom(-1),
|
|
551
|
m_mapBarBottom(-1),
|
|
552
|
m_mapBarTop(-1),
|
|
552
|
m_mapBarTop(-1),
|
|
553
|
m_mapFirst(0),
|
|
553
|
m_mapFirst(0),
|
|
554
|
m_mapCount(0),
|
|
554
|
m_mapCount(0),
|
|
555
|
m_mapOrientation(Qt::Vertical)
|
|
555
|
m_mapOrientation(Qt::Vertical)
|
|
556
|
{
|
|
556
|
{
|
|
557
|
}
|
|
557
|
}
|
|
558
|
|
|
558
|
|
|
559
|
QBarSet* QBarSeriesPrivate::barsetAt(int index)
|
|
559
|
QBarSet* QBarSeriesPrivate::barsetAt(int index)
|
|
560
|
{
|
|
560
|
{
|
|
561
|
return m_internalModel->barsetAt(index);
|
|
561
|
return m_internalModel->barsetAt(index);
|
|
562
|
}
|
|
562
|
}
|
|
563
|
|
|
563
|
|
|
564
|
QString QBarSeriesPrivate::categoryName(int category)
|
|
564
|
QString QBarSeriesPrivate::categoryName(int category)
|
|
565
|
{
|
|
565
|
{
|
|
566
|
return m_internalModel->categoryName(category);
|
|
566
|
return m_internalModel->categoryName(category);
|
|
567
|
}
|
|
567
|
}
|
|
568
|
|
|
568
|
|
|
569
|
void QBarSeriesPrivate::setToolTipEnabled(bool enabled)
|
|
569
|
void QBarSeriesPrivate::setToolTipEnabled(bool enabled)
|
|
570
|
{
|
|
570
|
{
|
|
571
|
// TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled.
|
|
571
|
// TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled.
|
|
572
|
if (enabled) {
|
|
572
|
if (enabled) {
|
|
573
|
for (int i=0; i<m_internalModel->barsetCount(); i++) {
|
|
573
|
for (int i=0; i<m_internalModel->barsetCount(); i++) {
|
|
574
|
QBarSet *set = m_internalModel->barsetAt(i);
|
|
574
|
QBarSet *set = m_internalModel->barsetAt(i);
|
|
575
|
connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString)));
|
|
575
|
connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString)));
|
|
576
|
}
|
|
576
|
}
|
|
577
|
} else {
|
|
577
|
} else {
|
|
578
|
for (int i=0; i<m_internalModel->barsetCount(); i++) {
|
|
578
|
for (int i=0; i<m_internalModel->barsetCount(); i++) {
|
|
579
|
QBarSet *set = m_internalModel->barsetAt(i);
|
|
579
|
QBarSet *set = m_internalModel->barsetAt(i);
|
|
580
|
disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString)));
|
|
580
|
disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString)));
|
|
581
|
}
|
|
581
|
}
|
|
582
|
}
|
|
582
|
}
|
|
583
|
}
|
|
583
|
}
|
|
584
|
|
|
584
|
|
|
585
|
void QBarSeriesPrivate::barsetClicked(QString category, Qt::MouseButtons button)
|
|
585
|
void QBarSeriesPrivate::barsetClicked(QString category, Qt::MouseButtons button)
|
|
586
|
{
|
|
586
|
{
|
|
587
|
emit clicked(qobject_cast<QBarSet*>(sender()), category, button);
|
|
587
|
emit clicked(qobject_cast<QBarSet*>(sender()), category, button);
|
|
588
|
}
|
|
588
|
}
|
|
589
|
|
|
589
|
|
|
590
|
qreal QBarSeriesPrivate::min()
|
|
590
|
qreal QBarSeriesPrivate::min()
|
|
591
|
{
|
|
591
|
{
|
|
592
|
return m_internalModel->min();
|
|
592
|
return m_internalModel->min();
|
|
593
|
}
|
|
593
|
}
|
|
594
|
|
|
594
|
|
|
595
|
qreal QBarSeriesPrivate::max()
|
|
595
|
qreal QBarSeriesPrivate::max()
|
|
596
|
{
|
|
596
|
{
|
|
597
|
return m_internalModel->max();
|
|
597
|
return m_internalModel->max();
|
|
598
|
}
|
|
598
|
}
|
|
599
|
|
|
599
|
|
|
600
|
qreal QBarSeriesPrivate::valueAt(int set, int category)
|
|
600
|
qreal QBarSeriesPrivate::valueAt(int set, int category)
|
|
601
|
{
|
|
601
|
{
|
|
602
|
return m_internalModel->valueAt(set, category);
|
|
602
|
return m_internalModel->valueAt(set, category);
|
|
603
|
}
|
|
603
|
}
|
|
604
|
|
|
604
|
|
|
605
|
qreal QBarSeriesPrivate::percentageAt(int set, int category)
|
|
605
|
qreal QBarSeriesPrivate::percentageAt(int set, int category)
|
|
606
|
{
|
|
606
|
{
|
|
607
|
return m_internalModel->percentageAt(set, category);
|
|
607
|
return m_internalModel->percentageAt(set, category);
|
|
608
|
}
|
|
608
|
}
|
|
609
|
|
|
609
|
|
|
610
|
qreal QBarSeriesPrivate::categorySum(int category)
|
|
610
|
qreal QBarSeriesPrivate::categorySum(int category)
|
|
611
|
{
|
|
611
|
{
|
|
612
|
return m_internalModel->categorySum(category);
|
|
612
|
return m_internalModel->categorySum(category);
|
|
613
|
}
|
|
613
|
}
|
|
614
|
|
|
614
|
|
|
615
|
qreal QBarSeriesPrivate::absoluteCategorySum(int category)
|
|
615
|
qreal QBarSeriesPrivate::absoluteCategorySum(int category)
|
|
616
|
{
|
|
616
|
{
|
|
617
|
return m_internalModel->absoluteCategorySum(category);
|
|
617
|
return m_internalModel->absoluteCategorySum(category);
|
|
618
|
}
|
|
618
|
}
|
|
619
|
|
|
619
|
|
|
620
|
qreal QBarSeriesPrivate::maxCategorySum()
|
|
620
|
qreal QBarSeriesPrivate::maxCategorySum()
|
|
621
|
{
|
|
621
|
{
|
|
622
|
return m_internalModel->maxCategorySum();
|
|
622
|
return m_internalModel->maxCategorySum();
|
|
623
|
}
|
|
623
|
}
|
|
624
|
|
|
624
|
|
|
625
|
BarChartModel& QBarSeriesPrivate::modelInternal()
|
|
625
|
BarChartModel& QBarSeriesPrivate::modelInternal()
|
|
626
|
{
|
|
626
|
{
|
|
627
|
return *m_internalModel;
|
|
627
|
return *m_internalModel;
|
|
628
|
}
|
|
628
|
}
|
|
629
|
|
|
629
|
|
|
630
|
bool QBarSeriesPrivate::setModel(QAbstractItemModel *model)
|
|
630
|
bool QBarSeriesPrivate::setModel(QAbstractItemModel *model)
|
|
631
|
{
|
|
631
|
{
|
|
632
|
// disconnect signals from old model
|
|
632
|
// disconnect signals from old model
|
|
633
|
if(m_model)
|
|
633
|
if(m_model)
|
|
634
|
{
|
|
634
|
{
|
|
635
|
disconnect(m_model, 0, this, 0);
|
|
635
|
disconnect(m_model, 0, this, 0);
|
|
636
|
m_mapCategories = -1;
|
|
636
|
m_mapCategories = -1;
|
|
637
|
m_mapBarBottom = -1;
|
|
637
|
m_mapBarBottom = -1;
|
|
638
|
m_mapBarTop = -1;
|
|
638
|
m_mapBarTop = -1;
|
|
639
|
m_mapFirst = 0;
|
|
639
|
m_mapFirst = 0;
|
|
640
|
m_mapCount = 0;
|
|
640
|
m_mapCount = 0;
|
|
641
|
m_mapOrientation = Qt::Vertical;
|
|
641
|
m_mapOrientation = Qt::Vertical;
|
|
642
|
}
|
|
642
|
}
|
|
643
|
|
|
643
|
|
|
644
|
// set new model
|
|
644
|
// set new model
|
|
645
|
if(model)
|
|
645
|
if(model)
|
|
646
|
{
|
|
646
|
{
|
|
647
|
m_model = model;
|
|
647
|
m_model = model;
|
|
648
|
return true;
|
|
648
|
return true;
|
|
649
|
}
|
|
649
|
}
|
|
650
|
else
|
|
650
|
else
|
|
651
|
{
|
|
651
|
{
|
|
652
|
m_model = 0;
|
|
652
|
m_model = 0;
|
|
653
|
return false;
|
|
653
|
return false;
|
|
654
|
}
|
|
654
|
}
|
|
655
|
}
|
|
655
|
}
|
|
656
|
|
|
656
|
|
|
657
|
void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation)
|
|
657
|
void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation)
|
|
658
|
{
|
|
658
|
{
|
|
659
|
Q_Q(QBarSeries);
|
|
659
|
Q_Q(QBarSeries);
|
|
660
|
|
|
660
|
|
|
661
|
if (!m_model)
|
|
661
|
if (m_model == 0)
|
|
662
|
return;
|
|
662
|
return;
|
|
663
|
|
|
663
|
|
|
664
|
m_mapCategories = categories;
|
|
664
|
m_mapCategories = categories;
|
|
665
|
m_mapBarBottom = bottomBoundry;
|
|
665
|
m_mapBarBottom = bottomBoundry;
|
|
666
|
m_mapBarTop = topBoundry;
|
|
666
|
m_mapBarTop = topBoundry;
|
|
667
|
// m_mapFirst = 1;
|
|
667
|
// m_mapFirst = 1;
|
|
668
|
m_mapOrientation = orientation;
|
|
668
|
m_mapOrientation = orientation;
|
|
669
|
|
|
669
|
|
|
670
|
// connect the signals
|
|
670
|
// connect the signals
|
|
671
|
if (m_mapOrientation == Qt::Vertical) {
|
|
671
|
if (m_mapOrientation == Qt::Vertical) {
|
|
672
|
m_mapCount = m_model->rowCount() - m_mapFirst;
|
|
672
|
m_mapCount = m_model->rowCount() - m_mapFirst;
|
|
673
|
connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
|
673
|
connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
|
674
|
this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
|
|
674
|
this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
|
|
675
|
connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)),
|
|
675
|
connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)),
|
|
676
|
this, SLOT(modelDataAdded(QModelIndex,int,int)));
|
|
676
|
this, SLOT(modelDataAdded(QModelIndex,int,int)));
|
|
677
|
connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)),
|
|
677
|
connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)),
|
|
678
|
this, SLOT(modelDataRemoved(QModelIndex,int,int)));
|
|
678
|
this, SLOT(modelDataRemoved(QModelIndex,int,int)));
|
|
679
|
} else {
|
|
679
|
} else {
|
|
680
|
m_mapCount = m_model->columnCount() - m_mapFirst;
|
|
680
|
m_mapCount = m_model->columnCount() - m_mapFirst;
|
|
681
|
connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
|
681
|
connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
|
682
|
this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
|
|
682
|
this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
|
|
683
|
connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)),
|
|
683
|
connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)),
|
|
684
|
this, SLOT(modelDataAdded(QModelIndex,int,int)));
|
|
684
|
this, SLOT(modelDataAdded(QModelIndex,int,int)));
|
|
685
|
connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)),
|
|
685
|
connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)),
|
|
686
|
this, SLOT(modelDataRemoved(QModelIndex,int,int)));
|
|
686
|
this, SLOT(modelDataRemoved(QModelIndex,int,int)));
|
|
687
|
}
|
|
687
|
}
|
|
688
|
|
|
688
|
|
|
689
|
// create the initial bars
|
|
689
|
// create the initial bars
|
|
690
|
delete m_internalModel;
|
|
690
|
delete m_internalModel;
|
|
691
|
if (m_mapOrientation == Qt::Vertical) {
|
|
691
|
if (m_mapOrientation == Qt::Vertical) {
|
|
692
|
QStringList categories;
|
|
692
|
QStringList categories;
|
|
693
|
for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
|
|
693
|
for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
|
|
694
|
categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString();
|
|
694
|
categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString();
|
|
695
|
m_internalModel = new BarChartModel(categories, this);
|
|
695
|
m_internalModel = new BarChartModel(categories, this);
|
|
696
|
|
|
696
|
|
|
697
|
for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
|
|
697
|
for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
|
|
698
|
QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1));
|
|
698
|
QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1));
|
|
699
|
for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++)
|
|
699
|
for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++)
|
|
700
|
*barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble();
|
|
700
|
*barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble();
|
|
701
|
q->appendBarSet(barSet);
|
|
701
|
q->appendBarSet(barSet);
|
|
702
|
}
|
|
702
|
}
|
|
703
|
} else {
|
|
703
|
} else {
|
|
704
|
QStringList categories;
|
|
704
|
QStringList categories;
|
|
705
|
for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
|
|
705
|
for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++)
|
|
706
|
categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString();
|
|
706
|
categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString();
|
|
707
|
m_internalModel = new BarChartModel(categories, this);
|
|
707
|
m_internalModel = new BarChartModel(categories, this);
|
|
708
|
|
|
708
|
|
|
709
|
for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
|
|
709
|
for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
|
|
710
|
QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1));
|
|
710
|
QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1));
|
|
711
|
for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++)
|
|
711
|
for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++)
|
|
712
|
*barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble();
|
|
712
|
*barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble();
|
|
713
|
q->appendBarSet(barSet);
|
|
713
|
q->appendBarSet(barSet);
|
|
714
|
}
|
|
714
|
}
|
|
715
|
}
|
|
715
|
}
|
|
716
|
}
|
|
716
|
}
|
|
717
|
|
|
717
|
|
|
718
|
void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
|
|
718
|
void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
|
|
719
|
{
|
|
719
|
{
|
|
720
|
Q_UNUSED(bottomRight)
|
|
720
|
Q_UNUSED(bottomRight)
|
|
721
|
|
|
721
|
|
|
722
|
if (m_mapOrientation == Qt::Vertical)
|
|
722
|
if (m_mapOrientation == Qt::Vertical)
|
|
723
|
{
|
|
723
|
{
|
|
724
|
// model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
|
|
724
|
// model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
|
|
725
|
if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount)
|
|
725
|
if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount)
|
|
726
|
barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
|
|
726
|
barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
|
|
727
|
}
|
|
727
|
}
|
|
728
|
else
|
|
728
|
else
|
|
729
|
{
|
|
729
|
{
|
|
730
|
// model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
|
|
730
|
// model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
|
|
731
|
if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount)
|
|
731
|
if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount)
|
|
732
|
barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
|
|
732
|
barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
|
|
733
|
}
|
|
733
|
}
|
|
734
|
}
|
|
734
|
}
|
|
735
|
|
|
735
|
|
|
736
|
void QBarSeriesPrivate::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/)
|
|
736
|
void QBarSeriesPrivate::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/)
|
|
737
|
{
|
|
737
|
{
|
|
738
|
Q_Q(QBarSeries);
|
|
738
|
Q_Q(QBarSeries);
|
|
739
|
|
|
739
|
|
|
740
|
if (m_mapOrientation == Qt::Vertical) {
|
|
740
|
if (m_mapOrientation == Qt::Vertical) {
|
|
741
|
q->insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1));
|
|
741
|
q->insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1));
|
|
742
|
for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) {
|
|
742
|
for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) {
|
|
743
|
barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble());
|
|
743
|
barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble());
|
|
744
|
}
|
|
744
|
}
|
|
745
|
} else {
|
|
745
|
} else {
|
|
746
|
q->insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1));
|
|
746
|
q->insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1));
|
|
747
|
for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) {
|
|
747
|
for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) {
|
|
748
|
barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble());
|
|
748
|
barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble());
|
|
749
|
}
|
|
749
|
}
|
|
750
|
}
|
|
750
|
}
|
|
751
|
emit restructuredBars();
|
|
751
|
emit restructuredBars();
|
|
752
|
}
|
|
752
|
}
|
|
753
|
|
|
753
|
|
|
754
|
void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end)
|
|
754
|
void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end)
|
|
755
|
{
|
|
755
|
{
|
|
756
|
Q_Q(QBarSeries);
|
|
756
|
Q_Q(QBarSeries);
|
|
757
|
Q_UNUSED(parent)
|
|
757
|
Q_UNUSED(parent)
|
|
758
|
Q_UNUSED(end)
|
|
758
|
Q_UNUSED(end)
|
|
759
|
|
|
759
|
|
|
760
|
q->removeCategory(start - m_mapFirst);
|
|
760
|
q->removeCategory(start - m_mapFirst);
|
|
761
|
for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++)
|
|
761
|
for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++)
|
|
762
|
{
|
|
762
|
{
|
|
763
|
barsetAt(i)->removeValue(start - m_mapFirst);
|
|
763
|
barsetAt(i)->removeValue(start - m_mapFirst);
|
|
764
|
}
|
|
764
|
}
|
|
765
|
emit restructuredBars();
|
|
765
|
emit restructuredBars();
|
|
766
|
}
|
|
766
|
}
|
|
767
|
|
|
767
|
|
|
768
|
void QBarSeriesPrivate::barsetChanged()
|
|
768
|
void QBarSeriesPrivate::barsetChanged()
|
|
769
|
{
|
|
769
|
{
|
|
770
|
emit updatedBars();
|
|
770
|
emit updatedBars();
|
|
771
|
}
|
|
771
|
}
|
|
772
|
|
|
772
|
|
|
773
|
void QBarSeriesPrivate::scaleDomain(Domain& domain)
|
|
773
|
void QBarSeriesPrivate::scaleDomain(Domain& domain)
|
|
774
|
{
|
|
774
|
{
|
|
775
|
Q_Q(QBarSeries);
|
|
775
|
Q_Q(QBarSeries);
|
|
776
|
qreal minX(domain.minX());
|
|
776
|
qreal minX(domain.minX());
|
|
777
|
qreal minY(domain.minY());
|
|
777
|
qreal minY(domain.minY());
|
|
778
|
qreal maxX(domain.maxX());
|
|
778
|
qreal maxX(domain.maxX());
|
|
779
|
qreal maxY(domain.maxY());
|
|
779
|
qreal maxY(domain.maxY());
|
|
780
|
int tickXCount(domain.tickXCount());
|
|
780
|
int tickXCount(domain.tickXCount());
|
|
781
|
int tickYCount(domain.tickYCount());
|
|
781
|
int tickYCount(domain.tickYCount());
|
|
782
|
|
|
782
|
|
|
783
|
qreal x = q->categoryCount();
|
|
783
|
qreal x = q->categoryCount();
|
|
784
|
qreal y = q->max();
|
|
784
|
qreal y = q->max();
|
|
785
|
minX = qMin(minX, x);
|
|
785
|
minX = qMin(minX, x);
|
|
786
|
minY = qMin(minY, y);
|
|
786
|
minY = qMin(minY, y);
|
|
787
|
maxX = qMax(maxX, x);
|
|
787
|
maxX = qMax(maxX, x);
|
|
788
|
maxY = qMax(maxY, y);
|
|
788
|
maxY = qMax(maxY, y);
|
|
789
|
tickXCount = x+1;
|
|
789
|
tickXCount = x+1;
|
|
790
|
|
|
790
|
|
|
791
|
domain.setRangeX(minX,maxX,tickXCount);
|
|
791
|
domain.setRangeX(minX,maxX,tickXCount);
|
|
792
|
domain.setRangeY(minY,maxY,tickYCount);
|
|
792
|
domain.setRangeY(minY,maxY,tickYCount);
|
|
793
|
}
|
|
793
|
}
|
|
794
|
|
|
794
|
|
|
795
|
Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
|
|
795
|
Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
|
|
796
|
{
|
|
796
|
{
|
|
797
|
Q_Q(QBarSeries);
|
|
797
|
Q_Q(QBarSeries);
|
|
798
|
|
|
798
|
|
|
799
|
BarChartItem* bar = new BarChartItem(q,presenter);
|
|
799
|
BarChartItem* bar = new BarChartItem(q,presenter);
|
|
800
|
if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
|
|
800
|
if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
|
|
801
|
presenter->animator()->addAnimation(bar);
|
|
801
|
presenter->animator()->addAnimation(bar);
|
|
802
|
}
|
|
802
|
}
|
|
803
|
presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
|
|
803
|
presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
|
|
804
|
return bar;
|
|
804
|
return bar;
|
|
805
|
|
|
805
|
|
|
806
|
}
|
|
806
|
}
|
|
807
|
|
|
807
|
|
|
808
|
#include "moc_qbarseries.cpp"
|
|
808
|
#include "moc_qbarseries.cpp"
|
|
809
|
#include "moc_qbarseries_p.cpp"
|
|
809
|
#include "moc_qbarseries_p.cpp"
|
|
810
|
|
|
810
|
|
|
811
|
QTCOMMERCIALCHART_END_NAMESPACE
|
|
811
|
QTCOMMERCIALCHART_END_NAMESPACE
|