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