##// END OF EJS Templates
Removed scale from chart's sizeChanged signals
Tero Ahola -
r54:f2e3dfe7c506
parent child
Show More
@@ -1,151 +1,150
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 #include "xylinechartitem_p.h"
7 #include "xylinechartitem_p.h"
8 #include "xyplotdomain_p.h"
8 #include "xyplotdomain_p.h"
9 #include "axis_p.h"
9 #include "axis_p.h"
10 #include "xygrid_p.h"
10 #include "xygrid_p.h"
11 #include <QGraphicsScene>
11 #include <QGraphicsScene>
12 #include <QDebug>
12 #include <QDebug>
13
13
14 QTCOMMERCIALCHART_BEGIN_NAMESPACE
14 QTCOMMERCIALCHART_BEGIN_NAMESPACE
15
15
16 QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent),
16 QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent),
17 m_axisX(new Axis(this)),
17 m_axisX(new Axis(this)),
18 m_axisY(new Axis(this)),
18 m_axisY(new Axis(this)),
19 m_grid(new XYGrid(this)),
19 m_grid(new XYGrid(this)),
20 m_plotDataIndex(0),
20 m_plotDataIndex(0),
21 m_marginSize(0)
21 m_marginSize(0)
22 {
22 {
23 // setFlags(QGraphicsItem::ItemClipsChildrenToShape);
23 // setFlags(QGraphicsItem::ItemClipsChildrenToShape);
24 // set axis
24 // set axis
25 m_axisY->rotate(90);
25 m_axisY->rotate(90);
26 }
26 }
27
27
28 QChart::~QChart(){}
28 QChart::~QChart(){}
29
29
30 QRectF QChart::boundingRect() const
30 QRectF QChart::boundingRect() const
31 {
31 {
32 return m_rect;
32 return m_rect;
33 }
33 }
34
34
35 void QChart::addSeries(QChartSeries* series)
35 void QChart::addSeries(QChartSeries* series)
36 {
36 {
37 // TODO: we should check the series not already added
37 // TODO: we should check the series not already added
38
38
39 m_series<<series;
39 m_series<<series;
40
40
41 switch(series->type())
41 switch(series->type())
42 {
42 {
43 case QChartSeries::SeriesTypeLine: {
43 case QChartSeries::SeriesTypeLine: {
44
44
45 QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series);
45 QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series);
46
46
47 XYPlotDomain domain;
47 XYPlotDomain domain;
48 //TODO "nice numbers algorithm"
48 //TODO "nice numbers algorithm"
49 domain.m_ticksX=4;
49 domain.m_ticksX=4;
50 domain.m_ticksY=4;
50 domain.m_ticksY=4;
51
51
52 for (int i = 0 ; i < xyseries->count() ; i++)
52 for (int i = 0 ; i < xyseries->count() ; i++)
53 {
53 {
54 qreal x = xyseries->x(i);
54 qreal x = xyseries->x(i);
55 qreal y = xyseries->y(i);
55 qreal y = xyseries->y(i);
56 domain.m_minX = qMin(domain.m_minX,x);
56 domain.m_minX = qMin(domain.m_minX,x);
57 domain.m_minY = qMin(domain.m_minY,y);
57 domain.m_minY = qMin(domain.m_minY,y);
58 domain.m_maxX = qMax(domain.m_maxX,x);
58 domain.m_maxX = qMax(domain.m_maxX,x);
59 domain.m_maxY = qMax(domain.m_maxY,y);
59 domain.m_maxY = qMax(domain.m_maxY,y);
60 }
60 }
61
61
62 XYLineChartItem* item = new XYLineChartItem(xyseries,this);
62 XYLineChartItem* item = new XYLineChartItem(xyseries,this);
63 item->updateXYPlotDomain(domain);
63 item->updateXYPlotDomain(domain);
64 m_plotDomainList<<domain;
64 m_plotDomainList<<domain;
65 m_xyLineChartItems<<item;
65 m_xyLineChartItems<<item;
66 break;
66 break;
67 }
67 }
68 // TODO: Not tested:
68 // TODO: Not tested:
69 // case QChartSeries::SeriesTypeScatter: {
69 // case QChartSeries::SeriesTypeScatter: {
70 // QScatterSeries *scatter = qobject_cast<QScatterSeries *>(series);
70 // QScatterSeries *scatter = qobject_cast<QScatterSeries *>(series);
71 // if (scatter) {
71 // if (scatter) {
72 // scatter->d->setParentItem(this);
72 // scatter->d->setParentItem(this);
73 // scene()->addItem(scatter->d);
73 // scene()->addItem(scatter->d);
74 // }
74 // }
75 // break;
75 // break;
76 // }
76 // }
77 }
77 }
78 }
78 }
79
79
80 QChartSeries* QChart::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type)
80 QChartSeries* QChart::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type)
81 {
81 {
82 // TODO: support also other types; not only scatter and pie
82 // TODO: support also other types; not only scatter and pie
83 Q_ASSERT(type == QChartSeries::SeriesTypeScatter
83 Q_ASSERT(type == QChartSeries::SeriesTypeScatter
84 || type == QChartSeries::SeriesTypePie);
84 || type == QChartSeries::SeriesTypePie);
85
85
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, qreal, qreal)),
89 connect(this, SIGNAL(sizeChanged(QRectF)),
90 scatterSeries, SLOT(chartSizeChanged(QRectF, qreal, qreal)));
90 scatterSeries, SLOT(chartSizeChanged(QRectF)));
91 scatterSeries->d->setParentItem(this);
91 scatterSeries->d->setParentItem(this);
92 return scatterSeries;
92 return scatterSeries;
93 }
93 }
94 case QChartSeries::SeriesTypePie: {
94 case QChartSeries::SeriesTypePie: {
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, qreal, qreal)),
98 connect(this, SIGNAL(sizeChanged(QRectF)),
99 pieSeries, SLOT(chartSizeChanged(QRectF, qreal, qreal)));
99 pieSeries, SLOT(chartSizeChanged(QRectF)));
100 return pieSeries;
100 return pieSeries;
101 }
101 }
102 default:
102 default:
103 break;
103 break;
104 }
104 }
105
105
106 return 0;
106 return 0;
107 }
107 }
108
108
109 void QChart::setSize(const QSizeF& size)
109 void QChart::setSize(const QSizeF& size)
110 {
110 {
111 m_rect = QRect(QPoint(0,0),size.toSize());
111 m_rect = QRect(QPoint(0,0),size.toSize());
112 m_rect.adjust(margin(),margin(), -margin(), -margin());
112 m_rect.adjust(margin(),margin(), -margin(), -margin());
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: calculate the scale
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;
125
124
126 // TODO: line chart items are updated separately as they don't support update
125 // TODO: line chart items are updated separately as they don't support update
127 // via sizeChanged signal
126 // via sizeChanged signal
128 foreach(XYLineChartItem* item ,m_xyLineChartItems)
127 foreach(XYLineChartItem* item ,m_xyLineChartItems)
129 item->updateXYPlotDomain(m_plotDomainList.at(m_plotDataIndex));
128 item->updateXYPlotDomain(m_plotDomainList.at(m_plotDataIndex));
130
129
131
130
132 if (m_plotDomainList.count())
131 if (m_plotDomainList.count())
133 m_grid->setXYPlotData(m_plotDomainList.at(m_plotDataIndex));
132 m_grid->setXYPlotData(m_plotDomainList.at(m_plotDataIndex));
134
133
135 update();
134 update();
136 }
135 }
137
136
138 int QChart::margin() const
137 int QChart::margin() const
139 {
138 {
140 return m_marginSize;
139 return m_marginSize;
141 }
140 }
142
141
143 void QChart::setMargin(int margin)
142 void QChart::setMargin(int margin)
144 {
143 {
145 m_marginSize = margin;
144 m_marginSize = margin;
146 }
145 }
147
146
148 #include "moc_qchart.cpp"
147 #include "moc_qchart.cpp"
149
148
150
149
151 QTCOMMERCIALCHART_END_NAMESPACE
150 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,63 +1,64
1 #ifndef CHART_H
1 #ifndef CHART_H
2 #define CHART_H
2 #define CHART_H
3
3
4 #include <qchartglobal.h>
4 #include <qchartglobal.h>
5 #include <qchartseries.h>
5 #include <qchartseries.h>
6 #include <QGraphicsObject>
6 #include <QGraphicsObject>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class Axis;
10 class Axis;
11 class XYGrid;
11 class XYGrid;
12 class QChartSeries;
12 class QChartSeries;
13 class XYPlotDomain;
13 class XYPlotDomain;
14 class XYLineChartItem;
14 class XYLineChartItem;
15
15
16 // TODO: We don't need to have QChart tied to QGraphicsItem:
16 // TODO: We don't need to have QChart tied to QGraphicsItem:
17 //class QTCOMMERCIALCHART_EXPORT QChart
17 //class QTCOMMERCIALCHART_EXPORT QChart
18 //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem {
18 //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem {
19 // public: QChartGraphicsItem(QChart &chart);
19 // public: QChartGraphicsItem(QChart &chart);
20
20
21 /*!
21 /*!
22 * TODO: define the responsibilities
22 * TODO: define the responsibilities
23 */
23 */
24 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsObject
24 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsObject
25 {
25 {
26 Q_OBJECT
26 Q_OBJECT
27 public:
27 public:
28 QChart(QGraphicsObject* parent = 0);
28 QChart(QGraphicsObject* parent = 0);
29 ~QChart();
29 ~QChart();
30
30
31 //from QGraphicsItem
31 //from QGraphicsItem
32 QRectF boundingRect() const;
32 QRectF boundingRect() const;
33 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){};
33 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){};
34
34
35 void addSeries(QChartSeries* series);
35 void addSeries(QChartSeries* series);
36 //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type);
36 //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type);
37 // TODO: who owns the series now? maybe owned by chart and returned a reference instead...
37 // TODO: who owns the series now? maybe owned by chart and returned a reference instead...
38 QChartSeries* createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type);
38 QChartSeries* createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type);
39
39
40 virtual void setSize(const QSizeF& rect);
40 virtual void setSize(const QSizeF& rect);
41 void setMargin(int margin);
41 void setMargin(int margin);
42 int margin() const;
42 int margin() const;
43
43
44 signals:
44 signals:
45 void sizeChanged(QRectF rect, qreal xscale, qreal yscale);
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)
49 Axis* m_axisX;
50 Axis* m_axisX;
50 Axis* m_axisY;
51 Axis* m_axisY;
51 XYGrid* m_grid;
52 XYGrid* m_grid;
52 QRect m_rect;
53 QRect m_rect;
53 QList<const QChartSeries*> m_series;
54 QList<const QChartSeries*> m_series;
54 QList<XYPlotDomain> m_plotDomainList;
55 QList<XYPlotDomain> m_plotDomainList;
55 QList<XYLineChartItem*> m_xyLineChartItems;
56 QList<XYLineChartItem*> m_xyLineChartItems;
56 QList<QGraphicsItem*> m_items;
57 QList<QGraphicsItem*> m_items;
57 int m_plotDataIndex;
58 int m_plotDataIndex;
58 int m_marginSize;
59 int m_marginSize;
59 };
60 };
60
61
61 QTCOMMERCIALCHART_END_NAMESPACE
62 QTCOMMERCIALCHART_END_NAMESPACE
62
63
63 #endif
64 #endif
@@ -1,54 +1,54
1 #include "qpieseries.h"
1 #include "qpieseries.h"
2 #include "pieslice.h"
2 #include "pieslice.h"
3 #include <QGraphicsObject>
3 #include <QGraphicsObject>
4 #include <QDebug>
4 #include <QDebug>
5
5
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
7
8 QPieSeries::QPieSeries(QList<qreal> x, QGraphicsObject *parent) :
8 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);
33 slice->setParentItem(parentItem);
25 slice->setParentItem(parentItem);
34 m_slices.append(slice);
26 m_slices.append(slice);
35 angle += span;
27 angle += span;
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;
42 c.setRed(qrand() % 255);
42 c.setRed(qrand() % 255);
43 c.setGreen(qrand() % 255);
43 c.setGreen(qrand() % 255);
44 c.setBlue(qrand() % 255);
44 c.setBlue(qrand() % 255);
45 return c;
45 return c;
46 }
46 }
47
47
48 void QPieSeries::setData(QList<int> data)
48 void QPieSeries::setData(QList<int> data)
49 {
49 {
50 }
50 }
51
51
52 #include "moc_qpieseries.cpp"
52 #include "moc_qpieseries.cpp"
53
53
54 QTCOMMERCIALCHART_END_NAMESPACE
54 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,40 +1,40
1 #ifndef PIESERIES_H
1 #ifndef PIESERIES_H
2 #define PIESERIES_H
2 #define PIESERIES_H
3
3
4 #include "qchartseries.h"
4 #include "qchartseries.h"
5 #include <QObject>
5 #include <QObject>
6 #include <QRectF>
6 #include <QRectF>
7 #include <QColor>
7 #include <QColor>
8
8
9 class QGraphicsObject;
9 class QGraphicsObject;
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 class PieSlice;
11 class PieSlice;
12
12
13 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QChartSeries
13 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QChartSeries
14 {
14 {
15 Q_OBJECT
15 Q_OBJECT
16 public:
16 public:
17 // TODO: use a generic data class instead of x and y
17 // TODO: use a generic data class instead of x and y
18 QPieSeries(QList<qreal> x, QGraphicsObject *parent = 0);
18 QPieSeries(QList<qreal> x, QGraphicsObject *parent = 0);
19 ~QPieSeries();
19 ~QPieSeries();
20 QColor randomColor();
20 QColor randomColor();
21 void setData(QList<int> data);
21 void setData(QList<int> data);
22
22
23 public: // from QChartSeries
23 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, qreal xscale, qreal yscale);
27 void chartSizeChanged(QRectF rect);
28
28
29 private:
29 private:
30 //Q_DECLARE_PRIVATE(QPieSeries)
30 //Q_DECLARE_PRIVATE(QPieSeries)
31 Q_DISABLE_COPY(QPieSeries)
31 Q_DISABLE_COPY(QPieSeries)
32 // TODO: move the followin to internal impl
32 // TODO: move the followin to internal impl
33 QList<qreal> m_x;
33 QList<qreal> m_x;
34 QList<PieSlice*> m_slices;
34 QList<PieSlice*> m_slices;
35 QSizeF m_size;
35 QSizeF m_size;
36 };
36 };
37
37
38 QTCOMMERCIALCHART_END_NAMESPACE
38 QTCOMMERCIALCHART_END_NAMESPACE
39
39
40 #endif // PIESERIES_H
40 #endif // PIESERIES_H
@@ -1,76 +1,88
1 #include "qscatterseries.h"
1 #include "qscatterseries.h"
2 #include "qscatterseries_p.h"
2 #include "qscatterseries_p.h"
3 #include "qchart.h"
3 #include "qchart.h"
4 #include <QPainter>
4 #include <QPainter>
5 #include <QGraphicsScene>
5 #include <QGraphicsScene>
6 #include <QDebug>
6 #include <QDebug>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 //#define QSeriesData QList<qreal>
10 //#define QSeriesData QList<qreal>
11
11
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, qreal xscale, qreal yscale)
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 * xscale);
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 * yscale);
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);
34 }
40 }
35
41
36 void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
42 void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
37 {
43 {
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, 50));
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);
45
51
46 // TODO: m_scenex and m_sceny are left empty during construction -> we would need a resize
52 // TODO: m_scenex and m_sceny are left empty during construction -> we would need a resize
47 // event right after construction or maybe given a size during initialization
53 // event right after construction or maybe given a size during initialization
48 for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) {
54 for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) {
49 if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i))
55 if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i))
50 //painter->drawArc(m_scenex.at(i), m_sceney.at(i), 2, 2, 0, 5760);
56 //painter->drawArc(m_scenex.at(i), m_sceney.at(i), 2, 2, 0, 5760);
51 painter->drawPoint(m_scenex.at(i), m_sceney.at(i));
57 painter->drawPoint(m_scenex.at(i), m_sceney.at(i));
52 }
58 }
53 }
59 }
54
60
55 QScatterSeries::QScatterSeries(QList<qreal> x, QList<qreal> y, QObject *parent) :
61 QScatterSeries::QScatterSeries(QList<qreal> x, QList<qreal> y, QObject *parent) :
56 QChartSeries(parent),
62 QChartSeries(parent),
57 d(new QScatterSeriesPrivate(x, y, qobject_cast<QGraphicsItem *> (parent)))
63 d(new QScatterSeriesPrivate(x, y, qobject_cast<QGraphicsItem *> (parent)))
58 {
64 {
59 }
65 }
60
66
61 void QScatterSeries::chartSizeChanged(QRectF rect, qreal xscale, qreal yscale)
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, xscale, yscale);
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;
72 }
84 }
73
85
74 #include "moc_qscatterseries.cpp"
86 #include "moc_qscatterseries.cpp"
75
87
76 QTCOMMERCIALCHART_END_NAMESPACE
88 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,33 +1,34
1 #ifndef QSCATTERSERIES_H
1 #ifndef QSCATTERSERIES_H
2 #define QSCATTERSERIES_H
2 #define QSCATTERSERIES_H
3
3
4 #include "qchartseries.h"
4 #include "qchartseries.h"
5 #include <QRectF>
5 #include <QRectF>
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 class QScatterSeriesPrivate;
8 class QScatterSeriesPrivate;
9
9
10 class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QChartSeries
10 class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QChartSeries
11 {
11 {
12 Q_OBJECT
12 Q_OBJECT
13 public:
13 public:
14 //QScatterSeries(QSeriesData *data, QObject *chart);
14 //QScatterSeries(QSeriesData *data, QObject *chart);
15 QScatterSeries(QList<qreal> x, QList<qreal> y, QObject *parent = 0);
15 QScatterSeries(QList<qreal> x, QList<qreal> y, QObject *parent = 0);
16 ~QScatterSeries();
16 ~QScatterSeries();
17
17
18 public: // from QChartSeries
18 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, qreal xscale, qreal yscale);
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)
26 Q_DISABLE_COPY(QScatterSeries)
27 Q_DISABLE_COPY(QScatterSeries)
27 friend class QChart;
28 friend class QChart;
28 QScatterSeriesPrivate *const d;
29 QScatterSeriesPrivate *const d;
29 };
30 };
30
31
31 QTCOMMERCIALCHART_END_NAMESPACE
32 QTCOMMERCIALCHART_END_NAMESPACE
32
33
33 #endif // QSCATTERSERIES_H
34 #endif // QSCATTERSERIES_H
@@ -1,31 +1,33
1 #ifndef QSCATTERSERIESPRIVATE_H
1 #ifndef QSCATTERSERIESPRIVATE_H
2 #define QSCATTERSERIESPRIVATE_H
2 #define QSCATTERSERIESPRIVATE_H
3
3
4 #include "qchartseries.h"
4 #include "qchartseries.h"
5 #include <QGraphicsItem>
5 #include <QGraphicsItem>
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 /*!
9 /*!
10 * The PIMPL class of QScatterSeries.
10 * The PIMPL class of QScatterSeries.
11 */
11 */
12 class QScatterSeriesPrivate : public QGraphicsItem
12 class QScatterSeriesPrivate : public QGraphicsItem
13 {
13 {
14 public:
14 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, qreal xscale, qreal yscale);
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 };
28
30
29 QTCOMMERCIALCHART_END_NAMESPACE
31 QTCOMMERCIALCHART_END_NAMESPACE
30
32
31 #endif // QSCATTERSERIES_H
33 #endif // QSCATTERSERIES_H
General Comments 0
You need to be logged in to leave comments. Login now