mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
Extract function
This commit is contained in:
parent
555540b85d
commit
3e2bda7cf1
@ -216,27 +216,10 @@ QModelIndex FolderModel::index(int row, int column, const QModelIndex &parent)
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
void 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);
|
||||
}
|
||||
|
||||
QModelIndex FolderModel::index(qulonglong folderId) const
|
||||
{
|
||||
QModelIndex index;
|
||||
iterate(QModelIndex(), this, [&](const QModelIndex &idx) {
|
||||
YACReader::iterate(QModelIndex(), this, [&](const QModelIndex &idx) {
|
||||
if (index.isValid()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <QStandardPaths>
|
||||
#include <QDataStream>
|
||||
#include <QMetaType>
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
#define VERSION "9.10.0"
|
||||
|
||||
@ -68,6 +69,10 @@ QString getSettingsPath();
|
||||
QString colorToName(LabelColors colors);
|
||||
QString labelColorToRGBString(LabelColors color);
|
||||
|
||||
void iterate(const QModelIndex &index,
|
||||
const QAbstractItemModel *model,
|
||||
const std::function<bool(const QModelIndex &)> &iteration);
|
||||
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(YACReader::OpenComicSource::Source)
|
||||
|
Loading…
Reference in New Issue
Block a user