|
@@
-1,319
+1,312
|
|
1
|
#include "qchart.h"
|
|
1
|
#include "qchart.h"
|
|
2
|
#include "qchartseries.h"
|
|
2
|
#include "qchartseries.h"
|
|
3
|
#include "qscatterseries.h"
|
|
3
|
#include "qscatterseries.h"
|
|
4
|
#include "qscatterseries_p.h"
|
|
4
|
#include "qscatterseries_p.h"
|
|
5
|
#include "qpieseries.h"
|
|
5
|
#include "qpieseries.h"
|
|
6
|
#include "qxychartseries.h"
|
|
6
|
#include "qxychartseries.h"
|
|
7
|
|
|
7
|
|
|
8
|
#include "barchartseries.h"
|
|
8
|
#include "barchartseries.h"
|
|
9
|
#include "bargroup.h"
|
|
9
|
#include "bargroup.h"
|
|
10
|
|
|
10
|
|
|
11
|
#include "xylinechartitem_p.h"
|
|
11
|
#include "xylinechartitem_p.h"
|
|
12
|
#include "plotdomain_p.h"
|
|
12
|
#include "plotdomain_p.h"
|
|
13
|
#include "axisitem_p.h"
|
|
13
|
#include "axisitem_p.h"
|
|
14
|
#include <QGraphicsScene>
|
|
14
|
#include <QGraphicsScene>
|
|
15
|
#include <QDebug>
|
|
15
|
#include <QDebug>
|
|
16
|
|
|
16
|
|
|
17
|
QTCOMMERCIALCHART_BEGIN_NAMESPACE
|
|
17
|
QTCOMMERCIALCHART_BEGIN_NAMESPACE
|
|
18
|
|
|
18
|
|
|
19
|
QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent),
|
|
19
|
QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent),
|
|
20
|
m_background(new QGraphicsRectItem(this)),
|
|
20
|
m_background(new QGraphicsRectItem(this)),
|
|
21
|
m_title(new QGraphicsTextItem(this)),
|
|
21
|
m_title(new QGraphicsTextItem(this)),
|
|
22
|
m_axisX(new AxisItem(AxisItem::X_AXIS,this)),
|
|
22
|
m_axisX(new AxisItem(AxisItem::X_AXIS,this)),
|
|
23
|
m_axisY(new AxisItem(AxisItem::Y_AXIS,this)),
|
|
23
|
m_axisY(new AxisItem(AxisItem::Y_AXIS,this)),
|
|
24
|
m_plotDataIndex(0),
|
|
24
|
m_plotDataIndex(0),
|
|
25
|
m_marginSize(0)
|
|
25
|
m_marginSize(0)
|
|
26
|
{
|
|
26
|
{
|
|
27
|
// TODO: the default theme?
|
|
27
|
// TODO: the default theme?
|
|
28
|
setTheme(QChart::ChartThemeVanilla);
|
|
28
|
setTheme(QChart::ChartThemeVanilla);
|
|
29
|
// setFlags(QGraphicsItem::ItemClipsChildrenToShape);
|
|
29
|
// setFlags(QGraphicsItem::ItemClipsChildrenToShape);
|
|
30
|
PlotDomain domain;
|
|
30
|
PlotDomain domain;
|
|
31
|
m_plotDomainList<<domain;
|
|
31
|
m_plotDomainList<<domain;
|
|
32
|
|
|
32
|
|
|
33
|
m_chartItems<<m_axisX;
|
|
33
|
m_chartItems<<m_axisX;
|
|
34
|
m_chartItems<<m_axisY;
|
|
34
|
m_chartItems<<m_axisY;
|
|
35
|
}
|
|
35
|
}
|
|
36
|
|
|
36
|
|
|
37
|
QChart::~QChart(){}
|
|
37
|
QChart::~QChart(){}
|
|
38
|
|
|
38
|
|
|
39
|
QRectF QChart::boundingRect() const
|
|
39
|
QRectF QChart::boundingRect() const
|
|
40
|
{
|
|
40
|
{
|
|
41
|
return m_rect;
|
|
41
|
return m_rect;
|
|
42
|
}
|
|
42
|
}
|
|
43
|
|
|
43
|
|
|
44
|
void QChart::addSeries(QChartSeries* series)
|
|
44
|
void QChart::addSeries(QChartSeries* series)
|
|
45
|
{
|
|
45
|
{
|
|
46
|
// TODO: we should check the series not already added
|
|
46
|
// TODO: we should check the series not already added
|
|
47
|
|
|
47
|
|
|
48
|
m_chartSeries << series;
|
|
48
|
m_chartSeries << series;
|
|
49
|
|
|
49
|
|
|
50
|
switch(series->type())
|
|
50
|
switch(series->type())
|
|
51
|
{
|
|
51
|
{
|
|
52
|
case QChartSeries::SeriesTypeLine: {
|
|
52
|
case QChartSeries::SeriesTypeLine: {
|
|
53
|
|
|
53
|
|
|
54
|
QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series);
|
|
54
|
QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series);
|
|
55
|
// Use color defined by theme in case the series does not define a custom color
|
|
55
|
// Use color defined by theme in case the series does not define a custom color
|
|
56
|
if (!xyseries->color().isValid() && m_themeColors.count())
|
|
56
|
if (!xyseries->color().isValid() && m_themeColors.count())
|
|
57
|
xyseries->setColor(nextColor());
|
|
57
|
xyseries->setColor(nextColor());
|
|
58
|
|
|
58
|
|
|
59
|
m_plotDataIndex = 0 ;
|
|
59
|
m_plotDataIndex = 0 ;
|
|
60
|
m_plotDomainList.resize(1);
|
|
60
|
m_plotDomainList.resize(1);
|
|
61
|
|
|
61
|
|
|
62
|
PlotDomain& domain = m_plotDomainList[m_plotDataIndex];
|
|
62
|
PlotDomain& domain = m_plotDomainList[m_plotDataIndex];
|
|
63
|
|
|
63
|
|
|
64
|
for (int i = 0 ; i < xyseries->count() ; i++)
|
|
64
|
for (int i = 0 ; i < xyseries->count() ; i++)
|
|
65
|
{
|
|
65
|
{
|
|
66
|
qreal x = xyseries->x(i);
|
|
66
|
qreal x = xyseries->x(i);
|
|
67
|
qreal y = xyseries->y(i);
|
|
67
|
qreal y = xyseries->y(i);
|
|
68
|
domain.m_minX = qMin(domain.m_minX,x);
|
|
68
|
domain.m_minX = qMin(domain.m_minX,x);
|
|
69
|
domain.m_minY = qMin(domain.m_minY,y);
|
|
69
|
domain.m_minY = qMin(domain.m_minY,y);
|
|
70
|
domain.m_maxX = qMax(domain.m_maxX,x);
|
|
70
|
domain.m_maxX = qMax(domain.m_maxX,x);
|
|
71
|
domain.m_maxY = qMax(domain.m_maxY,y);
|
|
71
|
domain.m_maxY = qMax(domain.m_maxY,y);
|
|
72
|
}
|
|
72
|
}
|
|
73
|
|
|
73
|
|
|
74
|
XYLineChartItem* item = new XYLineChartItem(xyseries,this);
|
|
74
|
XYLineChartItem* item = new XYLineChartItem(xyseries,this);
|
|
75
|
m_chartItems<<item;
|
|
75
|
m_chartItems<<item;
|
|
76
|
|
|
76
|
|
|
77
|
foreach(ChartItem* i ,m_chartItems)
|
|
77
|
foreach(ChartItem* i ,m_chartItems)
|
|
78
|
i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex));
|
|
78
|
i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex));
|
|
79
|
|
|
79
|
|
|
80
|
break;
|
|
80
|
break;
|
|
81
|
}
|
|
81
|
}
|
|
82
|
case QChartSeries::SeriesTypeBar: {
|
|
82
|
case QChartSeries::SeriesTypeBar: {
|
|
83
|
|
|
83
|
|
|
84
|
qDebug() << "barSeries added";
|
|
84
|
qDebug() << "barSeries added";
|
|
85
|
BarChartSeries* barSeries = static_cast<BarChartSeries*>(series);
|
|
85
|
BarChartSeries* barSeries = static_cast<BarChartSeries*>(series);
|
|
86
|
connect(this, SIGNAL(sizeChanged(QRectF)),
|
|
86
|
connect(this, SIGNAL(sizeChanged(QRectF)),
|
|
87
|
barSeries, SLOT(chartSizeChanged(QRectF)));
|
|
87
|
barSeries, SLOT(chartSizeChanged(QRectF)));
|
|
88
|
|
|
88
|
|
|
89
|
break;
|
|
89
|
break;
|
|
90
|
}
|
|
90
|
}
|
|
91
|
case QChartSeries::SeriesTypeScatter: {
|
|
91
|
case QChartSeries::SeriesTypeScatter: {
|
|
92
|
QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
|
|
92
|
QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
|
|
93
|
scatterSeries->d->setParentItem(this);
|
|
93
|
scatterSeries->d->setParentItem(this);
|
|
94
|
// Set pre-defined colors in case the series has no colors defined
|
|
94
|
// Set pre-defined colors in case the series has no colors defined
|
|
95
|
if (!scatterSeries->markerColor().isValid())
|
|
95
|
if (!scatterSeries->markerColor().isValid())
|
|
96
|
scatterSeries->setMarkerColor(nextColor());
|
|
96
|
scatterSeries->setMarkerColor(nextColor());
|
|
97
|
connect(this, SIGNAL(sizeChanged(QRectF)),
|
|
97
|
connect(this, SIGNAL(sizeChanged(QRectF)),
|
|
98
|
scatterSeries, SLOT(chartSizeChanged(QRectF)));
|
|
98
|
scatterSeries, SLOT(chartSizeChanged(QRectF)));
|
|
99
|
// QColor nextColor = m_themeColors.takeFirst();
|
|
99
|
// QColor nextColor = m_themeColors.takeFirst();
|
|
100
|
// nextColor.setAlpha(150); // TODO: default opacity?
|
|
100
|
// nextColor.setAlpha(150); // TODO: default opacity?
|
|
101
|
// scatterSeries->setMarkerColor(nextColor);
|
|
101
|
// scatterSeries->setMarkerColor(nextColor);
|
|
102
|
break;
|
|
102
|
break;
|
|
103
|
}
|
|
103
|
}
|
|
104
|
case QChartSeries::SeriesTypePie: {
|
|
104
|
case QChartSeries::SeriesTypePie: {
|
|
105
|
QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series);
|
|
105
|
QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series);
|
|
106
|
for (int i(0); i < pieSeries->sliceCount(); i++) {
|
|
106
|
for (int i(0); i < pieSeries->sliceCount(); i++) {
|
|
107
|
if (!pieSeries->sliceColor(i).isValid())
|
|
107
|
if (!pieSeries->sliceColor(i).isValid())
|
|
108
|
pieSeries->setSliceColor(i, nextColor());
|
|
108
|
pieSeries->setSliceColor(i, nextColor());
|
|
109
|
}
|
|
109
|
}
|
|
110
|
connect(this, SIGNAL(sizeChanged(QRectF)),
|
|
110
|
connect(this, SIGNAL(sizeChanged(QRectF)),
|
|
111
|
pieSeries, SLOT(chartSizeChanged(QRectF)));
|
|
111
|
pieSeries, SLOT(chartSizeChanged(QRectF)));
|
|
112
|
|
|
112
|
|
|
113
|
// Set pre-defined colors in case the series has no colors defined
|
|
113
|
// Set pre-defined colors in case the series has no colors defined
|
|
114
|
// TODO: how to define the color for all the slices of a pie?
|
|
114
|
// TODO: how to define the color for all the slices of a pie?
|
|
115
|
// for (int (i); i < pieSeries.sliceCount(); i++)
|
|
115
|
// for (int (i); i < pieSeries.sliceCount(); i++)
|
|
116
|
break;
|
|
116
|
break;
|
|
117
|
}
|
|
117
|
}
|
|
118
|
}
|
|
118
|
}
|
|
119
|
}
|
|
119
|
}
|
|
120
|
|
|
120
|
|
|
121
|
QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type)
|
|
121
|
QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type)
|
|
122
|
{
|
|
122
|
{
|
|
123
|
// TODO: support also other types; not only scatter and pie
|
|
123
|
// TODO: support also other types; not only scatter and pie
|
|
124
|
|
|
124
|
|
|
125
|
QChartSeries *series(0);
|
|
125
|
QChartSeries *series(0);
|
|
126
|
|
|
126
|
|
|
127
|
switch (type) {
|
|
127
|
switch (type) {
|
|
128
|
case QChartSeries::SeriesTypeLine: {
|
|
128
|
case QChartSeries::SeriesTypeLine: {
|
|
129
|
series = QXYChartSeries::create();
|
|
129
|
series = QXYChartSeries::create();
|
|
130
|
break;
|
|
130
|
break;
|
|
131
|
}
|
|
131
|
}
|
|
132
|
case QChartSeries::SeriesTypeBar: {
|
|
132
|
case QChartSeries::SeriesTypeBar: {
|
|
133
|
series = new BarChartSeries(this);
|
|
133
|
series = new BarChartSeries(this);
|
|
134
|
break;
|
|
134
|
break;
|
|
135
|
}
|
|
135
|
}
|
|
136
|
case QChartSeries::SeriesTypeScatter: {
|
|
136
|
case QChartSeries::SeriesTypeScatter: {
|
|
137
|
series = new QScatterSeries(this);
|
|
137
|
series = new QScatterSeries(this);
|
|
138
|
break;
|
|
138
|
break;
|
|
139
|
}
|
|
139
|
}
|
|
140
|
case QChartSeries::SeriesTypePie: {
|
|
140
|
case QChartSeries::SeriesTypePie: {
|
|
141
|
series = new QPieSeries(this);
|
|
141
|
series = new QPieSeries(this);
|
|
142
|
break;
|
|
142
|
break;
|
|
143
|
}
|
|
143
|
}
|
|
144
|
default:
|
|
144
|
default:
|
|
145
|
Q_ASSERT(false);
|
|
145
|
Q_ASSERT(false);
|
|
146
|
break;
|
|
146
|
break;
|
|
147
|
}
|
|
147
|
}
|
|
148
|
|
|
148
|
|
|
149
|
addSeries(series);
|
|
149
|
addSeries(series);
|
|
150
|
return series;
|
|
150
|
return series;
|
|
151
|
}
|
|
151
|
}
|
|
152
|
|
|
152
|
|
|
153
|
void QChart::setSize(const QSize& size)
|
|
153
|
void QChart::setSize(const QSize& size)
|
|
154
|
{
|
|
154
|
{
|
|
155
|
m_rect = QRect(QPoint(0,0),size);
|
|
155
|
m_rect = QRect(QPoint(0,0),size);
|
|
156
|
QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
|
|
156
|
QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
|
|
157
|
|
|
157
|
|
|
158
|
|
|
158
|
|
|
159
|
//recalculate background gradient
|
|
159
|
//recalculate background gradient
|
|
160
|
m_background->setRect(rect);
|
|
160
|
m_background->setRect(rect);
|
|
161
|
m_backgroundGradient.setFinalStop(0,m_background->rect().height());
|
|
161
|
m_backgroundGradient.setFinalStop(0,m_background->rect().height());
|
|
162
|
m_background->setBrush(m_backgroundGradient);
|
|
162
|
m_background->setBrush(m_backgroundGradient);
|
|
163
|
|
|
163
|
|
|
164
|
//resize elements
|
|
164
|
//resize elements
|
|
165
|
foreach (ChartItem* item ,m_chartItems) {
|
|
165
|
foreach (ChartItem* item ,m_chartItems) {
|
|
166
|
item->setPos(rect.topLeft());
|
|
166
|
item->setPos(rect.topLeft());
|
|
167
|
item->setSize(rect.size());
|
|
167
|
item->setSize(rect.size());
|
|
168
|
|
|
168
|
|
|
169
|
}
|
|
169
|
}
|
|
170
|
// TODO: TTD for setting scale
|
|
170
|
// TODO: TTD for setting scale
|
|
171
|
//emit scaleChanged(100, 100);
|
|
171
|
//emit scaleChanged(100, 100);
|
|
172
|
// TODO: calculate the origo
|
|
172
|
// TODO: calculate the origo
|
|
173
|
// TODO: not sure if emitting a signal here is the best from performance point of view
|
|
173
|
// TODO: not sure if emitting a signal here is the best from performance point of view
|
|
174
|
emit sizeChanged(QRectF(0, 0, size.width(), size.height()));
|
|
174
|
emit sizeChanged(QRectF(0, 0, size.width(), size.height()));
|
|
175
|
|
|
175
|
|
|
176
|
update();
|
|
176
|
update();
|
|
177
|
}
|
|
177
|
}
|
|
178
|
|
|
178
|
|
|
179
|
void QChart::setBackgroundColor(const QColor& color)
|
|
179
|
void QChart::setBackgroundColor(const QColor& color)
|
|
180
|
{
|
|
180
|
{
|
|
181
|
m_backgroundGradient.setColorAt( 0.0, Qt::white);
|
|
181
|
m_backgroundGradient.setColorAt( 0.0, Qt::white);
|
|
182
|
m_backgroundGradient.setColorAt( 1.0, color);
|
|
182
|
m_backgroundGradient.setColorAt( 1.0, color);
|
|
183
|
m_background->setBrush(m_backgroundGradient);
|
|
183
|
m_background->setBrush(m_backgroundGradient);
|
|
184
|
m_background->setPen(Qt::NoPen);
|
|
184
|
m_background->setPen(Qt::NoPen);
|
|
185
|
m_background->update();
|
|
185
|
m_background->update();
|
|
186
|
}
|
|
186
|
}
|
|
187
|
|
|
187
|
|
|
188
|
void QChart::setTitle(const QString& title)
|
|
188
|
void QChart::setTitle(const QString& title)
|
|
189
|
{
|
|
189
|
{
|
|
190
|
m_title->setPlainText(title);
|
|
190
|
m_title->setPlainText(title);
|
|
191
|
}
|
|
191
|
}
|
|
192
|
|
|
192
|
|
|
193
|
int QChart::margin() const
|
|
193
|
int QChart::margin() const
|
|
194
|
{
|
|
194
|
{
|
|
195
|
return m_marginSize;
|
|
195
|
return m_marginSize;
|
|
196
|
}
|
|
196
|
}
|
|
197
|
|
|
197
|
|
|
198
|
void QChart::setMargin(int margin)
|
|
198
|
void QChart::setMargin(int margin)
|
|
199
|
{
|
|
199
|
{
|
|
200
|
m_marginSize = margin;
|
|
200
|
m_marginSize = margin;
|
|
201
|
}
|
|
201
|
}
|
|
202
|
|
|
202
|
|
|
203
|
void QChart::setTheme(QChart::ChartThemeId theme)
|
|
203
|
void QChart::setTheme(QChart::ChartThemeId theme)
|
|
204
|
{
|
|
204
|
{
|
|
205
|
// if (theme != m_currentTheme) {
|
|
205
|
// if (theme != m_currentTheme) {
|
|
206
|
m_themeColors.clear();
|
|
206
|
m_themeColors.clear();
|
|
207
|
|
|
207
|
|
|
208
|
// TODO: define color themes
|
|
208
|
// TODO: define color themes
|
|
209
|
switch (theme) {
|
|
209
|
switch (theme) {
|
|
210
|
case QChart::ChartThemeVanilla:
|
|
210
|
case QChart::ChartThemeVanilla:
|
|
211
|
m_themeColors.append(QColor(217, 197, 116));
|
|
211
|
m_themeColors.append(QColor(217, 197, 116));
|
|
212
|
m_themeColors.append(QColor(214, 168, 150));
|
|
212
|
m_themeColors.append(QColor(214, 168, 150));
|
|
213
|
m_themeColors.append(QColor(160, 160, 113));
|
|
213
|
m_themeColors.append(QColor(160, 160, 113));
|
|
214
|
m_themeColors.append(QColor(210, 210, 52));
|
|
214
|
m_themeColors.append(QColor(210, 210, 52));
|
|
215
|
m_themeColors.append(QColor(136, 114, 58));
|
|
215
|
m_themeColors.append(QColor(136, 114, 58));
|
|
216
|
break;
|
|
216
|
break;
|
|
217
|
case QChart::ChartThemeIcy:
|
|
217
|
case QChart::ChartThemeIcy:
|
|
218
|
m_themeColors.append(QColor(0, 3, 165));
|
|
218
|
m_themeColors.append(QColor(0, 3, 165));
|
|
219
|
m_themeColors.append(QColor(49, 52, 123));
|
|
219
|
m_themeColors.append(QColor(49, 52, 123));
|
|
220
|
m_themeColors.append(QColor(71, 114, 187));
|
|
220
|
m_themeColors.append(QColor(71, 114, 187));
|
|
221
|
m_themeColors.append(QColor(48, 97, 87));
|
|
221
|
m_themeColors.append(QColor(48, 97, 87));
|
|
222
|
m_themeColors.append(QColor(19, 71, 90));
|
|
222
|
m_themeColors.append(QColor(19, 71, 90));
|
|
223
|
m_themeColors.append(QColor(110, 70, 228));
|
|
223
|
m_themeColors.append(QColor(110, 70, 228));
|
|
224
|
break;
|
|
224
|
break;
|
|
225
|
case QChart::ChartThemeGrayscale:
|
|
225
|
case QChart::ChartThemeGrayscale:
|
|
226
|
m_themeColors.append(QColor(0, 0, 0));
|
|
226
|
m_themeColors.append(QColor(0, 0, 0));
|
|
227
|
m_themeColors.append(QColor(50, 50, 50));
|
|
227
|
m_themeColors.append(QColor(50, 50, 50));
|
|
228
|
m_themeColors.append(QColor(100, 100, 100));
|
|
228
|
m_themeColors.append(QColor(100, 100, 100));
|
|
229
|
m_themeColors.append(QColor(140, 140, 140));
|
|
229
|
m_themeColors.append(QColor(140, 140, 140));
|
|
230
|
m_themeColors.append(QColor(180, 180, 180));
|
|
230
|
m_themeColors.append(QColor(180, 180, 180));
|
|
231
|
break;
|
|
231
|
break;
|
|
232
|
default:
|
|
232
|
default:
|
|
233
|
Q_ASSERT(false);
|
|
233
|
Q_ASSERT(false);
|
|
234
|
break;
|
|
234
|
break;
|
|
235
|
}
|
|
235
|
}
|
|
236
|
|
|
236
|
|
|
237
|
foreach(QChartSeries* series, m_chartSeries) {
|
|
237
|
foreach(QChartSeries* series, m_chartSeries) {
|
|
238
|
// TODO: other series interested on themes?
|
|
238
|
// TODO: other series interested on themes?
|
|
239
|
if (series->type() == QChartSeries::SeriesTypeLine) {
|
|
239
|
if (series->type() == QChartSeries::SeriesTypeLine) {
|
|
240
|
QXYChartSeries *lineseries = reinterpret_cast<QXYChartSeries *>(series);
|
|
240
|
QXYChartSeries *lineseries = reinterpret_cast<QXYChartSeries *>(series);
|
|
241
|
lineseries->setColor(nextColor());
|
|
241
|
lineseries->setColor(nextColor());
|
|
242
|
} else if (series->type() == QChartSeries::SeriesTypeScatter) {
|
|
242
|
} else if (series->type() == QChartSeries::SeriesTypeScatter) {
|
|
243
|
QScatterSeries *scatter = qobject_cast<QScatterSeries *>(series);
|
|
243
|
QScatterSeries *scatter = qobject_cast<QScatterSeries *>(series);
|
|
244
|
scatter->setMarkerColor(nextColor());
|
|
244
|
scatter->setMarkerColor(nextColor());
|
|
245
|
} else if (series->type() == QChartSeries::SeriesTypePie) {
|
|
245
|
} else if (series->type() == QChartSeries::SeriesTypePie) {
|
|
246
|
QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series);
|
|
246
|
QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series);
|
|
247
|
for (int i(0); i < pieSeries->sliceCount(); i++)
|
|
247
|
for (int i(0); i < pieSeries->sliceCount(); i++)
|
|
248
|
pieSeries->setSliceColor(i, nextColor());
|
|
248
|
pieSeries->setSliceColor(i, nextColor());
|
|
249
|
}
|
|
249
|
}
|
|
250
|
}
|
|
250
|
}
|
|
251
|
update();
|
|
251
|
update();
|
|
252
|
}
|
|
252
|
}
|
|
253
|
|
|
253
|
|
|
254
|
QColor QChart::nextColor()
|
|
254
|
QColor QChart::nextColor()
|
|
255
|
{
|
|
255
|
{
|
|
256
|
QColor nextColor = m_themeColors.first();
|
|
256
|
QColor nextColor = m_themeColors.first();
|
|
257
|
m_themeColors.move(0, m_themeColors.size() - 1);
|
|
257
|
m_themeColors.move(0, m_themeColors.size() - 1);
|
|
258
|
return nextColor;
|
|
258
|
return nextColor;
|
|
259
|
}
|
|
259
|
}
|
|
260
|
|
|
260
|
|
|
261
|
void QChart::zoomInToRect(const QRect& rectangle)
|
|
261
|
void QChart::zoomInToRect(const QRect& rectangle)
|
|
262
|
{
|
|
262
|
{
|
|
263
|
|
|
263
|
|
|
264
|
if(!rectangle.isValid()) return;
|
|
264
|
if(!rectangle.isValid()) return;
|
|
265
|
|
|
265
|
|
|
266
|
qreal margin = this->margin();
|
|
266
|
qreal margin = this->margin();
|
|
267
|
|
|
267
|
|
|
268
|
QRect rect = rectangle.normalized();
|
|
268
|
QRect rect = rectangle.normalized();
|
|
269
|
rect.translate(-margin, -margin);
|
|
269
|
rect.translate(-margin, -margin);
|
|
270
|
|
|
270
|
|
|
271
|
PlotDomain& oldDomain = m_plotDomainList[m_plotDataIndex];
|
|
271
|
PlotDomain& oldDomain = m_plotDomainList[m_plotDataIndex];
|
|
272
|
PlotDomain newDomain;
|
|
|
|
|
273
|
|
|
272
|
|
|
274
|
qreal dx = oldDomain.spanX() / (m_rect.width() - 2 * margin);
|
|
273
|
PlotDomain domain = oldDomain.subDomain(rect,m_rect.width() - 2 * margin,m_rect.height() - 2 * margin);
|
|
275
|
qreal dy = oldDomain.spanY() / (m_rect.height() - 2 * margin);
|
|
|
|
|
276
|
|
|
|
|
|
277
|
newDomain.m_minX = oldDomain.m_minX + dx * rect.left();
|
|
|
|
|
278
|
newDomain.m_maxX = oldDomain.m_minX + dx * rect.right();
|
|
|
|
|
279
|
newDomain.m_minY = oldDomain.m_maxY - dy * rect.bottom();
|
|
|
|
|
280
|
newDomain.m_maxY = oldDomain.m_maxY - dy * rect.top();
|
|
|
|
|
281
|
|
|
274
|
|
|
282
|
m_plotDomainList.resize(m_plotDataIndex + 1);
|
|
275
|
m_plotDomainList.resize(m_plotDataIndex + 1);
|
|
283
|
m_plotDomainList<<newDomain;
|
|
276
|
m_plotDomainList<<domain;
|
|
284
|
m_plotDataIndex++;
|
|
277
|
m_plotDataIndex++;
|
|
285
|
|
|
278
|
|
|
286
|
foreach (ChartItem* item ,m_chartItems)
|
|
279
|
foreach (ChartItem* item ,m_chartItems)
|
|
287
|
item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
|
|
280
|
item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
|
|
288
|
update();
|
|
281
|
update();
|
|
289
|
}
|
|
282
|
}
|
|
290
|
|
|
283
|
|
|
291
|
void QChart::zoomIn()
|
|
284
|
void QChart::zoomIn()
|
|
292
|
{
|
|
285
|
{
|
|
293
|
if (m_plotDataIndex < m_plotDomainList.count() - 1) {
|
|
286
|
if (m_plotDataIndex < m_plotDomainList.count() - 1) {
|
|
294
|
m_plotDataIndex++;
|
|
287
|
m_plotDataIndex++;
|
|
295
|
foreach (ChartItem* item ,m_chartItems)
|
|
288
|
foreach (ChartItem* item ,m_chartItems)
|
|
296
|
item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
|
|
289
|
item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
|
|
297
|
update();
|
|
290
|
update();
|
|
298
|
}else{
|
|
291
|
}else{
|
|
299
|
QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
|
|
292
|
QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
|
|
300
|
rect.setWidth(rect.width()/2);
|
|
293
|
rect.setWidth(rect.width()/2);
|
|
301
|
rect.setHeight(rect.height()/2);
|
|
294
|
rect.setHeight(rect.height()/2);
|
|
302
|
rect.moveCenter(m_rect.center());
|
|
295
|
rect.moveCenter(m_rect.center());
|
|
303
|
zoomInToRect(rect);
|
|
296
|
zoomInToRect(rect);
|
|
304
|
}
|
|
297
|
}
|
|
305
|
}
|
|
298
|
}
|
|
306
|
|
|
299
|
|
|
307
|
void QChart::zoomOut()
|
|
300
|
void QChart::zoomOut()
|
|
308
|
{
|
|
301
|
{
|
|
309
|
if (m_plotDataIndex > 0) {
|
|
302
|
if (m_plotDataIndex > 0) {
|
|
310
|
m_plotDataIndex--;
|
|
303
|
m_plotDataIndex--;
|
|
311
|
foreach (ChartItem* item ,m_chartItems)
|
|
304
|
foreach (ChartItem* item ,m_chartItems)
|
|
312
|
item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
|
|
305
|
item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
|
|
313
|
update();
|
|
306
|
update();
|
|
314
|
}
|
|
307
|
}
|
|
315
|
}
|
|
308
|
}
|
|
316
|
|
|
309
|
|
|
317
|
#include "moc_qchart.cpp"
|
|
310
|
#include "moc_qchart.cpp"
|
|
318
|
|
|
311
|
|
|
319
|
QTCOMMERCIALCHART_END_NAMESPACE
|
|
312
|
QTCOMMERCIALCHART_END_NAMESPACE
|