mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10: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);
|
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
|
QVariant FolderModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
@ -155,10 +161,9 @@ QVariant FolderModel::data(const QModelIndex &index, int role) const
|
|||||||
return item->data(FolderModel::Finished);
|
return item->data(FolderModel::Finished);
|
||||||
|
|
||||||
if (role == FolderModel::MangaRole)
|
if (role == FolderModel::MangaRole)
|
||||||
return item->data(FolderModel::Manga);
|
return item->data(FolderModel::Manga)
|
||||||
|
|
||||||
if (role == FolderModel::IdRole)
|
if (role == FolderModel::IdRole) return item->id;
|
||||||
return item->id;
|
|
||||||
|
|
||||||
if (role == FolderModel::CoverPathRole)
|
if (role == FolderModel::CoverPathRole)
|
||||||
return getCoverUrlPathForComicHash(item->data(FirstChildHash).toString());
|
return getCoverUrlPathForComicHash(item->data(FirstChildHash).toString());
|
||||||
@ -210,6 +215,39 @@ 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<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
|
QModelIndex FolderModel::parent(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
|
@ -54,6 +54,7 @@ public:
|
|||||||
int role = Qt::DisplayRole) const override;
|
int role = Qt::DisplayRole) const override;
|
||||||
QModelIndex index(int row, int column,
|
QModelIndex index(int row, int column,
|
||||||
const QModelIndex &parent = QModelIndex()) const override;
|
const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
QModelIndex index(qulonglong folderId) const;
|
||||||
QModelIndex parent(const QModelIndex &index) const override;
|
QModelIndex parent(const QModelIndex &index) const override;
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
@ -61,6 +62,7 @@ public:
|
|||||||
|
|
||||||
// Convenience methods
|
// Convenience methods
|
||||||
void reload();
|
void reload();
|
||||||
|
void reload(const QModelIndex &index);
|
||||||
void setupModelData(QString path);
|
void setupModelData(QString path);
|
||||||
QString getDatabase();
|
QString getDatabase();
|
||||||
QString getFolderPath(const QModelIndex &folder);
|
QString getFolderPath(const QModelIndex &folder);
|
||||||
|
@ -1547,10 +1547,14 @@ void LibraryWindow::reloadCurrentFolderComicsContent()
|
|||||||
void LibraryWindow::reloadAfterCopyMove(const QModelIndex &mi)
|
void LibraryWindow::reloadAfterCopyMove(const QModelIndex &mi)
|
||||||
{
|
{
|
||||||
if (getCurrentFolderIndex() == 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();
|
enableNeededActions();
|
||||||
}
|
}
|
||||||
@ -2076,6 +2080,7 @@ void LibraryWindow::create(QString source, QString dest, QString name)
|
|||||||
|
|
||||||
void LibraryWindow::reloadCurrentLibrary()
|
void LibraryWindow::reloadCurrentLibrary()
|
||||||
{
|
{
|
||||||
|
qDebug() << "reloadCurrentLibrary";
|
||||||
loadLibrary(selectedLibrary->currentText());
|
loadLibrary(selectedLibrary->currentText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user