##// END OF EJS Templates
Revert "Integrated scatter series"...
Michal Klocek -
r39:abd9caf3a53e
parent child
Show More
@@ -1,12 +1,9
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"
5 #include "xylinechartitem_p.h"
3 #include "xylinechartitem_p.h"
6 #include "xyplotdomain_p.h"
4 #include "xyplotdomain_p.h"
7 #include "axis_p.h"
5 #include "axis_p.h"
8 #include "xygrid_p.h"
6 #include "xygrid_p.h"
9 #include <QGraphicsScene>
10 #include <QDebug>
7 #include <QDebug>
11
8
12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -87,30 +84,6 void QChart::addSeries(QChartSeries* series)
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 void QChart::setSize(const QSizeF& size)
87 void QChart::setSize(const QSizeF& size)
115 {
88 {
116 Q_D(QChart);
89 Q_D(QChart);
@@ -120,11 +93,10 void QChart::setSize(const QSizeF& size)
120 d->m_grid->setPos(d->m_rect.topLeft());
93 d->m_grid->setPos(d->m_rect.topLeft());
121 d->m_grid->setSize(d->m_rect.size());
94 d->m_grid->setSize(d->m_rect.size());
122 d->m_plotDataList[0].m_viewportRect = d->m_rect;
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
96 foreach(QGraphicsItem* item , d->m_items)
124 // via paint method
97 reinterpret_cast<XYLineChartItem*>(item)->updateXYPlotData(d->m_plotDataList.at(0));
125 // foreach(QGraphicsItem* item , d->m_items) {
126 // reinterpret_cast<XYLineChartItem*>(item);//->updateXYPlotData(d->m_plotDataList.at(0));
127 update();
98 update();
99
128 }
100 }
129
101
130 int QChart::margin() const
102 int QChart::margin() const
@@ -2,7 +2,6
2 #define CHART_H
2 #define CHART_H
3
3
4 #include <qchartglobal.h>
4 #include <qchartglobal.h>
5 #include <qchartseries.h>
6 #include <QGraphicsItem>
5 #include <QGraphicsItem>
7
6
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -13,16 +12,9 class QChartSeries;
13 class XYPlotDomain;
12 class XYPlotDomain;
14 class QChartPrivate;
13 class QChartPrivate;
15
14
16 // TODO: We don't need to have QChart tied to QGraphicsItem:
15 class QTCOMMERCIALCHART_EXPORT QChart : public 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
25 {
16 {
17
26 public:
18 public:
27 QChart(QGraphicsItem* parent = 0);
19 QChart(QGraphicsItem* parent = 0);
28 virtual ~QChart();
20 virtual ~QChart();
@@ -32,9 +24,6 public:
32 virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){};
24 virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){};
33
25
34 void addSeries(QChartSeries* series);
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 virtual void setSize(const QSizeF& rect);
28 virtual void setSize(const QSizeF& rect);
40 void setMargin(int margin);
29 void setMargin(int margin);
@@ -20,15 +20,16 public:
20 };
20 };
21
21
22 protected:
22 protected:
23 QChartSeries(QObject *parent = 0) : QObject(parent) {};
23 QChartSeries(QObject *parent = 0):QObject(parent){};
24
24
25 public:
25 public:
26 virtual ~QChartSeries() {};
26 virtual ~QChartSeries(){};
27
27
28 //factory method
28 //factory method
29 static QChartSeries* create(QObject* parent = 0) { return 0;}
29 static QChartSeries* create(QObject* parent = 0 ){ return 0;}
30 //pure virtual
30 //pure virtual
31 virtual QChartSeriesType type() const = 0;
31 virtual QChartSeriesType type() const = 0;
32
32 };
33 };
33
34
34 QTCOMMERCIALCHART_END_NAMESPACE
35 QTCOMMERCIALCHART_END_NAMESPACE
@@ -19,7 +19,6 public:
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();
23 }
22 }
24
23
25 ~QChartWidgetPrivate() {
24 ~QChartWidgetPrivate() {
@@ -65,12 +64,6 void QChartWidget::addSeries(QChartSeries* series)
65 d->m_chart->addSeries(series);
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 #include "moc_qchartwidget.cpp"
67 #include "moc_qchartwidget.cpp"
75
68
76 QTCOMMERCIALCHART_END_NAMESPACE
69 QTCOMMERCIALCHART_END_NAMESPACE
@@ -21,10 +21,7 public:
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
25 void addSeries(QChartSeries* series);
24 void addSeries(QChartSeries* series);
26 QChartSeries* createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type);
27
28 protected:
25 protected:
29 QChartWidgetPrivate * const d_ptr;
26 QChartWidgetPrivate * const d_ptr;
30
27
@@ -1,7 +1,14
1 !include( ../common.pri ) {
2 error( Couldn't find the common.pri file! )
3 }
4
5
1 TARGET = QtCommercialChart
6 TARGET = QtCommercialChart
7 DESTDIR = $$CHART_BUILD_LIB_DIR
2 TEMPLATE = lib
8 TEMPLATE = lib
3 QT += core \
9 QT += core \
4 gui
10 gui
11
5 CONFIG += debug_and_release
12 CONFIG += debug_and_release
6 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
13 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
7
14
@@ -10,38 +17,35 SOURCES += \
10 xylinechart/xylinechartitem.cpp \
17 xylinechart/xylinechartitem.cpp \
11 xylinechart/xygrid.cpp \
18 xylinechart/xygrid.cpp \
12 xylinechart/xyplotdomain.cpp \
19 xylinechart/xyplotdomain.cpp \
13 qscatterseries.cpp \
14 qchart.cpp \
20 qchart.cpp \
15 axis.cpp \
21 axis.cpp \
16 qchartwidget.cpp \
22 qchartwidget.cpp
17 qchartdata.cpp
18
23
19 PRIVATE_HEADERS += \
24 PRIVATE_HEADERS += \
20 xylinechart/xylinechartitem_p.h \
25 xylinechart/xylinechartitem_p.h \
21 xylinechart/xyplotdomain_p.h \
26 xylinechart/xyplotdomain_p.h \
22 xylinechart/xygrid_p.h \
27 xylinechart/xygrid_p.h \
23 qscatterseries_p.h \
24 axis_p.h
28 axis_p.h
25
29
26 PUBLIC_HEADERS += \
30 PUBLIC_HEADERS += \
27 qchartseries.h \
31 qchartseries.h \
28 qscatterseries.h \
29 qchart.h \
32 qchart.h \
30 qchartdata.h \
31 qchartwidget.h \
33 qchartwidget.h \
32 qchartglobal.h \
34 qchartglobal.h \
33 xylinechart/qxychartseries.h
35 xylinechart/qxychartseries.h
34
36
35 HEADERS += $$PUBLIC_HEADERS
37 HEADERS += $$PUBLIC_HEADERS
36 HEADERS += $$PRIVATE_HEADERS
38 HEADERS += $$PRIVATE_HEADERS
37
39
38 INCLUDEPATH += xylinechart \
40 INCLUDEPATH += xylinechart \
39 .
41 .
40
42
41 OBJECTS_DIR = ../build/lib
43 OBJECTS_DIR = $$CHART_BUILD_DIR/lib
42 MOC_DIR = ../build/lib
44 MOC_DIR = $$CHART_BUILD_DIR/lib
43 UI_DIR = ../build/lib
45 UI_DIR = $$CHART_BUILD_DIR/lib
44 RCC_DIR = ../build/lib
46 RCC_DIR = $$CHART_BUILD_DIR/lib
47
48
45 DEFINES += QTCOMMERCIALCHART_LIBRARY
49 DEFINES += QTCOMMERCIALCHART_LIBRARY
46
50
47 public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart
51 public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart
@@ -49,3 +53,21 public_headers.files = $$PUBLIC_HEADERS
49 target.path = $$[QT_INSTALL_LIBS]
53 target.path = $$[QT_INSTALL_LIBS]
50 INSTALLS += target \
54 INSTALLS += target \
51 public_headers
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
@@ -101,46 +101,38 void MainWidget::addSeries(QString series, QString data)
101 m_defaultSeries = series;
101 m_defaultSeries = series;
102
102
103 QXYChartSeries* series0 = 0;
103 QXYChartSeries* series0 = 0;
104 QChartSeries* scatterSeries = 0;
104
105 // TODO: a dedicated data class for storing x and y values
105 // TODO: color of the series
106 QList<qreal> x;
106 if (series == "Scatter") {
107 QList<qreal> y;
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 if (data == "linear") {
115 if (data == "linear") {
110 for (int i = 0; i < 10; i++) {
116 for (int i = 0; i < 10; i++)
111 x.append(i);
117 series0->add(i, 10);
112 y.append(10);
113 }
114 } else if (data == "linear, 1M") {
118 } else if (data == "linear, 1M") {
115 for (int i = 0; i < 10000; i++) {
119 for (int i = 0; i < 1000000; i++)
116 x.append(i);
120 series0->add(i, 20);
117 y.append(20);
118 }
119 } else if (data == "SIN") {
121 } else if (data == "SIN") {
120 for (int i = 0; i < 100; i++) {
122 for (int x = 0; x < 100; x++)
121 x.append(i);
123 series0->add(x, abs(sin(3.14159265358979 / 50 * x) * 100));
122 y.append(abs(sin(3.14159265358979 / 50 * i) * 100));
124 QList<QXYChartSeries*> dataset;
123 }
125 dataset << series0;
124 } else if (data == "SIN + random") {
126 } else if (data == "SIN + random") {
125 for (qreal i = 0; i < 100; i += 0.1) {
127 for (qreal x = 0; x < 100; x += 0.1) {
126 x.append(i + (rand() % 5));
128 series0->add(x + (rand() % 5),
127 y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
129 abs(sin(3.14159265358979 / 50 * x) * 100) + (rand() % 5));
128 }
130 }
129 } else {
131 } else {
130 // TODO: check if data has a valid file name
132 // TODO: check if data has a valid file name
131 }
133 }
132
134
133 // TODO: color of the series
135 m_chartWidget->addSeries(series0);
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 }
144 }
136 }
145
137
146 void MainWidget::chartTypeChanged(int itemIndex)
138 void MainWidget::chartTypeChanged(int itemIndex)
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
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