@@ -1,62 +1,62 | |||||
1 | #include <QApplication> |
|
1 | #include <QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <qchartview.h> |
|
3 | #include <qchartview.h> | |
4 | #include <qlinechartseries.h> |
|
4 | #include <qlinechartseries.h> | |
5 | #include <qchart.h> |
|
5 | #include <qchart.h> | |
6 | #include <qchartaxis.h> |
|
6 | #include <qchartaxis.h> | |
7 | #include <cmath> |
|
7 | #include <cmath> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
9 | QTCOMMERCIALCHART_USE_NAMESPACE | |
10 |
|
10 | |||
11 | #define PI 3.14159265358979 |
|
11 | #define PI 3.14159265358979 | |
12 |
|
12 | |||
13 | int main(int argc, char *argv[]) |
|
13 | int main(int argc, char *argv[]) | |
14 | { |
|
14 | { | |
15 | QApplication a(argc, argv); |
|
15 | QApplication a(argc, argv); | |
16 |
|
16 | |||
17 | QMainWindow window; |
|
17 | QMainWindow window; | |
18 |
|
18 | |||
19 | QLineChartSeries* series0 = new QLineChartSeries(); |
|
19 | QLineChartSeries* series0 = new QLineChartSeries(); | |
20 | QPen blue(Qt::blue); |
|
20 | QPen blue(Qt::blue); | |
21 | blue.setWidth(3); |
|
21 | blue.setWidth(3); | |
22 | series0->setPen(blue); |
|
22 | series0->setPen(blue); | |
23 | QLineChartSeries* series1 = new QLineChartSeries(); |
|
23 | QLineChartSeries* series1 = new QLineChartSeries(); | |
24 | QPen red(Qt::red); |
|
24 | QPen red(Qt::red); | |
25 | red.setWidth(3); |
|
25 | red.setWidth(3); | |
26 | series1->setPen(red); |
|
26 | series1->setPen(red); | |
27 |
|
27 | |||
28 | int numPoints = 100; |
|
28 | int numPoints = 100; | |
29 |
|
29 | |||
30 | for (int x = 0; x <= numPoints; ++x) { |
|
30 | for (int x = 0; x <= numPoints; ++x) { | |
31 | series0->add(x, fabs(sin(PI/50*x)*100)); |
|
31 | series0->add(x, fabs(sin(PI/50*x)*100)); | |
32 | series1->add(x, fabs(cos(PI/50*x)*100)); |
|
32 | series1->add(x, fabs(cos(PI/50*x)*100)); | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | QChartView* chartView = new QChartView(&window); |
|
35 | QChartView* chartView = new QChartView(&window); | |
36 |
|
36 | |||
37 | chartView->setRenderHint(QPainter::Antialiasing); |
|
37 | chartView->setRenderHint(QPainter::Antialiasing); | |
38 |
chartView->setTitle(" |
|
38 | chartView->setChartTitle("This is custom axis chart example"); | |
39 | chartView->addSeries(series0); |
|
39 | chartView->addSeries(series0); | |
40 | chartView->addSeries(series1); |
|
40 | chartView->addSeries(series1); | |
41 |
|
41 | |||
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 axis = chartView->defaultAxisX(); |
|
49 | QChartAxis axis = chartView->defaultAxisX(); | |
50 | axis.setLabelsOrientation(QChartAxis::LabelsOrientationSlide); |
|
50 | axis.setLabelsOrientation(QChartAxis::LabelsOrientationSlide); | |
51 | axis.setGridPen(Qt::DashLine); |
|
51 | axis.setGridPen(Qt::DashLine); | |
52 |
|
52 | |||
53 | chartView->setDefaultAxisX(axis); |
|
53 | chartView->setDefaultAxisX(axis); | |
54 | axis.setShadesBrush(Qt::yellow); |
|
54 | axis.setShadesBrush(Qt::yellow); | |
55 | chartView->setDefaultAxisY(axis); |
|
55 | chartView->setDefaultAxisY(axis); | |
56 |
|
56 | |||
57 | window.setCentralWidget(chartView); |
|
57 | window.setCentralWidget(chartView); | |
58 | window.resize(400, 300); |
|
58 | window.resize(400, 300); | |
59 | window.show(); |
|
59 | window.show(); | |
60 |
|
60 | |||
61 | return a.exec(); |
|
61 | return a.exec(); | |
62 | } |
|
62 | } |
@@ -1,51 +1,55 | |||||
1 | #include <QApplication> |
|
1 | #include <QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <qchartview.h> |
|
3 | #include <qchartview.h> | |
4 | #include <qlinechartseries.h> |
|
4 | #include <qlinechartseries.h> | |
5 | #include <qchart.h> |
|
5 | #include <qchart.h> | |
6 | #include <cmath> |
|
6 | #include <cmath> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
8 | QTCOMMERCIALCHART_USE_NAMESPACE | |
9 |
|
9 | |||
10 | #define PI 3.14159265358979 |
|
10 | #define PI 3.14159265358979 | |
11 |
|
11 | |||
12 | int main(int argc, char *argv[]) |
|
12 | int main(int argc, char *argv[]) | |
13 | { |
|
13 | { | |
14 | QApplication a(argc, argv); |
|
14 | QApplication a(argc, argv); | |
15 |
|
15 | |||
16 | QMainWindow window; |
|
16 | QMainWindow window; | |
17 |
|
17 | |||
18 | QLineChartSeries* series0 = new QLineChartSeries(); |
|
18 | QLineChartSeries* series0 = new QLineChartSeries(); | |
19 | QPen blue(Qt::blue); |
|
19 | QPen blue(Qt::blue); | |
20 | blue.setWidth(3); |
|
20 | blue.setWidth(3); | |
21 | series0->setPen(blue); |
|
21 | series0->setPen(blue); | |
22 | QLineChartSeries* series1 = new QLineChartSeries(); |
|
22 | QLineChartSeries* series1 = new QLineChartSeries(); | |
23 | QPen red(Qt::red); |
|
23 | QPen red(Qt::red); | |
24 | red.setWidth(3); |
|
24 | red.setWidth(3); | |
25 | series1->setPen(red); |
|
25 | series1->setPen(red); | |
26 |
|
26 | |||
27 | int numPoints = 100; |
|
27 | int numPoints = 100; | |
28 |
|
28 | |||
29 | for (int x = 0; x <= numPoints; ++x) { |
|
29 | for (int x = 0; x <= numPoints; ++x) { | |
30 | series0->add(x, fabs(sin(PI/50*x)*100)); |
|
30 | series0->add(x, fabs(sin(PI/50*x)*100)); | |
31 | series1->add(x, fabs(cos(PI/50*x)*100)); |
|
31 | series1->add(x, fabs(cos(PI/50*x)*100)); | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | QChartView* chartView = new QChartView(&window); |
|
34 | QChartView* chartView = new QChartView(&window); | |
35 | chartView->setRenderHint(QPainter::Antialiasing); |
|
35 | chartView->setRenderHint(QPainter::Antialiasing); | |
36 | chartView->setTitle("Custom color line chart example"); |
|
36 | ||
|
37 | QFont font; | |||
|
38 | font.setPixelSize(18); | |||
|
39 | chartView->setChartTitleFont(font); | |||
|
40 | chartView->setChartTitle("Custom color line chart example"); | |||
37 | chartView->addSeries(series0); |
|
41 | chartView->addSeries(series0); | |
38 | chartView->addSeries(series1); |
|
42 | chartView->addSeries(series1); | |
39 |
|
43 | |||
40 | QLinearGradient backgroundGradient; |
|
44 | QLinearGradient backgroundGradient; | |
41 | backgroundGradient.setColorAt(0.0, Qt::blue); |
|
45 | backgroundGradient.setColorAt(0.0, Qt::blue); | |
42 | backgroundGradient.setColorAt(1.0, Qt::yellow); |
|
46 | backgroundGradient.setColorAt(1.0, Qt::yellow); | |
43 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
47 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
44 | chartView->setChartBackgroundBrush(backgroundGradient); |
|
48 | chartView->setChartBackgroundBrush(backgroundGradient); | |
45 |
|
49 | |||
46 | window.setCentralWidget(chartView); |
|
50 | window.setCentralWidget(chartView); | |
47 | window.resize(400, 300); |
|
51 | window.resize(400, 300); | |
48 | window.show(); |
|
52 | window.show(); | |
49 |
|
53 | |||
50 | return a.exec(); |
|
54 | return a.exec(); | |
51 | } |
|
55 | } |
@@ -1,40 +1,40 | |||||
1 | #include <QApplication> |
|
1 | #include <QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <qchartview.h> |
|
3 | #include <qchartview.h> | |
4 | #include <qlinechartseries.h> |
|
4 | #include <qlinechartseries.h> | |
5 | #include <qchart.h> |
|
5 | #include <qchart.h> | |
6 | #include <cmath> |
|
6 | #include <cmath> | |
7 | #include "wavegenerator.h" |
|
7 | #include "wavegenerator.h" | |
8 | #include <QGLWidget> |
|
8 | #include <QGLWidget> | |
9 |
|
9 | |||
10 | int main(int argc, char *argv[]) |
|
10 | int main(int argc, char *argv[]) | |
11 | { |
|
11 | { | |
12 | QApplication a(argc, argv); |
|
12 | QApplication a(argc, argv); | |
13 |
|
13 | |||
14 | QMainWindow window; |
|
14 | QMainWindow window; | |
15 |
|
15 | |||
16 | QLineChartSeries* series0 = new QLineChartSeries(); |
|
16 | QLineChartSeries* series0 = new QLineChartSeries(); | |
17 | QPen blue(Qt::blue); |
|
17 | QPen blue(Qt::blue); | |
18 | blue.setWidth(3); |
|
18 | blue.setWidth(3); | |
19 | series0->setPen(blue); |
|
19 | series0->setPen(blue); | |
20 | QLineChartSeries* series1 = new QLineChartSeries(); |
|
20 | QLineChartSeries* series1 = new QLineChartSeries(); | |
21 | QPen red(Qt::red); |
|
21 | QPen red(Qt::red); | |
22 | red.setWidth(3); |
|
22 | red.setWidth(3); | |
23 | series1->setPen(red); |
|
23 | series1->setPen(red); | |
24 |
|
24 | |||
25 | WaveGenerator generator(series0,series1); |
|
25 | WaveGenerator generator(series0,series1); | |
26 |
|
26 | |||
27 | QChartView* chartView = new QChartView(&window); |
|
27 | QChartView* chartView = new QChartView(&window); | |
28 |
|
28 | |||
29 | chartView->setViewport( new QGLWidget() ); |
|
29 | chartView->setViewport( new QGLWidget() ); | |
30 | chartView->setRenderHint(QPainter::Antialiasing); |
|
30 | chartView->setRenderHint(QPainter::Antialiasing); | |
31 | chartView->setTitle("This is wave generator buahha."); |
|
31 | chartView->setChartTitle("This is wave generator buahha."); | |
32 | chartView->addSeries(series0); |
|
32 | chartView->addSeries(series0); | |
33 | chartView->addSeries(series1); |
|
33 | chartView->addSeries(series1); | |
34 |
|
34 | |||
35 | window.setCentralWidget(chartView); |
|
35 | window.setCentralWidget(chartView); | |
36 | window.resize(400, 300); |
|
36 | window.resize(400, 300); | |
37 | window.show(); |
|
37 | window.show(); | |
38 |
|
38 | |||
39 | return a.exec(); |
|
39 | return a.exec(); | |
40 | } |
|
40 | } |
@@ -1,46 +1,46 | |||||
1 | #include <QApplication> |
|
1 | #include <QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <qchartview.h> |
|
3 | #include <qchartview.h> | |
4 | #include <qlinechartseries.h> |
|
4 | #include <qlinechartseries.h> | |
5 | #include <qchart.h> |
|
5 | #include <qchart.h> | |
6 | #include <cmath> |
|
6 | #include <cmath> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
8 | QTCOMMERCIALCHART_USE_NAMESPACE | |
9 |
|
9 | |||
10 | #define PI 3.14159265358979 |
|
10 | #define PI 3.14159265358979 | |
11 |
|
11 | |||
12 | int main(int argc, char *argv[]) |
|
12 | int main(int argc, char *argv[]) | |
13 | { |
|
13 | { | |
14 | QApplication a(argc, argv); |
|
14 | QApplication a(argc, argv); | |
15 |
|
15 | |||
16 | QMainWindow window; |
|
16 | QMainWindow window; | |
17 |
|
17 | |||
18 | QLineChartSeries* series0 = new QLineChartSeries(); |
|
18 | QLineChartSeries* series0 = new QLineChartSeries(); | |
19 | QPen blue(Qt::blue); |
|
19 | QPen blue(Qt::blue); | |
20 | blue.setWidth(3); |
|
20 | blue.setWidth(3); | |
21 | series0->setPen(blue); |
|
21 | series0->setPen(blue); | |
22 | QLineChartSeries* series1 = new QLineChartSeries(); |
|
22 | QLineChartSeries* series1 = new QLineChartSeries(); | |
23 | QPen red(Qt::red); |
|
23 | QPen red(Qt::red); | |
24 | red.setWidth(3); |
|
24 | red.setWidth(3); | |
25 | series1->setPen(red); |
|
25 | series1->setPen(red); | |
26 |
|
26 | |||
27 | int numPoints = 100; |
|
27 | int numPoints = 100; | |
28 |
|
28 | |||
29 | for (int x = 0; x <= numPoints; ++x) { |
|
29 | for (int x = 0; x <= numPoints; ++x) { | |
30 | series0->add(x, fabs(sin(PI/50*x)*100)); |
|
30 | series0->add(x, fabs(sin(PI/50*x)*100)); | |
31 | series1->add(x, fabs(cos(PI/50*x)*100)); |
|
31 | series1->add(x, fabs(cos(PI/50*x)*100)); | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | QChartView* chartView = new QChartView(&window); |
|
34 | QChartView* chartView = new QChartView(&window); | |
35 |
|
35 | |||
36 | chartView->setRenderHint(QPainter::Antialiasing); |
|
36 | chartView->setRenderHint(QPainter::Antialiasing); | |
37 | chartView->setTitle("Basic line chart example"); |
|
37 | chartView->setChartTitle("Basic line chart example"); | |
38 | chartView->addSeries(series0); |
|
38 | chartView->addSeries(series0); | |
39 | chartView->addSeries(series1); |
|
39 | chartView->addSeries(series1); | |
40 |
|
40 | |||
41 | window.setCentralWidget(chartView); |
|
41 | window.setCentralWidget(chartView); | |
42 | window.resize(400, 300); |
|
42 | window.resize(400, 300); | |
43 | window.show(); |
|
43 | window.show(); | |
44 |
|
44 | |||
45 | return a.exec(); |
|
45 | return a.exec(); | |
46 | } |
|
46 | } |
@@ -1,44 +1,44 | |||||
1 | #include "chartwidget.h" |
|
1 | #include "chartwidget.h" | |
2 | #include <QApplication> |
|
2 | #include <QApplication> | |
3 | #include <QMainWindow> |
|
3 | #include <QMainWindow> | |
4 | #include <qlinechartseries.h> |
|
4 | #include <qlinechartseries.h> | |
5 | #include <cmath> |
|
5 | #include <cmath> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
7 | QTCOMMERCIALCHART_USE_NAMESPACE | |
8 |
|
8 | |||
9 | #define PI 3.14159265358979 |
|
9 | #define PI 3.14159265358979 | |
10 |
|
10 | |||
11 | int main(int argc, char *argv[]) |
|
11 | int main(int argc, char *argv[]) | |
12 | { |
|
12 | { | |
13 | QApplication a(argc, argv); |
|
13 | QApplication a(argc, argv); | |
14 |
|
14 | |||
15 | QMainWindow window; |
|
15 | QMainWindow window; | |
16 |
|
16 | |||
17 | QLineChartSeries* series0 = new QLineChartSeries(); |
|
17 | QLineChartSeries* series0 = new QLineChartSeries(); | |
18 | QPen blue(Qt::blue); |
|
18 | QPen blue(Qt::blue); | |
19 | blue.setWidth(3); |
|
19 | blue.setWidth(3); | |
20 | series0->setPen(blue); |
|
20 | series0->setPen(blue); | |
21 | QLineChartSeries* series1 = new QLineChartSeries(); |
|
21 | QLineChartSeries* series1 = new QLineChartSeries(); | |
22 | QPen red(Qt::red); |
|
22 | QPen red(Qt::red); | |
23 | red.setWidth(3); |
|
23 | red.setWidth(3); | |
24 | series1->setPen(red); |
|
24 | series1->setPen(red); | |
25 |
|
25 | |||
26 | int numPoints = 100; |
|
26 | int numPoints = 100; | |
27 |
|
27 | |||
28 | for (int x = 0; x <= numPoints; ++x) { |
|
28 | for (int x = 0; x <= numPoints; ++x) { | |
29 | series0->add(x, fabs(sin(PI/50*x)*100)); |
|
29 | series0->add(x, fabs(sin(PI/50*x)*100)); | |
30 | series1->add(x, fabs(cos(PI/50*x)*100)); |
|
30 | series1->add(x, fabs(cos(PI/50*x)*100)); | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | ChartWidget* chartWidget = new ChartWidget(&window); |
|
33 | ChartWidget* chartWidget = new ChartWidget(&window); | |
34 | chartWidget->setRenderHint(QPainter::Antialiasing); |
|
34 | chartWidget->setRenderHint(QPainter::Antialiasing); | |
35 | chartWidget->setTitle("Zoom in/out line chart example"); |
|
35 | chartWidget->setChartTitle("Zoom in/out line chart example"); | |
36 | chartWidget->addSeries(series0); |
|
36 | chartWidget->addSeries(series0); | |
37 | chartWidget->addSeries(series1); |
|
37 | chartWidget->addSeries(series1); | |
38 |
|
38 | |||
39 | window.setCentralWidget(chartWidget); |
|
39 | window.setCentralWidget(chartWidget); | |
40 | window.resize(400, 300); |
|
40 | window.resize(400, 300); | |
41 | window.show(); |
|
41 | window.show(); | |
42 |
|
42 | |||
43 | return a.exec(); |
|
43 | return a.exec(); | |
44 | } |
|
44 | } |
@@ -1,204 +1,209 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qscatterseries.h" |
|
2 | #include "qscatterseries.h" | |
3 | #include "qscatterseries_p.h" |
|
3 | #include "qscatterseries_p.h" | |
4 | #include "qpieseries.h" |
|
4 | #include "qpieseries.h" | |
5 | #include "qchartaxis.h" |
|
5 | #include "qchartaxis.h" | |
6 | #include "chartpresenter_p.h" |
|
6 | #include "chartpresenter_p.h" | |
7 | #include "chartdataset_p.h" |
|
7 | #include "chartdataset_p.h" | |
8 |
|
8 | |||
9 | //series |
|
9 | //series | |
10 | #include "barchartseries.h" |
|
10 | #include "barchartseries.h" | |
11 | #include "stackedbarchartseries.h" |
|
11 | #include "stackedbarchartseries.h" | |
12 | #include "percentbarchartseries.h" |
|
12 | #include "percentbarchartseries.h" | |
13 | #include "qlinechartseries.h" |
|
13 | #include "qlinechartseries.h" | |
14 |
|
14 | |||
15 | #include <QGraphicsScene> |
|
15 | #include <QGraphicsScene> | |
16 | #include <QGraphicsSceneResizeEvent> |
|
16 | #include <QGraphicsSceneResizeEvent> | |
17 | #include <QDebug> |
|
17 | #include <QDebug> | |
18 |
|
18 | |||
19 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
19 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
20 |
|
20 | |||
21 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
21 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
22 | m_backgroundItem(0), |
|
22 | m_backgroundItem(0), | |
23 | m_titleItem(0), |
|
23 | m_titleItem(0), | |
24 | m_dataset(new ChartDataSet(this)), |
|
24 | m_dataset(new ChartDataSet(this)), | |
25 | m_presenter(new ChartPresenter(this,m_dataset)) |
|
25 | m_presenter(new ChartPresenter(this,m_dataset)) | |
26 | { |
|
26 | { | |
27 | } |
|
27 | } | |
28 |
|
28 | |||
29 | QChart::~QChart() {} |
|
29 | QChart::~QChart() {} | |
30 |
|
30 | |||
31 | void QChart::addSeries(QChartSeries* series) |
|
31 | void QChart::addSeries(QChartSeries* series) | |
32 | { |
|
32 | { | |
33 | m_dataset->addSeries(series); |
|
33 | m_dataset->addSeries(series); | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | //TODO on review, is it really needed ?? |
|
36 | //TODO on review, is it really needed ?? | |
37 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) |
|
37 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) | |
38 | { |
|
38 | { | |
39 | QChartSeries *series(0); |
|
39 | QChartSeries *series(0); | |
40 |
|
40 | |||
41 | switch (type) { |
|
41 | switch (type) { | |
42 | case QChartSeries::SeriesTypeLine: { |
|
42 | case QChartSeries::SeriesTypeLine: { | |
43 | series = new QLineChartSeries(this); |
|
43 | series = new QLineChartSeries(this); | |
44 | break; |
|
44 | break; | |
45 | } |
|
45 | } | |
46 | case QChartSeries::SeriesTypeBar: { |
|
46 | case QChartSeries::SeriesTypeBar: { | |
47 | //series = new BarChartSeries(this); |
|
47 | //series = new BarChartSeries(this); | |
48 | break; |
|
48 | break; | |
49 | } |
|
49 | } | |
50 | case QChartSeries::SeriesTypeStackedBar: { |
|
50 | case QChartSeries::SeriesTypeStackedBar: { | |
51 | //series = new StackedBarChartSeries(this); |
|
51 | //series = new StackedBarChartSeries(this); | |
52 | break; |
|
52 | break; | |
53 | } |
|
53 | } | |
54 | case QChartSeries::SeriesTypePercentBar: { |
|
54 | case QChartSeries::SeriesTypePercentBar: { | |
55 | //series = new PercentBarChartSeries(this); |
|
55 | //series = new PercentBarChartSeries(this); | |
56 | break; |
|
56 | break; | |
57 | } |
|
57 | } | |
58 | case QChartSeries::SeriesTypeScatter: { |
|
58 | case QChartSeries::SeriesTypeScatter: { | |
59 | series = new QScatterSeries(this); |
|
59 | series = new QScatterSeries(this); | |
60 | break; |
|
60 | break; | |
61 | } |
|
61 | } | |
62 | case QChartSeries::SeriesTypePie: { |
|
62 | case QChartSeries::SeriesTypePie: { | |
63 | series = new QPieSeries(this); |
|
63 | series = new QPieSeries(this); | |
64 | break; |
|
64 | break; | |
65 | } |
|
65 | } | |
66 | default: |
|
66 | default: | |
67 | Q_ASSERT(false); |
|
67 | Q_ASSERT(false); | |
68 | break; |
|
68 | break; | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | addSeries(series); |
|
71 | addSeries(series); | |
72 | return series; |
|
72 | return series; | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void QChart::setChartBackgroundBrush(const QBrush& brush) |
|
75 | void QChart::setChartBackgroundBrush(const QBrush& brush) | |
76 | { |
|
76 | { | |
77 |
|
77 | |||
78 | if(!m_backgroundItem) { |
|
78 | if(!m_backgroundItem) { | |
79 | m_backgroundItem = new QGraphicsRectItem(this); |
|
79 | m_backgroundItem = new QGraphicsRectItem(this); | |
80 | m_backgroundItem->setZValue(-1); |
|
80 | m_backgroundItem->setZValue(-1); | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | m_backgroundItem->setBrush(brush); |
|
83 | m_backgroundItem->setBrush(brush); | |
84 | m_backgroundItem->update(); |
|
84 | m_backgroundItem->update(); | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | void QChart::setChartBackgroundPen(const QPen& pen) |
|
87 | void QChart::setChartBackgroundPen(const QPen& pen) | |
88 | { |
|
88 | { | |
89 |
|
89 | |||
90 | if(!m_backgroundItem) { |
|
90 | if(!m_backgroundItem) { | |
91 | m_backgroundItem = new QGraphicsRectItem(this); |
|
91 | m_backgroundItem = new QGraphicsRectItem(this); | |
92 | m_backgroundItem->setZValue(-1); |
|
92 | m_backgroundItem->setZValue(-1); | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 | m_backgroundItem->setPen(pen); |
|
95 | m_backgroundItem->setPen(pen); | |
96 | m_backgroundItem->update(); |
|
96 | m_backgroundItem->update(); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 |
void QChart::setTitle(const QString& title |
|
99 | void QChart::setChartTitle(const QString& title) | |
100 | { |
|
100 | { | |
101 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); |
|
101 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); | |
102 | m_titleItem->setPlainText(title); |
|
102 | m_titleItem->setPlainText(title); | |
|
103 | } | |||
|
104 | ||||
|
105 | void QChart::setChartTitleFont(const QFont& font) | |||
|
106 | { | |||
|
107 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); | |||
103 | m_titleItem->setFont(font); |
|
108 | m_titleItem->setFont(font); | |
104 | } |
|
109 | } | |
105 |
|
110 | |||
106 | int QChart::margin() const |
|
111 | int QChart::margin() const | |
107 | { |
|
112 | { | |
108 | return m_presenter->margin(); |
|
113 | return m_presenter->margin(); | |
109 | } |
|
114 | } | |
110 |
|
115 | |||
111 | void QChart::setMargin(int margin) |
|
116 | void QChart::setMargin(int margin) | |
112 | { |
|
117 | { | |
113 | m_presenter->setMargin(margin); |
|
118 | m_presenter->setMargin(margin); | |
114 | } |
|
119 | } | |
115 |
|
120 | |||
116 | void QChart::setChartTheme(QChart::ChartTheme theme) |
|
121 | void QChart::setChartTheme(QChart::ChartTheme theme) | |
117 | { |
|
122 | { | |
118 | m_presenter->setChartTheme(theme); |
|
123 | m_presenter->setChartTheme(theme); | |
119 | } |
|
124 | } | |
120 |
|
125 | |||
121 | QChart::ChartTheme QChart::chartTheme() const |
|
126 | QChart::ChartTheme QChart::chartTheme() const | |
122 | { |
|
127 | { | |
123 | return m_presenter->chartTheme(); |
|
128 | return m_presenter->chartTheme(); | |
124 | } |
|
129 | } | |
125 |
|
130 | |||
126 | void QChart::zoomInToRect(const QRectF& rectangle) |
|
131 | void QChart::zoomInToRect(const QRectF& rectangle) | |
127 | { |
|
132 | { | |
128 | m_presenter->zoomInToRect(rectangle); |
|
133 | m_presenter->zoomInToRect(rectangle); | |
129 | } |
|
134 | } | |
130 |
|
135 | |||
131 | void QChart::zoomIn() |
|
136 | void QChart::zoomIn() | |
132 | { |
|
137 | { | |
133 | m_presenter->zoomIn(); |
|
138 | m_presenter->zoomIn(); | |
134 | } |
|
139 | } | |
135 |
|
140 | |||
136 | void QChart::zoomOut() |
|
141 | void QChart::zoomOut() | |
137 | { |
|
142 | { | |
138 | m_presenter->zoomOut(); |
|
143 | m_presenter->zoomOut(); | |
139 | } |
|
144 | } | |
140 |
|
145 | |||
141 | void QChart::zoomReset() |
|
146 | void QChart::zoomReset() | |
142 | { |
|
147 | { | |
143 | m_presenter->zoomReset(); |
|
148 | m_presenter->zoomReset(); | |
144 | } |
|
149 | } | |
145 |
|
150 | |||
146 | void QChart::setDefaultAxisX(const QChartAxis& axis) |
|
151 | void QChart::setDefaultAxisX(const QChartAxis& axis) | |
147 | { |
|
152 | { | |
148 | m_presenter->setDefaultAxisX(axis); |
|
153 | m_presenter->setDefaultAxisX(axis); | |
149 | } |
|
154 | } | |
150 |
|
155 | |||
151 | void QChart::setDefaultAxisY(const QChartAxis& axis) |
|
156 | void QChart::setDefaultAxisY(const QChartAxis& axis) | |
152 | { |
|
157 | { | |
153 | m_presenter->setDefaultAxisY(axis); |
|
158 | m_presenter->setDefaultAxisY(axis); | |
154 | } |
|
159 | } | |
155 |
|
160 | |||
156 | QChartAxis QChart::defaultAxisX() const |
|
161 | QChartAxis QChart::defaultAxisX() const | |
157 | { |
|
162 | { | |
158 | return m_presenter->defaultAxisX(); |
|
163 | return m_presenter->defaultAxisX(); | |
159 | } |
|
164 | } | |
160 |
|
165 | |||
161 | QChartAxis QChart::defaultAxisY() const |
|
166 | QChartAxis QChart::defaultAxisY() const | |
162 | { |
|
167 | { | |
163 | return m_presenter->defaultAxisY(); |
|
168 | return m_presenter->defaultAxisY(); | |
164 | } |
|
169 | } | |
165 |
|
170 | |||
166 | int QChart::addAxisY(const QChartAxis& axis) |
|
171 | int QChart::addAxisY(const QChartAxis& axis) | |
167 | { |
|
172 | { | |
168 | return m_presenter->addAxisY(axis); |
|
173 | return m_presenter->addAxisY(axis); | |
169 | } |
|
174 | } | |
170 |
|
175 | |||
171 | QChartAxis QChart::axisY(int id) const |
|
176 | QChartAxis QChart::axisY(int id) const | |
172 | { |
|
177 | { | |
173 | return m_presenter->axisY(id); |
|
178 | return m_presenter->axisY(id); | |
174 | } |
|
179 | } | |
175 |
|
180 | |||
176 | void QChart::removeAxisY(int id) |
|
181 | void QChart::removeAxisY(int id) | |
177 | { |
|
182 | { | |
178 | m_presenter->removeAxisY(id); |
|
183 | m_presenter->removeAxisY(id); | |
179 | } |
|
184 | } | |
180 |
|
185 | |||
181 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
186 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
182 | { |
|
187 | { | |
183 |
|
188 | |||
184 | m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
189 | m_rect = QRectF(QPoint(0,0),event->newSize()); | |
185 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
190 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
186 |
|
191 | |||
187 | // recalculate title position |
|
192 | // recalculate title position | |
188 | if (m_titleItem) { |
|
193 | if (m_titleItem) { | |
189 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
194 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
190 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); |
|
195 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); | |
191 | } |
|
196 | } | |
192 |
|
197 | |||
193 | //recalculate background gradient |
|
198 | //recalculate background gradient | |
194 | if (m_backgroundItem) { |
|
199 | if (m_backgroundItem) { | |
195 | m_backgroundItem->setRect(rect); |
|
200 | m_backgroundItem->setRect(rect); | |
196 | } |
|
201 | } | |
197 |
|
202 | |||
198 | QGraphicsWidget::resizeEvent(event); |
|
203 | QGraphicsWidget::resizeEvent(event); | |
199 | update(); |
|
204 | update(); | |
200 | } |
|
205 | } | |
201 |
|
206 | |||
202 | #include "moc_qchart.cpp" |
|
207 | #include "moc_qchart.cpp" | |
203 |
|
208 | |||
204 | QTCOMMERCIALCHART_END_NAMESPACE |
|
209 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,92 +1,93 | |||||
1 | #ifndef CHART_H |
|
1 | #ifndef CHART_H | |
2 | #define CHART_H |
|
2 | #define CHART_H | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <qchartseries.h> |
|
5 | #include <qchartseries.h> | |
6 | #include <QGraphicsWidget> |
|
6 | #include <QGraphicsWidget> | |
7 | #include <QLinearGradient> |
|
7 | #include <QLinearGradient> | |
8 | #include <QFont> |
|
8 | #include <QFont> | |
9 |
|
9 | |||
10 | class QGraphicsSceneResizeEvent; |
|
10 | class QGraphicsSceneResizeEvent; | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
13 |
|
13 | |||
14 | class AxisItem; |
|
14 | class AxisItem; | |
15 | class QChartSeries; |
|
15 | class QChartSeries; | |
16 | class PlotDomain; |
|
16 | class PlotDomain; | |
17 | class BarGroup; |
|
17 | class BarGroup; | |
18 | class QChartAxis; |
|
18 | class QChartAxis; | |
19 | class ChartTheme; |
|
19 | class ChartTheme; | |
20 | class ChartItem; |
|
20 | class ChartItem; | |
21 | class ChartDataSet; |
|
21 | class ChartDataSet; | |
22 | class ChartPresenter; |
|
22 | class ChartPresenter; | |
23 |
|
23 | |||
24 | // TODO: We don't need to have QChart tied to QGraphicsItem: |
|
24 | // TODO: We don't need to have QChart tied to QGraphicsItem: | |
25 | //class QTCOMMERCIALCHART_EXPORT QChart |
|
25 | //class QTCOMMERCIALCHART_EXPORT QChart | |
26 | //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem { |
|
26 | //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem { | |
27 | // public: QChartGraphicsItem(QChart &chart); |
|
27 | // public: QChartGraphicsItem(QChart &chart); | |
28 |
|
28 | |||
29 | /*! |
|
29 | /*! | |
30 | * TODO: define the responsibilities |
|
30 | * TODO: define the responsibilities | |
31 | */ |
|
31 | */ | |
32 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
32 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget | |
33 | { |
|
33 | { | |
34 | Q_OBJECT |
|
34 | Q_OBJECT | |
35 | public: |
|
35 | public: | |
36 | enum ChartTheme { |
|
36 | enum ChartTheme { | |
37 | /*! The default theme follows the GUI style of the Operating System */ |
|
37 | /*! The default theme follows the GUI style of the Operating System */ | |
38 | ChartThemeDefault, |
|
38 | ChartThemeDefault, | |
39 | ChartThemeVanilla, |
|
39 | ChartThemeVanilla, | |
40 | ChartThemeIcy, |
|
40 | ChartThemeIcy, | |
41 | ChartThemeGrayscale, |
|
41 | ChartThemeGrayscale, | |
42 | ChartThemeScientific, |
|
42 | ChartThemeScientific, | |
43 | //ChartThemeUnnamed1 |
|
43 | //ChartThemeUnnamed1 | |
44 | }; |
|
44 | }; | |
45 |
|
45 | |||
46 | public: |
|
46 | public: | |
47 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
47 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |
48 | ~QChart(); |
|
48 | ~QChart(); | |
49 |
|
49 | |||
50 | void addSeries(QChartSeries* series); |
|
50 | void addSeries(QChartSeries* series); | |
51 |
|
51 | |||
52 | //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type); |
|
52 | //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type); | |
53 | // TODO: who owns the series now? maybe owned by chart and returned a reference instead... |
|
53 | // TODO: who owns the series now? maybe owned by chart and returned a reference instead... | |
54 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); |
|
54 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); | |
55 |
|
55 | |||
56 | void setMargin(int margin); |
|
56 | void setMargin(int margin); | |
57 | int margin() const; |
|
57 | int margin() const; | |
58 | void setChartTheme(QChart::ChartTheme theme); |
|
58 | void setChartTheme(QChart::ChartTheme theme); | |
59 | QChart::ChartTheme chartTheme() const; |
|
59 | QChart::ChartTheme chartTheme() const; | |
60 |
|
60 | |||
61 |
void setTitle(const QString& title |
|
61 | void setChartTitle(const QString& title); | |
|
62 | void setChartTitleFont(const QFont& font); | |||
62 | void setChartBackgroundBrush(const QBrush& brush); |
|
63 | void setChartBackgroundBrush(const QBrush& brush); | |
63 | void setChartBackgroundPen(const QPen& pen); |
|
64 | void setChartBackgroundPen(const QPen& pen); | |
64 |
|
65 | |||
65 | void zoomInToRect(const QRectF& rectangle); |
|
66 | void zoomInToRect(const QRectF& rectangle); | |
66 | void zoomIn(); |
|
67 | void zoomIn(); | |
67 | void zoomOut(); |
|
68 | void zoomOut(); | |
68 | void zoomReset(); |
|
69 | void zoomReset(); | |
69 |
|
70 | |||
70 | void setDefaultAxisX(const QChartAxis& axis); |
|
71 | void setDefaultAxisX(const QChartAxis& axis); | |
71 | void setDefaultAxisY(const QChartAxis& axis); |
|
72 | void setDefaultAxisY(const QChartAxis& axis); | |
72 | QChartAxis defaultAxisX() const; |
|
73 | QChartAxis defaultAxisX() const; | |
73 | QChartAxis defaultAxisY() const; |
|
74 | QChartAxis defaultAxisY() const; | |
74 | QChartAxis axisY(int id) const; |
|
75 | QChartAxis axisY(int id) const; | |
75 | int addAxisY(const QChartAxis& axis); |
|
76 | int addAxisY(const QChartAxis& axis); | |
76 | void removeAxisY(int id); |
|
77 | void removeAxisY(int id); | |
77 |
|
78 | |||
78 | protected: |
|
79 | protected: | |
79 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
80 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
80 |
|
81 | |||
81 | private: |
|
82 | private: | |
82 | Q_DISABLE_COPY(QChart) |
|
83 | Q_DISABLE_COPY(QChart) | |
83 | QGraphicsRectItem* m_backgroundItem; |
|
84 | QGraphicsRectItem* m_backgroundItem; | |
84 | QGraphicsTextItem* m_titleItem; |
|
85 | QGraphicsTextItem* m_titleItem; | |
85 | QRectF m_rect; |
|
86 | QRectF m_rect; | |
86 | ChartDataSet *m_dataset; |
|
87 | ChartDataSet *m_dataset; | |
87 | ChartPresenter *m_presenter; |
|
88 | ChartPresenter *m_presenter; | |
88 | }; |
|
89 | }; | |
89 |
|
90 | |||
90 | QTCOMMERCIALCHART_END_NAMESPACE |
|
91 | QTCOMMERCIALCHART_END_NAMESPACE | |
91 |
|
92 | |||
92 | #endif |
|
93 | #endif |
@@ -1,236 +1,241 | |||||
1 | #include "qchartview.h" |
|
1 | #include "qchartview.h" | |
2 | #include "qchart.h" |
|
2 | #include "qchart.h" | |
3 | #include "qchartaxis.h" |
|
3 | #include "qchartaxis.h" | |
4 | #include <QGraphicsView> |
|
4 | #include <QGraphicsView> | |
5 | #include <QGraphicsScene> |
|
5 | #include <QGraphicsScene> | |
6 | #include <QRubberBand> |
|
6 | #include <QRubberBand> | |
7 | #include <QResizeEvent> |
|
7 | #include <QResizeEvent> | |
8 | #include <QDebug> |
|
8 | #include <QDebug> | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
|
11 | |||
12 | QChartView::QChartView(QWidget *parent) : |
|
12 | QChartView::QChartView(QWidget *parent) : | |
13 | QGraphicsView(parent), |
|
13 | QGraphicsView(parent), | |
14 | m_scene(new QGraphicsScene()), |
|
14 | m_scene(new QGraphicsScene()), | |
15 | m_chart(new QChart()), |
|
15 | m_chart(new QChart()), | |
16 | m_rubberBand(0), |
|
16 | m_rubberBand(0), | |
17 | m_verticalRubberBand(false), |
|
17 | m_verticalRubberBand(false), | |
18 | m_horizonalRubberBand(false) |
|
18 | m_horizonalRubberBand(false) | |
19 | { |
|
19 | { | |
20 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
20 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
21 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
21 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
22 | setScene(m_scene); |
|
22 | setScene(m_scene); | |
23 | m_chart->setMargin(50); |
|
23 | m_chart->setMargin(50); | |
24 | m_scene->addItem(m_chart); |
|
24 | m_scene->addItem(m_chart); | |
25 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
25 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
26 | } |
|
26 | } | |
27 |
|
27 | |||
28 | QChartView::~QChartView() |
|
28 | QChartView::~QChartView() | |
29 | { |
|
29 | { | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | void QChartView::resizeEvent(QResizeEvent *event) |
|
32 | void QChartView::resizeEvent(QResizeEvent *event) | |
33 | { |
|
33 | { | |
34 | m_scene->setSceneRect(0,0,size().width(),size().height()); |
|
34 | m_scene->setSceneRect(0,0,size().width(),size().height()); | |
35 | m_chart->resize(size()); |
|
35 | m_chart->resize(size()); | |
36 | QWidget::resizeEvent(event); |
|
36 | QWidget::resizeEvent(event); | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | void QChartView::addSeries(QChartSeries* series) |
|
39 | void QChartView::addSeries(QChartSeries* series) | |
40 | { |
|
40 | { | |
41 | m_chart->addSeries(series); |
|
41 | m_chart->addSeries(series); | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | QChartSeries* QChartView::createSeries(QChartSeries::QChartSeriesType type) |
|
44 | QChartSeries* QChartView::createSeries(QChartSeries::QChartSeriesType type) | |
45 | { |
|
45 | { | |
46 |
|
46 | |||
47 | return m_chart->createSeries(type); |
|
47 | return m_chart->createSeries(type); | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | void QChartView::zoomInToRect(const QRect& rectangle) |
|
50 | void QChartView::zoomInToRect(const QRect& rectangle) | |
51 | { |
|
51 | { | |
52 | m_chart->zoomInToRect(rectangle); |
|
52 | m_chart->zoomInToRect(rectangle); | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | void QChartView::zoomIn() |
|
55 | void QChartView::zoomIn() | |
56 | { |
|
56 | { | |
57 | m_chart->zoomIn(); |
|
57 | m_chart->zoomIn(); | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | void QChartView::zoomOut() |
|
60 | void QChartView::zoomOut() | |
61 | { |
|
61 | { | |
62 | m_chart->zoomOut(); |
|
62 | m_chart->zoomOut(); | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | int QChartView::margin() const |
|
65 | int QChartView::margin() const | |
66 | { |
|
66 | { | |
67 | return m_chart->margin(); |
|
67 | return m_chart->margin(); | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | void QChartView::setTitle(const QString& title) |
|
70 | void QChartView::setChartTitle(const QString& title) | |
71 | { |
|
71 | { | |
72 | m_chart->setTitle(title); |
|
72 | m_chart->setChartTitle(title); | |
|
73 | } | |||
|
74 | ||||
|
75 | void QChartView::setChartTitleFont(const QFont& font) | |||
|
76 | { | |||
|
77 | m_chart->setChartTitleFont(font); | |||
73 | } |
|
78 | } | |
74 |
|
79 | |||
75 | void QChartView::setChartBackgroundBrush(const QBrush& brush) |
|
80 | void QChartView::setChartBackgroundBrush(const QBrush& brush) | |
76 | { |
|
81 | { | |
77 | m_chart->setChartBackgroundBrush(brush); |
|
82 | m_chart->setChartBackgroundBrush(brush); | |
78 | } |
|
83 | } | |
79 | void QChartView::setChartBackgroundPen(const QPen& pen) |
|
84 | void QChartView::setChartBackgroundPen(const QPen& pen) | |
80 | { |
|
85 | { | |
81 | m_chart->setChartBackgroundPen(pen); |
|
86 | m_chart->setChartBackgroundPen(pen); | |
82 | } |
|
87 | } | |
83 |
|
88 | |||
84 | void QChartView::setRubberBandPolicy(const RubberBandPolicy policy) |
|
89 | void QChartView::setRubberBandPolicy(const RubberBandPolicy policy) | |
85 | { |
|
90 | { | |
86 | switch(policy) { |
|
91 | switch(policy) { | |
87 | case VerticalRubberBand: |
|
92 | case VerticalRubberBand: | |
88 | m_verticalRubberBand = true; |
|
93 | m_verticalRubberBand = true; | |
89 | m_horizonalRubberBand = false; |
|
94 | m_horizonalRubberBand = false; | |
90 | break; |
|
95 | break; | |
91 | case HorizonalRubberBand: |
|
96 | case HorizonalRubberBand: | |
92 | m_verticalRubberBand = false; |
|
97 | m_verticalRubberBand = false; | |
93 | m_horizonalRubberBand = true; |
|
98 | m_horizonalRubberBand = true; | |
94 | break; |
|
99 | break; | |
95 | case RectangleRubberBand: |
|
100 | case RectangleRubberBand: | |
96 | m_verticalRubberBand = true; |
|
101 | m_verticalRubberBand = true; | |
97 | m_horizonalRubberBand = true; |
|
102 | m_horizonalRubberBand = true; | |
98 | break; |
|
103 | break; | |
99 | case NoRubberBand: |
|
104 | case NoRubberBand: | |
100 | default: |
|
105 | default: | |
101 | delete m_rubberBand; |
|
106 | delete m_rubberBand; | |
102 | m_rubberBand=0; |
|
107 | m_rubberBand=0; | |
103 | m_horizonalRubberBand = false; |
|
108 | m_horizonalRubberBand = false; | |
104 | m_verticalRubberBand = false; |
|
109 | m_verticalRubberBand = false; | |
105 | return; |
|
110 | return; | |
106 | } |
|
111 | } | |
107 | if(!m_rubberBand) { |
|
112 | if(!m_rubberBand) { | |
108 | m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); |
|
113 | m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); | |
109 | m_rubberBand->setEnabled(true); |
|
114 | m_rubberBand->setEnabled(true); | |
110 | } |
|
115 | } | |
111 | } |
|
116 | } | |
112 |
|
117 | |||
113 | QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const |
|
118 | QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const | |
114 | { |
|
119 | { | |
115 | if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand; |
|
120 | if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand; | |
116 | if(m_horizonalRubberBand) return HorizonalRubberBand; |
|
121 | if(m_horizonalRubberBand) return HorizonalRubberBand; | |
117 | if(m_verticalRubberBand) return VerticalRubberBand; |
|
122 | if(m_verticalRubberBand) return VerticalRubberBand; | |
118 | return NoRubberBand; |
|
123 | return NoRubberBand; | |
119 | } |
|
124 | } | |
120 |
|
125 | |||
121 | void QChartView::mousePressEvent(QMouseEvent *event) |
|
126 | void QChartView::mousePressEvent(QMouseEvent *event) | |
122 | { |
|
127 | { | |
123 | if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { |
|
128 | if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { | |
124 |
|
129 | |||
125 | int margin = m_chart->margin(); |
|
130 | int margin = m_chart->margin(); | |
126 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); |
|
131 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); | |
127 |
|
132 | |||
128 | if (rect.contains(event->pos())) { |
|
133 | if (rect.contains(event->pos())) { | |
129 | m_rubberBandOrigin = event->pos(); |
|
134 | m_rubberBandOrigin = event->pos(); | |
130 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize())); |
|
135 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize())); | |
131 | m_rubberBand->show(); |
|
136 | m_rubberBand->show(); | |
132 | event->accept(); |
|
137 | event->accept(); | |
133 | } |
|
138 | } | |
134 | } |
|
139 | } | |
135 | } |
|
140 | } | |
136 |
|
141 | |||
137 | void QChartView::mouseMoveEvent(QMouseEvent *event) |
|
142 | void QChartView::mouseMoveEvent(QMouseEvent *event) | |
138 | { |
|
143 | { | |
139 | if(m_rubberBand && m_rubberBand->isVisible()) { |
|
144 | if(m_rubberBand && m_rubberBand->isVisible()) { | |
140 | int margin = m_chart->margin(); |
|
145 | int margin = m_chart->margin(); | |
141 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); |
|
146 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); | |
142 | int width = event->pos().x() - m_rubberBandOrigin.x(); |
|
147 | int width = event->pos().x() - m_rubberBandOrigin.x(); | |
143 | int height = event->pos().y() - m_rubberBandOrigin.y(); |
|
148 | int height = event->pos().y() - m_rubberBandOrigin.y(); | |
144 | if(!m_verticalRubberBand) { |
|
149 | if(!m_verticalRubberBand) { | |
145 | m_rubberBandOrigin.setY(rect.top()); |
|
150 | m_rubberBandOrigin.setY(rect.top()); | |
146 | height = rect.height(); |
|
151 | height = rect.height(); | |
147 | } |
|
152 | } | |
148 | if(!m_horizonalRubberBand) { |
|
153 | if(!m_horizonalRubberBand) { | |
149 | m_rubberBandOrigin.setX(rect.left()); |
|
154 | m_rubberBandOrigin.setX(rect.left()); | |
150 | width= rect.width(); |
|
155 | width= rect.width(); | |
151 | } |
|
156 | } | |
152 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized()); |
|
157 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized()); | |
153 | } |
|
158 | } | |
154 | else { |
|
159 | else { | |
155 | QGraphicsView::mouseMoveEvent(event); |
|
160 | QGraphicsView::mouseMoveEvent(event); | |
156 | } |
|
161 | } | |
157 | } |
|
162 | } | |
158 |
|
163 | |||
159 | void QChartView::mouseReleaseEvent(QMouseEvent *event) |
|
164 | void QChartView::mouseReleaseEvent(QMouseEvent *event) | |
160 | { |
|
165 | { | |
161 | if(m_rubberBand) { |
|
166 | if(m_rubberBand) { | |
162 | if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) { |
|
167 | if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) { | |
163 | m_rubberBand->hide(); |
|
168 | m_rubberBand->hide(); | |
164 | QRect rect = m_rubberBand->geometry(); |
|
169 | QRect rect = m_rubberBand->geometry(); | |
165 | m_chart->zoomInToRect(rect); |
|
170 | m_chart->zoomInToRect(rect); | |
166 | event->accept(); |
|
171 | event->accept(); | |
167 | } |
|
172 | } | |
168 |
|
173 | |||
169 | if(event->button()==Qt::RightButton) |
|
174 | if(event->button()==Qt::RightButton) | |
170 | m_chart->zoomReset(); |
|
175 | m_chart->zoomReset(); | |
171 | } |
|
176 | } | |
172 | else { |
|
177 | else { | |
173 | QGraphicsView::mouseReleaseEvent(event); |
|
178 | QGraphicsView::mouseReleaseEvent(event); | |
174 | } |
|
179 | } | |
175 | } |
|
180 | } | |
176 |
|
181 | |||
177 | void QChartView::keyPressEvent(QKeyEvent *event) |
|
182 | void QChartView::keyPressEvent(QKeyEvent *event) | |
178 | { |
|
183 | { | |
179 | switch (event->key()) { |
|
184 | switch (event->key()) { | |
180 | case Qt::Key_Plus: |
|
185 | case Qt::Key_Plus: | |
181 | zoomIn(); |
|
186 | zoomIn(); | |
182 | break; |
|
187 | break; | |
183 | case Qt::Key_Minus: |
|
188 | case Qt::Key_Minus: | |
184 | zoomOut(); |
|
189 | zoomOut(); | |
185 | break; |
|
190 | break; | |
186 | default: |
|
191 | default: | |
187 | QGraphicsView::keyPressEvent(event); |
|
192 | QGraphicsView::keyPressEvent(event); | |
188 | break; |
|
193 | break; | |
189 | } |
|
194 | } | |
190 | } |
|
195 | } | |
191 |
|
196 | |||
192 | void QChartView::setChartTheme(QChart::ChartTheme theme) |
|
197 | void QChartView::setChartTheme(QChart::ChartTheme theme) | |
193 | { |
|
198 | { | |
194 | m_chart->setChartTheme(theme); |
|
199 | m_chart->setChartTheme(theme); | |
195 | } |
|
200 | } | |
196 |
|
201 | |||
197 | QChart::ChartTheme QChartView::chartTheme() const |
|
202 | QChart::ChartTheme QChartView::chartTheme() const | |
198 | { |
|
203 | { | |
199 | return m_chart->chartTheme(); |
|
204 | return m_chart->chartTheme(); | |
200 | } |
|
205 | } | |
201 |
|
206 | |||
202 | void QChartView::setDefaultAxisX(const QChartAxis& axis) |
|
207 | void QChartView::setDefaultAxisX(const QChartAxis& axis) | |
203 | { |
|
208 | { | |
204 | m_chart->setDefaultAxisX(axis); |
|
209 | m_chart->setDefaultAxisX(axis); | |
205 | } |
|
210 | } | |
206 |
|
211 | |||
207 | void QChartView::setDefaultAxisY(const QChartAxis& axis) |
|
212 | void QChartView::setDefaultAxisY(const QChartAxis& axis) | |
208 | { |
|
213 | { | |
209 | m_chart->setDefaultAxisY(axis); |
|
214 | m_chart->setDefaultAxisY(axis); | |
210 | } |
|
215 | } | |
211 |
|
216 | |||
212 | QChartAxis QChartView::defaultAxisX() const |
|
217 | QChartAxis QChartView::defaultAxisX() const | |
213 | { |
|
218 | { | |
214 | return m_chart->defaultAxisX(); |
|
219 | return m_chart->defaultAxisX(); | |
215 | } |
|
220 | } | |
216 |
|
221 | |||
217 | QChartAxis QChartView::defaultAxisY() const |
|
222 | QChartAxis QChartView::defaultAxisY() const | |
218 | { |
|
223 | { | |
219 | return m_chart->defaultAxisY(); |
|
224 | return m_chart->defaultAxisY(); | |
220 | } |
|
225 | } | |
221 |
|
226 | |||
222 | int QChartView::addAxisY(const QChartAxis& axis) |
|
227 | int QChartView::addAxisY(const QChartAxis& axis) | |
223 | { |
|
228 | { | |
224 | return m_chart->addAxisY(axis); |
|
229 | return m_chart->addAxisY(axis); | |
225 | } |
|
230 | } | |
226 |
|
231 | |||
227 | QChartAxis QChartView::axisY(int id) const |
|
232 | QChartAxis QChartView::axisY(int id) const | |
228 | { |
|
233 | { | |
229 | return m_chart->axisY(id); |
|
234 | return m_chart->axisY(id); | |
230 | } |
|
235 | } | |
231 |
|
236 | |||
232 | void QChartView::removeAxisY(int id) |
|
237 | void QChartView::removeAxisY(int id) | |
233 | { |
|
238 | { | |
234 | m_chart->removeAxisY(id); |
|
239 | m_chart->removeAxisY(id); | |
235 | } |
|
240 | } | |
236 | QTCOMMERCIALCHART_END_NAMESPACE |
|
241 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,77 +1,78 | |||||
1 | #ifndef QCHARTWIDGET_H |
|
1 | #ifndef QCHARTWIDGET_H | |
2 | #define QCHARTWIDGET_H |
|
2 | #define QCHARTWIDGET_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qchartseries.h" |
|
5 | #include "qchartseries.h" | |
6 | #include "qchart.h" |
|
6 | #include "qchart.h" | |
7 | #include <QGraphicsView> |
|
7 | #include <QGraphicsView> | |
8 |
|
8 | |||
9 | class QGraphicsScene; |
|
9 | class QGraphicsScene; | |
10 | class QRubberBand; |
|
10 | class QRubberBand; | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
13 |
|
13 | |||
14 | class QChart; |
|
14 | class QChart; | |
15 |
|
15 | |||
16 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView |
|
16 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView | |
17 | { |
|
17 | { | |
18 | public: |
|
18 | public: | |
19 | enum RubberBandPolicy { NoRubberBand, VerticalRubberBand, HorizonalRubberBand, RectangleRubberBand }; |
|
19 | enum RubberBandPolicy { NoRubberBand, VerticalRubberBand, HorizonalRubberBand, RectangleRubberBand }; | |
20 |
|
20 | |||
21 | explicit QChartView(QWidget *parent = 0); |
|
21 | explicit QChartView(QWidget *parent = 0); | |
22 | ~QChartView(); |
|
22 | ~QChartView(); | |
23 |
|
23 | |||
24 | //implement from QWidget |
|
24 | //implement from QWidget | |
25 | void resizeEvent(QResizeEvent *event); |
|
25 | void resizeEvent(QResizeEvent *event); | |
26 |
|
26 | |||
27 | void addSeries(QChartSeries* series); |
|
27 | void addSeries(QChartSeries* series); | |
28 |
|
28 | |||
29 | // Convenience function |
|
29 | // Convenience function | |
30 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); |
|
30 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); | |
31 |
|
31 | |||
32 | int margin() const; |
|
32 | int margin() const; | |
33 |
|
33 | |||
34 | void setTitle(const QString& title); |
|
34 | void setChartTitle(const QString& title); | |
|
35 | void setChartTitleFont(const QFont& font); | |||
35 | void setChartBackgroundBrush(const QBrush& brush); |
|
36 | void setChartBackgroundBrush(const QBrush& brush); | |
36 | void setChartBackgroundPen(const QPen& pen); |
|
37 | void setChartBackgroundPen(const QPen& pen); | |
37 |
|
38 | |||
38 | void zoomInToRect(const QRect& rectangle); |
|
39 | void zoomInToRect(const QRect& rectangle); | |
39 | void zoomIn(); |
|
40 | void zoomIn(); | |
40 | void zoomOut(); |
|
41 | void zoomOut(); | |
41 |
|
42 | |||
42 | void setRubberBandPolicy(const RubberBandPolicy ); |
|
43 | void setRubberBandPolicy(const RubberBandPolicy ); | |
43 | RubberBandPolicy rubberBandPolicy() const; |
|
44 | RubberBandPolicy rubberBandPolicy() const; | |
44 |
|
45 | |||
45 | void setChartTheme(QChart::ChartTheme theme); |
|
46 | void setChartTheme(QChart::ChartTheme theme); | |
46 | QChart::ChartTheme chartTheme() const; |
|
47 | QChart::ChartTheme chartTheme() const; | |
47 |
|
48 | |||
48 | void setDefaultAxisX(const QChartAxis& axis); |
|
49 | void setDefaultAxisX(const QChartAxis& axis); | |
49 | void setDefaultAxisY(const QChartAxis& axis); |
|
50 | void setDefaultAxisY(const QChartAxis& axis); | |
50 | QChartAxis defaultAxisX() const; |
|
51 | QChartAxis defaultAxisX() const; | |
51 | QChartAxis defaultAxisY() const; |
|
52 | QChartAxis defaultAxisY() const; | |
52 | QChartAxis axisY(int id) const; |
|
53 | QChartAxis axisY(int id) const; | |
53 | int addAxisY(const QChartAxis& axis); |
|
54 | int addAxisY(const QChartAxis& axis); | |
54 | void removeAxisY(int id); |
|
55 | void removeAxisY(int id); | |
55 |
|
56 | |||
56 | protected: |
|
57 | protected: | |
57 | void mousePressEvent(QMouseEvent *event); |
|
58 | void mousePressEvent(QMouseEvent *event); | |
58 | void mouseMoveEvent(QMouseEvent *event); |
|
59 | void mouseMoveEvent(QMouseEvent *event); | |
59 | void mouseReleaseEvent(QMouseEvent *event); |
|
60 | void mouseReleaseEvent(QMouseEvent *event); | |
60 | void keyPressEvent(QKeyEvent *event); |
|
61 | void keyPressEvent(QKeyEvent *event); | |
61 |
|
62 | |||
62 |
|
63 | |||
63 | private: |
|
64 | private: | |
64 | QGraphicsScene *m_scene; |
|
65 | QGraphicsScene *m_scene; | |
65 | QChart* m_chart; |
|
66 | QChart* m_chart; | |
66 | QPoint m_rubberBandOrigin; |
|
67 | QPoint m_rubberBandOrigin; | |
67 | QRubberBand* m_rubberBand; |
|
68 | QRubberBand* m_rubberBand; | |
68 | bool m_verticalRubberBand; |
|
69 | bool m_verticalRubberBand; | |
69 | bool m_horizonalRubberBand; |
|
70 | bool m_horizonalRubberBand; | |
70 | Q_DISABLE_COPY(QChartView) |
|
71 | Q_DISABLE_COPY(QChartView) | |
71 |
|
72 | |||
72 |
|
73 | |||
73 | }; |
|
74 | }; | |
74 |
|
75 | |||
75 | QTCOMMERCIALCHART_END_NAMESPACE |
|
76 | QTCOMMERCIALCHART_END_NAMESPACE | |
76 |
|
77 | |||
77 | #endif // QCHARTWIDGET_H |
|
78 | #endif // QCHARTWIDGET_H |
General Comments 0
You need to be logged in to leave comments.
Login now