@@ -1,78 +1,78 | |||||
1 | #include <QApplication> |
|
1 | #include <QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <qchartview.h> |
|
3 | #include <qchartview.h> | |
4 | #include <qlineseries.h> |
|
4 | #include <qlineseries.h> | |
5 | #include <qchart.h> |
|
5 | #include <qchart.h> | |
6 | #include <qchartaxis.h> |
|
6 | #include <qchartaxis.h> | |
7 | #include <qchartaxiscategories.h> |
|
7 | #include <qchartaxiscategories.h> | |
8 | #include <cmath> |
|
8 | #include <cmath> | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
10 | QTCOMMERCIALCHART_USE_NAMESPACE | |
11 |
|
11 | |||
12 | #define PI 3.14159265358979 |
|
12 | #define PI 3.14159265358979 | |
13 |
|
13 | |||
14 | int main(int argc, char *argv[]) |
|
14 | int main(int argc, char *argv[]) | |
15 | { |
|
15 | { | |
16 | QApplication a(argc, argv); |
|
16 | QApplication a(argc, argv); | |
17 |
|
17 | |||
18 | QMainWindow window; |
|
18 | QMainWindow window; | |
19 |
|
19 | |||
20 | QLineSeries* series0 = new QLineSeries(); |
|
20 | QLineSeries* series0 = new QLineSeries(); | |
21 | QPen blue(Qt::blue); |
|
21 | QPen blue(Qt::blue); | |
22 | blue.setWidth(3); |
|
22 | blue.setWidth(3); | |
23 | series0->setPen(blue); |
|
23 | series0->setPen(blue); | |
24 | QLineSeries* series1 = new QLineSeries(); |
|
24 | QLineSeries* series1 = new QLineSeries(); | |
25 | QPen red(Qt::red); |
|
25 | QPen red(Qt::red); | |
26 | red.setWidth(3); |
|
26 | red.setWidth(3); | |
27 | series1->setPen(red); |
|
27 | series1->setPen(red); | |
28 |
|
28 | |||
29 | int numPoints = 100; |
|
29 | int numPoints = 100; | |
30 |
|
30 | |||
31 | for (int x = 0; x <= numPoints; ++x) { |
|
31 | for (int x = 0; x <= numPoints; ++x) { | |
32 | series0->add(x, fabs(sin(PI/50*x)*100)); |
|
32 | series0->add(x, fabs(sin(PI/50*x)*100)); | |
33 | series1->add(x, fabs(cos(PI/50*x)*100)); |
|
33 | series1->add(x, fabs(cos(PI/50*x)*100)); | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | QChartView* chartView = new QChartView(&window); |
|
36 | QChartView* chartView = new QChartView(&window); | |
37 |
|
37 | |||
38 | chartView->setRenderHint(QPainter::Antialiasing); |
|
38 | chartView->setRenderHint(QPainter::Antialiasing); | |
39 | chartView->setChartTitle("This is custom axis chart example"); |
|
39 | chartView->setChartTitle("This is custom axis chart example"); | |
40 | chartView->addSeries(series0); |
|
40 | chartView->addSeries(series0); | |
41 | chartView->addSeries(series1); |
|
41 | chartView->addSeries(series1); | |
42 |
|
42 | |||
43 | QLinearGradient backgroundGradient; |
|
43 | QLinearGradient backgroundGradient; | |
44 | backgroundGradient.setColorAt(0.0, Qt::white); |
|
44 | backgroundGradient.setColorAt(0.0, Qt::white); | |
45 | backgroundGradient.setColorAt(1.0, QRgb(0xffff80)); |
|
45 | backgroundGradient.setColorAt(1.0, QRgb(0xffff80)); | |
46 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
46 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
47 | chartView->setChartBackgroundBrush(backgroundGradient); |
|
47 | chartView->setChartBackgroundBrush(backgroundGradient); | |
48 |
|
48 | |||
49 | QChartAxis* axisX = chartView->axisX(); |
|
49 | QChartAxis* axisX = chartView->axisX(); | |
50 | axisX->setLabelsAngle(45); |
|
50 | axisX->setLabelsAngle(45); | |
51 | axisX->setGridPen(Qt::DashLine); |
|
51 | axisX->setGridPen(Qt::DashLine); | |
52 |
|
52 | |||
53 | QChartAxisCategories& categoriesX = axisX->categories(); |
|
53 | QChartAxisCategories& categoriesX = axisX->categories(); | |
54 | categoriesX.insert(0,"low"); |
|
54 | categoriesX.insert(0,"low"); | |
55 | categoriesX.insert(50,"medium"); |
|
55 | categoriesX.insert(50,"medium"); | |
56 | categoriesX.insert(100,"High"); |
|
56 | categoriesX.insert(100,"High"); | |
57 |
|
57 | |||
58 | axisX->setMin(-10); |
|
58 | axisX->setMin(-10); | |
59 | axisX->setMax(200); |
|
59 | axisX->setMax(2200); | |
60 |
|
60 | |||
61 | QChartAxis* axisY = chartView->axisY(); |
|
61 | QChartAxis* axisY = chartView->axisY(); | |
62 | axisY->setLabelsAngle(45); |
|
62 | axisY->setLabelsAngle(45); | |
63 | axisY->setShadesBrush(Qt::yellow); |
|
63 | axisY->setShadesBrush(Qt::yellow); | |
64 |
|
64 | |||
65 | QChartAxisCategories& categoriesY = axisY->categories(); |
|
65 | QChartAxisCategories& categoriesY = axisY->categories(); | |
66 | categoriesY.insert(0,"low"); |
|
66 | categoriesY.insert(0,"low"); | |
67 | categoriesY.insert(50,"medium"); |
|
67 | categoriesY.insert(50,"medium"); | |
68 | categoriesY.insert(100,"High"); |
|
68 | categoriesY.insert(100,"High"); | |
69 |
|
69 | |||
70 | axisY->setMin(-10); |
|
70 | axisY->setMin(-10); | |
71 | axisY->setMax(200); |
|
71 | axisY->setMax(200); | |
72 |
|
72 | |||
73 | window.setCentralWidget(chartView); |
|
73 | window.setCentralWidget(chartView); | |
74 | window.resize(400, 300); |
|
74 | window.resize(400, 300); | |
75 | window.show(); |
|
75 | window.show(); | |
76 |
|
76 | |||
77 | return a.exec(); |
|
77 | return a.exec(); | |
78 | } |
|
78 | } |
@@ -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 |
|
|
19 | splinechart \ | |
20 | areachart \ |
|
20 | areachart \ | |
21 | stackedbarchartdrilldown |
|
21 | stackedbarchartdrilldown |
@@ -1,101 +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->axisX()->setRange(0, 1500); |
|
50 | chart->setChartTitle("Spline chart example"); | |
51 | chart->axisY()->setRange(0, 400); |
|
51 | ||
|
52 | // chart->setMinimumSize(800,600); | |||
|
53 | // chart->axisX()->setRange(0, 1500); | |||
|
54 | ||||
|
55 | // chart->axisX()->setMax(1500); | |||
|
56 | // chart->axisY()->setRange(0, 400); | |||
|
57 | chart->axisX()->setMax(1500); | |||
|
58 | // chart-> | |||
52 |
|
59 | |||
53 | chart->setMinimumSize(800,600); |
|
60 | chart->setMinimumSize(800,600); | |
54 | //! [3] |
|
61 | //! [3] | |
55 |
|
62 | |||
56 | //! [4] |
|
63 | //! [4] | |
57 | //add new data point button |
|
64 | //add new data point button | |
58 | QPushButton* addButton = new QPushButton("Add new point"); |
|
65 | QPushButton* addButton = new QPushButton("Add new point"); | |
59 | connect(addButton, SIGNAL(clicked()), this, SLOT(addNewPoint())); |
|
66 | connect(addButton, SIGNAL(clicked()), this, SLOT(addNewPoint())); | |
60 |
|
67 | |||
61 | // remove the last data point in the series |
|
68 | // remove the last data point in the series | |
62 | QPushButton* removeButton = new QPushButton("Remove point"); |
|
69 | QPushButton* removeButton = new QPushButton("Remove point"); | |
63 | connect(removeButton, SIGNAL(clicked()), this, SLOT(removePoint())); |
|
70 | connect(removeButton, SIGNAL(clicked()), this, SLOT(removePoint())); | |
64 | //! [4] |
|
71 | //! [4] | |
65 |
|
72 | |||
66 | //! [5] |
|
73 | //! [5] | |
67 | //butttons layout |
|
74 | //butttons layout | |
68 | QVBoxLayout* buttonsLayout = new QVBoxLayout; |
|
75 | QVBoxLayout* buttonsLayout = new QVBoxLayout; | |
69 | buttonsLayout->addWidget(addButton); |
|
76 | buttonsLayout->addWidget(addButton); | |
70 | buttonsLayout->addWidget(removeButton); |
|
77 | buttonsLayout->addWidget(removeButton); | |
71 | buttonsLayout->addStretch(); |
|
78 | buttonsLayout->addStretch(); | |
72 |
|
79 | |||
73 | QGridLayout* mainLayout = new QGridLayout; |
|
80 | QGridLayout* mainLayout = new QGridLayout; | |
74 | mainLayout->addWidget(chart, 1, 0); |
|
81 | mainLayout->addWidget(chart, 1, 0); | |
75 | mainLayout->addLayout(buttonsLayout, 1, 1); |
|
82 | mainLayout->addLayout(buttonsLayout, 1, 1); | |
76 | setLayout(mainLayout); |
|
83 | setLayout(mainLayout); | |
77 | //! [5] |
|
84 | //! [5] | |
78 | } |
|
85 | } | |
79 |
|
86 | |||
80 | //! [add point] |
|
87 | //! [add point] | |
81 | void SplineWidget::addNewPoint() |
|
88 | void SplineWidget::addNewPoint() | |
82 | { |
|
89 | { | |
83 | if (series->count() > 0) |
|
90 | if (series->count() > 0) | |
84 | 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))); | |
85 | else |
|
92 | else | |
86 | series->add(QPointF(50, 50 + qrand()%50)); |
|
93 | series->add(QPointF(50, 50 + qrand()%50)); | |
87 | } |
|
94 | } | |
88 | //! [add point] |
|
95 | //! [add point] | |
89 |
|
96 | |||
90 | //! [remove point] |
|
97 | //! [remove point] | |
91 | void SplineWidget::removePoint() |
|
98 | void SplineWidget::removePoint() | |
92 | { |
|
99 | { | |
93 | if (series->count() > 0) |
|
100 | if (series->count() > 0) | |
94 | 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))); | |
95 | } |
|
102 | } | |
96 | //! [remove point] |
|
103 | //! [remove point] | |
97 |
|
104 | |||
98 | SplineWidget::~SplineWidget() |
|
105 | SplineWidget::~SplineWidget() | |
99 | { |
|
106 | { | |
100 |
|
107 | |||
101 | } |
|
108 | } |
@@ -1,364 +1,366 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | #include "chartpresenter_p.h" |
|
3 | #include "chartpresenter_p.h" | |
4 | #include "chartdataset_p.h" |
|
4 | #include "chartdataset_p.h" | |
5 | #include "charttheme_p.h" |
|
5 | #include "charttheme_p.h" | |
6 | //series |
|
6 | //series | |
7 | #include "qbarseries.h" |
|
7 | #include "qbarseries.h" | |
8 | #include "qstackedbarseries.h" |
|
8 | #include "qstackedbarseries.h" | |
9 | #include "qpercentbarseries.h" |
|
9 | #include "qpercentbarseries.h" | |
10 | #include "qlineseries.h" |
|
10 | #include "qlineseries.h" | |
11 | #include "qareaseries.h" |
|
11 | #include "qareaseries.h" | |
12 | #include "qpieseries.h" |
|
12 | #include "qpieseries.h" | |
13 | #include "qscatterseries.h" |
|
13 | #include "qscatterseries.h" | |
14 | #include "qsplineseries.h" |
|
14 | #include "qsplineseries.h" | |
15 | //items |
|
15 | //items | |
16 | #include "axisitem_p.h" |
|
16 | #include "axisitem_p.h" | |
17 | #include "axisanimationitem_p.h" |
|
17 | #include "axisanimationitem_p.h" | |
18 | #include "areachartitem_p.h" |
|
18 | #include "areachartitem_p.h" | |
19 | #include "barpresenter_p.h" |
|
19 | #include "barpresenter_p.h" | |
20 | #include "stackedbarpresenter_p.h" |
|
20 | #include "stackedbarpresenter_p.h" | |
21 | #include "percentbarpresenter_p.h" |
|
21 | #include "percentbarpresenter_p.h" | |
22 | #include "linechartitem_p.h" |
|
22 | #include "linechartitem_p.h" | |
23 | #include "linechartanimationitem_p.h" |
|
23 | #include "linechartanimationitem_p.h" | |
24 | #include "piepresenter_p.h" |
|
24 | #include "piepresenter_p.h" | |
25 | #include "scatterpresenter_p.h" |
|
25 | #include "scatterpresenter_p.h" | |
26 | #include "splinepresenter_p.h" |
|
26 | #include "splinepresenter_p.h" | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
30 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | |
31 | m_chart(chart), |
|
31 | m_chart(chart), | |
32 | m_dataset(dataset), |
|
32 | m_dataset(dataset), | |
33 | m_chartTheme(0), |
|
33 | m_chartTheme(0), | |
34 | m_zoomIndex(0), |
|
34 | m_zoomIndex(0), | |
35 | m_marginSize(0), |
|
35 | m_marginSize(0), | |
36 | m_rect(QRectF(QPoint(0,0),m_chart->size())), |
|
36 | m_rect(QRectF(QPoint(0,0),m_chart->size())), | |
37 | m_options(QChart::NoAnimation) |
|
37 | m_options(QChart::NoAnimation) | |
38 | { |
|
38 | { | |
39 | createConnections(); |
|
39 | createConnections(); | |
40 | setChartTheme(QChart::ChartThemeDefault); |
|
40 | setChartTheme(QChart::ChartThemeDefault); | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | ChartPresenter::~ChartPresenter() |
|
43 | ChartPresenter::~ChartPresenter() | |
44 | { |
|
44 | { | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | void ChartPresenter::createConnections() |
|
47 | void ChartPresenter::createConnections() | |
48 | { |
|
48 | { | |
49 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
49 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); | |
50 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),this,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
50 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),this,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
51 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*))); |
|
51 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*))); | |
52 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),this,SLOT(handleAxisAdded(QChartAxis*,Domain*))); |
|
52 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),this,SLOT(handleAxisAdded(QChartAxis*,Domain*))); | |
53 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); |
|
53 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 |
|
56 | |||
57 | QRectF ChartPresenter::geometry() const |
|
57 | QRectF ChartPresenter::geometry() const | |
58 | { |
|
58 | { | |
59 | return m_rect; |
|
59 | return m_rect; | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | void ChartPresenter::handleGeometryChanged() |
|
62 | void ChartPresenter::handleGeometryChanged() | |
63 | { |
|
63 | { | |
64 | QRectF rect(QPoint(0,0),m_chart->size()); |
|
64 | QRectF rect(QPoint(0,0),m_chart->size()); | |
65 | rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); |
|
65 | rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); | |
66 |
|
66 | |||
67 | //rewrite zoom stack |
|
67 | //rewrite zoom stack | |
68 | for(int i=0;i<m_zoomStack.count();i++){ |
|
68 | for(int i=0;i<m_zoomStack.count();i++){ | |
69 | QRectF r = m_zoomStack[i]; |
|
69 | QRectF r = m_zoomStack[i]; | |
70 | qreal w = rect.width()/m_rect.width(); |
|
70 | qreal w = rect.width()/m_rect.width(); | |
71 | qreal h = rect.height()/m_rect.height(); |
|
71 | qreal h = rect.height()/m_rect.height(); | |
72 | QPointF tl = r.topLeft(); |
|
72 | QPointF tl = r.topLeft(); | |
73 | tl.setX(tl.x()*w); |
|
73 | tl.setX(tl.x()*w); | |
74 | tl.setY(tl.y()*h); |
|
74 | tl.setY(tl.y()*h); | |
75 | QPointF br = r.bottomRight(); |
|
75 | QPointF br = r.bottomRight(); | |
76 | br.setX(br.x()*w); |
|
76 | br.setX(br.x()*w); | |
77 | br.setY(br.y()*h); |
|
77 | br.setY(br.y()*h); | |
78 | r.setTopLeft(tl); |
|
78 | r.setTopLeft(tl); | |
79 | r.setBottomRight(br); |
|
79 | r.setBottomRight(br); | |
80 | m_zoomStack[i]=r; |
|
80 | m_zoomStack[i]=r; | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | m_rect = rect; |
|
83 | m_rect = rect; | |
84 | Q_ASSERT(m_rect.isValid()); |
|
84 | Q_ASSERT(m_rect.isValid()); | |
85 | emit geometryChanged(m_rect); |
|
85 | emit geometryChanged(m_rect); | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | int ChartPresenter::margin() const |
|
88 | int ChartPresenter::margin() const | |
89 | { |
|
89 | { | |
90 | return m_marginSize; |
|
90 | return m_marginSize; | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 | void ChartPresenter::setMargin(int margin) |
|
93 | void ChartPresenter::setMargin(int margin) | |
94 | { |
|
94 | { | |
95 | m_marginSize = margin; |
|
95 | m_marginSize = margin; | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain) |
|
98 | void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain) | |
99 | { |
|
99 | { | |
100 |
|
100 | |||
101 | AxisItem* item ; |
|
101 | AxisItem* item ; | |
102 |
|
102 | |||
103 | if(!m_options.testFlag(QChart::GridAxisAnimations)) |
|
103 | if(!m_options.testFlag(QChart::GridAxisAnimations)) | |
104 | { |
|
104 | { | |
105 | item = new AxisItem(axis,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); |
|
105 | item = new AxisItem(axis,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); | |
106 | }else{ |
|
106 | }else{ | |
107 | item = new AxisAnimationItem(axis,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); |
|
107 | item = new AxisAnimationItem(axis,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); | |
108 | } |
|
108 | } | |
109 | if(axis==m_dataset->axisX()){ |
|
109 | if(axis==m_dataset->axisX()){ | |
110 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal)),item,SLOT(handleRangeChanged(qreal,qreal))); |
|
110 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal)),item,SLOT(handleRangeChanged(qreal,qreal))); | |
111 | //initialize |
|
111 | //initialize | |
112 | item->handleRangeChanged(domain->minX(),domain->maxX()); |
|
112 | item->handleRangeChanged(domain->minX(),domain->maxX()); | |
113 | } |
|
113 | } | |
114 | else{ |
|
114 | else{ | |
115 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal)),item,SLOT(handleRangeChanged(qreal,qreal))); |
|
115 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal)),item,SLOT(handleRangeChanged(qreal,qreal))); | |
116 | //initialize |
|
116 | //initialize | |
117 | item->handleRangeChanged(domain->minY(),domain->maxY()); |
|
117 | item->handleRangeChanged(domain->minY(),domain->maxY()); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
120 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
121 | //initialize |
|
121 | //initialize | |
122 | item->handleGeometryChanged(m_rect); |
|
122 | item->handleGeometryChanged(m_rect); | |
123 | m_chartTheme->decorate(axis,item); |
|
123 | m_chartTheme->decorate(axis,item); | |
124 | m_axisItems.insert(axis,item); |
|
124 | m_axisItems.insert(axis,item); | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) |
|
127 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) | |
128 | { |
|
128 | { | |
129 | AxisItem* item = m_axisItems.take(axis); |
|
129 | AxisItem* item = m_axisItems.take(axis); | |
130 | Q_ASSERT(item); |
|
130 | Q_ASSERT(item); | |
131 | delete item; |
|
131 | delete item; | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 |
|
134 | |||
135 | void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) |
|
135 | void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |
136 | { |
|
136 | { | |
137 | switch(series->type()) |
|
137 | switch(series->type()) | |
138 | { |
|
138 | { | |
139 | case QSeries::SeriesTypeLine: { |
|
139 | case QSeries::SeriesTypeLine: { | |
140 |
|
140 | |||
141 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); |
|
141 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); | |
142 | LineChartItem* item; |
|
142 | LineChartItem* item; | |
143 | if(m_options.testFlag(QChart::SeriesAnimations)){ |
|
143 | if(m_options.testFlag(QChart::SeriesAnimations)){ | |
144 | item = new LineChartAnimationItem(lineSeries,m_chart); |
|
144 | item = new LineChartAnimationItem(lineSeries,m_chart); | |
145 | }else{ |
|
145 | }else{ | |
146 | item = new LineChartItem(lineSeries,m_chart); |
|
146 | item = new LineChartItem(lineSeries,m_chart); | |
147 | } |
|
147 | } | |
148 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
148 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
149 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
149 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
150 | //initialize |
|
150 | //initialize | |
151 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); |
|
151 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); | |
152 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
152 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
153 | //decorate |
|
153 | //decorate | |
154 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); |
|
154 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); | |
155 | m_chartItems.insert(series,item); |
|
155 | m_chartItems.insert(series,item); | |
156 | break; |
|
156 | break; | |
157 | } |
|
157 | } | |
158 |
|
158 | |||
159 | case QSeries::SeriesTypeArea: { |
|
159 | case QSeries::SeriesTypeArea: { | |
160 |
|
160 | |||
161 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); |
|
161 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); | |
162 | AreaChartItem* item; |
|
162 | AreaChartItem* item; | |
163 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
163 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
164 | item = new AreaChartItem(areaSeries,m_chart); |
|
164 | item = new AreaChartItem(areaSeries,m_chart); | |
165 | } |
|
165 | } | |
166 | else { |
|
166 | else { | |
167 | item = new AreaChartItem(areaSeries,m_chart); |
|
167 | item = new AreaChartItem(areaSeries,m_chart); | |
168 | } |
|
168 | } | |
169 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
169 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
170 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
170 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
171 | //initialize |
|
171 | //initialize | |
172 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); |
|
172 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); | |
173 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
173 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
174 | //decorate |
|
174 | //decorate | |
175 | m_chartTheme->decorate(item,areaSeries,m_chartItems.count()); |
|
175 | m_chartTheme->decorate(item,areaSeries,m_chartItems.count()); | |
176 | m_chartItems.insert(series,item); |
|
176 | m_chartItems.insert(series,item); | |
177 | break; |
|
177 | break; | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 | case QSeries::SeriesTypeBar: { |
|
180 | case QSeries::SeriesTypeBar: { | |
181 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
181 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); | |
182 | BarPresenter* item = new BarPresenter(barSeries,m_chart); |
|
182 | BarPresenter* item = new BarPresenter(barSeries,m_chart); | |
183 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); |
|
183 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); | |
184 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
184 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
185 | // QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
185 | // QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
186 | m_chartItems.insert(series,item); |
|
186 | m_chartItems.insert(series,item); | |
187 | // m_axisXItem->setVisible(false); |
|
187 | // m_axisXItem->setVisible(false); | |
188 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
188 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
189 | break; |
|
189 | break; | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | case QSeries::SeriesTypeStackedBar: { |
|
192 | case QSeries::SeriesTypeStackedBar: { | |
193 |
|
193 | |||
194 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
194 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); | |
195 | StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart); |
|
195 | StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart); | |
196 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); |
|
196 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); | |
197 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
197 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
198 | // QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
198 | // QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
199 | m_chartItems.insert(series,item); |
|
199 | m_chartItems.insert(series,item); | |
200 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
200 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
201 | break; |
|
201 | break; | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | case QSeries::SeriesTypePercentBar: { |
|
204 | case QSeries::SeriesTypePercentBar: { | |
205 |
|
205 | |||
206 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
206 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); | |
207 | PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart); |
|
207 | PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart); | |
208 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); |
|
208 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); | |
209 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
209 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
210 | // QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
210 | // QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
211 | m_chartItems.insert(series,item); |
|
211 | m_chartItems.insert(series,item); | |
212 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
212 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
213 | break; |
|
213 | break; | |
214 | } |
|
214 | } | |
215 | case QSeries::SeriesTypeScatter: { |
|
215 | case QSeries::SeriesTypeScatter: { | |
216 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
216 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
217 | ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart); |
|
217 | ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart); | |
218 | QObject::connect(scatterPresenter, SIGNAL(clicked(QPointF)), |
|
218 | QObject::connect(scatterPresenter, SIGNAL(clicked(QPointF)), | |
219 | scatterSeries, SIGNAL(clicked(QPointF))); |
|
219 | scatterSeries, SIGNAL(clicked(QPointF))); | |
220 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), |
|
220 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), | |
221 | scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); |
|
221 | scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); | |
222 | m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count()); |
|
222 | m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count()); | |
223 | m_chartItems.insert(scatterSeries, scatterPresenter); |
|
223 | m_chartItems.insert(scatterSeries, scatterPresenter); | |
224 | if(m_rect.isValid()) scatterPresenter->handleGeometryChanged(m_rect); |
|
224 | if(m_rect.isValid()) scatterPresenter->handleGeometryChanged(m_rect); | |
225 | break; |
|
225 | break; | |
226 | } |
|
226 | } | |
227 | case QSeries::SeriesTypePie: { |
|
227 | case QSeries::SeriesTypePie: { | |
228 | QPieSeries *s = qobject_cast<QPieSeries *>(series); |
|
228 | QPieSeries *s = qobject_cast<QPieSeries *>(series); | |
229 | PiePresenter* pie = new PiePresenter(m_chart, s); |
|
229 | PiePresenter* pie = new PiePresenter(m_chart, s); | |
230 | m_chartTheme->decorate(pie, s, m_chartItems.count()); |
|
230 | m_chartTheme->decorate(pie, s, m_chartItems.count()); | |
231 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); |
|
231 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); | |
232 |
|
232 | |||
233 | // Hide all from background when there is only piechart |
|
233 | // Hide all from background when there is only piechart | |
234 | // TODO: refactor this ugly code... should be one setting for this |
|
234 | // TODO: refactor this ugly code... should be one setting for this | |
235 | if (m_chartItems.count() == 0) { |
|
235 | if (m_chartItems.count() == 0) { | |
236 | m_chart->axisX()->setAxisVisible(false); |
|
236 | m_chart->axisX()->setAxisVisible(false); | |
237 | m_chart->axisY()->setAxisVisible(false); |
|
237 | m_chart->axisY()->setAxisVisible(false); | |
238 | m_chart->axisX()->setGridVisible(false); |
|
238 | m_chart->axisX()->setGridVisible(false); | |
239 | m_chart->axisY()->setGridVisible(false); |
|
239 | m_chart->axisY()->setGridVisible(false); | |
240 | m_chart->axisX()->setLabelsVisible(false); |
|
240 | m_chart->axisX()->setLabelsVisible(false); | |
241 | m_chart->axisY()->setLabelsVisible(false); |
|
241 | m_chart->axisY()->setLabelsVisible(false); | |
242 | m_chart->axisX()->setShadesVisible(false); |
|
242 | m_chart->axisX()->setShadesVisible(false); | |
243 | m_chart->axisY()->setShadesVisible(false); |
|
243 | m_chart->axisY()->setShadesVisible(false); | |
244 | m_chart->setChartBackgroundBrush(Qt::transparent); |
|
244 | m_chart->setChartBackgroundBrush(Qt::transparent); | |
245 | } |
|
245 | } | |
246 |
|
246 | |||
247 | m_chartItems.insert(series, pie); |
|
247 | m_chartItems.insert(series, pie); | |
248 | pie->handleGeometryChanged(m_rect); |
|
248 | pie->handleGeometryChanged(m_rect); | |
249 | break; |
|
249 | break; | |
250 | } |
|
250 | } | |
251 |
|
251 | |||
252 | case QSeries::SeriesTypeSpline: { |
|
252 | case QSeries::SeriesTypeSpline: { | |
253 | QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(series); |
|
253 | QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(series); | |
254 | SplinePresenter* splinePresenter = new SplinePresenter(splineSeries, m_chart); |
|
254 | SplinePresenter* splinePresenter = new SplinePresenter(splineSeries, m_chart); | |
255 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), splinePresenter, SLOT(handleGeometryChanged(const QRectF&))); |
|
255 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), splinePresenter, SLOT(handleGeometryChanged(const QRectF&))); | |
|
256 | //initialize | |||
|
257 | splinePresenter->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); | |||
256 | m_chartTheme->decorate(splinePresenter, splineSeries, m_chartItems.count()); |
|
258 | m_chartTheme->decorate(splinePresenter, splineSeries, m_chartItems.count()); | |
257 | m_chartItems.insert(splineSeries, splinePresenter); |
|
259 | m_chartItems.insert(splineSeries, splinePresenter); | |
258 | break; |
|
260 | break; | |
259 | } |
|
261 | } | |
260 | default: { |
|
262 | default: { | |
261 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
263 | qDebug()<< "Series type" << series->type() << "not implemented."; | |
262 | break; |
|
264 | break; | |
263 | } |
|
265 | } | |
264 | } |
|
266 | } | |
265 |
|
267 | |||
266 | zoomReset(); |
|
268 | zoomReset(); | |
267 | } |
|
269 | } | |
268 |
|
270 | |||
269 | void ChartPresenter::handleSeriesRemoved(QSeries* series) |
|
271 | void ChartPresenter::handleSeriesRemoved(QSeries* series) | |
270 | { |
|
272 | { | |
271 | ChartItem* item = m_chartItems.take(series); |
|
273 | ChartItem* item = m_chartItems.take(series); | |
272 | delete item; |
|
274 | delete item; | |
273 | } |
|
275 | } | |
274 |
|
276 | |||
275 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) |
|
277 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) | |
276 | { |
|
278 | { | |
277 | delete m_chartTheme; |
|
279 | delete m_chartTheme; | |
278 |
|
280 | |||
279 | m_chartTheme = ChartTheme::createTheme(theme); |
|
281 | m_chartTheme = ChartTheme::createTheme(theme); | |
280 |
|
282 | |||
281 | m_chartTheme->decorate(m_chart); |
|
283 | m_chartTheme->decorate(m_chart); | |
282 | QMapIterator<QSeries*,ChartItem*> i(m_chartItems); |
|
284 | QMapIterator<QSeries*,ChartItem*> i(m_chartItems); | |
283 |
|
285 | |||
284 | int index=0; |
|
286 | int index=0; | |
285 | while (i.hasNext()) { |
|
287 | while (i.hasNext()) { | |
286 | i.next(); |
|
288 | i.next(); | |
287 | m_chartTheme->decorate(i.value(),i.key(),index); |
|
289 | m_chartTheme->decorate(i.value(),i.key(),index); | |
288 | index++; |
|
290 | index++; | |
289 | } |
|
291 | } | |
290 |
|
292 | |||
291 | QMapIterator<QChartAxis*,AxisItem*> j(m_axisItems); |
|
293 | QMapIterator<QChartAxis*,AxisItem*> j(m_axisItems); | |
292 | while (j.hasNext()) { |
|
294 | while (j.hasNext()) { | |
293 | j.next(); |
|
295 | j.next(); | |
294 | m_chartTheme->decorate(j.key(),j.value()); |
|
296 | m_chartTheme->decorate(j.key(),j.value()); | |
295 | } |
|
297 | } | |
296 | } |
|
298 | } | |
297 |
|
299 | |||
298 | QChart::ChartTheme ChartPresenter::chartTheme() |
|
300 | QChart::ChartTheme ChartPresenter::chartTheme() | |
299 | { |
|
301 | { | |
300 | return m_chartTheme->id(); |
|
302 | return m_chartTheme->id(); | |
301 | } |
|
303 | } | |
302 |
|
304 | |||
303 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
305 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |
304 | { |
|
306 | { | |
305 | if(m_options!=options) { |
|
307 | if(m_options!=options) { | |
306 |
|
308 | |||
307 | m_options=options; |
|
309 | m_options=options; | |
308 |
|
310 | |||
309 | //recreate elements |
|
311 | //recreate elements | |
310 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); |
|
312 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); | |
311 | QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); |
|
313 | QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); | |
312 |
|
314 | |||
313 | foreach(QChartAxis* axis, axisList) { |
|
315 | foreach(QChartAxis* axis, axisList) { | |
314 | handleAxisRemoved(axis); |
|
316 | handleAxisRemoved(axis); | |
315 | handleAxisAdded(axis,m_dataset->domain(axis)); |
|
317 | handleAxisAdded(axis,m_dataset->domain(axis)); | |
316 | } |
|
318 | } | |
317 | foreach(QSeries* series, seriesList) { |
|
319 | foreach(QSeries* series, seriesList) { | |
318 | handleSeriesRemoved(series); |
|
320 | handleSeriesRemoved(series); | |
319 | handleSeriesAdded(series,m_dataset->domain(series)); |
|
321 | handleSeriesAdded(series,m_dataset->domain(series)); | |
320 | } |
|
322 | } | |
321 | } |
|
323 | } | |
322 | } |
|
324 | } | |
323 |
|
325 | |||
324 | void ChartPresenter::zoomIn() |
|
326 | void ChartPresenter::zoomIn() | |
325 | { |
|
327 | { | |
326 | QRectF rect = geometry(); |
|
328 | QRectF rect = geometry(); | |
327 | rect.setWidth(rect.width()/2); |
|
329 | rect.setWidth(rect.width()/2); | |
328 | rect.setHeight(rect.height()/2); |
|
330 | rect.setHeight(rect.height()/2); | |
329 | rect.moveCenter(geometry().center()); |
|
331 | rect.moveCenter(geometry().center()); | |
330 | zoomIn(rect); |
|
332 | zoomIn(rect); | |
331 | } |
|
333 | } | |
332 |
|
334 | |||
333 | void ChartPresenter::zoomIn(const QRectF& rect) |
|
335 | void ChartPresenter::zoomIn(const QRectF& rect) | |
334 | { |
|
336 | { | |
335 | QRectF r = rect.normalized(); |
|
337 | QRectF r = rect.normalized(); | |
336 | r.translate(-m_marginSize, -m_marginSize); |
|
338 | r.translate(-m_marginSize, -m_marginSize); | |
337 | m_dataset->zoomInDomain(r,geometry().size()); |
|
339 | m_dataset->zoomInDomain(r,geometry().size()); | |
338 | m_zoomStack<<r; |
|
340 | m_zoomStack<<r; | |
339 | m_zoomIndex++; |
|
341 | m_zoomIndex++; | |
340 | } |
|
342 | } | |
341 |
|
343 | |||
342 | void ChartPresenter::zoomOut() |
|
344 | void ChartPresenter::zoomOut() | |
343 | { |
|
345 | { | |
344 | if(m_zoomIndex==0) return; |
|
346 | if(m_zoomIndex==0) return; | |
345 | m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size()); |
|
347 | m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size()); | |
346 | m_zoomIndex--; |
|
348 | m_zoomIndex--; | |
347 | m_zoomStack.resize(m_zoomIndex); |
|
349 | m_zoomStack.resize(m_zoomIndex); | |
348 | } |
|
350 | } | |
349 |
|
351 | |||
350 | void ChartPresenter::zoomReset() |
|
352 | void ChartPresenter::zoomReset() | |
351 | { |
|
353 | { | |
352 | m_zoomIndex=0; |
|
354 | m_zoomIndex=0; | |
353 | m_zoomStack.resize(m_zoomIndex); |
|
355 | m_zoomStack.resize(m_zoomIndex); | |
354 | } |
|
356 | } | |
355 |
|
357 | |||
356 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
|
358 | QChart::AnimationOptions ChartPresenter::animationOptions() const | |
357 | { |
|
359 | { | |
358 | return m_options; |
|
360 | return m_options; | |
359 | } |
|
361 | } | |
360 |
|
362 | |||
361 |
|
363 | |||
362 | #include "moc_chartpresenter_p.cpp" |
|
364 | #include "moc_chartpresenter_p.cpp" | |
363 |
|
365 | |||
364 | QTCOMMERCIALCHART_END_NAMESPACE |
|
366 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,77 +1,77 | |||||
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 | QPainterPath splinePath; |
|
28 | QPainterPath splinePath; | |
29 | const QPointF& point = points.at(0); |
|
29 | const QPointF& point = points.at(0); | |
30 | splinePath.moveTo(point); |
|
30 | splinePath.moveTo(point); | |
31 |
|
31 | |||
32 | // QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series); |
|
32 | // QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series); | |
33 | for (int i = 0; i < points.size() - 1; i++) |
|
33 | for (int i = 0; i < points.size() - 1; i++) | |
34 | { |
|
34 | { | |
35 | const QPointF& point = points.at(i + 1); |
|
35 | const QPointF& point = points.at(i + 1); | |
36 | splinePath.cubicTo(calculateGeometryControlPoint(2 * i), calculateGeometryControlPoint(2 * i + 1), point); |
|
36 | splinePath.cubicTo(calculateGeometryControlPoint(2 * i), calculateGeometryControlPoint(2 * i + 1), point); | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 |
|
39 | |||
40 |
|
40 | |||
41 | prepareGeometryChange(); |
|
41 | prepareGeometryChange(); | |
42 | m_path = splinePath; |
|
42 | m_path = splinePath; | |
43 | m_rect = splinePath.boundingRect(); |
|
43 | m_rect = splinePath.boundingRect(); | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | void SplinePresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
46 | void SplinePresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
47 | { |
|
47 | { | |
48 | Q_UNUSED(widget); |
|
48 | Q_UNUSED(widget); | |
49 | Q_UNUSED(option); |
|
49 | Q_UNUSED(option); | |
50 | painter->save(); |
|
50 | painter->save(); | |
51 | painter->setPen(m_pen); |
|
51 | painter->setPen(m_pen); | |
52 | painter->setClipRect(m_clipRect); |
|
52 | painter->setClipRect(m_clipRect); | |
53 | painter->drawPath(m_path); |
|
53 | painter->drawPath(m_path); | |
54 |
|
54 | |||
55 | QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series); |
|
55 | QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series); | |
56 |
for (int i = 0; i < |
|
56 | for (int i = 0; i < m_points.size() - 1; i++) | |
57 | { |
|
57 | { | |
58 | painter->setPen(Qt::red); |
|
58 | painter->setPen(Qt::red); | |
59 | painter->drawEllipse(m_points[i], 2, 2); |
|
59 | painter->drawEllipse(m_points[i], 2, 2); | |
60 |
|
60 | |||
61 | painter->setPen(Qt::blue); |
|
61 | painter->setPen(Qt::blue); | |
62 | // painter->drawLine(m_series->at(i), m_series->controlPoint(2 * i)); |
|
62 | // painter->drawLine(m_series->at(i), m_series->controlPoint(2 * i)); | |
63 | // painter->drawLine(m_series->at(i + 1), m_series->controlPoint(2 * i + 1)); |
|
63 | // painter->drawLine(m_series->at(i + 1), m_series->controlPoint(2 * i + 1)); | |
64 | // painter->drawEllipse(calculateGeometryControlPoint(2 * i), 4, 4); |
|
64 | // painter->drawEllipse(calculateGeometryControlPoint(2 * i), 4, 4); | |
65 | // painter->drawEllipse(calculateGeometryControlPoint(2 * i + 1), 4, 4); |
|
65 | // painter->drawEllipse(calculateGeometryControlPoint(2 * i + 1), 4, 4); | |
66 | } |
|
66 | } | |
67 | if (m_points.count() > 0) |
|
67 | if (m_points.count() > 0) | |
68 | { |
|
68 | { | |
69 | painter->setPen(Qt::red); |
|
69 | painter->setPen(Qt::red); | |
70 | painter->drawEllipse(m_points[m_points.count() - 1], 2, 2); |
|
70 | painter->drawEllipse(m_points[m_points.count() - 1], 2, 2); | |
71 | } |
|
71 | } | |
72 | painter->restore(); |
|
72 | painter->restore(); | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | #include "moc_splinepresenter_p.cpp" |
|
75 | #include "moc_splinepresenter_p.cpp" | |
76 |
|
76 | |||
77 | QTCOMMERCIALCHART_END_NAMESPACE |
|
77 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now