summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/charts/barmodelmapper/customtablemodel.cpp7
-rw-r--r--examples/charts/chartthemes/themewidget.cpp9
-rw-r--r--examples/charts/datetimeaxis/main.cpp1
-rw-r--r--examples/charts/dynamicspline/chart.cpp6
-rw-r--r--examples/charts/legendmarkers/mainwidget.cpp2
-rw-r--r--examples/charts/modeldata/customtablemodel.cpp8
-rw-r--r--examples/charts/nesteddonuts/widget.cpp9
-rw-r--r--examples/charts/openglseries/datasource.cpp5
-rw-r--r--examples/charts/piechartdrilldown/main.cpp6
-rw-r--r--examples/charts/qmloscilloscope/datasource.cpp3
-rw-r--r--examples/charts/scatterchart/chartview.cpp6
-rw-r--r--examples/charts/stackedbarchartdrilldown/main.cpp3
-rw-r--r--examples/charts/zoomlinechart/main.cpp3
13 files changed, 29 insertions, 39 deletions
diff --git a/examples/charts/barmodelmapper/customtablemodel.cpp b/examples/charts/barmodelmapper/customtablemodel.cpp
index a1446386..71165dff 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 982c50e0..f1f28af4 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) :
@@ -136,16 +136,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 21985998..ee7061d2 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::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..e36a5d3d 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 3d2292c8..f8090455 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 5f554500..b5992214 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::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 8deeb0c3..1fed557a 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::bounded(1000), month, yearSeries);
QObject::connect(series, &QPieSeries::clicked, chart, &DrilldownChart::handleSliceClicked);
diff --git a/examples/charts/qmloscilloscope/datasource.cpp b/examples/charts/qmloscilloscope/datasource.cpp
index 1d67c979..dddee543 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::getReal();
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..46d00190 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::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]