@@ -0,0 +1,67 | |||||
|
1 | #include "qscatterseries.h" | |||
|
2 | #include "qscatterseries_p.h" | |||
|
3 | #include "qchart.h" | |||
|
4 | #include <QPainter> | |||
|
5 | #include <QGraphicsScene> | |||
|
6 | ||||
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
8 | ||||
|
9 | //#define QSeriesData QList<qreal> | |||
|
10 | ||||
|
11 | QScatterSeriesPrivate::QScatterSeriesPrivate(QList<qreal> x, QList<qreal> y, QGraphicsItem *parent) : | |||
|
12 | QGraphicsItem(parent), | |||
|
13 | m_x(x), | |||
|
14 | m_y(y) | |||
|
15 | { | |||
|
16 | } | |||
|
17 | ||||
|
18 | void QScatterSeriesPrivate::setSize() | |||
|
19 | { | |||
|
20 | } | |||
|
21 | ||||
|
22 | QRectF QScatterSeriesPrivate::boundingRect() const | |||
|
23 | { | |||
|
24 | return QRectF(0, 0, 100, 100); | |||
|
25 | } | |||
|
26 | ||||
|
27 | void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |||
|
28 | { | |||
|
29 | QPen pen = painter->pen(); | |||
|
30 | QBrush brush = pen.brush(); | |||
|
31 | // TODO: The opacity should be user definable... | |||
|
32 | brush.setColor(QColor(255, 82, 0, 50)); | |||
|
33 | pen.setBrush(brush); | |||
|
34 | pen.setWidth(4); | |||
|
35 | 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 | ||||
|
46 | for (int i(0); i < m_x.count() && i < m_y.count(); i++) { | |||
|
47 | transform.reset(); | |||
|
48 | transform.translate(m_x.at(i) * xscale, m_y.at(i) * yscale); | |||
|
49 | painter->setTransform(transform); | |||
|
50 | painter->drawArc(0, 0, 4, 4, 0, 5760); | |||
|
51 | } | |||
|
52 | } | |||
|
53 | ||||
|
54 | QScatterSeries::QScatterSeries(QList<qreal> x, QList<qreal> y, QObject *parent) : | |||
|
55 | QChartSeries(parent), | |||
|
56 | d(new QScatterSeriesPrivate(x, y, qobject_cast<QGraphicsItem *> (parent))) | |||
|
57 | { | |||
|
58 | } | |||
|
59 | ||||
|
60 | QScatterSeries::~QScatterSeries() | |||
|
61 | { | |||
|
62 | delete d; | |||
|
63 | } | |||
|
64 | ||||
|
65 | #include "moc_qscatterseries.cpp" | |||
|
66 | ||||
|
67 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,29 | |||||
|
1 | #ifndef QSCATTERSERIES_H | |||
|
2 | #define QSCATTERSERIES_H | |||
|
3 | ||||
|
4 | #include "qchartseries.h" | |||
|
5 | ||||
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
7 | class QScatterSeriesPrivate; | |||
|
8 | ||||
|
9 | class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QChartSeries | |||
|
10 | { | |||
|
11 | Q_OBJECT | |||
|
12 | public: | |||
|
13 | //QScatterSeries(QSeriesData *data, QObject *chart); | |||
|
14 | QScatterSeries(QList<qreal> x, QList<qreal> y, QObject *chart = 0); | |||
|
15 | ~QScatterSeries(); | |||
|
16 | ||||
|
17 | public: // from QChartSeries | |||
|
18 | virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeScatter; } | |||
|
19 | ||||
|
20 | private: | |||
|
21 | Q_DECLARE_PRIVATE(QScatterSeries) | |||
|
22 | Q_DISABLE_COPY(QScatterSeries) | |||
|
23 | friend class QChart; | |||
|
24 | QScatterSeriesPrivate *const d; | |||
|
25 | }; | |||
|
26 | ||||
|
27 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
28 | ||||
|
29 | #endif // QSCATTERSERIES_H |
@@ -0,0 +1,29 | |||||
|
1 | #ifndef QSCATTERSERIESPRIVATE_H | |||
|
2 | #define QSCATTERSERIESPRIVATE_H | |||
|
3 | ||||
|
4 | #include "qchartseries.h" | |||
|
5 | #include <QGraphicsItem> | |||
|
6 | ||||
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
8 | ||||
|
9 | /*! | |||
|
10 | * The PIMPL class of QScatterSeries. | |||
|
11 | */ | |||
|
12 | class QScatterSeriesPrivate : public QGraphicsItem | |||
|
13 | { | |||
|
14 | public: | |||
|
15 | QScatterSeriesPrivate(QList<qreal> x, QList<qreal> y, QGraphicsItem *parent); | |||
|
16 | ||||
|
17 | public: // from QGraphicsItem | |||
|
18 | void setSize(); | |||
|
19 | QRectF boundingRect() const; | |||
|
20 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |||
|
21 | ||||
|
22 | // TODO: use the chart data class instead of list of x and y values? | |||
|
23 | QList<qreal> m_x; | |||
|
24 | QList<qreal> m_y; | |||
|
25 | }; | |||
|
26 | ||||
|
27 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
28 | ||||
|
29 | #endif // QSCATTERSERIES_H |
@@ -1,114 +1,140 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qchartseries.h" |
|
2 | #include "qchartseries.h" | |
|
3 | #include "qscatterseries.h" | |||
|
4 | #include "qscatterseries_p.h" | |||
3 | #include "xylinechartitem_p.h" |
|
5 | #include "xylinechartitem_p.h" | |
4 | #include "xyplotdomain_p.h" |
|
6 | #include "xyplotdomain_p.h" | |
5 | #include "axis_p.h" |
|
7 | #include "axis_p.h" | |
6 | #include "xygrid_p.h" |
|
8 | #include "xygrid_p.h" | |
|
9 | #include <QGraphicsScene> | |||
7 | #include <QDebug> |
|
10 | #include <QDebug> | |
8 |
|
11 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
13 | |||
11 | class QChartPrivate |
|
14 | class QChartPrivate | |
12 | { |
|
15 | { | |
13 | public: |
|
16 | public: | |
14 |
|
17 | |||
15 | QChartPrivate(QChart* parent): |
|
18 | QChartPrivate(QChart* parent): | |
16 | m_axisX(new Axis(parent)), |
|
19 | m_axisX(new Axis(parent)), | |
17 | m_axisY(new Axis(parent)), |
|
20 | m_axisY(new Axis(parent)), | |
18 | m_grid(new XYGrid(parent)), |
|
21 | m_grid(new XYGrid(parent)), | |
19 | m_plotDataIndex(0), |
|
22 | m_plotDataIndex(0), | |
20 | m_marginSize(0){} |
|
23 | m_marginSize(0){} | |
21 |
|
24 | |||
22 | Axis* m_axisX; |
|
25 | Axis* m_axisX; | |
23 | Axis* m_axisY; |
|
26 | Axis* m_axisY; | |
24 | XYGrid* m_grid; |
|
27 | XYGrid* m_grid; | |
25 | QRect m_rect; |
|
28 | QRect m_rect; | |
26 | QList<const QChartSeries*> m_series; |
|
29 | QList<const QChartSeries*> m_series; | |
27 | QList<XYPlotDomain> m_plotDataList; |
|
30 | QList<XYPlotDomain> m_plotDataList; | |
28 | QList<QGraphicsItem*> m_items; |
|
31 | QList<QGraphicsItem*> m_items; | |
29 | int m_plotDataIndex; |
|
32 | int m_plotDataIndex; | |
30 | int m_marginSize; |
|
33 | int m_marginSize; | |
31 |
|
34 | |||
32 | }; |
|
35 | }; | |
33 |
|
36 | |||
34 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
37 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
35 |
|
38 | |||
36 | QChart::QChart(QGraphicsItem* parent):QGraphicsItem(parent), |
|
39 | QChart::QChart(QGraphicsItem* parent):QGraphicsItem(parent), | |
37 | d_ptr(new QChartPrivate(this)) |
|
40 | d_ptr(new QChartPrivate(this)) | |
38 | { |
|
41 | { | |
39 | // setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
42 | // setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
40 | // set axis |
|
43 | // set axis | |
41 | Q_D(QChart); |
|
44 | Q_D(QChart); | |
42 | d->m_axisY->rotate(90); |
|
45 | d->m_axisY->rotate(90); | |
43 |
|
46 | |||
44 | //TODO hardcoded values , to removed soon |
|
47 | //TODO hardcoded values , to removed soon | |
45 | XYPlotDomain data; |
|
48 | XYPlotDomain data; | |
46 | data.m_minX = 0.0; |
|
49 | data.m_minX = 0.0; | |
47 | data.m_maxX = 100.0; |
|
50 | data.m_maxX = 100.0; | |
48 | data.m_minY = 0.0; |
|
51 | data.m_minY = 0.0; | |
49 | data.m_maxY = 100.0; |
|
52 | data.m_maxY = 100.0; | |
50 | data.m_ticksX=4; |
|
53 | data.m_ticksX=4; | |
51 | data.m_ticksY=4; |
|
54 | data.m_ticksY=4; | |
52 |
|
55 | |||
53 | d->m_plotDataList.clear(); |
|
56 | d->m_plotDataList.clear(); | |
54 | d->m_plotDataList << data; |
|
57 | d->m_plotDataList << data; | |
55 |
|
58 | |||
56 | d->m_grid->setZValue(10); |
|
59 | d->m_grid->setZValue(10); | |
57 | d->m_grid->setXYPlotData(d->m_plotDataList.at(0)); |
|
60 | d->m_grid->setXYPlotData(d->m_plotDataList.at(0)); | |
58 | } |
|
61 | } | |
59 |
|
62 | |||
60 | QChart::~QChart(){} |
|
63 | QChart::~QChart(){} | |
61 |
|
64 | |||
62 | QRectF QChart::boundingRect() const |
|
65 | QRectF QChart::boundingRect() const | |
63 | { |
|
66 | { | |
64 | Q_D(const QChart); |
|
67 | Q_D(const QChart); | |
65 | return d->m_rect; |
|
68 | return d->m_rect; | |
66 | } |
|
69 | } | |
67 |
|
70 | |||
68 | void QChart::addSeries(QChartSeries* series) |
|
71 | void QChart::addSeries(QChartSeries* series) | |
69 | { |
|
72 | { | |
70 | Q_D(QChart); |
|
73 | Q_D(QChart); | |
71 | d->m_series<<series; |
|
74 | d->m_series<<series; | |
72 |
|
75 | |||
73 | switch(series->type()) |
|
76 | switch(series->type()) | |
74 | { |
|
77 | { | |
75 | case QChartSeries::SeriesTypeLine: { |
|
78 | case QChartSeries::SeriesTypeLine: { | |
76 | XYLineChartItem* item = new XYLineChartItem(reinterpret_cast<QXYChartSeries*>(series),this); |
|
79 | XYLineChartItem* item = new XYLineChartItem(reinterpret_cast<QXYChartSeries*>(series),this); | |
77 | item->updateXYPlotData(d->m_plotDataList.at(0)); |
|
80 | item->updateXYPlotData(d->m_plotDataList.at(0)); | |
78 | d->m_items<<item; |
|
81 | d->m_items<<item; | |
79 | break; |
|
82 | break; | |
80 | } |
|
83 | } | |
81 | case QChartSeries::SeriesTypeScatter: { |
|
84 | case QChartSeries::SeriesTypeScatter: { | |
82 | break; |
|
85 | break; | |
83 | } |
|
86 | } | |
84 | } |
|
87 | } | |
85 | } |
|
88 | } | |
86 |
|
89 | |||
|
90 | QChartSeries* QChart::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type) | |||
|
91 | { | |||
|
92 | Q_D(QChart); | |||
|
93 | ||||
|
94 | // TODO: support also other types | |||
|
95 | Q_ASSERT(type == QChartSeries::SeriesTypeScatter); | |||
|
96 | QChartSeries *series = 0; | |||
|
97 | ||||
|
98 | switch (type) { | |||
|
99 | case QChartSeries::SeriesTypeScatter: { | |||
|
100 | QScatterSeries *scatterSeries = new QScatterSeries(x, y, this); | |||
|
101 | d->m_items.append(scatterSeries->d); | |||
|
102 | scene()->addItem(scatterSeries->d); | |||
|
103 | //series = qobject_cast<QChartSeries *>(scatterSeries); | |||
|
104 | break; | |||
|
105 | } | |||
|
106 | default: | |||
|
107 | break; | |||
|
108 | } | |||
|
109 | ||||
|
110 | return series; | |||
|
111 | } | |||
87 | void QChart::setSize(const QSizeF& size) |
|
112 | void QChart::setSize(const QSizeF& size) | |
88 | { |
|
113 | { | |
89 | Q_D(QChart); |
|
114 | Q_D(QChart); | |
90 | //TODO refactor to setGeometry |
|
115 | //TODO refactor to setGeometry | |
91 | d->m_rect = QRect(QPoint(0,0),size.toSize()); |
|
116 | d->m_rect = QRect(QPoint(0,0),size.toSize()); | |
92 | d->m_rect.adjust(margin(),margin(),-margin(),-margin()); |
|
117 | d->m_rect.adjust(margin(),margin(),-margin(),-margin()); | |
93 | d->m_grid->setPos(d->m_rect.topLeft()); |
|
118 | d->m_grid->setPos(d->m_rect.topLeft()); | |
94 | d->m_grid->setSize(d->m_rect.size()); |
|
119 | d->m_grid->setSize(d->m_rect.size()); | |
95 | d->m_plotDataList[0].m_viewportRect = d->m_rect; |
|
120 | d->m_plotDataList[0].m_viewportRect = d->m_rect; | |
|
121 | // TODO: line chart items would need to be updated separately as they don't support update | |||
|
122 | // via paint method | |||
96 | foreach(QGraphicsItem* item , d->m_items) |
|
123 | foreach(QGraphicsItem* item , d->m_items) | |
97 | reinterpret_cast<XYLineChartItem*>(item)->updateXYPlotData(d->m_plotDataList.at(0)); |
|
124 | reinterpret_cast<XYLineChartItem*>(item)->updateXYPlotData(d->m_plotDataList.at(0)); | |
98 | update(); |
|
125 | update(); | |
99 |
|
||||
100 | } |
|
126 | } | |
101 |
|
127 | |||
102 | int QChart::margin() const |
|
128 | int QChart::margin() const | |
103 | { |
|
129 | { | |
104 | Q_D(const QChart); |
|
130 | Q_D(const QChart); | |
105 | return d->m_marginSize; |
|
131 | return d->m_marginSize; | |
106 | } |
|
132 | } | |
107 |
|
133 | |||
108 | void QChart::setMargin(int margin) |
|
134 | void QChart::setMargin(int margin) | |
109 | { |
|
135 | { | |
110 | Q_D(QChart); |
|
136 | Q_D(QChart); | |
111 | d->m_marginSize = margin; |
|
137 | d->m_marginSize = margin; | |
112 | } |
|
138 | } | |
113 |
|
139 | |||
114 | QTCOMMERCIALCHART_END_NAMESPACE |
|
140 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,43 +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 <QGraphicsItem> |
|
6 | #include <QGraphicsItem> | |
6 |
|
7 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
9 | |||
9 | class Axis; |
|
10 | class Axis; | |
10 | class XYGrid; |
|
11 | class XYGrid; | |
11 | class QChartSeries; |
|
12 | class QChartSeries; | |
12 | class XYPlotDomain; |
|
13 | class XYPlotDomain; | |
13 | class QChartPrivate; |
|
14 | class QChartPrivate; | |
14 |
|
15 | |||
15 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsItem |
|
16 | // TODO: We don't need to have QChart tied to QGraphicsItem: | |
|
17 | //class QTCOMMERCIALCHART_EXPORT QChart | |||
|
18 | //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem { | |||
|
19 | // public: QChartGraphicsItem(QChart &chart); | |||
|
20 | ||||
|
21 | /*! | |||
|
22 | * TODO: define the responsibilities | |||
|
23 | */ | |||
|
24 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsItem, public QObject | |||
16 | { |
|
25 | { | |
17 |
|
26 | |||
18 | public: |
|
27 | public: | |
19 | QChart(QGraphicsItem* parent = 0); |
|
28 | QChart(QGraphicsItem* parent = 0); | |
20 | virtual ~QChart(); |
|
29 | virtual ~QChart(); | |
21 |
|
30 | |||
22 | //from QGraphicsItem |
|
31 | //from QGraphicsItem | |
23 | virtual QRectF boundingRect() const; |
|
32 | virtual QRectF boundingRect() const; | |
24 | virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){}; |
|
33 | virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){}; | |
25 |
|
34 | |||
26 | void addSeries(QChartSeries* series); |
|
35 | void addSeries(QChartSeries* series); | |
|
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... | |||
|
38 | QChartSeries* createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type); | |||
27 |
|
39 | |||
28 | virtual void setSize(const QSizeF& rect); |
|
40 | virtual void setSize(const QSizeF& rect); | |
29 | void setMargin(int margin); |
|
41 | void setMargin(int margin); | |
30 | int margin() const; |
|
42 | int margin() const; | |
31 |
|
43 | |||
32 | protected: |
|
44 | protected: | |
33 | QChartPrivate * const d_ptr; |
|
45 | QChartPrivate * const d_ptr; | |
34 |
|
46 | |||
35 | private: |
|
47 | private: | |
36 | Q_DISABLE_COPY(QChart) |
|
48 | Q_DISABLE_COPY(QChart) | |
37 | Q_DECLARE_PRIVATE(QChart) |
|
49 | Q_DECLARE_PRIVATE(QChart) | |
38 |
|
50 | |||
39 | }; |
|
51 | }; | |
40 |
|
52 | |||
41 | QTCOMMERCIALCHART_END_NAMESPACE |
|
53 | QTCOMMERCIALCHART_END_NAMESPACE | |
42 |
|
54 | |||
43 | #endif |
|
55 | #endif |
@@ -1,69 +1,75 | |||||
1 | #include "qchartwidget.h" |
|
1 | #include "qchartwidget.h" | |
2 | #include "qchartseries.h" |
|
2 | #include "qchartseries.h" | |
3 | #include <QGraphicsView> |
|
3 | #include <QGraphicsView> | |
4 | #include <QGraphicsScene> |
|
4 | #include <QGraphicsScene> | |
5 | #include <QResizeEvent> |
|
5 | #include <QResizeEvent> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | class QChartWidgetPrivate |
|
9 | class QChartWidgetPrivate | |
10 | { |
|
10 | { | |
11 | public: |
|
11 | public: | |
12 | QChartWidgetPrivate(QChartWidget *parent) : |
|
12 | QChartWidgetPrivate(QChartWidget *parent) : | |
13 | m_view(0), |
|
13 | m_view(0), | |
14 | m_scene(0), |
|
14 | m_scene(0), | |
15 | m_chart(0) |
|
15 | m_chart(0) | |
16 | { |
|
16 | { | |
17 | m_scene = new QGraphicsScene(); |
|
17 | m_scene = new QGraphicsScene(); | |
18 | m_view = new QGraphicsView(parent); |
|
18 | m_view = new QGraphicsView(parent); | |
19 | m_view->setScene(m_scene); |
|
19 | m_view->setScene(m_scene); | |
20 | m_chart = new QChart(); |
|
20 | m_chart = new QChart(); | |
21 | m_scene->addItem(m_chart); |
|
21 | m_scene->addItem(m_chart); | |
|
22 | m_view->show(); | |||
22 | } |
|
23 | } | |
23 |
|
24 | |||
24 | ~QChartWidgetPrivate() { |
|
25 | ~QChartWidgetPrivate() { | |
25 | } |
|
26 | } | |
26 |
|
27 | |||
27 | QGraphicsView *m_view; |
|
28 | QGraphicsView *m_view; | |
28 | QGraphicsScene *m_scene; |
|
29 | QGraphicsScene *m_scene; | |
29 | QChart* m_chart; |
|
30 | QChart* m_chart; | |
30 | }; |
|
31 | }; | |
31 |
|
32 | |||
32 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
33 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
33 |
|
34 | |||
34 | QChartWidget::QChartWidget(QWidget *parent) : |
|
35 | QChartWidget::QChartWidget(QWidget *parent) : | |
35 | QWidget(parent), |
|
36 | QWidget(parent), | |
36 | d_ptr(new QChartWidgetPrivate(this)) |
|
37 | d_ptr(new QChartWidgetPrivate(this)) | |
37 | { |
|
38 | { | |
38 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
39 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
39 | } |
|
40 | } | |
40 |
|
41 | |||
41 | QChartWidget::~QChartWidget() |
|
42 | QChartWidget::~QChartWidget() | |
42 | { |
|
43 | { | |
43 | delete d_ptr; |
|
44 | delete d_ptr; | |
44 | } |
|
45 | } | |
45 |
|
46 | |||
46 | void QChartWidget::resizeEvent(QResizeEvent *event) |
|
47 | void QChartWidget::resizeEvent(QResizeEvent *event) | |
47 | { |
|
48 | { | |
48 | Q_D(QChartWidget); |
|
49 | Q_D(QChartWidget); | |
49 | d->m_view->resize(size().width(),size().height()); |
|
50 | d->m_view->resize(size().width(),size().height()); | |
50 | d->m_scene->setSceneRect(0,0,size().width(),size().height()); |
|
51 | d->m_scene->setSceneRect(0,0,size().width(),size().height()); | |
51 | d->m_chart->setSize(size()); |
|
52 | d->m_chart->setSize(size()); | |
52 | QWidget::resizeEvent(event); |
|
53 | QWidget::resizeEvent(event); | |
53 | } |
|
54 | } | |
54 |
|
55 | |||
55 | QSize QChartWidget::sizeHint() const |
|
56 | QSize QChartWidget::sizeHint() const | |
56 | { |
|
57 | { | |
57 | // TODO: calculate size hint based on contents? |
|
58 | // TODO: calculate size hint based on contents? | |
58 | return QSize(100, 100); |
|
59 | return QSize(100, 100); | |
59 | } |
|
60 | } | |
60 |
|
61 | |||
61 | void QChartWidget::addSeries(QChartSeries* series) |
|
62 | void QChartWidget::addSeries(QChartSeries* series) | |
62 | { |
|
63 | { | |
63 | Q_D(QChartWidget); |
|
64 | Q_D(QChartWidget); | |
64 | d->m_chart->addSeries(series); |
|
65 | d->m_chart->addSeries(series); | |
65 | } |
|
66 | } | |
66 |
|
67 | |||
|
68 | QChartSeries* QChartWidget::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type) | |||
|
69 | { | |||
|
70 | Q_D(QChartWidget); | |||
|
71 | return d->m_chart->createSeries(x, y, type); | |||
|
72 | } | |||
67 | #include "moc_qchartwidget.cpp" |
|
73 | #include "moc_qchartwidget.cpp" | |
68 |
|
74 | |||
69 | QTCOMMERCIALCHART_END_NAMESPACE |
|
75 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,36 +1,38 | |||||
1 | #ifndef QCHARTWIDGET_H |
|
1 | #ifndef QCHARTWIDGET_H | |
2 | #define QCHARTWIDGET_H |
|
2 | #define QCHARTWIDGET_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qchart.h" |
|
5 | #include "qchart.h" | |
6 | #include <QWidget> |
|
6 | #include <QWidget> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class QChartSeries; |
|
10 | class QChartSeries; | |
11 | class QChartWidgetPrivate; |
|
11 | class QChartWidgetPrivate; | |
12 |
|
12 | |||
13 | class QTCOMMERCIALCHART_EXPORT QChartWidget : public QWidget |
|
13 | class QTCOMMERCIALCHART_EXPORT QChartWidget : public QWidget | |
14 | { |
|
14 | { | |
15 | Q_OBJECT |
|
15 | Q_OBJECT | |
16 | public: |
|
16 | public: | |
17 | explicit QChartWidget(QWidget *parent = 0); |
|
17 | explicit QChartWidget(QWidget *parent = 0); | |
18 | ~QChartWidget(); |
|
18 | ~QChartWidget(); | |
19 |
|
19 | |||
20 | //implement from QWidget |
|
20 | //implement from QWidget | |
21 | void resizeEvent(QResizeEvent *event); |
|
21 | void resizeEvent(QResizeEvent *event); | |
22 | QSize sizeHint() const; |
|
22 | QSize sizeHint() const; | |
23 |
|
23 | |||
|
24 | // TODO: addSeries and createSeries are optional solutions | |||
24 | void addSeries(QChartSeries* series); |
|
25 | void addSeries(QChartSeries* series); | |
|
26 | QChartSeries* createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type); | |||
25 | protected: |
|
27 | protected: | |
26 | QChartWidgetPrivate * const d_ptr; |
|
28 | QChartWidgetPrivate * const d_ptr; | |
27 |
|
29 | |||
28 | private: |
|
30 | private: | |
29 | Q_DISABLE_COPY(QChartWidget) |
|
31 | Q_DISABLE_COPY(QChartWidget) | |
30 | Q_DECLARE_PRIVATE(QChartWidget) |
|
32 | Q_DECLARE_PRIVATE(QChartWidget) | |
31 |
|
33 | |||
32 | }; |
|
34 | }; | |
33 |
|
35 | |||
34 | QTCOMMERCIALCHART_END_NAMESPACE |
|
36 | QTCOMMERCIALCHART_END_NAMESPACE | |
35 |
|
37 | |||
36 | #endif // QCHARTWIDGET_H |
|
38 | #endif // QCHARTWIDGET_H |
@@ -1,73 +1,76 | |||||
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 |
|
5 | |||
6 | TARGET = QtCommercialChart |
|
6 | TARGET = QtCommercialChart | |
7 | DESTDIR = $$CHART_BUILD_LIB_DIR |
|
7 | DESTDIR = $$CHART_BUILD_LIB_DIR | |
8 | TEMPLATE = lib |
|
8 | TEMPLATE = lib | |
9 | QT += core \ |
|
9 | QT += core \ | |
10 | gui |
|
10 | gui | |
11 |
|
11 | |||
12 | CONFIG += debug_and_release |
|
12 | CONFIG += debug_and_release | |
13 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd |
|
13 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd | |
14 |
|
14 | |||
15 | SOURCES += \ |
|
15 | SOURCES += \ | |
16 | xylinechart/qxychartseries.cpp \ |
|
16 | xylinechart/qxychartseries.cpp \ | |
17 | xylinechart/xylinechartitem.cpp \ |
|
17 | xylinechart/xylinechartitem.cpp \ | |
18 | xylinechart/xygrid.cpp \ |
|
18 | xylinechart/xygrid.cpp \ | |
19 | xylinechart/xyplotdomain.cpp \ |
|
19 | xylinechart/xyplotdomain.cpp \ | |
|
20 | qscatterseries.cpp \ | |||
20 | qchart.cpp \ |
|
21 | qchart.cpp \ | |
21 | axis.cpp \ |
|
22 | axis.cpp \ | |
22 | qchartwidget.cpp |
|
23 | qchartwidget.cpp | |
23 |
|
24 | |||
24 | PRIVATE_HEADERS += \ |
|
25 | PRIVATE_HEADERS += \ | |
25 | xylinechart/xylinechartitem_p.h \ |
|
26 | xylinechart/xylinechartitem_p.h \ | |
26 | xylinechart/xyplotdomain_p.h \ |
|
27 | xylinechart/xyplotdomain_p.h \ | |
27 | xylinechart/xygrid_p.h \ |
|
28 | xylinechart/xygrid_p.h \ | |
|
29 | qscatterseries_p.h \ | |||
28 | axis_p.h |
|
30 | axis_p.h | |
29 |
|
31 | |||
30 | PUBLIC_HEADERS += \ |
|
32 | PUBLIC_HEADERS += \ | |
31 | qchartseries.h \ |
|
33 | qchartseries.h \ | |
|
34 | qscatterseries.h \ | |||
32 | qchart.h \ |
|
35 | qchart.h \ | |
33 | qchartwidget.h \ |
|
36 | qchartwidget.h \ | |
34 | qchartglobal.h \ |
|
37 | qchartglobal.h \ | |
35 | xylinechart/qxychartseries.h |
|
38 | xylinechart/qxychartseries.h | |
36 |
|
39 | |||
37 | HEADERS += $$PUBLIC_HEADERS |
|
40 | HEADERS += $$PUBLIC_HEADERS | |
38 | HEADERS += $$PRIVATE_HEADERS |
|
41 | HEADERS += $$PRIVATE_HEADERS | |
39 |
|
42 | |||
40 | INCLUDEPATH += xylinechart \ |
|
43 | INCLUDEPATH += xylinechart \ | |
41 | . |
|
44 | . | |
42 |
|
45 | |||
43 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
46 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib | |
44 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
47 | MOC_DIR = $$CHART_BUILD_DIR/lib | |
45 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
48 | UI_DIR = $$CHART_BUILD_DIR/lib | |
46 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
49 | RCC_DIR = $$CHART_BUILD_DIR/lib | |
47 |
|
50 | |||
48 |
|
51 | |||
49 | DEFINES += QTCOMMERCIALCHART_LIBRARY |
|
52 | DEFINES += QTCOMMERCIALCHART_LIBRARY | |
50 |
|
53 | |||
51 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart |
|
54 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart | |
52 | public_headers.files = $$PUBLIC_HEADERS |
|
55 | public_headers.files = $$PUBLIC_HEADERS | |
53 | target.path = $$[QT_INSTALL_LIBS] |
|
56 | target.path = $$[QT_INSTALL_LIBS] | |
54 | INSTALLS += target \ |
|
57 | INSTALLS += target \ | |
55 | public_headers |
|
58 | public_headers | |
56 |
|
59 | |||
57 |
|
60 | |||
58 | install_build_headers.name = bild_headers |
|
61 | install_build_headers.name = bild_headers | |
59 | install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
62 | install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
60 | install_build_headers.input = PUBLIC_HEADERS |
|
63 | install_build_headers.input = PUBLIC_HEADERS | |
61 | install_build_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} $$CHART_BUILD_HEADER_DIR |
|
64 | install_build_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} $$CHART_BUILD_HEADER_DIR | |
62 | install_build_headers.CONFIG += target_predeps no_link |
|
65 | install_build_headers.CONFIG += target_predeps no_link | |
63 | QMAKE_EXTRA_COMPILERS += install_build_headers |
|
66 | QMAKE_EXTRA_COMPILERS += install_build_headers | |
64 |
|
67 | |||
65 | chartversion.target = qchartversion_p.h |
|
68 | chartversion.target = qchartversion_p.h | |
66 | chartversion.commands = @echo "build_time" > $$chartversion.target; |
|
69 | chartversion.commands = @echo "build_time" > $$chartversion.target; | |
67 | chartversion.depends = $$HEADERS $$SOURCES |
|
70 | chartversion.depends = $$HEADERS $$SOURCES | |
68 | PRE_TARGETDEPS += qchartversion_p.h |
|
71 | PRE_TARGETDEPS += qchartversion_p.h | |
69 | QMAKE_CLEAN+= qchartversion_p.h |
|
72 | QMAKE_CLEAN+= qchartversion_p.h | |
70 | QMAKE_EXTRA_TARGETS += chartversion |
|
73 | QMAKE_EXTRA_TARGETS += chartversion | |
71 |
|
74 | |||
72 | unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR |
|
75 | unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR | |
73 | win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR No newline at end of file |
|
76 | win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR |
@@ -1,225 +1,231 | |||||
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 = 0; |
|
103 | // TODO: a dedicated data class for storing x and y values | |
104 |
|
104 | QList<qreal> x; | ||
105 | // TODO: color of the series |
|
105 | QList<qreal> y; | |
106 | if (series == "Scatter") { |
|
|||
107 | series0 = QXYChartSeries::create(); |
|
|||
108 | } else if (series == "Line") { |
|
|||
109 | series0 = QXYChartSeries::create(); |
|
|||
110 | } else { |
|
|||
111 | // TODO |
|
|||
112 | series0 = QXYChartSeries::create(); |
|
|||
113 | } |
|
|||
114 |
|
106 | |||
115 | if (data == "linear") { |
|
107 | if (data == "linear") { | |
116 | for (int i = 0; i < 10; i++) |
|
108 | for (int i = 0; i < 10; i++) { | |
117 |
|
|
109 | x.append(i); | |
|
110 | y.append(10); | |||
|
111 | } | |||
118 | } else if (data == "linear, 1M") { |
|
112 | } else if (data == "linear, 1M") { | |
119 |
for (int i = 0; i < 10000 |
|
113 | for (int i = 0; i < 10000; i++) { | |
120 |
|
|
114 | x.append(i); | |
|
115 | y.append(20); | |||
|
116 | } | |||
121 | } else if (data == "SIN") { |
|
117 | } else if (data == "SIN") { | |
122 |
for (int |
|
118 | for (int i = 0; i < 100; i++) { | |
123 | series0->add(x, abs(sin(3.14159265358979 / 50 * x) * 100)); |
|
119 | x.append(i); | |
124 | QList<QXYChartSeries*> dataset; |
|
120 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100)); | |
125 | dataset << series0; |
|
121 | } | |
126 | } else if (data == "SIN + random") { |
|
122 | } else if (data == "SIN + random") { | |
127 |
for (qreal |
|
123 | for (qreal i = 0; i < 100; i += 0.1) { | |
128 |
|
|
124 | x.append(i + (rand() % 5)); | |
129 |
|
|
125 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |
130 | } |
|
126 | } | |
131 | } else { |
|
127 | } else { | |
132 | // TODO: check if data has a valid file name |
|
128 | // TODO: check if data has a valid file name | |
133 | } |
|
129 | } | |
134 |
|
130 | |||
135 | m_chartWidget->addSeries(series0); |
|
131 | // TODO: color of the series | |
|
132 | if (series == "Scatter") { | |||
|
133 | /*QChartSeries* scatterSeries = */m_chartWidget->createSeries(x, y, QChartSeries::SeriesTypeScatter); | |||
|
134 | } 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); | |||
|
139 | } else { | |||
|
140 | // TODO | |||
|
141 | } | |||
136 | } |
|
142 | } | |
137 |
|
143 | |||
138 | void MainWidget::chartTypeChanged(int itemIndex) |
|
144 | void MainWidget::chartTypeChanged(int itemIndex) | |
139 | { |
|
145 | { | |
140 | // TODO: change chart type |
|
146 | // TODO: change chart type | |
141 | switch (itemIndex) { |
|
147 | switch (itemIndex) { | |
142 | case 4: |
|
148 | case 4: | |
143 | //m_chartWidget->setType(4); |
|
149 | //m_chartWidget->setType(4); | |
144 | break; |
|
150 | break; | |
145 | default: { |
|
151 | default: { | |
146 | //m_chartWidget->setType(0); |
|
152 | //m_chartWidget->setType(0); | |
147 | break; |
|
153 | break; | |
148 | } |
|
154 | } | |
149 | } |
|
155 | } | |
150 | } |
|
156 | } | |
151 |
|
157 | |||
152 | void MainWidget::testDataChanged(int itemIndex) |
|
158 | void MainWidget::testDataChanged(int itemIndex) | |
153 | { |
|
159 | { | |
154 | qDebug() << "testDataChanged: " << itemIndex; |
|
160 | qDebug() << "testDataChanged: " << itemIndex; | |
155 |
|
161 | |||
156 | // switch (itemIndex) { |
|
162 | // switch (itemIndex) { | |
157 | // case 0: { |
|
163 | // case 0: { | |
158 | // QList<QChartDataPoint> data; |
|
164 | // QList<QChartDataPoint> data; | |
159 | // for (int x = 0; x < 20; x++) { |
|
165 | // for (int x = 0; x < 20; x++) { | |
160 | // data.append(QChartDataPoint() << x << x / 2); |
|
166 | // data.append(QChartDataPoint() << x << x / 2); | |
161 | // } |
|
167 | // } | |
162 | // m_chartWidget->setData(data); |
|
168 | // m_chartWidget->setData(data); | |
163 | // break; |
|
169 | // break; | |
164 | // } |
|
170 | // } | |
165 | // case 1: { |
|
171 | // case 1: { | |
166 | // QList<QChartDataPoint> data; |
|
172 | // QList<QChartDataPoint> data; | |
167 | // for (int x = 0; x < 100; x++) { |
|
173 | // for (int x = 0; x < 100; x++) { | |
168 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100)); |
|
174 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100)); | |
169 | // } |
|
175 | // } | |
170 | // m_chartWidget->setData(data); |
|
176 | // m_chartWidget->setData(data); | |
171 | // break; |
|
177 | // break; | |
172 | // } |
|
178 | // } | |
173 | // case 2: { |
|
179 | // case 2: { | |
174 | // QList<QChartDataPoint> data; |
|
180 | // QList<QChartDataPoint> data; | |
175 | // for (int x = 0; x < 1000; x++) { |
|
181 | // for (int x = 0; x < 1000; x++) { | |
176 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
182 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
177 | // 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)); | |
178 | // 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)); | |
179 | // } |
|
185 | // } | |
180 | // m_chartWidget->setData(data); |
|
186 | // m_chartWidget->setData(data); | |
181 | // break; |
|
187 | // break; | |
182 | // } |
|
188 | // } | |
183 | // default: |
|
189 | // default: | |
184 | // break; |
|
190 | // break; | |
185 | // } |
|
191 | // } | |
186 | } |
|
192 | } | |
187 |
|
193 | |||
188 | void MainWidget::backgroundChanged(int itemIndex) |
|
194 | void MainWidget::backgroundChanged(int itemIndex) | |
189 | { |
|
195 | { | |
190 | qDebug() << "backgroundChanged: " << itemIndex; |
|
196 | qDebug() << "backgroundChanged: " << itemIndex; | |
191 | } |
|
197 | } | |
192 |
|
198 | |||
193 | void MainWidget::autoScaleChanged(int value) |
|
199 | void MainWidget::autoScaleChanged(int value) | |
194 | { |
|
200 | { | |
195 | if (value) { |
|
201 | if (value) { | |
196 | // TODO: enable auto scaling |
|
202 | // TODO: enable auto scaling | |
197 | } else { |
|
203 | } else { | |
198 | // TODO: set scaling manually (and disable auto scaling) |
|
204 | // TODO: set scaling manually (and disable auto scaling) | |
199 | } |
|
205 | } | |
200 |
|
206 | |||
201 | m_xMinSpin->setEnabled(!value); |
|
207 | m_xMinSpin->setEnabled(!value); | |
202 | m_xMaxSpin->setEnabled(!value); |
|
208 | m_xMaxSpin->setEnabled(!value); | |
203 | m_yMinSpin->setEnabled(!value); |
|
209 | m_yMinSpin->setEnabled(!value); | |
204 | m_yMaxSpin->setEnabled(!value); |
|
210 | m_yMaxSpin->setEnabled(!value); | |
205 | } |
|
211 | } | |
206 |
|
212 | |||
207 | void MainWidget::xMinChanged(int value) |
|
213 | void MainWidget::xMinChanged(int value) | |
208 | { |
|
214 | { | |
209 | qDebug() << "xMinChanged: " << value; |
|
215 | qDebug() << "xMinChanged: " << value; | |
210 | } |
|
216 | } | |
211 |
|
217 | |||
212 | void MainWidget::xMaxChanged(int value) |
|
218 | void MainWidget::xMaxChanged(int value) | |
213 | { |
|
219 | { | |
214 | qDebug() << "xMaxChanged: " << value; |
|
220 | qDebug() << "xMaxChanged: " << value; | |
215 | } |
|
221 | } | |
216 |
|
222 | |||
217 | void MainWidget::yMinChanged(int value) |
|
223 | void MainWidget::yMinChanged(int value) | |
218 | { |
|
224 | { | |
219 | qDebug() << "yMinChanged: " << value; |
|
225 | qDebug() << "yMinChanged: " << value; | |
220 | } |
|
226 | } | |
221 |
|
227 | |||
222 | void MainWidget::yMaxChanged(int value) |
|
228 | void MainWidget::yMaxChanged(int value) | |
223 | { |
|
229 | { | |
224 | qDebug() << "yMaxChanged: " << value; |
|
230 | qDebug() << "yMaxChanged: " << value; | |
225 | } |
|
231 | } |
General Comments 0
You need to be logged in to leave comments.
Login now