Commit 56720037 authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Port to std::shuffle

std::random_shuffle is gone in C++17
parent 4936e523
......@@ -30,6 +30,7 @@ SlideFilterModel::SlideFilterModel(QObject *parent)
: QSortFilterProxyModel{parent}
, m_SortingMode{Image::Random}
, m_usedInConfig{false}
, m_random(m_randomDevice())
{
srand(time(nullptr));
setSortCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive);
......@@ -60,7 +61,7 @@ void SlideFilterModel::setSourceModel(QAbstractItemModel *sourceModel)
const int old_count = m_randomOrder.size();
m_randomOrder.resize(this->sourceModel()->rowCount());
std::iota(m_randomOrder.begin() + old_count, m_randomOrder.end(), old_count);
std::random_shuffle(m_randomOrder.begin() + old_count, m_randomOrder.end());
std::shuffle(m_randomOrder.begin() + old_count, m_randomOrder.end(), m_random);
});
connect(sourceModel, &QAbstractItemModel::rowsRemoved, this, [this] {
if (m_SortingMode != Image::Random || m_usedInConfig) {
......@@ -116,7 +117,7 @@ void SlideFilterModel::setSortingMode(Image::SlideshowMode mode)
void SlideFilterModel::invalidate()
{
if (m_SortingMode == Image::Random && !m_usedInConfig) {
std::random_shuffle(m_randomOrder.begin(), m_randomOrder.end());
std::shuffle(m_randomOrder.begin(), m_randomOrder.end(), m_random);
}
QSortFilterProxyModel::invalidate();
}
......@@ -143,6 +144,6 @@ void SlideFilterModel::buildRandomOrder()
if (sourceModel()) {
m_randomOrder.resize(sourceModel()->rowCount());
std::iota(m_randomOrder.begin(), m_randomOrder.end(), 0);
std::random_shuffle(m_randomOrder.begin(), m_randomOrder.end());
std::shuffle(m_randomOrder.begin(), m_randomOrder.end(), m_random);
}
}
......@@ -24,6 +24,8 @@
#include <QSortFilterProxyModel>
#include <QVector>
#include <random>
class SlideFilterModel : public QSortFilterProxyModel
{
Q_OBJECT
......@@ -51,5 +53,7 @@ private:
QVector<int> m_randomOrder;
Image::SlideshowMode m_SortingMode;
bool m_usedInConfig;
std::random_device m_randomDevice;
std::mt19937 m_random;
};
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment