##// END OF EJS Templates
Renamed to QtCommercialChart
Tero Ahola -
r30:ef99599d15b7
parent child
Show More
@@ -0,0 +1,9
1 message( "Configuring with QtCommercialChart addon..." )
2
3 INCLUDEPATH += $$[QT_INSTALL_HEADERS]/QtCommercialChart
4
5 CONFIG(debug, debug|release) {
6 LIBS += -lQtCommercialChartd
7 } else {
8 LIBS += -lQtCommercialChart
9 }
@@ -0,0 +1,25
1 #ifndef CHARTGLOBAL_H
2 #define CHARTGLOBAL_H
3
4 #define QTCOMMERCIALCHART_VERSION_STR "1.0"
5 #define QTCOMMERCIALCHART_VERSION 0x01
6
7 #if defined(QTCOMMERCIALCHART_LIBRARY)
8 # define QTCOMMERCIALCHART_EXPORT Q_DECL_EXPORT
9 #else
10 # define QTCOMMERCIALCHART_EXPORT Q_DECL_IMPORT
11 #endif
12
13 #define QTCOMMERCIALCHART_NAMESPACE QtCommercialChart
14
15 #ifdef QTCOMMERCIALCHART_NAMESPACE
16 # define QTCOMMERCIALCHART_BEGIN_NAMESPACE namespace QTCOMMERCIALCHART_NAMESPACE {
17 # define QTCOMMERCIALCHART_END_NAMESPACE }
18 # define QTCOMMERCIALCHART_USE_NAMESPACE using namespace QTCOMMERCIALCHART_NAMESPACE;
19 #else
20 # define QTCOMMERCIALCHART_BEGIN_NAMESPACE
21 # define QTCOMMERCIALCHART_END_NAMESPACE
22 # define QTCOMMERCIALCHART_USE_NAMESPACE
23 #endif
24
25 #endif
@@ -1,11 +1,10
1 TEMPLATE = subdirs
2 SUBDIRS += src #qmlplugin
3
4 QMAKE_CXXFLAGS += -g -Wall
5 QMAKE_DISTCLEAN += -r build
6
7 # install feature file
8 feature.path = $$[QT_INSTALL_DATA]/mkspecs/features
9 feature.files = $$PWD/features/charts.prf
10 INSTALLS += feature
11
1 TEMPLATE = subdirs
2 SUBDIRS += src #qmlplugin
3
4 QMAKE_CXXFLAGS += -g -Wall
5 QMAKE_DISTCLEAN += -r build
6
7 # install feature file
8 feature.path = $$[QT_INSTALL_DATA]/mkspecs/features
9 feature.files = $$PWD/features/qtcommercialchart.prf
10 INSTALLS += feature
@@ -1,8 +1,8
1 1 TARGET = lineChart
2 2 TEMPLATE = app
3 3
4 4 QT += core gui
5 5
6 CONFIG += charts
6 CONFIG += qtcommercialchart
7 7
8 8 SOURCES += main.cpp
@@ -1,55 +1,55
1 1 #include <QApplication>
2 2 #include <QMainWindow>
3 3 #include <qchartwidget.h>
4 4 #include <qxychartseries.h>
5 5 #include <qchart.h>
6 6 #include <cmath>
7 7
8 QCHART_USE_NAMESPACE
8 QTCOMMERCIALCHART_USE_NAMESPACE
9 9
10 10 #define PI 3.14159265358979
11 11
12 12 int main(int argc, char *argv[])
13 13 {
14 14 QApplication a(argc, argv);
15 15
16 16 QMainWindow window;
17 17
18 18 QXYChartSeries* series0 = QXYChartSeries::create();
19 19 series0->setColor(Qt::blue);
20 20 QXYChartSeries* series1 = QXYChartSeries::create();
21 21 series1->setColor(Qt::red);
22 22 QXYChartSeries* series2 = QXYChartSeries::create();
23 23 series2->setColor(Qt::gray);
24 24 QXYChartSeries* series3 = QXYChartSeries::create();
25 25 series3->setColor(Qt::green);
26 26
27 27 int numPoints = 100;
28 28
29 29 for (int x = 0; x < numPoints; ++x) {
30 30 series0->add(x,0);
31 31 series1->add(x, abs(sin(PI/50*x)*100));
32 32 series2->add(x, abs(cos(PI/50*x)*100));
33 33 series3->add(x,100);
34 34 }
35 35
36 36 QList<QXYChartSeries*> dataset;
37 37
38 38 //qDebug()<<"Series 1:" << *series1;
39 39 //qDebug()<<"Series 2:" << *series2;
40 40
41 41 dataset << series0;
42 42 dataset << series1;
43 43 dataset << series2;
44 44 dataset << series3;
45 45
46 46 QChartWidget* chartWidget = new QChartWidget(&window);
47 47 chartWidget->addSeries(series1);
48 48 chartWidget->addSeries(series2);
49 49
50 50 window.setCentralWidget(chartWidget);
51 51 window.resize(400, 300);
52 52 window.show();
53 53
54 54 return a.exec();
55 55 }
@@ -1,50 +1,50
1 1 #include "axis_p.h"
2 2 #include <QPainter>
3 3 #include <QDebug>
4 4
5 QCHART_BEGIN_NAMESPACE
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 6
7 7 Axis::Axis(QGraphicsItem* parent): QGraphicsItem(parent)
8 8 {
9 9 }
10 10
11 11 Axis::~Axis()
12 12 {
13 13 }
14 14
15 15 void Axis::setLength(int length)
16 16 {
17 17 QPainterPath path;
18 18 path.moveTo(QPointF(0,0));
19 19 path.lineTo(length,0);
20 20 // path.lineTo(length-4,0);
21 21 // path.lineTo(length,3);
22 22 // path.lineTo(length-4,6);
23 23 // path.lineTo(length-4,4);
24 24 // path.lineTo(0,4);
25 25 // path.lineTo(0,2);
26 26 m_path=path;
27 27 update();
28 28 }
29 29
30 30 QRectF Axis::boundingRect() const
31 31 {
32 32 return m_path.boundingRect();
33 33 }
34 34
35 35 QPainterPath Axis::shape() const
36 36 {
37 37 return m_path;
38 38 }
39 39
40 40 void Axis::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget)
41 41 {
42 42 painter->save();
43 43 QPen pen(Qt::black);
44 44 //pen.setWidth(10);
45 45 painter->setPen(pen);
46 46 painter->drawPath(m_path);
47 47 painter->restore();
48 48 }
49 49
50 QCHART_END_NAMESPACE
50 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,29 +1,29
1 1 #ifndef AXIS_H_
2 2 #define AXIS_H_
3 3
4 #include <qchartconfig.h>
4 #include <qchartglobal.h>
5 5 #include <QGraphicsItem>
6 6
7 QCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 8
9 9 class Axis: public QGraphicsItem
10 10 {
11 11 public:
12 12 Axis(QGraphicsItem* parent = 0);
13 13 virtual ~Axis();
14 14
15 15 //from QGraphicsItem
16 16 virtual QPainterPath shape() const;
17 17 virtual QRectF boundingRect() const;
18 18 virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
19 19
20 20 void setLength(int length);
21 21 void setWidth(int width);
22 22
23 23 private:
24 24 QPainterPath m_path;
25 25 };
26 26
27 QCHART_END_NAMESPACE
27 QTCOMMERCIALCHART_END_NAMESPACE
28 28
29 29 #endif /* AXIS_H_ */
@@ -1,112 +1,114
1 1 #include "qchart.h"
2 2 #include "qchartseries.h"
3 3 #include "xylinechartitem_p.h"
4 4 #include "xyplotdomain_p.h"
5 5 #include "axis_p.h"
6 6 #include "xygrid_p.h"
7 7 #include <QDebug>
8 8
9 QCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 10
11 11 class QChartPrivate
12 12 {
13 13 public:
14 14
15 15 QChartPrivate(QChart* parent):
16 16 m_axisX(new Axis(parent)),
17 17 m_axisY(new Axis(parent)),
18 18 m_grid(new XYGrid(parent)),
19 19 m_plotDataIndex(0),
20 20 m_marginSize(0){}
21 21
22 22 Axis* m_axisX;
23 23 Axis* m_axisY;
24 24 XYGrid* m_grid;
25 25 QRect m_rect;
26 26 QList<const QChartSeries*> m_series;
27 27 QList<XYPlotDomain> m_plotDataList;
28 28 QList<QGraphicsItem*> m_items;
29 29 int m_plotDataIndex;
30 30 int m_marginSize;
31 31
32 32 };
33 33
34 34 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
35 35
36 36 QChart::QChart(QGraphicsItem* parent):QGraphicsItem(parent),
37 37 d_ptr(new QChartPrivate(this))
38 38 {
39 39 // setFlags(QGraphicsItem::ItemClipsChildrenToShape);
40 40 // set axis
41 41 Q_D(QChart);
42 42 d->m_axisY->rotate(90);
43 43
44 44 //TODO hardcoded values , to removed soon
45 45 XYPlotDomain data;
46 46 data.m_minX = 0.0;
47 47 data.m_maxX = 100.0;
48 48 data.m_minY = 0.0;
49 49 data.m_maxY = 100.0;
50 50 data.m_ticksX=4;
51 51 data.m_ticksY=4;
52 52
53 53 d->m_plotDataList.clear();
54 54 d->m_plotDataList << data;
55 55
56 56 d->m_grid->setZValue(10);
57 57 d->m_grid->setXYPlotData(d->m_plotDataList.at(0));
58 58 }
59 59
60 60 QChart::~QChart(){}
61 61
62 62 QRectF QChart::boundingRect() const
63 63 {
64 64 Q_D(const QChart);
65 65 return d->m_rect;
66 66 }
67 67
68 68 void QChart::addSeries(QChartSeries* series)
69 69 {
70 70 Q_D(QChart);
71 71 d->m_series<<series;
72 72
73 73 switch(series->type())
74 74 {
75 case QChartSeries::LINE:
75 case QChartSeries::SeriesTypeLine: {
76 76 XYLineChartItem* item = new XYLineChartItem(reinterpret_cast<QXYChartSeries*>(series),this);
77 77 item->updateXYPlotData(d->m_plotDataList.at(0));
78 78 d->m_items<<item;
79 79 break;
80 80 }
81 case QChartSeries::SeriesTypeScatter: {
82 break;
83 }
84 }
81 85 }
82 86
83 87 void QChart::setSize(const QSizeF& size)
84 88 {
85 89 Q_D(QChart);
86 90 //TODO refactor to setGeometry
87 91 d->m_rect = QRect(QPoint(0,0),size.toSize());
88 92 d->m_rect.adjust(margin(),margin(),-margin(),-margin());
89 93 d->m_grid->setPos(d->m_rect.topLeft());
90 94 d->m_grid->setSize(d->m_rect.size());
91 95 d->m_plotDataList[0].m_viewportRect = d->m_rect;
92 96 foreach(QGraphicsItem* item , d->m_items)
93 97 reinterpret_cast<XYLineChartItem*>(item)->updateXYPlotData(d->m_plotDataList.at(0));
94 98 update();
95 99
96 100 }
97 101
98 102 int QChart::margin() const
99 103 {
100 104 Q_D(const QChart);
101 105 return d->m_marginSize;
102 106 }
103 107
104 108 void QChart::setMargin(int margin)
105 109 {
106 110 Q_D(QChart);
107 111 d->m_marginSize = margin;
108 112 }
109 113
110
111
112 QCHART_END_NAMESPACE
114 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,43 +1,43
1 1 #ifndef CHART_H
2 2 #define CHART_H
3 3
4 #include <qchartconfig.h>
4 #include <qchartglobal.h>
5 5 #include <QGraphicsItem>
6 6
7 QCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 8
9 9 class Axis;
10 10 class XYGrid;
11 11 class QChartSeries;
12 12 class XYPlotDomain;
13 13 class QChartPrivate;
14 14
15 class QCHART_EXPORT QChart : public QGraphicsItem
15 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsItem
16 16 {
17 17
18 18 public:
19 19 QChart(QGraphicsItem* parent = 0);
20 20 virtual ~QChart();
21 21
22 22 //from QGraphicsItem
23 23 virtual QRectF boundingRect() const;
24 24 virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){};
25 25
26 26 void addSeries(QChartSeries* series);
27 27
28 28 virtual void setSize(const QSizeF& rect);
29 29 void setMargin(int margin);
30 30 int margin() const;
31 31
32 32 protected:
33 33 QChartPrivate * const d_ptr;
34 34
35 35 private:
36 36 Q_DISABLE_COPY(QChart)
37 37 Q_DECLARE_PRIVATE(QChart)
38 38
39 39 };
40 40
41 QCHART_END_NAMESPACE
41 QTCOMMERCIALCHART_END_NAMESPACE
42 42
43 43 #endif
@@ -1,31 +1,38
1 1 #ifndef QCHARTSERIES_H
2 2 #define QCHARTSERIES_H
3 3
4 #include "qchartconfig.h"
4 #include "qchartglobal.h"
5 5 #include <QObject>
6 6
7 QCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 8
9 class QCHART_EXPORT QChartSeries : public QObject
9 class QTCOMMERCIALCHART_EXPORT QChartSeries : public QObject
10 10 {
11 11
12 12 public:
13 enum QChartSeriesType {LINE,PIE,BAR};
13 enum QChartSeriesType {
14 SeriesTypeLine = 0,
15 // SeriesTypeArea,
16 // SeriesTypeBar,
17 // SeriesTypePie,
18 SeriesTypeScatter
19 // SeriesTypeSpline
20 };
14 21
15 22 protected:
16 23 QChartSeries(QObject *parent = 0):QObject(parent){};
17 24
18 25 public:
19 26 virtual ~QChartSeries(){};
20 27
21 28 //factory method
22 29 static QChartSeries* create(QObject* parent = 0 ){ return 0;}
23 30 //pure virtual
24 31 virtual QChartSeriesType type() const = 0;
25 32
26 33 };
27 34
28 QCHART_END_NAMESPACE
35 QTCOMMERCIALCHART_END_NAMESPACE
29 36
30 37 #endif
31 38
@@ -1,69 +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 QCHART_BEGIN_NAMESPACE
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 22 }
23 23
24 24 ~QChartWidgetPrivate() {
25 25 }
26 26
27 27 QGraphicsView *m_view;
28 28 QGraphicsScene *m_scene;
29 29 QChart* m_chart;
30 30 };
31 31
32 32 ///////////////////////////////////////////////////////////////////////////////////////////////////
33 33
34 34 QChartWidget::QChartWidget(QWidget *parent) :
35 35 QWidget(parent),
36 36 d_ptr(new QChartWidgetPrivate(this))
37 37 {
38 38 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
39 39 }
40 40
41 41 QChartWidget::~QChartWidget()
42 42 {
43 43 delete d_ptr;
44 44 }
45 45
46 46 void QChartWidget::resizeEvent(QResizeEvent *event)
47 47 {
48 48 Q_D(QChartWidget);
49 49 d->m_view->resize(size().width(),size().height());
50 50 d->m_scene->setSceneRect(0,0,size().width(),size().height());
51 51 d->m_chart->setSize(size());
52 52 QWidget::resizeEvent(event);
53 53 }
54 54
55 55 QSize QChartWidget::sizeHint() const
56 56 {
57 57 // TODO: calculate size hint based on contents?
58 58 return QSize(100, 100);
59 59 }
60 60
61 61 void QChartWidget::addSeries(QChartSeries* series)
62 62 {
63 63 Q_D(QChartWidget);
64 64 d->m_chart->addSeries(series);
65 65 }
66 66
67 67 #include "moc_qchartwidget.cpp"
68 68
69 QCHART_END_NAMESPACE
69 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,36 +1,36
1 1 #ifndef QCHARTWIDGET_H
2 2 #define QCHARTWIDGET_H
3 3
4 #include "qchartconfig.h"
4 #include "qchartglobal.h"
5 5 #include "qchart.h"
6 6 #include <QWidget>
7 7
8 QCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 class QChartSeries;
11 11 class QChartWidgetPrivate;
12 12
13 class QCHART_EXPORT QChartWidget : public QWidget
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 24 void addSeries(QChartSeries* series);
25 25 protected:
26 26 QChartWidgetPrivate * const d_ptr;
27 27
28 28 private:
29 29 Q_DISABLE_COPY(QChartWidget)
30 30 Q_DECLARE_PRIVATE(QChartWidget)
31 31
32 32 };
33 33
34 QCHART_END_NAMESPACE
34 QTCOMMERCIALCHART_END_NAMESPACE
35 35
36 36 #endif // QCHARTWIDGET_H
@@ -1,46 +1,49
1 TARGET = QChart
2 TEMPLATE = lib
3 QT += core \
4 gui
5 CONFIG += debug_and_release
6 CONFIG(debug, debug|release):TARGET = QChartd
7
8 SOURCES += \
9 xylinechart/qxychartseries.cpp \
10 xylinechart/xylinechartitem.cpp \
11 xylinechart/xygrid.cpp \
12 xylinechart/xyplotdomain.cpp \
13 qchart.cpp \
14 axis.cpp \
15 qchartwidget.cpp
16
17 PRIVATE_HEADERS += \
18 xylinechart/xylinechartitem_p.h \
19 xylinechart/xyplotdomain_p.h \
20 xylinechart/xygrid_p.h \
21 axis_p.h
22
23 PUBLIC_HEADERS += \
24 qchartseries.h \
25 qchart.h \
26 qchartwidget.h \
27 qchartconfig.h \
28 xylinechart/qxychartseries.h
29
30 HEADERS += $$PUBLIC_HEADERS
31 HEADERS += $$PRIVATE_HEADERS
32
33 INCLUDEPATH += xylinechart \
34 .
35
36 OBJECTS_DIR = ../build/lib
37 MOC_DIR = ../build/lib
38 UI_DIR = ../build/lib
39 RCC_DIR = ../build/lib
40 DEFINES += QCHART_LIBRARY
41
42 public_headers.path = $$[QT_INSTALL_HEADERS]/QCharts
43 public_headers.files = $$PUBLIC_HEADERS
44 target.path = $$[QT_INSTALL_LIBS]
45 INSTALLS += target \
46 public_headers
1 TARGET = QtCommercialChart
2 TEMPLATE = lib
3 QT += core \
4 gui
5 CONFIG += debug_and_release
6 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
7
8 SOURCES += \
9 xylinechart/qxychartseries.cpp \
10 xylinechart/xylinechartitem.cpp \
11 xylinechart/xygrid.cpp \
12 xylinechart/xyplotdomain.cpp \
13 qchart.cpp \
14 axis.cpp \
15 qchartwidget.cpp
16
17 PRIVATE_HEADERS += \
18 xylinechart/xylinechartitem_p.h \
19 xylinechart/xyplotdomain_p.h \
20 xylinechart/xygrid_p.h \
21 axis_p.h
22
23 PUBLIC_HEADERS += \
24 qchartseries.h \
25 qchart.h \
26 qchartwidget.h \
27 qchartglobal.h \
28 xylinechart/qxychartseries.h
29
30 HEADERS += $$PUBLIC_HEADERS
31 HEADERS += $$PRIVATE_HEADERS
32
33 INCLUDEPATH += xylinechart \
34 .
35
36 OBJECTS_DIR = ../build/lib
37 MOC_DIR = ../build/lib
38 UI_DIR = ../build/lib
39 RCC_DIR = ../build/lib
40 DEFINES += QTCOMMERCIALCHART_LIBRARY
41
42 public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart
43 public_headers.files = $$PUBLIC_HEADERS
44 target.path = $$[QT_INSTALL_LIBS]
45 INSTALLS += target \
46 public_headers
47
48
49
@@ -1,68 +1,68
1 1 #include "qxychartseries.h"
2 2
3 QCHART_BEGIN_NAMESPACE
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4 4
5 5 QXYChartSeries::QXYChartSeries(QObject* parent):QChartSeries(parent),
6 6 m_color(Qt::black)
7 7 {
8 8 }
9 9
10 10 QXYChartSeries::~QXYChartSeries()
11 11 {
12 12 }
13 13
14 14 QXYChartSeries* QXYChartSeries::create(QObject* parent)
15 15 {
16 16 //TODO: here we take QChartData when it is ready
17 17 // return null if malformed;
18 18 return new QXYChartSeries(parent);
19 19 }
20 20
21 21 void QXYChartSeries::setColor(const QColor& color)
22 22 {
23 23 m_color = color;
24 24 }
25 25
26 26 void QXYChartSeries::add(qreal x,qreal y)
27 27 {
28 28 m_x<<x;
29 29 m_y<<y;
30 30 }
31 31
32 32 void QXYChartSeries::clear()
33 33 {
34 34 m_x.clear();
35 35 m_y.clear();
36 36 }
37 37
38 38 qreal QXYChartSeries::x(int pos) const
39 39 {
40 40 return m_x.at(pos);
41 41 }
42 42
43 43 qreal QXYChartSeries::y(int pos) const
44 44 {
45 45 return m_y.at(pos);
46 46 }
47 47
48 48 int QXYChartSeries::count() const
49 49 {
50 50 Q_ASSERT(m_x.size() == m_y.size());
51 51
52 52 return m_x.size();
53 53
54 54 }
55 55
56 56 QDebug operator<< (QDebug debug, const QXYChartSeries series)
57 57 {
58 58 Q_ASSERT(series.m_x.size() == series.m_y.size());
59 59
60 60 int size = series.m_x.size();
61 61
62 62 for (int i=0;i<size;i++) {
63 63 debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") ";
64 64 }
65 65 return debug.space();
66 66 }
67 67
68 QCHART_END_NAMESPACE
68 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,40 +1,40
1 1 #ifndef QXYSERIES_H_
2 2 #define QXYSERIES_H_
3 3
4 #include "qchartconfig.h"
4 #include "qchartglobal.h"
5 5 #include "qchartseries.h"
6 6 #include <QDebug>
7 7 #include <QColor>
8 8
9 QCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 10
11 class QCHART_EXPORT QXYChartSeries : public QChartSeries
11 class QTCOMMERCIALCHART_EXPORT QXYChartSeries : public QChartSeries
12 12 {
13 13 private:
14 14 QXYChartSeries(QObject* parent=0);
15 15 public:
16 16 virtual ~QXYChartSeries();
17 17
18 18 //implemented from QChartSeries
19 19 static QXYChartSeries* create(QObject* parent=0);
20 virtual QChartSeriesType type() const { return QChartSeries::LINE;};
20 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeLine;}
21 21
22 22 void add(qreal x, qreal y);
23 23 void clear();
24 24 void setColor(const QColor& color);
25 25 const QColor& color() const { return m_color;}
26 26 int count() const;
27 27 qreal x(int pos) const;
28 28 qreal y(int pos) const;
29 29 friend QDebug operator<< (QDebug d, const QXYChartSeries series);
30 30
31 31 private:
32 32 QColor m_color;
33 33 QList<qreal> m_x;
34 34 QList<qreal> m_y;
35 35
36 36 };
37 37
38 QCHART_END_NAMESPACE
38 QTCOMMERCIALCHART_END_NAMESPACE
39 39
40 40 #endif
@@ -1,70 +1,70
1 1 #include "xygrid_p.h"
2 2 #include <QPainter>
3 3 #include <QDebug>
4 4
5 QCHART_BEGIN_NAMESPACE
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 6
7 7 XYGrid::XYGrid(QGraphicsItem* parent):QGraphicsItem(parent)
8 8 {
9 9 }
10 10
11 11 XYGrid::~XYGrid()
12 12 {
13 13 // TODO Auto-generated destructor stub
14 14 }
15 15
16 16 void XYGrid::setSize(const QSizeF& size)
17 17 {
18 18 m_rect.setSize(size.toSize());
19 19 }
20 20
21 21 void XYGrid::setXYPlotData(const XYPlotDomain& xyPlotData)
22 22 {
23 23 m_xyPlotData = xyPlotData;
24 24 }
25 25
26 26 QRectF XYGrid::boundingRect() const
27 27 {
28 28 return m_rect;
29 29 }
30 30
31 31 void XYGrid::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget)
32 32 {
33 33
34 34 if (!m_rect.isValid())
35 35 return;
36 36
37 37 const qreal deltaX = (m_rect.width() -1) / m_xyPlotData.ticksX();
38 38 const qreal deltaY = (m_rect.height() - 1) / m_xyPlotData.ticksY();
39 39
40 40 for (int i = 0; i <= m_xyPlotData.ticksX(); ++i) {
41 41
42 42 int x = i * deltaX + m_rect.left();
43 43 qreal label = m_xyPlotData.m_minX + (i * m_xyPlotData.spanX()
44 44 / m_xyPlotData.ticksX());
45 45 painter->drawLine(x, m_rect.top()+1, x, m_rect.bottom());
46 46 //painter->drawLine(x, m_rect.bottom(), x, m_rect.bottom() + 5);
47 47
48 48 painter->drawText(x - 50, m_rect.bottom() + 5, 100, 20,
49 49 Qt::AlignHCenter | Qt::AlignTop,
50 50 QString::number(label));
51 51 }
52 52
53 53 for (int j = 0; j <= m_xyPlotData.ticksY(); ++j) {
54 54
55 55 int y = j * -deltaY + m_rect.bottom();
56 56 qreal label = m_xyPlotData.m_minY + (j * m_xyPlotData.spanY()
57 57 / m_xyPlotData.ticksY());
58 58
59 59 painter->drawLine(m_rect.left(), y, m_rect.right()-1, y);
60 60 //painter->drawLine(m_rect.left() - 5, y, m_rect.left(), y);
61 61 //TODO : margin = 50 ;
62 62 painter->drawText(m_rect.left() - 50, y - 10, 50 - 5, 20,
63 63 Qt::AlignRight | Qt::AlignVCenter,
64 64 QString::number(label));
65 65 }
66 66
67 67 //painter->drawRect(m_rect.adjusted(0, 0, -1, -1));
68 68 }
69 69
70 QCHART_END_NAMESPACE
70 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,31 +1,31
1 1 #ifndef XYGRID_H_
2 2 #define XYGRID_H_
3 3
4 #include <qchartconfig.h>
4 #include <qchartglobal.h>
5 5 #include <xyplotdomain_p.h>
6 6 #include <QGraphicsItem>
7 7
8 QCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 class XYGrid : public QGraphicsItem
11 11 {
12 12 public:
13 13 XYGrid(QGraphicsItem* parent = 0);
14 14 virtual ~XYGrid();
15 15
16 16 //from QGraphicsItem
17 17 virtual QRectF boundingRect() const;
18 18 virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
19 19
20 20 //TODO: this is just temporary interface
21 21 void setXYPlotData(const XYPlotDomain& xyPlotData);
22 22 void setSize(const QSizeF& rect);
23 23
24 24 private:
25 25 QRectF m_rect;
26 26 XYPlotDomain m_xyPlotData;
27 27 };
28 28
29 QCHART_END_NAMESPACE
29 QTCOMMERCIALCHART_END_NAMESPACE
30 30
31 31 #endif /* XYGRID_H_ */
@@ -1,56 +1,56
1 1 #include "xylinechartitem_p.h"
2 2 #include "axis_p.h"
3 3 #include "xygrid_p.h"
4 4 #include "qxychartseries.h"
5 5 #include <QPainter>
6 6 #include <QStyleOptionGraphicsItem>
7 7 #include <QDebug>
8 8
9 QCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 10
11 11 XYLineChartItem::XYLineChartItem(QXYChartSeries* series,QGraphicsItem *parent):QGraphicsItem(parent),
12 12 m_series(series)
13 13 {
14 14
15 15 }
16 16
17 17 void XYLineChartItem::updateXYPlotData(const XYPlotDomain& data)
18 18 {
19 19 m_xyPlotData=data;
20 20
21 21 if (!m_xyPlotData.m_viewportRect.isValid())
22 22 return;
23 23
24 24 const QRect& rect = m_xyPlotData.m_viewportRect;
25 25
26 26 const qreal deltaX = (rect.width()-1)/m_xyPlotData.spanX();
27 27 const qreal deltaY = (rect.height()-1)/m_xyPlotData.spanY();
28 28
29 29 m_polyline.clear();
30 30 m_polyline.resize(m_series->count());
31 31
32 32 for (int j = 0; j < m_series->count(); ++j) {
33 33 qreal dx = m_series->x(j) - m_xyPlotData.m_minX;
34 34 qreal dy = m_series->y(j) - m_xyPlotData.m_minY;
35 35 qreal x = (dx * deltaX) + rect.left();
36 36 qreal y = - (dy * deltaY) + rect.bottom();
37 37 m_polyline[j] = QPointF(x, y);
38 38 }
39 39
40 40 }
41 41
42 42 QRectF XYLineChartItem::boundingRect() const
43 43 {
44 44 return m_polyline.boundingRect();
45 45 }
46 46
47 47
48 48 void XYLineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget)
49 49 {
50 50 painter->setClipRect(m_xyPlotData.m_viewportRect.adjusted(+1, +1, -1, -1));
51 51 painter->setPen(m_series->color());
52 52 painter->drawPolyline(m_polyline);
53 53
54 54 }
55 55
56 QCHART_END_NAMESPACE
56 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,33 +1,33
1 1 #ifndef XYLINECHARTITEM_H
2 2 #define XYLINECHARTITEM_H
3 3
4 #include "qchartconfig.h"
4 #include "qchartglobal.h"
5 5 #include "qchart.h"
6 6 #include "xyplotdomain_p.h"
7 7
8 QCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 class QXYChartSeries;
11 11
12 12 class XYLineChartItem : public QGraphicsItem
13 13 {
14 14
15 15 public:
16 16 XYLineChartItem(QXYChartSeries* m_series,QGraphicsItem *parent = 0);
17 17 virtual ~ XYLineChartItem(){};
18 18
19 19 //from QGraphicsItem
20 20 virtual QRectF boundingRect() const;
21 21 virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
22 22
23 23 void updateXYPlotData(const XYPlotDomain& data);
24 24
25 25 private:
26 26 QPolygonF m_polyline;
27 27 QXYChartSeries* m_series;
28 28 XYPlotDomain m_xyPlotData;
29 29 };
30 30
31 QCHART_END_NAMESPACE
31 QTCOMMERCIALCHART_END_NAMESPACE
32 32
33 33 #endif
@@ -1,33 +1,33
1 1 #include "xyplotdomain_p.h"
2 2
3 QCHART_BEGIN_NAMESPACE
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4 4
5 5 XYPlotDomain::XYPlotDomain():
6 6 m_ticksX(0),
7 7 m_ticksY(0),
8 8 m_minX(0),
9 9 m_maxX(0),
10 10 m_minY(0),
11 11 m_maxY(0)
12 12 {
13 13
14 14 }
15 15
16 16 XYPlotDomain::~XYPlotDomain()
17 17 {
18 18 // TODO Auto-generated destructor stub
19 19 }
20 20
21 21 qreal XYPlotDomain::spanX() const
22 22 {
23 23 Q_ASSERT(m_maxX >= m_minX);
24 24 return m_maxX - m_minX;
25 25 }
26 26
27 27 qreal XYPlotDomain::spanY() const
28 28 {
29 29 Q_ASSERT(m_maxY >= m_minY);
30 30 return m_maxY - m_minY;
31 31 }
32 32
33 QCHART_END_NAMESPACE
33 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,30 +1,30
1 1 #ifndef PLOTDOMAIN_H_
2 2 #define PLOTDOMAIN_H_
3 #include "qchartconfig.h"
3 #include "qchartglobal.h"
4 4 #include <QRect>
5 5
6 QCHART_BEGIN_NAMESPACE
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 7
8 8 class XYPlotDomain {
9 9 public:
10 10 XYPlotDomain();
11 11 virtual ~XYPlotDomain();
12 12
13 13 qreal spanX() const;
14 14 qreal spanY() const;
15 15 int ticksX() const { return m_ticksX; }
16 16 int ticksY() const { return m_ticksY; }
17 17
18 18 public:
19 19 int m_ticksX;
20 20 int m_ticksY;
21 21 qreal m_minX;
22 22 qreal m_maxX;
23 23 qreal m_minY;
24 24 qreal m_maxY;
25 25 QRect m_viewportRect;
26 26 };
27 27
28 QCHART_END_NAMESPACE
28 QTCOMMERCIALCHART_END_NAMESPACE
29 29
30 30 #endif /* PLOTTER_H_ */
@@ -1,33 +1,33
1 1 TARGET = chartwidgettest
2 2 TEMPLATE = app
3 3
4 4 QT += core gui
5 5 contains(QT_MAJOR_VERSION, 5) {
6 6 QT += widgets
7 7 }
8 8
9 CONFIG += charts
9 CONFIG += qtcommercialchart
10 10
11 11 OBJECTS_DIR = tmp
12 12 MOC_DIR = tmp
13 13
14 14 SOURCES += main.cpp \
15 15 mainwidget.cpp \
16 16 # qscatterseries.cpp \
17 17 # qseriespointgraphicsitem.cpp \
18 18 dataseriedialog.cpp
19 19
20 20 HEADERS += \
21 21 mainwidget.h \
22 22 # qscatterseries.h \
23 23 # qseriespointgraphicsitem.h \
24 24 dataseriedialog.h
25 25
26 26
27 27
28 28
29 29
30 30
31 31
32 32
33 33
@@ -1,223 +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 QCHART_USE_NAMESPACE
16 QTCOMMERCIALCHART_USE_NAMESPACE
17 17
18 18 MainWidget::MainWidget(QWidget *parent) :
19 19 QWidget(parent)
20 20 {
21 m_chartWidget = new QChartWidget(this);
22 // m_chartWidget->resize(QSize(200,200));
23 // m_chartWidget->setColor(Qt::red);
24
25 21 QPushButton *addSeriesButton = new QPushButton("Add series");
26 22 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
27 23
28 24 // Chart background
29 25 QComboBox *backgroundCombo = new QComboBox(this);
30 26 backgroundCombo->addItem("None");
31 27 backgroundCombo->addItem("TODO Grid");
32 28 backgroundCombo->addItem("TODO Image");
33 29 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
34 30 this, SLOT(backgroundChanged(int)));
35 31
36 32 // Axis
37 33 // TODO: multiple axes?
38 34 m_autoScaleCheck = new QCheckBox("Automatic scaling");
39 35 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
40 36 // Allow setting also non-sense values (like -2147483648 and 2147483647)
41 37 m_xMinSpin = new QSpinBox();
42 38 m_xMinSpin->setMinimum(INT_MIN);
43 39 m_xMinSpin->setMaximum(INT_MAX);
44 40 m_xMinSpin->setValue(0);
45 41 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
46 42 m_xMaxSpin = new QSpinBox();
47 43 m_xMaxSpin->setMinimum(INT_MIN);
48 44 m_xMaxSpin->setMaximum(INT_MAX);
49 45 m_xMaxSpin->setValue(10);
50 46 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
51 47 m_yMinSpin = new QSpinBox();
52 48 m_yMinSpin->setMinimum(INT_MIN);
53 49 m_yMinSpin->setMaximum(INT_MAX);
54 50 m_yMinSpin->setValue(0);
55 51 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
56 52 m_yMaxSpin = new QSpinBox();
57 53 m_yMaxSpin->setMinimum(INT_MIN);
58 54 m_yMaxSpin->setMaximum(INT_MAX);
59 55 m_yMaxSpin->setValue(10);
60 56 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
61 57
62 58 QGridLayout *grid = new QGridLayout();
63 59 QHBoxLayout *hbox = new QHBoxLayout();
64 60 //grid->addWidget(new QLabel("Add series:"), 0, 0);
65 61 grid->addWidget(addSeriesButton, 0, 1);
66 62 grid->addWidget(new QLabel("Background:"), 2, 0);
67 63 grid->addWidget(backgroundCombo, 2, 1);
68 64 grid->addWidget(m_autoScaleCheck, 3, 0);
69 65 grid->addWidget(new QLabel("x min:"), 4, 0);
70 66 grid->addWidget(m_xMinSpin, 4, 1);
71 67 grid->addWidget(new QLabel("x max:"), 5, 0);
72 68 grid->addWidget(m_xMaxSpin, 5, 1);
73 69 grid->addWidget(new QLabel("y min:"), 6, 0);
74 70 grid->addWidget(m_yMinSpin, 6, 1);
75 71 grid->addWidget(new QLabel("y max:"), 7, 0);
76 72 grid->addWidget(m_yMaxSpin, 7, 1);
77 73 // add row with empty label to make all the other rows static
78 74 grid->addWidget(new QLabel(""), 8, 0);
79 75 grid->setRowStretch(8, 1);
80 76
81 77 hbox->addLayout(grid);
78
79 m_chartWidget = new QChartWidget(this);
80 //m_chartWidget->setColor(Qt::red);
82 81 hbox->addWidget(m_chartWidget);
83 hbox->setStretch(1, 1);
82 // hbox->setStretch(1, 1);
84 83
85 84 setLayout(hbox);
86 85
87 86 m_autoScaleCheck->setChecked(true);
88 87 chartTypeChanged(4);
89 88 testDataChanged(0);
90 89 }
91 90
92 91 void MainWidget::addSeries()
93 92 {
94 93 DataSerieDialog dialog(m_defaultSeries, this);
95 94 connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString)));
96 95 dialog.exec();
97 96 }
98 97
99 98 void MainWidget::addSeries(QString series, QString data)
100 99 {
101 100 qDebug() << "addSeries: " << series << " data: " << data;
102 101 m_defaultSeries = series;
103 102
103 QXYChartSeries* series0 = 0;
104
104 105 // TODO: color of the series
105 QXYChartSeries* series0 = QXYChartSeries::create();
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 }
106 114
107 115 if (data == "linear") {
108 116 for (int i = 0; i < 10; i++)
109 117 series0->add(i, 10);
110 118 } else if (data == "linear, 1M") {
111 119 for (int i = 0; i < 1000000; i++)
112 120 series0->add(i, 20);
113 121 } else if (data == "SIN") {
114 122 for (int x = 0; x < 100; x++)
115 123 series0->add(x, abs(sin(3.14159265358979 / 50 * x) * 100));
116 124 QList<QXYChartSeries*> dataset;
117 125 dataset << series0;
118 126 } else if (data == "SIN + random") {
119 127 for (qreal x = 0; x < 100; x += 0.1) {
120 128 series0->add(x + (rand() % 5),
121 129 abs(sin(3.14159265358979 / 50 * x) * 100) + (rand() % 5));
122 130 }
123 131 } else {
124 132 // TODO: check if data has a valid file name
125 133 }
126 134
127 if (series == "Scatter") {
128 m_chartWidget->addSeries(series0);
129 } else if (series == "Line") {
130 m_chartWidget->addSeries(series0);
131 } else {
132 // TODO
133 }
135 m_chartWidget->addSeries(series0);
134 136 }
135 137
136 138 void MainWidget::chartTypeChanged(int itemIndex)
137 139 {
138 140 // TODO: change chart type
139 141 switch (itemIndex) {
140 142 case 4:
141 143 //m_chartWidget->setType(4);
142 144 break;
143 145 default: {
144 146 //m_chartWidget->setType(0);
145 147 break;
146 148 }
147 149 }
148 150 }
149 151
150 152 void MainWidget::testDataChanged(int itemIndex)
151 153 {
152 154 qDebug() << "testDataChanged: " << itemIndex;
153 155
154 156 // switch (itemIndex) {
155 157 // case 0: {
156 158 // QList<QChartDataPoint> data;
157 159 // for (int x = 0; x < 20; x++) {
158 160 // data.append(QChartDataPoint() << x << x / 2);
159 161 // }
160 162 // m_chartWidget->setData(data);
161 163 // break;
162 164 // }
163 165 // case 1: {
164 166 // QList<QChartDataPoint> data;
165 167 // for (int x = 0; x < 100; x++) {
166 168 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100));
167 169 // }
168 170 // m_chartWidget->setData(data);
169 171 // break;
170 172 // }
171 173 // case 2: {
172 174 // QList<QChartDataPoint> data;
173 175 // for (int x = 0; x < 1000; x++) {
174 176 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
175 177 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
176 178 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
177 179 // }
178 180 // m_chartWidget->setData(data);
179 181 // break;
180 182 // }
181 183 // default:
182 184 // break;
183 185 // }
184 186 }
185 187
186 188 void MainWidget::backgroundChanged(int itemIndex)
187 189 {
188 190 qDebug() << "backgroundChanged: " << itemIndex;
189 191 }
190 192
191 193 void MainWidget::autoScaleChanged(int value)
192 194 {
193 195 if (value) {
194 196 // TODO: enable auto scaling
195 197 } else {
196 198 // TODO: set scaling manually (and disable auto scaling)
197 199 }
198 200
199 201 m_xMinSpin->setEnabled(!value);
200 202 m_xMaxSpin->setEnabled(!value);
201 203 m_yMinSpin->setEnabled(!value);
202 204 m_yMaxSpin->setEnabled(!value);
203 205 }
204 206
205 207 void MainWidget::xMinChanged(int value)
206 208 {
207 209 qDebug() << "xMinChanged: " << value;
208 210 }
209 211
210 212 void MainWidget::xMaxChanged(int value)
211 213 {
212 214 qDebug() << "xMaxChanged: " << value;
213 215 }
214 216
215 217 void MainWidget::yMinChanged(int value)
216 218 {
217 219 qDebug() << "yMinChanged: " << value;
218 220 }
219 221
220 222 void MainWidget::yMaxChanged(int value)
221 223 {
222 224 qDebug() << "yMaxChanged: " << value;
223 225 }
@@ -1,43 +1,43
1 1 #ifndef MAINWIDGET_H
2 2 #define MAINWIDGET_H
3 3
4 #include <qchartconfig.h>
4 #include <qchartglobal.h>
5 5 #include <qchartwidget.h>
6 6 #include <QWidget>
7 7
8 8 class QSpinBox;
9 9 class QCheckBox;
10 10
11 QCHART_USE_NAMESPACE
11 QTCOMMERCIALCHART_USE_NAMESPACE
12 12
13 13 class MainWidget : public QWidget
14 14 {
15 15 Q_OBJECT
16 16 public:
17 17 explicit MainWidget(QWidget *parent = 0);
18 18
19 19 signals:
20 20
21 21 private slots:
22 22 void chartTypeChanged(int itemIndex);
23 23 void addSeries();
24 24 void addSeries(QString series, QString data);
25 25 void testDataChanged(int itemIndex);
26 26 void backgroundChanged(int itemIndex);
27 27 void autoScaleChanged(int value);
28 28 void xMinChanged(int value);
29 29 void xMaxChanged(int value);
30 30 void yMinChanged(int value);
31 31 void yMaxChanged(int value);
32 32
33 33 private:
34 34 QChartWidget *m_chartWidget;
35 35 QCheckBox *m_autoScaleCheck;
36 36 QSpinBox *m_xMinSpin;
37 37 QSpinBox *m_xMaxSpin;
38 38 QSpinBox *m_yMinSpin;
39 39 QSpinBox *m_yMaxSpin;
40 40 QString m_defaultSeries;
41 41 };
42 42
43 43 #endif // MAINWIDGET_H
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