mirror of
https://github.com/YACReader/yacreader
synced 2025-07-14 02:54:46 -04:00
Extract function
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
#include "yacreader_global.h"
|
||||
|
||||
#include <QModelIndex>
|
||||
|
||||
using namespace YACReader;
|
||||
|
||||
QString YACReader::getSettingsPath()
|
||||
@ -100,3 +102,20 @@ QDataStream &YACReader::operator>>(QDataStream &stream, OpenComicSource &source)
|
||||
stream >> source.sourceId;
|
||||
return stream;
|
||||
}
|
||||
|
||||
void YACReader::iterate(const QModelIndex &index,
|
||||
const QAbstractItemModel *model,
|
||||
const std::function<bool(const QModelIndex &)> &iteration)
|
||||
{
|
||||
if (index.isValid()) {
|
||||
auto continueIterating = iteration(index);
|
||||
if (!continueIterating) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ((index.flags() & Qt::ItemNeverHasChildren) || !model->hasChildren(index))
|
||||
return;
|
||||
auto rows = model->rowCount(index);
|
||||
for (int i = 0; i < rows; ++i)
|
||||
iterate(model->index(i, 0, index), model, iteration);
|
||||
}
|
||||
|
Reference in New Issue
Block a user