Skip to content

Commit 84a11da

Browse files
committed
view filter fix-up: randomized slideshow
1 parent 663a5c2 commit 84a11da

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

Phototonic.cpp

+15-3
Original file line numberDiff line numberDiff line change
@@ -2719,10 +2719,22 @@ void Phototonic::slideShowHandler() {
27192719
thumbsViewer->setCurrentIndex(next);
27202720
last = thumbsViewer->currentIndex().row();
27212721

2722-
if (Settings::slideShowRandom)
2723-
next = QRandomGenerator::global()->bounded(thumbsViewer->model()->rowCount());
2724-
else
2722+
if (Settings::slideShowRandom) {
2723+
next = QRandomGenerator::global()->bounded(thumbsViewer->visibleThumbs());
2724+
if (thumbsViewer->visibleThumbs() != thumbsViewer->model()->rowCount()) {
2725+
// for the filtered case we've to figure the nth non-hidden thumb, naively picking some
2726+
// number and moving to the next visible will cause less than random results if a huge
2727+
// block is hidden because we'll often end at its adjacent indexes
2728+
int n = next;
2729+
for (next = 0; next < thumbsViewer->model()->rowCount(); ++next) {
2730+
if (!thumbsViewer->isRowHidden(next) && --n < 0)
2731+
break;
2732+
}
2733+
}
2734+
2735+
} else {
27252736
next = thumbsViewer->nextRow();
2737+
}
27262738

27272739
if (next < 0)
27282740
next = Settings::wrapImageList ? 0 : -2;

ThumbsViewer.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ void ThumbsViewer::reLoad() {
442442
histFiles.clear(); // these can grow out of control and currently sort O(n^2)
443443
histograms.clear();
444444
m_histSorted = false;
445+
m_visibleThumbs = 0;
445446

446447
loadPrepare();
447448

@@ -711,6 +712,8 @@ void ThumbsViewer::filterRows(int first, int last) {
711712
setRowHidden(i, false);
712713
}
713714

715+
m_visibleThumbs += shown.size() - hidden.size();
716+
714717
if (!hidden.isEmpty())
715718
emit filesHidden(hidden);
716719
if (!shown.isEmpty())

ThumbsViewer.h

+2
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ Q_OBJECT
140140
bool isBusy() { return m_busy; }
141141
static int removeFromCache(const QString &path);
142142
static int moveCache(const QString &oldpath, const QString &newpath);
143+
int visibleThumbs() const { return m_visibleThumbs; }
143144
QDir thumbsDir;
144145
QDir::SortFlags thumbsSortFlags;
145146
int thumbSize;
@@ -201,6 +202,7 @@ Q_OBJECT
201202
QStandardItemModel *m_model;
202203
QString m_desiredThumbPath;
203204
bool m_filterDirty;
205+
int m_visibleThumbs;
204206

205207
public slots:
206208
void invertSelection();

0 commit comments

Comments
 (0)