@@ -0,0 +1,69 | |||||
|
1 | #include "xylinechartitem_p.h" | |||
|
2 | #include "axis_p.h" | |||
|
3 | #include "xygrid_p.h" | |||
|
4 | #include "qxychartseries.h" | |||
|
5 | #include <QPainter> | |||
|
6 | #include <QStyleOptionGraphicsItem> | |||
|
7 | #include <QDebug> | |||
|
8 | ||||
|
9 | QCHART_BEGIN_NAMESPACE | |||
|
10 | ||||
|
11 | XYLineChartItem::XYLineChartItem(QXYChartSeries* series,QGraphicsItem *parent):QGraphicsItem(parent), | |||
|
12 | m_series(series), | |||
|
13 | m_dirtyGeometry(true) | |||
|
14 | { | |||
|
15 | ||||
|
16 | } | |||
|
17 | ||||
|
18 | void XYLineChartItem::setChartSize(const QRectF& rect) | |||
|
19 | { | |||
|
20 | m_rect = rect; | |||
|
21 | m_dirtyGeometry = true; | |||
|
22 | } | |||
|
23 | ||||
|
24 | void XYLineChartItem::setXYPlotData(const XYPlotData& data){ | |||
|
25 | m_xyPlotData=data; | |||
|
26 | m_dirtyGeometry = true; | |||
|
27 | } | |||
|
28 | ||||
|
29 | QRectF XYLineChartItem::boundingRect() const | |||
|
30 | { | |||
|
31 | return m_polyline.boundingRect(); | |||
|
32 | } | |||
|
33 | ||||
|
34 | ||||
|
35 | void XYLineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget) | |||
|
36 | { | |||
|
37 | if(m_dirtyGeometry) { | |||
|
38 | ||||
|
39 | m_dirtyGeometry=false; | |||
|
40 | ||||
|
41 | if (!m_rect.isValid()) | |||
|
42 | return; | |||
|
43 | ||||
|
44 | painter->setClipRect(m_rect.adjusted(+1, +1, -1, -1)); | |||
|
45 | ||||
|
46 | const qreal deltaX = (m_rect.width()-1)/m_xyPlotData.spanX(); | |||
|
47 | const qreal deltaY = (m_rect.height()-1)/m_xyPlotData.spanY(); | |||
|
48 | ||||
|
49 | m_polyline.clear(); | |||
|
50 | m_polyline.resize(m_series->count()); | |||
|
51 | ||||
|
52 | for (int j = 0; j < m_series->count(); ++j) { | |||
|
53 | qreal dx = m_series->x(j) - m_xyPlotData.m_minX; | |||
|
54 | qreal dy = m_series->y(j) - m_xyPlotData.m_minY; | |||
|
55 | qreal x = (dx * deltaX) + m_rect.left(); | |||
|
56 | qreal y = - (dy * deltaY) + m_rect.bottom(); | |||
|
57 | m_polyline[j] = QPointF(x, y); | |||
|
58 | } | |||
|
59 | painter->setPen(m_series->color()); | |||
|
60 | painter->drawPolyline(m_polyline); | |||
|
61 | } | |||
|
62 | ||||
|
63 | painter->setClipRect(m_rect.adjusted(+1, +1, -1, -1)); | |||
|
64 | painter->setPen(m_series->color()); | |||
|
65 | painter->drawPolyline(m_polyline); | |||
|
66 | ||||
|
67 | } | |||
|
68 | ||||
|
69 | QCHART_END_NAMESPACE |
@@ -0,0 +1,37 | |||||
|
1 | #ifndef XYLINECHARTITEM_H | |||
|
2 | #define XYLINECHARTITEM_H | |||
|
3 | ||||
|
4 | #include "qchartconfig.h" | |||
|
5 | #include "qchart.h" | |||
|
6 | #include "xyplotdata_p.h" | |||
|
7 | ||||
|
8 | QCHART_BEGIN_NAMESPACE | |||
|
9 | ||||
|
10 | class QXYChartSeries; | |||
|
11 | ||||
|
12 | class XYLineChartItem : public QGraphicsItem | |||
|
13 | { | |||
|
14 | ||||
|
15 | public: | |||
|
16 | XYLineChartItem(QXYChartSeries* m_series,QGraphicsItem *parent = 0); | |||
|
17 | virtual ~ XYLineChartItem(){}; | |||
|
18 | ||||
|
19 | //from QGraphicsItem | |||
|
20 | virtual QRectF boundingRect() const; | |||
|
21 | virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |||
|
22 | ||||
|
23 | //TODO: this is just temporary interface | |||
|
24 | void setChartSize(const QRectF& size); | |||
|
25 | void setXYPlotData(const XYPlotData& data); | |||
|
26 | ||||
|
27 | private: | |||
|
28 | QRectF m_rect; | |||
|
29 | QPolygonF m_polyline; | |||
|
30 | QXYChartSeries* m_series; | |||
|
31 | XYPlotData m_xyPlotData; | |||
|
32 | bool m_dirtyGeometry; | |||
|
33 | }; | |||
|
34 | ||||
|
35 | QCHART_END_NAMESPACE | |||
|
36 | ||||
|
37 | #endif |
@@ -1,9 +1,8 | |||||
1 | TARGET = lineChart |
|
1 | TARGET = lineChart | |
2 | TEMPLATE = app |
|
2 | TEMPLATE = app | |
3 |
|
3 | |||
4 | QT += core gui |
|
4 | QT += core gui | |
5 |
|
5 | |||
6 | CONFIG += charts |
|
6 | CONFIG += charts | |
7 |
|
7 | |||
8 | HEADERS += chartview.h |
|
8 | SOURCES += main.cpp | |
9 | SOURCES += main.cpp chartview.cpp |
|
@@ -1,57 +1,56 | |||||
1 | #include <QApplication> |
|
1 | #include <QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <qchartwidget.h> |
|
3 | #include <qchartwidget.h> | |
|
4 | #include <qxychartseries.h> | |||
4 | #include <qchart.h> |
|
5 | #include <qchart.h> | |
5 | #include "chartview.h" |
|
6 | #include "chartview.h" | |
6 | #include <cmath> |
|
7 | #include <cmath> | |
7 |
|
8 | |||
8 | QCHART_USE_NAMESPACE |
|
9 | QCHART_USE_NAMESPACE | |
9 |
|
10 | |||
10 | #define PI 3.14159265358979 |
|
11 | #define PI 3.14159265358979 | |
11 |
|
12 | |||
12 | int main(int argc, char *argv[]) |
|
13 | int main(int argc, char *argv[]) | |
13 | { |
|
14 | { | |
14 | QApplication a(argc, argv); |
|
15 | QApplication a(argc, argv); | |
15 |
|
16 | |||
16 | QMainWindow window; |
|
17 | QMainWindow window; | |
17 |
|
18 | |||
18 |
QXYSeries* series0 = |
|
19 | QXYChartSeries* series0 = QXYChartSeries::create(); | |
19 | series0->setColor(Qt::blue); |
|
20 | series0->setColor(Qt::blue); | |
20 |
QXYSeries* series1 = |
|
21 | QXYChartSeries* series1 = QXYChartSeries::create(); | |
21 | series1->setColor(Qt::red); |
|
22 | series1->setColor(Qt::red); | |
22 |
QXYSeries* series2 = |
|
23 | QXYChartSeries* series2 = QXYChartSeries::create(); | |
23 | series2->setColor(Qt::gray); |
|
24 | series2->setColor(Qt::gray); | |
24 |
QXYSeries* series3 = |
|
25 | QXYChartSeries* series3 = QXYChartSeries::create(); | |
25 | series3->setColor(Qt::green); |
|
26 | series3->setColor(Qt::green); | |
26 |
|
27 | |||
27 | int numPoints = 100; |
|
28 | int numPoints = 100; | |
28 |
|
29 | |||
29 | for (int x = 0; x < numPoints; ++x) { |
|
30 | for (int x = 0; x < numPoints; ++x) { | |
30 | series0->add(x,0); |
|
31 | series0->add(x,0); | |
31 | series1->add(x, abs(sin(PI/50*x)*100)); |
|
32 | series1->add(x, abs(sin(PI/50*x)*100)); | |
32 | series2->add(x, abs(cos(PI/50*x)*100)); |
|
33 | series2->add(x, abs(cos(PI/50*x)*100)); | |
33 | series3->add(x,100); |
|
34 | series3->add(x,100); | |
34 | } |
|
35 | } | |
35 |
|
36 | |||
36 | QList<QXYSeries*> dataset; |
|
37 | QList<QXYChartSeries*> dataset; | |
37 |
|
38 | |||
38 | qDebug()<<"Series 1:" << *series1; |
|
39 | //qDebug()<<"Series 1:" << *series1; | |
39 | qDebug()<<"Series 2:" << *series2; |
|
40 | //qDebug()<<"Series 2:" << *series2; | |
40 |
|
41 | |||
41 | dataset << series0; |
|
42 | dataset << series0; | |
42 | dataset << series1; |
|
43 | dataset << series1; | |
43 | dataset << series2; |
|
44 | dataset << series2; | |
44 | dataset << series3; |
|
45 | dataset << series3; | |
45 |
|
46 | |||
46 | QChart* chart = QChart::createXYLineChart(dataset); |
|
47 | QChartWidget* chartWidget = new QChartWidget(&window); | |
47 | chart->setMargin(50); |
|
48 | chartWidget->addSeries(series1); | |
48 | QChartWidget* chartWidget = new QChartWidget(); |
|
49 | chartWidget->addSeries(series2); | |
49 | chartWidget->addChart(chart); |
|
|||
50 |
|
50 | |||
51 | ChartView* view = new ChartView(chartWidget,&window); |
|
51 | window.setCentralWidget(chartWidget); | |
52 | window.setCentralWidget(view); |
|
|||
53 | window.resize(400, 300); |
|
52 | window.resize(400, 300); | |
54 | window.show(); |
|
53 | window.show(); | |
55 |
|
54 | |||
56 | return a.exec(); |
|
55 | return a.exec(); | |
57 | } |
|
56 | } |
@@ -1,29 +1,75 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 |
#include " |
|
2 | #include "qchartseries.h" | |
|
3 | #include "xylinechartitem_p.h" | |||
|
4 | #include "axis_p.h" | |||
|
5 | #include "xygrid_p.h" | |||
|
6 | #include <QDebug> | |||
3 |
|
7 | |||
4 | QCHART_BEGIN_NAMESPACE |
|
8 | QCHART_BEGIN_NAMESPACE | |
5 |
|
9 | |||
6 | QChart::QChart(QGraphicsItem* parent):QGraphicsItem(parent), |
|
10 | QChart::QChart(QGraphicsItem* parent):QGraphicsItem(parent), | |
7 | m_marginSize(0) |
|
11 | m_marginSize(0), | |
|
12 | m_axisX(new Axis(this)), | |||
|
13 | m_axisY(new Axis(this)), | |||
|
14 | m_grid(new XYGrid(this)), | |||
|
15 | m_plotDataIndex(0) | |||
8 | { |
|
16 | { | |
9 | // setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
17 | // setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
|
18 | // set axis | |||
|
19 | m_axisY->rotate(90); | |||
|
20 | ||||
|
21 | XYPlotData data; | |||
|
22 | data.m_minX = 0.0; | |||
|
23 | data.m_maxX = 100.0; | |||
|
24 | data.m_minY = 0.0; | |||
|
25 | data.m_maxY = 100.0; | |||
|
26 | data.m_ticksX=4; | |||
|
27 | data.m_ticksY=4; | |||
|
28 | ||||
|
29 | m_plotDataList.clear(); | |||
|
30 | m_plotDataList << data; | |||
|
31 | ||||
|
32 | m_grid->setZValue(10); | |||
|
33 | m_grid->setXYPlotData(m_plotDataList.at(0)); | |||
10 | } |
|
34 | } | |
11 |
|
35 | |||
12 | QChart::~QChart(){} |
|
36 | QChart::~QChart(){} | |
13 |
|
37 | |||
|
38 | QRectF QChart::boundingRect() const | |||
|
39 | { | |||
|
40 | return m_rect; | |||
|
41 | } | |||
14 |
|
42 | |||
15 | QChart* QChart::createXYLineChart(const QList<QXYSeries*>& dataset) |
|
43 | void QChart::addSeries(QChartSeries* series) | |
16 | { |
|
44 | { | |
17 | XYLineChart* chart = new XYLineChart(); |
|
45 | m_series<<series; | |
18 | foreach (const QXYSeries* series,dataset) { |
|
46 | ||
19 | chart->addXYSeries(series); |
|
47 | switch(series->type()) | |
|
48 | { | |||
|
49 | case QChartSeries::LINE: | |||
|
50 | qDebug()<<"xyline added"; | |||
|
51 | XYLineChartItem* item = new XYLineChartItem(reinterpret_cast<QXYChartSeries*>(series),this); | |||
|
52 | item->setXYPlotData(m_plotDataList.at(0)); | |||
|
53 | m_items<<item; | |||
|
54 | break; | |||
20 | } |
|
55 | } | |
21 | return chart; |
|
56 | } | |
|
57 | ||||
|
58 | void QChart::setSize(const QSizeF& size) { | |||
|
59 | //TODO refactor to setGeometry | |||
|
60 | m_rect = QRect(QPoint(0,0),size.toSize()); | |||
|
61 | m_rect.adjust(margin(),margin(),-margin(),-margin()); | |||
|
62 | m_grid->setPos(m_rect.topLeft()); | |||
|
63 | m_grid->setSize(m_rect.size()); | |||
|
64 | foreach(QGraphicsItem* item , m_items) | |||
|
65 | reinterpret_cast<XYLineChartItem*>(item)->setChartSize(m_rect); | |||
|
66 | update(); | |||
|
67 | ||||
22 | } |
|
68 | } | |
23 |
|
69 | |||
24 | void QChart::setMargin(int margin) |
|
70 | void QChart::setMargin(int margin) | |
25 | { |
|
71 | { | |
26 | m_marginSize = margin; |
|
72 | m_marginSize = margin; | |
27 | } |
|
73 | } | |
28 |
|
74 | |||
29 | QCHART_END_NAMESPACE |
|
75 | QCHART_END_NAMESPACE |
@@ -1,40 +1,46 | |||||
1 | #ifndef CHART_H |
|
1 | #ifndef CHART_H | |
2 | #define CHART_H |
|
2 | #define CHART_H | |
3 |
|
3 | |||
4 | #include <qchartconfig.h> |
|
4 | #include <qchartconfig.h> | |
5 | #include <qxyseries.h> |
|
5 | //TODO: temporary class | |
|
6 | #include <xyplotdata_p.h> | |||
6 | #include <QGraphicsItem> |
|
7 | #include <QGraphicsItem> | |
7 |
|
8 | |||
8 | QCHART_BEGIN_NAMESPACE |
|
9 | QCHART_BEGIN_NAMESPACE | |
9 |
|
10 | |||
|
11 | class Axis; | |||
|
12 | class XYGrid; | |||
|
13 | class QChartSeries; | |||
|
14 | ||||
10 | class QCHART_EXPORT QChart : public QGraphicsItem |
|
15 | class QCHART_EXPORT QChart : public QGraphicsItem | |
11 | { |
|
16 | { | |
12 | public: |
|
|||
13 | enum DataSeriesType { |
|
|||
14 | DataSeriesTypeLine = 0, |
|
|||
15 | DataSeriesTypeArea, |
|
|||
16 | DataSeriesTypeBar, |
|
|||
17 | DataSeriesTypePie, |
|
|||
18 | DataSeriesTypeScatter, |
|
|||
19 | DataSeriesTypeSpline |
|
|||
20 | }; |
|
|||
21 |
|
||||
22 | protected: |
|
|||
23 | QChart(QGraphicsItem* parent =0); |
|
|||
24 |
|
17 | |||
25 | public: |
|
18 | public: | |
|
19 | QChart(QGraphicsItem* parent = 0); | |||
26 | virtual ~QChart(); |
|
20 | virtual ~QChart(); | |
27 |
|
21 | |||
28 | static QChart* createXYLineChart(const QList<QXYSeries*>& dataset); |
|
22 | //from QGraphicsItem | |
|
23 | virtual QRectF boundingRect() const; | |||
|
24 | virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){}; | |||
|
25 | ||||
|
26 | void addSeries(QChartSeries* series); | |||
29 |
|
27 | |||
30 |
virtual void setSize(const QSizeF& rect) |
|
28 | virtual void setSize(const QSizeF& rect); | |
31 | void setMargin(int margin); |
|
29 | void setMargin(int margin); | |
32 | int margin() const { return m_marginSize;} |
|
30 | int margin() const { return m_marginSize;} | |
33 |
|
31 | |||
34 | private: |
|
32 | private: | |
|
33 | QRect m_rect; | |||
|
34 | QList<const QChartSeries*> m_series; | |||
|
35 | Axis* m_axisX; | |||
|
36 | Axis* m_axisY; | |||
|
37 | XYGrid* m_grid; | |||
|
38 | QList<XYPlotData> m_plotDataList; | |||
|
39 | QList<QGraphicsItem*> m_items; | |||
|
40 | int m_plotDataIndex; | |||
35 | int m_marginSize; |
|
41 | int m_marginSize; | |
36 | }; |
|
42 | }; | |
37 |
|
43 | |||
38 | QCHART_END_NAMESPACE |
|
44 | QCHART_END_NAMESPACE | |
39 |
|
45 | |||
40 | #endif |
|
46 | #endif |
@@ -1,53 +1,65 | |||||
1 | #include "qchartwidget.h" |
|
1 | #include "qchartwidget.h" | |
2 |
#include "q |
|
2 | #include "qchartseries.h" | |
3 | #include "xylinechart_p.h" |
|
|||
4 | #include <QGraphicsView> |
|
3 | #include <QGraphicsView> | |
5 | #include <QGraphicsScene> |
|
4 | #include <QGraphicsScene> | |
|
5 | #include <QResizeEvent> | |||
6 |
|
6 | |||
7 | QCHART_BEGIN_NAMESPACE |
|
7 | QCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | class QChartWidgetPrivate |
|
9 | class QChartWidgetPrivate | |
10 | { |
|
10 | { | |
11 | public: |
|
11 | public: | |
12 |
QChartWidgetPrivate(QWidget *parent) : |
|
12 | QChartWidgetPrivate(QChartWidget *parent) : | |
|
13 | m_view(0), | |||
|
14 | m_scene(0), | |||
|
15 | m_chart(0), | |||
|
16 | q_ptr( parent ) | |||
|
17 | { | |||
13 | m_scene = new QGraphicsScene(); |
|
18 | m_scene = new QGraphicsScene(); | |
14 |
m_view = new QGraphicsView( |
|
19 | m_view = new QGraphicsView(parent); | |
15 |
m_view-> |
|
20 | m_view->setScene(m_scene); | |
16 | m_view->show(); |
|
21 | m_chart = new QChart(); | |
|
22 | m_scene->addItem(m_chart); | |||
17 | } |
|
23 | } | |
|
24 | ||||
18 | ~QChartWidgetPrivate() { |
|
25 | ~QChartWidgetPrivate() { | |
19 | delete m_view; |
|
|||
20 | delete m_scene; |
|
|||
21 | } |
|
26 | } | |
22 |
|
27 | |||
23 | QGraphicsView *m_view; |
|
28 | QGraphicsView *m_view; | |
24 | QGraphicsScene *m_scene; |
|
29 | QGraphicsScene *m_scene; | |
25 | QChart* m_chart; |
|
30 | QChart* m_chart; | |
|
31 | QChartWidget * const q_ptr; | |||
|
32 | Q_DECLARE_PUBLIC(QChartWidget); | |||
26 | }; |
|
33 | }; | |
27 |
|
34 | |||
28 | QChartWidget::QChartWidget(QWidget *parent) : |
|
35 | QChartWidget::QChartWidget(QWidget *parent) : | |
29 | QWidget(parent), |
|
36 | QWidget(parent), | |
30 | d(new QChartWidgetPrivate(this)) |
|
37 | d_ptr(new QChartWidgetPrivate(this)) | |
31 | { |
|
38 | { | |
32 | setMinimumSize(d->m_view->size()); |
|
39 | ||
33 | } |
|
40 | } | |
34 |
|
41 | |||
35 | QChartWidget::~QChartWidget() |
|
42 | QChartWidget::~QChartWidget() | |
36 | { |
|
43 | { | |
37 | delete d; |
|
44 | delete d_ptr; | |
38 | } |
|
45 | } | |
39 |
|
46 | |||
40 | void QChartWidget::addDataSeries( |
|
47 | void QChartWidget::resizeEvent(QResizeEvent *event) | |
41 | QChart::DataSeriesType dataSeriesType, |
|
|||
42 | QList<QXYSeries*> dataset) |
|
|||
43 | { |
|
48 | { | |
44 | // TODO: implement management of several data series of different types |
|
49 | Q_D(QChartWidget); | |
|
50 | d->m_view->resize(size().width(),size().height()); | |||
|
51 | d->m_scene->setSceneRect(0,0,size().width(),size().height()); | |||
|
52 | d->m_chart->setSize(size()); | |||
|
53 | QWidget::resizeEvent(event); | |||
|
54 | } | |||
45 |
|
55 | |||
46 | d->m_chart = QChart::createXYLineChart(dataset); |
|
56 | ||
47 | d->m_scene->addItem(d->m_chart); |
|
57 | void QChartWidget::addSeries(QChartSeries* series) | |
48 | d->m_chart->setSize(this->size()); |
|
58 | { | |
|
59 | Q_D(QChartWidget); | |||
|
60 | d->m_chart->addSeries(series); | |||
49 | } |
|
61 | } | |
50 |
|
62 | |||
51 | #include "moc_qchartwidget.cpp" |
|
63 | #include "moc_qchartwidget.cpp" | |
52 |
|
64 | |||
53 | QCHART_END_NAMESPACE |
|
65 | QCHART_END_NAMESPACE |
@@ -1,36 +1,35 | |||||
1 | #ifndef QCHARTWIDGET_H |
|
1 | #ifndef QCHARTWIDGET_H | |
2 | #define QCHARTWIDGET_H |
|
2 | #define QCHARTWIDGET_H | |
3 |
|
3 | |||
4 | #include "qchartconfig.h" |
|
4 | #include "qchartconfig.h" | |
5 | #include "qchart.h" |
|
5 | #include "qchart.h" | |
6 | #include <QWidget> |
|
6 | #include <QWidget> | |
7 |
|
7 | |||
8 | QCHART_BEGIN_NAMESPACE |
|
8 | QCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 |
class Q |
|
10 | class QChartSeries; | |
11 | class QChartWidgetPrivate; |
|
11 | class QChartWidgetPrivate; | |
12 |
|
12 | |||
13 | class QCHART_EXPORT QChartWidget : public QWidget |
|
13 | class QCHART_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 | // TODO: replace QXYSeries list with a charts data API |
|
|||
20 | // TODO: return QChartDataSeries |
|
|||
21 | void addDataSeries(QChart::DataSeriesType dataSeriesType, QList<QXYSeries*> dataset); |
|
|||
22 |
|
19 | |||
23 | signals: |
|
20 | //implement from QWidget | |
|
21 | void resizeEvent(QResizeEvent *event); | |||
24 |
|
22 | |||
25 | public slots: |
|
23 | void addSeries(QChartSeries* series); | |
|
24 | protected: | |||
|
25 | QChartWidgetPrivate * const d_ptr; | |||
26 |
|
26 | |||
27 | private: |
|
27 | private: | |
28 | friend class QChartWidgetPrivate; |
|
|||
29 | Q_DISABLE_COPY(QChartWidget) |
|
28 | Q_DISABLE_COPY(QChartWidget) | |
30 |
|
|
29 | Q_DECLARE_PRIVATE(QChartWidget) | |
31 | QChartWidgetPrivate * const d; |
|
30 | ||
32 | }; |
|
31 | }; | |
33 |
|
32 | |||
34 | QCHART_END_NAMESPACE |
|
33 | QCHART_END_NAMESPACE | |
35 |
|
34 | |||
36 | #endif // QCHARTWIDGET_H |
|
35 | #endif // QCHARTWIDGET_H |
@@ -1,45 +1,46 | |||||
1 | TARGET = QChart |
|
1 | TARGET = QChart | |
2 | TEMPLATE = lib |
|
2 | TEMPLATE = lib | |
3 | QT += core \ |
|
3 | QT += core \ | |
4 | gui |
|
4 | gui | |
5 | CONFIG += debug_and_release |
|
5 | CONFIG += debug_and_release | |
6 | CONFIG(debug, debug|release):TARGET = QChartd |
|
6 | CONFIG(debug, debug|release):TARGET = QChartd | |
7 |
|
7 | |||
8 | SOURCES += \ |
|
8 | SOURCES += \ | |
9 |
xylinechart/q |
|
9 | xylinechart/qxychartseries.cpp \ | |
10 |
xylinechart/ |
|
10 | xylinechart/xylinechartitem.cpp \ | |
11 | xylinechart/xylinechart.cpp \ |
|
|||
12 | xylinechart/xygrid.cpp \ |
|
11 | xylinechart/xygrid.cpp \ | |
13 | xylinechart/xyplotdata.cpp \ |
|
12 | xylinechart/xyplotdata.cpp \ | |
14 | qchart.cpp \ |
|
13 | qchart.cpp \ | |
15 | axis.cpp \ |
|
14 | axis.cpp \ | |
16 | qchartwidget.cpp |
|
15 | qchartwidget.cpp | |
17 |
|
16 | |||
18 | PRIVATE_HEADERS += \ |
|
17 | PRIVATE_HEADERS += \ | |
19 | xylinechart/xylinechart_p.h \ |
|
18 | xylinechart/xylinechartitem_p.h \ | |
20 | xylinechart/xygrid_p.h \ |
|
19 | xylinechart/xygrid_p.h \ | |
21 | xylinechart/xyplotdata_p.h \ |
|
|||
22 | axis_p.h |
|
20 | axis_p.h | |
|
21 | ||||
23 | PUBLIC_HEADERS += \ |
|
22 | PUBLIC_HEADERS += \ | |
24 |
|
|
23 | qchartseries.h \ | |
25 | xylinechart/qchartgraphicswidget.h \ |
|
|||
26 | qchart.h \ |
|
24 | qchart.h \ | |
27 | qchartwidget.h \ |
|
25 | qchartwidget.h \ | |
28 | qchartconfig.h |
|
26 | qchartconfig.h \ | |
|
27 | xylinechart/qxychartseries.h \ | |||
|
28 | xylinechart/xyplotdata_p.h # to be removed | |||
|
29 | ||||
29 | HEADERS += $$PUBLIC_HEADERS |
|
30 | HEADERS += $$PUBLIC_HEADERS | |
30 | HEADERS += $$PRIVATE_HEADERS |
|
31 | HEADERS += $$PRIVATE_HEADERS | |
31 |
|
32 | |||
32 | INCLUDEPATH += xylinechart \ |
|
33 | INCLUDEPATH += xylinechart \ | |
33 | . |
|
34 | . | |
34 |
|
35 | |||
35 | OBJECTS_DIR = ../build/lib |
|
36 | OBJECTS_DIR = ../build/lib | |
36 | MOC_DIR = ../build/lib |
|
37 | MOC_DIR = ../build/lib | |
37 | UI_DIR = ../build/lib |
|
38 | UI_DIR = ../build/lib | |
38 | RCC_DIR = ../build/lib |
|
39 | RCC_DIR = ../build/lib | |
39 | DEFINES += QCHART_LIBRARY |
|
40 | DEFINES += QCHART_LIBRARY | |
40 |
|
41 | |||
41 | public_headers.path = $$[QT_INSTALL_HEADERS]/QCharts |
|
42 | public_headers.path = $$[QT_INSTALL_HEADERS]/QCharts | |
42 | public_headers.files = $$PUBLIC_HEADERS |
|
43 | public_headers.files = $$PUBLIC_HEADERS | |
43 | target.path = $$[QT_INSTALL_LIBS] |
|
44 | target.path = $$[QT_INSTALL_LIBS] | |
44 | INSTALLS += target \ |
|
45 | INSTALLS += target \ | |
45 | public_headers |
|
46 | public_headers |
@@ -1,63 +1,68 | |||||
1 | #include "qxyseries.h" |
|
1 | #include "qxychartseries.h" | |
2 |
|
2 | |||
3 | QCHART_BEGIN_NAMESPACE |
|
3 | QCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | QXYSeries::QXYSeries(): |
|
5 | QXYChartSeries::QXYChartSeries(QObject* parent):QChartSeries(parent), | |
6 | m_color(Qt::black) |
|
6 | m_color(Qt::black) | |
7 | { |
|
7 | { | |
8 | } |
|
8 | } | |
9 |
|
9 | |||
10 | QXYSeries::~QXYSeries() |
|
10 | QXYChartSeries::~QXYChartSeries() | |
11 | { |
|
11 | { | |
12 | } |
|
12 | } | |
13 |
|
13 | |||
|
14 | QXYChartSeries* QXYChartSeries::create(QObject* parent) | |||
|
15 | { | |||
|
16 | //TODO: here we take QChartData when it is ready | |||
|
17 | // return null if malformed; | |||
|
18 | return new QXYChartSeries(parent); | |||
|
19 | } | |||
14 |
|
20 | |||
15 | void QXYSeries::setColor(const QColor& color) |
|
21 | void QXYChartSeries::setColor(const QColor& color) | |
16 | { |
|
22 | { | |
17 | m_color = color; |
|
23 | m_color = color; | |
18 | } |
|
24 | } | |
19 |
|
25 | |||
20 |
|
26 | void QXYChartSeries::add(qreal x,qreal y) | ||
21 | void QXYSeries::add(qreal x,qreal y) |
|
|||
22 | { |
|
27 | { | |
23 | m_x<<x; |
|
28 | m_x<<x; | |
24 | m_y<<y; |
|
29 | m_y<<y; | |
25 | } |
|
30 | } | |
26 |
|
31 | |||
27 | void QXYSeries::clear() |
|
32 | void QXYChartSeries::clear() | |
28 | { |
|
33 | { | |
29 | m_x.clear(); |
|
34 | m_x.clear(); | |
30 | m_y.clear(); |
|
35 | m_y.clear(); | |
31 | } |
|
36 | } | |
32 |
|
37 | |||
33 | qreal QXYSeries::x(int pos) const |
|
38 | qreal QXYChartSeries::x(int pos) const | |
34 | { |
|
39 | { | |
35 | return m_x.at(pos); |
|
40 | return m_x.at(pos); | |
36 | } |
|
41 | } | |
37 |
|
42 | |||
38 | qreal QXYSeries::y(int pos) const |
|
43 | qreal QXYChartSeries::y(int pos) const | |
39 | { |
|
44 | { | |
40 | return m_y.at(pos); |
|
45 | return m_y.at(pos); | |
41 | } |
|
46 | } | |
42 |
|
47 | |||
43 | int QXYSeries::count() const |
|
48 | int QXYChartSeries::count() const | |
44 | { |
|
49 | { | |
45 | Q_ASSERT(m_x.size() == m_y.size()); |
|
50 | Q_ASSERT(m_x.size() == m_y.size()); | |
46 |
|
51 | |||
47 | return m_x.size(); |
|
52 | return m_x.size(); | |
48 |
|
53 | |||
49 | } |
|
54 | } | |
50 |
|
55 | |||
51 | QDebug operator<< (QDebug debug, const QXYSeries series) |
|
56 | QDebug operator<< (QDebug debug, const QXYChartSeries series) | |
52 | { |
|
57 | { | |
53 | Q_ASSERT(series.m_x.size() == series.m_y.size()); |
|
58 | Q_ASSERT(series.m_x.size() == series.m_y.size()); | |
54 |
|
59 | |||
55 | int size = series.m_x.size(); |
|
60 | int size = series.m_x.size(); | |
56 |
|
61 | |||
57 | for (int i=0;i<size;i++) { |
|
62 | for (int i=0;i<size;i++) { | |
58 | debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") "; |
|
63 | debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") "; | |
59 | } |
|
64 | } | |
60 | return debug.space(); |
|
65 | return debug.space(); | |
61 | } |
|
66 | } | |
62 |
|
67 | |||
63 | QCHART_END_NAMESPACE |
|
68 | QCHART_END_NAMESPACE |
@@ -1,33 +1,40 | |||||
1 | #ifndef QXYSERIES_H_ |
|
1 | #ifndef QXYSERIES_H_ | |
2 | #define QXYSERIES_H_ |
|
2 | #define QXYSERIES_H_ | |
3 |
|
3 | |||
4 | #include "qchartconfig.h" |
|
4 | #include "qchartconfig.h" | |
|
5 | #include "qchartseries.h" | |||
5 | #include <QDebug> |
|
6 | #include <QDebug> | |
6 | #include <QColor> |
|
7 | #include <QColor> | |
7 |
|
8 | |||
8 | QCHART_BEGIN_NAMESPACE |
|
9 | QCHART_BEGIN_NAMESPACE | |
9 |
|
10 | |||
10 | class QCHART_EXPORT QXYSeries |
|
11 | class QCHART_EXPORT QXYChartSeries : public QChartSeries | |
11 | { |
|
12 | { | |
|
13 | private: | |||
|
14 | QXYChartSeries(QObject* parent=0); | |||
12 | public: |
|
15 | public: | |
13 | QXYSeries(); |
|
16 | virtual ~QXYChartSeries(); | |
14 | virtual ~QXYSeries(); |
|
17 | ||
|
18 | //implemented from QChartSeries | |||
|
19 | static QXYChartSeries* create(QObject* parent=0); | |||
|
20 | virtual QChartSeriesType type() const { return QChartSeries::LINE;}; | |||
|
21 | ||||
15 | void add(qreal x, qreal y); |
|
22 | void add(qreal x, qreal y); | |
16 | void clear(); |
|
23 | void clear(); | |
17 | void setColor(const QColor& color); |
|
24 | void setColor(const QColor& color); | |
18 | const QColor& color() const { return m_color;} |
|
25 | const QColor& color() const { return m_color;} | |
19 | int count() const; |
|
26 | int count() const; | |
20 | qreal x(int pos) const; |
|
27 | qreal x(int pos) const; | |
21 | qreal y(int pos) const; |
|
28 | qreal y(int pos) const; | |
22 | friend QDebug operator<< (QDebug d, const QXYSeries series); |
|
29 | friend QDebug operator<< (QDebug d, const QXYChartSeries series); | |
23 |
|
30 | |||
24 | private: |
|
31 | private: | |
25 | QColor m_color; |
|
32 | QColor m_color; | |
26 | QList<qreal> m_x; |
|
33 | QList<qreal> m_x; | |
27 | QList<qreal> m_y; |
|
34 | QList<qreal> m_y; | |
28 |
|
35 | |||
29 | }; |
|
36 | }; | |
30 |
|
37 | |||
31 | QCHART_END_NAMESPACE |
|
38 | QCHART_END_NAMESPACE | |
32 |
|
39 | |||
33 | #endif |
|
40 | #endif |
@@ -1,67 +1,70 | |||||
1 | #include "xygrid_p.h" |
|
1 | #include "xygrid_p.h" | |
2 | #include "xylinechart_p.h" |
|
|||
3 | #include <QPainter> |
|
2 | #include <QPainter> | |
|
3 | #include <QDebug> | |||
4 |
|
4 | |||
5 | QCHART_BEGIN_NAMESPACE |
|
5 | QCHART_BEGIN_NAMESPACE | |
6 |
|
6 | |||
7 |
XYGrid::XYGrid( |
|
7 | XYGrid::XYGrid(QGraphicsItem* parent):QGraphicsItem(parent) | |
8 | m_chart(chart) |
|
|||
9 | { |
|
8 | { | |
10 | } |
|
9 | } | |
11 |
|
10 | |||
12 | XYGrid::~XYGrid() |
|
11 | XYGrid::~XYGrid() | |
13 | { |
|
12 | { | |
14 | // TODO Auto-generated destructor stub |
|
13 | // TODO Auto-generated destructor stub | |
15 | } |
|
14 | } | |
16 |
|
15 | |||
17 |
void XYGrid::setSize(const QSizeF& size) |
|
16 | void XYGrid::setSize(const QSizeF& size) | |
|
17 | { | |||
18 | m_rect.setSize(size.toSize()); |
|
18 | m_rect.setSize(size.toSize()); | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
|
21 | void XYGrid::setXYPlotData(const XYPlotData& xyPlotData) | |||
|
22 | { | |||
|
23 | m_xyPlotData = xyPlotData; | |||
|
24 | } | |||
21 |
|
25 | |||
22 | QRectF XYGrid::boundingRect() const |
|
26 | QRectF XYGrid::boundingRect() const | |
23 | { |
|
27 | { | |
24 | return m_rect; |
|
28 | return m_rect; | |
25 | } |
|
29 | } | |
26 |
|
30 | |||
27 | void XYGrid::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget) |
|
31 | void XYGrid::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget) | |
28 | { |
|
32 | { | |
29 | if (!m_rect.isValid()) |
|
|||
30 | return; |
|
|||
31 |
|
33 | |||
32 | const XYPlotData& plotData = m_chart->xyPlotData(); |
|
34 | if (!m_rect.isValid()) | |
|
35 | return; | |||
33 |
|
36 | |||
34 |
|
|
37 | const qreal deltaX = (m_rect.width() -1) / m_xyPlotData.ticksX(); | |
35 |
|
|
38 | const qreal deltaY = (m_rect.height() - 1) / m_xyPlotData.ticksY(); | |
36 |
|
39 | |||
37 |
|
|
40 | for (int i = 0; i <= m_xyPlotData.ticksX(); ++i) { | |
38 |
|
41 | |||
39 |
|
|
42 | int x = i * deltaX + m_rect.left(); | |
40 |
|
|
43 | qreal label = m_xyPlotData.m_minX + (i * m_xyPlotData.spanX() | |
41 |
|
|
44 | / m_xyPlotData.ticksX()); | |
42 |
|
|
45 | painter->drawLine(x, m_rect.top()+1, x, m_rect.bottom()); | |
43 |
|
|
46 | //painter->drawLine(x, m_rect.bottom(), x, m_rect.bottom() + 5); | |
44 |
|
47 | |||
45 |
|
|
48 | painter->drawText(x - 50, m_rect.bottom() + 5, 100, 20, | |
46 |
|
|
49 | Qt::AlignHCenter | Qt::AlignTop, | |
47 |
|
|
50 | QString::number(label)); | |
48 | } |
|
51 | } | |
49 |
|
52 | |||
50 |
|
|
53 | for (int j = 0; j <= m_xyPlotData.ticksY(); ++j) { | |
51 |
|
54 | |||
52 |
|
|
55 | int y = j * -deltaY + m_rect.bottom(); | |
53 |
|
|
56 | qreal label = m_xyPlotData.m_minY + (j * m_xyPlotData.spanY() | |
54 |
|
|
57 | / m_xyPlotData.ticksY()); | |
55 |
|
58 | |||
56 |
|
|
59 | painter->drawLine(m_rect.left(), y, m_rect.right()-1, y); | |
57 |
|
|
60 | //painter->drawLine(m_rect.left() - 5, y, m_rect.left(), y); | |
58 |
|
|
61 | //TODO : margin = 50 ; | |
59 |
|
|
62 | painter->drawText(m_rect.left() - 50, y - 10, 50 - 5, 20, | |
60 |
|
|
63 | Qt::AlignRight | Qt::AlignVCenter, | |
61 |
|
|
64 | QString::number(label)); | |
62 | } |
|
65 | } | |
63 |
|
66 | |||
64 |
|
|
67 | //painter->drawRect(m_rect.adjusted(0, 0, -1, -1)); | |
65 | } |
|
68 | } | |
66 |
|
69 | |||
67 | QCHART_END_NAMESPACE |
|
70 | QCHART_END_NAMESPACE |
@@ -1,31 +1,31 | |||||
1 | #ifndef XYGRID_H_ |
|
1 | #ifndef XYGRID_H_ | |
2 | #define XYGRID_H_ |
|
2 | #define XYGRID_H_ | |
3 |
|
3 | |||
4 | #include <qchartconfig.h> |
|
4 | #include <qchartconfig.h> | |
|
5 | #include <xyplotdata_p.h> | |||
5 | #include <QGraphicsItem> |
|
6 | #include <QGraphicsItem> | |
6 |
|
7 | |||
7 | QCHART_BEGIN_NAMESPACE |
|
8 | QCHART_BEGIN_NAMESPACE | |
8 |
|
9 | |||
9 | class XYPlotData; |
|
|||
10 | class XYLineChart; |
|
|||
11 |
|
||||
12 | class XYGrid : public QGraphicsItem |
|
10 | class XYGrid : public QGraphicsItem | |
13 | { |
|
11 | { | |
14 | public: |
|
12 | public: | |
15 |
XYGrid( |
|
13 | XYGrid(QGraphicsItem* parent = 0); | |
16 | virtual ~XYGrid(); |
|
14 | virtual ~XYGrid(); | |
17 |
|
15 | |||
18 | //from QGraphicsItem |
|
16 | //from QGraphicsItem | |
19 | virtual QRectF boundingRect() const; |
|
17 | virtual QRectF boundingRect() const; | |
20 | virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
18 | virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
21 |
|
19 | |||
|
20 | //TODO: this is just temporary interface | |||
|
21 | void setXYPlotData(const XYPlotData& xyPlotData); | |||
22 | void setSize(const QSizeF& rect); |
|
22 | void setSize(const QSizeF& rect); | |
23 |
|
23 | |||
24 | private: |
|
24 | private: | |
25 | QRectF m_rect; |
|
25 | QRectF m_rect; | |
26 | const XYLineChart* const m_chart; |
|
26 | XYPlotData m_xyPlotData; | |
27 | }; |
|
27 | }; | |
28 |
|
28 | |||
29 | QCHART_END_NAMESPACE |
|
29 | QCHART_END_NAMESPACE | |
30 |
|
30 | |||
31 | #endif /* XYGRID_H_ */ |
|
31 | #endif /* XYGRID_H_ */ |
@@ -1,222 +1,222 | |||||
1 | #include "mainwidget.h" |
|
1 | #include "mainwidget.h" | |
2 | #include "dataseriedialog.h" |
|
2 | #include "dataseriedialog.h" | |
3 | #include <qxyseries.h> |
|
3 | #include <qxyseries.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 | QCHART_USE_NAMESPACE |
|
16 | QCHART_USE_NAMESPACE | |
17 |
|
17 | |||
18 | MainWidget::MainWidget(QWidget *parent) : |
|
18 | MainWidget::MainWidget(QWidget *parent) : | |
19 | QWidget(parent) |
|
19 | QWidget(parent) | |
20 | { |
|
20 | { | |
21 | m_chartWidget = new QChartWidget(this); |
|
21 | m_chartWidget = new QChartWidget(this); | |
22 | // m_chartWidget->resize(QSize(200,200)); |
|
22 | // m_chartWidget->resize(QSize(200,200)); | |
23 | // m_chartWidget->setColor(Qt::red); |
|
23 | // m_chartWidget->setColor(Qt::red); | |
24 |
|
24 | |||
25 | QPushButton *addSeriesButton = new QPushButton("Add series"); |
|
25 | QPushButton *addSeriesButton = new QPushButton("Add series"); | |
26 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
26 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); | |
27 |
|
27 | |||
28 | // Chart background |
|
28 | // Chart background | |
29 | QComboBox *backgroundCombo = new QComboBox(this); |
|
29 | QComboBox *backgroundCombo = new QComboBox(this); | |
30 | backgroundCombo->addItem("None"); |
|
30 | backgroundCombo->addItem("None"); | |
31 | backgroundCombo->addItem("TODO Grid"); |
|
31 | backgroundCombo->addItem("TODO Grid"); | |
32 | backgroundCombo->addItem("TODO Image"); |
|
32 | backgroundCombo->addItem("TODO Image"); | |
33 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
33 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), | |
34 | this, SLOT(backgroundChanged(int))); |
|
34 | this, SLOT(backgroundChanged(int))); | |
35 |
|
35 | |||
36 | // Axis |
|
36 | // Axis | |
37 | // TODO: multiple axes? |
|
37 | // TODO: multiple axes? | |
38 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
38 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); | |
39 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
39 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); | |
40 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
40 | // Allow setting also non-sense values (like -2147483648 and 2147483647) | |
41 | m_xMinSpin = new QSpinBox(); |
|
41 | m_xMinSpin = new QSpinBox(); | |
42 | m_xMinSpin->setMinimum(INT_MIN); |
|
42 | m_xMinSpin->setMinimum(INT_MIN); | |
43 | m_xMinSpin->setMaximum(INT_MAX); |
|
43 | m_xMinSpin->setMaximum(INT_MAX); | |
44 | m_xMinSpin->setValue(0); |
|
44 | m_xMinSpin->setValue(0); | |
45 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
45 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); | |
46 | m_xMaxSpin = new QSpinBox(); |
|
46 | m_xMaxSpin = new QSpinBox(); | |
47 | m_xMaxSpin->setMinimum(INT_MIN); |
|
47 | m_xMaxSpin->setMinimum(INT_MIN); | |
48 | m_xMaxSpin->setMaximum(INT_MAX); |
|
48 | m_xMaxSpin->setMaximum(INT_MAX); | |
49 | m_xMaxSpin->setValue(10); |
|
49 | m_xMaxSpin->setValue(10); | |
50 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
50 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); | |
51 | m_yMinSpin = new QSpinBox(); |
|
51 | m_yMinSpin = new QSpinBox(); | |
52 | m_yMinSpin->setMinimum(INT_MIN); |
|
52 | m_yMinSpin->setMinimum(INT_MIN); | |
53 | m_yMinSpin->setMaximum(INT_MAX); |
|
53 | m_yMinSpin->setMaximum(INT_MAX); | |
54 | m_yMinSpin->setValue(0); |
|
54 | m_yMinSpin->setValue(0); | |
55 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
55 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); | |
56 | m_yMaxSpin = new QSpinBox(); |
|
56 | m_yMaxSpin = new QSpinBox(); | |
57 | m_yMaxSpin->setMinimum(INT_MIN); |
|
57 | m_yMaxSpin->setMinimum(INT_MIN); | |
58 | m_yMaxSpin->setMaximum(INT_MAX); |
|
58 | m_yMaxSpin->setMaximum(INT_MAX); | |
59 | m_yMaxSpin->setValue(10); |
|
59 | m_yMaxSpin->setValue(10); | |
60 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
60 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); | |
61 |
|
61 | |||
62 | QGridLayout *grid = new QGridLayout(); |
|
62 | QGridLayout *grid = new QGridLayout(); | |
63 | QHBoxLayout *hbox = new QHBoxLayout(); |
|
63 | QHBoxLayout *hbox = new QHBoxLayout(); | |
64 | //grid->addWidget(new QLabel("Add series:"), 0, 0); |
|
64 | //grid->addWidget(new QLabel("Add series:"), 0, 0); | |
65 | grid->addWidget(addSeriesButton, 0, 1); |
|
65 | grid->addWidget(addSeriesButton, 0, 1); | |
66 | grid->addWidget(new QLabel("Background:"), 2, 0); |
|
66 | grid->addWidget(new QLabel("Background:"), 2, 0); | |
67 | grid->addWidget(backgroundCombo, 2, 1); |
|
67 | grid->addWidget(backgroundCombo, 2, 1); | |
68 | grid->addWidget(m_autoScaleCheck, 3, 0); |
|
68 | grid->addWidget(m_autoScaleCheck, 3, 0); | |
69 | grid->addWidget(new QLabel("x min:"), 4, 0); |
|
69 | grid->addWidget(new QLabel("x min:"), 4, 0); | |
70 | grid->addWidget(m_xMinSpin, 4, 1); |
|
70 | grid->addWidget(m_xMinSpin, 4, 1); | |
71 | grid->addWidget(new QLabel("x max:"), 5, 0); |
|
71 | grid->addWidget(new QLabel("x max:"), 5, 0); | |
72 | grid->addWidget(m_xMaxSpin, 5, 1); |
|
72 | grid->addWidget(m_xMaxSpin, 5, 1); | |
73 | grid->addWidget(new QLabel("y min:"), 6, 0); |
|
73 | grid->addWidget(new QLabel("y min:"), 6, 0); | |
74 | grid->addWidget(m_yMinSpin, 6, 1); |
|
74 | grid->addWidget(m_yMinSpin, 6, 1); | |
75 | grid->addWidget(new QLabel("y max:"), 7, 0); |
|
75 | grid->addWidget(new QLabel("y max:"), 7, 0); | |
76 | grid->addWidget(m_yMaxSpin, 7, 1); |
|
76 | grid->addWidget(m_yMaxSpin, 7, 1); | |
77 | // add row with empty label to make all the other rows static |
|
77 | // add row with empty label to make all the other rows static | |
78 | grid->addWidget(new QLabel(""), 8, 0); |
|
78 | grid->addWidget(new QLabel(""), 8, 0); | |
79 | grid->setRowStretch(8, 1); |
|
79 | grid->setRowStretch(8, 1); | |
80 |
|
80 | |||
81 | hbox->addLayout(grid); |
|
81 | hbox->addLayout(grid); | |
82 | hbox->addWidget(m_chartWidget); |
|
82 | hbox->addWidget(m_chartWidget); | |
83 | hbox->setStretch(1, 1); |
|
83 | hbox->setStretch(1, 1); | |
84 |
|
84 | |||
85 | setLayout(hbox); |
|
85 | setLayout(hbox); | |
86 |
|
86 | |||
87 | m_autoScaleCheck->setChecked(true); |
|
87 | m_autoScaleCheck->setChecked(true); | |
88 | chartTypeChanged(4); |
|
88 | chartTypeChanged(4); | |
89 | testDataChanged(0); |
|
89 | testDataChanged(0); | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | void MainWidget::addSeries() |
|
92 | void MainWidget::addSeries() | |
93 | { |
|
93 | { | |
94 | DataSerieDialog dialog(this); |
|
94 | DataSerieDialog dialog(this); | |
95 | connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString))); |
|
95 | connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString))); | |
96 | dialog.exec(); |
|
96 | dialog.exec(); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | void MainWidget::addSeries(QString series, QString data) |
|
99 | void MainWidget::addSeries(QString series, QString data) | |
100 | { |
|
100 | { | |
101 | qDebug() << "addSeries: " << series << " data: " << data; |
|
101 | qDebug() << "addSeries: " << series << " data: " << data; | |
102 |
|
102 | |||
103 | QXYSeries* series0 = new QXYSeries(); |
|
103 | QXYChartSeries* series0 = new QXYChartSeries(); | |
104 |
|
104 | |||
105 | if (data == "linear") { |
|
105 | if (data == "linear") { | |
106 | // TODO |
|
106 | // TODO | |
107 | } else if (data == "SIN") { |
|
107 | } else if (data == "SIN") { | |
108 | series0->setColor(Qt::blue); |
|
108 | series0->setColor(Qt::blue); | |
109 | for (int x = 0; x < 100; x++) |
|
109 | for (int x = 0; x < 100; x++) | |
110 | series0->add(x, abs(sin(3.14159265358979 / 50 * x) * 100)); |
|
110 | series0->add(x, abs(sin(3.14159265358979 / 50 * x) * 100)); | |
111 | QList<QXYSeries*> dataset; |
|
111 | QList<QXYChartSeries*> dataset; | |
112 | dataset << series0; |
|
112 | dataset << series0; | |
113 | } else if (data == "SIN + random") { |
|
113 | } else if (data == "SIN + random") { | |
114 | series0->setColor(Qt::blue); |
|
114 | series0->setColor(Qt::blue); | |
115 | for (qreal x = 0; x < 100; x += 0.1) { |
|
115 | for (qreal x = 0; x < 100; x += 0.1) { | |
116 | series0->add(x + (rand() % 5), |
|
116 | series0->add(x + (rand() % 5), | |
117 | abs(sin(3.14159265358979 / 50 * x) * 100) + (rand() % 5)); |
|
117 | abs(sin(3.14159265358979 / 50 * x) * 100) + (rand() % 5)); | |
118 | } |
|
118 | } | |
119 | } else { |
|
119 | } else { | |
120 | // TODO: check if data has a valid file name |
|
120 | // TODO: check if data has a valid file name | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | QList<QXYSeries*> dataset; |
|
123 | QList<QXYChartSeries*> dataset; | |
124 | dataset << series0; |
|
124 | dataset << series0; | |
125 |
|
125 | |||
126 | if (series == "Scatter") { |
|
126 | if (series == "Scatter") { | |
127 | m_chartWidget->addDataSeries(QChart::DataSeriesTypeScatter, dataset); |
|
127 | m_chartWidget->addDataSeries(QChart::DataSeriesTypeScatter, dataset); | |
128 | } else if (series == "Line") { |
|
128 | } else if (series == "Line") { | |
129 | m_chartWidget->addDataSeries(QChart::DataSeriesTypeLine, dataset); |
|
129 | m_chartWidget->addDataSeries(QChart::DataSeriesTypeLine, dataset); | |
130 | } else { |
|
130 | } else { | |
131 | // TODO |
|
131 | // TODO | |
132 | } |
|
132 | } | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 | void MainWidget::chartTypeChanged(int itemIndex) |
|
135 | void MainWidget::chartTypeChanged(int itemIndex) | |
136 | { |
|
136 | { | |
137 | // TODO: change chart type |
|
137 | // TODO: change chart type | |
138 | switch (itemIndex) { |
|
138 | switch (itemIndex) { | |
139 | case 4: |
|
139 | case 4: | |
140 | //m_chartWidget->setType(4); |
|
140 | //m_chartWidget->setType(4); | |
141 | break; |
|
141 | break; | |
142 | default: { |
|
142 | default: { | |
143 | //m_chartWidget->setType(0); |
|
143 | //m_chartWidget->setType(0); | |
144 | break; |
|
144 | break; | |
145 | } |
|
145 | } | |
146 | } |
|
146 | } | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | void MainWidget::testDataChanged(int itemIndex) |
|
149 | void MainWidget::testDataChanged(int itemIndex) | |
150 | { |
|
150 | { | |
151 | qDebug() << "testDataChanged: " << itemIndex; |
|
151 | qDebug() << "testDataChanged: " << itemIndex; | |
152 |
|
152 | |||
153 | // switch (itemIndex) { |
|
153 | // switch (itemIndex) { | |
154 | // case 0: { |
|
154 | // case 0: { | |
155 | // QList<QChartDataPoint> data; |
|
155 | // QList<QChartDataPoint> data; | |
156 | // for (int x = 0; x < 20; x++) { |
|
156 | // for (int x = 0; x < 20; x++) { | |
157 | // data.append(QChartDataPoint() << x << x / 2); |
|
157 | // data.append(QChartDataPoint() << x << x / 2); | |
158 | // } |
|
158 | // } | |
159 | // m_chartWidget->setData(data); |
|
159 | // m_chartWidget->setData(data); | |
160 | // break; |
|
160 | // break; | |
161 | // } |
|
161 | // } | |
162 | // case 1: { |
|
162 | // case 1: { | |
163 | // QList<QChartDataPoint> data; |
|
163 | // QList<QChartDataPoint> data; | |
164 | // for (int x = 0; x < 100; x++) { |
|
164 | // for (int x = 0; x < 100; x++) { | |
165 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100)); |
|
165 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100)); | |
166 | // } |
|
166 | // } | |
167 | // m_chartWidget->setData(data); |
|
167 | // m_chartWidget->setData(data); | |
168 | // break; |
|
168 | // break; | |
169 | // } |
|
169 | // } | |
170 | // case 2: { |
|
170 | // case 2: { | |
171 | // QList<QChartDataPoint> data; |
|
171 | // QList<QChartDataPoint> data; | |
172 | // for (int x = 0; x < 1000; x++) { |
|
172 | // for (int x = 0; x < 1000; x++) { | |
173 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
173 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
174 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
174 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
175 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
175 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
176 | // } |
|
176 | // } | |
177 | // m_chartWidget->setData(data); |
|
177 | // m_chartWidget->setData(data); | |
178 | // break; |
|
178 | // break; | |
179 | // } |
|
179 | // } | |
180 | // default: |
|
180 | // default: | |
181 | // break; |
|
181 | // break; | |
182 | // } |
|
182 | // } | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | void MainWidget::backgroundChanged(int itemIndex) |
|
185 | void MainWidget::backgroundChanged(int itemIndex) | |
186 | { |
|
186 | { | |
187 | qDebug() << "backgroundChanged: " << itemIndex; |
|
187 | qDebug() << "backgroundChanged: " << itemIndex; | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | void MainWidget::autoScaleChanged(int value) |
|
190 | void MainWidget::autoScaleChanged(int value) | |
191 | { |
|
191 | { | |
192 | if (value) { |
|
192 | if (value) { | |
193 | // TODO: enable auto scaling |
|
193 | // TODO: enable auto scaling | |
194 | } else { |
|
194 | } else { | |
195 | // TODO: set scaling manually (and disable auto scaling) |
|
195 | // TODO: set scaling manually (and disable auto scaling) | |
196 | } |
|
196 | } | |
197 |
|
197 | |||
198 | m_xMinSpin->setEnabled(!value); |
|
198 | m_xMinSpin->setEnabled(!value); | |
199 | m_xMaxSpin->setEnabled(!value); |
|
199 | m_xMaxSpin->setEnabled(!value); | |
200 | m_yMinSpin->setEnabled(!value); |
|
200 | m_yMinSpin->setEnabled(!value); | |
201 | m_yMaxSpin->setEnabled(!value); |
|
201 | m_yMaxSpin->setEnabled(!value); | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | void MainWidget::xMinChanged(int value) |
|
204 | void MainWidget::xMinChanged(int value) | |
205 | { |
|
205 | { | |
206 | qDebug() << "xMinChanged: " << value; |
|
206 | qDebug() << "xMinChanged: " << value; | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | void MainWidget::xMaxChanged(int value) |
|
209 | void MainWidget::xMaxChanged(int value) | |
210 | { |
|
210 | { | |
211 | qDebug() << "xMaxChanged: " << value; |
|
211 | qDebug() << "xMaxChanged: " << value; | |
212 | } |
|
212 | } | |
213 |
|
213 | |||
214 | void MainWidget::yMinChanged(int value) |
|
214 | void MainWidget::yMinChanged(int value) | |
215 | { |
|
215 | { | |
216 | qDebug() << "yMinChanged: " << value; |
|
216 | qDebug() << "yMinChanged: " << value; | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | void MainWidget::yMaxChanged(int value) |
|
219 | void MainWidget::yMaxChanged(int value) | |
220 | { |
|
220 | { | |
221 | qDebug() << "yMaxChanged: " << value; |
|
221 | qDebug() << "yMaxChanged: " << value; | |
222 | } |
|
222 | } |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now