mirror of
https://github.com/YACReader/yacreader
synced 2025-06-03 00:58:32 -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();
|
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 FolderModel::index(qulonglong folderId) const
|
||||||
{
|
{
|
||||||
QModelIndex index;
|
QModelIndex index;
|
||||||
iterate(QModelIndex(), this, [&](const QModelIndex &idx) {
|
YACReader::iterate(QModelIndex(), this, [&](const QModelIndex &idx) {
|
||||||
if (index.isValid()) {
|
if (index.isValid()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include "yacreader_global.h"
|
#include "yacreader_global.h"
|
||||||
|
|
||||||
|
#include <QModelIndex>
|
||||||
|
|
||||||
using namespace YACReader;
|
using namespace YACReader;
|
||||||
|
|
||||||
QString YACReader::getSettingsPath()
|
QString YACReader::getSettingsPath()
|
||||||
@ -100,3 +102,20 @@ QDataStream &YACReader::operator>>(QDataStream &stream, OpenComicSource &source)
|
|||||||
stream >> source.sourceId;
|
stream >> source.sourceId;
|
||||||
return stream;
|
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 <QStandardPaths>
|
||||||
#include <QDataStream>
|
#include <QDataStream>
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
|
#include <QAbstractItemModel>
|
||||||
|
|
||||||
#define VERSION "9.10.0"
|
#define VERSION "9.10.0"
|
||||||
|
|
||||||
@ -68,6 +69,10 @@ QString getSettingsPath();
|
|||||||
QString colorToName(LabelColors colors);
|
QString colorToName(LabelColors colors);
|
||||||
QString labelColorToRGBString(LabelColors color);
|
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)
|
Q_DECLARE_METATYPE(YACReader::OpenComicSource::Source)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user