Skip to content

Commit

Permalink
Using std::shuffle breaks on Qt5 on recent MinGW
Browse files Browse the repository at this point in the history
  • Loading branch information
VSRonin committed Mar 7, 2024
1 parent 433063d commit 12bf339
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
17 changes: 17 additions & 0 deletions tests/modeltestmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ using ComplexModel = GenericModel;
# endif
#endif

#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
namespace ModelTestManager {
int generateRandomNumber()
{
return std::rand();
}
}
#else
# include <QRandomGenerator>
namespace ModelTestManager {
int generateRandomNumber()
{
return QRandomGenerator::global()->generate();
}
}
#endif

#ifndef SKIP_QTBUG_92220
# if (QT_VERSION < QT_VERSION_CHECK(5, 13, 0) || (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) && QT_VERSION <= QT_VERSION_CHECK(6, 0, 3)))
# define SKIP_QTBUG_92220
Expand Down
20 changes: 8 additions & 12 deletions tests/tst_GenericModel/tst_genericmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3236,33 +3236,29 @@ void tst_GenericModel::bSort_data()

void tst_GenericModel::bSort()
{
#ifdef QT_GUI_LIB

QFETCH(bool, useGenericModel);
QFETCH(bool, useTable);
QAbstractItemModel *model = nullptr;
if (useGenericModel)
model = new GenericModel;
#ifdef QT_GUI_LIB
else
model = new QStandardItemModel;
#else
QSKIP("This benchmark requires the Qt GUI module");
#endif
if (!model)
return;
model->insertColumns(0, useTable ? 5 : 1);
model->insertRows(0, 50000);
QVector<int> numData;
numData.reserve(model->rowCount());
for (int ri = 0, maxR = model->rowCount(); ri < maxR; ++ri)
numData.append(ri);
std::random_device rd;
std::default_random_engine g(rd());
std::shuffle(numData.begin(), numData.end(), g);
for (int ri = 0, maxR = model->rowCount(); ri < maxR; ++ri) {
for (int ci = 0, maxC = model->columnCount(); ci < maxC; ++ci)
model->setData(model->index(ri, ci), numData.at(ri));
model->setData(model->index(ri, ci), ModelTestManager::generateRandomNumber());
}
QBENCHMARK_ONCE {
model->sort(0);
}
#else
QSKIP("This benchmark requires the Qt GUI module");
#endif
}

void tst_GenericModel::fillTable(QAbstractItemModel *model, int rows, int cols, const QModelIndex &parent, int shift) const
Expand Down

0 comments on commit 12bf339

Please sign in to comment.