Commit c900324b authored by Stefan Brüns's avatar Stefan Brüns
Browse files

Simplify loop conditions

Replace the `yPos <= maxYPos)` check in the inner loop with an more
explicit check whenever a thumnail is drawn.

`(yPos <= maxYPos) && !validThumbnails)` is redundant, as yPos is only
incremented whenever validThumbnails is incremented. Move the
validThumbnails check into the loop.
parent 78a8c7d3
......@@ -520,11 +520,9 @@ QImage ThumbnailProtocol::thumbForDirectory(const QString& directory)
QImage firstThumbnail;
int skipped = 0;
const int maxYPos = folderHeight - bottomMargin - segmentHeight;
int validThumbnails = 0;
while ((skipped <= skipValidItems) && (yPos <= maxYPos) && validThumbnails == 0) {
while (skipped <= skipValidItems) {
QDirIterator dir(directory, QDir::Files | QDir::Readable);
if (!dir.hasNext()) {
break;
......@@ -534,7 +532,7 @@ QImage ThumbnailProtocol::thumbForDirectory(const QString& directory)
// for the same directory and sequence-item
qsrand(qHash(directory) + skipValidItems);
while (dir.hasNext() && (yPos <= maxYPos)) {
while (dir.hasNext()) {
++iterations;
if (iterations > 500) {
skipValidItems = skipped = 0;
......@@ -570,6 +568,9 @@ QImage ThumbnailProtocol::thumbForDirectory(const QString& directory)
}
++validThumbnails;
if (validThumbnails >= visibleCount) {
break;
}
xPos += segmentWidth + spacing;
if (xPos > folderWidth - rightMargin - segmentWidth) {
......@@ -578,6 +579,10 @@ QImage ThumbnailProtocol::thumbForDirectory(const QString& directory)
}
}
if (validThumbnails > 0) {
break;
}
if (skipped != 0) { // Round up to full pages
const int roundedDown = (skipped / visibleCount) * visibleCount;
if (roundedDown < skipped) {
......
Markdown is supported
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