mirror of
https://github.com/YACReader/yacreader
synced 2026-04-12 15:49:53 -04:00
Fix accessing the root folder for setting the library type
This commit is contained in:
@ -315,6 +315,35 @@ void FolderModel::takeUpdatedChildrenInfo(FolderItem *parent, const QModelIndex
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Folder FolderModel::folderFromItem(FolderItem *folderItem)
|
||||||
|
{
|
||||||
|
auto name = folderItem->data(FolderModel::Name).toString();
|
||||||
|
auto parentItem = folderItem->parent();
|
||||||
|
|
||||||
|
QString path;
|
||||||
|
if (parentItem == nullptr) {
|
||||||
|
parentItem = rootItem;
|
||||||
|
path = "/";
|
||||||
|
} else {
|
||||||
|
path = parentItem->data(Columns::Path).toString() + "/" + name;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto folder = Folder(folderItem->id,
|
||||||
|
parentItem->id,
|
||||||
|
name,
|
||||||
|
path,
|
||||||
|
folderItem->data(Columns::Completed).toBool(),
|
||||||
|
folderItem->data(Columns::Finished).toBool(),
|
||||||
|
folderItem->data(Columns::NumChildren).toInt(),
|
||||||
|
folderItem->data(Columns::FirstChildHash).toString(),
|
||||||
|
folderItem->data(Columns::CustomImage).toString(),
|
||||||
|
folderItem->data(Columns::Type).value<YACReader::FileType>(),
|
||||||
|
folderItem->data(Columns::Added).toLongLong(),
|
||||||
|
folderItem->data(Columns::Updated).toLongLong());
|
||||||
|
|
||||||
|
return folder;
|
||||||
|
}
|
||||||
|
|
||||||
void FolderModel::reload(const QModelIndex &index)
|
void FolderModel::reload(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
// TODO: reload just the content under index for better efficiency
|
// TODO: reload just the content under index for better efficiency
|
||||||
@ -790,25 +819,23 @@ FolderModel *FolderModel::getSubfoldersModel(const QModelIndex &mi)
|
|||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Folder FolderModel::getRootFolder()
|
||||||
|
{
|
||||||
|
if (this->rootItem == nullptr) {
|
||||||
|
return Folder();
|
||||||
|
}
|
||||||
|
|
||||||
|
return folderFromItem(this->rootItem);
|
||||||
|
}
|
||||||
|
|
||||||
Folder FolderModel::getFolder(const QModelIndex &mi)
|
Folder FolderModel::getFolder(const QModelIndex &mi)
|
||||||
{
|
{
|
||||||
auto folderItem = static_cast<FolderItem *>(mi.internalPointer());
|
if (!mi.isValid()) {
|
||||||
auto name = folderItem->data(FolderModel::Name).toString();
|
return Folder();
|
||||||
auto parentItem = folderItem->parent();
|
}
|
||||||
auto folder = Folder(folderItem->id,
|
|
||||||
parentItem->id,
|
|
||||||
name,
|
|
||||||
folderItem->parent()->data(Columns::Path).toString() + "/" + name,
|
|
||||||
folderItem->data(Columns::Completed).toBool(),
|
|
||||||
folderItem->data(Columns::Finished).toBool(),
|
|
||||||
folderItem->data(Columns::NumChildren).toInt(),
|
|
||||||
folderItem->data(Columns::FirstChildHash).toString(),
|
|
||||||
folderItem->data(Columns::CustomImage).toString(),
|
|
||||||
folderItem->data(Columns::Type).value<YACReader::FileType>(),
|
|
||||||
folderItem->data(Columns::Added).toLongLong(),
|
|
||||||
folderItem->data(Columns::Updated).toLongLong());
|
|
||||||
|
|
||||||
return folder;
|
auto folderItem = static_cast<FolderItem *>(mi.internalPointer());
|
||||||
|
return folderFromItem(folderItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex FolderModel::getIndexFromFolderId(qulonglong folderId, const QModelIndex &parent)
|
QModelIndex FolderModel::getIndexFromFolderId(qulonglong folderId, const QModelIndex &parent)
|
||||||
|
|||||||
@ -76,6 +76,7 @@ public:
|
|||||||
QStringList getSubfoldersNames(const QModelIndex &mi);
|
QStringList getSubfoldersNames(const QModelIndex &mi);
|
||||||
FolderModel *getSubfoldersModel(const QModelIndex &mi); // it creates a model that contains just the direct subfolders
|
FolderModel *getSubfoldersModel(const QModelIndex &mi); // it creates a model that contains just the direct subfolders
|
||||||
|
|
||||||
|
Folder getRootFolder();
|
||||||
Folder getFolder(const QModelIndex &mi);
|
Folder getFolder(const QModelIndex &mi);
|
||||||
QModelIndex getIndexFromFolderId(qulonglong folderId, const QModelIndex &parent = QModelIndex());
|
QModelIndex getIndexFromFolderId(qulonglong folderId, const QModelIndex &parent = QModelIndex());
|
||||||
QModelIndex getIndexFromFolder(const Folder &folder, const QModelIndex &parent = QModelIndex());
|
QModelIndex getIndexFromFolder(const Folder &folder, const QModelIndex &parent = QModelIndex());
|
||||||
@ -133,6 +134,8 @@ private:
|
|||||||
// parent contains the current data in the model (parentModelIndex is its index), updated contains fresh info loaded from the DB,
|
// parent contains the current data in the model (parentModelIndex is its index), updated contains fresh info loaded from the DB,
|
||||||
void takeUpdatedChildrenInfo(FolderItem *parent, const QModelIndex &parentModelIndex, FolderItem *updated);
|
void takeUpdatedChildrenInfo(FolderItem *parent, const QModelIndex &parentModelIndex, FolderItem *updated);
|
||||||
|
|
||||||
|
Folder folderFromItem(FolderItem *item);
|
||||||
|
|
||||||
FolderItem *rootItem; // items tree
|
FolderItem *rootItem; // items tree
|
||||||
QMap<unsigned long long int, FolderItem *> items; // items lookup
|
QMap<unsigned long long int, FolderItem *> items; // items lookup
|
||||||
|
|
||||||
|
|||||||
@ -608,8 +608,7 @@ void LibraryWindow::createMenus()
|
|||||||
auto typeMenu = new QMenu(tr("Set type"), selectedLibrary);
|
auto typeMenu = new QMenu(tr("Set type"), selectedLibrary);
|
||||||
|
|
||||||
connect(typeMenu, &QMenu::aboutToShow, this, [=]() {
|
connect(typeMenu, &QMenu::aboutToShow, this, [=]() {
|
||||||
auto rootIndex = foldersModel->index(0, 0);
|
auto folder = foldersModel->getRootFolder();
|
||||||
auto folder = foldersModel->getFolder(rootIndex);
|
|
||||||
setupActions(folder.type);
|
setupActions(folder.type);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user