@@ -1,51 +1,51 | |||||
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 = 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 = 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 | chartView->setTitle("Custom color line chart example"); | |
37 | chartView->addSeries(series0); |
|
37 | chartView->addSeries(series0); | |
38 | chartView->addSeries(series1); |
|
38 | chartView->addSeries(series1); | |
39 |
|
39 | |||
40 | QLinearGradient backgroundGradient; |
|
40 | QLinearGradient backgroundGradient; | |
41 | backgroundGradient.setColorAt(0.0, Qt::blue); |
|
41 | backgroundGradient.setColorAt(0.0, Qt::blue); | |
42 | backgroundGradient.setColorAt(1.0, Qt::yellow); |
|
42 | backgroundGradient.setColorAt(1.0, Qt::yellow); | |
43 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
43 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
44 | chartView->setChartBackgroundBrush(backgroundGradient); |
|
44 | chartView->setChartBackgroundBrush(backgroundGradient); | |
45 |
|
45 | |||
46 | window.setCentralWidget(chartView); |
|
46 | window.setCentralWidget(chartView); | |
47 | window.resize(400, 300); |
|
47 | window.resize(400, 300); | |
48 | window.show(); |
|
48 | window.show(); | |
49 |
|
49 | |||
50 | return a.exec(); |
|
50 | return a.exec(); | |
51 | } |
|
51 | } |
@@ -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 = 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 = 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->setTitle("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 = 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 = 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->setTitle("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 = 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 = 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->setTitle("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,292 +1,272 | |||||
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 "barchartseries.h" |
|
7 | #include "barchartseries.h" | |
8 | #include "stackedbarchartseries.h" |
|
8 | #include "stackedbarchartseries.h" | |
9 | #include "percentbarchartseries.h" |
|
9 | #include "percentbarchartseries.h" | |
10 | #include "qlinechartseries.h" |
|
10 | #include "qlinechartseries.h" | |
11 | #include "qpieseries.h" |
|
11 | #include "qpieseries.h" | |
12 | //items |
|
12 | //items | |
13 | #include "axisitem_p.h" |
|
13 | #include "axisitem_p.h" | |
14 | #include "bargroup.h" |
|
14 | #include "bargroup.h" | |
15 | #include "stackedbargroup.h" |
|
15 | #include "stackedbargroup.h" | |
16 | #include "linechartitem_p.h" |
|
16 | #include "linechartitem_p.h" | |
17 | #include "percentbargroup.h" |
|
17 | #include "percentbargroup.h" | |
18 | #include "linechartanimationitem_p.h" |
|
18 | #include "linechartanimationitem_p.h" | |
19 | #include "piepresenter.h" |
|
19 | #include "piepresenter.h" | |
20 |
|
20 | |||
21 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
21 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
22 |
|
22 | |||
23 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
23 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | |
24 | m_chart(chart), |
|
24 | m_chart(chart), | |
25 | m_dataset(dataset), |
|
25 | m_dataset(dataset), | |
26 | m_chartTheme(0), |
|
26 | m_chartTheme(0), | |
27 | m_domainIndex(0), |
|
27 | m_domainIndex(0), | |
28 | m_marginSize(0), |
|
28 | m_marginSize(0), | |
29 | m_axisX(new QChartAxis(this)), |
|
29 | m_axisX(new QChartAxis(this)), | |
30 | m_axisY(new QChartAxis(this)), |
|
30 | m_axisY(new QChartAxis(this)), | |
31 | m_rect(QRectF(QPoint(0,0),m_chart->size())) |
|
31 | m_rect(QRectF(QPoint(0,0),m_chart->size())) | |
32 | { |
|
32 | { | |
33 | setChartTheme(QChart::ChartThemeDefault); |
|
33 | setChartTheme(QChart::ChartThemeDefault); | |
34 | m_axisItems[m_axisX] = new AxisItem(m_axisX,AxisItem::X_AXIS,m_chart); |
|
34 | m_axisItems[m_axisX] = new AxisItem(m_axisX,AxisItem::X_AXIS,m_chart); | |
35 | m_axisItems[m_axisY] = new AxisItem(m_axisY,AxisItem::Y_AXIS,m_chart); |
|
35 | m_axisItems[m_axisY] = new AxisItem(m_axisY,AxisItem::Y_AXIS,m_chart); | |
36 | createConnections(); |
|
36 | createConnections(); | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | ChartPresenter::~ChartPresenter() |
|
39 | ChartPresenter::~ChartPresenter() | |
40 | { |
|
40 | { | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | void ChartPresenter::createConnections() |
|
43 | void ChartPresenter::createConnections() | |
44 | { |
|
44 | { | |
45 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
45 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); | |
46 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); |
|
46 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); | |
47 |
|
47 | |||
48 | QMapIterator<QChartAxis*,AxisItem*> i(m_axisItems); |
|
48 | QMapIterator<QChartAxis*,AxisItem*> i(m_axisItems); | |
49 |
|
49 | |||
50 | while (i.hasNext()) { |
|
50 | while (i.hasNext()) { | |
51 | i.next(); |
|
51 | i.next(); | |
52 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),i.value(),SLOT(handleGeometryChanged(const QRectF&))); |
|
52 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),i.value(),SLOT(handleGeometryChanged(const QRectF&))); | |
53 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),i.value(),SLOT(handleDomainChanged(const Domain&))); |
|
53 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),i.value(),SLOT(handleDomainChanged(const Domain&))); | |
54 | } |
|
54 | } | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | void ChartPresenter::handleGeometryChanged() |
|
57 | void ChartPresenter::handleGeometryChanged() | |
58 | { |
|
58 | { | |
59 | m_rect = QRectF(QPoint(0,0),m_chart->size()); |
|
59 | m_rect = QRectF(QPoint(0,0),m_chart->size()); | |
60 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); |
|
60 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); | |
61 | Q_ASSERT(m_rect.isValid()); |
|
61 | Q_ASSERT(m_rect.isValid()); | |
62 | emit geometryChanged(m_rect); |
|
62 | emit geometryChanged(m_rect); | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | int ChartPresenter::margin() const |
|
65 | int ChartPresenter::margin() const | |
66 | { |
|
66 | { | |
67 | return m_marginSize; |
|
67 | return m_marginSize; | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | void ChartPresenter::setMargin(int margin) |
|
70 | void ChartPresenter::setMargin(int margin) | |
71 | { |
|
71 | { | |
72 | m_marginSize = margin; |
|
72 | m_marginSize = margin; | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void ChartPresenter::handleSeriesAdded(QChartSeries* series) |
|
75 | void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |
76 | { |
|
76 | { | |
77 | switch(series->type()) |
|
77 | switch(series->type()) | |
78 | { |
|
78 | { | |
79 | case QChartSeries::SeriesTypeLine: { |
|
79 | case QChartSeries::SeriesTypeLine: { | |
80 | QLineChartSeries* lineSeries = static_cast<QLineChartSeries*>(series); |
|
80 | QLineChartSeries* lineSeries = static_cast<QLineChartSeries*>(series); | |
81 | LineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart); |
|
81 | LineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart); | |
82 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); |
|
82 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); | |
83 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
83 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
84 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
84 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
85 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
85 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
86 | m_chartItems.insert(series,item); |
|
86 | m_chartItems.insert(series,item); | |
87 | break; |
|
87 | break; | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | case QChartSeries::SeriesTypeBar: { |
|
90 | case QChartSeries::SeriesTypeBar: { | |
91 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); |
|
91 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); | |
92 | BarGroup* item = new BarGroup(*barSeries,m_chart); |
|
92 | BarGroup* item = new BarGroup(*barSeries,m_chart); | |
93 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); |
|
93 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); | |
94 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
94 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
95 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
95 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
96 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
96 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
97 | m_chartItems.insert(series,item); |
|
97 | m_chartItems.insert(series,item); | |
98 | // m_axisXItem->setVisible(false); |
|
98 | // m_axisXItem->setVisible(false); | |
99 | break; |
|
99 | break; | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | case QChartSeries::SeriesTypeStackedBar: { |
|
102 | case QChartSeries::SeriesTypeStackedBar: { | |
103 |
|
103 | |||
104 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); |
|
104 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); | |
105 | StackedBarGroup* item = new StackedBarGroup(*stackedBarSeries,m_chart); |
|
105 | StackedBarGroup* item = new StackedBarGroup(*stackedBarSeries,m_chart); | |
106 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); |
|
106 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); | |
107 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
107 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
108 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
108 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
109 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
109 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
110 | m_chartItems.insert(series,item); |
|
110 | m_chartItems.insert(series,item); | |
111 | break; |
|
111 | break; | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | case QChartSeries::SeriesTypePercentBar: { |
|
114 | case QChartSeries::SeriesTypePercentBar: { | |
115 |
|
115 | |||
116 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); |
|
116 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); | |
117 | PercentBarGroup* item = new PercentBarGroup(*percentBarSeries,m_chart); |
|
117 | PercentBarGroup* item = new PercentBarGroup(*percentBarSeries,m_chart); | |
118 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); |
|
118 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); | |
119 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
119 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
120 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
120 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
121 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
121 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
122 | m_chartItems.insert(series,item); |
|
122 | m_chartItems.insert(series,item); | |
123 | break; |
|
123 | break; | |
124 | } |
|
124 | } | |
125 | /* |
|
125 | /* | |
126 | case QChartSeries::SeriesTypeScatter: { |
|
126 | case QChartSeries::SeriesTypeScatter: { | |
127 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
127 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
128 | scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); |
|
128 | scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); | |
129 | scatterSeries->d->setParentItem(this); |
|
129 | scatterSeries->d->setParentItem(this); | |
130 | scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
130 | scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
131 | m_chartItems << scatterSeries->d; |
|
131 | m_chartItems << scatterSeries->d; | |
132 | m_chartTheme->addObserver(scatterSeries->d); |
|
132 | m_chartTheme->addObserver(scatterSeries->d); | |
133 |
|
133 | |||
134 | foreach (qreal x, scatterSeries->d->m_x) { |
|
134 | foreach (qreal x, scatterSeries->d->m_x) { | |
135 | domain.m_minX = qMin(domain.m_minX, x); |
|
135 | domain.m_minX = qMin(domain.m_minX, x); | |
136 | domain.m_maxX = qMax(domain.m_maxX, x); |
|
136 | domain.m_maxX = qMax(domain.m_maxX, x); | |
137 | } |
|
137 | } | |
138 | foreach (qreal y, scatterSeries->d->m_y) { |
|
138 | foreach (qreal y, scatterSeries->d->m_y) { | |
139 | domain.m_minY = qMin(domain.m_minY, y); |
|
139 | domain.m_minY = qMin(domain.m_minY, y); | |
140 | domain.m_maxY = qMax(domain.m_maxY, y); |
|
140 | domain.m_maxY = qMax(domain.m_maxY, y); | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | break; |
|
143 | break; | |
144 | } |
|
144 | } | |
145 | */ |
|
145 | */ | |
146 |
|
146 | |||
147 | case QChartSeries::SeriesTypePie: { |
|
147 | case QChartSeries::SeriesTypePie: { | |
148 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); |
|
148 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); | |
149 | PiePresenter* pie = new PiePresenter(m_chart, pieSeries); |
|
149 | PiePresenter* pie = new PiePresenter(m_chart, pieSeries); | |
150 | pieSeries->m_piePresenter = pie; // TODO: remove this pointer passing use signals&slots |
|
150 | pieSeries->m_piePresenter = pie; // TODO: remove this pointer passing use signals&slots | |
151 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); |
|
151 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); | |
152 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), pie, SLOT(handleDomainChanged(const Domain&))); |
|
152 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), pie, SLOT(handleDomainChanged(const Domain&))); | |
153 | m_chartItems.insert(series, pie); |
|
153 | m_chartItems.insert(series, pie); | |
154 | break; |
|
154 | break; | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | default: { |
|
157 | default: { | |
158 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
158 | qDebug()<< "Series type" << series->type() << "not implemented."; | |
159 | break; |
|
159 | break; | |
160 | } |
|
160 | } | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | if(m_rect.isValid()) emit geometryChanged(m_rect); |
|
163 | if(m_rect.isValid()) emit geometryChanged(m_rect); | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | void ChartPresenter::handleSeriesChanged(QChartSeries* series) |
|
166 | void ChartPresenter::handleSeriesChanged(QChartSeries* series) | |
167 | { |
|
167 | { | |
168 | //TODO: |
|
168 | //TODO: | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | void ChartPresenter::zoomInToRect(const QRectF& rect) |
|
171 | void ChartPresenter::zoomInToRect(const QRectF& rect) | |
172 | { |
|
172 | { | |
173 | if(!rect.isValid()) return; |
|
173 | if(!rect.isValid()) return; | |
174 | QRectF r = rect.normalized(); |
|
174 | QRectF r = rect.normalized(); | |
175 | r.translate(-m_marginSize, -m_marginSize); |
|
175 | r.translate(-m_marginSize, -m_marginSize); | |
176 | Domain domain (m_dataset->domain().subDomain(r,m_rect.width(),m_rect.height())); |
|
176 | Domain domain (m_dataset->domain().subDomain(r,m_rect.width(),m_rect.height())); | |
177 | m_dataset->addDomain(domain); |
|
177 | m_dataset->addDomain(domain); | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 | void ChartPresenter::zoomIn() |
|
180 | void ChartPresenter::zoomIn() | |
181 | { |
|
181 | { | |
182 | if (!m_dataset->nextDomain()) { |
|
182 | if (!m_dataset->nextDomain()) { | |
183 | QRectF rect = m_rect; |
|
183 | QRectF rect = m_rect; | |
184 | rect.setWidth(rect.width()/2); |
|
184 | rect.setWidth(rect.width()/2); | |
185 | rect.setHeight(rect.height()/2); |
|
185 | rect.setHeight(rect.height()/2); | |
186 | rect.moveCenter(m_rect.center()); |
|
186 | rect.moveCenter(m_rect.center()); | |
187 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); |
|
187 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); | |
188 | m_dataset->addDomain(domain); |
|
188 | m_dataset->addDomain(domain); | |
189 | } |
|
189 | } | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | void ChartPresenter::zoomOut() |
|
192 | void ChartPresenter::zoomOut() | |
193 | { |
|
193 | { | |
194 | m_dataset->previousDomain(); |
|
194 | m_dataset->previousDomain(); | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | void ChartPresenter::zoomReset() |
|
197 | void ChartPresenter::zoomReset() | |
198 | { |
|
198 | { | |
199 | m_dataset->clearDomains(); |
|
199 | m_dataset->clearDomains(); | |
200 | } |
|
200 | } | |
201 |
|
201 | |||
202 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) |
|
202 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) | |
203 | { |
|
203 | { | |
204 | delete m_chartTheme; |
|
204 | delete m_chartTheme; | |
205 |
|
205 | |||
206 | m_chartTheme = ChartTheme::createTheme(theme); |
|
206 | m_chartTheme = ChartTheme::createTheme(theme); | |
207 |
|
207 | |||
208 | m_chartTheme->decorate(m_chart); |
|
208 | m_chartTheme->decorate(m_chart); | |
209 | QMapIterator<QChartSeries*,ChartItem*> i(m_chartItems); |
|
209 | QMapIterator<QChartSeries*,ChartItem*> i(m_chartItems); | |
210 |
|
210 | |||
211 | int index=0; |
|
211 | int index=0; | |
212 | while (i.hasNext()) { |
|
212 | while (i.hasNext()) { | |
213 | i.next(); |
|
213 | i.next(); | |
214 | index++; |
|
214 | index++; | |
215 | m_chartTheme->decorate(i.value(),i.key(),index); |
|
215 | m_chartTheme->decorate(i.value(),i.key(),index); | |
216 | } |
|
216 | } | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 |
|
219 | |||
220 | QChart::ChartTheme ChartPresenter::chartTheme() |
|
220 | QChart::ChartTheme ChartPresenter::chartTheme() | |
221 | { |
|
221 | { | |
222 | return m_chartTheme->id(); |
|
222 | return m_chartTheme->id(); | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 | QChartAxis* ChartPresenter::axisX() |
|
225 | QChartAxis* ChartPresenter::axisX() | |
226 | { |
|
226 | { | |
227 | return m_axisX; |
|
227 | return m_axisX; | |
228 | } |
|
228 | } | |
229 |
|
229 | |||
230 | QChartAxis* ChartPresenter::axisY() |
|
230 | QChartAxis* ChartPresenter::axisY() | |
231 | { |
|
231 | { | |
232 | return m_axisY; |
|
232 | return m_axisY; | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | QChartAxis* ChartPresenter::addAxisX() |
|
235 | QChartAxis* ChartPresenter::addAxisX() | |
236 | { |
|
236 | { | |
237 | //only one axis |
|
237 | //only one axis | |
238 | if(m_axisX==0){ |
|
238 | if(m_axisX==0){ | |
239 | m_axisX = new QChartAxis(this); |
|
239 | m_axisX = new QChartAxis(this); | |
240 | m_axisItems[m_axisX] = new AxisItem(m_axisX,AxisItem::X_AXIS,m_chart); |
|
240 | m_axisItems[m_axisX] = new AxisItem(m_axisX,AxisItem::X_AXIS,m_chart); | |
241 | } |
|
241 | } | |
242 | return m_axisX; |
|
242 | return m_axisX; | |
243 | } |
|
243 | } | |
244 |
|
244 | |||
245 | QChartAxis* ChartPresenter::addAxisY() |
|
245 | QChartAxis* ChartPresenter::addAxisY() | |
246 | { |
|
246 | { | |
247 | if(m_axisY==0){ |
|
247 | if(m_axisY==0){ | |
248 | m_axisY = new QChartAxis(this); |
|
248 | m_axisY = new QChartAxis(this); | |
249 | m_axisItems[m_axisY] = new AxisItem(m_axisY,AxisItem::Y_AXIS,m_chart); |
|
249 | m_axisItems[m_axisY] = new AxisItem(m_axisY,AxisItem::Y_AXIS,m_chart); | |
250 | return m_axisY; |
|
250 | return m_axisY; | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | QChartAxis* axis = new QChartAxis(this); |
|
253 | QChartAxis* axis = new QChartAxis(this); | |
254 | m_axisItems[axis] = new AxisItem(axis,AxisItem::Y_AXIS,m_chart); |
|
254 | m_axisItems[axis] = new AxisItem(axis,AxisItem::Y_AXIS,m_chart); | |
255 | return axis; |
|
255 | return axis; | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | void ChartPresenter::removeAxis(QChartAxis* axis) |
|
258 | void ChartPresenter::removeAxis(QChartAxis* axis) | |
259 | { |
|
259 | { | |
260 | AxisItem* item = m_axisItems.take(axis); |
|
260 | AxisItem* item = m_axisItems.take(axis); | |
261 | if(item){ |
|
261 | if(item){ | |
262 | delete item; |
|
262 | delete item; | |
263 | delete axis; |
|
263 | delete axis; | |
264 | } |
|
264 | } | |
265 | //reset pointers to default ones |
|
265 | //reset pointers to default ones | |
266 | if(axis == m_axisX) m_axisX=0; |
|
266 | if(axis == m_axisX) m_axisX=0; | |
267 | else if(axis == m_axisY) m_axisY=0; |
|
267 | else if(axis == m_axisY) m_axisY=0; | |
268 | } |
|
268 | } | |
269 |
|
269 | |||
270 | /* |
|
|||
271 | void ChartPresenter::setAxisX(const QChartAxis& axis) |
|
|||
272 | { |
|
|||
273 | setAxis(m_axisXItem,axis); |
|
|||
274 | } |
|
|||
275 | void ChartPresenter::setAxisY(const QChartAxis& axis) |
|
|||
276 | { |
|
|||
277 | setAxis(m_axisYItem.at(0),axis); |
|
|||
278 | } |
|
|||
279 |
|
||||
280 | void ChartPresenter::setAxisY(const QList<QChartAxis>& axis) |
|
|||
281 | { |
|
|||
282 | //TODO not implemented |
|
|||
283 | } |
|
|||
284 |
|
||||
285 | void ChartPresenter::setAxis(AxisItem *item, const QChartAxis& axis) |
|
|||
286 | { |
|
|||
287 | item->setVisible(axis.isAxisVisible()); |
|
|||
288 | } |
|
|||
289 | */ |
|
|||
290 | #include "moc_chartpresenter_p.cpp" |
|
270 | #include "moc_chartpresenter_p.cpp" | |
291 |
|
271 | |||
292 | QTCOMMERCIALCHART_END_NAMESPACE |
|
272 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,77 +1,70 | |||||
1 | #include "qlinechartseries.h" |
|
1 | #include "qlinechartseries.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | QLineChartSeries::QLineChartSeries(QObject* parent):QChartSeries(parent) |
|
5 | QLineChartSeries::QLineChartSeries(QObject* parent):QChartSeries(parent) | |
6 | { |
|
6 | { | |
7 | } |
|
7 | } | |
8 |
|
8 | |||
9 | QLineChartSeries::~QLineChartSeries() |
|
9 | QLineChartSeries::~QLineChartSeries() | |
10 | { |
|
10 | { | |
11 | } |
|
11 | } | |
12 |
|
12 | |||
13 | QLineChartSeries* QLineChartSeries::create(QObject* parent) |
|
|||
14 | { |
|
|||
15 | //TODO: here we take QChartData when it is ready |
|
|||
16 | // return null if malformed; |
|
|||
17 | return new QLineChartSeries(parent); |
|
|||
18 | } |
|
|||
19 |
|
||||
20 | int QLineChartSeries::add(qreal x,qreal y) |
|
13 | int QLineChartSeries::add(qreal x,qreal y) | |
21 | { |
|
14 | { | |
22 | m_x<<x; |
|
15 | m_x<<x; | |
23 | m_y<<y; |
|
16 | m_y<<y; | |
24 | return m_x.size()-1; |
|
17 | return m_x.size()-1; | |
25 | } |
|
18 | } | |
26 |
|
19 | |||
27 | void QLineChartSeries::set(int index,qreal x,qreal y) |
|
20 | void QLineChartSeries::set(int index,qreal x,qreal y) | |
28 | { |
|
21 | { | |
29 | m_x[index]=x; |
|
22 | m_x[index]=x; | |
30 | m_y[index]=y; |
|
23 | m_y[index]=y; | |
31 | emit changed(index); |
|
24 | emit changed(index); | |
32 | } |
|
25 | } | |
33 |
|
26 | |||
34 | void QLineChartSeries::clear() |
|
27 | void QLineChartSeries::clear() | |
35 | { |
|
28 | { | |
36 | m_x.clear(); |
|
29 | m_x.clear(); | |
37 | m_y.clear(); |
|
30 | m_y.clear(); | |
38 | } |
|
31 | } | |
39 |
|
32 | |||
40 | qreal QLineChartSeries::x(int pos) const |
|
33 | qreal QLineChartSeries::x(int pos) const | |
41 | { |
|
34 | { | |
42 | return m_x.at(pos); |
|
35 | return m_x.at(pos); | |
43 | } |
|
36 | } | |
44 |
|
37 | |||
45 | qreal QLineChartSeries::y(int pos) const |
|
38 | qreal QLineChartSeries::y(int pos) const | |
46 | { |
|
39 | { | |
47 | return m_y.at(pos); |
|
40 | return m_y.at(pos); | |
48 | } |
|
41 | } | |
49 |
|
42 | |||
50 | int QLineChartSeries::count() const |
|
43 | int QLineChartSeries::count() const | |
51 | { |
|
44 | { | |
52 | Q_ASSERT(m_x.size() == m_y.size()); |
|
45 | Q_ASSERT(m_x.size() == m_y.size()); | |
53 |
|
46 | |||
54 | return m_x.size(); |
|
47 | return m_x.size(); | |
55 |
|
48 | |||
56 | } |
|
49 | } | |
57 |
|
50 | |||
58 | void QLineChartSeries::setPen(const QPen& pen) |
|
51 | void QLineChartSeries::setPen(const QPen& pen) | |
59 | { |
|
52 | { | |
60 | m_pen=pen; |
|
53 | m_pen=pen; | |
61 | } |
|
54 | } | |
62 |
|
55 | |||
63 | QDebug operator<< (QDebug debug, const QLineChartSeries series) |
|
56 | QDebug operator<< (QDebug debug, const QLineChartSeries series) | |
64 | { |
|
57 | { | |
65 | Q_ASSERT(series.m_x.size() == series.m_y.size()); |
|
58 | Q_ASSERT(series.m_x.size() == series.m_y.size()); | |
66 |
|
59 | |||
67 | int size = series.m_x.size(); |
|
60 | int size = series.m_x.size(); | |
68 |
|
61 | |||
69 | for (int i=0;i<size;i++) { |
|
62 | for (int i=0;i<size;i++) { | |
70 | debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") "; |
|
63 | debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") "; | |
71 | } |
|
64 | } | |
72 | return debug.space(); |
|
65 | return debug.space(); | |
73 | } |
|
66 | } | |
74 |
|
67 | |||
75 | #include "moc_qlinechartseries.cpp" |
|
68 | #include "moc_qlinechartseries.cpp" | |
76 |
|
69 | |||
77 | QTCOMMERCIALCHART_END_NAMESPACE |
|
70 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,48 +1,46 | |||||
1 | #ifndef QLINECHARTSERIES_H_ |
|
1 | #ifndef QLINECHARTSERIES_H_ | |
2 | #define QLINECHARTSERIES_H_ |
|
2 | #define QLINECHARTSERIES_H_ | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qchartseries.h" |
|
5 | #include "qchartseries.h" | |
6 | #include <QDebug> |
|
6 | #include <QDebug> | |
7 | #include <QPen> |
|
7 | #include <QPen> | |
8 | #include <QBrush> |
|
8 | #include <QBrush> | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
|
11 | |||
12 | class QTCOMMERCIALCHART_EXPORT QLineChartSeries : public QChartSeries |
|
12 | class QTCOMMERCIALCHART_EXPORT QLineChartSeries : public QChartSeries | |
13 | { |
|
13 | { | |
14 | Q_OBJECT |
|
14 | Q_OBJECT | |
15 | private: |
|
|||
16 | QLineChartSeries(QObject* parent=0); |
|
|||
17 | public: |
|
15 | public: | |
|
16 | QLineChartSeries(QObject* parent=0); | |||
18 | virtual ~QLineChartSeries(); |
|
17 | virtual ~QLineChartSeries(); | |
19 |
|
18 | |||
20 | public: // from QChartSeries |
|
19 | public: // from QChartSeries | |
21 | static QLineChartSeries* create(QObject* parent=0); |
|
|||
22 | virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeLine;} |
|
20 | virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeLine;} | |
23 |
|
21 | |||
24 | public: |
|
22 | public: | |
25 | int add(qreal x, qreal y); |
|
23 | int add(qreal x, qreal y); | |
26 | void set(int index,qreal x,qreal y); |
|
24 | void set(int index,qreal x,qreal y); | |
27 | void clear(); |
|
25 | void clear(); | |
28 |
|
26 | |||
29 | void setPen(const QPen& pen); |
|
27 | void setPen(const QPen& pen); | |
30 | const QPen& pen() const { return m_pen;} |
|
28 | const QPen& pen() const { return m_pen;} | |
31 |
|
29 | |||
32 | int count() const; |
|
30 | int count() const; | |
33 | qreal x(int pos) const; |
|
31 | qreal x(int pos) const; | |
34 | qreal y(int pos) const; |
|
32 | qreal y(int pos) const; | |
35 | friend QDebug operator<< (QDebug d, const QLineChartSeries series); |
|
33 | friend QDebug operator<< (QDebug d, const QLineChartSeries series); | |
36 |
|
34 | |||
37 | signals: |
|
35 | signals: | |
38 | void changed(int index); |
|
36 | void changed(int index); | |
39 |
|
37 | |||
40 | private: |
|
38 | private: | |
41 | QVector<qreal> m_x; |
|
39 | QVector<qreal> m_x; | |
42 | QVector<qreal> m_y; |
|
40 | QVector<qreal> m_y; | |
43 | QPen m_pen; |
|
41 | QPen m_pen; | |
44 | }; |
|
42 | }; | |
45 |
|
43 | |||
46 | QTCOMMERCIALCHART_END_NAMESPACE |
|
44 | QTCOMMERCIALCHART_END_NAMESPACE | |
47 |
|
45 | |||
48 | #endif |
|
46 | #endif |
@@ -1,196 +1,196 | |||||
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 | // TODO: support also other types; not only scatter and pie |
|
39 | // TODO: support also other types; not only scatter and pie | |
40 |
|
40 | |||
41 | QChartSeries *series(0); |
|
41 | QChartSeries *series(0); | |
42 |
|
42 | |||
43 | switch (type) { |
|
43 | switch (type) { | |
44 | case QChartSeries::SeriesTypeLine: { |
|
44 | case QChartSeries::SeriesTypeLine: { | |
45 |
series = QLineChartSeries |
|
45 | series = new QLineChartSeries(this); | |
46 | break; |
|
46 | break; | |
47 | } |
|
47 | } | |
48 | case QChartSeries::SeriesTypeBar: { |
|
48 | case QChartSeries::SeriesTypeBar: { | |
49 | series = new BarChartSeries(this); |
|
49 | series = new BarChartSeries(this); | |
50 | break; |
|
50 | break; | |
51 | } |
|
51 | } | |
52 | case QChartSeries::SeriesTypeStackedBar: { |
|
52 | case QChartSeries::SeriesTypeStackedBar: { | |
53 | series = new StackedBarChartSeries(this); |
|
53 | series = new StackedBarChartSeries(this); | |
54 | break; |
|
54 | break; | |
55 | } |
|
55 | } | |
56 | case QChartSeries::SeriesTypePercentBar: { |
|
56 | case QChartSeries::SeriesTypePercentBar: { | |
57 | series = new PercentBarChartSeries(this); |
|
57 | series = new PercentBarChartSeries(this); | |
58 | break; |
|
58 | break; | |
59 | } |
|
59 | } | |
60 | case QChartSeries::SeriesTypeScatter: { |
|
60 | case QChartSeries::SeriesTypeScatter: { | |
61 | series = new QScatterSeries(this); |
|
61 | series = new QScatterSeries(this); | |
62 | break; |
|
62 | break; | |
63 | } |
|
63 | } | |
64 | case QChartSeries::SeriesTypePie: { |
|
64 | case QChartSeries::SeriesTypePie: { | |
65 | series = new QPieSeries(this); |
|
65 | series = new QPieSeries(this); | |
66 | break; |
|
66 | break; | |
67 | } |
|
67 | } | |
68 | default: |
|
68 | default: | |
69 | Q_ASSERT(false); |
|
69 | Q_ASSERT(false); | |
70 | break; |
|
70 | break; | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | addSeries(series); |
|
73 | addSeries(series); | |
74 | return series; |
|
74 | return series; | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | void QChart::setChartBackgroundBrush(const QBrush& brush) |
|
77 | void QChart::setChartBackgroundBrush(const QBrush& brush) | |
78 | { |
|
78 | { | |
79 |
|
79 | |||
80 | if(!m_backgroundItem) { |
|
80 | if(!m_backgroundItem) { | |
81 | m_backgroundItem = new QGraphicsRectItem(this); |
|
81 | m_backgroundItem = new QGraphicsRectItem(this); | |
82 | m_backgroundItem->setZValue(-1); |
|
82 | m_backgroundItem->setZValue(-1); | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | m_backgroundItem->setBrush(brush); |
|
85 | m_backgroundItem->setBrush(brush); | |
86 | m_backgroundItem->update(); |
|
86 | m_backgroundItem->update(); | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | void QChart::setChartBackgroundPen(const QPen& pen) |
|
89 | void QChart::setChartBackgroundPen(const QPen& pen) | |
90 | { |
|
90 | { | |
91 |
|
91 | |||
92 | if(!m_backgroundItem) { |
|
92 | if(!m_backgroundItem) { | |
93 | m_backgroundItem = new QGraphicsRectItem(this); |
|
93 | m_backgroundItem = new QGraphicsRectItem(this); | |
94 | m_backgroundItem->setZValue(-1); |
|
94 | m_backgroundItem->setZValue(-1); | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | m_backgroundItem->setPen(pen); |
|
97 | m_backgroundItem->setPen(pen); | |
98 | m_backgroundItem->update(); |
|
98 | m_backgroundItem->update(); | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | void QChart::setTitle(const QString& title,const QFont& font) |
|
101 | void QChart::setTitle(const QString& title,const QFont& font) | |
102 | { |
|
102 | { | |
103 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); |
|
103 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); | |
104 | m_titleItem->setPlainText(title); |
|
104 | m_titleItem->setPlainText(title); | |
105 | m_titleItem->setFont(font); |
|
105 | m_titleItem->setFont(font); | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | int QChart::margin() const |
|
108 | int QChart::margin() const | |
109 | { |
|
109 | { | |
110 | return m_presenter->margin(); |
|
110 | return m_presenter->margin(); | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | void QChart::setMargin(int margin) |
|
113 | void QChart::setMargin(int margin) | |
114 | { |
|
114 | { | |
115 | m_presenter->setMargin(margin); |
|
115 | m_presenter->setMargin(margin); | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | void QChart::setChartTheme(QChart::ChartTheme theme) |
|
118 | void QChart::setChartTheme(QChart::ChartTheme theme) | |
119 | { |
|
119 | { | |
120 | m_presenter->setChartTheme(theme); |
|
120 | m_presenter->setChartTheme(theme); | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | QChart::ChartTheme QChart::chartTheme() const |
|
123 | QChart::ChartTheme QChart::chartTheme() const | |
124 | { |
|
124 | { | |
125 | return m_presenter->chartTheme(); |
|
125 | return m_presenter->chartTheme(); | |
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 | void QChart::zoomInToRect(const QRectF& rectangle) |
|
128 | void QChart::zoomInToRect(const QRectF& rectangle) | |
129 | { |
|
129 | { | |
130 | m_presenter->zoomInToRect(rectangle); |
|
130 | m_presenter->zoomInToRect(rectangle); | |
131 | } |
|
131 | } | |
132 |
|
132 | |||
133 | void QChart::zoomIn() |
|
133 | void QChart::zoomIn() | |
134 | { |
|
134 | { | |
135 | m_presenter->zoomIn(); |
|
135 | m_presenter->zoomIn(); | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | void QChart::zoomOut() |
|
138 | void QChart::zoomOut() | |
139 | { |
|
139 | { | |
140 | m_presenter->zoomOut(); |
|
140 | m_presenter->zoomOut(); | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | void QChart::zoomReset() |
|
143 | void QChart::zoomReset() | |
144 | { |
|
144 | { | |
145 | m_presenter->zoomReset(); |
|
145 | m_presenter->zoomReset(); | |
146 | } |
|
146 | } | |
147 |
|
147 | |||
148 | QChartAxis* QChart::axisX() |
|
148 | QChartAxis* QChart::axisX() | |
149 | { |
|
149 | { | |
150 | return m_presenter->axisX(); |
|
150 | return m_presenter->axisX(); | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | QChartAxis* QChart::axisY() |
|
153 | QChartAxis* QChart::axisY() | |
154 | { |
|
154 | { | |
155 | return m_presenter->axisY(); |
|
155 | return m_presenter->axisY(); | |
156 | } |
|
156 | } | |
157 |
|
157 | |||
158 | QChartAxis* QChart::addAxisX() |
|
158 | QChartAxis* QChart::addAxisX() | |
159 | { |
|
159 | { | |
160 | return m_presenter->addAxisX(); |
|
160 | return m_presenter->addAxisX(); | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | QChartAxis* QChart::addAxisY() |
|
163 | QChartAxis* QChart::addAxisY() | |
164 | { |
|
164 | { | |
165 | return m_presenter->addAxisY(); |
|
165 | return m_presenter->addAxisY(); | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | void QChart::removeAxis(QChartAxis* axis) |
|
168 | void QChart::removeAxis(QChartAxis* axis) | |
169 | { |
|
169 | { | |
170 | m_presenter->removeAxis(axis); |
|
170 | m_presenter->removeAxis(axis); | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
173 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
174 | { |
|
174 | { | |
175 |
|
175 | |||
176 | m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
176 | m_rect = QRectF(QPoint(0,0),event->newSize()); | |
177 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
177 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
178 |
|
178 | |||
179 | // recalculate title position |
|
179 | // recalculate title position | |
180 | if (m_titleItem) { |
|
180 | if (m_titleItem) { | |
181 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
181 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
182 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); |
|
182 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | //recalculate background gradient |
|
185 | //recalculate background gradient | |
186 | if (m_backgroundItem) { |
|
186 | if (m_backgroundItem) { | |
187 | m_backgroundItem->setRect(rect); |
|
187 | m_backgroundItem->setRect(rect); | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | QGraphicsWidget::resizeEvent(event); |
|
190 | QGraphicsWidget::resizeEvent(event); | |
191 | update(); |
|
191 | update(); | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | #include "moc_qchart.cpp" |
|
194 | #include "moc_qchart.cpp" | |
195 |
|
195 | |||
196 | QTCOMMERCIALCHART_END_NAMESPACE |
|
196 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,34 +1,5 | |||||
1 | #include "qchartglobal.h" |
|
|||
2 |
|
|
1 | #include "qchartseries.h" | |
3 |
|
2 | |||
4 | #include "barchartseries.h" |
|
|||
5 | #include "qlinechartseries.h" |
|
|||
6 |
|
||||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
||||
9 | QChartSeries* QChartSeries::create(QChartSeriesType type, QObject* parent) |
|
|||
10 | { |
|
|||
11 | qDebug() << "QChartSeries::create"; |
|
|||
12 | // TODO: Other types |
|
|||
13 | switch (type) { |
|
|||
14 | case QChartSeries::SeriesTypeLine: { |
|
|||
15 | QLineChartSeries* s = QLineChartSeries::create(parent); // TODO: do we need create method for derived implementations? |
|
|||
16 | return s; |
|
|||
17 | } |
|
|||
18 | case QChartSeries::SeriesTypePie: { |
|
|||
19 | return 0; |
|
|||
20 | } |
|
|||
21 | case QChartSeries::SeriesTypeScatter: { |
|
|||
22 | return 0; |
|
|||
23 | } |
|
|||
24 | case QChartSeries::SeriesTypeBar: { |
|
|||
25 | BarChartSeries* s = new BarChartSeries(parent); |
|
|||
26 | return s; |
|
|||
27 | } |
|
|||
28 | default: |
|
|||
29 | return 0; |
|
|||
30 | } |
|
|||
31 | } |
|
|||
32 |
|
||||
33 | #include "moc_qchartseries.cpp" |
|
4 | #include "moc_qchartseries.cpp" | |
34 | QTCOMMERCIALCHART_END_NAMESPACE |
|
5 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,50 +1,47 | |||||
1 | #ifndef QCHARTSERIES_H |
|
1 | #ifndef QCHARTSERIES_H | |
2 | #define QCHARTSERIES_H |
|
2 | #define QCHARTSERIES_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include <QObject> |
|
5 | #include <QObject> | |
6 | #include <QAbstractItemModel> |
|
6 | #include <QAbstractItemModel> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class QTCOMMERCIALCHART_EXPORT QChartSeries : public QObject |
|
10 | class QTCOMMERCIALCHART_EXPORT QChartSeries : public QObject | |
11 | { |
|
11 | { | |
12 | Q_OBJECT |
|
12 | Q_OBJECT | |
13 | public: |
|
13 | public: | |
14 | enum QChartSeriesType { |
|
14 | enum QChartSeriesType { | |
15 | SeriesTypeInvalid = -1, |
|
15 | SeriesTypeInvalid = -1, | |
16 | SeriesTypeLine, |
|
16 | SeriesTypeLine, | |
17 | // SeriesTypeArea, |
|
17 | // SeriesTypeArea, | |
18 | SeriesTypeBar, |
|
18 | SeriesTypeBar, | |
19 | SeriesTypeStackedBar, |
|
19 | SeriesTypeStackedBar, | |
20 | SeriesTypePercentBar, |
|
20 | SeriesTypePercentBar, | |
21 | SeriesTypePie, |
|
21 | SeriesTypePie, | |
22 | SeriesTypeScatter |
|
22 | SeriesTypeScatter | |
23 | // SeriesTypeSpline |
|
23 | // SeriesTypeSpline | |
24 | }; |
|
24 | }; | |
25 |
|
25 | |||
26 | protected: |
|
26 | protected: | |
27 | QChartSeries(QObject *parent = 0):QObject(parent){}; |
|
27 | QChartSeries(QObject *parent = 0):QObject(parent){}; | |
28 |
|
28 | |||
29 | public: |
|
29 | public: | |
30 | virtual ~QChartSeries(){}; |
|
30 | virtual ~QChartSeries(){}; | |
31 |
|
31 | |||
32 | // Factory method |
|
|||
33 | static QChartSeries* create(QChartSeriesType type, QObject* parent = 0 ); |
|
|||
34 |
|
||||
35 | // Pure virtual |
|
32 | // Pure virtual | |
36 | virtual QChartSeriesType type() const = 0; |
|
33 | virtual QChartSeriesType type() const = 0; | |
37 |
|
34 | |||
38 | virtual bool setData(QList<int> /*data*/) { return false; } |
|
35 | virtual bool setData(QList<int> /*data*/) { return false; } | |
39 | virtual bool setData(QList<qreal> /*data*/) { return false; } |
|
36 | virtual bool setData(QList<qreal> /*data*/) { return false; } | |
40 | virtual bool setData(QList<qreal> /*x*/, QList<qreal> /*y*/){ return false; } |
|
37 | virtual bool setData(QList<qreal> /*x*/, QList<qreal> /*y*/){ return false; } | |
41 |
|
38 | |||
42 | // Prototype for data model. TODO: remove the other setData methods and use something like this for now? |
|
39 | // Prototype for data model. TODO: remove the other setData methods and use something like this for now? | |
43 | virtual bool setData(QAbstractItemModel* /*model*/) { return false; } |
|
40 | virtual bool setData(QAbstractItemModel* /*model*/) { return false; } | |
44 |
|
41 | |||
45 | }; |
|
42 | }; | |
46 |
|
43 | |||
47 | QTCOMMERCIALCHART_END_NAMESPACE |
|
44 | QTCOMMERCIALCHART_END_NAMESPACE | |
48 |
|
45 | |||
49 | #endif |
|
46 | #endif | |
50 |
|
47 |
@@ -1,381 +1,381 | |||||
1 | #include "mainwidget.h" |
|
1 | #include "mainwidget.h" | |
2 | #include "dataseriedialog.h" |
|
2 | #include "dataseriedialog.h" | |
3 | #include "qchartseries.h" |
|
3 | #include "qchartseries.h" | |
4 | #include "qpieseries.h" |
|
4 | #include "qpieseries.h" | |
5 | #include <qlinechartseries.h> |
|
5 | #include <qlinechartseries.h> | |
6 | #include <barchartseries.h> |
|
6 | #include <barchartseries.h> | |
7 | #include <QPushButton> |
|
7 | #include <QPushButton> | |
8 | #include <QComboBox> |
|
8 | #include <QComboBox> | |
9 | #include <QSpinBox> |
|
9 | #include <QSpinBox> | |
10 | #include <QCheckBox> |
|
10 | #include <QCheckBox> | |
11 | #include <QGridLayout> |
|
11 | #include <QGridLayout> | |
12 | #include <QHBoxLayout> |
|
12 | #include <QHBoxLayout> | |
13 | #include <QLabel> |
|
13 | #include <QLabel> | |
14 | #include <QSpacerItem> |
|
14 | #include <QSpacerItem> | |
15 | #include <QMessageBox> |
|
15 | #include <QMessageBox> | |
16 | #include <cmath> |
|
16 | #include <cmath> | |
17 | #include <QDebug> |
|
17 | #include <QDebug> | |
18 | #include <QStandardItemModel> |
|
18 | #include <QStandardItemModel> | |
19 |
|
19 | |||
20 |
|
20 | |||
21 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
21 | QTCOMMERCIALCHART_USE_NAMESPACE | |
22 |
|
22 | |||
23 | MainWidget::MainWidget(QWidget *parent) : |
|
23 | MainWidget::MainWidget(QWidget *parent) : | |
24 | QWidget(parent) |
|
24 | QWidget(parent) | |
25 | { |
|
25 | { | |
26 | m_chartWidget = new QChartView(this); |
|
26 | m_chartWidget = new QChartView(this); | |
27 | m_chartWidget->setRubberBandPolicy(QChartView::HorizonalRubberBand); |
|
27 | m_chartWidget->setRubberBandPolicy(QChartView::HorizonalRubberBand); | |
28 |
|
28 | |||
29 | // Grid layout for the controls for configuring the chart widget |
|
29 | // Grid layout for the controls for configuring the chart widget | |
30 | QGridLayout *grid = new QGridLayout(); |
|
30 | QGridLayout *grid = new QGridLayout(); | |
31 | QPushButton *addSeriesButton = new QPushButton("Add series"); |
|
31 | QPushButton *addSeriesButton = new QPushButton("Add series"); | |
32 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
32 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); | |
33 | grid->addWidget(addSeriesButton, 0, 1); |
|
33 | grid->addWidget(addSeriesButton, 0, 1); | |
34 | initBackroundCombo(grid); |
|
34 | initBackroundCombo(grid); | |
35 | initScaleControls(grid); |
|
35 | initScaleControls(grid); | |
36 | initThemeCombo(grid); |
|
36 | initThemeCombo(grid); | |
37 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); |
|
37 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); | |
38 | connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartWidget, SLOT(setZoomEnabled(bool))); |
|
38 | connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartWidget, SLOT(setZoomEnabled(bool))); | |
39 | zoomCheckBox->setChecked(true); |
|
39 | zoomCheckBox->setChecked(true); | |
40 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); |
|
40 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); | |
41 | // add row with empty label to make all the other rows static |
|
41 | // add row with empty label to make all the other rows static | |
42 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); |
|
42 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); | |
43 | grid->setRowStretch(grid->rowCount() - 1, 1); |
|
43 | grid->setRowStretch(grid->rowCount() - 1, 1); | |
44 |
|
44 | |||
45 | // Another grid layout as a main layout |
|
45 | // Another grid layout as a main layout | |
46 | QGridLayout *mainLayout = new QGridLayout(); |
|
46 | QGridLayout *mainLayout = new QGridLayout(); | |
47 | mainLayout->addLayout(grid, 0, 0); |
|
47 | mainLayout->addLayout(grid, 0, 0); | |
48 |
|
48 | |||
49 | // Init series type specific controls |
|
49 | // Init series type specific controls | |
50 | initPieControls(); |
|
50 | initPieControls(); | |
51 | mainLayout->addLayout(m_pieLayout, 2, 0); |
|
51 | mainLayout->addLayout(m_pieLayout, 2, 0); | |
52 | // Scatter series specific settings |
|
52 | // Scatter series specific settings | |
53 | // m_scatterLayout = new QGridLayout(); |
|
53 | // m_scatterLayout = new QGridLayout(); | |
54 | // m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0); |
|
54 | // m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0); | |
55 | // m_scatterLayout->setEnabled(false); |
|
55 | // m_scatterLayout->setEnabled(false); | |
56 | // mainLayout->addLayout(m_scatterLayout, 1, 0); |
|
56 | // mainLayout->addLayout(m_scatterLayout, 1, 0); | |
57 |
|
57 | |||
58 | // Add layouts and the chart widget to the main layout |
|
58 | // Add layouts and the chart widget to the main layout | |
59 | mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1); |
|
59 | mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1); | |
60 | setLayout(mainLayout); |
|
60 | setLayout(mainLayout); | |
61 |
|
61 | |||
62 | // force an update to test data |
|
62 | // force an update to test data | |
63 | testDataChanged(0); |
|
63 | testDataChanged(0); | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | // Combo box for selecting the chart's background |
|
66 | // Combo box for selecting the chart's background | |
67 | void MainWidget::initBackroundCombo(QGridLayout *grid) |
|
67 | void MainWidget::initBackroundCombo(QGridLayout *grid) | |
68 | { |
|
68 | { | |
69 | QComboBox *backgroundCombo = new QComboBox(this); |
|
69 | QComboBox *backgroundCombo = new QComboBox(this); | |
70 | backgroundCombo->addItem("Color"); |
|
70 | backgroundCombo->addItem("Color"); | |
71 | backgroundCombo->addItem("Gradient"); |
|
71 | backgroundCombo->addItem("Gradient"); | |
72 | backgroundCombo->addItem("Image"); |
|
72 | backgroundCombo->addItem("Image"); | |
73 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
73 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), | |
74 | this, SLOT(backgroundChanged(int))); |
|
74 | this, SLOT(backgroundChanged(int))); | |
75 |
|
75 | |||
76 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); |
|
76 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); | |
77 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); |
|
77 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | // Scale related controls (auto-scale vs. manual min-max values) |
|
80 | // Scale related controls (auto-scale vs. manual min-max values) | |
81 | void MainWidget::initScaleControls(QGridLayout *grid) |
|
81 | void MainWidget::initScaleControls(QGridLayout *grid) | |
82 | { |
|
82 | { | |
83 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
83 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); | |
84 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
84 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); | |
85 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
85 | // Allow setting also non-sense values (like -2147483648 and 2147483647) | |
86 | m_xMinSpin = new QSpinBox(); |
|
86 | m_xMinSpin = new QSpinBox(); | |
87 | m_xMinSpin->setMinimum(INT_MIN); |
|
87 | m_xMinSpin->setMinimum(INT_MIN); | |
88 | m_xMinSpin->setMaximum(INT_MAX); |
|
88 | m_xMinSpin->setMaximum(INT_MAX); | |
89 | m_xMinSpin->setValue(0); |
|
89 | m_xMinSpin->setValue(0); | |
90 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
90 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); | |
91 | m_xMaxSpin = new QSpinBox(); |
|
91 | m_xMaxSpin = new QSpinBox(); | |
92 | m_xMaxSpin->setMinimum(INT_MIN); |
|
92 | m_xMaxSpin->setMinimum(INT_MIN); | |
93 | m_xMaxSpin->setMaximum(INT_MAX); |
|
93 | m_xMaxSpin->setMaximum(INT_MAX); | |
94 | m_xMaxSpin->setValue(10); |
|
94 | m_xMaxSpin->setValue(10); | |
95 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
95 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); | |
96 | m_yMinSpin = new QSpinBox(); |
|
96 | m_yMinSpin = new QSpinBox(); | |
97 | m_yMinSpin->setMinimum(INT_MIN); |
|
97 | m_yMinSpin->setMinimum(INT_MIN); | |
98 | m_yMinSpin->setMaximum(INT_MAX); |
|
98 | m_yMinSpin->setMaximum(INT_MAX); | |
99 | m_yMinSpin->setValue(0); |
|
99 | m_yMinSpin->setValue(0); | |
100 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
100 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); | |
101 | m_yMaxSpin = new QSpinBox(); |
|
101 | m_yMaxSpin = new QSpinBox(); | |
102 | m_yMaxSpin->setMinimum(INT_MIN); |
|
102 | m_yMaxSpin->setMinimum(INT_MIN); | |
103 | m_yMaxSpin->setMaximum(INT_MAX); |
|
103 | m_yMaxSpin->setMaximum(INT_MAX); | |
104 | m_yMaxSpin->setValue(10); |
|
104 | m_yMaxSpin->setValue(10); | |
105 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
105 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); | |
106 |
|
106 | |||
107 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); |
|
107 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); | |
108 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); |
|
108 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); | |
109 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); |
|
109 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); | |
110 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); |
|
110 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); | |
111 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); |
|
111 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); | |
112 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); |
|
112 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); | |
113 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); |
|
113 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); | |
114 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); |
|
114 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); | |
115 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); |
|
115 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); | |
116 |
|
116 | |||
117 | m_autoScaleCheck->setChecked(true); |
|
117 | m_autoScaleCheck->setChecked(true); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | // Combo box for selecting theme |
|
120 | // Combo box for selecting theme | |
121 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
121 | void MainWidget::initThemeCombo(QGridLayout *grid) | |
122 | { |
|
122 | { | |
123 | QComboBox *chartTheme = new QComboBox(); |
|
123 | QComboBox *chartTheme = new QComboBox(); | |
124 | chartTheme->addItem("Default"); |
|
124 | chartTheme->addItem("Default"); | |
125 | chartTheme->addItem("Vanilla"); |
|
125 | chartTheme->addItem("Vanilla"); | |
126 | chartTheme->addItem("Icy"); |
|
126 | chartTheme->addItem("Icy"); | |
127 | chartTheme->addItem("Grayscale"); |
|
127 | chartTheme->addItem("Grayscale"); | |
128 | chartTheme->addItem("Scientific"); |
|
128 | chartTheme->addItem("Scientific"); | |
129 | chartTheme->addItem("Unnamed1"); |
|
129 | chartTheme->addItem("Unnamed1"); | |
130 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
130 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), | |
131 | this, SLOT(changeChartTheme(int))); |
|
131 | this, SLOT(changeChartTheme(int))); | |
132 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); |
|
132 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); | |
133 | grid->addWidget(chartTheme, 8, 1); |
|
133 | grid->addWidget(chartTheme, 8, 1); | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | void MainWidget::initPieControls() |
|
136 | void MainWidget::initPieControls() | |
137 | { |
|
137 | { | |
138 | // Pie series specific settings |
|
138 | // Pie series specific settings | |
139 | // Pie size factory |
|
139 | // Pie size factory | |
140 | QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox(); |
|
140 | QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox(); | |
141 | pieSizeSpin->setMinimum(LONG_MIN); |
|
141 | pieSizeSpin->setMinimum(LONG_MIN); | |
142 | pieSizeSpin->setMaximum(LONG_MAX); |
|
142 | pieSizeSpin->setMaximum(LONG_MAX); | |
143 | pieSizeSpin->setValue(1.0); |
|
143 | pieSizeSpin->setValue(1.0); | |
144 | pieSizeSpin->setSingleStep(0.1); |
|
144 | pieSizeSpin->setSingleStep(0.1); | |
145 | connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double))); |
|
145 | connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double))); | |
146 | // Pie position |
|
146 | // Pie position | |
147 | QComboBox *piePosCombo = new QComboBox(this); |
|
147 | QComboBox *piePosCombo = new QComboBox(this); | |
148 | piePosCombo->addItem("Maximized"); |
|
148 | piePosCombo->addItem("Maximized"); | |
149 | piePosCombo->addItem("Top left"); |
|
149 | piePosCombo->addItem("Top left"); | |
150 | piePosCombo->addItem("Top right"); |
|
150 | piePosCombo->addItem("Top right"); | |
151 | piePosCombo->addItem("Bottom left"); |
|
151 | piePosCombo->addItem("Bottom left"); | |
152 | piePosCombo->addItem("Bottom right"); |
|
152 | piePosCombo->addItem("Bottom right"); | |
153 | connect(piePosCombo, SIGNAL(currentIndexChanged(int)), |
|
153 | connect(piePosCombo, SIGNAL(currentIndexChanged(int)), | |
154 | this, SLOT(setPiePosition(int))); |
|
154 | this, SLOT(setPiePosition(int))); | |
155 | m_pieLayout = new QGridLayout(); |
|
155 | m_pieLayout = new QGridLayout(); | |
156 | m_pieLayout->setEnabled(false); |
|
156 | m_pieLayout->setEnabled(false); | |
157 | m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0); |
|
157 | m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0); | |
158 | m_pieLayout->addWidget(pieSizeSpin, 0, 1); |
|
158 | m_pieLayout->addWidget(pieSizeSpin, 0, 1); | |
159 | m_pieLayout->addWidget(new QLabel("Pie position"), 1, 0); |
|
159 | m_pieLayout->addWidget(new QLabel("Pie position"), 1, 0); | |
160 | m_pieLayout->addWidget(piePosCombo, 1, 1); |
|
160 | m_pieLayout->addWidget(piePosCombo, 1, 1); | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | void MainWidget::addSeries() |
|
163 | void MainWidget::addSeries() | |
164 | { |
|
164 | { | |
165 | DataSerieDialog dialog(m_defaultSeriesName, this); |
|
165 | DataSerieDialog dialog(m_defaultSeriesName, this); | |
166 | connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString))); |
|
166 | connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString))); | |
167 | dialog.exec(); |
|
167 | dialog.exec(); | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | void MainWidget::addSeries(QString series, QString data) |
|
170 | void MainWidget::addSeries(QString series, QString data) | |
171 | { |
|
171 | { | |
172 | qDebug() << "addSeries: " << series << " data: " << data; |
|
172 | qDebug() << "addSeries: " << series << " data: " << data; | |
173 | m_defaultSeriesName = series; |
|
173 | m_defaultSeriesName = series; | |
174 |
|
174 | |||
175 | // TODO: a dedicated data class for storing x and y values |
|
175 | // TODO: a dedicated data class for storing x and y values | |
176 | QList<qreal> x; |
|
176 | QList<qreal> x; | |
177 | QList<qreal> y; |
|
177 | QList<qreal> y; | |
178 |
|
178 | |||
179 | if (data == "linear") { |
|
179 | if (data == "linear") { | |
180 | for (int i = 0; i < 20; i++) { |
|
180 | for (int i = 0; i < 20; i++) { | |
181 | x.append(i); |
|
181 | x.append(i); | |
182 | y.append(i); |
|
182 | y.append(i); | |
183 | } |
|
183 | } | |
184 | } else if (data == "linear, 1M") { |
|
184 | } else if (data == "linear, 1M") { | |
185 | // 1 million data points from 0.0001 to 100 |
|
185 | // 1 million data points from 0.0001 to 100 | |
186 | // TODO: What is the requirement? Should we be able to show this kind of data with |
|
186 | // TODO: What is the requirement? Should we be able to show this kind of data with | |
187 | // reasonable performance, or can we expect the application developer to do "data mining" |
|
187 | // reasonable performance, or can we expect the application developer to do "data mining" | |
188 | // for us, so that the count of data points given to QtCommercial Chart is always |
|
188 | // for us, so that the count of data points given to QtCommercial Chart is always | |
189 | // reasonable? |
|
189 | // reasonable? | |
190 | for (qreal i = 0; i < 100; i += 0.0001) { |
|
190 | for (qreal i = 0; i < 100; i += 0.0001) { | |
191 | x.append(i); |
|
191 | x.append(i); | |
192 | y.append(20); |
|
192 | y.append(20); | |
193 | } |
|
193 | } | |
194 | } else if (data == "SIN") { |
|
194 | } else if (data == "SIN") { | |
195 | for (int i = 0; i < 100; i++) { |
|
195 | for (int i = 0; i < 100; i++) { | |
196 | x.append(i); |
|
196 | x.append(i); | |
197 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
197 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100)); | |
198 | } |
|
198 | } | |
199 | } else if (data == "SIN + random") { |
|
199 | } else if (data == "SIN + random") { | |
200 | for (qreal i = 0; i < 100; i += 0.1) { |
|
200 | for (qreal i = 0; i < 100; i += 0.1) { | |
201 | x.append(i + (rand() % 5)); |
|
201 | x.append(i + (rand() % 5)); | |
202 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
202 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |
203 | } |
|
203 | } | |
204 | } else { |
|
204 | } else { | |
205 | // TODO: check if data has a valid file name |
|
205 | // TODO: check if data has a valid file name | |
206 | Q_ASSERT(false); |
|
206 | Q_ASSERT(false); | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | // TODO: color of the series |
|
209 | // TODO: color of the series | |
210 | QChartSeries *newSeries = 0; |
|
210 | QChartSeries *newSeries = 0; | |
211 | if (series == "Scatter") { |
|
211 | if (series == "Scatter") { | |
212 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeScatter); |
|
212 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeScatter); | |
213 | Q_ASSERT(newSeries->setData(x, y)); |
|
213 | Q_ASSERT(newSeries->setData(x, y)); | |
214 | } else if (series == "Pie") { |
|
214 | } else if (series == "Pie") { | |
215 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie); |
|
215 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie); | |
216 | Q_ASSERT(newSeries->setData(y)); |
|
216 | Q_ASSERT(newSeries->setData(y)); | |
217 | } else if (series == "Line") { |
|
217 | } else if (series == "Line") { | |
218 | // TODO: adding data to an existing line series does not give any visuals for some reason |
|
218 | // TODO: adding data to an existing line series does not give any visuals for some reason | |
219 | // newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeLine); |
|
219 | // newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeLine); | |
220 | // QXYChartSeries *lineSeries = static_cast<QXYChartSeries *>(newSeries); |
|
220 | // QXYChartSeries *lineSeries = static_cast<QXYChartSeries *>(newSeries); | |
221 | // lineSeries->setColor(Qt::blue); |
|
221 | // lineSeries->setColor(Qt::blue); | |
222 | // for (int i(0); i < x.count() && i < y.count(); i++) { |
|
222 | // for (int i(0); i < x.count() && i < y.count(); i++) { | |
223 | // lineSeries->add(x.at(i), y.at(i)); |
|
223 | // lineSeries->add(x.at(i), y.at(i)); | |
224 | // } |
|
224 | // } | |
225 | //Q_ASSERT(newSeries->setData(x, y)); |
|
225 | //Q_ASSERT(newSeries->setData(x, y)); | |
226 |
QLineChartSeries* series0 = QLineChartSeries |
|
226 | QLineChartSeries* series0 = new QLineChartSeries(); | |
227 | for (int i(0); i < x.count() && i < y.count(); i++) |
|
227 | for (int i(0); i < x.count() && i < y.count(); i++) | |
228 | series0->add(x.at(i), y.at(i)); |
|
228 | series0->add(x.at(i), y.at(i)); | |
229 | m_chartWidget->addSeries(series0); |
|
229 | m_chartWidget->addSeries(series0); | |
230 | newSeries = series0; |
|
230 | newSeries = series0; | |
231 | } else { |
|
231 | } else { | |
232 | // TODO |
|
232 | // TODO | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | // BarChart |
|
235 | // BarChart | |
236 | if (series == "Bar") { |
|
236 | if (series == "Bar") { | |
237 | // This is the another way of creating series. Should we create test cases for both ways, if we support them? |
|
237 | // This is the another way of creating series. Should we create test cases for both ways, if we support them? | |
238 | qDebug() << "Bar chart series"; |
|
238 | qDebug() << "Bar chart series"; | |
239 |
newSeries = |
|
239 | newSeries = new BarChartSeries(this); | |
240 |
|
240 | |||
241 | // Create some test data to chart |
|
241 | // Create some test data to chart | |
242 | QStandardItemModel dataModel(2,10,this); |
|
242 | QStandardItemModel dataModel(2,10,this); | |
243 | QModelIndex index; |
|
243 | QModelIndex index; | |
244 | index = dataModel.index(0,0); |
|
244 | index = dataModel.index(0,0); | |
245 | // Series 1, items 6 to 9 missing. |
|
245 | // Series 1, items 6 to 9 missing. | |
246 | dataModel.setData(dataModel.index(0,0),1); |
|
246 | dataModel.setData(dataModel.index(0,0),1); | |
247 | dataModel.setData(dataModel.index(0,1),12); |
|
247 | dataModel.setData(dataModel.index(0,1),12); | |
248 | dataModel.setData(dataModel.index(0,2),5); |
|
248 | dataModel.setData(dataModel.index(0,2),5); | |
249 | dataModel.setData(dataModel.index(0,3),8); |
|
249 | dataModel.setData(dataModel.index(0,3),8); | |
250 | dataModel.setData(dataModel.index(0,4),17); |
|
250 | dataModel.setData(dataModel.index(0,4),17); | |
251 | dataModel.setData(dataModel.index(0,5),9); |
|
251 | dataModel.setData(dataModel.index(0,5),9); | |
252 |
|
252 | |||
253 | // Series 2, some other items missing |
|
253 | // Series 2, some other items missing | |
254 | dataModel.setData(dataModel.index(1,0),5); |
|
254 | dataModel.setData(dataModel.index(1,0),5); | |
255 | dataModel.setData(dataModel.index(1,3),4); |
|
255 | dataModel.setData(dataModel.index(1,3),4); | |
256 | dataModel.setData(dataModel.index(1,5),7); |
|
256 | dataModel.setData(dataModel.index(1,5),7); | |
257 | dataModel.setData(dataModel.index(1,6),8); |
|
257 | dataModel.setData(dataModel.index(1,6),8); | |
258 | dataModel.setData(dataModel.index(1,8),9); |
|
258 | dataModel.setData(dataModel.index(1,8),9); | |
259 | dataModel.setData(dataModel.index(1,9),9); |
|
259 | dataModel.setData(dataModel.index(1,9),9); | |
260 |
|
260 | |||
261 | newSeries->setData(&dataModel); |
|
261 | newSeries->setData(&dataModel); | |
262 |
|
262 | |||
263 | m_chartWidget->addSeries(newSeries); |
|
263 | m_chartWidget->addSeries(newSeries); | |
264 | } |
|
264 | } | |
265 |
|
265 | |||
266 | setCurrentSeries(newSeries); |
|
266 | setCurrentSeries(newSeries); | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | void MainWidget::setCurrentSeries(QChartSeries *series) |
|
269 | void MainWidget::setCurrentSeries(QChartSeries *series) | |
270 | { |
|
270 | { | |
271 | m_currentSeries = series; |
|
271 | m_currentSeries = series; | |
272 | switch (m_currentSeries->type()) { |
|
272 | switch (m_currentSeries->type()) { | |
273 | case QChartSeries::SeriesTypeLine: |
|
273 | case QChartSeries::SeriesTypeLine: | |
274 | break; |
|
274 | break; | |
275 | case QChartSeries::SeriesTypeScatter: |
|
275 | case QChartSeries::SeriesTypeScatter: | |
276 | break; |
|
276 | break; | |
277 | case QChartSeries::SeriesTypePie: |
|
277 | case QChartSeries::SeriesTypePie: | |
278 | break; |
|
278 | break; | |
279 | case QChartSeries::SeriesTypeBar: |
|
279 | case QChartSeries::SeriesTypeBar: | |
280 | qDebug() << "setCurrentSeries (bar)"; |
|
280 | qDebug() << "setCurrentSeries (bar)"; | |
281 | break; |
|
281 | break; | |
282 | default: |
|
282 | default: | |
283 | Q_ASSERT(false); |
|
283 | Q_ASSERT(false); | |
284 | break; |
|
284 | break; | |
285 | } |
|
285 | } | |
286 | } |
|
286 | } | |
287 |
|
287 | |||
288 | void MainWidget::testDataChanged(int itemIndex) |
|
288 | void MainWidget::testDataChanged(int itemIndex) | |
289 | { |
|
289 | { | |
290 | qDebug() << "testDataChanged: " << itemIndex; |
|
290 | qDebug() << "testDataChanged: " << itemIndex; | |
291 |
|
291 | |||
292 | // switch (itemIndex) { |
|
292 | // switch (itemIndex) { | |
293 | // case 0: { |
|
293 | // case 0: { | |
294 | // QList<QChartDataPoint> data; |
|
294 | // QList<QChartDataPoint> data; | |
295 | // for (int x = 0; x < 20; x++) { |
|
295 | // for (int x = 0; x < 20; x++) { | |
296 | // data.append(QChartDataPoint() << x << x / 2); |
|
296 | // data.append(QChartDataPoint() << x << x / 2); | |
297 | // } |
|
297 | // } | |
298 | // m_chartWidget->setData(data); |
|
298 | // m_chartWidget->setData(data); | |
299 | // break; |
|
299 | // break; | |
300 | // } |
|
300 | // } | |
301 | // case 1: { |
|
301 | // case 1: { | |
302 | // QList<QChartDataPoint> data; |
|
302 | // QList<QChartDataPoint> data; | |
303 | // for (int x = 0; x < 100; x++) { |
|
303 | // for (int x = 0; x < 100; x++) { | |
304 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100)); |
|
304 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100)); | |
305 | // } |
|
305 | // } | |
306 | // m_chartWidget->setData(data); |
|
306 | // m_chartWidget->setData(data); | |
307 | // break; |
|
307 | // break; | |
308 | // } |
|
308 | // } | |
309 | // case 2: { |
|
309 | // case 2: { | |
310 | // QList<QChartDataPoint> data; |
|
310 | // QList<QChartDataPoint> data; | |
311 | // for (int x = 0; x < 1000; x++) { |
|
311 | // for (int x = 0; x < 1000; x++) { | |
312 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
312 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
313 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
313 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
314 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
314 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
315 | // } |
|
315 | // } | |
316 | // m_chartWidget->setData(data); |
|
316 | // m_chartWidget->setData(data); | |
317 | // break; |
|
317 | // break; | |
318 | // } |
|
318 | // } | |
319 | // default: |
|
319 | // default: | |
320 | // break; |
|
320 | // break; | |
321 | // } |
|
321 | // } | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | void MainWidget::backgroundChanged(int itemIndex) |
|
324 | void MainWidget::backgroundChanged(int itemIndex) | |
325 | { |
|
325 | { | |
326 | qDebug() << "backgroundChanged: " << itemIndex; |
|
326 | qDebug() << "backgroundChanged: " << itemIndex; | |
327 | } |
|
327 | } | |
328 |
|
328 | |||
329 | void MainWidget::autoScaleChanged(int value) |
|
329 | void MainWidget::autoScaleChanged(int value) | |
330 | { |
|
330 | { | |
331 | if (value) { |
|
331 | if (value) { | |
332 | // TODO: enable auto scaling |
|
332 | // TODO: enable auto scaling | |
333 | } else { |
|
333 | } else { | |
334 | // TODO: set scaling manually (and disable auto scaling) |
|
334 | // TODO: set scaling manually (and disable auto scaling) | |
335 | } |
|
335 | } | |
336 |
|
336 | |||
337 | m_xMinSpin->setEnabled(!value); |
|
337 | m_xMinSpin->setEnabled(!value); | |
338 | m_xMaxSpin->setEnabled(!value); |
|
338 | m_xMaxSpin->setEnabled(!value); | |
339 | m_yMinSpin->setEnabled(!value); |
|
339 | m_yMinSpin->setEnabled(!value); | |
340 | m_yMaxSpin->setEnabled(!value); |
|
340 | m_yMaxSpin->setEnabled(!value); | |
341 | } |
|
341 | } | |
342 |
|
342 | |||
343 | void MainWidget::xMinChanged(int value) |
|
343 | void MainWidget::xMinChanged(int value) | |
344 | { |
|
344 | { | |
345 | qDebug() << "xMinChanged: " << value; |
|
345 | qDebug() << "xMinChanged: " << value; | |
346 | } |
|
346 | } | |
347 |
|
347 | |||
348 | void MainWidget::xMaxChanged(int value) |
|
348 | void MainWidget::xMaxChanged(int value) | |
349 | { |
|
349 | { | |
350 | qDebug() << "xMaxChanged: " << value; |
|
350 | qDebug() << "xMaxChanged: " << value; | |
351 | } |
|
351 | } | |
352 |
|
352 | |||
353 | void MainWidget::yMinChanged(int value) |
|
353 | void MainWidget::yMinChanged(int value) | |
354 | { |
|
354 | { | |
355 | qDebug() << "yMinChanged: " << value; |
|
355 | qDebug() << "yMinChanged: " << value; | |
356 | } |
|
356 | } | |
357 |
|
357 | |||
358 | void MainWidget::yMaxChanged(int value) |
|
358 | void MainWidget::yMaxChanged(int value) | |
359 | { |
|
359 | { | |
360 | qDebug() << "yMaxChanged: " << value; |
|
360 | qDebug() << "yMaxChanged: " << value; | |
361 | } |
|
361 | } | |
362 |
|
362 | |||
363 | void MainWidget::changeChartTheme(int themeIndex) |
|
363 | void MainWidget::changeChartTheme(int themeIndex) | |
364 | { |
|
364 | { | |
365 | qDebug() << "changeChartTheme: " << themeIndex; |
|
365 | qDebug() << "changeChartTheme: " << themeIndex; | |
366 | m_chartWidget->setChartTheme((QChart::ChartTheme) themeIndex); |
|
366 | m_chartWidget->setChartTheme((QChart::ChartTheme) themeIndex); | |
367 | } |
|
367 | } | |
368 |
|
368 | |||
369 | void MainWidget::setPieSizeFactor(double size) |
|
369 | void MainWidget::setPieSizeFactor(double size) | |
370 | { |
|
370 | { | |
371 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); |
|
371 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); | |
372 | if (pie) |
|
372 | if (pie) | |
373 | pie->setSizeFactor(qreal(size)); |
|
373 | pie->setSizeFactor(qreal(size)); | |
374 | } |
|
374 | } | |
375 |
|
375 | |||
376 | void MainWidget::setPiePosition(int position) |
|
376 | void MainWidget::setPiePosition(int position) | |
377 | { |
|
377 | { | |
378 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); |
|
378 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); | |
379 | if (pie) |
|
379 | if (pie) | |
380 | pie->setPosition((QPieSeries::PiePosition) position); |
|
380 | pie->setPosition((QPieSeries::PiePosition) position); | |
381 | } |
|
381 | } |
General Comments 0
You need to be logged in to leave comments.
Login now