diff options
57 files changed, 495 insertions, 276 deletions
diff --git a/.qmake.conf b/.qmake.conf index 2108ac6f..138038d5 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -1,3 +1,3 @@ load(qt_build_config) -MODULE_VERSION = 5.9.3 +MODULE_VERSION = 5.10.0 diff --git a/dist/changes-5.10.0 b/dist/changes-5.10.0 new file mode 100644 index 00000000..6847eb8d --- /dev/null +++ b/dist/changes-5.10.0 @@ -0,0 +1,22 @@ +Qt 5.10 introduces many new features and improvements as well as bugfixes +over the 5.9.x series. For more details, refer to the online documentation +included in this distribution. The documentation is also available online: + +http://doc.qt.io/qt-5/index.html + +The Qt version 5.10 series is binary compatible with the 5.10.x series. +Applications compiled for 5.9 will continue to run with 5.10. + +Some of the changes listed in this file include issue tracking numbers +corresponding to tasks in the Qt Bug Tracker: + +https://bugreports.qt.io/ + +Each of these identifiers can be entered in the bug tracker to obtain more +information about a particular change. + +**************************************************************************** +* Qt 5.10.0 Changes * +**************************************************************************** + + - This release contains only minor code improvements. diff --git a/examples/charts/barmodelmapper/customtablemodel.cpp b/examples/charts/barmodelmapper/customtablemodel.cpp index a1446386..4bbf4191 100644 --- a/examples/charts/barmodelmapper/customtablemodel.cpp +++ b/examples/charts/barmodelmapper/customtablemodel.cpp @@ -31,13 +31,12 @@ #include <QtCore/QVector> #include <QtCore/QTime> #include <QtCore/QRect> +#include <QtCore/QRandomGenerator> #include <QtGui/QColor> CustomTableModel::CustomTableModel(QObject *parent) : QAbstractTableModel(parent) { - qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); - m_columnCount = 6; m_rowCount = 12; @@ -46,9 +45,9 @@ CustomTableModel::CustomTableModel(QObject *parent) : QVector<qreal>* dataVec = new QVector<qreal>(m_columnCount); for (int k = 0; k < dataVec->size(); k++) { if (k % 2 == 0) - dataVec->replace(k, i * 50 + qrand() % 20); + dataVec->replace(k, i * 50 + QRandomGenerator::global()->bounded(20)); else - dataVec->replace(k, qrand() % 100); + dataVec->replace(k, QRandomGenerator::global()->bounded(100)); } m_data.append(dataVec); } diff --git a/examples/charts/chartthemes/chartthemes.pro b/examples/charts/chartthemes/chartthemes.pro index 5985f55c..193dc4e6 100644 --- a/examples/charts/chartthemes/chartthemes.pro +++ b/examples/charts/chartthemes/chartthemes.pro @@ -9,3 +9,6 @@ SOURCES += \ target.path = $$[QT_INSTALL_EXAMPLES]/charts/chartthemes INSTALLS += target + +FORMS += \ + themewidget.ui diff --git a/examples/charts/chartthemes/themewidget.cpp b/examples/charts/chartthemes/themewidget.cpp index 982c50e0..84ea8231 100644 --- a/examples/charts/chartthemes/themewidget.cpp +++ b/examples/charts/chartthemes/themewidget.cpp @@ -28,6 +28,7 @@ ****************************************************************************/ #include "themewidget.h" +#include "ui_themewidget.h" #include <QtCharts/QChartView> #include <QtCharts/QPieSeries> @@ -49,8 +50,10 @@ #include <QtWidgets/QCheckBox> #include <QtWidgets/QGroupBox> #include <QtWidgets/QLabel> -#include <QtCore/QTime> +#include <QtCore/QRandomGenerator> #include <QtCharts/QBarCategoryAxis> +#include <QtWidgets/QApplication> +#include <QtCharts/QValueAxis> ThemeWidget::ThemeWidget(QWidget *parent) : QWidget(parent), @@ -58,94 +61,73 @@ ThemeWidget::ThemeWidget(QWidget *parent) : m_valueMax(10), m_valueCount(7), m_dataTable(generateRandomData(m_listCount, m_valueMax, m_valueCount)), - m_themeComboBox(createThemeBox()), - m_antialiasCheckBox(new QCheckBox("Anti-aliasing")), - m_animatedComboBox(createAnimationBox()), - m_legendComboBox(createLegendBox()) + m_ui(new Ui_ThemeWidgetForm) { - connectSignals(); - // create layout - QGridLayout *baseLayout = new QGridLayout(); - QHBoxLayout *settingsLayout = new QHBoxLayout(); - settingsLayout->addWidget(new QLabel("Theme:")); - settingsLayout->addWidget(m_themeComboBox); - settingsLayout->addWidget(new QLabel("Animation:")); - settingsLayout->addWidget(m_animatedComboBox); - settingsLayout->addWidget(new QLabel("Legend:")); - settingsLayout->addWidget(m_legendComboBox); - settingsLayout->addWidget(m_antialiasCheckBox); - settingsLayout->addStretch(); - baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); + m_ui->setupUi(this); + populateThemeBox(); + populateAnimationBox(); + populateLegendBox(); //create charts QChartView *chartView; chartView = new QChartView(createAreaChart()); - baseLayout->addWidget(chartView, 1, 0); + m_ui->gridLayout->addWidget(chartView, 1, 0); m_charts << chartView; - chartView = new QChartView(createBarChart(m_valueCount)); - baseLayout->addWidget(chartView, 1, 1); + chartView = new QChartView(createPieChart()); + // Funny things happen if the pie slice labels do not fit the screen, so we ignore size policy + chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); + m_ui->gridLayout->addWidget(chartView, 1, 1); m_charts << chartView; + //![5] chartView = new QChartView(createLineChart()); - baseLayout->addWidget(chartView, 1, 2); + m_ui->gridLayout->addWidget(chartView, 1, 2); + //![5] m_charts << chartView; - chartView = new QChartView(createPieChart()); - // Funny things happen if the pie slice labels do not fit the screen, so we ignore size policy - chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); - baseLayout->addWidget(chartView, 2, 0); + chartView = new QChartView(createBarChart(m_valueCount)); + m_ui->gridLayout->addWidget(chartView, 2, 0); m_charts << chartView; chartView = new QChartView(createSplineChart()); - baseLayout->addWidget(chartView, 2, 1); + m_ui->gridLayout->addWidget(chartView, 2, 1); m_charts << chartView; chartView = new QChartView(createScatterChart()); - baseLayout->addWidget(chartView, 2, 2); + m_ui->gridLayout->addWidget(chartView, 2, 2); m_charts << chartView; - setLayout(baseLayout); - // Set defaults - m_antialiasCheckBox->setChecked(true); + m_ui->antialiasCheckBox->setChecked(true); + + // Set the colors from the light theme as default ones + QPalette pal = qApp->palette(); + pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); + pal.setColor(QPalette::WindowText, QRgb(0x404044)); + qApp->setPalette(pal); + updateUI(); } ThemeWidget::~ThemeWidget() { -} - -void ThemeWidget::connectSignals() -{ - connect(m_themeComboBox, - static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), - this, &ThemeWidget::updateUI); - connect(m_antialiasCheckBox, &QCheckBox::toggled, this, &ThemeWidget::updateUI); - connect(m_animatedComboBox, - static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), - this, &ThemeWidget::updateUI); - connect(m_legendComboBox, - static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), - this, &ThemeWidget::updateUI); + delete m_ui; } DataTable ThemeWidget::generateRandomData(int listCount, int valueMax, int valueCount) const { DataTable dataTable; - // set seed for random stuff - qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); - // generate random data for (int i(0); i < listCount; i++) { DataList dataList; qreal yValue(0); for (int j(0); j < valueCount; j++) { - yValue = yValue + (qreal)(qrand() % valueMax) / (qreal) valueCount; - QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount), + yValue = yValue + QRandomGenerator::global()->bounded(valueMax / (qreal) valueCount); + QPointF value((j + QRandomGenerator::global()->generateDouble()) * ((qreal) m_valueMax / (qreal) valueCount), yValue); QString label = "Slice " + QString::number(i) + ":" + QString::number(j); dataList << Data(value, label); @@ -156,41 +138,36 @@ DataTable ThemeWidget::generateRandomData(int listCount, int valueMax, int value return dataTable; } -QComboBox *ThemeWidget::createThemeBox() const +void ThemeWidget::populateThemeBox() { - // settings layout - QComboBox *themeComboBox = new QComboBox(); - themeComboBox->addItem("Light", QChart::ChartThemeLight); - themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); - themeComboBox->addItem("Dark", QChart::ChartThemeDark); - themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); - themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); - themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); - themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); - themeComboBox->addItem("Qt", QChart::ChartThemeQt); - return themeComboBox; + // add items to theme combobox + m_ui->themeComboBox->addItem("Light", QChart::ChartThemeLight); + m_ui->themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); + m_ui->themeComboBox->addItem("Dark", QChart::ChartThemeDark); + m_ui->themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); + m_ui->themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); + m_ui->themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); + m_ui->themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); + m_ui->themeComboBox->addItem("Qt", QChart::ChartThemeQt); } -QComboBox *ThemeWidget::createAnimationBox() const +void ThemeWidget::populateAnimationBox() { - // settings layout - QComboBox *animationComboBox = new QComboBox(); - animationComboBox->addItem("No Animations", QChart::NoAnimation); - animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); - animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); - animationComboBox->addItem("All Animations", QChart::AllAnimations); - return animationComboBox; + // add items to animation combobox + m_ui->animatedComboBox->addItem("No Animations", QChart::NoAnimation); + m_ui->animatedComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); + m_ui->animatedComboBox->addItem("Series Animations", QChart::SeriesAnimations); + m_ui->animatedComboBox->addItem("All Animations", QChart::AllAnimations); } -QComboBox *ThemeWidget::createLegendBox() const +void ThemeWidget::populateLegendBox() { - QComboBox *legendComboBox = new QComboBox(); - legendComboBox->addItem("No Legend ", 0); - legendComboBox->addItem("Legend Top", Qt::AlignTop); - legendComboBox->addItem("Legend Bottom", Qt::AlignBottom); - legendComboBox->addItem("Legend Left", Qt::AlignLeft); - legendComboBox->addItem("Legend Right", Qt::AlignRight); - return legendComboBox; + // add items to legend combobox + m_ui->legendComboBox->addItem("No Legend ", 0); + m_ui->legendComboBox->addItem("Legend Top", Qt::AlignTop); + m_ui->legendComboBox->addItem("Legend Bottom", Qt::AlignBottom); + m_ui->legendComboBox->addItem("Legend Left", Qt::AlignLeft); + m_ui->legendComboBox->addItem("Legend Right", Qt::AlignRight); } QChart *ThemeWidget::createAreaChart() const @@ -217,10 +194,15 @@ QChart *ThemeWidget::createAreaChart() const area->setName(name + QString::number(nameIndex)); nameIndex++; chart->addSeries(area); - chart->createDefaultAxes(); lowerSeries = upperSeries; } + chart->createDefaultAxes(); + chart->axisX()->setRange(0, m_valueCount - 1); + chart->axisY()->setRange(0, m_valueMax); + // Add space to label to add space between labels and axis + static_cast<QValueAxis *>(chart->axisY())->setLabelFormat("%.1f "); + return chart; } @@ -238,16 +220,23 @@ QChart *ThemeWidget::createBarChart(int valueCount) const series->append(set); } chart->addSeries(series); + chart->createDefaultAxes(); + chart->axisY()->setRange(0, m_valueMax * 2); + // Add space to label to add space between labels and axis + static_cast<QValueAxis *>(chart->axisY())->setLabelFormat("%.1f "); return chart; } QChart *ThemeWidget::createLineChart() const { + //![1] QChart *chart = new QChart(); chart->setTitle("Line chart"); + //![1] + //![2] QString name("Series "); int nameIndex = 0; for (const DataList &list : m_dataTable) { @@ -258,7 +247,17 @@ QChart *ThemeWidget::createLineChart() const nameIndex++; chart->addSeries(series); } + //![2] + + //![3] chart->createDefaultAxes(); + chart->axisX()->setRange(0, m_valueMax); + chart->axisY()->setRange(0, m_valueCount); + //![3] + //![4] + // Add space to label to add space between labels and axis + static_cast<QValueAxis *>(chart->axisY())->setLabelFormat("%.1f "); + //![4] return chart; } @@ -268,29 +267,24 @@ QChart *ThemeWidget::createPieChart() const QChart *chart = new QChart(); chart->setTitle("Pie chart"); - qreal pieSize = 1.0 / m_dataTable.count(); - for (int i = 0; i < m_dataTable.count(); i++) { - QPieSeries *series = new QPieSeries(chart); - for (const Data &data : m_dataTable[i]) { - QPieSlice *slice = series->append(data.second, data.first.y()); - if (data == m_dataTable[i].first()) { - slice->setLabelVisible(); - slice->setExploded(); - } + QPieSeries *series = new QPieSeries(chart); + for (const Data &data : m_dataTable[0]) { + QPieSlice *slice = series->append(data.second, data.first.y()); + if (data == m_dataTable[0].first()) { + // Show the first slice exploded with label + slice->setLabelVisible(); + slice->setExploded(); + slice->setExplodeDistanceFactor(0.5); } - qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); - series->setPieSize(pieSize); - series->setHorizontalPosition(hPos); - series->setVerticalPosition(0.5); - chart->addSeries(series); } + series->setPieSize(0.4); + chart->addSeries(series); return chart; } QChart *ThemeWidget::createSplineChart() const { - // spine chart QChart *chart = new QChart(); chart->setTitle("Spline chart"); QString name("Series "); @@ -303,7 +297,13 @@ QChart *ThemeWidget::createSplineChart() const nameIndex++; chart->addSeries(series); } + chart->createDefaultAxes(); + chart->axisX()->setRange(0, m_valueMax); + chart->axisY()->setRange(0, m_valueCount); + // Add space to label to add space between labels and axis + static_cast<QValueAxis *>(chart->axisY())->setLabelFormat("%.1f "); + return chart; } @@ -322,24 +322,37 @@ QChart *ThemeWidget::createScatterChart() const nameIndex++; chart->addSeries(series); } + chart->createDefaultAxes(); + chart->axisX()->setRange(0, m_valueMax); + chart->axisY()->setRange(0, m_valueCount); + // Add space to label to add space between labels and axis + static_cast<QValueAxis *>(chart->axisY())->setLabelFormat("%.1f "); + return chart; } void ThemeWidget::updateUI() { + //![6] QChart::ChartTheme theme = static_cast<QChart::ChartTheme>( - m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt()); - + m_ui->themeComboBox->itemData(m_ui->themeComboBox->currentIndex()).toInt()); + //![6] const auto charts = m_charts; - if (m_charts.at(0)->chart()->theme() != theme) { - for (QChartView *chartView : charts) + if (!m_charts.isEmpty() && m_charts.at(0)->chart()->theme() != theme) { + for (QChartView *chartView : charts) { + //![7] chartView->chart()->setTheme(theme); + //![7] + } + // Set palette colors based on selected theme + //![8] QPalette pal = window()->palette(); if (theme == QChart::ChartThemeLight) { pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); pal.setColor(QPalette::WindowText, QRgb(0x404044)); + //![8] } else if (theme == QChart::ChartThemeDark) { pal.setColor(QPalette::Window, QRgb(0x121218)); pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); @@ -365,18 +378,27 @@ void ThemeWidget::updateUI() window()->setPalette(pal); } - bool checked = m_antialiasCheckBox->isChecked(); + // Update antialiasing + //![11] + bool checked = m_ui->antialiasCheckBox->isChecked(); for (QChartView *chart : charts) chart->setRenderHint(QPainter::Antialiasing, checked); + //![11] + // Update animation options + //![9] QChart::AnimationOptions options( - m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); - if (m_charts.at(0)->chart()->animationOptions() != options) { + m_ui->animatedComboBox->itemData(m_ui->animatedComboBox->currentIndex()).toInt()); + if (!m_charts.isEmpty() && m_charts.at(0)->chart()->animationOptions() != options) { for (QChartView *chartView : charts) chartView->chart()->setAnimationOptions(options); } + //![9] - Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); + // Update legend alignment + //![10] + Qt::Alignment alignment( + m_ui->legendComboBox->itemData(m_ui->legendComboBox->currentIndex()).toInt()); if (!alignment) { for (QChartView *chartView : charts) @@ -387,5 +409,6 @@ void ThemeWidget::updateUI() chartView->chart()->legend()->show(); } } + //![10] } diff --git a/examples/charts/chartthemes/themewidget.h b/examples/charts/chartthemes/themewidget.h index 5b31ab7c..e2e093ab 100644 --- a/examples/charts/chartthemes/themewidget.h +++ b/examples/charts/chartthemes/themewidget.h @@ -36,6 +36,7 @@ QT_BEGIN_NAMESPACE class QComboBox; class QCheckBox; +class Ui_ThemeWidgetForm; QT_END_NAMESPACE QT_CHARTS_BEGIN_NAMESPACE @@ -61,9 +62,9 @@ private Q_SLOTS: private: DataTable generateRandomData(int listCount, int valueMax, int valueCount) const; - QComboBox *createThemeBox() const; - QComboBox *createAnimationBox() const; - QComboBox *createLegendBox() const; + void populateThemeBox(); + void populateAnimationBox(); + void populateLegendBox(); void connectSignals(); QChart *createAreaChart() const; QChart *createBarChart(int valueCount) const; @@ -79,10 +80,7 @@ private: QList<QChartView *> m_charts; DataTable m_dataTable; - QComboBox *m_themeComboBox; - QCheckBox *m_antialiasCheckBox; - QComboBox *m_animatedComboBox; - QComboBox *m_legendComboBox; + Ui_ThemeWidgetForm *m_ui; }; #endif /* THEMEWIDGET_H */ diff --git a/examples/charts/chartthemes/themewidget.ui b/examples/charts/chartthemes/themewidget.ui new file mode 100644 index 00000000..9ea2bb7c --- /dev/null +++ b/examples/charts/chartthemes/themewidget.ui @@ -0,0 +1,103 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>ThemeWidgetForm</class> + <widget class="QWidget" name="ThemeWidgetForm"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>900</width> + <height>600</height> + </rect> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0" colspan="3"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="themeLabel"> + <property name="text"> + <string>Theme:</string> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="themeComboBox"/> + </item> + <item> + <widget class="QLabel" name="animatedLabel"> + <property name="text"> + <string>Animation:</string> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="animatedComboBox"/> + </item> + <item> + <widget class="QLabel" name="legendLabel"> + <property name="text"> + <string>Legend:</string> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="legendComboBox"/> + </item> + <item> + <widget class="QCheckBox" name="antialiasCheckBox"> + <property name="text"> + <string>Anti-aliasing</string> + </property> + <property name="checked"> + <bool>false</bool> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>themeComboBox</sender> + <signal>currentIndexChanged(int)</signal> + <receiver>ThemeWidgetForm</receiver> + <slot>updateUI()</slot> + </connection> + <connection> + <sender>antialiasCheckBox</sender> + <signal>toggled(bool)</signal> + <receiver>ThemeWidgetForm</receiver> + <slot>updateUI()</slot> + </connection> + <connection> + <sender>legendComboBox</sender> + <signal>currentIndexChanged(int)</signal> + <receiver>ThemeWidgetForm</receiver> + <slot>updateUI()</slot> + </connection> + <connection> + <sender>animatedComboBox</sender> + <signal>currentIndexChanged(int)</signal> + <receiver>ThemeWidgetForm</receiver> + <slot>updateUI()</slot> + </connection> + </connections> + <slots> + <slot>updateUI()</slot> + </slots> +</ui> diff --git a/examples/charts/datetimeaxis/main.cpp b/examples/charts/datetimeaxis/main.cpp index 9a24a649..ca3f4320 100644 --- a/examples/charts/datetimeaxis/main.cpp +++ b/examples/charts/datetimeaxis/main.cpp @@ -43,7 +43,6 @@ QT_CHARTS_USE_NAMESPACE int main(int argc, char *argv[]) { QApplication a(argc, argv); - qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); //![1] QLineSeries *series = new QLineSeries(); diff --git a/examples/charts/dynamicspline/chart.cpp b/examples/charts/dynamicspline/chart.cpp index 21985998..beba2513 100644 --- a/examples/charts/dynamicspline/chart.cpp +++ b/examples/charts/dynamicspline/chart.cpp @@ -31,7 +31,7 @@ #include <QtCharts/QAbstractAxis> #include <QtCharts/QSplineSeries> #include <QtCharts/QValueAxis> -#include <QtCore/QTime> +#include <QtCore/QRandomGenerator> #include <QtCore/QDebug> Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags): @@ -42,8 +42,6 @@ Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags): m_x(5), m_y(1) { - qsrand((uint) QTime::currentTime().msec()); - QObject::connect(&m_timer, &QTimer::timeout, this, &Chart::handleTimeout); m_timer.setInterval(1000); @@ -73,7 +71,7 @@ void Chart::handleTimeout() qreal x = plotArea().width() / m_axis->tickCount(); qreal y = (m_axis->max() - m_axis->min()) / m_axis->tickCount(); m_x += y; - m_y = qrand() % 5 - 2.5; + m_y = QRandomGenerator::global()->bounded(5) - 2.5; m_series->append(m_x, m_y); scroll(x, 0); if (m_x == 100) diff --git a/examples/charts/legendmarkers/mainwidget.cpp b/examples/charts/legendmarkers/mainwidget.cpp index 46b2b275..a48a6384 100644 --- a/examples/charts/legendmarkers/mainwidget.cpp +++ b/examples/charts/legendmarkers/mainwidget.cpp @@ -82,7 +82,7 @@ void MainWidget::addSeries() int offset = m_chart->series().count(); for (int i = 0; i < 360; i++) { qreal x = offset * 20 + i; - data.append(QPointF(i, qSin(2.0 * 3.141592 * x / 360.0))); + data.append(QPointF(i, qSin(qDegreesToRadians(x)))); } series->append(data); diff --git a/examples/charts/modeldata/customtablemodel.cpp b/examples/charts/modeldata/customtablemodel.cpp index f86c7ed7..8ef3c2a9 100644 --- a/examples/charts/modeldata/customtablemodel.cpp +++ b/examples/charts/modeldata/customtablemodel.cpp @@ -29,15 +29,13 @@ #include "customtablemodel.h" #include <QtCore/QVector> -#include <QtCore/QTime> +#include <QtCore/QRandomGenerator> #include <QtCore/QRect> #include <QtGui/QColor> CustomTableModel::CustomTableModel(QObject *parent) : QAbstractTableModel(parent) { - qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); - m_columnCount = 4; m_rowCount = 15; @@ -46,9 +44,9 @@ CustomTableModel::CustomTableModel(QObject *parent) : QVector<qreal>* dataVec = new QVector<qreal>(m_columnCount); for (int k = 0; k < dataVec->size(); k++) { if (k % 2 == 0) - dataVec->replace(k, i * 50 + qrand() % 20); + dataVec->replace(k, i * 50 + QRandomGenerator::global()->bounded(20)); else - dataVec->replace(k, qrand() % 100); + dataVec->replace(k, QRandomGenerator::global()->bounded(100)); } m_data.append(dataVec); } diff --git a/examples/charts/nesteddonuts/widget.cpp b/examples/charts/nesteddonuts/widget.cpp index 3d2292c8..92c6415c 100644 --- a/examples/charts/nesteddonuts/widget.cpp +++ b/examples/charts/nesteddonuts/widget.cpp @@ -32,7 +32,7 @@ #include <QtCharts/QLegend> #include <QtCharts/QPieSeries> #include <QtCharts/QPieSlice> -#include <QtCore/QTime> +#include <QtCore/QRandomGenerator> #include <QtWidgets/QGridLayout> #include <QtCore/QTimer> @@ -42,7 +42,6 @@ Widget::Widget(QWidget *parent) : QWidget(parent) { setMinimumSize(800, 600); - qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); //! [1] QChartView *chartView = new QChartView; @@ -62,9 +61,9 @@ Widget::Widget(QWidget *parent) //! [3] for (int i = 0; i < donutCount; i++) { QPieSeries *donut = new QPieSeries; - int sliceCount = 3 + qrand() % 3; + int sliceCount = 3 + QRandomGenerator::global()->bounded(3); for (int j = 0; j < sliceCount; j++) { - qreal value = 100 + qrand() % 100; + qreal value = 100 + QRandomGenerator::global()->bounded(100); QPieSlice *slice = new QPieSlice(QString("%1").arg(value), value); slice->setLabelVisible(true); slice->setLabelColor(Qt::white); @@ -103,7 +102,7 @@ void Widget::updateRotation() { for (int i = 0; i < m_donuts.count(); i++) { QPieSeries *donut = m_donuts.at(i); - qreal phaseShift = -50 + qrand() % 100; + qreal phaseShift = -50 + QRandomGenerator::global()->bounded(100); donut->setPieStartAngle(donut->pieStartAngle() + phaseShift); donut->setPieEndAngle(donut->pieEndAngle() + phaseShift); } diff --git a/examples/charts/openglseries/datasource.cpp b/examples/charts/openglseries/datasource.cpp index 5f554500..af2dc10e 100644 --- a/examples/charts/openglseries/datasource.cpp +++ b/examples/charts/openglseries/datasource.cpp @@ -29,6 +29,7 @@ #include "datasource.h" #include <QtCore/QtMath> +#include <QtCore/QRandomGenerator> QT_CHARTS_USE_NAMESPACE @@ -111,8 +112,8 @@ void DataSource::generateData(int seriesCount, int rowCount, int colCount) qreal x(0); qreal y(0); // data with sin + random component - y = height + (yMultiplier * qSin(3.14159265358979 / 50 * j) - + (yMultiplier * (qreal) rand() / (qreal) RAND_MAX)); + y = height + (yMultiplier * qSin(M_PI / 50 * j) + + (yMultiplier * QRandomGenerator::global()->generateDouble())); // 0.000001 added to make values logaxis compatible x = 0.000001 + 20.0 * (qreal(j) / qreal(colCount)) + (xAdjustment * qreal(i)); points.append(QPointF(x, y)); diff --git a/examples/charts/piechartdrilldown/main.cpp b/examples/charts/piechartdrilldown/main.cpp index 8deeb0c3..e18f07f3 100644 --- a/examples/charts/piechartdrilldown/main.cpp +++ b/examples/charts/piechartdrilldown/main.cpp @@ -31,7 +31,7 @@ #include "drilldownslice.h" #include <QtWidgets/QApplication> #include <QtWidgets/QMainWindow> -#include <QtCore/QTime> +#include <QtCore/QRandomGenerator> #include <QtCharts/QChartView> #include <QtCharts/QLegend> #include <QtCharts/QPieSeries> @@ -42,8 +42,6 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); - qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); - QMainWindow window; DrilldownChart *chart = new DrilldownChart(); @@ -67,7 +65,7 @@ int main(int argc, char *argv[]) series->setName("Sales by month - " + name); for (const QString &month : months) - *series << new DrilldownSlice(qrand() % 1000, month, yearSeries); + *series << new DrilldownSlice(QRandomGenerator::global()->bounded(1000), month, yearSeries); QObject::connect(series, &QPieSeries::clicked, chart, &DrilldownChart::handleSliceClicked); diff --git a/examples/charts/qmlchart/qml/qmlchart/MainForm.ui.qml b/examples/charts/qmlchart/qml/qmlchart/MainForm.ui.qml new file mode 100644 index 00000000..1adbfd70 --- /dev/null +++ b/examples/charts/qmlchart/qml/qmlchart/MainForm.ui.qml @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Charts module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Item { + width: 600 + height: 400 + property bool sourceLoaded: false + property alias currentIndex: root.currentIndex + property alias info: infoText + + ListView { + id: root + focus: true + anchors.fill: parent + snapMode: ListView.SnapOneItem + highlightRangeMode: ListView.StrictlyEnforceRange + highlightMoveDuration: 250 + orientation: ListView.Horizontal + boundsBehavior: Flickable.StopAtBounds + + model: ListModel { + ListElement {component: "View1.qml"} + ListElement {component: "View2.qml"} + ListElement {component: "View3.qml"} + ListElement {component: "View4.qml"} + ListElement {component: "View5.qml"} + ListElement {component: "View6.qml"} + ListElement {component: "View7.qml"} + ListElement {component: "View8.qml"} + ListElement {component: "View9.qml"} + ListElement {component: "View10.qml"} + ListElement {component: "View11.qml"} + ListElement {component: "View12.qml"} + } + + delegate: Loader { + width: root.width + height: root.height + + source: component + asynchronous: true + + onLoaded: sourceLoaded = true + } + } + + Rectangle { + id: infoText + anchors.centerIn: parent + width: parent.width + height: 40 + color: "black" + Text { + color: "white" + anchors.centerIn: parent + text: "You can navigate between views using swipe or arrow keys" + } + } +} diff --git a/examples/charts/qmlchart/qml/qmlchart/View1.qml b/examples/charts/qmlchart/qml/qmlchart/View1.qml index 5f59989e..6b1de819 100644 --- a/examples/charts/qmlchart/qml/qmlchart/View1.qml +++ b/examples/charts/qmlchart/qml/qmlchart/View1.qml @@ -55,7 +55,7 @@ Item { } Component.onCompleted: { - // You can also manipulate slices dynamically + // You can also manipulate slices dynamically, like append a slice or set a slice exploded othersSlice = pieSeries.append("Others", 52.0); pieSeries.find("Volkswagen").exploded = true; } diff --git a/examples/charts/qmlchart/qml/qmlchart/View12.qml b/examples/charts/qmlchart/qml/qmlchart/View12.qml index e6279efc..6403c3f8 100644 --- a/examples/charts/qmlchart/qml/qmlchart/View12.qml +++ b/examples/charts/qmlchart/qml/qmlchart/View12.qml @@ -45,9 +45,9 @@ Item { id: pieOuter size: 0.96 holeSize: 0.7 - PieSlice { id: slice; label: "Alpha"; value: 19511; color: "#8AB846"; borderColor: "#163430" } - PieSlice { label: "Epsilon"; value: 11105; color: "#C0EEFF"; borderColor: "#3B391C" } - PieSlice { label: "Psi"; value: 9352; color: "#DF8939"; borderColor: "#13060C" } + PieSlice { id: slice; label: "Alpha"; value: 19511; color: "#99CA53" } + PieSlice { label: "Epsilon"; value: 11105; color: "#209FDF" } + PieSlice { label: "Psi"; value: 9352; color: "#F6A625" } } PieSeries { @@ -55,17 +55,17 @@ Item { id: pieInner holeSize: 0.25 - PieSlice { label: "Materials"; value: 10334; color: "#8AB846"; borderColor: "#163430" } - PieSlice { label: "Employee"; value: 3066; color: "#AAE356"; borderColor: "#163430" } - PieSlice { label: "Logistics"; value: 6111; color: "#99CC4E"; borderColor: "#163430" } + PieSlice { label: "Materials"; value: 10334; color: "#B9DB8A" } + PieSlice { label: "Employee"; value: 3066; color: "#DCEDC4" } + PieSlice { label: "Logistics"; value: 6111; color: "#F3F9EB" } - PieSlice { label: "Materials"; value: 7371; color: "#C0EEFF"; borderColor: "#3B391C" } - PieSlice { label: "Employee"; value: 2443; color: "#C9FAFF"; borderColor: "#3B391C" } - PieSlice { label: "Logistics"; value: 1291; color: "#B0FAFF"; borderColor: "#3B391C" } + PieSlice { label: "Materials"; value: 7371; color: "#63BCE9" } + PieSlice { label: "Employee"; value: 2443; color: "#A6D9F2" } + PieSlice { label: "Logistics"; value: 1291; color: "#E9F5FC" } - PieSlice { label: "Materials"; value: 4022; color: "#DF8939"; borderColor: "#13060C" } - PieSlice { label: "Employee"; value: 3998; color: "#FC9D42"; borderColor: "#13060C" } - PieSlice { label: "Logistics"; value: 1332; color: "#F2963F"; borderColor: "#13060C" } + PieSlice { label: "Materials"; value: 4022; color: "#F9C36C" } + PieSlice { label: "Employee"; value: 3998; color: "#FCE1B6" } + PieSlice { label: "Logistics"; value: 1332; color: "#FEF5E7" } } } diff --git a/examples/charts/qmlchart/qml/qmlchart/View4.qml b/examples/charts/qmlchart/qml/qmlchart/View4.qml index dc27a72a..5da50309 100644 --- a/examples/charts/qmlchart/qml/qmlchart/View4.qml +++ b/examples/charts/qmlchart/qml/qmlchart/View4.qml @@ -39,6 +39,7 @@ Item { anchors.fill: parent antialiasing: true + // Define x-axis to be used with the series instead of default one ValueAxis { id: valueAxis min: 2000 @@ -49,9 +50,6 @@ Item { AreaSeries { name: "Russian" - color: "#FFD52B1E" - borderColor: "#FF0039A5" - borderWidth: 3 axisX: valueAxis upperSeries: LineSeries { XYPoint { x: 2000; y: 1 } @@ -72,9 +70,6 @@ Item { AreaSeries { name: "Swedish" - color: "#AF005292" - borderColor: "#AFFDCA00" - borderWidth: 3 axisX: valueAxis upperSeries: LineSeries { XYPoint { x: 2000; y: 1 } @@ -94,9 +89,6 @@ Item { AreaSeries { name: "Finnish" - color: "#00357F" - borderColor: "#FEFEFE" - borderWidth: 3 axisX: valueAxis upperSeries: LineSeries { XYPoint { x: 2000; y: 0 } diff --git a/examples/charts/qmlchart/qml/qmlchart/main.qml b/examples/charts/qmlchart/qml/qmlchart/main.qml index 3d63eac6..e2e683d9 100644 --- a/examples/charts/qmlchart/qml/qmlchart/main.qml +++ b/examples/charts/qmlchart/qml/qmlchart/main.qml @@ -34,66 +34,19 @@ import QtQuick 2.0 Item { width: 600 height: 400 - property bool sourceLoaded: false - - ListView { - id: root - focus: true - anchors.fill: parent - snapMode: ListView.SnapOneItem - highlightRangeMode: ListView.StrictlyEnforceRange - highlightMoveDuration: 250 - orientation: ListView.Horizontal - boundsBehavior: Flickable.StopAtBounds + MainForm { + // Hide the default info text once view changes away from the first view onCurrentIndexChanged: { - if (infoText.opacity > 0.0) { + if (info.opacity > 0.0) { if (sourceLoaded) - infoText.opacity = 0.0; + info.opacity = 0.0; else if (currentIndex != 0) currentIndex = 0; } } - model: ListModel { - ListElement {component: "View1.qml"} - ListElement {component: "View2.qml"} - ListElement {component: "View3.qml"} - ListElement {component: "View4.qml"} - ListElement {component: "View5.qml"} - ListElement {component: "View6.qml"} - ListElement {component: "View7.qml"} - ListElement {component: "View8.qml"} - ListElement {component: "View9.qml"} - ListElement {component: "View10.qml"} - ListElement {component: "View11.qml"} - ListElement {component: "View12.qml"} - } - - delegate: Loader { - width: root.width - height: root.height - - source: component - asynchronous: true - - onLoaded: sourceLoaded = true - } - } - - Rectangle { - id: infoText - anchors.centerIn: parent - width: parent.width - height: 40 - color: "black" - Text { - color: "white" - anchors.centerIn: parent - text: "You can navigate between views using swipe or arrow keys" - } - - Behavior on opacity { + Behavior on info.opacity { NumberAnimation { duration: 400 } } } diff --git a/examples/charts/qmlchart/resources.qrc b/examples/charts/qmlchart/resources.qrc index 7b14dace..28b3a8a4 100644 --- a/examples/charts/qmlchart/resources.qrc +++ b/examples/charts/qmlchart/resources.qrc @@ -13,5 +13,6 @@ <file>qml/qmlchart/View10.qml</file> <file>qml/qmlchart/View11.qml</file> <file>qml/qmlchart/View12.qml</file> + <file>qml/qmlchart/MainForm.ui.qml</file> </qresource> </RCC> diff --git a/examples/charts/qmloscilloscope/datasource.cpp b/examples/charts/qmloscilloscope/datasource.cpp index 1d67c979..b773217b 100644 --- a/examples/charts/qmloscilloscope/datasource.cpp +++ b/examples/charts/qmloscilloscope/datasource.cpp @@ -33,6 +33,7 @@ #include <QtQuick/QQuickView> #include <QtQuick/QQuickItem> #include <QtCore/QDebug> +#include <QtCore/QRandomGenerator> #include <QtCore/QtMath> QT_CHARTS_USE_NAMESPACE @@ -80,7 +81,7 @@ void DataSource::generateData(int type, int rowCount, int colCount) switch (type) { case 0: // data with sin + random component - y = qSin(3.14159265358979 / 50 * j) + 0.5 + (qreal) rand() / (qreal) RAND_MAX; + y = qSin(M_PI / 50 * j) + 0.5 + QRandomGenerator::global()->generateDouble(); x = j; break; case 1: diff --git a/examples/charts/scatterchart/chartview.cpp b/examples/charts/scatterchart/chartview.cpp index c2f099c1..f96497bc 100644 --- a/examples/charts/scatterchart/chartview.cpp +++ b/examples/charts/scatterchart/chartview.cpp @@ -34,8 +34,6 @@ #include <QtGui/QPainter> #include <QtCore/QtMath> -const float Pi = 3.14159f; - ChartView::ChartView(QWidget *parent) : QChartView(new QChart(), parent) { @@ -71,8 +69,8 @@ ChartView::ChartView(QWidget *parent) : QPainterPath starPath; starPath.moveTo(28, 15); for (int i = 1; i < 5; ++i) { - starPath.lineTo(14 + 14 * qCos(0.8 * i * Pi), - 15 + 14 * qSin(0.8 * i * Pi)); + starPath.lineTo(14 + 14 * qCos(0.8 * i * M_PI), + 15 + 14 * qSin(0.8 * i * M_PI)); } starPath.closeSubpath(); diff --git a/examples/charts/stackedbarchartdrilldown/main.cpp b/examples/charts/stackedbarchartdrilldown/main.cpp index c2138f36..87035aea 100644 --- a/examples/charts/stackedbarchartdrilldown/main.cpp +++ b/examples/charts/stackedbarchartdrilldown/main.cpp @@ -29,6 +29,7 @@ #include <QtWidgets/QApplication> #include <QtWidgets/QMainWindow> +#include <QtCore/QRandomGenerator> #include <QtCharts/QChartView> #include <QtCharts/QBarSet> #include <QtCharts/QLegend> @@ -95,7 +96,7 @@ int main(int argc, char *argv[]) for (int month = 0; month < months.count(); month++) { QBarSet *weeklyCrop = new QBarSet(plant); for (int week = 0; week < weeks.count(); week++) - *weeklyCrop << (qrand() % 20); + *weeklyCrop << QRandomGenerator::global()->bounded(20); // Get the drilldown series from season series and add crop to it. seasonSeries->drilldownSeries(month)->append(weeklyCrop); *monthlyCrop << weeklyCrop->sum(); diff --git a/examples/charts/zoomlinechart/main.cpp b/examples/charts/zoomlinechart/main.cpp index 6a80982b..28a3d913 100644 --- a/examples/charts/zoomlinechart/main.cpp +++ b/examples/charts/zoomlinechart/main.cpp @@ -32,6 +32,7 @@ #include <QtWidgets/QApplication> #include <QtWidgets/QMainWindow> #include <QtCore/QtMath> +#include <QtCore/QRandomGenerator> #include <QtCharts/QLineSeries> #include <QtCharts/QValueAxis> @@ -45,7 +46,7 @@ int main(int argc, char *argv[]) QLineSeries *series = new QLineSeries(); for (int i = 0; i < 500; i++) { QPointF p((qreal) i, qSin(M_PI / 50 * i) * 100); - p.ry() += qrand() % 20; + p.ry() += QRandomGenerator::global()->bounded(20); *series << p; } //![1] diff --git a/src/charts/chartthememanager.cpp b/src/charts/chartthememanager.cpp index 2840b132..6d6f6cb7 100644 --- a/src/charts/chartthememanager.cpp +++ b/src/charts/chartthememanager.cpp @@ -28,7 +28,6 @@ ****************************************************************************/ #include <private/qabstractseries_p.h> #include <private/qabstractaxis_p.h> -#include <QtCore/QTime> //themes #include <private/chartthemesystem_p.h> #include <private/chartthemelight_p.h> @@ -45,7 +44,6 @@ QT_CHARTS_BEGIN_NAMESPACE ChartThemeManager::ChartThemeManager(QChart* chart) : m_chart(chart) { - qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); } diff --git a/src/charts/doc/images/examples_chartthemes_blue_cerulean.png b/src/charts/doc/images/examples_chartthemes_blue_cerulean.png Binary files differindex 69ac3793..858cd7b4 100644 --- a/src/charts/doc/images/examples_chartthemes_blue_cerulean.png +++ b/src/charts/doc/images/examples_chartthemes_blue_cerulean.png diff --git a/src/charts/doc/images/examples_chartthemes_brown_sand.png b/src/charts/doc/images/examples_chartthemes_brown_sand.png Binary files differindex ff5157a9..071595ed 100644 --- a/src/charts/doc/images/examples_chartthemes_brown_sand.png +++ b/src/charts/doc/images/examples_chartthemes_brown_sand.png diff --git a/src/charts/doc/images/examples_chartthemes_light.png b/src/charts/doc/images/examples_chartthemes_light.png Binary files differindex e6a64992..dedb6c6d 100644 --- a/src/charts/doc/images/examples_chartthemes_light.png +++ b/src/charts/doc/images/examples_chartthemes_light.png diff --git a/src/charts/doc/images/examples_qmlchart1.png b/src/charts/doc/images/examples_qmlchart1.png Binary files differindex 6a3c7812..38e7ab27 100644 --- a/src/charts/doc/images/examples_qmlchart1.png +++ b/src/charts/doc/images/examples_qmlchart1.png diff --git a/src/charts/doc/images/examples_qmlchart10.png b/src/charts/doc/images/examples_qmlchart10.png Binary files differindex 5fdd744c..e0429509 100644 --- a/src/charts/doc/images/examples_qmlchart10.png +++ b/src/charts/doc/images/examples_qmlchart10.png diff --git a/src/charts/doc/images/examples_qmlchart11.png b/src/charts/doc/images/examples_qmlchart11.png Binary files differindex 663967e7..dc072154 100644 --- a/src/charts/doc/images/examples_qmlchart11.png +++ b/src/charts/doc/images/examples_qmlchart11.png diff --git a/src/charts/doc/images/examples_qmlchart12.png b/src/charts/doc/images/examples_qmlchart12.png Binary files differindex e00465ad..e25945af 100644 --- a/src/charts/doc/images/examples_qmlchart12.png +++ b/src/charts/doc/images/examples_qmlchart12.png diff --git a/src/charts/doc/images/examples_qmlchart2.png b/src/charts/doc/images/examples_qmlchart2.png Binary files differindex 36a7873b..bcff9b95 100644 --- a/src/charts/doc/images/examples_qmlchart2.png +++ b/src/charts/doc/images/examples_qmlchart2.png diff --git a/src/charts/doc/images/examples_qmlchart3.png b/src/charts/doc/images/examples_qmlchart3.png Binary files differindex 74e3299c..d97636fd 100644 --- a/src/charts/doc/images/examples_qmlchart3.png +++ b/src/charts/doc/images/examples_qmlchart3.png diff --git a/src/charts/doc/images/examples_qmlchart4.png b/src/charts/doc/images/examples_qmlchart4.png Binary files differindex 7b0d96a3..5f2e3c56 100644 --- a/src/charts/doc/images/examples_qmlchart4.png +++ b/src/charts/doc/images/examples_qmlchart4.png diff --git a/src/charts/doc/images/examples_qmlchart5.png b/src/charts/doc/images/examples_qmlchart5.png Binary files differindex 129a4e90..76a61f9d 100644 --- a/src/charts/doc/images/examples_qmlchart5.png +++ b/src/charts/doc/images/examples_qmlchart5.png diff --git a/src/charts/doc/images/examples_qmlchart6.png b/src/charts/doc/images/examples_qmlchart6.png Binary files differindex 6968ffe3..2cfc889d 100644 --- a/src/charts/doc/images/examples_qmlchart6.png +++ b/src/charts/doc/images/examples_qmlchart6.png diff --git a/src/charts/doc/images/examples_qmlchart7.png b/src/charts/doc/images/examples_qmlchart7.png Binary files differindex acf29aed..99604414 100644 --- a/src/charts/doc/images/examples_qmlchart7.png +++ b/src/charts/doc/images/examples_qmlchart7.png diff --git a/src/charts/doc/images/examples_qmlchart8.png b/src/charts/doc/images/examples_qmlchart8.png Binary files differindex d1671758..3c4147b6 100644 --- a/src/charts/doc/images/examples_qmlchart8.png +++ b/src/charts/doc/images/examples_qmlchart8.png diff --git a/src/charts/doc/images/examples_qmlchart9.png b/src/charts/doc/images/examples_qmlchart9.png Binary files differindex 1ebbc7dc..c8a236fe 100644 --- a/src/charts/doc/images/examples_qmlchart9.png +++ b/src/charts/doc/images/examples_qmlchart9.png diff --git a/src/charts/doc/qtcharts.qdocconf b/src/charts/doc/qtcharts.qdocconf index 31d53d4f..ce695886 100644 --- a/src/charts/doc/qtcharts.qdocconf +++ b/src/charts/doc/qtcharts.qdocconf @@ -59,4 +59,5 @@ navigation.landingpage = Qt Charts navigation.cppclassespage = Qt Charts C++ Classes navigation.qmltypespage = Qt Charts QML Types -manifestmeta.highlighted.names += "QtCharts/Chart Themes Example" +manifestmeta.highlighted.names = "QtCharts/Chart Themes Example" \ + "QtCharts/Qml Charts Example" diff --git a/src/charts/doc/src/examples-chartthemes.qdoc b/src/charts/doc/src/examples-chartthemes.qdoc index bc9612bb..fc87f765 100644 --- a/src/charts/doc/src/examples-chartthemes.qdoc +++ b/src/charts/doc/src/examples-chartthemes.qdoc @@ -34,13 +34,76 @@ \brief The example shows the look and feel of the different built-in themes. - This example shows the look and feel of the different built-in themes for all supported chart - types. In order to give the result a more harmonious look, the background palette of the - application is customized to the theme selected. + This example shows the look and feel of the different built-in themes for some of the supported + chart types. \image examples_chartthemes_light.png \image examples_chartthemes_brown_sand.png \image examples_chartthemes_blue_cerulean.png \include examples-run.qdocinc + + \section1 Creating Charts + + The charts of different types are generated and added to the layout separately. For example, the + line chart is created as follows. The creation of other chart types is similar. + + First a chart is created. + + \snippet chartthemes/themewidget.cpp 1 + + A common set of random data is generated and placed in a list. This list is used in each chart + type to add data to the series of the chart. For the line series, QLineSeries instances are + created and added to the chart. + + \snippet chartthemes/themewidget.cpp 2 + + Default axes are created for the line series. We also specify ranges for the axes based on the + range of the data used for the series. + + \snippet chartthemes/themewidget.cpp 3 + + We also want to add more space between the labels and the y-axes. For this we specify a label + format that adds space characters to the labels. + + \snippet chartthemes/themewidget.cpp 4 + + Finally the line chart is added to the grid layout. + + \snippet chartthemes/themewidget.cpp 5 + + \section1 Changing Theme + + The user can select a built-in theme to be used in the example. This theme is then applied to + all charts in the layout. + + \snippet chartthemes/themewidget.cpp 6 + + \snippet chartthemes/themewidget.cpp 7 + + In order to give the result a more harmonious look, the background palette of the application is + customized to match the selected theme. The QPalette::Window and QPalette::WindowText roles are + set based on the selected theme. + + \snippet chartthemes/themewidget.cpp 8 + + \section1 Changing Animation, Legend and Anti-Aliasing + + In this example, it is also possible to see how changing animation, legend and anti-aliasing + affects the appearance of the chart. + + Based on the user's selection, the used animation type is set on each chart. It is possible to have + no animations in the chart, or have animations for grid axis or series, or both. + + \snippet chartthemes/themewidget.cpp 9 + + The chart can be shown with a legend. The legend can be aligned to different sides of the chart. + + \snippet chartthemes/themewidget.cpp 10 + + The user can also see how changing anti-aliasing option changes the appearance of the chart. + Anti-aliasing is updated based on the user's selection. + + \snippet chartthemes/themewidget.cpp 11 + */ diff --git a/src/charts/domain/polardomain.cpp b/src/charts/domain/polardomain.cpp index 1d5154e4..3c6e6b57 100644 --- a/src/charts/domain/polardomain.cpp +++ b/src/charts/domain/polardomain.cpp @@ -89,8 +89,8 @@ QVector<QPointF> PolarDomain::calculateGeometryPoints(const QVector<QPointF> &ve QPointF PolarDomain::polarCoordinateToPoint(qreal angularCoordinate, qreal radialCoordinate) const { - qreal dx = qSin(angularCoordinate * (M_PI / 180)) * radialCoordinate; - qreal dy = qCos(angularCoordinate * (M_PI / 180)) * radialCoordinate; + qreal dx = qSin(qDegreesToRadians(angularCoordinate)) * radialCoordinate; + qreal dy = qCos(qDegreesToRadians(angularCoordinate)) * radialCoordinate; return QPointF(dx, -dy); } diff --git a/src/charts/piechart/piesliceitem.cpp b/src/charts/piechart/piesliceitem.cpp index 19d6e4ef..05a790e4 100644 --- a/src/charts/piechart/piesliceitem.cpp +++ b/src/charts/piechart/piesliceitem.cpp @@ -43,8 +43,8 @@ QT_CHARTS_BEGIN_NAMESPACE QPointF offset(qreal angle, qreal length) { - qreal dx = qSin(angle * (M_PI / 180)) * length; - qreal dy = qCos(angle * (M_PI / 180)) * length; + qreal dx = qSin(qDegreesToRadians(angle)) * length; + qreal dy = qCos(qDegreesToRadians(angle)) * length; return QPointF(dx, -dy); } diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 321ca26c..81557a7f 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -37,9 +37,6 @@ SUBDIRS += \ qtHaveModule(quick) { SUBDIRS += qml \ qml-qtquicktest - - # QTBUG-20268 - boot2qt: SUBDIRS -= qml-qtquicktest } !contains(QT_CONFIG, private_tests): SUBDIRS -= \ diff --git a/tests/auto/qchart/BLACKLIST b/tests/auto/qchart/BLACKLIST deleted file mode 100644 index a73cce28..00000000 --- a/tests/auto/qchart/BLACKLIST +++ /dev/null @@ -1,3 +0,0 @@ -[zoomOut] -# QTBUG-20268 -b2qt diff --git a/tests/auto/qchart/tst_qchart.cpp b/tests/auto/qchart/tst_qchart.cpp index 8ca2b0e0..7347f16b 100644 --- a/tests/auto/qchart/tst_qchart.cpp +++ b/tests/auto/qchart/tst_qchart.cpp @@ -902,8 +902,8 @@ void tst_QChart::zoomOut() else QCOMPARE(minY, axisY->min()); - QVERIFY(maxX == axisX->max()); - QVERIFY(maxY == axisY->max()); + QCOMPARE(maxX, axisX->max()); + QCOMPARE(maxY, axisY->max()); } diff --git a/tests/auto/qxyseries/qlineseries.pro b/tests/auto/qxyseries/qlineseries.pro deleted file mode 100644 index cb353869..00000000 --- a/tests/auto/qxyseries/qlineseries.pro +++ /dev/null @@ -1,6 +0,0 @@ -!include( ../auto.pri ) { - error( "Couldn't find the auto.pri file!" ) -} -SOURCES += tst_qlineseries.cpp - -!system_build:mac: QMAKE_POST_LINK += "$$MAC_POST_LINK_PREFIX $$MAC_AUTOTESTS_BIN_DIR" diff --git a/tests/auto/qxyseries/tst_qxyseries.cpp b/tests/auto/qxyseries/tst_qxyseries.cpp index 767caca2..de878679 100644 --- a/tests/auto/qxyseries/tst_qxyseries.cpp +++ b/tests/auto/qxyseries/tst_qxyseries.cpp @@ -325,7 +325,7 @@ void tst_QXYSeries::remove_raw() // (simulate e.g. spamming a hypothetical "remove last point"-button) QList<QPointF> bunchOfPoints; for (int i = 0; i < 10; i++) - bunchOfPoints.append(QPointF(i, (qreal) rand() / (qreal) RAND_MAX)); + bunchOfPoints.append(QPointF(i, QRandomGenerator::global()->generateDouble())); m_series->replace(bunchOfPoints); QCOMPARE(m_series->points(), bunchOfPoints); QTest::qWait(1500); // Wait for append animations to be over @@ -337,7 +337,7 @@ void tst_QXYSeries::remove_raw() // Removal using index for (int i = 0; i < 10; i++) - bunchOfPoints.append(QPointF(i, (qreal) rand() / (qreal) RAND_MAX)); + bunchOfPoints.append(QPointF(i, QRandomGenerator::global()->generateDouble())); m_series->replace(bunchOfPoints); m_series->remove(5); m_series->remove(0); @@ -350,7 +350,7 @@ void tst_QXYSeries::remove_raw() // Multiple removal using index for (int i = 0; i < 10; i++) - bunchOfPoints.append(QPointF(i, (qreal) rand() / (qreal) RAND_MAX)); + bunchOfPoints.append(QPointF(i, QRandomGenerator::global()->generateDouble())); m_series->replace(bunchOfPoints); m_series->removePoints(5, 2); m_series->removePoints(0, 3); @@ -463,7 +463,7 @@ void tst_QXYSeries::replace_raw() // Replace all points QList<QPointF> allPoints; for (int i = 0; i < 10; i++) - allPoints.append(QPointF(i, (qreal) rand() / (qreal) RAND_MAX)); + allPoints.append(QPointF(i, QRandomGenerator::global()->generateDouble())); m_series->replace(allPoints); TRY_COMPARE(pointReplacedSpy.count(), points.count()); TRY_COMPARE(pointsReplacedSpy.count(), 1); diff --git a/tests/manual/barcharttester/chart-widget.cpp b/tests/manual/barcharttester/chart-widget.cpp index 6e7157b1..3c58f5ce 100644 --- a/tests/manual/barcharttester/chart-widget.cpp +++ b/tests/manual/barcharttester/chart-widget.cpp @@ -40,7 +40,6 @@ #include <QtCharts/QHorizontalStackedBarSeries> #include <QtCharts/QPercentBarSeries> #include <QtCharts/QStackedBarSeries> -#include <QtCore/QTime> #include <QElapsedTimer> #include <QDebug> @@ -152,8 +151,6 @@ ChartWidget::ChartWidget(QWidget *parent) : series->setBarWidth(barWidth); } - qsrand((uint) QTime::currentTime().msec()); - resize(800, 300); m_horizontalLayout = new QHBoxLayout(this); m_horizontalLayout->setSpacing(6); diff --git a/tests/manual/candlesticktester/mainwidget.cpp b/tests/manual/candlesticktester/mainwidget.cpp index 9c902a3f..ec2d5bd8 100644 --- a/tests/manual/candlesticktester/mainwidget.cpp +++ b/tests/manual/candlesticktester/mainwidget.cpp @@ -35,6 +35,7 @@ #include <QtCharts/QValueAxis> #include <QtCore/QDateTime> #include <QtCore/QDebug> +#include <QtCore/QRandomGenerator> #include <QtWidgets/QCheckBox> #include <QtWidgets/QComboBox> #include <QtWidgets/QDoubleSpinBox> @@ -64,8 +65,6 @@ MainWidget::MainWidget(QWidget *parent) m_customDecreasingColor(false), m_hModelMapper(new QHCandlestickModelMapper(this)) { - qsrand(QDateTime::currentDateTime().toTime_t()); - m_chartView->setRenderHint(QPainter::Antialiasing, false); m_hModelMapper->setModel(new CustomTableModel(this)); @@ -285,7 +284,9 @@ QGridLayout *MainWidget::createModelMapperControlsLayout() qreal MainWidget::randomValue(int min, int max) const { - return (qrand() / (qreal(RAND_MAX) + 1)) * ((qMax(min, max) - qMin(min, max)) + qMin(min, max)); + if (min > max) + qSwap(min, max); + return QRandomGenerator::global()->bounded(min, max); } QCandlestickSet *MainWidget::randomSet(qreal timestamp) diff --git a/tests/manual/chartviewer/model.h b/tests/manual/chartviewer/model.h index fcc53724..a4c3aa3c 100644 --- a/tests/manual/chartviewer/model.h +++ b/tests/manual/chartviewer/model.h @@ -33,8 +33,8 @@ #include <QtCore/QList> #include <QtCore/QPair> #include <QtCore/QPointF> +#include <QtCore/QRandomGenerator> #include <QtCore/QTime> -#include <stdlib.h> typedef QPair<QPointF, QString> Data; typedef QList<Data> DataList; @@ -51,17 +51,14 @@ public: { DataTable dataTable; - // set seed for random stuff - qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); - // generate random data for (int i(0); i < listCount; i++) { DataList dataList; qreal yValue(0.1); for (int j(0); j < valueCount; j++) { - yValue = yValue + (qreal)(qrand() % valueMax) / (qreal) valueCount; + yValue = yValue + QRandomGenerator::global()->bounded(valueMax / (qreal) valueCount); QPointF value( - (j + (qreal) qrand() / (qreal) RAND_MAX) + (j + QRandomGenerator::global()->generateDouble()) * ((qreal) valueMax / (qreal) valueCount), yValue); QString label = "Slice " + QString::number(i) + ":" + QString::number(j); dataList << Data(value, label); diff --git a/tests/manual/chartwidgettest/mainwidget.cpp b/tests/manual/chartwidgettest/mainwidget.cpp index da44298e..ebb00f22 100644 --- a/tests/manual/chartwidgettest/mainwidget.cpp +++ b/tests/manual/chartwidgettest/mainwidget.cpp @@ -49,12 +49,12 @@ #include <QtWidgets/QSpacerItem> #include <QtWidgets/QMessageBox> #include <QtCore/QDebug> +#include <QtCore/QRandomGenerator> #include <QtGui/QStandardItemModel> #include <QtCharts/QBarCategoryAxis> #include <QtWidgets/QOpenGLWidget> -#include <math.h> -#include <cmath> +#include <qmath.h> QT_CHARTS_USE_NAMESPACE @@ -218,11 +218,11 @@ QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QStr QList <qreal> newColumn; for (int i(0); i < rowCount; i++) { if (dataCharacteristics == "Sin") { - newColumn.append(std::abs(sin(3.14159265358979 / 50 * i) * 100)); + newColumn.append(std::abs(sin(M_PI / 50 * i) * 100)); } else if (dataCharacteristics == "Sin + random") { - newColumn.append(std::abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); + newColumn.append(std::abs(sin(M_PI / 50 * i) * 100) + QRandomGenerator::global()->bounded(5)); } else if (dataCharacteristics == "Random") { - newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX); + newColumn.append(QRandomGenerator::global()->bounded(11.0)); } else if (dataCharacteristics == "Linear") { //newColumn.append(i * (j + 1.0)); // TODO: temporary hack to make pie work; prevent zero values: diff --git a/tests/manual/openglseriestest/datasource.cpp b/tests/manual/openglseriestest/datasource.cpp index 459b9f01..dbf6874c 100644 --- a/tests/manual/openglseriestest/datasource.cpp +++ b/tests/manual/openglseriestest/datasource.cpp @@ -29,6 +29,7 @@ #include "datasource.h" #include <QtCore/QtMath> +#include <QtCore/QRandomGenerator> QT_CHARTS_USE_NAMESPACE @@ -117,8 +118,8 @@ void DataSource::generateData(int seriesIndex, int rowCount, int colCount) qreal x(0); qreal y(0); // data with sin + random component - y = height + (yMultiplier * qSin(3.14159265358979 / 50 * j) - + (yMultiplier * (qreal) rand() / (qreal) RAND_MAX)); + y = height + (yMultiplier * qSin(M_PI / 50 * j) + + (yMultiplier * QRandomGenerator::global()->generateDouble())); // 0.000001 added to make values logaxis compatible x = 0.000001 + 20.0 * (qreal(j) / qreal(colCount)) + (xAdjustment * qreal(i)); points.append(QPointF(x, y)); diff --git a/tests/manual/openglseriestest/mainwindow.cpp b/tests/manual/openglseriestest/mainwindow.cpp index 4aaeed13..1497dad8 100644 --- a/tests/manual/openglseriestest/mainwindow.cpp +++ b/tests/manual/openglseriestest/mainwindow.cpp @@ -36,6 +36,7 @@ #include <QtCharts/QDateTimeAxis> #include <QtCharts/QCategoryAxis> #include <QtCharts/QChart> +#include <QtCore/QRandomGenerator> #include <QtCore/QDebug> #include <QtCore/QDateTime> @@ -548,7 +549,7 @@ void MainWindow::addSeries(bool gl) if (m_seriesList.size() < maxSeriesCount) { QXYSeries *series; - if (qrand() % 2) { + if (QRandomGenerator::global()->bounded(2)) { series = new QLineSeries; series->setPen(QPen(QBrush(color), width)); } else { diff --git a/tests/manual/presenterchart/chartview.cpp b/tests/manual/presenterchart/chartview.cpp index 4bbf8080..b7d575de 100644 --- a/tests/manual/presenterchart/chartview.cpp +++ b/tests/manual/presenterchart/chartview.cpp @@ -32,7 +32,7 @@ #include <QtCharts/QScatterSeries> #include <QtCharts/QSplineSeries> #include <QtCharts/QAreaSeries> -#include <QtCore/QTime> +#include <QtCore/QRandomGenerator> ChartView::ChartView(QChart *chart, QWidget *parent) : QChartView(chart, parent), @@ -62,7 +62,7 @@ ChartView::ChartView(QChart *chart, QWidget *parent) int numPoints = 10; for (int x = 0; x <= numPoints; ++x) { - qreal y = qrand() % 100; + qreal y = QRandomGenerator::global()->bounded(100); series0->append(x, y); series1->append(x, y); series2->append(x, y); diff --git a/tests/manual/wavechart/wavechart.cpp b/tests/manual/wavechart/wavechart.cpp index b8abff92..695ddc72 100644 --- a/tests/manual/wavechart/wavechart.cpp +++ b/tests/manual/wavechart/wavechart.cpp @@ -28,18 +28,18 @@ ****************************************************************************/ #include "wavechart.h" -#include <math.h> +#include <qmath.h> +#include <qrandom.h> QT_CHARTS_USE_NAMESPACE -#define PI 3.14159265358979 static const int numPoints =100; WaveChart::WaveChart(QChart* chart, QWidget* parent) : QChartView(chart, parent), m_series(new QLineSeries()), m_wave(0), - m_step(2 * PI / numPoints) + m_step(2 * M_PI / numPoints) { QPen blue(Qt::blue); blue.setWidth(3); @@ -47,12 +47,9 @@ WaveChart::WaveChart(QChart* chart, QWidget* parent) : chart->legend()->setVisible(false); - QTime now = QTime::currentTime(); - qsrand((uint) now.msec()); - int fluctuate = 100; - for (qreal x = 0; x <= 2 * PI; x += m_step) { + for (qreal x = 0; x <= 2 * M_PI; x += m_step) { m_series->append(x, fabs(sin(x) * fluctuate)); } @@ -69,8 +66,8 @@ void WaveChart::update() int fluctuate; const QList<QPointF>& points = m_series->points(); - for (qreal i = 0, x = 0; x <= 2 * PI; x += m_step, i++) { - fluctuate = qrand() % 100; + for (qreal i = 0, x = 0; x <= 2 * M_PI; x += m_step, i++) { + fluctuate = QRandomGenerator::global()->bounded(100); m_series->replace(x,points[i].y(),x,fabs(sin(x) * fluctuate)); } |