Changeset View
Changeset View
Standalone View
Standalone View
wallpapers/image/slidefiltermodel.cpp
Show All 25 Lines | |||||
26 | 26 | | |||
27 | #include <algorithm> | 27 | #include <algorithm> | ||
28 | 28 | | |||
29 | SlideFilterModel::SlideFilterModel(QObject* parent) | 29 | SlideFilterModel::SlideFilterModel(QObject* parent) | ||
30 | : QSortFilterProxyModel{parent} | 30 | : QSortFilterProxyModel{parent} | ||
31 | , m_SortingMode{Image::Random} | 31 | , m_SortingMode{Image::Random} | ||
32 | , m_usedInConfig{false} | 32 | , m_usedInConfig{false} | ||
33 | { | 33 | { | ||
34 | srand(time(nullptr)); | ||||
34 | setSortCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive); | 35 | setSortCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive); | ||
35 | connect(this, &SlideFilterModel::usedInConfigChanged, this, &SlideFilterModel::invalidateFilter); | 36 | connect(this, &SlideFilterModel::usedInConfigChanged, this, &SlideFilterModel::invalidateFilter); | ||
36 | } | 37 | } | ||
37 | 38 | | |||
38 | bool SlideFilterModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const | 39 | bool SlideFilterModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const | ||
39 | { | 40 | { | ||
40 | auto index = sourceModel()->index(source_row, 0, source_parent); | 41 | auto index = sourceModel()->index(source_row, 0, source_parent); | ||
41 | return m_usedInConfig || index.data(BackgroundListModel::ToggleRole).toBool(); | 42 | return m_usedInConfig || index.data(BackgroundListModel::ToggleRole).toBool(); | ||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Line(s) | 130 | { | |||
131 | static_cast<SlideModel*>(sourceModel())->openContainingFolder(sourceIndex.row()); | 132 | static_cast<SlideModel*>(sourceModel())->openContainingFolder(sourceIndex.row()); | ||
132 | } | 133 | } | ||
133 | 134 | | |||
134 | void SlideFilterModel::buildRandomOrder() | 135 | void SlideFilterModel::buildRandomOrder() | ||
135 | { | 136 | { | ||
136 | if (sourceModel()) { | 137 | if (sourceModel()) { | ||
137 | m_randomOrder.resize(sourceModel()->rowCount()); | 138 | m_randomOrder.resize(sourceModel()->rowCount()); | ||
138 | std::iota(m_randomOrder.begin(), m_randomOrder.end(), 0); | 139 | std::iota(m_randomOrder.begin(), m_randomOrder.end(), 0); | ||
139 | std::random_shuffle(m_randomOrder.begin(), m_randomOrder.end()); | 140 | std::random_shuffle(m_randomOrder.begin(), m_randomOrder.end()); | ||
anthonyfieroni: random_shuffle is removed in C++17, so maybe we can change to
`std::shuffle(m_randomOrder.begin… | |||||
140 | } | 141 | } | ||
141 | } | 142 | } |
random_shuffle is removed in C++17, so maybe we can change to
std::shuffle(m_randomOrder.begin(), m_randomOrder.end(), rand);