@@ -1,153 +1,158 | |||||
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 "qxychartseries.h" |
|
5 | #include "qxychartseries.h" | |
6 | #include "xylinechartitem_p.h" |
|
6 | #include "xylinechartitem_p.h" | |
7 | #include "xyplotdomain_p.h" |
|
7 | #include "xyplotdomain_p.h" | |
8 | #include "axis_p.h" |
|
8 | #include "axis_p.h" | |
9 | #include "xygrid_p.h" |
|
9 | #include "xygrid_p.h" | |
10 | #include <QGraphicsScene> |
|
10 | #include <QGraphicsScene> | |
11 | #include <QDebug> |
|
11 | #include <QDebug> | |
12 |
|
12 | |||
13 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
13 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
14 |
|
14 | |||
15 | class QChartPrivate |
|
15 | class QChartPrivate | |
16 | { |
|
16 | { | |
17 | public: |
|
17 | public: | |
18 |
|
18 | |||
19 | QChartPrivate(QChart* parent): |
|
19 | QChartPrivate(QChart* parent): | |
20 | m_axisX(new Axis(parent)), |
|
20 | m_axisX(new Axis(parent)), | |
21 | m_axisY(new Axis(parent)), |
|
21 | m_axisY(new Axis(parent)), | |
22 | m_grid(new XYGrid(parent)), |
|
22 | m_grid(new XYGrid(parent)), | |
23 | m_plotDataIndex(0), |
|
23 | m_plotDataIndex(0), | |
24 | m_marginSize(0){} |
|
24 | m_marginSize(0){} | |
25 |
|
25 | |||
26 | Axis* m_axisX; |
|
26 | Axis* m_axisX; | |
27 | Axis* m_axisY; |
|
27 | Axis* m_axisY; | |
28 | XYGrid* m_grid; |
|
28 | XYGrid* m_grid; | |
29 | QRect m_rect; |
|
29 | QRect m_rect; | |
30 | QList<const QChartSeries*> m_series; |
|
30 | QList<const QChartSeries*> m_series; | |
31 | QList<XYPlotDomain> m_plotDomainList; |
|
31 | QList<XYPlotDomain> m_plotDomainList; | |
32 | QList<XYLineChartItem*> m_xyLineChartItems; |
|
32 | QList<XYLineChartItem*> m_xyLineChartItems; | |
33 | QList<QGraphicsItem*> m_items; |
|
33 | QList<QGraphicsItem*> m_items; | |
34 | int m_plotDataIndex; |
|
34 | int m_plotDataIndex; | |
35 | int m_marginSize; |
|
35 | int m_marginSize; | |
36 |
|
36 | |||
37 | }; |
|
37 | }; | |
38 |
|
38 | |||
39 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
39 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
40 |
|
40 | |||
41 |
QChart::QChart(QGraphics |
|
41 | QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent), | |
42 |
d |
|
42 | d(new QChartPrivate(this)) | |
43 | { |
|
43 | { | |
44 | // setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
44 | // setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
45 | // set axis |
|
45 | // set axis | |
46 | Q_D(QChart); |
|
|||
47 | d->m_axisY->rotate(90); |
|
46 | d->m_axisY->rotate(90); | |
48 | } |
|
47 | } | |
49 |
|
48 | |||
50 | QChart::~QChart(){} |
|
49 | QChart::~QChart(){} | |
51 |
|
50 | |||
52 | QRectF QChart::boundingRect() const |
|
51 | QRectF QChart::boundingRect() const | |
53 | { |
|
52 | { | |
54 | Q_D(const QChart); |
|
|||
55 | return d->m_rect; |
|
53 | return d->m_rect; | |
56 | } |
|
54 | } | |
57 |
|
55 | |||
58 | void QChart::addSeries(QChartSeries* series) |
|
56 | void QChart::addSeries(QChartSeries* series) | |
59 | { |
|
57 | { | |
60 | Q_D(QChart); |
|
58 | // TODO: we should check the series not already added | |
61 |
|
59 | |||
62 | d->m_series<<series; |
|
60 | d->m_series<<series; | |
63 |
|
61 | |||
64 | switch(series->type()) |
|
62 | switch(series->type()) | |
65 | { |
|
63 | { | |
66 | case QChartSeries::SeriesTypeLine: { |
|
64 | case QChartSeries::SeriesTypeLine: { | |
67 |
|
65 | |||
68 | QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series); |
|
66 | QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series); | |
69 |
|
67 | |||
70 | XYPlotDomain domain; |
|
68 | XYPlotDomain domain; | |
71 | //TODO "nice numbers algorithm" |
|
69 | //TODO "nice numbers algorithm" | |
72 | domain.m_ticksX=4; |
|
70 | domain.m_ticksX=4; | |
73 | domain.m_ticksY=4; |
|
71 | domain.m_ticksY=4; | |
74 |
|
72 | |||
75 | for (int i = 0 ; i < xyseries->count() ; i++) |
|
73 | for (int i = 0 ; i < xyseries->count() ; i++) | |
76 | { |
|
74 | { | |
77 | qreal x = xyseries->x(i); |
|
75 | qreal x = xyseries->x(i); | |
78 | qreal y = xyseries->y(i); |
|
76 | qreal y = xyseries->y(i); | |
79 | domain.m_minX = qMin(domain.m_minX,x); |
|
77 | domain.m_minX = qMin(domain.m_minX,x); | |
80 | domain.m_minY = qMin(domain.m_minY,y); |
|
78 | domain.m_minY = qMin(domain.m_minY,y); | |
81 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
79 | domain.m_maxX = qMax(domain.m_maxX,x); | |
82 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
80 | domain.m_maxY = qMax(domain.m_maxY,y); | |
83 | } |
|
81 | } | |
84 |
|
82 | |||
85 | XYLineChartItem* item = new XYLineChartItem(xyseries,this); |
|
83 | XYLineChartItem* item = new XYLineChartItem(xyseries,this); | |
86 | item->updateXYPlotDomain(domain); |
|
84 | item->updateXYPlotDomain(domain); | |
87 | d->m_plotDomainList<<domain; |
|
85 | d->m_plotDomainList<<domain; | |
88 | d->m_xyLineChartItems<<item; |
|
86 | d->m_xyLineChartItems<<item; | |
89 | break; |
|
87 | break; | |
90 | } |
|
88 | } | |
91 | case QChartSeries::SeriesTypeScatter: { |
|
89 | case QChartSeries::SeriesTypeScatter: { | |
|
90 | QScatterSeries *scatter = qobject_cast<QScatterSeries *>(series); | |||
|
91 | if (scatter) { | |||
|
92 | scatter->d->setParentItem(this); | |||
|
93 | scene()->addItem(scatter->d); | |||
|
94 | } | |||
92 | break; |
|
95 | break; | |
93 | } |
|
96 | } | |
94 | } |
|
97 | } | |
95 | } |
|
98 | } | |
96 |
|
99 | |||
97 | QChartSeries* QChart::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type) |
|
100 | QChartSeries* QChart::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type) | |
98 | { |
|
101 | { | |
99 | Q_D(QChart); |
|
102 | // TODO: support also other types in addition to scatter | |
100 |
|
||||
101 | // TODO: support also other types |
|
|||
102 | Q_ASSERT(type == QChartSeries::SeriesTypeScatter); |
|
103 | Q_ASSERT(type == QChartSeries::SeriesTypeScatter); | |
103 | QChartSeries *series = 0; |
|
104 | QChartSeries *series = 0; | |
104 |
|
105 | |||
105 | switch (type) { |
|
106 | switch (type) { | |
106 | case QChartSeries::SeriesTypeScatter: { |
|
107 | case QChartSeries::SeriesTypeScatter: { | |
107 | QScatterSeries *scatterSeries = new QScatterSeries(x, y, this); |
|
108 | QScatterSeries *scatterSeries = new QScatterSeries(x, y, this); | |
108 | d->m_items.append(scatterSeries->d); |
|
109 | scatterSeries->d->setParentItem(this); | |
109 | scene()->addItem(scatterSeries->d); |
|
|||
110 | //series = qobject_cast<QChartSeries *>(scatterSeries); |
|
|||
111 | break; |
|
110 | break; | |
112 | } |
|
111 | } | |
113 | default: |
|
112 | default: | |
114 | break; |
|
113 | break; | |
115 | } |
|
114 | } | |
116 |
|
115 | |||
117 | return series; |
|
116 | return series; | |
118 | } |
|
117 | } | |
|
118 | ||||
119 | void QChart::setSize(const QSizeF& size) |
|
119 | void QChart::setSize(const QSizeF& size) | |
120 | { |
|
120 | { | |
121 | Q_D(QChart); |
|
|||
122 | d->m_rect = QRect(QPoint(0,0),size.toSize()); |
|
121 | d->m_rect = QRect(QPoint(0,0),size.toSize()); | |
123 | d->m_rect.adjust(margin(),margin(),-margin(),-margin()); |
|
122 | d->m_rect.adjust(margin(),margin(), -margin(), -margin()); | |
124 | d->m_grid->setPos(d->m_rect.topLeft()); |
|
123 | d->m_grid->setPos(d->m_rect.topLeft()); | |
125 | d->m_grid->setSize(d->m_rect.size()); |
|
124 | d->m_grid->setSize(d->m_rect.size()); | |
126 | // TODO: line chart items would need to be updated separately as they don't support update |
|
|||
127 | // via paint method |
|
|||
128 | for (int i =0; i< d->m_plotDomainList.size();i++) |
|
|||
129 | { |
|
|||
130 | d->m_plotDomainList[i].m_viewportRect = d->m_rect; |
|
|||
131 |
|
125 | |||
132 | } |
|
126 | // TODO: calculate the scale | |
|
127 | // TODO: calculate the origo | |||
|
128 | // TODO: not sure if emitting a signal here is the best from performance point of view | |||
|
129 | const qreal xscale = size.width() / 100; | |||
|
130 | const qreal yscale = size.height() / 100; | |||
|
131 | emit sizeChanged(QRectF(0, 0, size.width(), size.height()), xscale, yscale); | |||
|
132 | ||||
|
133 | for (int i(0); i < d->m_plotDomainList.size(); i++) | |||
|
134 | d->m_plotDomainList[i].m_viewportRect = d->m_rect; | |||
133 |
|
135 | |||
|
136 | // TODO: line chart items are updated separately as they don't support update | |||
|
137 | // via sizeChanged signal | |||
134 | foreach(XYLineChartItem* item , d->m_xyLineChartItems) |
|
138 | foreach(XYLineChartItem* item , d->m_xyLineChartItems) | |
135 | item->updateXYPlotDomain(d->m_plotDomainList.at(d->m_plotDataIndex)); |
|
139 | item->updateXYPlotDomain(d->m_plotDomainList.at(d->m_plotDataIndex)); | |
136 |
|
140 | |||
137 | d->m_grid->setXYPlotData(d->m_plotDomainList.at(d->m_plotDataIndex)); |
|
141 | d->m_grid->setXYPlotData(d->m_plotDomainList.at(d->m_plotDataIndex)); | |
138 | update(); |
|
142 | update(); | |
139 | } |
|
143 | } | |
140 |
|
144 | |||
141 | int QChart::margin() const |
|
145 | int QChart::margin() const | |
142 | { |
|
146 | { | |
143 | Q_D(const QChart); |
|
|||
144 | return d->m_marginSize; |
|
147 | return d->m_marginSize; | |
145 | } |
|
148 | } | |
146 |
|
149 | |||
147 | void QChart::setMargin(int margin) |
|
150 | void QChart::setMargin(int margin) | |
148 | { |
|
151 | { | |
149 | Q_D(QChart); |
|
|||
150 | d->m_marginSize = margin; |
|
152 | d->m_marginSize = margin; | |
151 | } |
|
153 | } | |
152 |
|
154 | |||
|
155 | #include "moc_qchart.cpp" | |||
|
156 | ||||
|
157 | ||||
153 | QTCOMMERCIALCHART_END_NAMESPACE |
|
158 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,55 +1,55 | |||||
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 <QGraphics |
|
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 QChartPrivate; |
|
14 | class QChartPrivate; | |
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 QGraphics |
|
24 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsObject | |
25 | { |
|
25 | { | |
26 |
|
26 | Q_OBJECT | ||
27 | public: |
|
27 | public: | |
28 |
QChart(QGraphics |
|
28 | QChart(QGraphicsObject* parent = 0); | |
29 |
|
|
29 | ~QChart(); | |
30 |
|
30 | |||
31 | //from QGraphicsItem |
|
31 | //from QGraphicsItem | |
32 |
|
|
32 | QRectF boundingRect() const; | |
33 |
|
|
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 | protected: |
|
44 | signals: | |
45 | QChartPrivate * const d_ptr; |
|
45 | void sizeChanged(QRectF rect, qreal xscale, qreal yscale); | |
46 |
|
46 | |||
47 | private: |
|
47 | private: | |
|
48 | // Q_DECLARE_PRIVATE(QChart) | |||
48 | Q_DISABLE_COPY(QChart) |
|
49 | Q_DISABLE_COPY(QChart) | |
49 | Q_DECLARE_PRIVATE(QChart) |
|
50 | QChartPrivate *d; | |
50 |
|
||||
51 | }; |
|
51 | }; | |
52 |
|
52 | |||
53 | QTCOMMERCIALCHART_END_NAMESPACE |
|
53 | QTCOMMERCIALCHART_END_NAMESPACE | |
54 |
|
54 | |||
55 | #endif |
|
55 | #endif |
@@ -1,67 +1,77 | |||||
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 |
|
7 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
9 | |||
9 | //#define QSeriesData QList<qreal> |
|
10 | //#define QSeriesData QList<qreal> | |
10 |
|
11 | |||
11 | QScatterSeriesPrivate::QScatterSeriesPrivate(QList<qreal> x, QList<qreal> y, QGraphicsItem *parent) : |
|
12 | QScatterSeriesPrivate::QScatterSeriesPrivate(QList<qreal> x, QList<qreal> y, QGraphicsItem *parent) : | |
12 | QGraphicsItem(parent), |
|
13 | QGraphicsItem(parent), | |
13 | m_x(x), |
|
14 | m_x(x), | |
14 | m_y(y) |
|
15 | m_y(y) | |
15 | { |
|
16 | { | |
16 | } |
|
17 | } | |
17 |
|
18 | |||
18 |
void QScatterSeriesPrivate::s |
|
19 | void QScatterSeriesPrivate::resize(QRectF rect, qreal xscale, qreal yscale) | |
19 | { |
|
20 | { | |
|
21 | m_scenex.clear(); | |||
|
22 | m_sceney.clear(); | |||
|
23 | ||||
|
24 | foreach(qreal x, m_x) | |||
|
25 | m_scenex.append(rect.left() + x * xscale); | |||
|
26 | ||||
|
27 | foreach(qreal y, m_y) | |||
|
28 | m_sceney.append(rect.bottom() - y * yscale); | |||
20 | } |
|
29 | } | |
21 |
|
30 | |||
22 | QRectF QScatterSeriesPrivate::boundingRect() const |
|
31 | QRectF QScatterSeriesPrivate::boundingRect() const | |
23 | { |
|
32 | { | |
24 |
return QRectF(0, 0, |
|
33 | return QRectF(0, 0, 55, 100); | |
25 | } |
|
34 | } | |
26 |
|
35 | |||
27 | void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
36 | void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
28 | { |
|
37 | { | |
29 | QPen pen = painter->pen(); |
|
38 | QPen pen = painter->pen(); | |
30 | QBrush brush = pen.brush(); |
|
39 | QBrush brush = pen.brush(); | |
31 | // TODO: The opacity should be user definable... |
|
40 | // TODO: The opacity should be user definable... | |
32 | brush.setColor(QColor(255, 82, 0, 50)); |
|
41 | brush.setColor(QColor(255, 82, 0, 50)); | |
33 | pen.setBrush(brush); |
|
42 | pen.setBrush(brush); | |
34 | pen.setWidth(4); |
|
43 | pen.setWidth(4); | |
35 | painter->setPen(pen); |
|
44 | painter->setPen(pen); | |
36 | QTransform transform = painter->transform(); |
|
|||
37 |
|
||||
38 | // TODO: get min and max values of the axes from the QChart (or some dedicated class) |
|
|||
39 | const qreal xmin = 0.0; |
|
|||
40 | const qreal xmax = 100.0; |
|
|||
41 | const qreal xscale = scene()->width() / (xmax - xmin); |
|
|||
42 | const qreal ymin = 0.0; |
|
|||
43 | const qreal ymax = 100.0; |
|
|||
44 | const qreal yscale = scene()->height() / (ymax - ymin); |
|
|||
45 |
|
45 | |||
46 | for (int i(0); i < m_x.count() && i < m_y.count(); i++) { |
|
46 | // TODO: m_scenex and m_sceny are left empty during construction -> we would need a resize | |
47 | transform.reset(); |
|
47 | // event right after construction or maybe given a size during initialization | |
48 | transform.translate(m_x.at(i) * xscale, m_y.at(i) * yscale); |
|
48 | for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) { | |
49 | painter->setTransform(transform); |
|
49 | if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i)) | |
50 |
painter->drawArc( |
|
50 | //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)); | |||
51 | } |
|
52 | } | |
52 | } |
|
53 | } | |
53 |
|
54 | |||
54 | QScatterSeries::QScatterSeries(QList<qreal> x, QList<qreal> y, QObject *parent) : |
|
55 | QScatterSeries::QScatterSeries(QList<qreal> x, QList<qreal> y, QObject *parent) : | |
55 | QChartSeries(parent), |
|
56 | QChartSeries(parent), | |
56 | d(new QScatterSeriesPrivate(x, y, qobject_cast<QGraphicsItem *> (parent))) |
|
57 | d(new QScatterSeriesPrivate(x, y, qobject_cast<QGraphicsItem *> (parent))) | |
57 | { |
|
58 | { | |
|
59 | connect(parent, SIGNAL(sizeChanged(QRectF, qreal, qreal)), this, SLOT(chartSizeChanged(QRectF, qreal, qreal))); | |||
|
60 | } | |||
|
61 | ||||
|
62 | void QScatterSeries::chartSizeChanged(QRectF rect, qreal xscale, qreal yscale) | |||
|
63 | { | |||
|
64 | // Recalculate scatter data point locations on the scene | |||
|
65 | // d->transform().reset(); | |||
|
66 | // d->transform().translate(); | |||
|
67 | d->resize(rect, xscale, yscale); | |||
58 | } |
|
68 | } | |
59 |
|
69 | |||
60 | QScatterSeries::~QScatterSeries() |
|
70 | QScatterSeries::~QScatterSeries() | |
61 | { |
|
71 | { | |
62 | delete d; |
|
72 | delete d; | |
63 | } |
|
73 | } | |
64 |
|
74 | |||
65 | #include "moc_qscatterseries.cpp" |
|
75 | #include "moc_qscatterseries.cpp" | |
66 |
|
76 | |||
67 | QTCOMMERCIALCHART_END_NAMESPACE |
|
77 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,29 +1,33 | |||||
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 |
|
6 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 | class QScatterSeriesPrivate; |
|
8 | class QScatterSeriesPrivate; | |
8 |
|
9 | |||
9 | class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QChartSeries |
|
10 | class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QChartSeries | |
10 | { |
|
11 | { | |
11 | Q_OBJECT |
|
12 | Q_OBJECT | |
12 | public: |
|
13 | public: | |
13 | //QScatterSeries(QSeriesData *data, QObject *chart); |
|
14 | //QScatterSeries(QSeriesData *data, QObject *chart); | |
14 | QScatterSeries(QList<qreal> x, QList<qreal> y, QObject *chart = 0); |
|
15 | QScatterSeries(QList<qreal> x, QList<qreal> y, QObject *chart = 0); | |
15 | ~QScatterSeries(); |
|
16 | ~QScatterSeries(); | |
16 |
|
17 | |||
17 | public: // from QChartSeries |
|
18 | public: // from QChartSeries | |
18 | virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeScatter; } |
|
19 | virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeScatter; } | |
19 |
|
20 | |||
|
21 | public Q_SLOTS: | |||
|
22 | void chartSizeChanged(QRectF rect, qreal xscale, qreal yscale); | |||
|
23 | ||||
20 | private: |
|
24 | private: | |
21 | Q_DECLARE_PRIVATE(QScatterSeries) |
|
25 | Q_DECLARE_PRIVATE(QScatterSeries) | |
22 | Q_DISABLE_COPY(QScatterSeries) |
|
26 | Q_DISABLE_COPY(QScatterSeries) | |
23 | friend class QChart; |
|
27 | friend class QChart; | |
24 | QScatterSeriesPrivate *const d; |
|
28 | QScatterSeriesPrivate *const d; | |
25 | }; |
|
29 | }; | |
26 |
|
30 | |||
27 | QTCOMMERCIALCHART_END_NAMESPACE |
|
31 | QTCOMMERCIALCHART_END_NAMESPACE | |
28 |
|
32 | |||
29 | #endif // QSCATTERSERIES_H |
|
33 | #endif // QSCATTERSERIES_H |
@@ -1,29 +1,31 | |||||
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 setSize(); |
|
18 | void resize(QRectF rect, qreal xscale, qreal yscale); | |
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 | QList<qreal> m_scenex; | |||
|
26 | QList<qreal> m_sceney; | |||
25 | }; |
|
27 | }; | |
26 |
|
28 | |||
27 | QTCOMMERCIALCHART_END_NAMESPACE |
|
29 | QTCOMMERCIALCHART_END_NAMESPACE | |
28 |
|
30 | |||
29 | #endif // QSCATTERSERIES_H |
|
31 | #endif // QSCATTERSERIES_H |
@@ -1,76 +1,75 | |||||
1 | !include( ../common.pri ) { |
|
1 | !include( ../common.pri ) { | |
2 | error( Couldn't find the common.pri file! ) |
|
2 | error( Couldn't find the common.pri file! ) | |
3 | } |
|
3 | } | |
4 |
|
4 | |||
5 |
|
||||
6 | TARGET = QtCommercialChart |
|
5 | TARGET = QtCommercialChart | |
7 | DESTDIR = $$CHART_BUILD_LIB_DIR |
|
6 | DESTDIR = $$CHART_BUILD_LIB_DIR | |
8 | TEMPLATE = lib |
|
7 | TEMPLATE = lib | |
9 | QT += core \ |
|
8 | QT += core \ | |
10 | gui |
|
9 | gui | |
11 |
|
10 | |||
12 | CONFIG += debug_and_release |
|
11 | CONFIG += debug_and_release | |
13 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd |
|
12 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd | |
14 |
|
13 | |||
15 | SOURCES += \ |
|
14 | SOURCES += \ | |
16 | xylinechart/qxychartseries.cpp \ |
|
15 | xylinechart/qxychartseries.cpp \ | |
17 | xylinechart/xylinechartitem.cpp \ |
|
16 | xylinechart/xylinechartitem.cpp \ | |
18 | xylinechart/xygrid.cpp \ |
|
17 | xylinechart/xygrid.cpp \ | |
19 | xylinechart/xyplotdomain.cpp \ |
|
18 | xylinechart/xyplotdomain.cpp \ | |
20 | qscatterseries.cpp \ |
|
19 | qscatterseries.cpp \ | |
21 | qchart.cpp \ |
|
20 | qchart.cpp \ | |
22 | axis.cpp \ |
|
21 | axis.cpp \ | |
23 | qchartwidget.cpp |
|
22 | qchartwidget.cpp | |
24 |
|
23 | |||
25 | PRIVATE_HEADERS += \ |
|
24 | PRIVATE_HEADERS += \ | |
26 | xylinechart/xylinechartitem_p.h \ |
|
25 | xylinechart/xylinechartitem_p.h \ | |
27 | xylinechart/xyplotdomain_p.h \ |
|
26 | xylinechart/xyplotdomain_p.h \ | |
28 | xylinechart/xygrid_p.h \ |
|
27 | xylinechart/xygrid_p.h \ | |
29 | qscatterseries_p.h \ |
|
28 | qscatterseries_p.h \ | |
30 | axis_p.h |
|
29 | axis_p.h | |
31 |
|
30 | |||
32 | PUBLIC_HEADERS += \ |
|
31 | PUBLIC_HEADERS += \ | |
33 | qchartseries.h \ |
|
32 | qchartseries.h \ | |
34 | qscatterseries.h \ |
|
33 | qscatterseries.h \ | |
35 | qchart.h \ |
|
34 | qchart.h \ | |
36 | qchartwidget.h \ |
|
35 | qchartwidget.h \ | |
37 | qchartglobal.h \ |
|
36 | qchartglobal.h \ | |
38 | xylinechart/qxychartseries.h |
|
37 | xylinechart/qxychartseries.h | |
39 |
|
38 | |||
40 | HEADERS += $$PUBLIC_HEADERS |
|
39 | HEADERS += $$PUBLIC_HEADERS | |
41 | HEADERS += $$PRIVATE_HEADERS |
|
40 | HEADERS += $$PRIVATE_HEADERS | |
42 |
|
41 | |||
43 | INCLUDEPATH += xylinechart \ |
|
42 | INCLUDEPATH += xylinechart \ | |
44 | . |
|
43 | . | |
45 |
|
44 | |||
46 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
45 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib | |
47 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
46 | MOC_DIR = $$CHART_BUILD_DIR/lib | |
48 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
47 | UI_DIR = $$CHART_BUILD_DIR/lib | |
49 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
48 | RCC_DIR = $$CHART_BUILD_DIR/lib | |
50 |
|
49 | |||
51 |
|
50 | |||
52 | DEFINES += QTCOMMERCIALCHART_LIBRARY |
|
51 | DEFINES += QTCOMMERCIALCHART_LIBRARY | |
53 |
|
52 | |||
54 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart |
|
53 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart | |
55 | public_headers.files = $$PUBLIC_HEADERS |
|
54 | public_headers.files = $$PUBLIC_HEADERS | |
56 | target.path = $$[QT_INSTALL_LIBS] |
|
55 | target.path = $$[QT_INSTALL_LIBS] | |
57 | INSTALLS += target \ |
|
56 | INSTALLS += target \ | |
58 | public_headers |
|
57 | public_headers | |
59 |
|
58 | |||
60 |
|
59 | |||
61 | install_build_headers.name = bild_headers |
|
60 | install_build_headers.name = bild_headers | |
62 | install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
61 | install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
63 | install_build_headers.input = PUBLIC_HEADERS |
|
62 | install_build_headers.input = PUBLIC_HEADERS | |
64 | install_build_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} $$CHART_BUILD_HEADER_DIR |
|
63 | install_build_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} $$CHART_BUILD_HEADER_DIR | |
65 | install_build_headers.CONFIG += target_predeps no_link |
|
64 | install_build_headers.CONFIG += target_predeps no_link | |
66 | QMAKE_EXTRA_COMPILERS += install_build_headers |
|
65 | QMAKE_EXTRA_COMPILERS += install_build_headers | |
67 |
|
66 | |||
68 | chartversion.target = qchartversion_p.h |
|
67 | chartversion.target = qchartversion_p.h | |
69 | chartversion.commands = @echo "build_time" > $$chartversion.target; |
|
68 | chartversion.commands = @echo "build_time" > $$chartversion.target; | |
70 | chartversion.depends = $$HEADERS $$SOURCES |
|
69 | chartversion.depends = $$HEADERS $$SOURCES | |
71 | PRE_TARGETDEPS += qchartversion_p.h |
|
70 | PRE_TARGETDEPS += qchartversion_p.h | |
72 | QMAKE_CLEAN+= qchartversion_p.h |
|
71 | QMAKE_CLEAN+= qchartversion_p.h | |
73 | QMAKE_EXTRA_TARGETS += chartversion |
|
72 | QMAKE_EXTRA_TARGETS += chartversion | |
74 |
|
73 | |||
75 | unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR |
|
74 | unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR | |
76 | win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR |
|
75 | win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR |
@@ -1,33 +1,33 | |||||
1 | #ifndef XYLINECHARTITEM_H |
|
1 | #ifndef XYLINECHARTITEM_H | |
2 | #define XYLINECHARTITEM_H |
|
2 | #define XYLINECHARTITEM_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qchart.h" |
|
5 | #include <QGraphicsItem> | |
6 | #include "xyplotdomain_p.h" |
|
6 | #include "xyplotdomain_p.h" | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class QXYChartSeries; |
|
10 | class QXYChartSeries; | |
11 |
|
11 | |||
12 | class XYLineChartItem : public QGraphicsItem |
|
12 | class XYLineChartItem : public QGraphicsItem | |
13 | { |
|
13 | { | |
14 |
|
14 | |||
15 | public: |
|
15 | public: | |
16 | XYLineChartItem(QXYChartSeries* m_series,QGraphicsItem *parent = 0); |
|
16 | XYLineChartItem(QXYChartSeries* m_series,QGraphicsItem *parent = 0); | |
17 | virtual ~ XYLineChartItem(){}; |
|
17 | virtual ~ XYLineChartItem(){}; | |
18 |
|
18 | |||
19 | //from QGraphicsItem |
|
19 | //from QGraphicsItem | |
20 | virtual QRectF boundingRect() const; |
|
20 | virtual QRectF boundingRect() const; | |
21 | virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
21 | virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
22 |
|
22 | |||
23 | void updateXYPlotDomain(const XYPlotDomain& data); |
|
23 | void updateXYPlotDomain(const XYPlotDomain& data); | |
24 |
|
24 | |||
25 | private: |
|
25 | private: | |
26 | QPolygonF m_polyline; |
|
26 | QPolygonF m_polyline; | |
27 | QXYChartSeries* m_series; |
|
27 | QXYChartSeries* m_series; | |
28 | XYPlotDomain m_xyPlotData; |
|
28 | XYPlotDomain m_xyPlotData; | |
29 | }; |
|
29 | }; | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_END_NAMESPACE |
|
31 | QTCOMMERCIALCHART_END_NAMESPACE | |
32 |
|
32 | |||
33 | #endif |
|
33 | #endif |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file |
@@ -1,231 +1,239 | |||||
1 | #include "mainwidget.h" |
|
1 | #include "mainwidget.h" | |
2 | #include "dataseriedialog.h" |
|
2 | #include "dataseriedialog.h" | |
3 | #include <qxychartseries.h> |
|
3 | #include <qxychartseries.h> | |
4 | #include <QPushButton> |
|
4 | #include <QPushButton> | |
5 | #include <QComboBox> |
|
5 | #include <QComboBox> | |
6 | #include <QSpinBox> |
|
6 | #include <QSpinBox> | |
7 | #include <QCheckBox> |
|
7 | #include <QCheckBox> | |
8 | #include <QGridLayout> |
|
8 | #include <QGridLayout> | |
9 | #include <QHBoxLayout> |
|
9 | #include <QHBoxLayout> | |
10 | #include <QLabel> |
|
10 | #include <QLabel> | |
11 | #include <QSpacerItem> |
|
11 | #include <QSpacerItem> | |
12 | #include <QMessageBox> |
|
12 | #include <QMessageBox> | |
13 | #include <cmath> |
|
13 | #include <cmath> | |
14 | #include <QDebug> |
|
14 | #include <QDebug> | |
15 |
|
15 | |||
16 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
16 | QTCOMMERCIALCHART_USE_NAMESPACE | |
17 |
|
17 | |||
18 | MainWidget::MainWidget(QWidget *parent) : |
|
18 | MainWidget::MainWidget(QWidget *parent) : | |
19 | QWidget(parent) |
|
19 | QWidget(parent) | |
20 | { |
|
20 | { | |
21 | QPushButton *addSeriesButton = new QPushButton("Add series"); |
|
21 | QPushButton *addSeriesButton = new QPushButton("Add series"); | |
22 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
22 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); | |
23 |
|
23 | |||
24 | // Chart background |
|
24 | // Chart background | |
25 | QComboBox *backgroundCombo = new QComboBox(this); |
|
25 | QComboBox *backgroundCombo = new QComboBox(this); | |
26 | backgroundCombo->addItem("None"); |
|
26 | backgroundCombo->addItem("None"); | |
27 | backgroundCombo->addItem("TODO Grid"); |
|
27 | backgroundCombo->addItem("TODO Grid"); | |
28 | backgroundCombo->addItem("TODO Image"); |
|
28 | backgroundCombo->addItem("TODO Image"); | |
29 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
29 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), | |
30 | this, SLOT(backgroundChanged(int))); |
|
30 | this, SLOT(backgroundChanged(int))); | |
31 |
|
31 | |||
32 | // Axis |
|
32 | // Axis | |
33 | // TODO: multiple axes? |
|
33 | // TODO: multiple axes? | |
34 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
34 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); | |
35 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
35 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); | |
36 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
36 | // Allow setting also non-sense values (like -2147483648 and 2147483647) | |
37 | m_xMinSpin = new QSpinBox(); |
|
37 | m_xMinSpin = new QSpinBox(); | |
38 | m_xMinSpin->setMinimum(INT_MIN); |
|
38 | m_xMinSpin->setMinimum(INT_MIN); | |
39 | m_xMinSpin->setMaximum(INT_MAX); |
|
39 | m_xMinSpin->setMaximum(INT_MAX); | |
40 | m_xMinSpin->setValue(0); |
|
40 | m_xMinSpin->setValue(0); | |
41 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
41 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); | |
42 | m_xMaxSpin = new QSpinBox(); |
|
42 | m_xMaxSpin = new QSpinBox(); | |
43 | m_xMaxSpin->setMinimum(INT_MIN); |
|
43 | m_xMaxSpin->setMinimum(INT_MIN); | |
44 | m_xMaxSpin->setMaximum(INT_MAX); |
|
44 | m_xMaxSpin->setMaximum(INT_MAX); | |
45 | m_xMaxSpin->setValue(10); |
|
45 | m_xMaxSpin->setValue(10); | |
46 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
46 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); | |
47 | m_yMinSpin = new QSpinBox(); |
|
47 | m_yMinSpin = new QSpinBox(); | |
48 | m_yMinSpin->setMinimum(INT_MIN); |
|
48 | m_yMinSpin->setMinimum(INT_MIN); | |
49 | m_yMinSpin->setMaximum(INT_MAX); |
|
49 | m_yMinSpin->setMaximum(INT_MAX); | |
50 | m_yMinSpin->setValue(0); |
|
50 | m_yMinSpin->setValue(0); | |
51 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
51 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); | |
52 | m_yMaxSpin = new QSpinBox(); |
|
52 | m_yMaxSpin = new QSpinBox(); | |
53 | m_yMaxSpin->setMinimum(INT_MIN); |
|
53 | m_yMaxSpin->setMinimum(INT_MIN); | |
54 | m_yMaxSpin->setMaximum(INT_MAX); |
|
54 | m_yMaxSpin->setMaximum(INT_MAX); | |
55 | m_yMaxSpin->setValue(10); |
|
55 | m_yMaxSpin->setValue(10); | |
56 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
56 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); | |
57 |
|
57 | |||
58 | QGridLayout *grid = new QGridLayout(); |
|
58 | QGridLayout *grid = new QGridLayout(); | |
59 | QHBoxLayout *hbox = new QHBoxLayout(); |
|
59 | QHBoxLayout *hbox = new QHBoxLayout(); | |
60 | //grid->addWidget(new QLabel("Add series:"), 0, 0); |
|
60 | //grid->addWidget(new QLabel("Add series:"), 0, 0); | |
61 | grid->addWidget(addSeriesButton, 0, 1); |
|
61 | grid->addWidget(addSeriesButton, 0, 1); | |
62 | grid->addWidget(new QLabel("Background:"), 2, 0); |
|
62 | grid->addWidget(new QLabel("Background:"), 2, 0); | |
63 | grid->addWidget(backgroundCombo, 2, 1); |
|
63 | grid->addWidget(backgroundCombo, 2, 1); | |
64 | grid->addWidget(m_autoScaleCheck, 3, 0); |
|
64 | grid->addWidget(m_autoScaleCheck, 3, 0); | |
65 | grid->addWidget(new QLabel("x min:"), 4, 0); |
|
65 | grid->addWidget(new QLabel("x min:"), 4, 0); | |
66 | grid->addWidget(m_xMinSpin, 4, 1); |
|
66 | grid->addWidget(m_xMinSpin, 4, 1); | |
67 | grid->addWidget(new QLabel("x max:"), 5, 0); |
|
67 | grid->addWidget(new QLabel("x max:"), 5, 0); | |
68 | grid->addWidget(m_xMaxSpin, 5, 1); |
|
68 | grid->addWidget(m_xMaxSpin, 5, 1); | |
69 | grid->addWidget(new QLabel("y min:"), 6, 0); |
|
69 | grid->addWidget(new QLabel("y min:"), 6, 0); | |
70 | grid->addWidget(m_yMinSpin, 6, 1); |
|
70 | grid->addWidget(m_yMinSpin, 6, 1); | |
71 | grid->addWidget(new QLabel("y max:"), 7, 0); |
|
71 | grid->addWidget(new QLabel("y max:"), 7, 0); | |
72 | grid->addWidget(m_yMaxSpin, 7, 1); |
|
72 | grid->addWidget(m_yMaxSpin, 7, 1); | |
73 | // add row with empty label to make all the other rows static |
|
73 | // add row with empty label to make all the other rows static | |
74 | grid->addWidget(new QLabel(""), 8, 0); |
|
74 | grid->addWidget(new QLabel(""), 8, 0); | |
75 | grid->setRowStretch(8, 1); |
|
75 | grid->setRowStretch(8, 1); | |
76 |
|
76 | |||
77 | hbox->addLayout(grid); |
|
77 | hbox->addLayout(grid); | |
78 |
|
78 | |||
79 | m_chartWidget = new QChartWidget(this); |
|
79 | m_chartWidget = new QChartWidget(this); | |
80 | //m_chartWidget->setColor(Qt::red); |
|
80 | //m_chartWidget->setColor(Qt::red); | |
81 | hbox->addWidget(m_chartWidget); |
|
81 | hbox->addWidget(m_chartWidget); | |
82 | // hbox->setStretch(1, 1); |
|
82 | // hbox->setStretch(1, 1); | |
83 |
|
83 | |||
84 | setLayout(hbox); |
|
84 | setLayout(hbox); | |
85 |
|
85 | |||
86 | m_autoScaleCheck->setChecked(true); |
|
86 | m_autoScaleCheck->setChecked(true); | |
87 | chartTypeChanged(4); |
|
87 | chartTypeChanged(4); | |
88 | testDataChanged(0); |
|
88 | testDataChanged(0); | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | void MainWidget::addSeries() |
|
91 | void MainWidget::addSeries() | |
92 | { |
|
92 | { | |
93 | DataSerieDialog dialog(m_defaultSeries, this); |
|
93 | DataSerieDialog dialog(m_defaultSeries, this); | |
94 | connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString))); |
|
94 | connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString))); | |
95 | dialog.exec(); |
|
95 | dialog.exec(); | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | void MainWidget::addSeries(QString series, QString data) |
|
98 | void MainWidget::addSeries(QString series, QString data) | |
99 | { |
|
99 | { | |
100 | qDebug() << "addSeries: " << series << " data: " << data; |
|
100 | qDebug() << "addSeries: " << series << " data: " << data; | |
101 | m_defaultSeries = series; |
|
101 | m_defaultSeries = series; | |
102 |
|
102 | |||
|
103 | QXYChartSeries* series0 = QXYChartSeries::create(); | |||
|
104 | ||||
103 | // TODO: a dedicated data class for storing x and y values |
|
105 | // TODO: a dedicated data class for storing x and y values | |
104 | QList<qreal> x; |
|
106 | QList<qreal> x; | |
105 | QList<qreal> y; |
|
107 | QList<qreal> y; | |
106 |
|
108 | |||
107 | if (data == "linear") { |
|
109 | if (data == "linear") { | |
108 |
for (int i = 0; i < |
|
110 | for (int i = 0; i < 20; i++) { | |
109 | x.append(i); |
|
111 | x.append(i); | |
110 |
y.append( |
|
112 | y.append(i); | |
111 | } |
|
113 | } | |
|
114 | for (int i = 0; i < 20; i++) | |||
|
115 | series0->add(i, i); | |||
112 | } else if (data == "linear, 1M") { |
|
116 | } else if (data == "linear, 1M") { | |
113 | for (int i = 0; i < 10000; i++) { |
|
117 | for (int i = 0; i < 10000; i++) { | |
114 | x.append(i); |
|
118 | x.append(i); | |
115 | y.append(20); |
|
119 | y.append(20); | |
116 | } |
|
120 | } | |
|
121 | for (int i = 0; i < 1000000; i++) | |||
|
122 | series0->add(i, 10); | |||
117 | } else if (data == "SIN") { |
|
123 | } else if (data == "SIN") { | |
118 | for (int i = 0; i < 100; i++) { |
|
124 | for (int i = 0; i < 100; i++) { | |
119 | x.append(i); |
|
125 | x.append(i); | |
120 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
126 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100)); | |
121 | } |
|
127 | } | |
|
128 | for (int i = 0; i < 100; i++) | |||
|
129 | series0->add(i, abs(sin(3.14159265358979 / 50 * i) * 100)); | |||
122 | } else if (data == "SIN + random") { |
|
130 | } else if (data == "SIN + random") { | |
123 | for (qreal i = 0; i < 100; i += 0.1) { |
|
131 | for (qreal i = 0; i < 100; i += 0.1) { | |
124 | x.append(i + (rand() % 5)); |
|
132 | x.append(i + (rand() % 5)); | |
125 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
133 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |
126 | } |
|
134 | } | |
|
135 | for (qreal i = 0; i < 100; i += 0.1) | |||
|
136 | series0->add(i + (rand() % 5), abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |||
127 | } else { |
|
137 | } else { | |
128 | // TODO: check if data has a valid file name |
|
138 | // TODO: check if data has a valid file name | |
129 | } |
|
139 | } | |
130 |
|
140 | |||
131 | // TODO: color of the series |
|
141 | // TODO: color of the series | |
132 | if (series == "Scatter") { |
|
142 | if (series == "Scatter") { | |
133 | /*QChartSeries* scatterSeries = */m_chartWidget->createSeries(x, y, QChartSeries::SeriesTypeScatter); |
|
143 | /*QChartSeries* scatterSeries = */ | |
|
144 | m_chartWidget->createSeries(x, y, QChartSeries::SeriesTypeScatter); | |||
134 | } else if (series == "Line") { |
|
145 | } else if (series == "Line") { | |
135 | QXYChartSeries* series0 = QXYChartSeries::create(); |
|
|||
136 | for (int i = 0; i < 1000000; i++) |
|
|||
137 | series0->add(i, 20); |
|
|||
138 | m_chartWidget->addSeries(series0); |
|
146 | m_chartWidget->addSeries(series0); | |
139 | } else { |
|
147 | } else { | |
140 | // TODO |
|
148 | // TODO | |
141 | } |
|
149 | } | |
142 | } |
|
150 | } | |
143 |
|
151 | |||
144 | void MainWidget::chartTypeChanged(int itemIndex) |
|
152 | void MainWidget::chartTypeChanged(int itemIndex) | |
145 | { |
|
153 | { | |
146 | // TODO: change chart type |
|
154 | // TODO: change chart type | |
147 | switch (itemIndex) { |
|
155 | switch (itemIndex) { | |
148 | case 4: |
|
156 | case 4: | |
149 | //m_chartWidget->setType(4); |
|
157 | //m_chartWidget->setType(4); | |
150 | break; |
|
158 | break; | |
151 | default: { |
|
159 | default: { | |
152 | //m_chartWidget->setType(0); |
|
160 | //m_chartWidget->setType(0); | |
153 | break; |
|
161 | break; | |
154 | } |
|
162 | } | |
155 | } |
|
163 | } | |
156 | } |
|
164 | } | |
157 |
|
165 | |||
158 | void MainWidget::testDataChanged(int itemIndex) |
|
166 | void MainWidget::testDataChanged(int itemIndex) | |
159 | { |
|
167 | { | |
160 | qDebug() << "testDataChanged: " << itemIndex; |
|
168 | qDebug() << "testDataChanged: " << itemIndex; | |
161 |
|
169 | |||
162 | // switch (itemIndex) { |
|
170 | // switch (itemIndex) { | |
163 | // case 0: { |
|
171 | // case 0: { | |
164 | // QList<QChartDataPoint> data; |
|
172 | // QList<QChartDataPoint> data; | |
165 | // for (int x = 0; x < 20; x++) { |
|
173 | // for (int x = 0; x < 20; x++) { | |
166 | // data.append(QChartDataPoint() << x << x / 2); |
|
174 | // data.append(QChartDataPoint() << x << x / 2); | |
167 | // } |
|
175 | // } | |
168 | // m_chartWidget->setData(data); |
|
176 | // m_chartWidget->setData(data); | |
169 | // break; |
|
177 | // break; | |
170 | // } |
|
178 | // } | |
171 | // case 1: { |
|
179 | // case 1: { | |
172 | // QList<QChartDataPoint> data; |
|
180 | // QList<QChartDataPoint> data; | |
173 | // for (int x = 0; x < 100; x++) { |
|
181 | // for (int x = 0; x < 100; x++) { | |
174 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100)); |
|
182 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100)); | |
175 | // } |
|
183 | // } | |
176 | // m_chartWidget->setData(data); |
|
184 | // m_chartWidget->setData(data); | |
177 | // break; |
|
185 | // break; | |
178 | // } |
|
186 | // } | |
179 | // case 2: { |
|
187 | // case 2: { | |
180 | // QList<QChartDataPoint> data; |
|
188 | // QList<QChartDataPoint> data; | |
181 | // for (int x = 0; x < 1000; x++) { |
|
189 | // for (int x = 0; x < 1000; x++) { | |
182 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
190 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
183 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
191 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
184 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
192 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
185 | // } |
|
193 | // } | |
186 | // m_chartWidget->setData(data); |
|
194 | // m_chartWidget->setData(data); | |
187 | // break; |
|
195 | // break; | |
188 | // } |
|
196 | // } | |
189 | // default: |
|
197 | // default: | |
190 | // break; |
|
198 | // break; | |
191 | // } |
|
199 | // } | |
192 | } |
|
200 | } | |
193 |
|
201 | |||
194 | void MainWidget::backgroundChanged(int itemIndex) |
|
202 | void MainWidget::backgroundChanged(int itemIndex) | |
195 | { |
|
203 | { | |
196 | qDebug() << "backgroundChanged: " << itemIndex; |
|
204 | qDebug() << "backgroundChanged: " << itemIndex; | |
197 | } |
|
205 | } | |
198 |
|
206 | |||
199 | void MainWidget::autoScaleChanged(int value) |
|
207 | void MainWidget::autoScaleChanged(int value) | |
200 | { |
|
208 | { | |
201 | if (value) { |
|
209 | if (value) { | |
202 | // TODO: enable auto scaling |
|
210 | // TODO: enable auto scaling | |
203 | } else { |
|
211 | } else { | |
204 | // TODO: set scaling manually (and disable auto scaling) |
|
212 | // TODO: set scaling manually (and disable auto scaling) | |
205 | } |
|
213 | } | |
206 |
|
214 | |||
207 | m_xMinSpin->setEnabled(!value); |
|
215 | m_xMinSpin->setEnabled(!value); | |
208 | m_xMaxSpin->setEnabled(!value); |
|
216 | m_xMaxSpin->setEnabled(!value); | |
209 | m_yMinSpin->setEnabled(!value); |
|
217 | m_yMinSpin->setEnabled(!value); | |
210 | m_yMaxSpin->setEnabled(!value); |
|
218 | m_yMaxSpin->setEnabled(!value); | |
211 | } |
|
219 | } | |
212 |
|
220 | |||
213 | void MainWidget::xMinChanged(int value) |
|
221 | void MainWidget::xMinChanged(int value) | |
214 | { |
|
222 | { | |
215 | qDebug() << "xMinChanged: " << value; |
|
223 | qDebug() << "xMinChanged: " << value; | |
216 | } |
|
224 | } | |
217 |
|
225 | |||
218 | void MainWidget::xMaxChanged(int value) |
|
226 | void MainWidget::xMaxChanged(int value) | |
219 | { |
|
227 | { | |
220 | qDebug() << "xMaxChanged: " << value; |
|
228 | qDebug() << "xMaxChanged: " << value; | |
221 | } |
|
229 | } | |
222 |
|
230 | |||
223 | void MainWidget::yMinChanged(int value) |
|
231 | void MainWidget::yMinChanged(int value) | |
224 | { |
|
232 | { | |
225 | qDebug() << "yMinChanged: " << value; |
|
233 | qDebug() << "yMinChanged: " << value; | |
226 | } |
|
234 | } | |
227 |
|
235 | |||
228 | void MainWidget::yMaxChanged(int value) |
|
236 | void MainWidget::yMaxChanged(int value) | |
229 | { |
|
237 | { | |
230 | qDebug() << "yMaxChanged: " << value; |
|
238 | qDebug() << "yMaxChanged: " << value; | |
231 | } |
|
239 | } |
General Comments 0
You need to be logged in to leave comments.
Login now