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