mirror of
https://github.com/YACReader/yacreader
synced 2025-05-27 10:50:27 -04:00
Restore the selected index in the folders view when doing partial updates
This commit is contained in:
parent
0556276374
commit
54d2fba53d
@ -108,6 +108,12 @@ void FolderModel::reload()
|
||||
setupModelData(_databasePath);
|
||||
}
|
||||
|
||||
void FolderModel::reload(const QModelIndex &index)
|
||||
{
|
||||
// TODO: reload just the content under index for better efficiency
|
||||
setupModelData(_databasePath);
|
||||
}
|
||||
|
||||
QVariant FolderModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
@ -155,10 +161,9 @@ QVariant FolderModel::data(const QModelIndex &index, int role) const
|
||||
return item->data(FolderModel::Finished);
|
||||
|
||||
if (role == FolderModel::MangaRole)
|
||||
return item->data(FolderModel::Manga);
|
||||
return item->data(FolderModel::Manga)
|
||||
|
||||
if (role == FolderModel::IdRole)
|
||||
return item->id;
|
||||
if (role == FolderModel::IdRole) return item->id;
|
||||
|
||||
if (role == FolderModel::CoverPathRole)
|
||||
return getCoverUrlPathForComicHash(item->data(FirstChildHash).toString());
|
||||
@ -210,6 +215,39 @@ QModelIndex FolderModel::index(int row, int column, const QModelIndex &parent)
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
void iterate(const QModelIndex &index,
|
||||
const QAbstractItemModel *model,
|
||||
const std::function<boolean(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) {
|
||||
auto item = static_cast<FolderItem *>(idx.internalPointer());
|
||||
if (item->id == folderId) {
|
||||
index = idx;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
QModelIndex FolderModel::parent(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
|
@ -54,6 +54,7 @@ public:
|
||||
int role = Qt::DisplayRole) const override;
|
||||
QModelIndex index(int row, int column,
|
||||
const QModelIndex &parent = QModelIndex()) const override;
|
||||
QModelIndex index(qulonglong folderId) const;
|
||||
QModelIndex parent(const QModelIndex &index) const override;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
@ -61,6 +62,7 @@ public:
|
||||
|
||||
// Convenience methods
|
||||
void reload();
|
||||
void reload(const QModelIndex &index);
|
||||
void setupModelData(QString path);
|
||||
QString getDatabase();
|
||||
QString getFolderPath(const QModelIndex &folder);
|
||||
|
@ -1547,10 +1547,14 @@ void LibraryWindow::reloadCurrentFolderComicsContent()
|
||||
void LibraryWindow::reloadAfterCopyMove(const QModelIndex &mi)
|
||||
{
|
||||
if (getCurrentFolderIndex() == mi) {
|
||||
navigationController->loadFolderInfo(mi);
|
||||
}
|
||||
auto item = static_cast<FolderItem *>(mi.internalPointer());
|
||||
auto id = item->id;
|
||||
foldersModel->reload(mi);
|
||||
auto newMi = foldersModel->index(id);
|
||||
|
||||
foldersModel->reload();
|
||||
foldersView->setCurrentIndex(foldersModelProxy->mapFromSource(newMi));
|
||||
navigationController->loadFolderInfo(newMi);
|
||||
}
|
||||
|
||||
enableNeededActions();
|
||||
}
|
||||
@ -2076,6 +2080,7 @@ void LibraryWindow::create(QString source, QString dest, QString name)
|
||||
|
||||
void LibraryWindow::reloadCurrentLibrary()
|
||||
{
|
||||
qDebug() << "reloadCurrentLibrary";
|
||||
loadLibrary(selectedLibrary->currentText());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user