##// END OF EJS Templates
Fix issues based on android testing...
Miikka Heikkinen -
r2826:78282651dc64
parent child
Show More
@@ -1,118 +1,119
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd
3 ** Copyright (C) 2015 The Qt Company Ltd
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to The Qt Company, please use contact form at http://qt.io
5 ** For any questions to The Qt Company, please use contact form at http://qt.io
6 **
6 **
7 ** This file is part of the Qt Charts module.
7 ** This file is part of the Qt Charts module.
8 **
8 **
9 ** Licensees holding valid commercial license for Qt may use this file in
9 ** Licensees holding valid commercial license for Qt may use this file in
10 ** accordance with the Qt License Agreement provided with the Software
10 ** accordance with the Qt License Agreement provided with the Software
11 ** or, alternatively, in accordance with the terms contained in a written
11 ** or, alternatively, in accordance with the terms contained in a written
12 ** agreement between you and The Qt Company.
12 ** agreement between you and The Qt Company.
13 **
13 **
14 ** If you have questions regarding the use of this file, please use
14 ** If you have questions regarding the use of this file, please use
15 ** contact form at http://qt.io
15 ** contact form at http://qt.io
16 **
16 **
17 ****************************************************************************/
17 ****************************************************************************/
18
18
19 #include "datasource.h"
19 #include "datasource.h"
20 #include <QtCore/QtMath>
20 #include <QtCore/QtMath>
21
21
22 QT_CHARTS_USE_NAMESPACE
22 QT_CHARTS_USE_NAMESPACE
23
23
24 DataSource::DataSource(QObject *parent) :
24 DataSource::DataSource(QObject *parent) :
25 QObject(parent),
25 QObject(parent),
26 m_index(-1)
26 m_index(-1)
27 {
27 {
28 generateData(0, 0, 0);
28 generateData(0, 0, 0);
29 }
29 }
30
30
31 void DataSource::update(QAbstractSeries *series, int seriesIndex)
31 void DataSource::update(QAbstractSeries *series, int seriesIndex)
32 {
32 {
33 if (series) {
33 if (series) {
34 QXYSeries *xySeries = static_cast<QXYSeries *>(series);
34 QXYSeries *xySeries = static_cast<QXYSeries *>(series);
35 const QVector<QVector<QPointF> > &seriesData = m_data.at(seriesIndex);
35 const QVector<QVector<QPointF> > &seriesData = m_data.at(seriesIndex);
36 if (seriesIndex == 0)
36 if (seriesIndex == 0)
37 m_index++;
37 m_index++;
38 if (m_index > seriesData.count() - 1)
38 if (m_index > seriesData.count() - 1)
39 m_index = 0;
39 m_index = 0;
40
40
41 QVector<QPointF> points = seriesData.at(m_index);
41 QVector<QPointF> points = seriesData.at(m_index);
42 // Use replace instead of clear + append, it's optimized for performance
42 // Use replace instead of clear + append, it's optimized for performance
43 xySeries->replace(points);
43 xySeries->replace(points);
44 }
44 }
45 }
45 }
46
46
47 void DataSource::handleSceneChanged()
47 void DataSource::handleSceneChanged()
48 {
48 {
49 m_dataUpdater.start();
49 m_dataUpdater.start();
50 }
50 }
51
51
52 void DataSource::updateAllSeries()
52 void DataSource::updateAllSeries()
53 {
53 {
54 static int frameCount = 0;
54 static int frameCount = 0;
55 static QString labelText = QStringLiteral("FPS: %1");
55 static QString labelText = QStringLiteral("FPS: %1");
56
56
57 for (int i = 0; i < m_seriesList.size(); i++)
57 for (int i = 0; i < m_seriesList.size(); i++)
58 update(m_seriesList[i], i);
58 update(m_seriesList[i], i);
59
59
60 frameCount++;
60 frameCount++;
61 int elapsed = m_fpsTimer.elapsed();
61 int elapsed = m_fpsTimer.elapsed();
62 if (elapsed >= 1000) {
62 if (elapsed >= 1000) {
63 elapsed = m_fpsTimer.restart();
63 elapsed = m_fpsTimer.restart();
64 qreal fps = qreal(0.1 * int(10000.0 * (qreal(frameCount) / qreal(elapsed))));
64 qreal fps = qreal(0.1 * int(10000.0 * (qreal(frameCount) / qreal(elapsed))));
65 m_fpsLabel->setText(labelText.arg(QString::number(fps, 'f', 1)));
65 m_fpsLabel->setText(labelText.arg(QString::number(fps, 'f', 1)));
66 m_fpsLabel->adjustSize();
66 frameCount = 0;
67 frameCount = 0;
67 }
68 }
68 }
69 }
69
70
70 void DataSource::startUpdates(const QList<QXYSeries *> &seriesList, QLabel *fpsLabel)
71 void DataSource::startUpdates(const QList<QXYSeries *> &seriesList, QLabel *fpsLabel)
71 {
72 {
72 m_seriesList = seriesList;
73 m_seriesList = seriesList;
73 m_fpsLabel = fpsLabel;
74 m_fpsLabel = fpsLabel;
74
75
75 m_dataUpdater.setInterval(0);
76 m_dataUpdater.setInterval(0);
76 m_dataUpdater.setSingleShot(true);
77 m_dataUpdater.setSingleShot(true);
77 QObject::connect(&m_dataUpdater, &QTimer::timeout,
78 QObject::connect(&m_dataUpdater, &QTimer::timeout,
78 this, &DataSource::updateAllSeries);
79 this, &DataSource::updateAllSeries);
79
80
80 m_fpsTimer.start();
81 m_fpsTimer.start();
81 updateAllSeries();
82 updateAllSeries();
82 }
83 }
83
84
84 void DataSource::generateData(int seriesCount, int rowCount, int colCount)
85 void DataSource::generateData(int seriesCount, int rowCount, int colCount)
85 {
86 {
86 // Remove previous data
87 // Remove previous data
87 foreach (QVector<QVector<QPointF> > seriesData, m_data) {
88 foreach (QVector<QVector<QPointF> > seriesData, m_data) {
88 foreach (QVector<QPointF> row, seriesData)
89 foreach (QVector<QPointF> row, seriesData)
89 row.clear();
90 row.clear();
90 }
91 }
91
92
92 m_data.clear();
93 m_data.clear();
93
94
94 qreal xAdjustment = 20.0 / (colCount * rowCount);
95 qreal xAdjustment = 20.0 / (colCount * rowCount);
95 qreal yMultiplier = 3.0 / qreal(seriesCount);
96 qreal yMultiplier = 3.0 / qreal(seriesCount);
96
97
97 // Append the new data depending on the type
98 // Append the new data depending on the type
98 for (int k(0); k < seriesCount; k++) {
99 for (int k(0); k < seriesCount; k++) {
99 QVector<QVector<QPointF> > seriesData;
100 QVector<QVector<QPointF> > seriesData;
100 qreal height = qreal(k) * (10.0 / qreal(seriesCount)) + 0.3;
101 qreal height = qreal(k) * (10.0 / qreal(seriesCount)) + 0.3;
101 for (int i(0); i < rowCount; i++) {
102 for (int i(0); i < rowCount; i++) {
102 QVector<QPointF> points;
103 QVector<QPointF> points;
103 points.reserve(colCount);
104 points.reserve(colCount);
104 for (int j(0); j < colCount; j++) {
105 for (int j(0); j < colCount; j++) {
105 qreal x(0);
106 qreal x(0);
106 qreal y(0);
107 qreal y(0);
107 // data with sin + random component
108 // data with sin + random component
108 y = height + (yMultiplier * qSin(3.14159265358979 / 50 * j)
109 y = height + (yMultiplier * qSin(3.14159265358979 / 50 * j)
109 + (yMultiplier * (qreal) rand() / (qreal) RAND_MAX));
110 + (yMultiplier * (qreal) rand() / (qreal) RAND_MAX));
110 // 0.000001 added to make values logaxis compatible
111 // 0.000001 added to make values logaxis compatible
111 x = 0.000001 + 20.0 * (qreal(j) / qreal(colCount)) + (xAdjustment * qreal(i));
112 x = 0.000001 + 20.0 * (qreal(j) / qreal(colCount)) + (xAdjustment * qreal(i));
112 points.append(QPointF(x, y));
113 points.append(QPointF(x, y));
113 }
114 }
114 seriesData.append(points);
115 seriesData.append(points);
115 }
116 }
116 m_data.append(seriesData);
117 m_data.append(seriesData);
117 }
118 }
118 }
119 }
@@ -1,167 +1,168
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd
3 ** Copyright (C) 2015 The Qt Company Ltd
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to The Qt Company, please use contact form at http://qt.io
5 ** For any questions to The Qt Company, please use contact form at http://qt.io
6 **
6 **
7 ** This file is part of the Qt Charts module.
7 ** This file is part of the Qt Charts module.
8 **
8 **
9 ** Licensees holding valid commercial license for Qt may use this file in
9 ** Licensees holding valid commercial license for Qt may use this file in
10 ** accordance with the Qt License Agreement provided with the Software
10 ** accordance with the Qt License Agreement provided with the Software
11 ** or, alternatively, in accordance with the terms contained in a written
11 ** or, alternatively, in accordance with the terms contained in a written
12 ** agreement between you and The Qt Company.
12 ** agreement between you and The Qt Company.
13 **
13 **
14 ** If you have questions regarding the use of this file, please use
14 ** If you have questions regarding the use of this file, please use
15 ** contact form at http://qt.io
15 ** contact form at http://qt.io
16 **
16 **
17 ****************************************************************************/
17 ****************************************************************************/
18
18
19 #include "datasource.h"
19 #include "datasource.h"
20 #include <QtWidgets/QApplication>
20 #include <QtWidgets/QApplication>
21 #include <QtWidgets/QMainWindow>
21 #include <QtWidgets/QMainWindow>
22 #include <QtCharts/QChartView>
22 #include <QtCharts/QChartView>
23 #include <QtCharts/QLineSeries>
23 #include <QtCharts/QLineSeries>
24 #include <QtCharts/QScatterSeries>
24 #include <QtCharts/QScatterSeries>
25 #include <QtCharts/QValueAxis>
25 #include <QtCharts/QValueAxis>
26 #include <QtCharts/QLogValueAxis>
26 #include <QtCharts/QLogValueAxis>
27 #include <QtWidgets/QLabel>
27 #include <QtWidgets/QLabel>
28
28
29 // Uncomment to use logarithmic axes instead of regular value axes
29 // Uncomment to use logarithmic axes instead of regular value axes
30 //#define USE_LOG_AXIS
30 //#define USE_LOG_AXIS
31
31
32 // Uncomment to use regular series instead of OpenGL accelerated series
32 // Uncomment to use regular series instead of OpenGL accelerated series
33 //#define DONT_USE_GL_SERIES
33 //#define DONT_USE_GL_SERIES
34
34
35 // Uncomment to add a simple regular series (thick line) and a matching OpenGL series (thinner line)
35 // Uncomment to add a simple regular series (thick line) and a matching OpenGL series (thinner line)
36 // to verify the series have same visible geometry.
36 // to verify the series have same visible geometry.
37 //#define ADD_SIMPLE_SERIES
37 //#define ADD_SIMPLE_SERIES
38
38
39 QT_CHARTS_USE_NAMESPACE
39 QT_CHARTS_USE_NAMESPACE
40
40
41 int main(int argc, char *argv[])
41 int main(int argc, char *argv[])
42 {
42 {
43 QApplication a(argc, argv);
43 QApplication a(argc, argv);
44 QStringList colors;
44 QStringList colors;
45 colors << "red" << "blue" << "green" << "black";
45 colors << "red" << "blue" << "green" << "black";
46
46
47 QChart *chart = new QChart();
47 QChart *chart = new QChart();
48 chart->legend()->hide();
48 chart->legend()->hide();
49
49
50 #ifdef USE_LOG_AXIS
50 #ifdef USE_LOG_AXIS
51 QLogValueAxis *axisX = new QLogValueAxis;
51 QLogValueAxis *axisX = new QLogValueAxis;
52 QLogValueAxis *axisY = new QLogValueAxis;
52 QLogValueAxis *axisY = new QLogValueAxis;
53 #else
53 #else
54 QValueAxis *axisX = new QValueAxis;
54 QValueAxis *axisX = new QValueAxis;
55 QValueAxis *axisY = new QValueAxis;
55 QValueAxis *axisY = new QValueAxis;
56 #endif
56 #endif
57
57
58 chart->addAxis(axisX, Qt::AlignBottom);
58 chart->addAxis(axisX, Qt::AlignBottom);
59 chart->addAxis(axisY, Qt::AlignLeft);
59 chart->addAxis(axisY, Qt::AlignLeft);
60
60
61 const int seriesCount = 10;
61 const int seriesCount = 10;
62 #ifdef DONT_USE_GL_SERIES
62 #ifdef DONT_USE_GL_SERIES
63 const int pointCount = 100;
63 const int pointCount = 100;
64 chart->setTitle("Unaccelerated Series");
64 chart->setTitle("Unaccelerated Series");
65 #else
65 #else
66 const int pointCount = 10000;
66 const int pointCount = 10000;
67 chart->setTitle("OpenGL Accelerated Series");
67 chart->setTitle("OpenGL Accelerated Series");
68 #endif
68 #endif
69
69
70 QList<QXYSeries *> seriesList;
70 QList<QXYSeries *> seriesList;
71 for (int i = 0; i < seriesCount; i++) {
71 for (int i = 0; i < seriesCount; i++) {
72 QXYSeries *series = 0;
72 QXYSeries *series = 0;
73 int colorIndex = i % colors.size();
73 int colorIndex = i % colors.size();
74 if (i % 2) {
74 if (i % 2) {
75 series = new QScatterSeries;
75 series = new QScatterSeries;
76 QScatterSeries *scatter = static_cast<QScatterSeries *>(series);
76 QScatterSeries *scatter = static_cast<QScatterSeries *>(series);
77 scatter->setColor(QColor(colors.at(colorIndex)));
77 scatter->setColor(QColor(colors.at(colorIndex)));
78 scatter->setMarkerSize(qreal(colorIndex + 2) / 2.0);
78 scatter->setMarkerSize(qreal(colorIndex + 2) / 2.0);
79 // Scatter pen doesn't have affect in OpenGL drawing, but if you disable OpenGL drawing
79 // Scatter pen doesn't have affect in OpenGL drawing, but if you disable OpenGL drawing
80 // this makes the marker border visible and gives comparable marker size to OpenGL
80 // this makes the marker border visible and gives comparable marker size to OpenGL
81 // scatter points.
81 // scatter points.
82 scatter->setPen(QPen("black"));
82 scatter->setPen(QPen("black"));
83 } else {
83 } else {
84 series = new QLineSeries;
84 series = new QLineSeries;
85 series->setPen(QPen(QBrush(QColor(colors.at(colorIndex))),
85 series->setPen(QPen(QBrush(QColor(colors.at(colorIndex))),
86 qreal(colorIndex + 2) / 2.0));
86 qreal(colorIndex + 2) / 2.0));
87 }
87 }
88 seriesList.append(series);
88 seriesList.append(series);
89 #ifdef DONT_USE_GL_SERIES
89 #ifdef DONT_USE_GL_SERIES
90 series->setUseOpenGL(false);
90 series->setUseOpenGL(false);
91 #else
91 #else
92 //![1]
92 //![1]
93 series->setUseOpenGL(true);
93 series->setUseOpenGL(true);
94 //![1]
94 //![1]
95 #endif
95 #endif
96 chart->addSeries(series);
96 chart->addSeries(series);
97 series->attachAxis(axisX);
97 series->attachAxis(axisX);
98 series->attachAxis(axisY);
98 series->attachAxis(axisY);
99 }
99 }
100
100
101 if (axisX->type() == QAbstractAxis::AxisTypeLogValue)
101 if (axisX->type() == QAbstractAxis::AxisTypeLogValue)
102 axisX->setRange(0.1, 20.0);
102 axisX->setRange(0.1, 20.0);
103 else
103 else
104 axisX->setRange(0, 20.0);
104 axisX->setRange(0, 20.0);
105
105
106 if (axisY->type() == QAbstractAxis::AxisTypeLogValue)
106 if (axisY->type() == QAbstractAxis::AxisTypeLogValue)
107 axisY->setRange(0.1, 10.0);
107 axisY->setRange(0.1, 10.0);
108 else
108 else
109 axisY->setRange(0, 10.0);
109 axisY->setRange(0, 10.0);
110
110
111 #ifdef ADD_SIMPLE_SERIES
111 #ifdef ADD_SIMPLE_SERIES
112 QLineSeries *simpleRasterSeries = new QLineSeries;
112 QLineSeries *simpleRasterSeries = new QLineSeries;
113 *simpleRasterSeries << QPointF(0.001, 0.001)
113 *simpleRasterSeries << QPointF(0.001, 0.001)
114 << QPointF(2.5, 8.0)
114 << QPointF(2.5, 8.0)
115 << QPointF(5.0, 4.0)
115 << QPointF(5.0, 4.0)
116 << QPointF(7.5, 9.0)
116 << QPointF(7.5, 9.0)
117 << QPointF(10.0, 0.001)
117 << QPointF(10.0, 0.001)
118 << QPointF(12.5, 2.0)
118 << QPointF(12.5, 2.0)
119 << QPointF(15.0, 1.0)
119 << QPointF(15.0, 1.0)
120 << QPointF(17.5, 6.0)
120 << QPointF(17.5, 6.0)
121 << QPointF(20.0, 10.0);
121 << QPointF(20.0, 10.0);
122 simpleRasterSeries->setUseOpenGL(false);
122 simpleRasterSeries->setUseOpenGL(false);
123 simpleRasterSeries->setPen(QPen(QBrush("magenta"), 8));
123 simpleRasterSeries->setPen(QPen(QBrush("magenta"), 8));
124 chart->addSeries(simpleRasterSeries);
124 chart->addSeries(simpleRasterSeries);
125 simpleRasterSeries->attachAxis(axisX);
125 simpleRasterSeries->attachAxis(axisX);
126 simpleRasterSeries->attachAxis(axisY);
126 simpleRasterSeries->attachAxis(axisY);
127
127
128 QLineSeries *simpleGLSeries = new QLineSeries;
128 QLineSeries *simpleGLSeries = new QLineSeries;
129 simpleGLSeries->setUseOpenGL(true);
129 simpleGLSeries->setUseOpenGL(true);
130 simpleGLSeries->setPen(QPen(QBrush("black"), 2));
130 simpleGLSeries->setPen(QPen(QBrush("black"), 2));
131 simpleGLSeries->replace(simpleRasterSeries->points());
131 simpleGLSeries->replace(simpleRasterSeries->points());
132 chart->addSeries(simpleGLSeries);
132 chart->addSeries(simpleGLSeries);
133 simpleGLSeries->attachAxis(axisX);
133 simpleGLSeries->attachAxis(axisX);
134 simpleGLSeries->attachAxis(axisY);
134 simpleGLSeries->attachAxis(axisY);
135 #endif
135 #endif
136
136
137 QChartView *chartView = new QChartView(chart);
137 QChartView *chartView = new QChartView(chart);
138
138
139 QMainWindow window;
139 QMainWindow window;
140 window.setCentralWidget(chartView);
140 window.setCentralWidget(chartView);
141 window.resize(600, 400);
141 window.resize(600, 400);
142 window.show();
142 window.show();
143
143
144 DataSource dataSource;
144 DataSource dataSource;
145 dataSource.generateData(seriesCount, 10, pointCount);
145 dataSource.generateData(seriesCount, 10, pointCount);
146
146
147 QLabel *fpsLabel = new QLabel(&window);
147 QLabel *fpsLabel = new QLabel(&window);
148 QLabel *countLabel = new QLabel(&window);
148 QLabel *countLabel = new QLabel(&window);
149 QString countText = QStringLiteral("Total point count: %1");
149 QString countText = QStringLiteral("Total point count: %1");
150 countLabel->setText(countText.arg(pointCount * seriesCount));
150 countLabel->setText(countText.arg(pointCount * seriesCount));
151 countLabel->resize(window.width(), countLabel->height());
151 countLabel->adjustSize();
152 fpsLabel->move(10,2);
152 fpsLabel->move(10, 2);
153 fpsLabel->adjustSize();
153 fpsLabel->raise();
154 fpsLabel->raise();
154 fpsLabel->show();
155 fpsLabel->show();
155 countLabel->move(10, 14);
156 countLabel->move(10, fpsLabel->height());
156 fpsLabel->raise();
157 fpsLabel->raise();
157 countLabel->show();
158 countLabel->show();
158
159
159 // We can get more than one changed event per frame, so do async update.
160 // We can get more than one changed event per frame, so do async update.
160 // This also allows the application to be responsive.
161 // This also allows the application to be responsive.
161 QObject::connect(chart->scene(), &QGraphicsScene::changed,
162 QObject::connect(chart->scene(), &QGraphicsScene::changed,
162 &dataSource, &DataSource::handleSceneChanged);
163 &dataSource, &DataSource::handleSceneChanged);
163
164
164 dataSource.startUpdates(seriesList, fpsLabel);
165 dataSource.startUpdates(seriesList, fpsLabel);
165
166
166 return a.exec();
167 return a.exec();
167 }
168 }
@@ -1,96 +1,96
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd
3 ** Copyright (C) 2015 The Qt Company Ltd
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to The Qt Company, please use contact form at http://qt.io
5 ** For any questions to The Qt Company, please use contact form at http://qt.io
6 **
6 **
7 ** This file is part of the Qt Charts module.
7 ** This file is part of the Qt Charts module.
8 **
8 **
9 ** Licensees holding valid commercial license for Qt may use this file in
9 ** Licensees holding valid commercial license for Qt may use this file in
10 ** accordance with the Qt License Agreement provided with the Software
10 ** accordance with the Qt License Agreement provided with the Software
11 ** or, alternatively, in accordance with the terms contained in a written
11 ** or, alternatively, in accordance with the terms contained in a written
12 ** agreement between you and The Qt Company.
12 ** agreement between you and The Qt Company.
13 **
13 **
14 ** If you have questions regarding the use of this file, please use
14 ** If you have questions regarding the use of this file, please use
15 ** contact form at http://qt.io
15 ** contact form at http://qt.io
16 **
16 **
17 ****************************************************************************/
17 ****************************************************************************/
18
18
19 import QtQuick 2.1
19 import QtQuick 2.1
20 import QtQuick.Layouts 1.0
20 import QtQuick.Layouts 1.0
21
21
22 ColumnLayout {
22 ColumnLayout {
23 property alias openGLButton: openGLButton
23 property alias openGLButton: openGLButton
24 spacing: 8
24 spacing: 8
25 Layout.fillHeight: true
25 Layout.fillHeight: true
26 signal animationsEnabled(bool enabled)
26 signal animationsEnabled(bool enabled)
27 signal seriesTypeChanged(string type)
27 signal seriesTypeChanged(string type)
28 signal refreshRateChanged(variant rate);
28 signal refreshRateChanged(variant rate);
29 signal signalSourceChanged(string source, int signalCount, int sampleCount);
29 signal signalSourceChanged(string source, int signalCount, int sampleCount);
30 signal antialiasingEnabled(bool enabled)
30 signal antialiasingEnabled(bool enabled)
31 signal openGlChanged(bool enabled)
31 signal openGlChanged(bool enabled)
32
32
33 Text {
33 Text {
34 text: "Scope"
34 text: "Scope"
35 font.pointSize: 18
35 font.pointSize: 18
36 color: "white"
36 color: "white"
37 }
37 }
38
38
39 MultiButton {
39 MultiButton {
40 id: openGLButton
40 id: openGLButton
41 text: "OpenGL: "
41 text: "OpenGL: "
42 items: ["false", "true"]
42 items: ["false", "true"]
43 currentSelection: 0
43 currentSelection: 0
44 onSelectionChanged: openGlChanged(currentSelection == 1);
44 onSelectionChanged: openGlChanged(currentSelection == 1);
45 }
45 }
46
46
47 MultiButton {
47 MultiButton {
48 text: "Graph: "
48 text: "Graph: "
49 items: ["line", "spline", "scatter"]
49 items: ["line", "spline", "scatter"]
50 currentSelection: 0
50 currentSelection: 0
51 onSelectionChanged: seriesTypeChanged(items[currentSelection]);
51 onSelectionChanged: seriesTypeChanged(items[currentSelection]);
52 }
52 }
53
53
54 MultiButton {
54 MultiButton {
55 id: signalSourceButton
55 id: signalSourceButton
56 text: "Source: "
56 text: "Source: "
57 items: ["sin", "linear"]
57 items: ["sin", "linear"]
58 currentSelection: 0
58 currentSelection: 0
59 onSelectionChanged: signalSourceChanged(
59 onSelectionChanged: signalSourceChanged(
60 selection,
60 selection,
61 5,
61 5,
62 sampleCountButton.items[sampleCountButton.currentSelection]);
62 sampleCountButton.items[sampleCountButton.currentSelection]);
63 }
63 }
64
64
65 MultiButton {
65 MultiButton {
66 id: sampleCountButton
66 id: sampleCountButton
67 text: "Samples: "
67 text: "Samples: "
68 items: [6, 128, 1024, 10000]
68 items: ["6", "128", "1024", "10000"]
69 currentSelection: 2
69 currentSelection: 2
70 onSelectionChanged: signalSourceChanged(
70 onSelectionChanged: signalSourceChanged(
71 signalSourceButton.items[signalSourceButton.currentSelection],
71 signalSourceButton.items[signalSourceButton.currentSelection],
72 5,
72 5,
73 selection);
73 selection);
74 }
74 }
75
75
76 MultiButton {
76 MultiButton {
77 text: "Refresh rate: "
77 text: "Refresh rate: "
78 items: [1, 24, 60, 100]
78 items: ["1", "24", "60"]
79 currentSelection: 2
79 currentSelection: 2
80 onSelectionChanged: refreshRateChanged(items[currentSelection]);
80 onSelectionChanged: refreshRateChanged(items[currentSelection]);
81 }
81 }
82
82
83 MultiButton {
83 MultiButton {
84 text: "Animations: "
84 text: "Animations: "
85 items: ["OFF", "ON"]
85 items: ["OFF", "ON"]
86 currentSelection: 0
86 currentSelection: 0
87 onSelectionChanged: animationsEnabled(currentSelection == 1);
87 onSelectionChanged: animationsEnabled(currentSelection == 1);
88 }
88 }
89
89
90 MultiButton {
90 MultiButton {
91 text: "Antialias: "
91 text: "Antialias: "
92 items: ["OFF", "ON"]
92 items: ["OFF", "ON"]
93 currentSelection: 0
93 currentSelection: 0
94 onSelectionChanged: antialiasingEnabled(currentSelection == 1);
94 onSelectionChanged: antialiasingEnabled(currentSelection == 1);
95 }
95 }
96 }
96 }
@@ -1,58 +1,59
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd
3 ** Copyright (C) 2015 The Qt Company Ltd
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to The Qt Company, please use contact form at http://qt.io
5 ** For any questions to The Qt Company, please use contact form at http://qt.io
6 **
6 **
7 ** This file is part of the Qt Charts module.
7 ** This file is part of the Qt Charts module.
8 **
8 **
9 ** Licensees holding valid commercial license for Qt may use this file in
9 ** Licensees holding valid commercial license for Qt may use this file in
10 ** accordance with the Qt License Agreement provided with the Software
10 ** accordance with the Qt License Agreement provided with the Software
11 ** or, alternatively, in accordance with the terms contained in a written
11 ** or, alternatively, in accordance with the terms contained in a written
12 ** agreement between you and The Qt Company.
12 ** agreement between you and The Qt Company.
13 **
13 **
14 ** If you have questions regarding the use of this file, please use
14 ** If you have questions regarding the use of this file, please use
15 ** contact form at http://qt.io
15 ** contact form at http://qt.io
16 **
16 **
17 ****************************************************************************/
17 ****************************************************************************/
18
18
19 #include <private/chartitem_p.h>
19 #include <private/chartitem_p.h>
20 #include <private/qabstractseries_p.h>
20 #include <private/qabstractseries_p.h>
21 #include <private/abstractdomain_p.h>
21 #include <private/abstractdomain_p.h>
22 #include <QtGui/QPainter>
22
23
23 QT_CHARTS_BEGIN_NAMESPACE
24 QT_CHARTS_BEGIN_NAMESPACE
24
25
25 ChartItem::ChartItem(QAbstractSeriesPrivate *series,QGraphicsItem* item):
26 ChartItem::ChartItem(QAbstractSeriesPrivate *series,QGraphicsItem* item):
26 ChartElement(item),
27 ChartElement(item),
27 m_validData(true),
28 m_validData(true),
28 m_series(series)
29 m_series(series)
29 {
30 {
30
31
31 }
32 }
32
33
33 AbstractDomain* ChartItem::domain() const
34 AbstractDomain* ChartItem::domain() const
34 {
35 {
35 return m_series->domain();
36 return m_series->domain();
36 }
37 }
37
38
38 void ChartItem::handleDomainUpdated()
39 void ChartItem::handleDomainUpdated()
39 {
40 {
40 qWarning() << __FUNCTION__<< "Slot not implemented";
41 qWarning() << __FUNCTION__<< "Slot not implemented";
41 }
42 }
42
43
43 void ChartItem::reversePainter(QPainter *painter, const QRectF &clipRect)
44 void ChartItem::reversePainter(QPainter *painter, const QRectF &clipRect)
44 {
45 {
45 if (m_series->reverseXAxis()) {
46 if (m_series->reverseXAxis()) {
46 painter->translate(clipRect.width(), 0);
47 painter->translate(clipRect.width(), 0);
47 painter->scale(-1, 1);
48 painter->scale(-1, 1);
48 }
49 }
49
50
50 if (m_series->reverseYAxis()) {
51 if (m_series->reverseYAxis()) {
51 painter->translate(0, clipRect.height());
52 painter->translate(0, clipRect.height());
52 painter->scale(1, -1);
53 painter->scale(1, -1);
53 }
54 }
54 }
55 }
55
56
56 #include "moc_chartitem_p.cpp"
57 #include "moc_chartitem_p.cpp"
57
58
58 QT_CHARTS_END_NAMESPACE
59 QT_CHARTS_END_NAMESPACE
@@ -1,569 +1,570
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd
3 ** Copyright (C) 2015 The Qt Company Ltd
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to The Qt Company, please use contact form at http://qt.io
5 ** For any questions to The Qt Company, please use contact form at http://qt.io
6 **
6 **
7 ** This file is part of the Qt Charts module.
7 ** This file is part of the Qt Charts module.
8 **
8 **
9 ** Licensees holding valid commercial license for Qt may use this file in
9 ** Licensees holding valid commercial license for Qt may use this file in
10 ** accordance with the Qt License Agreement provided with the Software
10 ** accordance with the Qt License Agreement provided with the Software
11 ** or, alternatively, in accordance with the terms contained in a written
11 ** or, alternatively, in accordance with the terms contained in a written
12 ** agreement between you and The Qt Company.
12 ** agreement between you and The Qt Company.
13 **
13 **
14 ** If you have questions regarding the use of this file, please use
14 ** If you have questions regarding the use of this file, please use
15 ** contact form at http://qt.io
15 ** contact form at http://qt.io
16 **
16 **
17 ****************************************************************************/
17 ****************************************************************************/
18 #include <private/chartpresenter_p.h>
18 #include <private/chartpresenter_p.h>
19 #include <QtCharts/QChart>
19 #include <QtCharts/QChart>
20 #include <private/chartitem_p.h>
20 #include <private/chartitem_p.h>
21 #include <private/qchart_p.h>
21 #include <private/qchart_p.h>
22 #include <QtCharts/QAbstractAxis>
22 #include <QtCharts/QAbstractAxis>
23 #include <private/qabstractaxis_p.h>
23 #include <private/qabstractaxis_p.h>
24 #include <private/chartdataset_p.h>
24 #include <private/chartdataset_p.h>
25 #include <private/chartanimation_p.h>
25 #include <private/chartanimation_p.h>
26 #include <private/qabstractseries_p.h>
26 #include <private/qabstractseries_p.h>
27 #include <QtCharts/QAreaSeries>
27 #include <QtCharts/QAreaSeries>
28 #include <private/chartaxiselement_p.h>
28 #include <private/chartaxiselement_p.h>
29 #include <private/chartbackground_p.h>
29 #include <private/chartbackground_p.h>
30 #include <private/cartesianchartlayout_p.h>
30 #include <private/cartesianchartlayout_p.h>
31 #include <private/polarchartlayout_p.h>
31 #include <private/polarchartlayout_p.h>
32 #include <private/charttitle_p.h>
32 #include <private/charttitle_p.h>
33 #include <QtCore/QTimer>
33 #include <QtCore/QTimer>
34 #include <QtGui/QTextDocument>
34 #include <QtGui/QTextDocument>
35 #include <QtWidgets/QGraphicsScene>
35
36
36 QT_CHARTS_BEGIN_NAMESPACE
37 QT_CHARTS_BEGIN_NAMESPACE
37
38
38 ChartPresenter::ChartPresenter(QChart *chart, QChart::ChartType type)
39 ChartPresenter::ChartPresenter(QChart *chart, QChart::ChartType type)
39 : QObject(chart),
40 : QObject(chart),
40 m_chart(chart),
41 m_chart(chart),
41 m_options(QChart::NoAnimation),
42 m_options(QChart::NoAnimation),
42 m_animationDuration(ChartAnimationDuration),
43 m_animationDuration(ChartAnimationDuration),
43 m_animationCurve(QEasingCurve::OutQuart),
44 m_animationCurve(QEasingCurve::OutQuart),
44 m_state(ShowState),
45 m_state(ShowState),
45 m_background(0),
46 m_background(0),
46 m_plotAreaBackground(0),
47 m_plotAreaBackground(0),
47 m_title(0),
48 m_title(0),
48 m_localizeNumbers(false)
49 m_localizeNumbers(false)
49 #ifndef QT_NO_OPENGL
50 #ifndef QT_NO_OPENGL
50 , m_glWidget(0)
51 , m_glWidget(0)
51 , m_glUseWidget(true)
52 , m_glUseWidget(true)
52 #endif
53 #endif
53 {
54 {
54 if (type == QChart::ChartTypeCartesian)
55 if (type == QChart::ChartTypeCartesian)
55 m_layout = new CartesianChartLayout(this);
56 m_layout = new CartesianChartLayout(this);
56 else if (type == QChart::ChartTypePolar)
57 else if (type == QChart::ChartTypePolar)
57 m_layout = new PolarChartLayout(this);
58 m_layout = new PolarChartLayout(this);
58 Q_ASSERT(m_layout);
59 Q_ASSERT(m_layout);
59 }
60 }
60
61
61 ChartPresenter::~ChartPresenter()
62 ChartPresenter::~ChartPresenter()
62 {
63 {
63 #ifndef QT_NO_OPENGL
64 #ifndef QT_NO_OPENGL
64 delete m_glWidget.data();
65 delete m_glWidget.data();
65 #endif
66 #endif
66 }
67 }
67
68
68 void ChartPresenter::setGeometry(const QRectF rect)
69 void ChartPresenter::setGeometry(const QRectF rect)
69 {
70 {
70 if (m_rect != rect) {
71 if (m_rect != rect) {
71 m_rect = rect;
72 m_rect = rect;
72 foreach (ChartItem *chart, m_chartItems) {
73 foreach (ChartItem *chart, m_chartItems) {
73 chart->domain()->setSize(rect.size());
74 chart->domain()->setSize(rect.size());
74 chart->setPos(rect.topLeft());
75 chart->setPos(rect.topLeft());
75 }
76 }
76 #ifndef QT_NO_OPENGL
77 #ifndef QT_NO_OPENGL
77 if (!m_glWidget.isNull())
78 if (!m_glWidget.isNull())
78 m_glWidget->setGeometry(m_rect.toRect());
79 m_glWidget->setGeometry(m_rect.toRect());
79 #endif
80 #endif
80 emit plotAreaChanged(m_rect);
81 emit plotAreaChanged(m_rect);
81 }
82 }
82 }
83 }
83
84
84 QRectF ChartPresenter::geometry() const
85 QRectF ChartPresenter::geometry() const
85 {
86 {
86 return m_rect;
87 return m_rect;
87 }
88 }
88
89
89 void ChartPresenter::handleAxisAdded(QAbstractAxis *axis)
90 void ChartPresenter::handleAxisAdded(QAbstractAxis *axis)
90 {
91 {
91 axis->d_ptr->initializeGraphics(rootItem());
92 axis->d_ptr->initializeGraphics(rootItem());
92 axis->d_ptr->initializeAnimations(m_options, m_animationDuration, m_animationCurve);
93 axis->d_ptr->initializeAnimations(m_options, m_animationDuration, m_animationCurve);
93 ChartAxisElement *item = axis->d_ptr->axisItem();
94 ChartAxisElement *item = axis->d_ptr->axisItem();
94 item->setPresenter(this);
95 item->setPresenter(this);
95 item->setThemeManager(m_chart->d_ptr->m_themeManager);
96 item->setThemeManager(m_chart->d_ptr->m_themeManager);
96 m_axisItems<<item;
97 m_axisItems<<item;
97 m_axes<<axis;
98 m_axes<<axis;
98 m_layout->invalidate();
99 m_layout->invalidate();
99 }
100 }
100
101
101 void ChartPresenter::handleAxisRemoved(QAbstractAxis *axis)
102 void ChartPresenter::handleAxisRemoved(QAbstractAxis *axis)
102 {
103 {
103 ChartAxisElement *item = axis->d_ptr->m_item.take();
104 ChartAxisElement *item = axis->d_ptr->m_item.take();
104 item->hide();
105 item->hide();
105 item->disconnect();
106 item->disconnect();
106 item->deleteLater();
107 item->deleteLater();
107 m_axisItems.removeAll(item);
108 m_axisItems.removeAll(item);
108 m_axes.removeAll(axis);
109 m_axes.removeAll(axis);
109 m_layout->invalidate();
110 m_layout->invalidate();
110 }
111 }
111
112
112
113
113 void ChartPresenter::handleSeriesAdded(QAbstractSeries *series)
114 void ChartPresenter::handleSeriesAdded(QAbstractSeries *series)
114 {
115 {
115 series->d_ptr->initializeGraphics(rootItem());
116 series->d_ptr->initializeGraphics(rootItem());
116 series->d_ptr->initializeAnimations(m_options, m_animationDuration, m_animationCurve);
117 series->d_ptr->initializeAnimations(m_options, m_animationDuration, m_animationCurve);
117 series->d_ptr->setPresenter(this);
118 series->d_ptr->setPresenter(this);
118 ChartItem *chart = series->d_ptr->chartItem();
119 ChartItem *chart = series->d_ptr->chartItem();
119 chart->setPresenter(this);
120 chart->setPresenter(this);
120 chart->setThemeManager(m_chart->d_ptr->m_themeManager);
121 chart->setThemeManager(m_chart->d_ptr->m_themeManager);
121 chart->setDataSet(m_chart->d_ptr->m_dataset);
122 chart->setDataSet(m_chart->d_ptr->m_dataset);
122 chart->domain()->setSize(m_rect.size());
123 chart->domain()->setSize(m_rect.size());
123 chart->setPos(m_rect.topLeft());
124 chart->setPos(m_rect.topLeft());
124 chart->handleDomainUpdated(); //this could be moved to intializeGraphics when animator is refactored
125 chart->handleDomainUpdated(); //this could be moved to intializeGraphics when animator is refactored
125 m_chartItems<<chart;
126 m_chartItems<<chart;
126 m_series<<series;
127 m_series<<series;
127 m_layout->invalidate();
128 m_layout->invalidate();
128 }
129 }
129
130
130 void ChartPresenter::handleSeriesRemoved(QAbstractSeries *series)
131 void ChartPresenter::handleSeriesRemoved(QAbstractSeries *series)
131 {
132 {
132 ChartItem *chart = series->d_ptr->m_item.take();
133 ChartItem *chart = series->d_ptr->m_item.take();
133 chart->hide();
134 chart->hide();
134 chart->disconnect();
135 chart->disconnect();
135 chart->deleteLater();
136 chart->deleteLater();
136 if (chart->animation())
137 if (chart->animation())
137 chart->animation()->stopAndDestroyLater();
138 chart->animation()->stopAndDestroyLater();
138 m_chartItems.removeAll(chart);
139 m_chartItems.removeAll(chart);
139 m_series.removeAll(series);
140 m_series.removeAll(series);
140 m_layout->invalidate();
141 m_layout->invalidate();
141 }
142 }
142
143
143 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
144 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
144 {
145 {
145 if (m_options != options) {
146 if (m_options != options) {
146 QChart::AnimationOptions oldOptions = m_options;
147 QChart::AnimationOptions oldOptions = m_options;
147 m_options = options;
148 m_options = options;
148 if (options.testFlag(QChart::SeriesAnimations) != oldOptions.testFlag(QChart::SeriesAnimations)) {
149 if (options.testFlag(QChart::SeriesAnimations) != oldOptions.testFlag(QChart::SeriesAnimations)) {
149 foreach (QAbstractSeries *series, m_series)
150 foreach (QAbstractSeries *series, m_series)
150 series->d_ptr->initializeAnimations(m_options, m_animationDuration,
151 series->d_ptr->initializeAnimations(m_options, m_animationDuration,
151 m_animationCurve);
152 m_animationCurve);
152 }
153 }
153 if (options.testFlag(QChart::GridAxisAnimations) != oldOptions.testFlag(QChart::GridAxisAnimations)) {
154 if (options.testFlag(QChart::GridAxisAnimations) != oldOptions.testFlag(QChart::GridAxisAnimations)) {
154 foreach (QAbstractAxis *axis, m_axes)
155 foreach (QAbstractAxis *axis, m_axes)
155 axis->d_ptr->initializeAnimations(m_options, m_animationDuration, m_animationCurve);
156 axis->d_ptr->initializeAnimations(m_options, m_animationDuration, m_animationCurve);
156 }
157 }
157 m_layout->invalidate(); // So that existing animations don't just stop halfway
158 m_layout->invalidate(); // So that existing animations don't just stop halfway
158 }
159 }
159 }
160 }
160
161
161 void ChartPresenter::setAnimationDuration(int msecs)
162 void ChartPresenter::setAnimationDuration(int msecs)
162 {
163 {
163 if (m_animationDuration != msecs) {
164 if (m_animationDuration != msecs) {
164 m_animationDuration = msecs;
165 m_animationDuration = msecs;
165 foreach (QAbstractSeries *series, m_series)
166 foreach (QAbstractSeries *series, m_series)
166 series->d_ptr->initializeAnimations(m_options, m_animationDuration, m_animationCurve);
167 series->d_ptr->initializeAnimations(m_options, m_animationDuration, m_animationCurve);
167 foreach (QAbstractAxis *axis, m_axes)
168 foreach (QAbstractAxis *axis, m_axes)
168 axis->d_ptr->initializeAnimations(m_options, m_animationDuration, m_animationCurve);
169 axis->d_ptr->initializeAnimations(m_options, m_animationDuration, m_animationCurve);
169 m_layout->invalidate(); // So that existing animations don't just stop halfway
170 m_layout->invalidate(); // So that existing animations don't just stop halfway
170 }
171 }
171 }
172 }
172
173
173 void ChartPresenter::setAnimationEasingCurve(const QEasingCurve &curve)
174 void ChartPresenter::setAnimationEasingCurve(const QEasingCurve &curve)
174 {
175 {
175 if (m_animationCurve != curve) {
176 if (m_animationCurve != curve) {
176 m_animationCurve = curve;
177 m_animationCurve = curve;
177 foreach (QAbstractSeries *series, m_series)
178 foreach (QAbstractSeries *series, m_series)
178 series->d_ptr->initializeAnimations(m_options, m_animationDuration, m_animationCurve);
179 series->d_ptr->initializeAnimations(m_options, m_animationDuration, m_animationCurve);
179 foreach (QAbstractAxis *axis, m_axes)
180 foreach (QAbstractAxis *axis, m_axes)
180 axis->d_ptr->initializeAnimations(m_options, m_animationDuration, m_animationCurve);
181 axis->d_ptr->initializeAnimations(m_options, m_animationDuration, m_animationCurve);
181 m_layout->invalidate(); // So that existing animations don't just stop halfway
182 m_layout->invalidate(); // So that existing animations don't just stop halfway
182 }
183 }
183 }
184 }
184
185
185 void ChartPresenter::setState(State state,QPointF point)
186 void ChartPresenter::setState(State state,QPointF point)
186 {
187 {
187 m_state=state;
188 m_state=state;
188 m_statePoint=point;
189 m_statePoint=point;
189 }
190 }
190
191
191 QChart::AnimationOptions ChartPresenter::animationOptions() const
192 QChart::AnimationOptions ChartPresenter::animationOptions() const
192 {
193 {
193 return m_options;
194 return m_options;
194 }
195 }
195
196
196 void ChartPresenter::createBackgroundItem()
197 void ChartPresenter::createBackgroundItem()
197 {
198 {
198 if (!m_background) {
199 if (!m_background) {
199 m_background = new ChartBackground(rootItem());
200 m_background = new ChartBackground(rootItem());
200 m_background->setPen(Qt::NoPen); // Theme doesn't touch pen so don't use default
201 m_background->setPen(Qt::NoPen); // Theme doesn't touch pen so don't use default
201 m_background->setBrush(QChartPrivate::defaultBrush());
202 m_background->setBrush(QChartPrivate::defaultBrush());
202 m_background->setZValue(ChartPresenter::BackgroundZValue);
203 m_background->setZValue(ChartPresenter::BackgroundZValue);
203 }
204 }
204 }
205 }
205
206
206 void ChartPresenter::createPlotAreaBackgroundItem()
207 void ChartPresenter::createPlotAreaBackgroundItem()
207 {
208 {
208 if (!m_plotAreaBackground) {
209 if (!m_plotAreaBackground) {
209 if (m_chart->chartType() == QChart::ChartTypeCartesian)
210 if (m_chart->chartType() == QChart::ChartTypeCartesian)
210 m_plotAreaBackground = new QGraphicsRectItem(rootItem());
211 m_plotAreaBackground = new QGraphicsRectItem(rootItem());
211 else
212 else
212 m_plotAreaBackground = new QGraphicsEllipseItem(rootItem());
213 m_plotAreaBackground = new QGraphicsEllipseItem(rootItem());
213 // Use transparent pen instead of Qt::NoPen, as Qt::NoPen causes
214 // Use transparent pen instead of Qt::NoPen, as Qt::NoPen causes
214 // antialising artifacts with axis lines for some reason.
215 // antialising artifacts with axis lines for some reason.
215 m_plotAreaBackground->setPen(QPen(Qt::transparent));
216 m_plotAreaBackground->setPen(QPen(Qt::transparent));
216 m_plotAreaBackground->setBrush(Qt::NoBrush);
217 m_plotAreaBackground->setBrush(Qt::NoBrush);
217 m_plotAreaBackground->setZValue(ChartPresenter::PlotAreaZValue);
218 m_plotAreaBackground->setZValue(ChartPresenter::PlotAreaZValue);
218 m_plotAreaBackground->setVisible(false);
219 m_plotAreaBackground->setVisible(false);
219 }
220 }
220 }
221 }
221
222
222 void ChartPresenter::createTitleItem()
223 void ChartPresenter::createTitleItem()
223 {
224 {
224 if (!m_title) {
225 if (!m_title) {
225 m_title = new ChartTitle(rootItem());
226 m_title = new ChartTitle(rootItem());
226 m_title->setZValue(ChartPresenter::BackgroundZValue);
227 m_title->setZValue(ChartPresenter::BackgroundZValue);
227 }
228 }
228 }
229 }
229
230
230 void ChartPresenter::startAnimation(ChartAnimation *animation)
231 void ChartPresenter::startAnimation(ChartAnimation *animation)
231 {
232 {
232 animation->stop();
233 animation->stop();
233 QTimer::singleShot(0, animation, SLOT(startChartAnimation()));
234 QTimer::singleShot(0, animation, SLOT(startChartAnimation()));
234 }
235 }
235
236
236 void ChartPresenter::setBackgroundBrush(const QBrush &brush)
237 void ChartPresenter::setBackgroundBrush(const QBrush &brush)
237 {
238 {
238 createBackgroundItem();
239 createBackgroundItem();
239 m_background->setBrush(brush);
240 m_background->setBrush(brush);
240 m_layout->invalidate();
241 m_layout->invalidate();
241 }
242 }
242
243
243 QBrush ChartPresenter::backgroundBrush() const
244 QBrush ChartPresenter::backgroundBrush() const
244 {
245 {
245 if (!m_background)
246 if (!m_background)
246 return QBrush();
247 return QBrush();
247 return m_background->brush();
248 return m_background->brush();
248 }
249 }
249
250
250 void ChartPresenter::setBackgroundPen(const QPen &pen)
251 void ChartPresenter::setBackgroundPen(const QPen &pen)
251 {
252 {
252 createBackgroundItem();
253 createBackgroundItem();
253 m_background->setPen(pen);
254 m_background->setPen(pen);
254 m_layout->invalidate();
255 m_layout->invalidate();
255 }
256 }
256
257
257 QPen ChartPresenter::backgroundPen() const
258 QPen ChartPresenter::backgroundPen() const
258 {
259 {
259 if (!m_background)
260 if (!m_background)
260 return QPen();
261 return QPen();
261 return m_background->pen();
262 return m_background->pen();
262 }
263 }
263
264
264 void ChartPresenter::setBackgroundRoundness(qreal diameter)
265 void ChartPresenter::setBackgroundRoundness(qreal diameter)
265 {
266 {
266 createBackgroundItem();
267 createBackgroundItem();
267 m_background->setDiameter(diameter);
268 m_background->setDiameter(diameter);
268 m_layout->invalidate();
269 m_layout->invalidate();
269 }
270 }
270
271
271 qreal ChartPresenter::backgroundRoundness() const
272 qreal ChartPresenter::backgroundRoundness() const
272 {
273 {
273 if (!m_background)
274 if (!m_background)
274 return 0;
275 return 0;
275 return m_background->diameter();
276 return m_background->diameter();
276 }
277 }
277
278
278 void ChartPresenter::setPlotAreaBackgroundBrush(const QBrush &brush)
279 void ChartPresenter::setPlotAreaBackgroundBrush(const QBrush &brush)
279 {
280 {
280 createPlotAreaBackgroundItem();
281 createPlotAreaBackgroundItem();
281 m_plotAreaBackground->setBrush(brush);
282 m_plotAreaBackground->setBrush(brush);
282 m_layout->invalidate();
283 m_layout->invalidate();
283 }
284 }
284
285
285 QBrush ChartPresenter::plotAreaBackgroundBrush() const
286 QBrush ChartPresenter::plotAreaBackgroundBrush() const
286 {
287 {
287 if (!m_plotAreaBackground)
288 if (!m_plotAreaBackground)
288 return QBrush();
289 return QBrush();
289 return m_plotAreaBackground->brush();
290 return m_plotAreaBackground->brush();
290 }
291 }
291
292
292 void ChartPresenter::setPlotAreaBackgroundPen(const QPen &pen)
293 void ChartPresenter::setPlotAreaBackgroundPen(const QPen &pen)
293 {
294 {
294 createPlotAreaBackgroundItem();
295 createPlotAreaBackgroundItem();
295 m_plotAreaBackground->setPen(pen);
296 m_plotAreaBackground->setPen(pen);
296 m_layout->invalidate();
297 m_layout->invalidate();
297 }
298 }
298
299
299 QPen ChartPresenter::plotAreaBackgroundPen() const
300 QPen ChartPresenter::plotAreaBackgroundPen() const
300 {
301 {
301 if (!m_plotAreaBackground)
302 if (!m_plotAreaBackground)
302 return QPen();
303 return QPen();
303 return m_plotAreaBackground->pen();
304 return m_plotAreaBackground->pen();
304 }
305 }
305
306
306 void ChartPresenter::setTitle(const QString &title)
307 void ChartPresenter::setTitle(const QString &title)
307 {
308 {
308 createTitleItem();
309 createTitleItem();
309 m_title->setText(title);
310 m_title->setText(title);
310 m_layout->invalidate();
311 m_layout->invalidate();
311 }
312 }
312
313
313 QString ChartPresenter::title() const
314 QString ChartPresenter::title() const
314 {
315 {
315 if (!m_title)
316 if (!m_title)
316 return QString();
317 return QString();
317 return m_title->text();
318 return m_title->text();
318 }
319 }
319
320
320 void ChartPresenter::setTitleFont(const QFont &font)
321 void ChartPresenter::setTitleFont(const QFont &font)
321 {
322 {
322 createTitleItem();
323 createTitleItem();
323 m_title->setFont(font);
324 m_title->setFont(font);
324 m_layout->invalidate();
325 m_layout->invalidate();
325 }
326 }
326
327
327 QFont ChartPresenter::titleFont() const
328 QFont ChartPresenter::titleFont() const
328 {
329 {
329 if (!m_title)
330 if (!m_title)
330 return QFont();
331 return QFont();
331 return m_title->font();
332 return m_title->font();
332 }
333 }
333
334
334 void ChartPresenter::setTitleBrush(const QBrush &brush)
335 void ChartPresenter::setTitleBrush(const QBrush &brush)
335 {
336 {
336 createTitleItem();
337 createTitleItem();
337 m_title->setDefaultTextColor(brush.color());
338 m_title->setDefaultTextColor(brush.color());
338 m_layout->invalidate();
339 m_layout->invalidate();
339 }
340 }
340
341
341 QBrush ChartPresenter::titleBrush() const
342 QBrush ChartPresenter::titleBrush() const
342 {
343 {
343 if (!m_title)
344 if (!m_title)
344 return QBrush();
345 return QBrush();
345 return QBrush(m_title->defaultTextColor());
346 return QBrush(m_title->defaultTextColor());
346 }
347 }
347
348
348 void ChartPresenter::setBackgroundVisible(bool visible)
349 void ChartPresenter::setBackgroundVisible(bool visible)
349 {
350 {
350 createBackgroundItem();
351 createBackgroundItem();
351 m_background->setVisible(visible);
352 m_background->setVisible(visible);
352 }
353 }
353
354
354
355
355 bool ChartPresenter::isBackgroundVisible() const
356 bool ChartPresenter::isBackgroundVisible() const
356 {
357 {
357 if (!m_background)
358 if (!m_background)
358 return false;
359 return false;
359 return m_background->isVisible();
360 return m_background->isVisible();
360 }
361 }
361
362
362 void ChartPresenter::setPlotAreaBackgroundVisible(bool visible)
363 void ChartPresenter::setPlotAreaBackgroundVisible(bool visible)
363 {
364 {
364 createPlotAreaBackgroundItem();
365 createPlotAreaBackgroundItem();
365 m_plotAreaBackground->setVisible(visible);
366 m_plotAreaBackground->setVisible(visible);
366 }
367 }
367
368
368 bool ChartPresenter::isPlotAreaBackgroundVisible() const
369 bool ChartPresenter::isPlotAreaBackgroundVisible() const
369 {
370 {
370 if (!m_plotAreaBackground)
371 if (!m_plotAreaBackground)
371 return false;
372 return false;
372 return m_plotAreaBackground->isVisible();
373 return m_plotAreaBackground->isVisible();
373 }
374 }
374
375
375 void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled)
376 void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled)
376 {
377 {
377 createBackgroundItem();
378 createBackgroundItem();
378 m_background->setDropShadowEnabled(enabled);
379 m_background->setDropShadowEnabled(enabled);
379 }
380 }
380
381
381 bool ChartPresenter::isBackgroundDropShadowEnabled() const
382 bool ChartPresenter::isBackgroundDropShadowEnabled() const
382 {
383 {
383 if (!m_background)
384 if (!m_background)
384 return false;
385 return false;
385 return m_background->isDropShadowEnabled();
386 return m_background->isDropShadowEnabled();
386 }
387 }
387
388
388 void ChartPresenter::setLocalizeNumbers(bool localize)
389 void ChartPresenter::setLocalizeNumbers(bool localize)
389 {
390 {
390 m_localizeNumbers = localize;
391 m_localizeNumbers = localize;
391 m_layout->invalidate();
392 m_layout->invalidate();
392 }
393 }
393
394
394 void ChartPresenter::setLocale(const QLocale &locale)
395 void ChartPresenter::setLocale(const QLocale &locale)
395 {
396 {
396 m_locale = locale;
397 m_locale = locale;
397 m_layout->invalidate();
398 m_layout->invalidate();
398 }
399 }
399
400
400 AbstractChartLayout *ChartPresenter::layout()
401 AbstractChartLayout *ChartPresenter::layout()
401 {
402 {
402 return m_layout;
403 return m_layout;
403 }
404 }
404
405
405 QLegend *ChartPresenter::legend()
406 QLegend *ChartPresenter::legend()
406 {
407 {
407 return m_chart->legend();
408 return m_chart->legend();
408 }
409 }
409
410
410 void ChartPresenter::setVisible(bool visible)
411 void ChartPresenter::setVisible(bool visible)
411 {
412 {
412 m_chart->setVisible(visible);
413 m_chart->setVisible(visible);
413 }
414 }
414
415
415 ChartBackground *ChartPresenter::backgroundElement()
416 ChartBackground *ChartPresenter::backgroundElement()
416 {
417 {
417 return m_background;
418 return m_background;
418 }
419 }
419
420
420 QAbstractGraphicsShapeItem *ChartPresenter::plotAreaElement()
421 QAbstractGraphicsShapeItem *ChartPresenter::plotAreaElement()
421 {
422 {
422 return m_plotAreaBackground;
423 return m_plotAreaBackground;
423 }
424 }
424
425
425 QList<ChartAxisElement *> ChartPresenter::axisItems() const
426 QList<ChartAxisElement *> ChartPresenter::axisItems() const
426 {
427 {
427 return m_axisItems;
428 return m_axisItems;
428 }
429 }
429
430
430 QList<ChartItem *> ChartPresenter::chartItems() const
431 QList<ChartItem *> ChartPresenter::chartItems() const
431 {
432 {
432 return m_chartItems;
433 return m_chartItems;
433 }
434 }
434
435
435 ChartTitle *ChartPresenter::titleElement()
436 ChartTitle *ChartPresenter::titleElement()
436 {
437 {
437 return m_title;
438 return m_title;
438 }
439 }
439
440
440 QRectF ChartPresenter::textBoundingRect(const QFont &font, const QString &text, qreal angle)
441 QRectF ChartPresenter::textBoundingRect(const QFont &font, const QString &text, qreal angle)
441 {
442 {
442 static QGraphicsTextItem dummyTextItem;
443 static QGraphicsTextItem dummyTextItem;
443 static bool initMargin = true;
444 static bool initMargin = true;
444 if (initMargin) {
445 if (initMargin) {
445 dummyTextItem.document()->setDocumentMargin(textMargin());
446 dummyTextItem.document()->setDocumentMargin(textMargin());
446 initMargin = false;
447 initMargin = false;
447 }
448 }
448
449
449 dummyTextItem.setFont(font);
450 dummyTextItem.setFont(font);
450 dummyTextItem.setHtml(text);
451 dummyTextItem.setHtml(text);
451 QRectF boundingRect = dummyTextItem.boundingRect();
452 QRectF boundingRect = dummyTextItem.boundingRect();
452
453
453 // Take rotation into account
454 // Take rotation into account
454 if (angle) {
455 if (angle) {
455 QTransform transform;
456 QTransform transform;
456 transform.rotate(angle);
457 transform.rotate(angle);
457 boundingRect = transform.mapRect(boundingRect);
458 boundingRect = transform.mapRect(boundingRect);
458 }
459 }
459
460
460 return boundingRect;
461 return boundingRect;
461 }
462 }
462
463
463 // boundingRect parameter returns the rotated bounding rect of the text
464 // boundingRect parameter returns the rotated bounding rect of the text
464 QString ChartPresenter::truncatedText(const QFont &font, const QString &text, qreal angle,
465 QString ChartPresenter::truncatedText(const QFont &font, const QString &text, qreal angle,
465 qreal maxWidth, qreal maxHeight, QRectF &boundingRect)
466 qreal maxWidth, qreal maxHeight, QRectF &boundingRect)
466 {
467 {
467 QString truncatedString(text);
468 QString truncatedString(text);
468 boundingRect = textBoundingRect(font, truncatedString, angle);
469 boundingRect = textBoundingRect(font, truncatedString, angle);
469 if (boundingRect.width() > maxWidth || boundingRect.height() > maxHeight) {
470 if (boundingRect.width() > maxWidth || boundingRect.height() > maxHeight) {
470 // It can be assumed that almost any amount of string manipulation is faster
471 // It can be assumed that almost any amount of string manipulation is faster
471 // than calculating one bounding rectangle, so first prepare a list of truncated strings
472 // than calculating one bounding rectangle, so first prepare a list of truncated strings
472 // to try.
473 // to try.
473 static QRegExp truncateMatcher(QStringLiteral("&#?[0-9a-zA-Z]*;$"));
474 static QRegExp truncateMatcher(QStringLiteral("&#?[0-9a-zA-Z]*;$"));
474
475
475 QVector<QString> testStrings(text.length());
476 QVector<QString> testStrings(text.length());
476 int count(0);
477 int count(0);
477 static QLatin1Char closeTag('>');
478 static QLatin1Char closeTag('>');
478 static QLatin1Char openTag('<');
479 static QLatin1Char openTag('<');
479 static QLatin1Char semiColon(';');
480 static QLatin1Char semiColon(';');
480 static QLatin1String ellipsis("...");
481 static QLatin1String ellipsis("...");
481 while (truncatedString.length() > 1) {
482 while (truncatedString.length() > 1) {
482 int chopIndex(-1);
483 int chopIndex(-1);
483 int chopCount(1);
484 int chopCount(1);
484 QChar lastChar(truncatedString.at(truncatedString.length() - 1));
485 QChar lastChar(truncatedString.at(truncatedString.length() - 1));
485
486
486 if (lastChar == closeTag)
487 if (lastChar == closeTag)
487 chopIndex = truncatedString.lastIndexOf(openTag);
488 chopIndex = truncatedString.lastIndexOf(openTag);
488 else if (lastChar == semiColon)
489 else if (lastChar == semiColon)
489 chopIndex = truncateMatcher.indexIn(truncatedString, 0);
490 chopIndex = truncateMatcher.indexIn(truncatedString, 0);
490
491
491 if (chopIndex != -1)
492 if (chopIndex != -1)
492 chopCount = truncatedString.length() - chopIndex;
493 chopCount = truncatedString.length() - chopIndex;
493 truncatedString.chop(chopCount);
494 truncatedString.chop(chopCount);
494 testStrings[count] = truncatedString + ellipsis;
495 testStrings[count] = truncatedString + ellipsis;
495 count++;
496 count++;
496 }
497 }
497
498
498 // Binary search for best fit
499 // Binary search for best fit
499 int minIndex(0);
500 int minIndex(0);
500 int maxIndex(count - 1);
501 int maxIndex(count - 1);
501 int bestIndex(count);
502 int bestIndex(count);
502 QRectF checkRect;
503 QRectF checkRect;
503
504
504 while (maxIndex >= minIndex) {
505 while (maxIndex >= minIndex) {
505 int mid = (maxIndex + minIndex) / 2;
506 int mid = (maxIndex + minIndex) / 2;
506 checkRect = textBoundingRect(font, testStrings.at(mid), angle);
507 checkRect = textBoundingRect(font, testStrings.at(mid), angle);
507 if (checkRect.width() > maxWidth || checkRect.height() > maxHeight) {
508 if (checkRect.width() > maxWidth || checkRect.height() > maxHeight) {
508 // Checked index too large, all under this are also too large
509 // Checked index too large, all under this are also too large
509 minIndex = mid + 1;
510 minIndex = mid + 1;
510 } else {
511 } else {
511 // Checked index fits, all over this also fit
512 // Checked index fits, all over this also fit
512 maxIndex = mid - 1;
513 maxIndex = mid - 1;
513 bestIndex = mid;
514 bestIndex = mid;
514 boundingRect = checkRect;
515 boundingRect = checkRect;
515 }
516 }
516 }
517 }
517 // Default to "..." if nothing fits
518 // Default to "..." if nothing fits
518 if (bestIndex == count) {
519 if (bestIndex == count) {
519 boundingRect = textBoundingRect(font, ellipsis, angle);
520 boundingRect = textBoundingRect(font, ellipsis, angle);
520 truncatedString = ellipsis;
521 truncatedString = ellipsis;
521 } else {
522 } else {
522 truncatedString = testStrings.at(bestIndex);
523 truncatedString = testStrings.at(bestIndex);
523 }
524 }
524 }
525 }
525
526
526 return truncatedString;
527 return truncatedString;
527 }
528 }
528
529
529 QString ChartPresenter::numberToString(double value, char f, int prec)
530 QString ChartPresenter::numberToString(double value, char f, int prec)
530 {
531 {
531 if (m_localizeNumbers)
532 if (m_localizeNumbers)
532 return m_locale.toString(value, f, prec);
533 return m_locale.toString(value, f, prec);
533 else
534 else
534 return QString::number(value, f, prec);
535 return QString::number(value, f, prec);
535 }
536 }
536
537
537 QString ChartPresenter::numberToString(int value)
538 QString ChartPresenter::numberToString(int value)
538 {
539 {
539 if (m_localizeNumbers)
540 if (m_localizeNumbers)
540 return m_locale.toString(value);
541 return m_locale.toString(value);
541 else
542 else
542 return QString::number(value);
543 return QString::number(value);
543 }
544 }
544
545
545 void ChartPresenter::ensureGLWidget()
546 void ChartPresenter::ensureGLWidget()
546 {
547 {
547 #ifndef QT_NO_OPENGL
548 #ifndef QT_NO_OPENGL
548 // GLWidget pointer is wrapped in QPointer as its parent is not in our control, and therefore
549 // GLWidget pointer is wrapped in QPointer as its parent is not in our control, and therefore
549 // can potentially get deleted unexpectedly.
550 // can potentially get deleted unexpectedly.
550 if (m_glWidget.isNull() && m_glUseWidget && m_chart->scene()) {
551 if (m_glWidget.isNull() && m_glUseWidget && m_chart->scene()) {
551 QObject *parent = m_chart->scene()->parent();
552 QObject *parent = m_chart->scene()->parent();
552 while (parent) {
553 while (parent) {
553 QWidget *parentWidget = qobject_cast<QWidget *>(parent);
554 QWidget *parentWidget = qobject_cast<QWidget *>(parent);
554 if (parentWidget) {
555 if (parentWidget) {
555 m_glWidget = new GLWidget(m_chart->d_ptr->m_dataset->glXYSeriesDataManager(),
556 m_glWidget = new GLWidget(m_chart->d_ptr->m_dataset->glXYSeriesDataManager(),
556 parentWidget);
557 parentWidget);
557 m_glWidget->setGeometry(m_rect.toRect());
558 m_glWidget->setGeometry(m_rect.toRect());
558 m_glWidget->show();
559 m_glWidget->show();
559 break;
560 break;
560 }
561 }
561 parent = parent->parent();
562 parent = parent->parent();
562 }
563 }
563 }
564 }
564 #endif
565 #endif
565 }
566 }
566
567
567 #include "moc_chartpresenter_p.cpp"
568 #include "moc_chartpresenter_p.cpp"
568
569
569 QT_CHARTS_END_NAMESPACE
570 QT_CHARTS_END_NAMESPACE
@@ -1,208 +1,209
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd
3 ** Copyright (C) 2015 The Qt Company Ltd
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to The Qt Company, please use contact form at http://qt.io
5 ** For any questions to The Qt Company, please use contact form at http://qt.io
6 **
6 **
7 ** This file is part of the Qt Charts module.
7 ** This file is part of the Qt Charts module.
8 **
8 **
9 ** Licensees holding valid commercial license for Qt may use this file in
9 ** Licensees holding valid commercial license for Qt may use this file in
10 ** accordance with the Qt License Agreement provided with the Software
10 ** accordance with the Qt License Agreement provided with the Software
11 ** or, alternatively, in accordance with the terms contained in a written
11 ** or, alternatively, in accordance with the terms contained in a written
12 ** agreement between you and The Qt Company.
12 ** agreement between you and The Qt Company.
13 **
13 **
14 ** If you have questions regarding the use of this file, please use
14 ** If you have questions regarding the use of this file, please use
15 ** contact form at http://qt.io
15 ** contact form at http://qt.io
16 **
16 **
17 ****************************************************************************/
17 ****************************************************************************/
18
18
19 // W A R N I N G
19 // W A R N I N G
20 // -------------
20 // -------------
21 //
21 //
22 // This file is not part of the Qt Chart API. It exists purely as an
22 // This file is not part of the Qt Chart API. It exists purely as an
23 // implementation detail. This header file may change from version to
23 // implementation detail. This header file may change from version to
24 // version without notice, or even be removed.
24 // version without notice, or even be removed.
25 //
25 //
26 // We mean it.
26 // We mean it.
27
27
28 #ifndef CHARTPRESENTER_H
28 #ifndef CHARTPRESENTER_H
29 #define CHARTPRESENTER_H
29 #define CHARTPRESENTER_H
30
30
31 #include <QtCharts/QChartGlobal>
31 #include <QtCharts/QChartGlobal>
32 #include <QtCharts/QChart> //because of QChart::ChartThemeId
32 #include <QtCharts/QChart> //because of QChart::ChartThemeId
33 #include <private/glwidget_p.h>
33 #include <private/glwidget_p.h>
34 #include <QtCore/QRectF>
34 #include <QtCore/QRectF>
35 #include <QtCore/QMargins>
35 #include <QtCore/QMargins>
36 #include <QtCore/QLocale>
36 #include <QtCore/QLocale>
37 #include <QtCore/QPointer>
37 #include <QtCore/QPointer>
38 #include <QtCore/QEasingCurve>
38
39
39 QT_CHARTS_BEGIN_NAMESPACE
40 QT_CHARTS_BEGIN_NAMESPACE
40
41
41 class ChartItem;
42 class ChartItem;
42 class AxisItem;
43 class AxisItem;
43 class QAbstractSeries;
44 class QAbstractSeries;
44 class ChartDataSet;
45 class ChartDataSet;
45 class AbstractDomain;
46 class AbstractDomain;
46 class ChartAxisElement;
47 class ChartAxisElement;
47 class ChartAnimator;
48 class ChartAnimator;
48 class ChartBackground;
49 class ChartBackground;
49 class ChartTitle;
50 class ChartTitle;
50 class ChartAnimation;
51 class ChartAnimation;
51 class AbstractChartLayout;
52 class AbstractChartLayout;
52
53
53 class ChartPresenter: public QObject
54 class ChartPresenter: public QObject
54 {
55 {
55 Q_OBJECT
56 Q_OBJECT
56 public:
57 public:
57 enum ZValues {
58 enum ZValues {
58 BackgroundZValue = -1,
59 BackgroundZValue = -1,
59 PlotAreaZValue,
60 PlotAreaZValue,
60 ShadesZValue,
61 ShadesZValue,
61 GridZValue,
62 GridZValue,
62 AxisZValue,
63 AxisZValue,
63 SeriesZValue,
64 SeriesZValue,
64 LineChartZValue = SeriesZValue,
65 LineChartZValue = SeriesZValue,
65 SplineChartZValue = SeriesZValue,
66 SplineChartZValue = SeriesZValue,
66 BarSeriesZValue = SeriesZValue,
67 BarSeriesZValue = SeriesZValue,
67 ScatterSeriesZValue = SeriesZValue,
68 ScatterSeriesZValue = SeriesZValue,
68 PieSeriesZValue = SeriesZValue,
69 PieSeriesZValue = SeriesZValue,
69 BoxPlotSeriesZValue = SeriesZValue,
70 BoxPlotSeriesZValue = SeriesZValue,
70 LegendZValue,
71 LegendZValue,
71 TopMostZValue
72 TopMostZValue
72 };
73 };
73
74
74 enum State {
75 enum State {
75 ShowState,
76 ShowState,
76 ScrollUpState,
77 ScrollUpState,
77 ScrollDownState,
78 ScrollDownState,
78 ScrollLeftState,
79 ScrollLeftState,
79 ScrollRightState,
80 ScrollRightState,
80 ZoomInState,
81 ZoomInState,
81 ZoomOutState
82 ZoomOutState
82 };
83 };
83
84
84 ChartPresenter(QChart *chart, QChart::ChartType type);
85 ChartPresenter(QChart *chart, QChart::ChartType type);
85 virtual ~ChartPresenter();
86 virtual ~ChartPresenter();
86
87
87
88
88 void setGeometry(QRectF rect);
89 void setGeometry(QRectF rect);
89 QRectF geometry() const;
90 QRectF geometry() const;
90
91
91 QGraphicsItem *rootItem(){ return m_chart; }
92 QGraphicsItem *rootItem(){ return m_chart; }
92 ChartBackground *backgroundElement();
93 ChartBackground *backgroundElement();
93 QAbstractGraphicsShapeItem *plotAreaElement();
94 QAbstractGraphicsShapeItem *plotAreaElement();
94 ChartTitle *titleElement();
95 ChartTitle *titleElement();
95 QList<ChartAxisElement *> axisItems() const;
96 QList<ChartAxisElement *> axisItems() const;
96 QList<ChartItem *> chartItems() const;
97 QList<ChartItem *> chartItems() const;
97
98
98 QLegend *legend();
99 QLegend *legend();
99
100
100 void setBackgroundBrush(const QBrush &brush);
101 void setBackgroundBrush(const QBrush &brush);
101 QBrush backgroundBrush() const;
102 QBrush backgroundBrush() const;
102
103
103 void setBackgroundPen(const QPen &pen);
104 void setBackgroundPen(const QPen &pen);
104 QPen backgroundPen() const;
105 QPen backgroundPen() const;
105
106
106 void setBackgroundRoundness(qreal diameter);
107 void setBackgroundRoundness(qreal diameter);
107 qreal backgroundRoundness() const;
108 qreal backgroundRoundness() const;
108
109
109 void setPlotAreaBackgroundBrush(const QBrush &brush);
110 void setPlotAreaBackgroundBrush(const QBrush &brush);
110 QBrush plotAreaBackgroundBrush() const;
111 QBrush plotAreaBackgroundBrush() const;
111
112
112 void setPlotAreaBackgroundPen(const QPen &pen);
113 void setPlotAreaBackgroundPen(const QPen &pen);
113 QPen plotAreaBackgroundPen() const;
114 QPen plotAreaBackgroundPen() const;
114
115
115 void setTitle(const QString &title);
116 void setTitle(const QString &title);
116 QString title() const;
117 QString title() const;
117
118
118 void setTitleFont(const QFont &font);
119 void setTitleFont(const QFont &font);
119 QFont titleFont() const;
120 QFont titleFont() const;
120
121
121 void setTitleBrush(const QBrush &brush);
122 void setTitleBrush(const QBrush &brush);
122 QBrush titleBrush() const;
123 QBrush titleBrush() const;
123
124
124 void setBackgroundVisible(bool visible);
125 void setBackgroundVisible(bool visible);
125 bool isBackgroundVisible() const;
126 bool isBackgroundVisible() const;
126
127
127 void setPlotAreaBackgroundVisible(bool visible);
128 void setPlotAreaBackgroundVisible(bool visible);
128 bool isPlotAreaBackgroundVisible() const;
129 bool isPlotAreaBackgroundVisible() const;
129
130
130 void setBackgroundDropShadowEnabled(bool enabled);
131 void setBackgroundDropShadowEnabled(bool enabled);
131 bool isBackgroundDropShadowEnabled() const;
132 bool isBackgroundDropShadowEnabled() const;
132
133
133 void setLocalizeNumbers(bool localize);
134 void setLocalizeNumbers(bool localize);
134 inline bool localizeNumbers() const { return m_localizeNumbers; }
135 inline bool localizeNumbers() const { return m_localizeNumbers; }
135 void setLocale(const QLocale &locale);
136 void setLocale(const QLocale &locale);
136 inline const QLocale &locale() const { return m_locale; }
137 inline const QLocale &locale() const { return m_locale; }
137
138
138 void setVisible(bool visible);
139 void setVisible(bool visible);
139
140
140 void setAnimationOptions(QChart::AnimationOptions options);
141 void setAnimationOptions(QChart::AnimationOptions options);
141 QChart::AnimationOptions animationOptions() const;
142 QChart::AnimationOptions animationOptions() const;
142 void setAnimationDuration(int msecs);
143 void setAnimationDuration(int msecs);
143 int animationDuration() const { return m_animationDuration; }
144 int animationDuration() const { return m_animationDuration; }
144 void setAnimationEasingCurve(const QEasingCurve &curve);
145 void setAnimationEasingCurve(const QEasingCurve &curve);
145 QEasingCurve animationEasingCurve() const { return m_animationCurve; }
146 QEasingCurve animationEasingCurve() const { return m_animationCurve; }
146
147
147 void startAnimation(ChartAnimation *animation);
148 void startAnimation(ChartAnimation *animation);
148
149
149 void setState(State state,QPointF point);
150 void setState(State state,QPointF point);
150 State state() const { return m_state; }
151 State state() const { return m_state; }
151 QPointF statePoint() const { return m_statePoint; }
152 QPointF statePoint() const { return m_statePoint; }
152 AbstractChartLayout *layout();
153 AbstractChartLayout *layout();
153
154
154 QChart::ChartType chartType() const { return m_chart->chartType(); }
155 QChart::ChartType chartType() const { return m_chart->chartType(); }
155 QChart *chart() { return m_chart; }
156 QChart *chart() { return m_chart; }
156
157
157 static QRectF textBoundingRect(const QFont &font, const QString &text, qreal angle = 0.0);
158 static QRectF textBoundingRect(const QFont &font, const QString &text, qreal angle = 0.0);
158 static QString truncatedText(const QFont &font, const QString &text, qreal angle,
159 static QString truncatedText(const QFont &font, const QString &text, qreal angle,
159 qreal maxWidth, qreal maxHeight, QRectF &boundingRect);
160 qreal maxWidth, qreal maxHeight, QRectF &boundingRect);
160 inline static qreal textMargin() { return qreal(0.5); }
161 inline static qreal textMargin() { return qreal(0.5); }
161
162
162 QString numberToString(double value, char f = 'g', int prec = 6);
163 QString numberToString(double value, char f = 'g', int prec = 6);
163 QString numberToString(int value);
164 QString numberToString(int value);
164
165
165 void ensureGLWidget();
166 void ensureGLWidget();
166 void glSetUseWidget(bool enable) { m_glUseWidget = enable; }
167 void glSetUseWidget(bool enable) { m_glUseWidget = enable; }
167
168
168 private:
169 private:
169 void createBackgroundItem();
170 void createBackgroundItem();
170 void createPlotAreaBackgroundItem();
171 void createPlotAreaBackgroundItem();
171 void createTitleItem();
172 void createTitleItem();
172
173
173 public Q_SLOTS:
174 public Q_SLOTS:
174 void handleSeriesAdded(QAbstractSeries *series);
175 void handleSeriesAdded(QAbstractSeries *series);
175 void handleSeriesRemoved(QAbstractSeries *series);
176 void handleSeriesRemoved(QAbstractSeries *series);
176 void handleAxisAdded(QAbstractAxis *axis);
177 void handleAxisAdded(QAbstractAxis *axis);
177 void handleAxisRemoved(QAbstractAxis *axis);
178 void handleAxisRemoved(QAbstractAxis *axis);
178
179
179 Q_SIGNALS:
180 Q_SIGNALS:
180 void plotAreaChanged(const QRectF &plotArea);
181 void plotAreaChanged(const QRectF &plotArea);
181
182
182 private:
183 private:
183 QChart *m_chart;
184 QChart *m_chart;
184 QList<ChartItem *> m_chartItems;
185 QList<ChartItem *> m_chartItems;
185 QList<ChartAxisElement *> m_axisItems;
186 QList<ChartAxisElement *> m_axisItems;
186 QList<QAbstractSeries *> m_series;
187 QList<QAbstractSeries *> m_series;
187 QList<QAbstractAxis *> m_axes;
188 QList<QAbstractAxis *> m_axes;
188 QChart::AnimationOptions m_options;
189 QChart::AnimationOptions m_options;
189 int m_animationDuration;
190 int m_animationDuration;
190 QEasingCurve m_animationCurve;
191 QEasingCurve m_animationCurve;
191 State m_state;
192 State m_state;
192 QPointF m_statePoint;
193 QPointF m_statePoint;
193 AbstractChartLayout *m_layout;
194 AbstractChartLayout *m_layout;
194 ChartBackground *m_background;
195 ChartBackground *m_background;
195 QAbstractGraphicsShapeItem *m_plotAreaBackground;
196 QAbstractGraphicsShapeItem *m_plotAreaBackground;
196 ChartTitle *m_title;
197 ChartTitle *m_title;
197 QRectF m_rect;
198 QRectF m_rect;
198 bool m_localizeNumbers;
199 bool m_localizeNumbers;
199 QLocale m_locale;
200 QLocale m_locale;
200 #ifndef QT_NO_OPENGL
201 #ifndef QT_NO_OPENGL
201 QPointer<GLWidget> m_glWidget;
202 QPointer<GLWidget> m_glWidget;
202 #endif
203 #endif
203 bool m_glUseWidget;
204 bool m_glUseWidget;
204 };
205 };
205
206
206 QT_CHARTS_END_NAMESPACE
207 QT_CHARTS_END_NAMESPACE
207
208
208 #endif /* CHARTPRESENTER_H */
209 #endif /* CHARTPRESENTER_H */
General Comments 0
You need to be logged in to leave comments. Login now