@@ -1,31 +1,31 | |||
|
1 | 1 | !include(common.pri) { |
|
2 | 2 | error('missing common.pri') |
|
3 | 3 | } |
|
4 | 4 | |
|
5 | 5 | TEMPLATE = subdirs |
|
6 | 6 | SUBDIRS += src example test qmlplugin |
|
7 | 7 | |
|
8 | 8 | integrated_build:{ |
|
9 | 9 | message('Configured for integrated build') |
|
10 | 10 | } else { |
|
11 | 11 | message('Please build example test and qmlplugin after installing library.') |
|
12 | 12 | } |
|
13 | 13 | |
|
14 | 14 | CONFIG += ordered |
|
15 | 15 | QMAKE_CXXFLAGS += -g -Wall |
|
16 | unix:QMAKE_DISTCLEAN += -r build bin doc/html | |
|
17 | win32:QMAKE_DISTCLEAN += /Q /s build bin doc\\html | |
|
16 | unix:QMAKE_DISTCLEAN += -r build bin include lib doc/html | |
|
17 | win32:QMAKE_DISTCLEAN += /Q /s build bin include lib doc\\html | |
|
18 | 18 | |
|
19 | 19 | # install feature file |
|
20 | 20 | feature.path = $$[QT_INSTALL_DATA]/mkspecs/features |
|
21 | 21 | feature.files = $$PWD/features/qtcommercialchart.prf |
|
22 | 22 | INSTALLS += feature |
|
23 | 23 | |
|
24 | 24 | doc.target = doc |
|
25 | 25 | win32:{ |
|
26 | 26 | doc.commands = qdoc3 $$CHART_BUILD_DOC_DIR\\qcharts.qdocconf |
|
27 | 27 | }else{ |
|
28 | 28 | doc.commands = qdoc3 $$CHART_BUILD_DOC_DIR/qcharts.qdocconf |
|
29 | 29 | } |
|
30 | 30 | doc.depends = FORCE |
|
31 | 31 | QMAKE_EXTRA_TARGETS += doc |
@@ -1,67 +1,67 | |||
|
1 | 1 | #include <QApplication> |
|
2 | 2 | #include <QMainWindow> |
|
3 | 3 | #include <qchartview.h> |
|
4 |
#include <qline |
|
|
4 | #include <qlineseries.h> | |
|
5 | 5 | #include <qchart.h> |
|
6 | 6 | #include <qchartaxis.h> |
|
7 | 7 | #include <cmath> |
|
8 | 8 | |
|
9 | 9 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
10 | 10 | |
|
11 | 11 | #define PI 3.14159265358979 |
|
12 | 12 | |
|
13 | 13 | int main(int argc, char *argv[]) |
|
14 | 14 | { |
|
15 | 15 | QApplication a(argc, argv); |
|
16 | 16 | |
|
17 | 17 | QMainWindow window; |
|
18 | 18 | |
|
19 |
QLine |
|
|
19 | QLineSeries* series0 = new QLineSeries(); | |
|
20 | 20 | QPen blue(Qt::blue); |
|
21 | 21 | blue.setWidth(3); |
|
22 | 22 | series0->setPen(blue); |
|
23 |
QLine |
|
|
23 | QLineSeries* series1 = new QLineSeries(); | |
|
24 | 24 | QPen red(Qt::red); |
|
25 | 25 | red.setWidth(3); |
|
26 | 26 | series1->setPen(red); |
|
27 | 27 | |
|
28 | 28 | int numPoints = 100; |
|
29 | 29 | |
|
30 | 30 | for (int x = 0; x <= numPoints; ++x) { |
|
31 | 31 | series0->add(x, fabs(sin(PI/50*x)*100)); |
|
32 | 32 | series1->add(x, fabs(cos(PI/50*x)*100)); |
|
33 | 33 | } |
|
34 | 34 | |
|
35 | 35 | QChartView* chartView = new QChartView(&window); |
|
36 | 36 | |
|
37 | 37 | chartView->setRenderHint(QPainter::Antialiasing); |
|
38 | 38 | chartView->setChartTitle("This is custom axis chart example"); |
|
39 | 39 | chartView->addSeries(series0); |
|
40 | 40 | chartView->addSeries(series1); |
|
41 | 41 | |
|
42 | 42 | QLinearGradient backgroundGradient; |
|
43 | 43 | backgroundGradient.setColorAt(0.0, Qt::white); |
|
44 | 44 | backgroundGradient.setColorAt(1.0, QRgb(0xffff80)); |
|
45 | 45 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
46 | 46 | chartView->setChartBackgroundBrush(backgroundGradient); |
|
47 | 47 | |
|
48 | 48 | QChartAxis* axisX = chartView->axisX(); |
|
49 | 49 | axisX->setLabelsAngle(45); |
|
50 | 50 | axisX->setGridPen(Qt::DashLine); |
|
51 | 51 | axisX->addAxisTickLabel(0,"low"); |
|
52 | 52 | axisX->addAxisTickLabel(50,"medium"); |
|
53 | 53 | axisX->addAxisTickLabel(100,"High"); |
|
54 | 54 | |
|
55 | 55 | QChartAxis* axisY = chartView->axisY(); |
|
56 | 56 | axisY->setLabelsAngle(45); |
|
57 | 57 | axisY->setShadesBrush(Qt::yellow); |
|
58 | 58 | axisY->addAxisTickLabel(0,"low"); |
|
59 | 59 | axisY->addAxisTickLabel(50,"medium"); |
|
60 | 60 | axisY->addAxisTickLabel(100,"High"); |
|
61 | 61 | |
|
62 | 62 | window.setCentralWidget(chartView); |
|
63 | 63 | window.resize(400, 300); |
|
64 | 64 | window.show(); |
|
65 | 65 | |
|
66 | 66 | return a.exec(); |
|
67 | 67 | } |
@@ -1,83 +1,83 | |||
|
1 | 1 | #include <QtGui/QApplication> |
|
2 | 2 | #include <QMainWindow> |
|
3 | 3 | #include <qchartglobal.h> |
|
4 | 4 | #include <qchartview.h> |
|
5 |
#include <qline |
|
|
5 | #include <qlineseries.h> | |
|
6 | 6 | #include <qscatterseries.h> |
|
7 | 7 | #include <qbarseries.h> |
|
8 | 8 | #include <qbarset.h> |
|
9 | 9 | #include <qbarcategory.h> |
|
10 | 10 | #include <qpieseries.h> |
|
11 | 11 | |
|
12 | 12 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
13 | 13 | |
|
14 | 14 | int main(int argc, char *argv[]) |
|
15 | 15 | { |
|
16 | 16 | QApplication a(argc, argv); |
|
17 | 17 | |
|
18 | 18 | //! [1] |
|
19 | 19 | // Create chart view |
|
20 | 20 | QChartView *chartView = new QChartView(); |
|
21 | 21 | chartView->setRenderHint(QPainter::Antialiasing); |
|
22 | 22 | chartView->setChartTitle("Simple Line Chart"); |
|
23 | 23 | // Add series to the chart |
|
24 |
QLine |
|
|
24 | QLineSeries *line = new QLineSeries(); | |
|
25 | 25 | line->add(0.0, 0.8); |
|
26 | 26 | line->add(1.1, 1.1); |
|
27 | 27 | line->add(2.0, 2.5); |
|
28 | 28 | chartView->addSeries(line); |
|
29 | 29 | //! [1] |
|
30 | 30 | |
|
31 | 31 | chartView->setChartTitle("\'Scietific\' theme"); |
|
32 | 32 | //! [2] |
|
33 | 33 | // Change theme |
|
34 | 34 | chartView->setChartTheme(QChart::ChartThemeScientific); |
|
35 | 35 | //! [2] |
|
36 | 36 | |
|
37 | 37 | chartView->setChartTitle("Simple Pie Chart"); |
|
38 | 38 | //! [3] |
|
39 | 39 | // Add pie series |
|
40 | 40 | // ... |
|
41 | 41 | QPieSeries *pie = new QPieSeries(); |
|
42 | 42 | pie->add(3.4, "slice1"); |
|
43 | 43 | pie->add(6.7, "slice2"); |
|
44 | 44 | chartView->addSeries(pie); |
|
45 | 45 | //! [3] |
|
46 | 46 | |
|
47 | 47 | chartView->setChartTitle("Simple Scatter Chart"); |
|
48 | 48 | //! [4] |
|
49 | 49 | // Add scatter series |
|
50 | 50 | // ... |
|
51 | 51 | QScatterSeries *scatter = new QScatterSeries(); |
|
52 | 52 | for (qreal x(0); x < 100; x += 0.5) { |
|
53 | 53 | qreal y = rand() % 100; |
|
54 | 54 | *(scatter) << QPointF(x, y); |
|
55 | 55 | } |
|
56 | 56 | chartView->addSeries(scatter); |
|
57 | 57 | //! [4] |
|
58 | 58 | |
|
59 | 59 | chartView->setChartTitle("Simple Bar Chart"); |
|
60 | 60 | //! [5] |
|
61 | 61 | // ... |
|
62 | 62 | // Add bar series |
|
63 | 63 | QBarCategory *barCategory = new QBarCategory(); |
|
64 | 64 | *barCategory << "Jan" |
|
65 | 65 | << "Feb" |
|
66 | 66 | << "Mar"; |
|
67 | 67 | QBarSeries *bar = new QBarSeries(barCategory); |
|
68 | 68 | QBarSet *barSet = new QBarSet("Sales"); |
|
69 | 69 | *barSet << 123.2 |
|
70 | 70 | << 301.3 |
|
71 | 71 | << 285.8; |
|
72 | 72 | bar->addBarSet(barSet); |
|
73 | 73 | chartView->addSeries(bar); |
|
74 | 74 | //! [5] |
|
75 | 75 | |
|
76 | 76 | QMainWindow w; |
|
77 | 77 | w.resize(400, 300); |
|
78 | 78 | w.setCentralWidget(chartView); |
|
79 | 79 | w.setWindowFlags(Qt::FramelessWindowHint); |
|
80 | 80 | w.show(); |
|
81 | 81 | |
|
82 | 82 | return a.exec(); |
|
83 | 83 | } |
@@ -1,55 +1,55 | |||
|
1 | 1 | #include <QApplication> |
|
2 | 2 | #include <QMainWindow> |
|
3 | 3 | #include <qchartview.h> |
|
4 |
#include <qline |
|
|
4 | #include <qlineseries.h> | |
|
5 | 5 | #include <qchart.h> |
|
6 | 6 | #include <cmath> |
|
7 | 7 | |
|
8 | 8 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
9 | 9 | |
|
10 | 10 | #define PI 3.14159265358979 |
|
11 | 11 | |
|
12 | 12 | int main(int argc, char *argv[]) |
|
13 | 13 | { |
|
14 | 14 | QApplication a(argc, argv); |
|
15 | 15 | |
|
16 | 16 | QMainWindow window; |
|
17 | 17 | |
|
18 |
QLine |
|
|
18 | QLineSeries* series0 = new QLineSeries(); | |
|
19 | 19 | QPen blue(Qt::blue); |
|
20 | 20 | blue.setWidth(3); |
|
21 | 21 | series0->setPen(blue); |
|
22 |
QLine |
|
|
22 | QLineSeries* series1 = new QLineSeries(); | |
|
23 | 23 | QPen red(Qt::red); |
|
24 | 24 | red.setWidth(3); |
|
25 | 25 | series1->setPen(red); |
|
26 | 26 | |
|
27 | 27 | int numPoints = 100; |
|
28 | 28 | |
|
29 | 29 | for (int x = 0; x <= numPoints; ++x) { |
|
30 | 30 | series0->add(x, fabs(sin(PI/50*x)*100)); |
|
31 | 31 | series1->add(x, fabs(cos(PI/50*x)*100)); |
|
32 | 32 | } |
|
33 | 33 | |
|
34 | 34 | QChartView* chartView = new QChartView(&window); |
|
35 | 35 | chartView->setRenderHint(QPainter::Antialiasing); |
|
36 | 36 | |
|
37 | 37 | QFont font; |
|
38 | 38 | font.setPixelSize(18); |
|
39 | 39 | chartView->setChartTitleFont(font); |
|
40 | 40 | chartView->setChartTitle("Custom color line chart example"); |
|
41 | 41 | chartView->addSeries(series0); |
|
42 | 42 | chartView->addSeries(series1); |
|
43 | 43 | |
|
44 | 44 | QLinearGradient backgroundGradient; |
|
45 | 45 | backgroundGradient.setColorAt(0.0, Qt::blue); |
|
46 | 46 | backgroundGradient.setColorAt(1.0, Qt::yellow); |
|
47 | 47 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
48 | 48 | chartView->setChartBackgroundBrush(backgroundGradient); |
|
49 | 49 | |
|
50 | 50 | window.setCentralWidget(chartView); |
|
51 | 51 | window.resize(400, 300); |
|
52 | 52 | window.show(); |
|
53 | 53 | |
|
54 | 54 | return a.exec(); |
|
55 | 55 | } |
@@ -1,40 +1,40 | |||
|
1 | 1 | #include <QApplication> |
|
2 | 2 | #include <QMainWindow> |
|
3 | 3 | #include <qchartview.h> |
|
4 |
#include <qline |
|
|
4 | #include <qlineseries.h> | |
|
5 | 5 | #include <qchart.h> |
|
6 | 6 | #include <cmath> |
|
7 | 7 | #include "wavegenerator.h" |
|
8 | 8 | #include <QGLWidget> |
|
9 | 9 | |
|
10 | 10 | int main(int argc, char *argv[]) |
|
11 | 11 | { |
|
12 | 12 | QApplication a(argc, argv); |
|
13 | 13 | |
|
14 | 14 | QMainWindow window; |
|
15 | 15 | |
|
16 |
QLine |
|
|
16 | QLineSeries* series0 = new QLineSeries(); | |
|
17 | 17 | QPen blue(Qt::blue); |
|
18 | 18 | blue.setWidth(3); |
|
19 | 19 | series0->setPen(blue); |
|
20 |
QLine |
|
|
20 | QLineSeries* series1 = new QLineSeries(); | |
|
21 | 21 | QPen red(Qt::red); |
|
22 | 22 | red.setWidth(3); |
|
23 | 23 | series1->setPen(red); |
|
24 | 24 | |
|
25 | 25 | WaveGenerator generator(series0,series1); |
|
26 | 26 | |
|
27 | 27 | QChartView* chartView = new QChartView(&window); |
|
28 | 28 | |
|
29 | 29 | chartView->setViewport( new QGLWidget() ); |
|
30 | 30 | chartView->setRenderHint(QPainter::Antialiasing); |
|
31 | 31 | chartView->setChartTitle("This is wave generator buahha."); |
|
32 | 32 | chartView->addSeries(series0); |
|
33 | 33 | chartView->addSeries(series1); |
|
34 | 34 | |
|
35 | 35 | window.setCentralWidget(chartView); |
|
36 | 36 | window.resize(400, 300); |
|
37 | 37 | window.show(); |
|
38 | 38 | |
|
39 | 39 | return a.exec(); |
|
40 | 40 | } |
@@ -1,60 +1,60 | |||
|
1 | 1 | #include <QTimer> |
|
2 | 2 | #include <QTime> |
|
3 | 3 | #include <QObject> |
|
4 | 4 | #include <cmath> |
|
5 |
#include <qline |
|
|
5 | #include <qlineseries.h> | |
|
6 | 6 | |
|
7 | 7 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
8 | 8 | |
|
9 | 9 | #define PI 3.14159265358979 |
|
10 | 10 | static const int numPoints =100; |
|
11 | 11 | |
|
12 | 12 | class WaveGenerator: public QObject |
|
13 | 13 | { |
|
14 | 14 | Q_OBJECT |
|
15 | 15 | |
|
16 | 16 | public: |
|
17 |
WaveGenerator(QLine |
|
|
17 | WaveGenerator(QLineSeries* series1, QLineSeries* series2) : | |
|
18 | 18 | m_series1(series1), |
|
19 | 19 | m_series2(series2), |
|
20 | 20 | m_wave(0), |
|
21 | 21 | m_step(2*PI/numPoints) |
|
22 | 22 | { |
|
23 | 23 | |
|
24 | 24 | QTime now = QTime::currentTime(); |
|
25 | 25 | qsrand((uint)now.msec()); |
|
26 | 26 | |
|
27 | 27 | int fluctuate = 100; |
|
28 | 28 | |
|
29 | 29 | for (qreal x = 0; x <= 2*PI; x+=m_step) { |
|
30 | 30 | series1->add(x, fabs(sin(x)*fluctuate)); |
|
31 | 31 | series2->add(x, fabs(cos(x)*fluctuate)); |
|
32 | 32 | } |
|
33 | 33 | |
|
34 | 34 | QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(update())); |
|
35 | 35 | m_timer.setInterval(5000); |
|
36 | 36 | m_timer.start(); |
|
37 | 37 | |
|
38 | 38 | }; |
|
39 | 39 | |
|
40 | 40 | public slots: |
|
41 | 41 | void update() |
|
42 | 42 | { |
|
43 | 43 | int fluctuate; |
|
44 | 44 | |
|
45 | 45 | for (qreal i = 0, x = 0; x <= 2*PI; x+=m_step, i++) { |
|
46 | 46 | fluctuate = qrand() % 100; |
|
47 | 47 | m_series1->replace(x, fabs(sin(x)*fluctuate)); |
|
48 | 48 | fluctuate = qrand() % 100; |
|
49 | 49 | m_series2->replace(x, fabs(cos(x)*fluctuate)); |
|
50 | 50 | } |
|
51 | 51 | |
|
52 | 52 | } |
|
53 | 53 | |
|
54 | 54 | private: |
|
55 |
QLine |
|
|
56 |
QLine |
|
|
55 | QLineSeries* m_series1; | |
|
56 | QLineSeries* m_series2; | |
|
57 | 57 | int m_wave; |
|
58 | 58 | qreal m_step; |
|
59 | 59 | QTimer m_timer; |
|
60 | 60 | }; |
@@ -1,56 +1,56 | |||
|
1 | 1 | #include <QApplication> |
|
2 | 2 | #include <QMainWindow> |
|
3 | 3 | #include <qchartview.h> |
|
4 |
#include <qline |
|
|
4 | #include <qlineseries.h> | |
|
5 | 5 | #include <qchart.h> |
|
6 | 6 | #include <cmath> |
|
7 | 7 | |
|
8 | 8 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
9 | 9 | |
|
10 | 10 | int main(int argc, char *argv[]) |
|
11 | 11 | { |
|
12 | 12 | QApplication a(argc, argv); |
|
13 | 13 | |
|
14 | 14 | QMainWindow window; |
|
15 | 15 | |
|
16 | 16 | //![1] |
|
17 | 17 | |
|
18 |
QLine |
|
|
18 | QLineSeries* series0 = new QLineSeries(); | |
|
19 | 19 | QPen blue(Qt::blue); |
|
20 | 20 | blue.setWidth(3); |
|
21 | 21 | series0->setPen(blue); |
|
22 | 22 | |
|
23 |
QLine |
|
|
23 | QLineSeries* series1 = new QLineSeries(); | |
|
24 | 24 | QPen red(Qt::red); |
|
25 | 25 | red.setWidth(3); |
|
26 | 26 | series1->setPen(red); |
|
27 | 27 | //![1] |
|
28 | 28 | |
|
29 | 29 | //![2] |
|
30 | 30 | series0->add(0, 6); |
|
31 | 31 | series0->add(2, 4); |
|
32 | 32 | series0->add(3, 8); |
|
33 | 33 | series0->add(7, 4); |
|
34 | 34 | series0->add(10,5); |
|
35 | 35 | |
|
36 | 36 | series1->add(1, 1); |
|
37 | 37 | series1->add(3, 3); |
|
38 | 38 | series1->add(7, 6); |
|
39 | 39 | series1->add(8, 3); |
|
40 | 40 | series1->add(10,2); |
|
41 | 41 | //![2] |
|
42 | 42 | //![3] |
|
43 | 43 | QChartView* chartView = new QChartView(&window); |
|
44 | 44 | |
|
45 | 45 | chartView->setRenderHint(QPainter::Antialiasing); |
|
46 | 46 | chartView->setChartTitle("Basic line chart example"); |
|
47 | 47 | chartView->addSeries(series0); |
|
48 | 48 | chartView->addSeries(series1); |
|
49 | 49 | //![3] |
|
50 | 50 | |
|
51 | 51 | window.setCentralWidget(chartView); |
|
52 | 52 | window.resize(400, 300); |
|
53 | 53 | window.show(); |
|
54 | 54 | |
|
55 | 55 | return a.exec(); |
|
56 | 56 | } |
@@ -1,59 +1,59 | |||
|
1 | 1 | #include "chartview.h" |
|
2 |
#include <qline |
|
|
2 | #include <qlineseries.h> | |
|
3 | 3 | #include <QTime> |
|
4 | 4 | |
|
5 | 5 | ChartView::ChartView(QWidget* parent):QChartView(parent), |
|
6 | 6 | m_index(0) |
|
7 | 7 | { |
|
8 | 8 | QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout())); |
|
9 | 9 | m_timer.setInterval(3000); |
|
10 | 10 | |
|
11 | 11 | QTime now = QTime::currentTime(); |
|
12 | 12 | qsrand((uint)now.msec()); |
|
13 | 13 | |
|
14 |
QLine |
|
|
14 | QLineSeries* series0 = new QLineSeries(); | |
|
15 | 15 | QPen blue(Qt::blue); |
|
16 | 16 | blue.setWidth(3); |
|
17 | 17 | series0->setPen(blue); |
|
18 |
QLine |
|
|
18 | QLineSeries* series1 = new QLineSeries(); | |
|
19 | 19 | QPen red(Qt::red); |
|
20 | 20 | red.setWidth(3); |
|
21 | 21 | series1->setPen(red); |
|
22 |
QLine |
|
|
22 | QLineSeries* series2 = new QLineSeries(); | |
|
23 | 23 | QPen green(Qt::green); |
|
24 | 24 | green.setWidth(3); |
|
25 | 25 | series2->setPen(green); |
|
26 | 26 | |
|
27 | 27 | int numPoints = 10; |
|
28 | 28 | |
|
29 | 29 | for (int x = 0; x <= numPoints; ++x) { |
|
30 | 30 | series0->add(x, qrand() % 100); |
|
31 | 31 | series1->add(x, qrand() % 100); |
|
32 | 32 | series2->add(x, qrand() % 100); |
|
33 | 33 | } |
|
34 | 34 | |
|
35 | 35 | addSeries(series0); |
|
36 | 36 | |
|
37 | 37 | m_series<<series0; |
|
38 | 38 | m_series<<series1; |
|
39 | 39 | m_series<<series2; |
|
40 | 40 | |
|
41 | 41 | m_timer.start(); |
|
42 | 42 | } |
|
43 | 43 | |
|
44 | 44 | ChartView::~ChartView() |
|
45 | 45 | { |
|
46 | 46 | if(m_series.size()==0) return; |
|
47 | 47 | removeSeries(m_series.at(m_index)); |
|
48 | 48 | qDeleteAll(m_series); |
|
49 | 49 | } |
|
50 | 50 | |
|
51 | 51 | void ChartView::handleTimeout() |
|
52 | 52 | { |
|
53 | 53 | if(m_series.size()==0) return; |
|
54 | 54 | |
|
55 | 55 | removeSeries(m_series.at(m_index)); |
|
56 | 56 | m_index++; |
|
57 | 57 | m_index=m_index%m_series.size(); |
|
58 | 58 | addSeries(m_series.at(m_index)); |
|
59 | 59 | } |
@@ -1,44 +1,44 | |||
|
1 | 1 | #include "chartwidget.h" |
|
2 | 2 | #include <QApplication> |
|
3 | 3 | #include <QMainWindow> |
|
4 |
#include <qline |
|
|
4 | #include <qlineseries.h> | |
|
5 | 5 | #include <cmath> |
|
6 | 6 | |
|
7 | 7 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
8 | 8 | |
|
9 | 9 | #define PI 3.14159265358979 |
|
10 | 10 | |
|
11 | 11 | int main(int argc, char *argv[]) |
|
12 | 12 | { |
|
13 | 13 | QApplication a(argc, argv); |
|
14 | 14 | |
|
15 | 15 | QMainWindow window; |
|
16 | 16 | |
|
17 |
QLine |
|
|
17 | QLineSeries* series0 = new QLineSeries(); | |
|
18 | 18 | QPen blue(Qt::blue); |
|
19 | 19 | blue.setWidth(3); |
|
20 | 20 | series0->setPen(blue); |
|
21 |
QLine |
|
|
21 | QLineSeries* series1 = new QLineSeries(); | |
|
22 | 22 | QPen red(Qt::red); |
|
23 | 23 | red.setWidth(3); |
|
24 | 24 | series1->setPen(red); |
|
25 | 25 | |
|
26 | 26 | int numPoints = 100; |
|
27 | 27 | |
|
28 | 28 | for (int x = 0; x <= numPoints; ++x) { |
|
29 | 29 | series0->add(x, fabs(sin(PI/50*x)*100)); |
|
30 | 30 | series1->add(x, fabs(cos(PI/50*x)*100)); |
|
31 | 31 | } |
|
32 | 32 | |
|
33 | 33 | ChartWidget* chartWidget = new ChartWidget(&window); |
|
34 | 34 | chartWidget->setRenderHint(QPainter::Antialiasing); |
|
35 | 35 | chartWidget->setChartTitle("Zoom in/out line chart example"); |
|
36 | 36 | chartWidget->addSeries(series0); |
|
37 | 37 | chartWidget->addSeries(series1); |
|
38 | 38 | |
|
39 | 39 | window.setCentralWidget(chartWidget); |
|
40 | 40 | window.resize(400, 300); |
|
41 | 41 | window.show(); |
|
42 | 42 | |
|
43 | 43 | return a.exec(); |
|
44 | 44 | } |
@@ -1,55 +1,55 | |||
|
1 | 1 | #include "declarativelineseries.h" |
|
2 | 2 | #include "declarativechart.h" |
|
3 | 3 | #include "qchart.h" |
|
4 |
#include "qline |
|
|
4 | #include "qlineseries.h" | |
|
5 | 5 | |
|
6 | 6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | 7 | |
|
8 | 8 | DeclarativeLineSeries::DeclarativeLineSeries(QDeclarativeItem *parent) : |
|
9 | 9 | QDeclarativeItem(parent) |
|
10 | 10 | { |
|
11 | 11 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
12 | 12 | connect(this, SIGNAL(parentChanged()), |
|
13 | 13 | this, SLOT(setParentForSeries())); |
|
14 | 14 | } |
|
15 | 15 | |
|
16 | 16 | void DeclarativeLineSeries::setParentForSeries() |
|
17 | 17 | { |
|
18 | 18 | if (!m_series) { |
|
19 | 19 | DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent()); |
|
20 | 20 | |
|
21 | 21 | if (declarativeChart) { |
|
22 | 22 | QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart); |
|
23 | 23 | qDebug() << "creating line series for chart: " << chart; |
|
24 | 24 | Q_ASSERT(chart); |
|
25 | 25 | |
|
26 |
m_series = new QLine |
|
|
26 | m_series = new QLineSeries(); | |
|
27 | 27 | Q_ASSERT(m_series); |
|
28 | 28 | for (int i(0); i < m_data.count(); i++) { |
|
29 | 29 | ScatterElement *element = m_data.at(i); |
|
30 | 30 | m_series->add(element->x(), element->y()); |
|
31 | 31 | } |
|
32 | 32 | chart->addSeries(m_series); |
|
33 | 33 | } |
|
34 | 34 | } |
|
35 | 35 | } |
|
36 | 36 | |
|
37 | 37 | QDeclarativeListProperty<ScatterElement> DeclarativeLineSeries::data() |
|
38 | 38 | { |
|
39 | 39 | return QDeclarativeListProperty<ScatterElement>(this, 0, &DeclarativeLineSeries::appendData); |
|
40 | 40 | } |
|
41 | 41 | |
|
42 | 42 | void DeclarativeLineSeries::appendData(QDeclarativeListProperty<ScatterElement> *list, |
|
43 | 43 | ScatterElement *element) |
|
44 | 44 | { |
|
45 | 45 | DeclarativeLineSeries *series = qobject_cast<DeclarativeLineSeries *>(list->object); |
|
46 | 46 | if (series) { |
|
47 | 47 | series->m_data.append(element); |
|
48 | 48 | if (series->m_series) |
|
49 | 49 | series->m_series->add(element->x(), element->y()); |
|
50 | 50 | } |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | #include "moc_declarativelineseries.cpp" |
|
54 | 54 | |
|
55 | 55 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,39 +1,39 | |||
|
1 | 1 | #ifndef DECLARATIVELINESERIES_H |
|
2 | 2 | #define DECLARATIVELINESERIES_H |
|
3 | 3 | |
|
4 | 4 | #include "qchartglobal.h" |
|
5 | 5 | #include "scatterelement.h" // TODO: rename header |
|
6 | 6 | #include <QDeclarativeItem> |
|
7 | 7 | |
|
8 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 9 | |
|
10 | 10 | class QChart; |
|
11 |
class QLine |
|
|
11 | class QLineSeries; | |
|
12 | 12 | |
|
13 | 13 | class DeclarativeLineSeries : public QDeclarativeItem |
|
14 | 14 | { |
|
15 | 15 | Q_OBJECT |
|
16 | 16 | Q_PROPERTY(QDeclarativeListProperty<ScatterElement> data READ data) |
|
17 | 17 | |
|
18 | 18 | public: |
|
19 | 19 | explicit DeclarativeLineSeries(QDeclarativeItem *parent = 0); |
|
20 | 20 | QDeclarativeListProperty<ScatterElement> data(); |
|
21 | 21 | |
|
22 | 22 | signals: |
|
23 | 23 | |
|
24 | 24 | public slots: |
|
25 | 25 | static void appendData(QDeclarativeListProperty<ScatterElement> *list, |
|
26 | 26 | ScatterElement *element); |
|
27 | 27 | |
|
28 | 28 | private slots: |
|
29 | 29 | void setParentForSeries(); |
|
30 | 30 | |
|
31 | 31 | private: |
|
32 | 32 | QChart *m_chart; |
|
33 |
QLine |
|
|
33 | QLineSeries *m_series; | |
|
34 | 34 | QList<ScatterElement *> m_data; |
|
35 | 35 | }; |
|
36 | 36 | |
|
37 | 37 | QTCOMMERCIALCHART_END_NAMESPACE |
|
38 | 38 | |
|
39 | 39 | #endif // DECLARATIVELINESERIES_H |
@@ -1,357 +1,357 | |||
|
1 | 1 | #include "chartdataset_p.h" |
|
2 | 2 | #include "qchartaxis.h" |
|
3 | 3 | //series |
|
4 |
#include "qline |
|
|
4 | #include "qlineseries.h" | |
|
5 | 5 | #include "qbarseries.h" |
|
6 | 6 | #include "qstackedbarseries.h" |
|
7 | 7 | #include "qpercentbarseries.h" |
|
8 | 8 | #include "qpieseries.h" |
|
9 | 9 | #include "qscatterseries.h" |
|
10 | 10 | |
|
11 | 11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | 12 | |
|
13 | 13 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), |
|
14 | 14 | m_axisX(new QChartAxis(this)), |
|
15 | 15 | m_axisY(new QChartAxis(this)), |
|
16 | 16 | m_domainIndex(0), |
|
17 | 17 | m_axisXInitialized(false) |
|
18 | 18 | { |
|
19 | 19 | } |
|
20 | 20 | |
|
21 | 21 | ChartDataSet::~ChartDataSet() |
|
22 | 22 | { |
|
23 | 23 | // TODO Auto-generated destructor stub |
|
24 | 24 | } |
|
25 | 25 | |
|
26 | 26 | const Domain ChartDataSet::domain(QChartAxis *axisY) const |
|
27 | 27 | { |
|
28 | 28 | int i = m_domainMap.count(axisY); |
|
29 | 29 | if(i == 0){ |
|
30 | 30 | return Domain(); |
|
31 | 31 | } |
|
32 | 32 | i = i - m_domainIndex -1; |
|
33 | 33 | return m_domainMap.values(axisY).at(i); |
|
34 | 34 | } |
|
35 | 35 | |
|
36 | 36 | void ChartDataSet::addSeries(QChartSeries* series, QChartAxis *axisY) |
|
37 | 37 | { |
|
38 | 38 | // TODO: we should check the series not already added |
|
39 | 39 | |
|
40 | 40 | series->setParent(this); // take ownership |
|
41 | 41 | clearDomains(); |
|
42 | 42 | |
|
43 | 43 | if(axisY==0) axisY = m_axisY; |
|
44 | 44 | axisY->setParent(this); // take ownership |
|
45 | 45 | |
|
46 | 46 | QList<QChartSeries*> seriesList = m_seriesMap.values(axisY); |
|
47 | 47 | |
|
48 | 48 | QList<Domain> domainList = m_domainMap.values(axisY); |
|
49 | 49 | |
|
50 | 50 | Q_ASSERT(domainList.size()<=1); |
|
51 | 51 | |
|
52 | 52 | Domain domain; |
|
53 | 53 | |
|
54 | 54 | if(domainList.size()>0) domain = domainList.at(0); |
|
55 | 55 | |
|
56 | 56 | switch(series->type()) |
|
57 | 57 | { |
|
58 | 58 | case QChartSeries::SeriesTypeLine: { |
|
59 | 59 | |
|
60 |
QLine |
|
|
60 | QLineSeries* xyseries = static_cast<QLineSeries*>(series); | |
|
61 | 61 | |
|
62 | 62 | for (int i = 0; i < xyseries->count(); i++) |
|
63 | 63 | { |
|
64 | 64 | qreal x = xyseries->x(i); |
|
65 | 65 | qreal y = xyseries->y(i); |
|
66 | 66 | domain.m_minX = qMin(domain.m_minX,x); |
|
67 | 67 | domain.m_minY = qMin(domain.m_minY,y); |
|
68 | 68 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
69 | 69 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
70 | 70 | } |
|
71 | 71 | break; |
|
72 | 72 | } |
|
73 | 73 | case QChartSeries::SeriesTypeBar: { |
|
74 | 74 | qDebug() << "QChartSeries::SeriesTypeBar"; |
|
75 | 75 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
76 | 76 | qreal x = barSeries->countCategories(); |
|
77 | 77 | qreal y = barSeries->max(); |
|
78 | 78 | domain.m_minX = qMin(domain.m_minX,x); |
|
79 | 79 | domain.m_minY = qMin(domain.m_minY,y); |
|
80 | 80 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
81 | 81 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
82 | 82 | break; |
|
83 | 83 | } |
|
84 | 84 | case QChartSeries::SeriesTypeStackedBar: { |
|
85 | 85 | qDebug() << "QChartSeries::SeriesTypeStackedBar"; |
|
86 | 86 | |
|
87 | 87 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
88 | 88 | qreal x = stackedBarSeries->countCategories(); |
|
89 | 89 | qreal y = stackedBarSeries->maxCategorySum(); |
|
90 | 90 | domain.m_minX = qMin(domain.m_minX,x); |
|
91 | 91 | domain.m_minY = qMin(domain.m_minY,y); |
|
92 | 92 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
93 | 93 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
94 | 94 | break; |
|
95 | 95 | } |
|
96 | 96 | case QChartSeries::SeriesTypePercentBar: { |
|
97 | 97 | qDebug() << "QChartSeries::SeriesTypePercentBar"; |
|
98 | 98 | |
|
99 | 99 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
100 | 100 | qreal x = percentBarSeries->countCategories(); |
|
101 | 101 | domain.m_minX = qMin(domain.m_minX,x); |
|
102 | 102 | domain.m_minY = 0; |
|
103 | 103 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
104 | 104 | domain.m_maxY = 100; |
|
105 | 105 | break; |
|
106 | 106 | } |
|
107 | 107 | |
|
108 | 108 | case QChartSeries::SeriesTypePie: { |
|
109 | 109 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
110 | 110 | // TODO: domain stuff |
|
111 | 111 | break; |
|
112 | 112 | } |
|
113 | 113 | |
|
114 | 114 | case QChartSeries::SeriesTypeScatter: { |
|
115 | 115 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
116 | 116 | Q_ASSERT(scatterSeries); |
|
117 | 117 | foreach (QPointF point, scatterSeries->data()) { |
|
118 | 118 | domain.m_minX = qMin(domain.m_minX, point.x()); |
|
119 | 119 | domain.m_maxX = qMax(domain.m_maxX, point.x()); |
|
120 | 120 | domain.m_minY = qMin(domain.m_minY, point.y()); |
|
121 | 121 | domain.m_maxY = qMax(domain.m_maxY, point.y()); |
|
122 | 122 | } |
|
123 | 123 | break; |
|
124 | 124 | } |
|
125 | 125 | |
|
126 | 126 | default: { |
|
127 | 127 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; |
|
128 | 128 | return; |
|
129 | 129 | break; |
|
130 | 130 | } |
|
131 | 131 | |
|
132 | 132 | } |
|
133 | 133 | |
|
134 | 134 | if(!m_domainMap.contains(axisY)) |
|
135 | 135 | { |
|
136 | 136 | emit axisAdded(axisY); |
|
137 | 137 | QObject::connect(axisY,SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal))); |
|
138 | 138 | QObject::connect(axisY,SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal))); |
|
139 | 139 | QObject::connect(axisY,SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); |
|
140 | 140 | } |
|
141 | 141 | m_domainMap.replace(axisY,domain); |
|
142 | 142 | m_seriesMap.insert(axisY,series); |
|
143 | 143 | |
|
144 | 144 | if(!m_axisXInitialized) |
|
145 | 145 | { |
|
146 | 146 | emit axisAdded(axisX()); |
|
147 | 147 | QObject::connect(axisX(),SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal))); |
|
148 | 148 | QObject::connect(axisX(),SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal))); |
|
149 | 149 | QObject::connect(axisX(),SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); |
|
150 | 150 | m_axisXInitialized=true; |
|
151 | 151 | } |
|
152 | 152 | |
|
153 | 153 | |
|
154 | 154 | emit seriesAdded(series); |
|
155 | 155 | QStringList ylabels = createLabels(axisY,domain.m_minY,domain.m_maxY); |
|
156 | 156 | QStringList xlabels = createLabels(axisX(),domain.m_minX,domain.m_maxX); |
|
157 | 157 | emit axisLabelsChanged(axisY,ylabels); |
|
158 | 158 | emit axisLabelsChanged(axisX(),xlabels); |
|
159 | 159 | emit seriesDomainChanged(series,domain); |
|
160 | 160 | |
|
161 | 161 | } |
|
162 | 162 | |
|
163 | 163 | void ChartDataSet::removeSeries(QChartSeries* series) |
|
164 | 164 | { |
|
165 | 165 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
166 | 166 | foreach(QChartAxis* axis , keys) { |
|
167 | 167 | if(m_seriesMap.contains(axis,series)){ |
|
168 | 168 | emit seriesRemoved(series); |
|
169 | 169 | m_seriesMap.remove(axis,series); |
|
170 | 170 | //remove axis if no longer there |
|
171 | 171 | if(!m_seriesMap.contains(axis)){ |
|
172 | 172 | emit axisRemoved(axis); |
|
173 | 173 | m_domainMap.remove(axis); |
|
174 | 174 | if(axis != m_axisY) |
|
175 | 175 | delete axis; |
|
176 | 176 | } |
|
177 | 177 | series->setParent(0); |
|
178 | 178 | break; |
|
179 | 179 | } |
|
180 | 180 | } |
|
181 | 181 | } |
|
182 | 182 | |
|
183 | 183 | void ChartDataSet::removeAllSeries() |
|
184 | 184 | { |
|
185 | 185 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
186 | 186 | foreach(QChartAxis* axis , keys) { |
|
187 | 187 | QList<QChartSeries*> seriesList = m_seriesMap.values(axis); |
|
188 | 188 | for(int i =0 ; i < seriesList.size();i++ ) |
|
189 | 189 | { |
|
190 | 190 | emit seriesRemoved(seriesList.at(i)); |
|
191 | 191 | delete(seriesList.at(i)); |
|
192 | 192 | } |
|
193 | 193 | m_seriesMap.remove(axis); |
|
194 | 194 | m_domainMap.remove(axis); |
|
195 | 195 | emit axisRemoved(axis); |
|
196 | 196 | if(axis != m_axisY) delete axis; |
|
197 | 197 | } |
|
198 | 198 | m_domainIndex=0; |
|
199 | 199 | } |
|
200 | 200 | |
|
201 | 201 | bool ChartDataSet::nextDomain() |
|
202 | 202 | { |
|
203 | 203 | int limit = (m_domainMap.values().size()/m_domainMap.uniqueKeys().size())-1; |
|
204 | 204 | |
|
205 | 205 | if (m_domainIndex < limit) { |
|
206 | 206 | m_domainIndex++; |
|
207 | 207 | setDomain(m_domainIndex); |
|
208 | 208 | return true; |
|
209 | 209 | } |
|
210 | 210 | else { |
|
211 | 211 | return false; |
|
212 | 212 | } |
|
213 | 213 | } |
|
214 | 214 | |
|
215 | 215 | bool ChartDataSet::previousDomain() |
|
216 | 216 | { |
|
217 | 217 | if (m_domainIndex > 0) { |
|
218 | 218 | m_domainIndex--; |
|
219 | 219 | setDomain(m_domainIndex); |
|
220 | 220 | return true; |
|
221 | 221 | } |
|
222 | 222 | else { |
|
223 | 223 | return false; |
|
224 | 224 | } |
|
225 | 225 | } |
|
226 | 226 | |
|
227 | 227 | void ChartDataSet::setDomain(int index) |
|
228 | 228 | { |
|
229 | 229 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); |
|
230 | 230 | |
|
231 | 231 | Domain domain; |
|
232 | 232 | |
|
233 | 233 | foreach (QChartAxis* axis , domainList) { |
|
234 | 234 | int i = m_domainMap.count(axis) - index -1; |
|
235 | 235 | Q_ASSERT(i>=0); |
|
236 | 236 | domain = m_domainMap.values(axis).at(i); |
|
237 | 237 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
238 | 238 | QList<QChartSeries*> seriesList = m_seriesMap.values(axis); |
|
239 | 239 | foreach(QChartSeries* series, seriesList) { |
|
240 | 240 | emit seriesDomainChanged(series,domain); |
|
241 | 241 | } |
|
242 | 242 | emit axisLabelsChanged(axis,labels); |
|
243 | 243 | } |
|
244 | 244 | |
|
245 | 245 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); |
|
246 | 246 | emit axisLabelsChanged(axisX(),labels); |
|
247 | 247 | } |
|
248 | 248 | |
|
249 | 249 | void ChartDataSet::clearDomains(int toIndex) |
|
250 | 250 | { |
|
251 | 251 | Q_ASSERT(toIndex>=0); |
|
252 | 252 | |
|
253 | 253 | m_domainIndex = toIndex; |
|
254 | 254 | |
|
255 | 255 | QList<QChartAxis*> keys = m_domainMap.uniqueKeys(); |
|
256 | 256 | |
|
257 | 257 | foreach (QChartAxis* key , keys) |
|
258 | 258 | { |
|
259 | 259 | QList<Domain> domains = m_domainMap.values(key); |
|
260 | 260 | m_domainMap.remove(key); |
|
261 | 261 | int i = domains.size() - toIndex - 1; |
|
262 | 262 | while(i--){ |
|
263 | 263 | domains.removeFirst(); |
|
264 | 264 | } |
|
265 | 265 | for(int j=domains.size()-1; j>=0 ;j--) |
|
266 | 266 | m_domainMap.insert(key,domains.at(j)); |
|
267 | 267 | } |
|
268 | 268 | } |
|
269 | 269 | |
|
270 | 270 | void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport) |
|
271 | 271 | { |
|
272 | 272 | Q_ASSERT(rect.isValid()); |
|
273 | 273 | Q_ASSERT(viewport.isValid()); |
|
274 | 274 | |
|
275 | 275 | clearDomains(m_domainIndex); |
|
276 | 276 | |
|
277 | 277 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); |
|
278 | 278 | |
|
279 | 279 | Domain domain; |
|
280 | 280 | |
|
281 | 281 | foreach (QChartAxis* axis , domainList){ |
|
282 | 282 | domain = m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height()); |
|
283 | 283 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
284 | 284 | QList<QChartSeries*> seriesList = m_seriesMap.values(axis); |
|
285 | 285 | foreach(QChartSeries* series, seriesList){ |
|
286 | 286 | emit seriesDomainChanged(series,domain); |
|
287 | 287 | } |
|
288 | 288 | emit axisLabelsChanged(axis,labels); |
|
289 | 289 | m_domainMap.insert(axis,domain); |
|
290 | 290 | } |
|
291 | 291 | |
|
292 | 292 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); |
|
293 | 293 | emit axisLabelsChanged(axisX(),labels); |
|
294 | 294 | |
|
295 | 295 | m_domainIndex++; |
|
296 | 296 | } |
|
297 | 297 | |
|
298 | 298 | QChartAxis* ChartDataSet::axisY(QChartSeries* series) const |
|
299 | 299 | { |
|
300 | 300 | if(series == 0) return m_axisY; |
|
301 | 301 | |
|
302 | 302 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
303 | 303 | |
|
304 | 304 | foreach(QChartAxis* axis , keys) { |
|
305 | 305 | if(m_seriesMap.contains(axis,series)){ |
|
306 | 306 | return axis; |
|
307 | 307 | } |
|
308 | 308 | } |
|
309 | 309 | return 0; |
|
310 | 310 | } |
|
311 | 311 | |
|
312 | 312 | QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max) |
|
313 | 313 | { |
|
314 | 314 | Q_ASSERT(max>=min); |
|
315 | 315 | |
|
316 | 316 | QStringList labels; |
|
317 | 317 | |
|
318 | 318 | int ticks = axis->ticksCount()-1; |
|
319 | 319 | |
|
320 | 320 | for(int i=0; i<= ticks; i++){ |
|
321 | 321 | qreal value = min + (i * (max - min)/ ticks); |
|
322 | 322 | QString label = axis->axisTickLabel(value); |
|
323 | 323 | if(label.isEmpty()){ |
|
324 | 324 | labels << QString::number(value); |
|
325 | 325 | }else{ |
|
326 | 326 | labels << label; |
|
327 | 327 | } |
|
328 | 328 | } |
|
329 | 329 | return labels; |
|
330 | 330 | } |
|
331 | 331 | |
|
332 | 332 | |
|
333 | 333 | void ChartDataSet::handleMinChanged(qreal min) |
|
334 | 334 | { |
|
335 | 335 | |
|
336 | 336 | } |
|
337 | 337 | |
|
338 | 338 | void ChartDataSet::handleMaxChanged(qreal max) |
|
339 | 339 | { |
|
340 | 340 | |
|
341 | 341 | } |
|
342 | 342 | |
|
343 | 343 | void ChartDataSet::handleTickChanged(QChartAxis* axis) |
|
344 | 344 | { |
|
345 | 345 | Domain domain = m_domainMap.value(axisY()); |
|
346 | 346 | if(axis==axisX()){ |
|
347 | 347 | QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX); |
|
348 | 348 | emit axisLabelsChanged(axis,labels); |
|
349 | 349 | }else{ |
|
350 | 350 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
351 | 351 | emit axisLabelsChanged(axis,labels); |
|
352 | 352 | } |
|
353 | 353 | } |
|
354 | 354 | |
|
355 | 355 | #include "moc_chartdataset_p.cpp" |
|
356 | 356 | |
|
357 | 357 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,283 +1,283 | |||
|
1 | 1 | #include "qchart.h" |
|
2 | 2 | #include "qchartaxis.h" |
|
3 | 3 | #include "chartpresenter_p.h" |
|
4 | 4 | #include "chartdataset_p.h" |
|
5 | 5 | #include "charttheme_p.h" |
|
6 | 6 | //series |
|
7 | 7 | #include "qbarseries.h" |
|
8 | 8 | #include "qstackedbarseries.h" |
|
9 | 9 | #include "qpercentbarseries.h" |
|
10 |
#include "qline |
|
|
10 | #include "qlineseries.h" | |
|
11 | 11 | #include "qpieseries.h" |
|
12 | 12 | #include "qscatterseries.h" |
|
13 | 13 | //items |
|
14 | 14 | #include "axisitem_p.h" |
|
15 | 15 | #include "axisanimationitem_p.h" |
|
16 | 16 | #include "barpresenter.h" |
|
17 | 17 | #include "stackedbarpresenter.h" |
|
18 | 18 | #include "linechartitem_p.h" |
|
19 | 19 | #include "percentbarpresenter.h" |
|
20 | 20 | #include "linechartanimationitem_p.h" |
|
21 | 21 | #include "piepresenter.h" |
|
22 | 22 | #include "scatterpresenter_p.h" |
|
23 | 23 | |
|
24 | 24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | 25 | |
|
26 | 26 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
27 | 27 | m_chart(chart), |
|
28 | 28 | m_dataset(dataset), |
|
29 | 29 | m_chartTheme(0), |
|
30 | 30 | m_marginSize(0), |
|
31 | 31 | m_rect(QRectF(QPoint(0,0),m_chart->size())), |
|
32 | 32 | m_options(0) |
|
33 | 33 | { |
|
34 | 34 | createConnections(); |
|
35 | 35 | setChartTheme(QChart::ChartThemeDefault); |
|
36 | 36 | |
|
37 | 37 | } |
|
38 | 38 | |
|
39 | 39 | ChartPresenter::~ChartPresenter() |
|
40 | 40 | { |
|
41 | 41 | } |
|
42 | 42 | |
|
43 | 43 | void ChartPresenter::createConnections() |
|
44 | 44 | { |
|
45 | 45 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
46 | 46 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); |
|
47 | 47 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QChartSeries*)),this,SLOT(handleSeriesRemoved(QChartSeries*))); |
|
48 | 48 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*)),this,SLOT(handleAxisAdded(QChartAxis*))); |
|
49 | 49 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); |
|
50 | 50 | QObject::connect(m_dataset,SIGNAL(seriesDomainChanged(QChartSeries*,const Domain&)),this,SLOT(handleSeriesDomainChanged(QChartSeries*,const Domain&))); |
|
51 | 51 | QObject::connect(m_dataset,SIGNAL(axisLabelsChanged(QChartAxis*,const QStringList&)),this,SLOT(handleAxisLabelsChanged(QChartAxis*,const QStringList&))); |
|
52 | 52 | } |
|
53 | 53 | |
|
54 | 54 | |
|
55 | 55 | QRectF ChartPresenter::geometry() const |
|
56 | 56 | { |
|
57 | 57 | return m_rect; |
|
58 | 58 | } |
|
59 | 59 | |
|
60 | 60 | void ChartPresenter::handleGeometryChanged() |
|
61 | 61 | { |
|
62 | 62 | m_rect = QRectF(QPoint(0,0),m_chart->size()); |
|
63 | 63 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); |
|
64 | 64 | Q_ASSERT(m_rect.isValid()); |
|
65 | 65 | emit geometryChanged(m_rect); |
|
66 | 66 | } |
|
67 | 67 | |
|
68 | 68 | int ChartPresenter::margin() const |
|
69 | 69 | { |
|
70 | 70 | return m_marginSize; |
|
71 | 71 | } |
|
72 | 72 | |
|
73 | 73 | void ChartPresenter::setMargin(int margin) |
|
74 | 74 | { |
|
75 | 75 | m_marginSize = margin; |
|
76 | 76 | } |
|
77 | 77 | |
|
78 | 78 | void ChartPresenter::handleAxisAdded(QChartAxis* axis) |
|
79 | 79 | { |
|
80 | 80 | |
|
81 | 81 | AxisItem* item ; |
|
82 | 82 | |
|
83 | 83 | if(!m_options.testFlag(QChart::GridAxisAnimations)) |
|
84 | 84 | { |
|
85 | 85 | item = new AxisItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); |
|
86 | 86 | }else{ |
|
87 | 87 | item = new AxisAnimationItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); |
|
88 | 88 | } |
|
89 | 89 | |
|
90 | 90 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
91 | 91 | QObject::connect(axis,SIGNAL(update(QChartAxis*)),item,SLOT(handleAxisUpdate(QChartAxis*))); |
|
92 | 92 | |
|
93 | 93 | item->handleAxisUpdate(axis); |
|
94 | 94 | item->handleGeometryChanged(m_rect); |
|
95 | 95 | m_chartTheme->decorate(axis,item); |
|
96 | 96 | m_axisItems.insert(axis,item); |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | 99 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) |
|
100 | 100 | { |
|
101 | 101 | AxisItem* item = m_axisItems.take(axis); |
|
102 | 102 | Q_ASSERT(item); |
|
103 | 103 | delete item; |
|
104 | 104 | } |
|
105 | 105 | |
|
106 | 106 | |
|
107 | 107 | void ChartPresenter::handleSeriesAdded(QChartSeries* series) |
|
108 | 108 | { |
|
109 | 109 | switch(series->type()) |
|
110 | 110 | { |
|
111 | 111 | case QChartSeries::SeriesTypeLine: { |
|
112 |
QLine |
|
|
112 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); | |
|
113 | 113 | LineChartItem* item; |
|
114 | 114 | if(m_options.testFlag(QChart::SeriesAnimations)){ |
|
115 | 115 | item = new LineChartAnimationItem(this,lineSeries,m_chart); |
|
116 | 116 | }else{ |
|
117 | 117 | item = new LineChartItem(this,lineSeries,m_chart); |
|
118 | 118 | } |
|
119 | 119 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); |
|
120 | 120 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
121 | 121 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
122 | 122 | m_chartItems.insert(series,item); |
|
123 | 123 | break; |
|
124 | 124 | } |
|
125 | 125 | |
|
126 | 126 | case QChartSeries::SeriesTypeBar: { |
|
127 | 127 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
128 | 128 | BarPresenter* item = new BarPresenter(barSeries,m_chart); |
|
129 | 129 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); |
|
130 | 130 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
131 | 131 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
132 | 132 | m_chartItems.insert(series,item); |
|
133 | 133 | // m_axisXItem->setVisible(false); |
|
134 | 134 | break; |
|
135 | 135 | } |
|
136 | 136 | |
|
137 | 137 | case QChartSeries::SeriesTypeStackedBar: { |
|
138 | 138 | |
|
139 | 139 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
140 | 140 | StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart); |
|
141 | 141 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); |
|
142 | 142 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
143 | 143 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
144 | 144 | m_chartItems.insert(series,item); |
|
145 | 145 | break; |
|
146 | 146 | } |
|
147 | 147 | |
|
148 | 148 | case QChartSeries::SeriesTypePercentBar: { |
|
149 | 149 | |
|
150 | 150 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
151 | 151 | PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart); |
|
152 | 152 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); |
|
153 | 153 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
154 | 154 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
155 | 155 | m_chartItems.insert(series,item); |
|
156 | 156 | break; |
|
157 | 157 | } |
|
158 | 158 | case QChartSeries::SeriesTypeScatter: { |
|
159 | 159 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
160 | 160 | ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart); |
|
161 | 161 | QObject::connect(scatterPresenter, SIGNAL(clicked()), scatterSeries, SIGNAL(clicked())); |
|
162 | 162 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), |
|
163 | 163 | scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); |
|
164 | 164 | m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count()); |
|
165 | 165 | m_chartItems.insert(scatterSeries, scatterPresenter); |
|
166 | 166 | break; |
|
167 | 167 | } |
|
168 | 168 | case QChartSeries::SeriesTypePie: { |
|
169 | 169 | QPieSeries *s = qobject_cast<QPieSeries *>(series); |
|
170 | 170 | PiePresenter* pie = new PiePresenter(m_chart, s); |
|
171 | 171 | m_chartTheme->decorate(pie, s, m_chartItems.count()); |
|
172 | 172 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); |
|
173 | 173 | |
|
174 | 174 | // Hide all from background when there is only piechart |
|
175 | 175 | // TODO: refactor this ugly code... should be one setting for this |
|
176 | 176 | if (m_chartItems.count() == 0) { |
|
177 | 177 | m_chart->axisX()->setAxisVisible(false); |
|
178 | 178 | m_chart->axisY()->setAxisVisible(false); |
|
179 | 179 | m_chart->axisX()->setGridVisible(false); |
|
180 | 180 | m_chart->axisY()->setGridVisible(false); |
|
181 | 181 | m_chart->axisX()->setLabelsVisible(false); |
|
182 | 182 | m_chart->axisY()->setLabelsVisible(false); |
|
183 | 183 | m_chart->axisX()->setShadesVisible(false); |
|
184 | 184 | m_chart->axisY()->setShadesVisible(false); |
|
185 | 185 | m_chart->setChartBackgroundBrush(Qt::transparent); |
|
186 | 186 | } |
|
187 | 187 | |
|
188 | 188 | m_chartItems.insert(series, pie); |
|
189 | 189 | break; |
|
190 | 190 | } |
|
191 | 191 | default: { |
|
192 | 192 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
193 | 193 | break; |
|
194 | 194 | } |
|
195 | 195 | } |
|
196 | 196 | |
|
197 | 197 | if(m_rect.isValid()) emit geometryChanged(m_rect); |
|
198 | 198 | } |
|
199 | 199 | |
|
200 | 200 | void ChartPresenter::handleSeriesRemoved(QChartSeries* series) |
|
201 | 201 | { |
|
202 | 202 | ChartItem* item = m_chartItems.take(series); |
|
203 | 203 | delete item; |
|
204 | 204 | } |
|
205 | 205 | |
|
206 | 206 | void ChartPresenter::handleSeriesChanged(QChartSeries* series) |
|
207 | 207 | { |
|
208 | 208 | //TODO: |
|
209 | 209 | } |
|
210 | 210 | |
|
211 | 211 | void ChartPresenter::handleSeriesDomainChanged(QChartSeries* series, const Domain& domain) |
|
212 | 212 | { |
|
213 | 213 | m_chartItems.value(series)->handleDomainChanged(domain); |
|
214 | 214 | } |
|
215 | 215 | |
|
216 | 216 | void ChartPresenter::handleAxisLabelsChanged(QChartAxis* axis,const QStringList& labels) |
|
217 | 217 | { |
|
218 | 218 | m_axisItems.value(axis)->handleLabelsChanged(axis,labels); |
|
219 | 219 | } |
|
220 | 220 | |
|
221 | 221 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) |
|
222 | 222 | { |
|
223 | 223 | delete m_chartTheme; |
|
224 | 224 | |
|
225 | 225 | m_chartTheme = ChartTheme::createTheme(theme); |
|
226 | 226 | |
|
227 | 227 | m_chartTheme->decorate(m_chart); |
|
228 | 228 | QMapIterator<QChartSeries*,ChartItem*> i(m_chartItems); |
|
229 | 229 | |
|
230 | 230 | int index=0; |
|
231 | 231 | while (i.hasNext()) { |
|
232 | 232 | i.next(); |
|
233 | 233 | m_chartTheme->decorate(i.value(),i.key(),index); |
|
234 | 234 | index++; |
|
235 | 235 | } |
|
236 | 236 | |
|
237 | 237 | QMapIterator<QChartAxis*,AxisItem*> j(m_axisItems); |
|
238 | 238 | while (j.hasNext()) { |
|
239 | 239 | j.next(); |
|
240 | 240 | m_chartTheme->decorate(j.key(),j.value()); |
|
241 | 241 | } |
|
242 | 242 | } |
|
243 | 243 | |
|
244 | 244 | QChart::ChartTheme ChartPresenter::chartTheme() |
|
245 | 245 | { |
|
246 | 246 | return m_chartTheme->id(); |
|
247 | 247 | } |
|
248 | 248 | |
|
249 | 249 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
250 | 250 | { |
|
251 | 251 | if(m_options!=options) { |
|
252 | 252 | |
|
253 | 253 | m_options=options; |
|
254 | 254 | |
|
255 | 255 | //recreate elements |
|
256 | 256 | |
|
257 | 257 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); |
|
258 | 258 | QList<QChartSeries*> seriesList = m_chartItems.uniqueKeys(); |
|
259 | 259 | |
|
260 | 260 | foreach(QChartAxis* axis, axisList) { |
|
261 | 261 | handleAxisRemoved(axis); |
|
262 | 262 | handleAxisAdded(axis); |
|
263 | 263 | } |
|
264 | 264 | foreach(QChartSeries* series, seriesList) { |
|
265 | 265 | handleSeriesRemoved(series); |
|
266 | 266 | handleSeriesAdded(series); |
|
267 | 267 | } |
|
268 | 268 | |
|
269 | 269 | //now reintialize view data |
|
270 | 270 | //TODO: make it more nice |
|
271 | 271 | m_dataset->setDomain(m_dataset->domainIndex()); |
|
272 | 272 | } |
|
273 | 273 | } |
|
274 | 274 | |
|
275 | 275 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
|
276 | 276 | { |
|
277 | 277 | return m_options; |
|
278 | 278 | } |
|
279 | 279 | |
|
280 | 280 | |
|
281 | 281 | #include "moc_chartpresenter_p.cpp" |
|
282 | 282 | |
|
283 | 283 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,267 +1,267 | |||
|
1 | 1 | #include "charttheme_p.h" |
|
2 | 2 | #include "qchart.h" |
|
3 | 3 | #include "qchartaxis.h" |
|
4 | 4 | #include <QTime> |
|
5 | 5 | |
|
6 | 6 | //series |
|
7 | 7 | #include "qbarset.h" |
|
8 | 8 | #include "qbarseries.h" |
|
9 | 9 | #include "qstackedbarseries.h" |
|
10 | 10 | #include "qpercentbarseries.h" |
|
11 |
#include "qline |
|
|
11 | #include "qlineseries.h" | |
|
12 | 12 | #include "qscatterseries.h" |
|
13 | 13 | #include "qpieseries.h" |
|
14 | 14 | #include "qpieslice.h" |
|
15 | 15 | |
|
16 | 16 | //items |
|
17 | 17 | #include "axisitem_p.h" |
|
18 | 18 | #include "barpresenter.h" |
|
19 | 19 | #include "stackedbarpresenter.h" |
|
20 | 20 | #include "linechartitem_p.h" |
|
21 | 21 | #include "percentbarpresenter.h" |
|
22 | 22 | #include "scatterpresenter_p.h" |
|
23 | 23 | #include "piepresenter.h" |
|
24 | 24 | |
|
25 | 25 | //themes |
|
26 | 26 | #include "chartthemevanilla_p.h" |
|
27 | 27 | #include "chartthemeicy_p.h" |
|
28 | 28 | #include "chartthemegrayscale_p.h" |
|
29 | 29 | #include "chartthemescientific_p.h" |
|
30 | 30 | |
|
31 | 31 | |
|
32 | 32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | 33 | |
|
34 | 34 | /* TODO |
|
35 | 35 | case QChart::ChartThemeUnnamed1: |
|
36 | 36 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2)); |
|
37 | 37 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2)); |
|
38 | 38 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2)); |
|
39 | 39 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2)); |
|
40 | 40 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2)); |
|
41 | 41 | |
|
42 | 42 | m_gradientStartColor = QColor(QRgb(0xfff3dc9e)); |
|
43 | 43 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
44 | 44 | */ |
|
45 | 45 | |
|
46 | 46 | ChartTheme::ChartTheme(QChart::ChartTheme id) |
|
47 | 47 | { |
|
48 | 48 | m_id = id; |
|
49 | 49 | m_seriesColor.append(QRgb(0xff000000)); |
|
50 | 50 | m_seriesColor.append(QRgb(0xff707070)); |
|
51 | 51 | m_gradientStartColor = QColor(QRgb(0xffffffff)); |
|
52 | 52 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
53 | 53 | |
|
54 | 54 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
55 | 55 | } |
|
56 | 56 | |
|
57 | 57 | |
|
58 | 58 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) |
|
59 | 59 | { |
|
60 | 60 | switch(theme) { |
|
61 | 61 | case QChart::ChartThemeDefault: |
|
62 | 62 | return new ChartThemeIcy(); |
|
63 | 63 | case QChart::ChartThemeVanilla: |
|
64 | 64 | return new ChartThemeVanilla(); |
|
65 | 65 | case QChart::ChartThemeIcy: |
|
66 | 66 | return new ChartThemeIcy(); |
|
67 | 67 | case QChart::ChartThemeGrayscale: |
|
68 | 68 | return new ChartThemeGrayscale(); |
|
69 | 69 | case QChart::ChartThemeScientific: |
|
70 | 70 | return new ChartThemeScientific(); |
|
71 | 71 | } |
|
72 | 72 | } |
|
73 | 73 | |
|
74 | 74 | void ChartTheme::decorate(QChart* chart) |
|
75 | 75 | { |
|
76 | 76 | QLinearGradient backgroundGradient; |
|
77 | 77 | backgroundGradient.setColorAt(0.0, m_gradientStartColor); |
|
78 | 78 | backgroundGradient.setColorAt(1.0, m_gradientEndColor); |
|
79 | 79 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
80 | 80 | chart->setChartBackgroundBrush(backgroundGradient); |
|
81 | 81 | } |
|
82 | 82 | //TODO helper to by removed later |
|
83 | 83 | void ChartTheme::decorate(ChartItem* item, QChartSeries* series,int count) |
|
84 | 84 | { |
|
85 | 85 | switch(series->type()) |
|
86 | 86 | { |
|
87 | 87 | case QChartSeries::SeriesTypeLine: { |
|
88 |
QLine |
|
|
88 | QLineSeries* s = static_cast<QLineSeries*>(series); | |
|
89 | 89 | LineChartItem* i = static_cast<LineChartItem*>(item); |
|
90 | 90 | decorate(i,s,count); |
|
91 | 91 | break; |
|
92 | 92 | } |
|
93 | 93 | case QChartSeries::SeriesTypeBar: { |
|
94 | 94 | QBarSeries* b = static_cast<QBarSeries*>(series); |
|
95 | 95 | BarPresenter* i = static_cast<BarPresenter*>(item); |
|
96 | 96 | decorate(i,b,count); |
|
97 | 97 | break; |
|
98 | 98 | } |
|
99 | 99 | case QChartSeries::SeriesTypeStackedBar: { |
|
100 | 100 | QStackedBarSeries* s = static_cast<QStackedBarSeries*>(series); |
|
101 | 101 | StackedBarPresenter* i = static_cast<StackedBarPresenter*>(item); |
|
102 | 102 | decorate(i,s,count); |
|
103 | 103 | break; |
|
104 | 104 | } |
|
105 | 105 | case QChartSeries::SeriesTypePercentBar: { |
|
106 | 106 | QPercentBarSeries* s = static_cast<QPercentBarSeries*>(series); |
|
107 | 107 | PercentBarPresenter* i = static_cast<PercentBarPresenter*>(item); |
|
108 | 108 | decorate(i,s,count); |
|
109 | 109 | break; |
|
110 | 110 | } |
|
111 | 111 | case QChartSeries::SeriesTypeScatter: { |
|
112 | 112 | QScatterSeries* s = qobject_cast<QScatterSeries*>(series); |
|
113 | 113 | Q_ASSERT(s); |
|
114 | 114 | ScatterPresenter* i = static_cast<ScatterPresenter*>(item); |
|
115 | 115 | Q_ASSERT(i); |
|
116 | 116 | decorate(i, s, count); |
|
117 | 117 | break; |
|
118 | 118 | } |
|
119 | 119 | case QChartSeries::SeriesTypePie: { |
|
120 | 120 | QPieSeries* s = static_cast<QPieSeries*>(series); |
|
121 | 121 | PiePresenter* i = static_cast<PiePresenter*>(item); |
|
122 | 122 | decorate(i,s,count); |
|
123 | 123 | break; |
|
124 | 124 | } |
|
125 | 125 | default: |
|
126 | 126 | qDebug()<<"Wrong item to be decorated by theme"; |
|
127 | 127 | break; |
|
128 | 128 | } |
|
129 | 129 | |
|
130 | 130 | } |
|
131 | 131 | |
|
132 |
void ChartTheme::decorate(LineChartItem* item, QLine |
|
|
132 | void ChartTheme::decorate(LineChartItem* item, QLineSeries* series,int count) | |
|
133 | 133 | { |
|
134 | 134 | QPen pen; |
|
135 | 135 | if(pen != series->pen()){ |
|
136 | 136 | item->setPen(series->pen()); |
|
137 | 137 | return; |
|
138 | 138 | } |
|
139 | 139 | pen.setColor(m_seriesColor.at(count%m_seriesColor.size())); |
|
140 | 140 | pen.setWidthF(2); |
|
141 | 141 | item->setPen(pen); |
|
142 | 142 | } |
|
143 | 143 | |
|
144 | 144 | void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int count) |
|
145 | 145 | { |
|
146 | 146 | for (int i=0; i<series->countSets(); i++) { |
|
147 | 147 | series->nextSet(0==i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); |
|
148 | 148 | } |
|
149 | 149 | } |
|
150 | 150 | |
|
151 | 151 | void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count) |
|
152 | 152 | { |
|
153 | 153 | for (int i=0; i<series->countSets(); i++) { |
|
154 | 154 | series->nextSet(0==i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); |
|
155 | 155 | } |
|
156 | 156 | } |
|
157 | 157 | |
|
158 | 158 | void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count) |
|
159 | 159 | { |
|
160 | 160 | for (int i=0; i<series->countSets(); i++) { |
|
161 | 161 | series->nextSet(0==i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); |
|
162 | 162 | } |
|
163 | 163 | } |
|
164 | 164 | |
|
165 | 165 | void ChartTheme::decorate(ScatterPresenter* presenter, QScatterSeries* series, int count) |
|
166 | 166 | { |
|
167 | 167 | Q_ASSERT(presenter); |
|
168 | 168 | Q_ASSERT(series); |
|
169 | 169 | |
|
170 | 170 | QColor color = m_seriesColor.at(count % m_seriesColor.size()); |
|
171 | 171 | // TODO: define alpha in the theme? or in the series? |
|
172 | 172 | //color.setAlpha(120); |
|
173 | 173 | |
|
174 | 174 | QBrush brush(color, Qt::SolidPattern); |
|
175 | 175 | presenter->m_markerBrush = brush; |
|
176 | 176 | |
|
177 | 177 | QPen pen(brush, 3); |
|
178 | 178 | pen.setColor(color); |
|
179 | 179 | presenter->m_markerPen = pen; |
|
180 | 180 | } |
|
181 | 181 | |
|
182 | 182 | void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/) |
|
183 | 183 | { |
|
184 | 184 | // create a list of slice colors based on current theme |
|
185 | 185 | int i = 0; |
|
186 | 186 | QList<QColor> colors; |
|
187 | 187 | while (colors.count() < series->count()) { |
|
188 | 188 | |
|
189 | 189 | // get base color |
|
190 | 190 | QColor c = m_seriesColor[i++]; |
|
191 | 191 | i = i % m_seriesColor.count(); |
|
192 | 192 | |
|
193 | 193 | // dont use black colors... looks bad |
|
194 | 194 | if (c == Qt::black) |
|
195 | 195 | continue; |
|
196 | 196 | |
|
197 | 197 | // by default use the "raw" theme color |
|
198 | 198 | if (!colors.contains(c)) { |
|
199 | 199 | colors << c; |
|
200 | 200 | continue; |
|
201 | 201 | } |
|
202 | 202 | // ...ok we need to generate something that looks like the same color |
|
203 | 203 | // but different lightness |
|
204 | 204 | |
|
205 | 205 | int tryCount = 0; |
|
206 | 206 | while (tryCount++ < 100) { |
|
207 | 207 | |
|
208 | 208 | // find maximum value we can raise the lightness |
|
209 | 209 | int lMax = 255; |
|
210 | 210 | if (lMax > 255 - c.red()) |
|
211 | 211 | lMax = 255 - c.red(); |
|
212 | 212 | if (lMax > 255 - c.green()) |
|
213 | 213 | lMax = 255 - c.green(); |
|
214 | 214 | if (lMax > 255 - c.blue()) |
|
215 | 215 | lMax = 255 - c.blue(); |
|
216 | 216 | |
|
217 | 217 | // find maximum value we can make it darker |
|
218 | 218 | int dMax = 255; |
|
219 | 219 | if (dMax > c.red()) |
|
220 | 220 | dMax = c.red(); |
|
221 | 221 | if (dMax > c.green()) |
|
222 | 222 | dMax = c.green(); |
|
223 | 223 | if (dMax > c.blue()) |
|
224 | 224 | dMax = c.blue(); |
|
225 | 225 | |
|
226 | 226 | int max = dMax + lMax; |
|
227 | 227 | if (max == 0) { |
|
228 | 228 | // no room to make color lighter or darker... |
|
229 | 229 | qDebug() << "cannot generate a color for pie!"; |
|
230 | 230 | break; |
|
231 | 231 | } |
|
232 | 232 | |
|
233 | 233 | // generate random color |
|
234 | 234 | int r = c.red() - dMax; |
|
235 | 235 | int g = c.green() - dMax; |
|
236 | 236 | int b = c.blue() - dMax; |
|
237 | 237 | int d = qrand() % max; |
|
238 | 238 | c.setRgb(r+d, g+d, b+d); |
|
239 | 239 | |
|
240 | 240 | // found a unique color? |
|
241 | 241 | if (!colors.contains(c)) |
|
242 | 242 | break; |
|
243 | 243 | } |
|
244 | 244 | |
|
245 | 245 | qDebug() << "generated a color for pie" << c; |
|
246 | 246 | colors << c; |
|
247 | 247 | } |
|
248 | 248 | |
|
249 | 249 | // finally update colors |
|
250 | 250 | foreach (QPieSlice* s, series->slices()) { |
|
251 | 251 | QColor c = colors.takeFirst(); |
|
252 | 252 | s->setPen(c); |
|
253 | 253 | s->setBrush(c); |
|
254 | 254 | } |
|
255 | 255 | } |
|
256 | 256 | |
|
257 | 257 | |
|
258 | 258 | void ChartTheme::decorate(QChartAxis* axis,AxisItem* item) |
|
259 | 259 | { |
|
260 | 260 | //TODO: dummy defults for now |
|
261 | 261 | axis->setLabelsBrush(Qt::black); |
|
262 | 262 | axis->setLabelsPen(Qt::NoPen); |
|
263 | 263 | axis->setShadesPen(Qt::NoPen); |
|
264 | 264 | axis->setShadesOpacity(0.5); |
|
265 | 265 | } |
|
266 | 266 | |
|
267 | 267 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,52 +1,52 | |||
|
1 | 1 | #ifndef CHARTTHEME_H |
|
2 | 2 | #define CHARTTHEME_H |
|
3 | 3 | |
|
4 | 4 | #include "qchartglobal.h" |
|
5 | 5 | #include "qchart.h" |
|
6 | 6 | #include <QColor> |
|
7 | 7 | |
|
8 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 9 | |
|
10 | 10 | class ChartItem; |
|
11 | 11 | class QChartSeries; |
|
12 | 12 | class LineChartItem; |
|
13 |
class QLine |
|
|
13 | class QLineSeries; | |
|
14 | 14 | class BarPresenter; |
|
15 | 15 | class QBarSeries; |
|
16 | 16 | class StackedBarPresenter; |
|
17 | 17 | class QStackedBarSeries; |
|
18 | 18 | class QPercentBarSeries; |
|
19 | 19 | class PercentBarPresenter; |
|
20 | 20 | class QScatterSeries; |
|
21 | 21 | class ScatterPresenter; |
|
22 | 22 | class PiePresenter; |
|
23 | 23 | class QPieSeries; |
|
24 | 24 | |
|
25 | 25 | class ChartTheme |
|
26 | 26 | { |
|
27 | 27 | protected: |
|
28 | 28 | explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeDefault); |
|
29 | 29 | public: |
|
30 | 30 | static ChartTheme* createTheme(QChart::ChartTheme theme); |
|
31 | 31 | QChart::ChartTheme id() const {return m_id;} |
|
32 | 32 | void decorate(QChart* chart); |
|
33 | 33 | void decorate(ChartItem* item, QChartSeries* series,int count); |
|
34 | void decorate(LineChartItem* item, QLineChartSeries*, int count); | |
|
35 | 34 | void decorate(BarPresenter* item, QBarSeries* series,int count); |
|
36 | 35 | void decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count); |
|
37 | 36 | void decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count); |
|
37 | void decorate(LineChartItem* item, QLineSeries*, int count); | |
|
38 | 38 | void decorate(ScatterPresenter* presenter, QScatterSeries* series, int count); |
|
39 | 39 | void decorate(PiePresenter* item, QPieSeries* series, int count); |
|
40 | 40 | void decorate(QChartAxis* axis,AxisItem* item); |
|
41 | 41 | |
|
42 | 42 | protected: |
|
43 | 43 | QChart::ChartTheme m_id; |
|
44 | 44 | QColor m_gradientStartColor; |
|
45 | 45 | QColor m_gradientEndColor; |
|
46 | 46 | QList<QColor> m_seriesColor; |
|
47 | 47 | |
|
48 | 48 | }; |
|
49 | 49 | |
|
50 | 50 | QTCOMMERCIALCHART_END_NAMESPACE |
|
51 | 51 | |
|
52 | 52 | #endif // CHARTTHEME_H |
@@ -1,14 +1,14 | |||
|
1 | 1 | INCLUDEPATH += $$PWD |
|
2 | 2 | DEPENDPATH += $$PWD |
|
3 | 3 | |
|
4 | 4 | SOURCES += \ |
|
5 | 5 | $$PWD/linechartanimationitem.cpp \ |
|
6 | 6 | $$PWD/linechartitem.cpp \ |
|
7 |
$$PWD/qline |
|
|
7 | $$PWD/qlineseries.cpp | |
|
8 | 8 | |
|
9 | 9 | PRIVATE_HEADERS += \ |
|
10 | 10 | $$PWD/linechartitem_p.h \ |
|
11 | 11 | $$PWD/linechartanimationitem_p.h |
|
12 | 12 | |
|
13 | 13 | PUBLIC_HEADERS += \ |
|
14 |
$$PWD/qline |
|
|
14 | $$PWD/qlineseries.h No newline at end of file |
@@ -1,63 +1,63 | |||
|
1 | 1 | #include "linechartanimationitem_p.h" |
|
2 | 2 | #include "linechartitem_p.h" |
|
3 | 3 | #include <QPropertyAnimation> |
|
4 | 4 | |
|
5 | 5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | 6 | |
|
7 | 7 | const static int duration = 500; |
|
8 | 8 | |
|
9 | 9 | |
|
10 |
LineChartAnimationItem::LineChartAnimationItem(ChartPresenter* presenter, QLine |
|
|
10 | LineChartAnimationItem::LineChartAnimationItem(ChartPresenter* presenter, QLineSeries* series,QGraphicsItem *parent): | |
|
11 | 11 | LineChartItem(presenter,series,parent) |
|
12 | 12 | { |
|
13 | 13 | |
|
14 | 14 | } |
|
15 | 15 | |
|
16 | 16 | LineChartAnimationItem::~LineChartAnimationItem() |
|
17 | 17 | { |
|
18 | 18 | } |
|
19 | 19 | |
|
20 | 20 | void LineChartAnimationItem::addPoints(const QVector<QPointF>& points) |
|
21 | 21 | { |
|
22 | 22 | m_data=points; |
|
23 | 23 | clearView(); |
|
24 | 24 | QPropertyAnimation *animation = new QPropertyAnimation(this, "a_addPoints", parent()); |
|
25 | 25 | animation->setDuration(duration); |
|
26 | 26 | //animation->setEasingCurve(QEasingCurve::InOutBack); |
|
27 | 27 | animation->setKeyValueAt(0.0, 0); |
|
28 | 28 | animation->setKeyValueAt(1.0, m_data.size()); |
|
29 | 29 | animation->start(QAbstractAnimation::DeleteWhenStopped); |
|
30 | 30 | } |
|
31 | 31 | |
|
32 | 32 | void LineChartAnimationItem::setPoint(int index,const QPointF& point) |
|
33 | 33 | { |
|
34 | 34 | AnimationHelper* helper = new AnimationHelper(this,index); |
|
35 | 35 | QPropertyAnimation *animation = new QPropertyAnimation(helper, "point", parent()); |
|
36 | 36 | animation->setDuration(duration); |
|
37 | 37 | //animation->setEasingCurve(QEasingCurve::InOutBack); |
|
38 | 38 | animation->setKeyValueAt(0.0, points().value(index)); |
|
39 | 39 | animation->setKeyValueAt(1.0, point); |
|
40 | 40 | animation->start(QAbstractAnimation::DeleteWhenStopped); |
|
41 | 41 | } |
|
42 | 42 | |
|
43 | 43 | void LineChartAnimationItem::aw_addPoints(int points) |
|
44 | 44 | { |
|
45 | 45 | int index = count(); |
|
46 | 46 | for(int i = index;i< points ;i++){ |
|
47 | 47 | LineChartItem::addPoint(m_data.at(i)); |
|
48 | 48 | } |
|
49 | 49 | updateGeometry(); |
|
50 | 50 | update(); |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | void LineChartAnimationItem::aw_setPoint(int index,const QPointF& point) |
|
54 | 54 | { |
|
55 | 55 | LineChartItem::setPoint(index,point); |
|
56 | 56 | updateGeometry(); |
|
57 | 57 | update(); |
|
58 | 58 | } |
|
59 | 59 | |
|
60 | 60 | |
|
61 | 61 | #include "moc_linechartanimationitem_p.cpp" |
|
62 | 62 | |
|
63 | 63 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,55 +1,55 | |||
|
1 | 1 | #ifndef LINECHARTANIMATIONITEM_P_H_ |
|
2 | 2 | #define LINECHARTANIMATIONITEM_P_H_ |
|
3 | 3 | |
|
4 | 4 | #include "qchartglobal.h" |
|
5 | 5 | #include "linechartitem_p.h" |
|
6 | 6 | #include "domain_p.h" |
|
7 | 7 | |
|
8 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 9 | |
|
10 | 10 | class LineChartItem; |
|
11 | 11 | |
|
12 | 12 | class LineChartAnimationItem : public LineChartItem { |
|
13 | 13 | Q_OBJECT |
|
14 | 14 | Q_PROPERTY(int a_addPoints READ ar_addPoints WRITE aw_addPoints); |
|
15 | 15 | // Q_PROPERTY(QPointF a_setPoint READ ar_setPoint WRITE aw_setPoint); |
|
16 | 16 | public: |
|
17 |
LineChartAnimationItem(ChartPresenter* presenter, QLine |
|
|
17 | LineChartAnimationItem(ChartPresenter* presenter, QLineSeries *series, QGraphicsItem *parent = 0); | |
|
18 | 18 | virtual ~LineChartAnimationItem(); |
|
19 | 19 | |
|
20 | 20 | void addPoints(const QVector<QPointF>& points); |
|
21 | 21 | void setPoint(int index,const QPointF& point); |
|
22 | 22 | //void removePoint(const QPointF& point){}; |
|
23 | 23 | //void setPoint(const QPointF& oldPoint, const QPointF& newPoint){}; |
|
24 | 24 | |
|
25 | 25 | int ar_addPoints() const { return m_addPoints;} |
|
26 | 26 | void aw_addPoints(int points); |
|
27 | 27 | const QPointF& ar_setPoint() const { return m_setPoint;} |
|
28 | 28 | void aw_setPoint(int index,const QPointF& point); |
|
29 | 29 | |
|
30 | 30 | private: |
|
31 | 31 | QVector<QPointF> m_data; |
|
32 | 32 | Domain m_domain; |
|
33 | 33 | int m_addPoints; |
|
34 | 34 | QPointF m_setPoint; |
|
35 | 35 | int m_setPoint_index; |
|
36 | 36 | }; |
|
37 | 37 | |
|
38 | 38 | class AnimationHelper: public QObject |
|
39 | 39 | { |
|
40 | 40 | Q_OBJECT |
|
41 | 41 | Q_PROPERTY(QPointF point READ point WRITE setPoint); |
|
42 | 42 | public: |
|
43 | 43 | AnimationHelper(LineChartAnimationItem* item,int index):m_item(item),m_index(index){}; |
|
44 | 44 | void setPoint(const QPointF& point){ |
|
45 | 45 | m_item->aw_setPoint(m_index,point); |
|
46 | 46 | } |
|
47 | 47 | QPointF point(){return m_point;} |
|
48 | 48 | QPointF m_point; |
|
49 | 49 | LineChartAnimationItem* m_item; |
|
50 | 50 | int m_index; |
|
51 | 51 | }; |
|
52 | 52 | |
|
53 | 53 | QTCOMMERCIALCHART_END_NAMESPACE |
|
54 | 54 | |
|
55 | 55 | #endif |
@@ -1,210 +1,210 | |||
|
1 | 1 | #include "linechartitem_p.h" |
|
2 |
#include "qline |
|
|
2 | #include "qlineseries.h" | |
|
3 | 3 | #include "chartpresenter_p.h" |
|
4 | 4 | #include <QPainter> |
|
5 | 5 | |
|
6 | 6 | |
|
7 | 7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | 8 | |
|
9 | 9 | //TODO: optimazie : remove points which are not visible |
|
10 | 10 | |
|
11 |
LineChartItem::LineChartItem(ChartPresenter* presenter, QLine |
|
|
11 | LineChartItem::LineChartItem(ChartPresenter* presenter, QLineSeries* series,QGraphicsItem *parent):ChartItem(parent), | |
|
12 | 12 | m_presenter(presenter), |
|
13 | 13 | m_series(series), |
|
14 | 14 | m_dirtyData(false), |
|
15 | 15 | m_dirtyGeometry(false), |
|
16 | 16 | m_dirtyDomain(false) |
|
17 | 17 | { |
|
18 | 18 | setZValue(ChartPresenter::LineChartZValue); |
|
19 | 19 | } |
|
20 | 20 | |
|
21 | 21 | QRectF LineChartItem::boundingRect() const |
|
22 | 22 | { |
|
23 | 23 | return m_rect; |
|
24 | 24 | } |
|
25 | 25 | |
|
26 | 26 | QPainterPath LineChartItem::shape() const |
|
27 | 27 | { |
|
28 | 28 | return m_path; |
|
29 | 29 | } |
|
30 | 30 | |
|
31 | 31 | |
|
32 | 32 | void LineChartItem::addPoints(const QVector<QPointF>& points) |
|
33 | 33 | { |
|
34 | 34 | m_data = points; |
|
35 | 35 | for(int i=0; i<m_data.size();i++){ |
|
36 | 36 | const QPointF& point =m_data[i]; |
|
37 | 37 | QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3,this); |
|
38 | 38 | item->setPos(point.x()-1,point.y()-1);; |
|
39 | 39 | if(!m_clipRect.contains(point) || !m_series->isPointsVisible()) item->setVisible(false); |
|
40 | 40 | m_points << item; |
|
41 | 41 | } |
|
42 | 42 | } |
|
43 | 43 | |
|
44 | 44 | void LineChartItem::addPoint(const QPointF& point) |
|
45 | 45 | { |
|
46 | 46 | m_data << point; |
|
47 | 47 | QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3,this); |
|
48 | 48 | m_clipRect.contains(point); |
|
49 | 49 | item->setPos(point.x()-1,point.y()-1); |
|
50 | 50 | if(!m_clipRect.contains(point) || !m_series->isPointsVisible()) item->setVisible(false); |
|
51 | 51 | m_points << item; |
|
52 | 52 | } |
|
53 | 53 | |
|
54 | 54 | void LineChartItem::removePoint(const QPointF& point) |
|
55 | 55 | { |
|
56 | 56 | Q_ASSERT(m_data.count() == m_points.count()); |
|
57 | 57 | int index = m_data.lastIndexOf(point,0); |
|
58 | 58 | m_data.remove(index); |
|
59 | 59 | delete(m_points.takeAt(index)); |
|
60 | 60 | } |
|
61 | 61 | |
|
62 | 62 | void LineChartItem::setPoint(const QPointF& oldPoint,const QPointF& newPoint) |
|
63 | 63 | { |
|
64 | 64 | Q_ASSERT(m_data.count() == m_points.count()); |
|
65 | 65 | int index = m_data.lastIndexOf(oldPoint,0); |
|
66 | 66 | |
|
67 | 67 | if(index > -1){ |
|
68 | 68 | m_data.replace(index,newPoint); |
|
69 | 69 | QGraphicsItem* item = m_points.at(index); |
|
70 | 70 | item->setPos(newPoint.x()-1,newPoint.y()-1); |
|
71 | 71 | } |
|
72 | 72 | } |
|
73 | 73 | |
|
74 | 74 | void LineChartItem::setPoint(int index,const QPointF& point) |
|
75 | 75 | { |
|
76 | 76 | Q_ASSERT(m_data.count() == m_points.count()); |
|
77 | 77 | Q_ASSERT(index>=0); |
|
78 | 78 | |
|
79 | 79 | m_data.replace(index,point); |
|
80 | 80 | QGraphicsItem* item = m_points.at(index); |
|
81 | 81 | item->setPos(point.x()-1,point.y()-1); |
|
82 | 82 | } |
|
83 | 83 | |
|
84 | 84 | void LineChartItem::clear() |
|
85 | 85 | { |
|
86 | 86 | qDeleteAll(m_points); |
|
87 | 87 | m_points.clear(); |
|
88 | 88 | m_hash.clear(); |
|
89 | 89 | m_path = QPainterPath(); |
|
90 | 90 | m_rect = QRect(); |
|
91 | 91 | m_data.clear(); |
|
92 | 92 | } |
|
93 | 93 | |
|
94 | 94 | void LineChartItem::clearView() |
|
95 | 95 | { |
|
96 | 96 | qDeleteAll(m_points); |
|
97 | 97 | m_points.clear(); |
|
98 | 98 | m_path = QPainterPath(); |
|
99 | 99 | m_rect = QRect(); |
|
100 | 100 | m_data.clear(); |
|
101 | 101 | } |
|
102 | 102 | |
|
103 | 103 | void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
104 | 104 | { |
|
105 | 105 | Q_UNUSED(widget); |
|
106 | 106 | Q_UNUSED(option); |
|
107 | 107 | painter->save(); |
|
108 | 108 | painter->setPen(m_pen); |
|
109 | 109 | painter->setClipRect(m_clipRect); |
|
110 | 110 | painter->drawPath(m_path); |
|
111 | 111 | painter->restore(); |
|
112 | 112 | } |
|
113 | 113 | |
|
114 |
void LineChartItem::calculatePoint(QPointF& point, int index, const QLine |
|
|
114 | void LineChartItem::calculatePoint(QPointF& point, int index, const QLineSeries* series,const QSizeF& size, const Domain& domain) const | |
|
115 | 115 | { |
|
116 | 116 | const qreal deltaX = size.width()/domain.spanX(); |
|
117 | 117 | const qreal deltaY = size.height()/domain.spanY(); |
|
118 | 118 | qreal x = (series->x(index) - domain.m_minX)* deltaX; |
|
119 | 119 | qreal y = (series->y(index) - domain.m_minY)*-deltaY + size.height(); |
|
120 | 120 | point.setX(x); |
|
121 | 121 | point.setY(y); |
|
122 | 122 | } |
|
123 | 123 | |
|
124 | 124 | |
|
125 |
void LineChartItem::calculatePoints(QVector<QPointF>& points, QHash<int,int>& hash,const QLine |
|
|
125 | void LineChartItem::calculatePoints(QVector<QPointF>& points, QHash<int,int>& hash,const QLineSeries* series,const QSizeF& size, const Domain& domain) const | |
|
126 | 126 | { |
|
127 | 127 | const qreal deltaX = size.width()/domain.spanX(); |
|
128 | 128 | const qreal deltaY = size.height()/domain.spanY(); |
|
129 | 129 | |
|
130 | 130 | for (int i = 0; i < series->count(); ++i) { |
|
131 | 131 | qreal x = (series->x(i) - domain.m_minX)* deltaX; |
|
132 | 132 | qreal y = (series->y(i) - domain.m_minY)*-deltaY + size.height(); |
|
133 | 133 | hash[i] = points.size(); |
|
134 | 134 | points << QPointF(x,y); |
|
135 | 135 | } |
|
136 | 136 | } |
|
137 | 137 | |
|
138 | 138 | void LineChartItem::updateDomain() |
|
139 | 139 | { |
|
140 | 140 | clear(); |
|
141 | 141 | prepareGeometryChange(); |
|
142 | 142 | calculatePoints(m_data,m_hash,m_series,m_size, m_domain); |
|
143 | 143 | addPoints(m_data); |
|
144 | 144 | } |
|
145 | 145 | |
|
146 | 146 | void LineChartItem::updateData() |
|
147 | 147 | { |
|
148 | 148 | //for now the same |
|
149 | 149 | updateDomain(); |
|
150 | 150 | } |
|
151 | 151 | |
|
152 | 152 | void LineChartItem::updateGeometry() |
|
153 | 153 | { |
|
154 | 154 | |
|
155 | 155 | if(m_data.size()==0) return; |
|
156 | 156 | |
|
157 | 157 | prepareGeometryChange(); |
|
158 | 158 | QPainterPath path; |
|
159 | 159 | const QPointF& point = m_data.at(0); |
|
160 | 160 | path.moveTo(point); |
|
161 | 161 | |
|
162 | 162 | foreach( const QPointF& point , m_data) { |
|
163 | 163 | path.lineTo(point); |
|
164 | 164 | } |
|
165 | 165 | |
|
166 | 166 | m_path = path; |
|
167 | 167 | m_rect = path.boundingRect(); |
|
168 | 168 | } |
|
169 | 169 | |
|
170 | 170 | void LineChartItem::setPen(const QPen& pen) |
|
171 | 171 | { |
|
172 | 172 | m_pen = pen; |
|
173 | 173 | } |
|
174 | 174 | |
|
175 | 175 | //handlers |
|
176 | 176 | |
|
177 | 177 | void LineChartItem::handleModelChanged(int index) |
|
178 | 178 | { |
|
179 | 179 | Q_ASSERT(index<m_series->count()); |
|
180 | 180 | if(m_hash.contains(index)){ |
|
181 | 181 | int i = m_hash.value(index); |
|
182 | 182 | QPointF point; |
|
183 | 183 | calculatePoint(point,index,m_series,m_size,m_domain); |
|
184 | 184 | setPoint(i,point); |
|
185 | 185 | } |
|
186 | 186 | update(); |
|
187 | 187 | } |
|
188 | 188 | |
|
189 | 189 | void LineChartItem::handleDomainChanged(const Domain& domain) |
|
190 | 190 | { |
|
191 | 191 | m_domain = domain; |
|
192 | 192 | updateDomain(); |
|
193 | 193 | update(); |
|
194 | 194 | } |
|
195 | 195 | |
|
196 | 196 | void LineChartItem::handleGeometryChanged(const QRectF& rect) |
|
197 | 197 | { |
|
198 | 198 | Q_ASSERT(rect.isValid()); |
|
199 | 199 | m_size=rect.size(); |
|
200 | 200 | m_clipRect=rect.translated(-rect.topLeft()); |
|
201 | 201 | updateDomain(); |
|
202 | 202 | updateGeometry(); |
|
203 | 203 | setPos(rect.topLeft()); |
|
204 | 204 | update(); |
|
205 | 205 | } |
|
206 | 206 | |
|
207 | 207 | |
|
208 | 208 | #include "moc_linechartitem_p.cpp" |
|
209 | 209 | |
|
210 | 210 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,74 +1,74 | |||
|
1 | 1 | #ifndef LINECHARTITEM_H |
|
2 | 2 | #define LINECHARTITEM_H |
|
3 | 3 | |
|
4 | 4 | #include "qchartglobal.h" |
|
5 | 5 | #include "chartitem_p.h" |
|
6 | 6 | #include <QPen> |
|
7 | 7 | |
|
8 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 9 | |
|
10 | 10 | class ChartPresenter; |
|
11 |
class QLine |
|
|
11 | class QLineSeries; | |
|
12 | 12 | class LineChartAnimationItem; |
|
13 | 13 | |
|
14 | 14 | class LineChartItem : public QObject , public ChartItem |
|
15 | 15 | { |
|
16 | 16 | Q_OBJECT |
|
17 | 17 | public: |
|
18 |
LineChartItem(ChartPresenter* presenter, QLine |
|
|
18 | LineChartItem(ChartPresenter* presenter, QLineSeries* series,QGraphicsItem *parent = 0); | |
|
19 | 19 | ~ LineChartItem(){}; |
|
20 | 20 | |
|
21 | 21 | //from QGraphicsItem |
|
22 | 22 | QRectF boundingRect() const; |
|
23 | 23 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
24 | 24 | QPainterPath shape() const; |
|
25 | 25 | |
|
26 | 26 | void setPen(const QPen& pen); |
|
27 | 27 | const Domain& domain() const { return m_domain;} |
|
28 | 28 | |
|
29 | 29 | virtual void addPoint(const QPointF& ); |
|
30 | 30 | virtual void addPoints(const QVector<QPointF>& points); |
|
31 | 31 | virtual void removePoint(const QPointF& point); |
|
32 | 32 | virtual void setPoint(const QPointF& oldPoint, const QPointF& newPoint); |
|
33 | 33 | virtual void setPoint(int index,const QPointF& point); |
|
34 | 34 | void setPointsVisible(bool visible); |
|
35 | 35 | void clear(); |
|
36 | 36 | void clearView(); |
|
37 | 37 | int count() const { return m_data.size();} |
|
38 | 38 | |
|
39 | 39 | const QVector<QPointF>& points(){ return m_data;} |
|
40 | 40 | |
|
41 | 41 | protected: |
|
42 | 42 | virtual void updateGeometry(); |
|
43 | 43 | virtual void updateData(); |
|
44 | 44 | virtual void updateDomain(); |
|
45 | 45 | //refactor |
|
46 |
void calculatePoint(QPointF& point, int index, const QLine |
|
|
47 |
void calculatePoints(QVector<QPointF>& points,QHash<int,int>& hash,const QLine |
|
|
46 | void calculatePoint(QPointF& point, int index, const QLineSeries* series,const QSizeF& size, const Domain& domain) const; | |
|
47 | void calculatePoints(QVector<QPointF>& points,QHash<int,int>& hash,const QLineSeries* series, const QSizeF& size, const Domain& domain) const; | |
|
48 | 48 | |
|
49 | 49 | protected slots: |
|
50 | 50 | void handleModelChanged(int index); |
|
51 | 51 | void handleDomainChanged(const Domain& domain); |
|
52 | 52 | void handleGeometryChanged(const QRectF& size); |
|
53 | 53 | |
|
54 | 54 | private: |
|
55 | 55 | ChartPresenter* m_presenter; |
|
56 | 56 | QPainterPath m_path; |
|
57 | 57 | QSizeF m_size; |
|
58 | 58 | QRectF m_rect; |
|
59 | 59 | QRectF m_clipRect; |
|
60 | 60 | Domain m_domain; |
|
61 | 61 | QList<QGraphicsItem*> m_points; |
|
62 | 62 | QVector<QPointF> m_data; |
|
63 | 63 | QHash<int,int> m_hash; |
|
64 |
QLine |
|
|
64 | QLineSeries* m_series; | |
|
65 | 65 | QPen m_pen; |
|
66 | 66 | bool m_dirtyData; |
|
67 | 67 | bool m_dirtyGeometry; |
|
68 | 68 | bool m_dirtyDomain; |
|
69 | 69 | |
|
70 | 70 | }; |
|
71 | 71 | |
|
72 | 72 | QTCOMMERCIALCHART_END_NAMESPACE |
|
73 | 73 | |
|
74 | 74 | #endif |
@@ -1,195 +1,195 | |||
|
1 |
#include "qline |
|
|
1 | #include "qlineseries.h" | |
|
2 | 2 | |
|
3 | 3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
4 | 4 | |
|
5 | 5 | /*! |
|
6 | 6 | \class QLineChartSeries |
|
7 | 7 | \brief The QLineChartSeries class is used for making line charts. |
|
8 | 8 | |
|
9 | 9 | \mainclass |
|
10 | 10 | |
|
11 | 11 | A line chart is used to show information as a series of data points |
|
12 | 12 | connected by straight lines. |
|
13 | 13 | |
|
14 | 14 | \image linechart.png |
|
15 | 15 | |
|
16 | 16 | To create line charts, users need to first QLineChartSeries object. |
|
17 | 17 | |
|
18 | 18 | \snippet ../example/linechart/main.cpp 1 |
|
19 | 19 | |
|
20 | 20 | Populate with the data |
|
21 | 21 | |
|
22 | 22 | \snippet ../example/linechart/main.cpp 2 |
|
23 | 23 | |
|
24 | 24 | Add created series objects to QChartView or QChart instance. |
|
25 | 25 | |
|
26 | 26 | \snippet ../example/linechart/main.cpp 3 |
|
27 | 27 | |
|
28 | 28 | */ |
|
29 | 29 | |
|
30 | 30 | /*! |
|
31 | 31 | \fn virtual QChartSeriesType QLineChartSeries::type() const |
|
32 | 32 | \brief Returns type of series. |
|
33 | 33 | \sa QChartSeries, QChartSeriesType |
|
34 | 34 | */ |
|
35 | 35 | |
|
36 | 36 | /*! |
|
37 | 37 | \fn QPen QLineChartSeries::pen() const |
|
38 | 38 | \brief Returns the pen used to draw line for this series. |
|
39 | 39 | \sa setPen() |
|
40 | 40 | */ |
|
41 | 41 | |
|
42 | 42 | /*! |
|
43 | 43 | \fn bool QLineChartSeries::isPointsVisible() const |
|
44 | 44 | \brief Returns if the points are drawn for this series. |
|
45 | 45 | \sa setPointsVisible() |
|
46 | 46 | */ |
|
47 | 47 | |
|
48 | 48 | |
|
49 | 49 | /*! |
|
50 | 50 | \fn void QLineChartSeries::changed(int index) |
|
51 | 51 | \brief \internal \a index |
|
52 | 52 | */ |
|
53 | 53 | |
|
54 | 54 | /*! |
|
55 | 55 | Constructs empty series object which is a child of \a parent. |
|
56 | 56 | When series object is added to QChartView or QChart instance ownerships is transfered. |
|
57 | 57 | */ |
|
58 |
QLine |
|
|
58 | QLineSeries::QLineSeries(QObject* parent):QChartSeries(parent), | |
|
59 | 59 | m_pointsVisible(false) |
|
60 | 60 | { |
|
61 | 61 | } |
|
62 | 62 | /*! |
|
63 | 63 | Destroys the object. Series added to QChartView or QChart instances are owned by those, |
|
64 | 64 | and are deleted when mentioned object are destroyed. |
|
65 | 65 | */ |
|
66 |
QLine |
|
|
66 | QLineSeries::~QLineSeries() | |
|
67 | 67 | { |
|
68 | 68 | } |
|
69 | 69 | |
|
70 | 70 | /*! |
|
71 | 71 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. |
|
72 | 72 | */ |
|
73 |
void QLine |
|
|
73 | void QLineSeries::add(qreal x,qreal y) | |
|
74 | 74 | { |
|
75 | 75 | m_x<<x; |
|
76 | 76 | m_y<<y; |
|
77 | 77 | } |
|
78 | 78 | |
|
79 | 79 | /*! |
|
80 | 80 | This is an overloaded function. |
|
81 | 81 | Adds data \a point to the series. Points are connected with lines on the chart. |
|
82 | 82 | */ |
|
83 |
void QLine |
|
|
83 | void QLineSeries::add(const QPointF& point) | |
|
84 | 84 | { |
|
85 | 85 | m_x<<point.x(); |
|
86 | 86 | m_y<<point.y(); |
|
87 | 87 | } |
|
88 | 88 | |
|
89 | 89 | /*! |
|
90 | 90 | Modifies \a y value for given \a x a value. |
|
91 | 91 | */ |
|
92 |
void QLine |
|
|
92 | void QLineSeries::replace(qreal x,qreal y) | |
|
93 | 93 | { |
|
94 | 94 | int index = m_x.indexOf(x); |
|
95 | 95 | m_x[index]=x; |
|
96 | 96 | m_y[index]=y; |
|
97 | 97 | emit changed(index); |
|
98 | 98 | } |
|
99 | 99 | |
|
100 | 100 | /*! |
|
101 | 101 | This is an overloaded function. |
|
102 | 102 | Replaces current y value of for given \a point x value with \a point y value. |
|
103 | 103 | */ |
|
104 |
void QLine |
|
|
104 | void QLineSeries::replace(const QPointF& point) | |
|
105 | 105 | { |
|
106 | 106 | int index = m_x.indexOf(point.x()); |
|
107 | 107 | m_x[index]=point.x(); |
|
108 | 108 | m_y[index]=point.y(); |
|
109 | 109 | emit changed(index); |
|
110 | 110 | } |
|
111 | 111 | |
|
112 | 112 | /*! |
|
113 | 113 | Removes current \a x and y value. |
|
114 | 114 | */ |
|
115 |
void QLine |
|
|
115 | void QLineSeries::remove(qreal x) | |
|
116 | 116 | { |
|
117 | 117 | |
|
118 | 118 | } |
|
119 | 119 | |
|
120 | 120 | /*! |
|
121 | 121 | Removes current \a point x value. Note \point y value is ignored. |
|
122 | 122 | */ |
|
123 |
void QLine |
|
|
123 | void QLineSeries::remove(const QPointF& point) | |
|
124 | 124 | { |
|
125 | 125 | |
|
126 | 126 | } |
|
127 | 127 | |
|
128 | 128 | /*! |
|
129 | 129 | Clears all the data. |
|
130 | 130 | */ |
|
131 |
void QLine |
|
|
131 | void QLineSeries::clear() | |
|
132 | 132 | { |
|
133 | 133 | m_x.clear(); |
|
134 | 134 | m_y.clear(); |
|
135 | 135 | } |
|
136 | 136 | |
|
137 | 137 | /*! |
|
138 | 138 | \internal \a pos |
|
139 | 139 | */ |
|
140 |
qreal QLine |
|
|
140 | qreal QLineSeries::x(int pos) const | |
|
141 | 141 | { |
|
142 | 142 | return m_x.at(pos); |
|
143 | 143 | } |
|
144 | 144 | |
|
145 | 145 | /*! |
|
146 | 146 | \internal \a pos |
|
147 | 147 | */ |
|
148 |
qreal QLine |
|
|
148 | qreal QLineSeries::y(int pos) const | |
|
149 | 149 | { |
|
150 | 150 | return m_y.at(pos); |
|
151 | 151 | } |
|
152 | 152 | |
|
153 | 153 | /*! |
|
154 | 154 | Returns number of data points within series. |
|
155 | 155 | */ |
|
156 |
int QLine |
|
|
156 | int QLineSeries::count() const | |
|
157 | 157 | { |
|
158 | 158 | Q_ASSERT(m_x.size() == m_y.size()); |
|
159 | 159 | |
|
160 | 160 | return m_x.size(); |
|
161 | 161 | |
|
162 | 162 | } |
|
163 | 163 | |
|
164 | 164 | /*! |
|
165 | 165 | Sets \a pen used for drawing given series.. |
|
166 | 166 | */ |
|
167 |
void QLine |
|
|
167 | void QLineSeries::setPen(const QPen& pen) | |
|
168 | 168 | { |
|
169 | 169 | m_pen=pen; |
|
170 | 170 | } |
|
171 | 171 | |
|
172 | 172 | /*! |
|
173 | 173 | Sets if data points are \a visible and should be drawn on line. |
|
174 | 174 | */ |
|
175 |
void QLine |
|
|
175 | void QLineSeries::setPointsVisible(bool visible) | |
|
176 | 176 | { |
|
177 | 177 | m_pointsVisible=visible; |
|
178 | 178 | } |
|
179 | 179 | |
|
180 |
QDebug operator<< (QDebug debug, const QLine |
|
|
180 | QDebug operator<< (QDebug debug, const QLineSeries series) | |
|
181 | 181 | { |
|
182 | 182 | Q_ASSERT(series.m_x.size() == series.m_y.size()); |
|
183 | 183 | |
|
184 | 184 | int size = series.m_x.size(); |
|
185 | 185 | |
|
186 | 186 | for (int i=0;i<size;i++) { |
|
187 | 187 | debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") "; |
|
188 | 188 | } |
|
189 | 189 | return debug.space(); |
|
190 | 190 | } |
|
191 | 191 | |
|
192 | 192 | |
|
193 |
#include "moc_qline |
|
|
193 | #include "moc_qlineseries.cpp" | |
|
194 | 194 | |
|
195 | 195 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,52 +1,52 | |||
|
1 | 1 | #ifndef QLINECHARTSERIES_H_ |
|
2 | 2 | #define QLINECHARTSERIES_H_ |
|
3 | 3 | |
|
4 | 4 | #include "qchartglobal.h" |
|
5 | 5 | #include "qchartseries.h" |
|
6 | 6 | #include <QDebug> |
|
7 | 7 | #include <QPen> |
|
8 | 8 | #include <QBrush> |
|
9 | 9 | |
|
10 | 10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
11 | 11 | |
|
12 |
class QTCOMMERCIALCHART_EXPORT QLine |
|
|
12 | class QTCOMMERCIALCHART_EXPORT QLineSeries : public QChartSeries | |
|
13 | 13 | { |
|
14 | 14 | Q_OBJECT |
|
15 | 15 | public: |
|
16 |
QLine |
|
|
17 |
virtual ~QLine |
|
|
16 | QLineSeries(QObject* parent=0); | |
|
17 | virtual ~QLineSeries(); | |
|
18 | 18 | |
|
19 | 19 | public: // from QChartSeries |
|
20 | 20 | virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeLine;} |
|
21 | 21 | void add(qreal x, qreal y); |
|
22 | 22 | void add(const QPointF& point); |
|
23 | 23 | void replace(qreal x,qreal y); |
|
24 | 24 | void replace(const QPointF& point); |
|
25 | 25 | void remove(qreal x); |
|
26 | 26 | void remove(const QPointF& point); |
|
27 | 27 | void clear(); |
|
28 | 28 | |
|
29 | 29 | void setPen(const QPen& pen); |
|
30 | 30 | QPen pen() const { return m_pen;} |
|
31 | 31 | |
|
32 | 32 | void setPointsVisible(bool visible); |
|
33 | 33 | bool isPointsVisible() const {return m_pointsVisible;} |
|
34 | 34 | |
|
35 | 35 | int count() const; |
|
36 | 36 | qreal x(int pos) const; |
|
37 | 37 | qreal y(int pos) const; |
|
38 |
friend QDebug operator<< (QDebug d, const QLine |
|
|
38 | friend QDebug operator<< (QDebug d, const QLineSeries series); | |
|
39 | 39 | |
|
40 | 40 | signals: |
|
41 | 41 | void changed(int index); |
|
42 | 42 | |
|
43 | 43 | private: |
|
44 | 44 | QVector<qreal> m_x; |
|
45 | 45 | QVector<qreal> m_y; |
|
46 | 46 | QPen m_pen; |
|
47 | 47 | bool m_pointsVisible; |
|
48 | 48 | }; |
|
49 | 49 | |
|
50 | 50 | QTCOMMERCIALCHART_END_NAMESPACE |
|
51 | 51 | |
|
52 | 52 | #endif |
@@ -1,599 +1,599 | |||
|
1 | 1 | #include <QtTest/QtTest> |
|
2 | 2 | #include <qchartaxis.h> |
|
3 | 3 | #include <qchartseries.h> |
|
4 |
#include <qline |
|
|
4 | #include <qlineseries.h> | |
|
5 | 5 | #include <private/chartdataset_p.h> |
|
6 | 6 | #include <private/domain_p.h> |
|
7 | 7 | |
|
8 | 8 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
9 | 9 | |
|
10 | 10 | Q_DECLARE_METATYPE(Domain) |
|
11 | 11 | Q_DECLARE_METATYPE(QChartAxis*) |
|
12 | 12 | Q_DECLARE_METATYPE(QChartSeries*) |
|
13 |
Q_DECLARE_METATYPE(QLine |
|
|
13 | Q_DECLARE_METATYPE(QLineSeries*) | |
|
14 | 14 | |
|
15 | 15 | class tst_ChartDataSet: public QObject { |
|
16 | 16 | Q_OBJECT |
|
17 | 17 | |
|
18 | 18 | public slots: |
|
19 | 19 | void initTestCase(); |
|
20 | 20 | void cleanupTestCase(); |
|
21 | 21 | void init(); |
|
22 | 22 | void cleanup(); |
|
23 | 23 | |
|
24 | 24 | private slots: |
|
25 | 25 | void chartdataset_data(); |
|
26 | 26 | void chartdataset(); |
|
27 | 27 | |
|
28 | 28 | void addDomain_data(); |
|
29 | 29 | void addDomain(); |
|
30 | 30 | void addSeries_data(); |
|
31 | 31 | void addSeries(); |
|
32 | 32 | void axisY_data(); |
|
33 | 33 | void axisY(); |
|
34 | 34 | void clearDomains_data(); |
|
35 | 35 | void clearDomains(); |
|
36 | 36 | void domain_data(); |
|
37 | 37 | void domain(); |
|
38 | 38 | void nextpreviousDomain_data(); |
|
39 | 39 | void nextpreviousDomain(); |
|
40 | 40 | void removeSeries_data(); |
|
41 | 41 | void removeSeries(); |
|
42 | 42 | void removeAllSeries_data(); |
|
43 | 43 | void removeAllSeries(); |
|
44 | 44 | }; |
|
45 | 45 | |
|
46 | 46 | void tst_ChartDataSet::initTestCase() |
|
47 | 47 | { |
|
48 | 48 | qRegisterMetaType<Domain>("Domain"); |
|
49 | 49 | qRegisterMetaType<QChartAxis*>(); |
|
50 | 50 | qRegisterMetaType<QChartSeries*>(); |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | void tst_ChartDataSet::cleanupTestCase() |
|
54 | 54 | { |
|
55 | 55 | } |
|
56 | 56 | |
|
57 | 57 | void tst_ChartDataSet::init() |
|
58 | 58 | { |
|
59 | 59 | } |
|
60 | 60 | |
|
61 | 61 | void tst_ChartDataSet::cleanup() |
|
62 | 62 | { |
|
63 | 63 | } |
|
64 | 64 | |
|
65 | 65 | void tst_ChartDataSet::chartdataset_data() |
|
66 | 66 | { |
|
67 | 67 | } |
|
68 | 68 | |
|
69 | 69 | void tst_ChartDataSet::chartdataset() |
|
70 | 70 | { |
|
71 | 71 | ChartDataSet dataSet; |
|
72 | 72 | QVERIFY2(dataSet.axisX(), "Missing axisX."); |
|
73 | 73 | QVERIFY2(dataSet.axisY(), "Missing axisY."); |
|
74 | 74 | //check if not dangling pointer |
|
75 | 75 | dataSet.axisX()->objectName(); |
|
76 | 76 | dataSet.axisY()->objectName(); |
|
77 | 77 | QVERIFY(dataSet.domain(dataSet.axisX())==Domain()); |
|
78 | 78 | QVERIFY(dataSet.domain(dataSet.axisY())==Domain()); |
|
79 | 79 | QCOMPARE(dataSet.domainIndex(), 0); |
|
80 | 80 | } |
|
81 | 81 | |
|
82 | 82 | void tst_ChartDataSet::addDomain_data() |
|
83 | 83 | { |
|
84 | 84 | QTest::addColumn<QRectF>("rect"); |
|
85 | 85 | QTest::addColumn<QRectF>("viewport"); |
|
86 | 86 | QTest::newRow("400x400,1000x1000") << QRectF(200, 200, 600, 600) |
|
87 | 87 | << QRectF(0, 0, 1000, 1000); |
|
88 | 88 | QTest::newRow("600x600,1000x1000") << QRectF(100, 100, 700, 700) |
|
89 | 89 | << QRectF(0, 0, 1000, 1000); |
|
90 | 90 | QTest::newRow("200x200,1000x1000") << QRectF(400, 400, 600, 600) |
|
91 | 91 | << QRectF(0, 0, 1000, 1000); |
|
92 | 92 | } |
|
93 | 93 | |
|
94 | 94 | void tst_ChartDataSet::addDomain() |
|
95 | 95 | { |
|
96 | 96 | QFETCH(QRectF, rect); |
|
97 | 97 | QFETCH(QRectF, viewport); |
|
98 | 98 | |
|
99 | 99 | ChartDataSet dataSet; |
|
100 | 100 | |
|
101 | 101 | Domain domain1(0, 1000, 0, 1000); |
|
102 |
QLine |
|
|
102 | QLineSeries series; | |
|
103 | 103 | series.add(0, 0); |
|
104 | 104 | series.add(1000, 1000); |
|
105 | 105 | |
|
106 | 106 | dataSet.addSeries(&series); |
|
107 | 107 | |
|
108 | 108 | QCOMPARE(dataSet.domainIndex(), 0); |
|
109 | 109 | |
|
110 | 110 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
111 | 111 | QSignalSpy spy1(&dataSet, |
|
112 | 112 | SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&))); |
|
113 | 113 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
114 | 114 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*))); |
|
115 | 115 | QSignalSpy spy4(&dataSet, |
|
116 | 116 | SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&))); |
|
117 | 117 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*))); |
|
118 | 118 | |
|
119 | 119 | Domain domain2 = dataSet.domain(dataSet.axisY()); |
|
120 | 120 | QVERIFY(domain1 == domain2); |
|
121 | 121 | |
|
122 | 122 | dataSet.addDomain(rect, viewport); |
|
123 | 123 | QCOMPARE(dataSet.domainIndex(), 1); |
|
124 | 124 | Domain domain3 = dataSet.domain(dataSet.axisY()); |
|
125 | 125 | Domain domain4 = domain1.subDomain(rect, viewport.width(), |
|
126 | 126 | viewport.height()); |
|
127 | 127 | QVERIFY(domain3 == domain4); |
|
128 | 128 | |
|
129 | 129 | QCOMPARE(spy0.count(), 0); |
|
130 | 130 | QCOMPARE(spy1.count(), 2); |
|
131 | 131 | QCOMPARE(spy2.count(), 0); |
|
132 | 132 | QCOMPARE(spy3.count(), 0); |
|
133 | 133 | QCOMPARE(spy4.count(), 1); |
|
134 | 134 | QCOMPARE(spy5.count(), 0); |
|
135 | 135 | } |
|
136 | 136 | |
|
137 | 137 | void tst_ChartDataSet::addSeries_data() |
|
138 | 138 | { |
|
139 | 139 | QTest::addColumn<int>("seriesCount"); |
|
140 | 140 | QTest::addColumn<int>("axisYCount"); |
|
141 | 141 | QTest::newRow("2 series, default axis") << 2 << 0; |
|
142 | 142 | QTest::newRow("2 series, 2 new axis") << 2 << 2; |
|
143 | 143 | QTest::newRow("2 series, 1 new axis") << 2 << 2; |
|
144 | 144 | QTest::newRow("3 series, 3 new axis") << 3 << 3; |
|
145 | 145 | QTest::newRow("3 series, 2 new axis") << 3 << 2; |
|
146 | 146 | QTest::newRow("3 series, 1 new axis") << 3 << 1; |
|
147 | 147 | } |
|
148 | 148 | |
|
149 | 149 | void tst_ChartDataSet::addSeries() |
|
150 | 150 | { |
|
151 | 151 | QFETCH(int, seriesCount); |
|
152 | 152 | QFETCH(int, axisYCount); |
|
153 | 153 | |
|
154 | 154 | ChartDataSet dataSet; |
|
155 | 155 | |
|
156 | 156 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
157 | 157 | QSignalSpy spy1(&dataSet, |
|
158 | 158 | SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&))); |
|
159 | 159 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
160 | 160 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*))); |
|
161 | 161 | QSignalSpy spy4(&dataSet, |
|
162 | 162 | SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&))); |
|
163 | 163 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*))); |
|
164 | 164 | |
|
165 | 165 | QList<QChartAxis*> axisList; |
|
166 | 166 | |
|
167 | 167 | for (int i = 0; i < axisYCount; i++) { |
|
168 | 168 | QChartAxis* axis = new QChartAxis(); |
|
169 | 169 | axisList << axis; |
|
170 | 170 | } |
|
171 | 171 | |
|
172 | 172 | QList<QChartAxis*>::iterator iterator = axisList.begin(); |
|
173 | 173 | |
|
174 | 174 | for (int i = 0; i < seriesCount; i++) { |
|
175 | 175 | QChartAxis* axisY = 0; |
|
176 |
QLine |
|
|
176 | QLineSeries* series = new QLineSeries(); | |
|
177 | 177 | if (iterator != axisList.end()) { |
|
178 | 178 | axisY = *iterator; |
|
179 | 179 | iterator++; |
|
180 | 180 | } else if (axisList.count() > 0) { |
|
181 | 181 | iterator--; |
|
182 | 182 | axisY = *iterator; |
|
183 | 183 | iterator++; |
|
184 | 184 | } |
|
185 | 185 | dataSet.addSeries(series, axisY); |
|
186 | 186 | } |
|
187 | 187 | |
|
188 | 188 | //default axis |
|
189 | 189 | if (axisYCount == 0) |
|
190 | 190 | axisYCount+=2; |
|
191 | 191 | else |
|
192 | 192 | axisYCount++; |
|
193 | 193 | |
|
194 | 194 | QCOMPARE(spy0.count(), axisYCount); |
|
195 | 195 | QCOMPARE(spy1.count(), seriesCount*2); |
|
196 | 196 | QCOMPARE(spy2.count(), 0); |
|
197 | 197 | QCOMPARE(spy3.count(), seriesCount); |
|
198 | 198 | QCOMPARE(spy4.count(), seriesCount); |
|
199 | 199 | QCOMPARE(spy5.count(), 0); |
|
200 | 200 | |
|
201 | 201 | QCOMPARE(dataSet.domainIndex(), 0); |
|
202 | 202 | } |
|
203 | 203 | |
|
204 | 204 | void tst_ChartDataSet::axisY_data() |
|
205 | 205 | { |
|
206 | 206 | QTest::addColumn<QChartAxis*>("axisY"); |
|
207 | 207 | QTest::newRow("axisY1") << new QChartAxis(); |
|
208 | 208 | QTest::newRow("axisY2") << new QChartAxis(); |
|
209 | 209 | } |
|
210 | 210 | |
|
211 | 211 | void tst_ChartDataSet::axisY() |
|
212 | 212 | { |
|
213 | 213 | QFETCH(QChartAxis*, axisY); |
|
214 | 214 | |
|
215 | 215 | ChartDataSet dataSet; |
|
216 | 216 | |
|
217 | 217 | QChartAxis* defaultAxisY = dataSet.axisY(); |
|
218 | 218 | |
|
219 | 219 | QVERIFY2(defaultAxisY, "Missing axisY."); |
|
220 | 220 | |
|
221 |
QLine |
|
|
221 | QLineSeries* series1 = new QLineSeries(); | |
|
222 | 222 | dataSet.addSeries(series1); |
|
223 | 223 | |
|
224 |
QLine |
|
|
224 | QLineSeries* series2 = new QLineSeries(); | |
|
225 | 225 | dataSet.addSeries(series2, axisY); |
|
226 | 226 | |
|
227 | 227 | QVERIFY(dataSet.axisY(series1) == defaultAxisY); |
|
228 | 228 | QVERIFY(dataSet.axisY(series2) == axisY); |
|
229 | 229 | |
|
230 | 230 | |
|
231 | 231 | } |
|
232 | 232 | |
|
233 | 233 | void tst_ChartDataSet::clearDomains_data() |
|
234 | 234 | { |
|
235 | 235 | QTest::addColumn<int>("indexCount"); |
|
236 | 236 | QTest::newRow("0") << 0; |
|
237 | 237 | QTest::newRow("1") << 1; |
|
238 | 238 | QTest::newRow("5") << 2; |
|
239 | 239 | QTest::newRow("8") << 3; |
|
240 | 240 | } |
|
241 | 241 | |
|
242 | 242 | void tst_ChartDataSet::clearDomains() |
|
243 | 243 | { |
|
244 | 244 | QFETCH(int, indexCount); |
|
245 | 245 | |
|
246 | 246 | Domain domain1(0, 100, 0, 100); |
|
247 |
QLine |
|
|
247 | QLineSeries* series = new QLineSeries(); | |
|
248 | 248 | series->add(0, 0); |
|
249 | 249 | series->add(100, 100); |
|
250 | 250 | |
|
251 | 251 | ChartDataSet dataSet; |
|
252 | 252 | |
|
253 | 253 | QCOMPARE(dataSet.domainIndex(), 0); |
|
254 | 254 | |
|
255 | 255 | dataSet.addSeries(series); |
|
256 | 256 | |
|
257 | 257 | Domain domain2 = dataSet.domain(dataSet.axisY()); |
|
258 | 258 | |
|
259 | 259 | QVERIFY(domain2 == domain1); |
|
260 | 260 | |
|
261 | 261 | QList<Domain> domains; |
|
262 | 262 | |
|
263 | 263 | domains << domain1; |
|
264 | 264 | |
|
265 | 265 | for (int i = 0; i < indexCount; i++) { |
|
266 | 266 | dataSet.addDomain(QRect(0, 0, 10, 10), QRect(0, 0, 100, 100)); |
|
267 | 267 | domains << dataSet.domain(dataSet.axisY()); |
|
268 | 268 | } |
|
269 | 269 | |
|
270 | 270 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
271 | 271 | QSignalSpy spy1(&dataSet, |
|
272 | 272 | SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&))); |
|
273 | 273 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
274 | 274 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*))); |
|
275 | 275 | QSignalSpy spy4(&dataSet, |
|
276 | 276 | SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&))); |
|
277 | 277 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*))); |
|
278 | 278 | |
|
279 | 279 | dataSet.clearDomains(indexCount); |
|
280 | 280 | |
|
281 | 281 | QCOMPARE(dataSet.domainIndex(), indexCount); |
|
282 | 282 | |
|
283 | 283 | domain2 = dataSet.domain(dataSet.axisY()); |
|
284 | 284 | |
|
285 | 285 | QVERIFY(domain2 == domains.at(indexCount)); |
|
286 | 286 | |
|
287 | 287 | QCOMPARE(spy0.count(), 0); |
|
288 | 288 | QCOMPARE(spy1.count(), 0); |
|
289 | 289 | QCOMPARE(spy2.count(), 0); |
|
290 | 290 | QCOMPARE(spy3.count(), 0); |
|
291 | 291 | QCOMPARE(spy4.count(), 0); |
|
292 | 292 | QCOMPARE(spy5.count(), 0); |
|
293 | 293 | } |
|
294 | 294 | |
|
295 | 295 | void tst_ChartDataSet::domain_data() |
|
296 | 296 | { |
|
297 | 297 | QTest::addColumn<Domain>("domain1"); |
|
298 | 298 | QTest::addColumn<Domain>("domain2"); |
|
299 | 299 | QTest::addColumn<Domain>("domain3"); |
|
300 | 300 | QTest::addColumn<Domain>("domain"); |
|
301 | 301 | QTest::newRow("Domain(0,10,0,10)") << Domain(0, 10, 0, 10) |
|
302 | 302 | << Domain(0, 5, 0, 5) << Domain(0, 3, 0, 3) << Domain(0, 10, 0, 10); |
|
303 | 303 | QTest::newRow("Domain(-1,11,0,11)") << Domain(-1, 10, 0, 10) |
|
304 | 304 | << Domain(0, 11, 0, 11) << Domain(0, 3, 0, 3) |
|
305 | 305 | << Domain(-1, 11, 0, 11); |
|
306 | 306 | QTest::newRow("Domain(-5,5,1,8)") << Domain(-5, 0, 1, 1) |
|
307 | 307 | << Domain(0, 5, 0, 8) << Domain(1, 2, 1, 2) << Domain(-5, 5, 0, 8); |
|
308 | 308 | } |
|
309 | 309 | |
|
310 | 310 | void tst_ChartDataSet::domain() |
|
311 | 311 | { |
|
312 | 312 | QFETCH(Domain, domain1); |
|
313 | 313 | QFETCH(Domain, domain2); |
|
314 | 314 | QFETCH(Domain, domain3); |
|
315 | 315 | QFETCH(Domain, domain); |
|
316 | 316 | |
|
317 | 317 | ChartDataSet dataSet; |
|
318 |
QLine |
|
|
318 | QLineSeries* series1 = new QLineSeries(); | |
|
319 | 319 | series1->add(domain1.m_minX, domain1.m_minY); |
|
320 | 320 | series1->add(domain1.m_maxX, domain1.m_maxY); |
|
321 |
QLine |
|
|
321 | QLineSeries* series2 = new QLineSeries(); | |
|
322 | 322 | series2->add(domain2.m_minX, domain2.m_minY); |
|
323 | 323 | series2->add(domain2.m_maxX, domain2.m_maxY); |
|
324 |
QLine |
|
|
324 | QLineSeries* series3 = new QLineSeries(); | |
|
325 | 325 | series3->add(domain3.m_minX, domain3.m_minY); |
|
326 | 326 | series3->add(domain3.m_maxX, domain3.m_maxY); |
|
327 | 327 | |
|
328 | 328 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
329 | 329 | QSignalSpy spy1(&dataSet, |
|
330 | 330 | SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&))); |
|
331 | 331 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
332 | 332 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*))); |
|
333 | 333 | QSignalSpy spy4(&dataSet, |
|
334 | 334 | SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&))); |
|
335 | 335 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*))); |
|
336 | 336 | |
|
337 | 337 | dataSet.addSeries(series1); |
|
338 | 338 | dataSet.addSeries(series2); |
|
339 | 339 | dataSet.addSeries(series3); |
|
340 | 340 | |
|
341 | 341 | QCOMPARE(dataSet.domainIndex(), 0); |
|
342 | 342 | QVERIFY2(dataSet.domain(dataSet.axisY()) == domain, "Domain not equal"); |
|
343 | 343 | |
|
344 | 344 | QCOMPARE(spy0.count(), 2); |
|
345 | 345 | QCOMPARE(spy1.count(), 6); |
|
346 | 346 | QCOMPARE(spy2.count(), 0); |
|
347 | 347 | QCOMPARE(spy3.count(), 3); |
|
348 | 348 | QCOMPARE(spy4.count(), 3); |
|
349 | 349 | QCOMPARE(spy5.count(), 0); |
|
350 | 350 | } |
|
351 | 351 | |
|
352 | 352 | void tst_ChartDataSet::nextpreviousDomain_data() |
|
353 | 353 | { |
|
354 | 354 | QTest::addColumn<QRectF>("rect"); |
|
355 | 355 | QTest::addColumn<QRectF>("viewport"); |
|
356 | 356 | QTest::newRow("400x400,1000x1000") << QRectF(200, 200, 600, 600) |
|
357 | 357 | << QRectF(0, 0, 1000, 1000); |
|
358 | 358 | QTest::newRow("600x600,1000x1000") << QRectF(100, 100, 700, 700) |
|
359 | 359 | << QRectF(0, 0, 1000, 1000); |
|
360 | 360 | QTest::newRow("200x200,1000x1000") << QRectF(400, 400, 600, 600) |
|
361 | 361 | << QRectF(0, 0, 1000, 1000); |
|
362 | 362 | } |
|
363 | 363 | |
|
364 | 364 | void tst_ChartDataSet::nextpreviousDomain() |
|
365 | 365 | { |
|
366 | 366 | |
|
367 | 367 | QFETCH(QRectF, rect); |
|
368 | 368 | QFETCH(QRectF, viewport); |
|
369 | 369 | |
|
370 | 370 | ChartDataSet dataSet; |
|
371 | 371 | |
|
372 | 372 | Domain domain1(0, 1000, 0, 1000); |
|
373 |
QLine |
|
|
373 | QLineSeries* series = new QLineSeries(); | |
|
374 | 374 | series->add(0, 0); |
|
375 | 375 | series->add(1000, 1000); |
|
376 | 376 | |
|
377 | 377 | dataSet.addSeries(series); |
|
378 | 378 | |
|
379 | 379 | QCOMPARE(dataSet.domainIndex(), 0); |
|
380 | 380 | |
|
381 | 381 | Domain domain2 = dataSet.domain(dataSet.axisY()); |
|
382 | 382 | QVERIFY(domain1 == domain2); |
|
383 | 383 | |
|
384 | 384 | dataSet.addDomain(rect, viewport); |
|
385 | 385 | QCOMPARE(dataSet.domainIndex(), 1); |
|
386 | 386 | Domain domain3 = dataSet.domain(dataSet.axisY()); |
|
387 | 387 | Domain domain4 = domain1.subDomain(rect, viewport.width(), |
|
388 | 388 | viewport.height()); |
|
389 | 389 | QVERIFY(domain3 == domain4); |
|
390 | 390 | |
|
391 | 391 | dataSet.addDomain(rect, viewport); |
|
392 | 392 | QCOMPARE(dataSet.domainIndex(), 2); |
|
393 | 393 | Domain domain5 = dataSet.domain(dataSet.axisY()); |
|
394 | 394 | Domain domain6 = domain3.subDomain(rect, viewport.width(), |
|
395 | 395 | viewport.height()); |
|
396 | 396 | QVERIFY(domain5 == domain6); |
|
397 | 397 | |
|
398 | 398 | dataSet.addDomain(rect, viewport); |
|
399 | 399 | QCOMPARE(dataSet.domainIndex(), 3); |
|
400 | 400 | Domain domain7 = dataSet.domain(dataSet.axisY()); |
|
401 | 401 | Domain domain8 = domain5.subDomain(rect, viewport.width(), |
|
402 | 402 | viewport.height()); |
|
403 | 403 | QVERIFY(domain7 == domain8); |
|
404 | 404 | |
|
405 | 405 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
406 | 406 | QSignalSpy spy1(&dataSet, |
|
407 | 407 | SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&))); |
|
408 | 408 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
409 | 409 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*))); |
|
410 | 410 | QSignalSpy spy4(&dataSet, |
|
411 | 411 | SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&))); |
|
412 | 412 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*))); |
|
413 | 413 | |
|
414 | 414 | Domain domain; |
|
415 | 415 | |
|
416 | 416 | bool previous = dataSet.previousDomain(); |
|
417 | 417 | QCOMPARE(previous, true); |
|
418 | 418 | QCOMPARE(dataSet.domainIndex(), 2); |
|
419 | 419 | domain = dataSet.domain(dataSet.axisY()); |
|
420 | 420 | QVERIFY(domain == domain5); |
|
421 | 421 | previous = dataSet.previousDomain(); |
|
422 | 422 | QCOMPARE(previous, true); |
|
423 | 423 | QCOMPARE(dataSet.domainIndex(), 1); |
|
424 | 424 | domain = dataSet.domain(dataSet.axisY()); |
|
425 | 425 | QVERIFY(domain == domain3); |
|
426 | 426 | previous = dataSet.previousDomain(); |
|
427 | 427 | QCOMPARE(previous, true); |
|
428 | 428 | QCOMPARE(dataSet.domainIndex(), 0); |
|
429 | 429 | domain = dataSet.domain(dataSet.axisY()); |
|
430 | 430 | QVERIFY(domain == domain1); |
|
431 | 431 | previous = dataSet.previousDomain(); |
|
432 | 432 | QCOMPARE(previous, false); |
|
433 | 433 | QCOMPARE(dataSet.domainIndex(), 0); |
|
434 | 434 | domain = dataSet.domain(dataSet.axisY()); |
|
435 | 435 | QVERIFY(domain == domain1); |
|
436 | 436 | |
|
437 | 437 | bool next = dataSet.nextDomain(); |
|
438 | 438 | QCOMPARE(next, true); |
|
439 | 439 | QCOMPARE(dataSet.domainIndex(),1); |
|
440 | 440 | next = dataSet.nextDomain(); |
|
441 | 441 | QCOMPARE(next, true); |
|
442 | 442 | QCOMPARE(dataSet.domainIndex(),2); |
|
443 | 443 | next = dataSet.nextDomain(); |
|
444 | 444 | QCOMPARE(next, true); |
|
445 | 445 | QCOMPARE(dataSet.domainIndex(),3); |
|
446 | 446 | next = dataSet.nextDomain(); |
|
447 | 447 | QCOMPARE(next, false); |
|
448 | 448 | QCOMPARE(dataSet.domainIndex(),3); |
|
449 | 449 | |
|
450 | 450 | |
|
451 | 451 | QCOMPARE(spy0.count(), 0); |
|
452 | 452 | QCOMPARE(spy1.count(), 12); |
|
453 | 453 | QCOMPARE(spy2.count(), 0); |
|
454 | 454 | QCOMPARE(spy3.count(), 0); |
|
455 | 455 | QCOMPARE(spy4.count(), 6); |
|
456 | 456 | QCOMPARE(spy5.count(), 0); |
|
457 | 457 | } |
|
458 | 458 | |
|
459 | 459 | void tst_ChartDataSet::removeSeries_data() |
|
460 | 460 | { |
|
461 | 461 | QTest::addColumn<int>("seriesCount"); |
|
462 | 462 | QTest::addColumn<int>("axisYCount"); |
|
463 | 463 | QTest::newRow("2 series, default axis") << 2 << 0; |
|
464 | 464 | QTest::newRow("2 series, 2 new axis") << 2 << 2; |
|
465 | 465 | QTest::newRow("2 series, 1 new axis") << 2 << 2; |
|
466 | 466 | QTest::newRow("3 series, 3 new axis") << 3 << 3; |
|
467 | 467 | QTest::newRow("3 series, 2 new axis") << 3 << 2; |
|
468 | 468 | QTest::newRow("3 series, 1 new axis") << 3 << 1; |
|
469 | 469 | } |
|
470 | 470 | |
|
471 | 471 | void tst_ChartDataSet::removeSeries() |
|
472 | 472 | { |
|
473 | 473 | QFETCH(int, seriesCount); |
|
474 | 474 | QFETCH(int, axisYCount); |
|
475 | 475 | |
|
476 | 476 | ChartDataSet dataSet; |
|
477 | 477 | |
|
478 | 478 | QList<QChartAxis*> axisList; |
|
479 | 479 | QList<QChartSeries*> seriesList; |
|
480 | 480 | |
|
481 | 481 | for (int i = 0; i < axisYCount; i++) { |
|
482 | 482 | QChartAxis* axis = new QChartAxis(); |
|
483 | 483 | axisList << axis; |
|
484 | 484 | } |
|
485 | 485 | |
|
486 | 486 | QList<QChartAxis*>::iterator iterator = axisList.begin(); |
|
487 | 487 | |
|
488 | 488 | for (int i = 0; i < seriesCount; i++) { |
|
489 | 489 | QChartAxis* axisY = 0; |
|
490 |
QLine |
|
|
490 | QLineSeries* series = new QLineSeries(); | |
|
491 | 491 | if (iterator != axisList.end()) { |
|
492 | 492 | axisY = *iterator; |
|
493 | 493 | iterator++; |
|
494 | 494 | } else if (axisList.count() > 0) { |
|
495 | 495 | iterator--; |
|
496 | 496 | axisY = *iterator; |
|
497 | 497 | iterator++; |
|
498 | 498 | } |
|
499 | 499 | dataSet.addSeries(series, axisY); |
|
500 | 500 | seriesList << series; |
|
501 | 501 | } |
|
502 | 502 | |
|
503 | 503 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
504 | 504 | QSignalSpy spy1(&dataSet, |
|
505 | 505 | SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&))); |
|
506 | 506 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
507 | 507 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*))); |
|
508 | 508 | QSignalSpy spy4(&dataSet, |
|
509 | 509 | SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&))); |
|
510 | 510 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*))); |
|
511 | 511 | |
|
512 | 512 | for (int i = 0; i < seriesCount; i++) { |
|
513 | 513 | dataSet.removeSeries(seriesList.at(i)); |
|
514 | 514 | } |
|
515 | 515 | |
|
516 | 516 | //default axis |
|
517 | 517 | if (axisYCount == 0) |
|
518 | 518 | axisYCount++; |
|
519 | 519 | |
|
520 | 520 | QCOMPARE(spy0.count(), 0); |
|
521 | 521 | QCOMPARE(spy1.count(), 0); |
|
522 | 522 | QCOMPARE(spy2.count(), axisYCount); |
|
523 | 523 | QCOMPARE(spy3.count(), 0); |
|
524 | 524 | QCOMPARE(spy4.count(), 0); |
|
525 | 525 | QCOMPARE(spy5.count(), seriesCount); |
|
526 | 526 | |
|
527 | 527 | QCOMPARE(dataSet.domainIndex(), 0); |
|
528 | 528 | |
|
529 | 529 | qDeleteAll(seriesList); |
|
530 | 530 | } |
|
531 | 531 | |
|
532 | 532 | void tst_ChartDataSet::removeAllSeries_data() |
|
533 | 533 | { |
|
534 | 534 | QTest::addColumn<int>("seriesCount"); |
|
535 | 535 | QTest::addColumn<int>("axisYCount"); |
|
536 | 536 | QTest::newRow("2 series, default axis") << 2 << 0; |
|
537 | 537 | QTest::newRow("2 series, 2 new axis") << 2 << 2; |
|
538 | 538 | QTest::newRow("2 series, 1 new axis") << 2 << 2; |
|
539 | 539 | QTest::newRow("3 series, 3 new axis") << 3 << 3; |
|
540 | 540 | QTest::newRow("3 series, 2 new axis") << 3 << 2; |
|
541 | 541 | QTest::newRow("3 series, 1 new axis") << 3 << 1; |
|
542 | 542 | } |
|
543 | 543 | |
|
544 | 544 | void tst_ChartDataSet::removeAllSeries() |
|
545 | 545 | { |
|
546 | 546 | QFETCH(int, seriesCount); |
|
547 | 547 | QFETCH(int, axisYCount); |
|
548 | 548 | |
|
549 | 549 | ChartDataSet dataSet; |
|
550 | 550 | |
|
551 | 551 | QList<QChartAxis*> axisList; |
|
552 | 552 | |
|
553 | 553 | for (int i = 0; i < axisYCount; i++) { |
|
554 | 554 | QChartAxis* axis = new QChartAxis(); |
|
555 | 555 | axisList << axis; |
|
556 | 556 | } |
|
557 | 557 | |
|
558 | 558 | QList<QChartAxis*>::iterator iterator = axisList.begin(); |
|
559 | 559 | |
|
560 | 560 | for (int i = 0; i < seriesCount; i++) { |
|
561 | 561 | QChartAxis* axisY = 0; |
|
562 |
QLine |
|
|
562 | QLineSeries* series = new QLineSeries(); | |
|
563 | 563 | if (iterator != axisList.end()) { |
|
564 | 564 | axisY = *iterator; |
|
565 | 565 | iterator++; |
|
566 | 566 | } else if (axisList.count() > 0) { |
|
567 | 567 | iterator--; |
|
568 | 568 | axisY = *iterator; |
|
569 | 569 | iterator++; |
|
570 | 570 | } |
|
571 | 571 | dataSet.addSeries(series, axisY); |
|
572 | 572 | } |
|
573 | 573 | |
|
574 | 574 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
575 | 575 | QSignalSpy spy1(&dataSet, SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&))); |
|
576 | 576 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
577 | 577 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*))); |
|
578 | 578 | QSignalSpy spy4(&dataSet, SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&))); |
|
579 | 579 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*))); |
|
580 | 580 | |
|
581 | 581 | dataSet.removeAllSeries(); |
|
582 | 582 | //default axis |
|
583 | 583 | if (axisYCount == 0) |
|
584 | 584 | axisYCount++; |
|
585 | 585 | |
|
586 | 586 | QCOMPARE(spy0.count(), 0); |
|
587 | 587 | QCOMPARE(spy1.count(), 0); |
|
588 | 588 | QCOMPARE(spy2.count(), axisYCount); |
|
589 | 589 | QCOMPARE(spy3.count(), 0); |
|
590 | 590 | QCOMPARE(spy4.count(), 0); |
|
591 | 591 | QCOMPARE(spy5.count(), seriesCount); |
|
592 | 592 | |
|
593 | 593 | QCOMPARE(dataSet.domainIndex(), 0); |
|
594 | 594 | } |
|
595 | 595 | |
|
596 | 596 | |
|
597 | 597 | QTEST_MAIN(tst_ChartDataSet) |
|
598 | 598 | #include "tst_chartdataset.moc" |
|
599 | 599 |
@@ -1,372 +1,372 | |||
|
1 | 1 | #include "mainwidget.h" |
|
2 | 2 | #include "dataseriedialog.h" |
|
3 | 3 | #include "qchartseries.h" |
|
4 | 4 | #include "qpieseries.h" |
|
5 | 5 | #include "qscatterseries.h" |
|
6 |
#include <qline |
|
|
6 | #include <qlineseries.h> | |
|
7 | 7 | #include <qbarset.h> |
|
8 | 8 | #include <qbarcategory.h> |
|
9 | 9 | #include <qbarseries.h> |
|
10 | 10 | #include <qstackedbarseries.h> |
|
11 | 11 | #include <qpercentbarseries.h> |
|
12 | 12 | #include <QPushButton> |
|
13 | 13 | #include <QComboBox> |
|
14 | 14 | #include <QSpinBox> |
|
15 | 15 | #include <QCheckBox> |
|
16 | 16 | #include <QGridLayout> |
|
17 | 17 | #include <QHBoxLayout> |
|
18 | 18 | #include <QLabel> |
|
19 | 19 | #include <QSpacerItem> |
|
20 | 20 | #include <QMessageBox> |
|
21 | 21 | #include <cmath> |
|
22 | 22 | #include <QDebug> |
|
23 | 23 | #include <QStandardItemModel> |
|
24 | 24 | |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
27 | 27 | |
|
28 | 28 | MainWidget::MainWidget(QWidget *parent) : |
|
29 | 29 | QWidget(parent) |
|
30 | 30 | { |
|
31 | 31 | m_chartWidget = new QChartView(this); |
|
32 | 32 | m_chartWidget->setRubberBandPolicy(QChartView::HorizonalRubberBand); |
|
33 | 33 | |
|
34 | 34 | // Grid layout for the controls for configuring the chart widget |
|
35 | 35 | QGridLayout *grid = new QGridLayout(); |
|
36 | 36 | QPushButton *addSeriesButton = new QPushButton("Add series"); |
|
37 | 37 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
38 | 38 | grid->addWidget(addSeriesButton, 0, 1); |
|
39 | 39 | initBackroundCombo(grid); |
|
40 | 40 | initScaleControls(grid); |
|
41 | 41 | initThemeCombo(grid); |
|
42 | 42 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); |
|
43 | 43 | connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartWidget, SLOT(setZoomEnabled(bool))); |
|
44 | 44 | zoomCheckBox->setChecked(true); |
|
45 | 45 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); |
|
46 | 46 | // add row with empty label to make all the other rows static |
|
47 | 47 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); |
|
48 | 48 | grid->setRowStretch(grid->rowCount() - 1, 1); |
|
49 | 49 | |
|
50 | 50 | // Another grid layout as a main layout |
|
51 | 51 | QGridLayout *mainLayout = new QGridLayout(); |
|
52 | 52 | mainLayout->addLayout(grid, 0, 0); |
|
53 | 53 | |
|
54 | 54 | // Init series type specific controls |
|
55 | 55 | initPieControls(); |
|
56 | 56 | mainLayout->addLayout(m_pieLayout, 2, 0); |
|
57 | 57 | // Scatter series specific settings |
|
58 | 58 | // m_scatterLayout = new QGridLayout(); |
|
59 | 59 | // m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0); |
|
60 | 60 | // m_scatterLayout->setEnabled(false); |
|
61 | 61 | // mainLayout->addLayout(m_scatterLayout, 1, 0); |
|
62 | 62 | |
|
63 | 63 | // Add layouts and the chart widget to the main layout |
|
64 | 64 | mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1); |
|
65 | 65 | setLayout(mainLayout); |
|
66 | 66 | } |
|
67 | 67 | |
|
68 | 68 | // Combo box for selecting the chart's background |
|
69 | 69 | void MainWidget::initBackroundCombo(QGridLayout *grid) |
|
70 | 70 | { |
|
71 | 71 | QComboBox *backgroundCombo = new QComboBox(this); |
|
72 | 72 | backgroundCombo->addItem("Color"); |
|
73 | 73 | backgroundCombo->addItem("Gradient"); |
|
74 | 74 | backgroundCombo->addItem("Image"); |
|
75 | 75 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
76 | 76 | this, SLOT(backgroundChanged(int))); |
|
77 | 77 | |
|
78 | 78 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); |
|
79 | 79 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); |
|
80 | 80 | } |
|
81 | 81 | |
|
82 | 82 | // Scale related controls (auto-scale vs. manual min-max values) |
|
83 | 83 | void MainWidget::initScaleControls(QGridLayout *grid) |
|
84 | 84 | { |
|
85 | 85 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
86 | 86 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
87 | 87 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
88 | 88 | m_xMinSpin = new QSpinBox(); |
|
89 | 89 | m_xMinSpin->setMinimum(INT_MIN); |
|
90 | 90 | m_xMinSpin->setMaximum(INT_MAX); |
|
91 | 91 | m_xMinSpin->setValue(0); |
|
92 | 92 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
93 | 93 | m_xMaxSpin = new QSpinBox(); |
|
94 | 94 | m_xMaxSpin->setMinimum(INT_MIN); |
|
95 | 95 | m_xMaxSpin->setMaximum(INT_MAX); |
|
96 | 96 | m_xMaxSpin->setValue(10); |
|
97 | 97 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
98 | 98 | m_yMinSpin = new QSpinBox(); |
|
99 | 99 | m_yMinSpin->setMinimum(INT_MIN); |
|
100 | 100 | m_yMinSpin->setMaximum(INT_MAX); |
|
101 | 101 | m_yMinSpin->setValue(0); |
|
102 | 102 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
103 | 103 | m_yMaxSpin = new QSpinBox(); |
|
104 | 104 | m_yMaxSpin->setMinimum(INT_MIN); |
|
105 | 105 | m_yMaxSpin->setMaximum(INT_MAX); |
|
106 | 106 | m_yMaxSpin->setValue(10); |
|
107 | 107 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
108 | 108 | |
|
109 | 109 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); |
|
110 | 110 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); |
|
111 | 111 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); |
|
112 | 112 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); |
|
113 | 113 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); |
|
114 | 114 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); |
|
115 | 115 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); |
|
116 | 116 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); |
|
117 | 117 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); |
|
118 | 118 | |
|
119 | 119 | m_autoScaleCheck->setChecked(true); |
|
120 | 120 | } |
|
121 | 121 | |
|
122 | 122 | // Combo box for selecting theme |
|
123 | 123 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
124 | 124 | { |
|
125 | 125 | QComboBox *chartTheme = new QComboBox(); |
|
126 | 126 | chartTheme->addItem("Default"); |
|
127 | 127 | chartTheme->addItem("Vanilla"); |
|
128 | 128 | chartTheme->addItem("Icy"); |
|
129 | 129 | chartTheme->addItem("Grayscale"); |
|
130 | 130 | chartTheme->addItem("Scientific"); |
|
131 | 131 | chartTheme->addItem("Unnamed1"); |
|
132 | 132 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
133 | 133 | this, SLOT(changeChartTheme(int))); |
|
134 | 134 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); |
|
135 | 135 | grid->addWidget(chartTheme, 8, 1); |
|
136 | 136 | } |
|
137 | 137 | |
|
138 | 138 | void MainWidget::initPieControls() |
|
139 | 139 | { |
|
140 | 140 | // Pie series specific settings |
|
141 | 141 | // Pie size factory |
|
142 | 142 | QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox(); |
|
143 | 143 | pieSizeSpin->setMinimum(LONG_MIN); |
|
144 | 144 | pieSizeSpin->setMaximum(LONG_MAX); |
|
145 | 145 | pieSizeSpin->setValue(1.0); |
|
146 | 146 | pieSizeSpin->setSingleStep(0.1); |
|
147 | 147 | connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double))); |
|
148 | 148 | // Pie position |
|
149 | 149 | QComboBox *piePosCombo = new QComboBox(this); |
|
150 | 150 | piePosCombo->addItem("Maximized"); |
|
151 | 151 | piePosCombo->addItem("Top left"); |
|
152 | 152 | piePosCombo->addItem("Top right"); |
|
153 | 153 | piePosCombo->addItem("Bottom left"); |
|
154 | 154 | piePosCombo->addItem("Bottom right"); |
|
155 | 155 | connect(piePosCombo, SIGNAL(currentIndexChanged(int)), |
|
156 | 156 | this, SLOT(setPiePosition(int))); |
|
157 | 157 | m_pieLayout = new QGridLayout(); |
|
158 | 158 | m_pieLayout->setEnabled(false); |
|
159 | 159 | m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0); |
|
160 | 160 | m_pieLayout->addWidget(pieSizeSpin, 0, 1); |
|
161 | 161 | m_pieLayout->addWidget(new QLabel("Pie position"), 1, 0); |
|
162 | 162 | m_pieLayout->addWidget(piePosCombo, 1, 1); |
|
163 | 163 | } |
|
164 | 164 | |
|
165 | 165 | void MainWidget::addSeries() |
|
166 | 166 | { |
|
167 | 167 | DataSerieDialog dialog(m_defaultSeriesName, this); |
|
168 | 168 | connect(&dialog, SIGNAL(accepted(QString, int, int, QString, bool)), |
|
169 | 169 | this, SLOT(addSeries(QString, int, int, QString, bool))); |
|
170 | 170 | dialog.exec(); |
|
171 | 171 | } |
|
172 | 172 | |
|
173 | 173 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) |
|
174 | 174 | { |
|
175 | 175 | // TODO: dataCharacteristics |
|
176 | 176 | QList<RealList> testData; |
|
177 | 177 | for (int j(0); j < columnCount; j++) { |
|
178 | 178 | QList <qreal> newColumn; |
|
179 | 179 | for (int i(0); i < rowCount; i++) { |
|
180 | 180 | if (dataCharacteristics == "Sin") { |
|
181 | 181 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
182 | 182 | } else if (dataCharacteristics == "Sin + random") { |
|
183 | 183 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
184 | 184 | } else if (dataCharacteristics == "Random") { |
|
185 | 185 | newColumn.append(rand() % 5); |
|
186 | 186 | } else if (dataCharacteristics == "Linear") { |
|
187 | 187 | //newColumn.append(i * (j + 1.0)); |
|
188 | 188 | // TODO: temporary hack to make pie work; prevent zero values: |
|
189 | 189 | newColumn.append(i * (j + 1.0) + 0.1); |
|
190 | 190 | } else { // "constant" |
|
191 | 191 | newColumn.append((j + 1.0)); |
|
192 | 192 | } |
|
193 | 193 | } |
|
194 | 194 | testData.append(newColumn); |
|
195 | 195 | } |
|
196 | 196 | return testData; |
|
197 | 197 | } |
|
198 | 198 | |
|
199 | 199 | QStringList MainWidget::generateLabels(int count) |
|
200 | 200 | { |
|
201 | 201 | QStringList result; |
|
202 | 202 | for (int i(0); i < count; i++) |
|
203 | 203 | result.append("label" + QString::number(i)); |
|
204 | 204 | return result; |
|
205 | 205 | } |
|
206 | 206 | |
|
207 | 207 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) |
|
208 | 208 | { |
|
209 | 209 | qDebug() << "addSeries: " << seriesName |
|
210 | 210 | << " columnCount: " << columnCount |
|
211 | 211 | << " rowCount: " << rowCount |
|
212 | 212 | << " dataCharacteristics: " << dataCharacteristics |
|
213 | 213 | << " labels enabled: " << labelsEnabled; |
|
214 | 214 | m_defaultSeriesName = seriesName; |
|
215 | 215 | |
|
216 | 216 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); |
|
217 | 217 | |
|
218 | 218 | // Line series and scatter series use similar data |
|
219 | 219 | if (seriesName.contains("line", Qt::CaseInsensitive)) { |
|
220 | 220 | for (int j(0); j < data.count(); j ++) { |
|
221 | 221 | QList<qreal> column = data.at(j); |
|
222 |
QLine |
|
|
222 | QLineSeries *series = new QLineSeries(); | |
|
223 | 223 | for (int i(0); i < column.count(); i++) { |
|
224 | 224 | series->add(i, column.at(i)); |
|
225 | 225 | } |
|
226 | 226 | m_chartWidget->addSeries(series); |
|
227 | 227 | setCurrentSeries(series); |
|
228 | 228 | } |
|
229 | 229 | } else if (seriesName.contains("scatter", Qt::CaseInsensitive)) { |
|
230 | 230 | for (int j(0); j < data.count(); j++) { |
|
231 | 231 | QList<qreal> column = data.at(j); |
|
232 | 232 | QScatterSeries *series = new QScatterSeries(); |
|
233 | 233 | for (int i(0); i < column.count(); i++) { |
|
234 | 234 | (*series) << QPointF(i, column.at(i)); |
|
235 | 235 | } |
|
236 | 236 | m_chartWidget->addSeries(series); |
|
237 | 237 | setCurrentSeries(series); |
|
238 | 238 | } |
|
239 | 239 | } else if (seriesName.contains("pie", Qt::CaseInsensitive)) { |
|
240 | 240 | QStringList labels = generateLabels(rowCount); |
|
241 | 241 | for (int j(0); j < data.count(); j++) { |
|
242 | 242 | QPieSeries *series = new QPieSeries(); |
|
243 | 243 | QList<qreal> column = data.at(j); |
|
244 | 244 | for (int i(0); i < column.count(); i++) { |
|
245 | 245 | series->add(column.at(i), labels.at(i)); |
|
246 | 246 | } |
|
247 | 247 | m_chartWidget->addSeries(series); |
|
248 | 248 | setCurrentSeries(series); |
|
249 | 249 | } |
|
250 | 250 | } else if (seriesName == "Bar" |
|
251 | 251 | || seriesName == "Stacked bar" |
|
252 | 252 | || seriesName == "Percent bar") { |
|
253 | 253 | // TODO: replace QBarCategory with QStringList? |
|
254 | 254 | QBarCategory *category = new QBarCategory; |
|
255 | 255 | QStringList labels = generateLabels(rowCount); |
|
256 | 256 | foreach(QString label, labels) |
|
257 | 257 | *category << label; |
|
258 | 258 | QBarSeries* series = 0; |
|
259 | 259 | if (seriesName == "Bar") |
|
260 | 260 | series = new QBarSeries(category, this); |
|
261 | 261 | else if (seriesName == "Stacked bar") |
|
262 | 262 | series = new QStackedBarSeries(category, this); |
|
263 | 263 | else |
|
264 | 264 | series = new QPercentBarSeries(category, this); |
|
265 | 265 | |
|
266 | 266 | for (int j(0); j < data.count(); j++) { |
|
267 | 267 | QList<qreal> column = data.at(j); |
|
268 | 268 | QBarSet *set = new QBarSet("set" + QString::number(j)); |
|
269 | 269 | for (int i(0); i < column.count(); i++) { |
|
270 | 270 | *set << column.at(i); |
|
271 | 271 | } |
|
272 | 272 | series->addBarSet(set); |
|
273 | 273 | } |
|
274 | 274 | series->enableFloatingValues(); |
|
275 | 275 | series->enableToolTip(); |
|
276 | 276 | series->enableSeparators(false); |
|
277 | 277 | m_chartWidget->addSeries(series); |
|
278 | 278 | setCurrentSeries(series); |
|
279 | 279 | } |
|
280 | 280 | |
|
281 | 281 | // TODO: spline and area |
|
282 | 282 | } |
|
283 | 283 | |
|
284 | 284 | void MainWidget::setCurrentSeries(QChartSeries *series) |
|
285 | 285 | { |
|
286 | 286 | if (series) { |
|
287 | 287 | m_currentSeries = series; |
|
288 | 288 | switch (m_currentSeries->type()) { |
|
289 | 289 | case QChartSeries::SeriesTypeLine: |
|
290 | 290 | break; |
|
291 | 291 | case QChartSeries::SeriesTypeScatter: |
|
292 | 292 | break; |
|
293 | 293 | case QChartSeries::SeriesTypePie: |
|
294 | 294 | break; |
|
295 | 295 | case QChartSeries::SeriesTypeBar: |
|
296 | 296 | qDebug() << "setCurrentSeries (bar)"; |
|
297 | 297 | break; |
|
298 | 298 | case QChartSeries::SeriesTypeStackedBar: |
|
299 | 299 | qDebug() << "setCurrentSeries (Stackedbar)"; |
|
300 | 300 | break; |
|
301 | 301 | case QChartSeries::SeriesTypePercentBar: |
|
302 | 302 | qDebug() << "setCurrentSeries (Percentbar)"; |
|
303 | 303 | break; |
|
304 | 304 | default: |
|
305 | 305 | Q_ASSERT(false); |
|
306 | 306 | break; |
|
307 | 307 | } |
|
308 | 308 | } |
|
309 | 309 | } |
|
310 | 310 | |
|
311 | 311 | void MainWidget::backgroundChanged(int itemIndex) |
|
312 | 312 | { |
|
313 | 313 | qDebug() << "backgroundChanged: " << itemIndex; |
|
314 | 314 | } |
|
315 | 315 | |
|
316 | 316 | void MainWidget::autoScaleChanged(int value) |
|
317 | 317 | { |
|
318 | 318 | if (value) { |
|
319 | 319 | // TODO: enable auto scaling |
|
320 | 320 | } else { |
|
321 | 321 | // TODO: set scaling manually (and disable auto scaling) |
|
322 | 322 | } |
|
323 | 323 | |
|
324 | 324 | m_xMinSpin->setEnabled(!value); |
|
325 | 325 | m_xMaxSpin->setEnabled(!value); |
|
326 | 326 | m_yMinSpin->setEnabled(!value); |
|
327 | 327 | m_yMaxSpin->setEnabled(!value); |
|
328 | 328 | } |
|
329 | 329 | |
|
330 | 330 | void MainWidget::xMinChanged(int value) |
|
331 | 331 | { |
|
332 | 332 | qDebug() << "xMinChanged: " << value; |
|
333 | 333 | } |
|
334 | 334 | |
|
335 | 335 | void MainWidget::xMaxChanged(int value) |
|
336 | 336 | { |
|
337 | 337 | qDebug() << "xMaxChanged: " << value; |
|
338 | 338 | } |
|
339 | 339 | |
|
340 | 340 | void MainWidget::yMinChanged(int value) |
|
341 | 341 | { |
|
342 | 342 | qDebug() << "yMinChanged: " << value; |
|
343 | 343 | } |
|
344 | 344 | |
|
345 | 345 | void MainWidget::yMaxChanged(int value) |
|
346 | 346 | { |
|
347 | 347 | qDebug() << "yMaxChanged: " << value; |
|
348 | 348 | } |
|
349 | 349 | |
|
350 | 350 | void MainWidget::changeChartTheme(int themeIndex) |
|
351 | 351 | { |
|
352 | 352 | qDebug() << "changeChartTheme: " << themeIndex; |
|
353 | 353 | m_chartWidget->setChartTheme((QChart::ChartTheme) themeIndex); |
|
354 | 354 | //TODO: remove this hack. This is just to make it so that theme change is seen immediately. |
|
355 | 355 | QSize s = size(); |
|
356 | 356 | s.setWidth(s.width()+1); |
|
357 | 357 | resize(s); |
|
358 | 358 | } |
|
359 | 359 | |
|
360 | 360 | void MainWidget::setPieSizeFactor(double size) |
|
361 | 361 | { |
|
362 | 362 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); |
|
363 | 363 | if (pie) |
|
364 | 364 | pie->setSizeFactor(qreal(size)); |
|
365 | 365 | } |
|
366 | 366 | |
|
367 | 367 | void MainWidget::setPiePosition(int position) |
|
368 | 368 | { |
|
369 | 369 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); |
|
370 | 370 | if (pie) |
|
371 | 371 | pie->setPosition((QPieSeries::PiePosition) position); |
|
372 | 372 | } |
General Comments 0
You need to be logged in to leave comments.
Login now