diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2017-06-12 16:01:04 -0700 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2017-07-04 11:46:00 +0000 |
commit | dbb55fba566fd3878b5ef76a2216f0c3f961147f (patch) | |
tree | 0c6f4a7a5cfb7dcfa41c88b205ddb155530b228d /examples/charts | |
parent | 94f565a00cbc8d779251355cdb94704277711da7 (diff) |
Use QRandomGenerator instead of q?rand
Change-Id: Icd0e0d4b27cb4e5eb892fffd14b5285d43f4afbf
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'examples/charts')
-rw-r--r-- | examples/charts/barmodelmapper/customtablemodel.cpp | 7 | ||||
-rw-r--r-- | examples/charts/chartthemes/themewidget.cpp | 9 | ||||
-rw-r--r-- | examples/charts/datetimeaxis/main.cpp | 1 | ||||
-rw-r--r-- | examples/charts/dynamicspline/chart.cpp | 6 | ||||
-rw-r--r-- | examples/charts/modeldata/customtablemodel.cpp | 8 | ||||
-rw-r--r-- | examples/charts/nesteddonuts/widget.cpp | 9 | ||||
-rw-r--r-- | examples/charts/openglseries/datasource.cpp | 3 | ||||
-rw-r--r-- | examples/charts/piechartdrilldown/main.cpp | 6 | ||||
-rw-r--r-- | examples/charts/qmloscilloscope/datasource.cpp | 3 | ||||
-rw-r--r-- | examples/charts/stackedbarchartdrilldown/main.cpp | 3 | ||||
-rw-r--r-- | examples/charts/zoomlinechart/main.cpp | 3 |
11 files changed, 25 insertions, 33 deletions
diff --git a/examples/charts/barmodelmapper/customtablemodel.cpp b/examples/charts/barmodelmapper/customtablemodel.cpp index 23b5271c..2caef9b5 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::bounded(20)); else - dataVec->replace(k, qrand() % 100); + dataVec->replace(k, QRandomGenerator::bounded(100)); } m_data.append(dataVec); } diff --git a/examples/charts/chartthemes/themewidget.cpp b/examples/charts/chartthemes/themewidget.cpp index 9739dde1..6f408c75 100644 --- a/examples/charts/chartthemes/themewidget.cpp +++ b/examples/charts/chartthemes/themewidget.cpp @@ -49,7 +49,7 @@ #include <QtWidgets/QCheckBox> #include <QtWidgets/QGroupBox> #include <QtWidgets/QLabel> -#include <QtCore/QTime> +#include <QtCore/QRandomGenerator> #include <QtCharts/QBarCategoryAxis> ThemeWidget::ThemeWidget(QWidget *parent) : @@ -129,16 +129,13 @@ DataTable ThemeWidget::generateRandomData(int listCount, int valueMax, int value { 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::bounded(valueMax / (qreal) valueCount); + QPointF value((j + QRandomGenerator::getReal()) * ((qreal) m_valueMax / (qreal) valueCount), yValue); QString label = "Slice " + QString::number(i) + ":" + QString::number(j); dataList << Data(value, label); 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 264f2460..9f33423c 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, SIGNAL(timeout()), this, SLOT(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::bounded(5) - 2.5; m_series->append(m_x, m_y); scroll(x, 0); if (m_x == 100) diff --git a/examples/charts/modeldata/customtablemodel.cpp b/examples/charts/modeldata/customtablemodel.cpp index 1bc607be..98cd8c8c 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::bounded(20)); else - dataVec->replace(k, qrand() % 100); + dataVec->replace(k, QRandomGenerator::bounded(100)); } m_data.append(dataVec); } diff --git a/examples/charts/nesteddonuts/widget.cpp b/examples/charts/nesteddonuts/widget.cpp index 35860a01..533b8969 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::bounded(3); for (int j = 0; j < sliceCount; j++) { - qreal value = 100 + qrand() % 100; + qreal value = 100 + QRandomGenerator::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::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 291bc722..1448e54e 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 @@ -118,7 +119,7 @@ void DataSource::generateData(int seriesCount, int rowCount, int colCount) qreal y(0); // data with sin + random component y = height + (yMultiplier * qSin(M_PI / 50 * j) - + (yMultiplier * (qreal) rand() / (qreal) RAND_MAX)); + + (yMultiplier * QRandomGenerator::getReal())); // 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 69f87158..bea7fb3c 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(); @@ -65,7 +63,7 @@ int main(int argc, char *argv[]) series->setName("Sales by month - " + name); foreach (QString month, months) - *series << new DrilldownSlice(qrand() % 1000, month, yearSeries); + *series << new DrilldownSlice(QRandomGenerator::bounded(1000), month, yearSeries); QObject::connect(series, SIGNAL(clicked(QPieSlice*)), chart, SLOT(handleSliceClicked(QPieSlice*))); diff --git a/examples/charts/qmloscilloscope/datasource.cpp b/examples/charts/qmloscilloscope/datasource.cpp index f687beb0..1f6c7272 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 @@ -82,7 +83,7 @@ void DataSource::generateData(int type, int rowCount, int colCount) switch (type) { case 0: // data with sin + random component - y = qSin(M_PI / 50 * j) + 0.5 + (qreal) rand() / (qreal) RAND_MAX; + y = qSin(M_PI / 50 * j) + 0.5 + QRandomGenerator::getReal(); x = j; break; case 1: diff --git a/examples/charts/stackedbarchartdrilldown/main.cpp b/examples/charts/stackedbarchartdrilldown/main.cpp index c3e03505..f4bbc3f0 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> @@ -90,7 +91,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::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..b3c6a33f 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::bounded(20); *series << p; } //![1] |