@@ -86,8 +86,8 QChartSeries* QChart::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries: | |||
|
86 | 86 | switch (type) { |
|
87 | 87 | case QChartSeries::SeriesTypeScatter: { |
|
88 | 88 | QScatterSeries *scatterSeries = new QScatterSeries(x, y, this); |
|
89 |
connect(this, SIGNAL(sizeChanged(QRectF |
|
|
90 |
scatterSeries, SLOT(chartSizeChanged(QRectF |
|
|
89 | connect(this, SIGNAL(sizeChanged(QRectF)), | |
|
90 | scatterSeries, SLOT(chartSizeChanged(QRectF))); | |
|
91 | 91 | scatterSeries->d->setParentItem(this); |
|
92 | 92 | return scatterSeries; |
|
93 | 93 | } |
@@ -95,8 +95,8 QChartSeries* QChart::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries: | |||
|
95 | 95 | // TODO: we now have also a list of y values as a parameter, it is ignored |
|
96 | 96 | // we should use a generic data class instead of list of x and y values |
|
97 | 97 | QPieSeries *pieSeries = new QPieSeries(x, this); |
|
98 |
connect(this, SIGNAL(sizeChanged(QRectF |
|
|
99 |
pieSeries, SLOT(chartSizeChanged(QRectF |
|
|
98 | connect(this, SIGNAL(sizeChanged(QRectF)), | |
|
99 | pieSeries, SLOT(chartSizeChanged(QRectF))); | |
|
100 | 100 | return pieSeries; |
|
101 | 101 | } |
|
102 | 102 | default: |
@@ -113,12 +113,11 void QChart::setSize(const QSizeF& size) | |||
|
113 | 113 | m_grid->setPos(m_rect.topLeft()); |
|
114 | 114 | m_grid->setSize(m_rect.size()); |
|
115 | 115 | |
|
116 |
// TODO: |
|
|
116 | // TODO: TTD for setting scale | |
|
117 | //emit scaleChanged(100, 100); | |
|
117 | 118 | // TODO: calculate the origo |
|
118 | 119 | // TODO: not sure if emitting a signal here is the best from performance point of view |
|
119 | const qreal xscale = size.width() / 100; | |
|
120 | const qreal yscale = size.height() / 100; | |
|
121 | emit sizeChanged(QRectF(0, 0, size.width(), size.height()), xscale, yscale); | |
|
120 | emit sizeChanged(QRectF(0, 0, size.width(), size.height())); | |
|
122 | 121 | |
|
123 | 122 | for (int i(0); i < m_plotDomainList.size(); i++) |
|
124 | 123 | m_plotDomainList[i].m_viewportRect = m_rect; |
@@ -42,7 +42,8 public: | |||
|
42 | 42 | int margin() const; |
|
43 | 43 | |
|
44 | 44 | signals: |
|
45 |
void sizeChanged(QRectF rect |
|
|
45 | void sizeChanged(QRectF rect); | |
|
46 | void scaleChanged(qreal xscale, qreal yscale); | |
|
46 | 47 | |
|
47 | 48 | private: |
|
48 | 49 | Q_DISABLE_COPY(QChart) |
@@ -9,24 +9,16 QPieSeries::QPieSeries(QList<qreal> x, QGraphicsObject *parent) : | |||
|
9 | 9 | QChartSeries(parent), |
|
10 | 10 | m_x(x) |
|
11 | 11 | { |
|
12 | } | |
|
13 | ||
|
14 | QPieSeries::~QPieSeries() | |
|
15 | { | |
|
16 | } | |
|
17 | ||
|
18 | void QPieSeries::chartSizeChanged(QRectF rect, qreal xscale, qreal yscale) | |
|
19 | { | |
|
12 | // Create slices | |
|
20 | 13 | qreal fullPie = 360; |
|
21 | 14 | qreal total = 0; |
|
22 | 15 | foreach (qreal value, m_x) |
|
23 | 16 | total += value; |
|
24 | 17 | |
|
25 | // We must have a parent for the graphics items we create | |
|
26 | // TODO: maybe QChartSeries needs to be a QGraphicsObject to make this clear for the users? | |
|
27 | QGraphicsItem *parentItem = qobject_cast<QGraphicsItem *>(parent()); | |
|
18 | QGraphicsItem *parentItem = qobject_cast<QGraphicsItem *>(parent); | |
|
28 | 19 | Q_ASSERT(parentItem); |
|
29 | 20 | qreal angle = 0; |
|
21 | // TODO: no need to create new slices in case size changed; we should re-use the existing ones | |
|
30 | 22 | foreach (qreal value, m_x) { |
|
31 | 23 | qreal span = value / total * fullPie; |
|
32 | 24 | PieSlice *slice = new PieSlice(randomColor(), angle, span); |
@@ -36,6 +28,14 void QPieSeries::chartSizeChanged(QRectF rect, qreal xscale, qreal yscale) | |||
|
36 | 28 | } |
|
37 | 29 | } |
|
38 | 30 | |
|
31 | QPieSeries::~QPieSeries() | |
|
32 | { | |
|
33 | } | |
|
34 | ||
|
35 | void QPieSeries::chartSizeChanged(QRectF /*rect*/) | |
|
36 | { | |
|
37 | } | |
|
38 | ||
|
39 | 39 | QColor QPieSeries::randomColor() |
|
40 | 40 | { |
|
41 | 41 | QColor c; |
@@ -24,7 +24,7 public: // from QChartSeries | |||
|
24 | 24 | QChartSeriesType type() const { return QChartSeries::SeriesTypePie; } |
|
25 | 25 | |
|
26 | 26 | public Q_SLOTS: |
|
27 |
void chartSizeChanged(QRectF rect |
|
|
27 | void chartSizeChanged(QRectF rect); | |
|
28 | 28 | |
|
29 | 29 | private: |
|
30 | 30 | //Q_DECLARE_PRIVATE(QPieSeries) |
@@ -12,22 +12,28 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
12 | 12 | QScatterSeriesPrivate::QScatterSeriesPrivate(QList<qreal> x, QList<qreal> y, QGraphicsItem *parent) : |
|
13 | 13 | QGraphicsItem(parent), |
|
14 | 14 | m_x(x), |
|
15 | m_y(y) | |
|
15 | m_y(y), | |
|
16 | m_scalex(100), // TODO: let the use define the scale (or autoscaled) | |
|
17 | m_scaley(100) | |
|
16 | 18 | { |
|
19 | resize(parent->boundingRect()); | |
|
17 | 20 | } |
|
18 | 21 | |
|
19 |
void QScatterSeriesPrivate::resize(QRectF rect |
|
|
22 | void QScatterSeriesPrivate::resize(QRectF rect) | |
|
20 | 23 | { |
|
21 | 24 | m_scenex.clear(); |
|
22 | 25 | m_sceney.clear(); |
|
23 | 26 | |
|
24 | 27 | foreach(qreal x, m_x) |
|
25 |
m_scenex.append(rect.left() + x * |
|
|
28 | m_scenex.append(rect.left() + x * (rect.width() / m_scalex)); | |
|
26 | 29 | |
|
27 | 30 | foreach(qreal y, m_y) |
|
28 |
m_sceney.append(rect.bottom() - y * |
|
|
31 | m_sceney.append(rect.bottom() - y * (rect.height() / m_scaley)); | |
|
29 | 32 | } |
|
30 | 33 | |
|
34 | // TODO: | |
|
35 | //void QScatterSeriesPrivate::setAxisScale(qreal xscale, qreal yscale) | |
|
36 | ||
|
31 | 37 | QRectF QScatterSeriesPrivate::boundingRect() const |
|
32 | 38 | { |
|
33 | 39 | return QRectF(0, 0, 55, 100); |
@@ -38,7 +44,7 void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsI | |||
|
38 | 44 | QPen pen = painter->pen(); |
|
39 | 45 | QBrush brush = pen.brush(); |
|
40 | 46 | // TODO: The opacity should be user definable... |
|
41 |
brush.setColor(QColor(255, 82, 0, |
|
|
47 | brush.setColor(QColor(255, 82, 0, 100)); | |
|
42 | 48 | pen.setBrush(brush); |
|
43 | 49 | pen.setWidth(4); |
|
44 | 50 | painter->setPen(pen); |
@@ -58,14 +64,20 QScatterSeries::QScatterSeries(QList<qreal> x, QList<qreal> y, QObject *parent) | |||
|
58 | 64 | { |
|
59 | 65 | } |
|
60 | 66 | |
|
61 |
void QScatterSeries::chartSizeChanged(QRectF rect |
|
|
67 | void QScatterSeries::chartSizeChanged(QRectF rect) | |
|
62 | 68 | { |
|
63 | 69 | // Recalculate scatter data point locations on the scene |
|
64 | 70 | // d->transform().reset(); |
|
65 | 71 | // d->transform().translate(); |
|
66 |
d->resize(rect |
|
|
72 | d->resize(rect); | |
|
67 | 73 | } |
|
68 | 74 | |
|
75 | // TODO: | |
|
76 | //void QScatterSeries::chartScaleChanged(qreal xscale, qreal yscale) | |
|
77 | //{ | |
|
78 | // d->rescale(xscale, yscale); | |
|
79 | //} | |
|
80 | ||
|
69 | 81 | QScatterSeries::~QScatterSeries() |
|
70 | 82 | { |
|
71 | 83 | delete d; |
@@ -19,7 +19,8 public: // from QChartSeries | |||
|
19 | 19 | QChartSeriesType type() const { return QChartSeries::SeriesTypeScatter; } |
|
20 | 20 | |
|
21 | 21 | public Q_SLOTS: |
|
22 |
void chartSizeChanged(QRectF rect |
|
|
22 | void chartSizeChanged(QRectF rect); | |
|
23 | //void chartScaleChanged(qreal xscale, qreal yscale); | |
|
23 | 24 | |
|
24 | 25 | private: |
|
25 | 26 | Q_DECLARE_PRIVATE(QScatterSeries) |
@@ -15,13 +15,15 public: | |||
|
15 | 15 | QScatterSeriesPrivate(QList<qreal> x, QList<qreal> y, QGraphicsItem *parent); |
|
16 | 16 | |
|
17 | 17 | public: // from QGraphicsItem |
|
18 |
void resize(QRectF rect |
|
|
18 | void resize(QRectF rect); | |
|
19 | 19 | QRectF boundingRect() const; |
|
20 | 20 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
21 | 21 | |
|
22 | 22 | // TODO: use the chart data class instead of list of x and y values? |
|
23 | 23 | QList<qreal> m_x; |
|
24 | 24 | QList<qreal> m_y; |
|
25 | qreal m_scalex; | |
|
26 | qreal m_scaley; | |
|
25 | 27 | QList<qreal> m_scenex; |
|
26 | 28 | QList<qreal> m_sceney; |
|
27 | 29 | }; |
General Comments 0
You need to be logged in to leave comments.
Login now