@@ -1,21 +1,21 | |||||
1 | TEMPLATE = subdirs |
|
1 | TEMPLATE = subdirs | |
2 | SUBDIRS += linechart \ |
|
2 | SUBDIRS += linechart \ | |
3 | zoomlinechart \ |
|
3 | zoomlinechart \ | |
4 | colorlinechart \ |
|
4 | colorlinechart \ | |
5 | barchart \ |
|
5 | barchart \ | |
6 | stackedbarchart \ |
|
6 | stackedbarchart \ | |
7 | percentbarchart \ |
|
7 | percentbarchart \ | |
8 | scatter \ |
|
8 | scatter \ | |
9 | piechart \ |
|
9 | piechart \ | |
10 | piechartcustomization \ |
|
10 | piechartcustomization \ | |
11 | piechartdrilldown \ |
|
11 | piechartdrilldown \ | |
12 | dynamiclinechart \ |
|
12 | dynamiclinechart \ | |
13 | axischart \ |
|
13 | axischart \ | |
14 | multichart \ |
|
14 | multichart \ | |
15 | gdpbarchart \ |
|
15 | gdpbarchart \ | |
16 | presenterchart \ |
|
16 | presenterchart \ | |
17 | chartview \ |
|
17 | chartview \ | |
18 | scatterinteractions \ |
|
18 | scatterinteractions \ | |
19 | splinechart \ |
|
19 | #splinechart \ | |
20 | areachart \ |
|
20 | areachart \ | |
21 | stackedbarchartdrilldown |
|
21 | stackedbarchartdrilldown |
@@ -1,108 +1,108 | |||||
1 | #include "splinewidget.h" |
|
1 | #include "splinewidget.h" | |
2 | #include "qchartview.h" |
|
2 | #include "qchartview.h" | |
3 | #include "qlineseries.h" |
|
3 | #include "qlineseries.h" | |
4 | #include <QGridLayout> |
|
4 | #include <QGridLayout> | |
5 | #include <QPushButton> |
|
5 | #include <QPushButton> | |
6 | #include "qchartaxis.h" |
|
6 | #include "qchartaxis.h" | |
7 | #include <qmath.h> |
|
7 | #include <qmath.h> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
9 | QTCOMMERCIALCHART_USE_NAMESPACE | |
10 |
|
10 | |||
11 | SplineWidget::SplineWidget(QWidget *parent) |
|
11 | SplineWidget::SplineWidget(QWidget *parent) | |
12 | : QWidget(parent) |
|
12 | : QWidget(parent) | |
13 | { |
|
13 | { | |
14 | qsrand(time(NULL)); |
|
14 | // qsrand(time(NULL)); | |
15 | //! [1] |
|
15 | //! [1] | |
16 | //create QSplineSeries |
|
16 | //create QSplineSeries | |
17 | series = new QSplineSeries; |
|
17 | series = new QSplineSeries; | |
18 | //! [1] |
|
18 | //! [1] | |
19 |
|
19 | |||
20 | //! [2] |
|
20 | //! [2] | |
21 | // customize the series presentation settings |
|
21 | // customize the series presentation settings | |
22 | QPen seriesPen(Qt::blue); |
|
22 | QPen seriesPen(Qt::blue); | |
23 | seriesPen.setWidth(3); |
|
23 | seriesPen.setWidth(3); | |
24 | series->setPen(seriesPen); |
|
24 | series->setPen(seriesPen); | |
25 | //! [2] |
|
25 | //! [2] | |
26 |
|
26 | |||
27 | //! [add points to series] |
|
27 | //! [add points to series] | |
28 | //add data points to the series |
|
28 | //add data points to the series | |
29 | series->add(QPointF(150, 100)); |
|
29 | series->add(QPointF(150, 100)); | |
30 | series->add(QPointF(200, 130)); |
|
30 | series->add(QPointF(200, 130)); | |
31 | series->add(QPointF(250, 120)); |
|
31 | series->add(QPointF(250, 120)); | |
32 | series->add(QPointF(300, 140)); |
|
32 | series->add(QPointF(300, 140)); | |
33 | series->add(QPointF(350, 160)); |
|
33 | series->add(QPointF(350, 160)); | |
34 | //! [add points to series] |
|
34 | //! [add points to series] | |
35 | // series->add(QPointF(400, 120)); |
|
35 | // series->add(QPointF(400, 120)); | |
36 | // series->add(QPointF(450, 150)); |
|
36 | // series->add(QPointF(450, 150)); | |
37 | // series->add(QPointF(500, 145)); |
|
37 | // series->add(QPointF(500, 145)); | |
38 | // series->add(QPointF(550, 170)); |
|
38 | // series->add(QPointF(550, 170)); | |
39 | // series->add(QPointF(600, 190)); |
|
39 | // series->add(QPointF(600, 190)); | |
40 | // series->add(QPointF(650, 210)); |
|
40 | // series->add(QPointF(650, 210)); | |
41 | // series->add(QPointF(700, 190)); |
|
41 | // series->add(QPointF(700, 190)); | |
42 | // series->add(QPointF(750, 180)); |
|
42 | // series->add(QPointF(750, 180)); | |
43 | // series->add(QPointF(800, 170)); |
|
43 | // series->add(QPointF(800, 170)); | |
44 |
|
44 | |||
45 | //! [3] |
|
45 | //! [3] | |
46 | // create chart view |
|
46 | // create chart view | |
47 | QChartView* chart = new QChartView; |
|
47 | QChartView* chart = new QChartView; | |
48 | chart->addSeries(series); |
|
48 | chart->addSeries(series); | |
49 |
|
49 | |||
50 | chart->setChartTitle("Spline chart example"); |
|
50 | chart->setChartTitle("Spline chart example"); | |
51 |
|
51 | |||
52 | // chart->setMinimumSize(800,600); |
|
52 | // chart->setMinimumSize(800,600); | |
53 | // chart->axisX()->setRange(0, 1500); |
|
53 | // chart->axisX()->setRange(0, 1500); | |
54 |
|
54 | |||
55 | // chart->axisX()->setMax(1500); |
|
55 | // chart->axisX()->setMax(1500); | |
56 | // chart->axisY()->setRange(0, 400); |
|
56 | // chart->axisY()->setRange(0, 400); | |
57 | chart->axisX()->setMax(1500); |
|
57 | chart->axisX()->setMax(1500); | |
58 | // chart-> |
|
58 | // chart-> | |
59 |
|
59 | |||
60 | chart->setMinimumSize(800,600); |
|
60 | chart->setMinimumSize(800,600); | |
61 | //! [3] |
|
61 | //! [3] | |
62 |
|
62 | |||
63 | //! [4] |
|
63 | //! [4] | |
64 | //add new data point button |
|
64 | //add new data point button | |
65 | QPushButton* addButton = new QPushButton("Add new point"); |
|
65 | QPushButton* addButton = new QPushButton("Add new point"); | |
66 | connect(addButton, SIGNAL(clicked()), this, SLOT(addNewPoint())); |
|
66 | connect(addButton, SIGNAL(clicked()), this, SLOT(addNewPoint())); | |
67 |
|
67 | |||
68 | // remove the last data point in the series |
|
68 | // remove the last data point in the series | |
69 | QPushButton* removeButton = new QPushButton("Remove point"); |
|
69 | QPushButton* removeButton = new QPushButton("Remove point"); | |
70 | connect(removeButton, SIGNAL(clicked()), this, SLOT(removePoint())); |
|
70 | connect(removeButton, SIGNAL(clicked()), this, SLOT(removePoint())); | |
71 | //! [4] |
|
71 | //! [4] | |
72 |
|
72 | |||
73 | //! [5] |
|
73 | //! [5] | |
74 | //butttons layout |
|
74 | //butttons layout | |
75 | QVBoxLayout* buttonsLayout = new QVBoxLayout; |
|
75 | QVBoxLayout* buttonsLayout = new QVBoxLayout; | |
76 | buttonsLayout->addWidget(addButton); |
|
76 | buttonsLayout->addWidget(addButton); | |
77 | buttonsLayout->addWidget(removeButton); |
|
77 | buttonsLayout->addWidget(removeButton); | |
78 | buttonsLayout->addStretch(); |
|
78 | buttonsLayout->addStretch(); | |
79 |
|
79 | |||
80 | QGridLayout* mainLayout = new QGridLayout; |
|
80 | QGridLayout* mainLayout = new QGridLayout; | |
81 | mainLayout->addWidget(chart, 1, 0); |
|
81 | mainLayout->addWidget(chart, 1, 0); | |
82 | mainLayout->addLayout(buttonsLayout, 1, 1); |
|
82 | mainLayout->addLayout(buttonsLayout, 1, 1); | |
83 | setLayout(mainLayout); |
|
83 | setLayout(mainLayout); | |
84 | //! [5] |
|
84 | //! [5] | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | //! [add point] |
|
87 | //! [add point] | |
88 | void SplineWidget::addNewPoint() |
|
88 | void SplineWidget::addNewPoint() | |
89 | { |
|
89 | { | |
90 | if (series->count() > 0) |
|
90 | if (series->count() > 0) | |
91 | series->add(QPointF(series->x(series->count() - 1) + 20 + qrand()%40, qAbs(series->y(series->count() - 1) - 50 + qrand()%100))); |
|
91 | series->add(QPointF(series->x(series->count() - 1) + 20 + qrand()%40, qAbs(series->y(series->count() - 1) - 50 + qrand()%100))); | |
92 | else |
|
92 | else | |
93 | series->add(QPointF(50, 50 + qrand()%50)); |
|
93 | series->add(QPointF(50, 50 + qrand()%50)); | |
94 | } |
|
94 | } | |
95 | //! [add point] |
|
95 | //! [add point] | |
96 |
|
96 | |||
97 | //! [remove point] |
|
97 | //! [remove point] | |
98 | void SplineWidget::removePoint() |
|
98 | void SplineWidget::removePoint() | |
99 | { |
|
99 | { | |
100 | if (series->count() > 0) |
|
100 | if (series->count() > 0) | |
101 | series->remove(QPointF(series->x(series->count() - 1), series->y(series->count() - 1))); |
|
101 | series->remove(QPointF(series->x(series->count() - 1), series->y(series->count() - 1))); | |
102 | } |
|
102 | } | |
103 | //! [remove point] |
|
103 | //! [remove point] | |
104 |
|
104 | |||
105 | SplineWidget::~SplineWidget() |
|
105 | SplineWidget::~SplineWidget() | |
106 | { |
|
106 | { | |
107 |
|
107 | |||
108 | } |
|
108 | } |
@@ -1,78 +1,75 | |||||
1 | #include "splinepresenter_p.h" |
|
1 | #include "splinepresenter_p.h" | |
2 | #include <QPainter> |
|
2 | #include <QPainter> | |
3 |
|
3 | |||
4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
5 |
|
5 | |||
6 | SplinePresenter::SplinePresenter(QSplineSeries* series, QGraphicsObject *parent) : |
|
6 | SplinePresenter::SplinePresenter(QSplineSeries* series, QGraphicsObject *parent) : | |
7 | LineChartItem(series, parent)//,m_boundingRect() |
|
7 | LineChartItem(series, parent)//,m_boundingRect() | |
8 | { |
|
8 | { | |
9 | // |
|
9 | // | |
10 | } |
|
10 | } | |
11 |
|
11 | |||
12 |
|
12 | |||
13 |
|
13 | |||
14 | QPointF SplinePresenter::calculateGeometryControlPoint(int index) const |
|
14 | QPointF SplinePresenter::calculateGeometryControlPoint(int index) const | |
15 | { |
|
15 | { | |
16 | QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series); |
|
16 | QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series); | |
17 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); |
|
17 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); | |
18 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); |
|
18 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); | |
19 | qreal x = (splineSeries->controlPoint(index).x() - m_minX)* deltaX; |
|
19 | qreal x = (splineSeries->controlPoint(index).x() - m_minX)* deltaX; | |
20 | qreal y = (splineSeries->controlPoint(index).y() - m_minY)*-deltaY + m_size.height(); |
|
20 | qreal y = (splineSeries->controlPoint(index).y() - m_minY)*-deltaY + m_size.height(); | |
21 | return QPointF(x,y); |
|
21 | return QPointF(x,y); | |
22 | } |
|
22 | } | |
23 |
|
23 | |||
24 | void SplinePresenter::applyGeometry(QVector<QPointF>& points) |
|
24 | void SplinePresenter::applyGeometry(QVector<QPointF>& points) | |
25 | { |
|
25 | { | |
26 | if(points.size()==0) return; |
|
26 | if(points.size()==0) return; | |
27 |
|
27 | |||
28 | qDebug() << "Kueku"; |
|
|||
29 | QPainterPath splinePath; |
|
28 | QPainterPath splinePath; | |
30 | const QPointF& point = points.at(0); |
|
29 | const QPointF& point = points.at(0); | |
31 | splinePath.moveTo(point); |
|
30 | splinePath.moveTo(point); | |
32 |
|
31 | |||
33 | // QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series); |
|
32 | // QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series); | |
34 | for (int i = 0; i < points.size() - 1; i++) |
|
33 | for (int i = 0; i < points.size() - 1; i++) | |
35 | { |
|
34 | { | |
36 | const QPointF& point = points.at(i + 1); |
|
35 | const QPointF& point = points.at(i + 1); | |
37 | splinePath.cubicTo(calculateGeometryControlPoint(2 * i), calculateGeometryControlPoint(2 * i + 1), point); |
|
36 | splinePath.cubicTo(calculateGeometryControlPoint(2 * i), calculateGeometryControlPoint(2 * i + 1), point); | |
38 | } |
|
37 | } | |
39 |
|
38 | |||
40 |
|
||||
41 |
|
||||
42 | prepareGeometryChange(); |
|
39 | prepareGeometryChange(); | |
43 | m_path = splinePath; |
|
40 | m_path = splinePath; | |
44 | m_rect = splinePath.boundingRect(); |
|
41 | m_rect = splinePath.boundingRect(); | |
45 | } |
|
42 | } | |
46 |
|
43 | |||
47 | void SplinePresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
44 | void SplinePresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
48 | { |
|
45 | { | |
49 | Q_UNUSED(widget); |
|
46 | Q_UNUSED(widget); | |
50 | Q_UNUSED(option); |
|
47 | Q_UNUSED(option); | |
51 | painter->save(); |
|
48 | painter->save(); | |
52 | painter->setPen(m_pen); |
|
49 | painter->setPen(m_pen); | |
53 | painter->setClipRect(m_clipRect); |
|
50 | painter->setClipRect(m_clipRect); | |
54 | painter->drawPath(m_path); |
|
51 | painter->drawPath(m_path); | |
55 |
|
52 | |||
56 | QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series); |
|
53 | QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series); | |
57 | for (int i = 0; i < m_points.size() - 1; i++) |
|
54 | for (int i = 0; i < m_points.size() - 1; i++) | |
58 | { |
|
55 | { | |
59 | painter->setPen(Qt::red); |
|
56 | painter->setPen(Qt::red); | |
60 | painter->drawEllipse(m_points[i], 2, 2); |
|
57 | painter->drawEllipse(m_points[i], 2, 2); | |
61 |
|
58 | |||
62 | painter->setPen(Qt::blue); |
|
59 | painter->setPen(Qt::blue); | |
63 | // painter->drawLine(m_series->at(i), m_series->controlPoint(2 * i)); |
|
60 | // painter->drawLine(m_series->at(i), m_series->controlPoint(2 * i)); | |
64 | // painter->drawLine(m_series->at(i + 1), m_series->controlPoint(2 * i + 1)); |
|
61 | // painter->drawLine(m_series->at(i + 1), m_series->controlPoint(2 * i + 1)); | |
65 | // painter->drawEllipse(calculateGeometryControlPoint(2 * i), 4, 4); |
|
62 | // painter->drawEllipse(calculateGeometryControlPoint(2 * i), 4, 4); | |
66 | // painter->drawEllipse(calculateGeometryControlPoint(2 * i + 1), 4, 4); |
|
63 | // painter->drawEllipse(calculateGeometryControlPoint(2 * i + 1), 4, 4); | |
67 | } |
|
64 | } | |
68 | if (m_points.count() > 0) |
|
65 | if (m_points.count() > 0) | |
69 | { |
|
66 | { | |
70 | painter->setPen(Qt::red); |
|
67 | painter->setPen(Qt::red); | |
71 | painter->drawEllipse(m_points[m_points.count() - 1], 2, 2); |
|
68 | painter->drawEllipse(m_points[m_points.count() - 1], 2, 2); | |
72 | } |
|
69 | } | |
73 | painter->restore(); |
|
70 | painter->restore(); | |
74 | } |
|
71 | } | |
75 |
|
72 | |||
76 | #include "moc_splinepresenter_p.cpp" |
|
73 | #include "moc_splinepresenter_p.cpp" | |
77 |
|
74 | |||
78 | QTCOMMERCIALCHART_END_NAMESPACE |
|
75 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now