From efddb36fef268108d211b0fa2de369d280c4f8cf Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Thu, 30 May 2024 11:18:48 +0400 Subject: [PATCH] Made DownloadManager::Downloads private --- src/contentmanager.cpp | 4 +++- src/contentmanagermodel.cpp | 4 ++-- src/contentmanagermodel.h | 4 +--- src/downloadmanagement.h | 1 + 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/contentmanager.cpp b/src/contentmanager.cpp index e03af8f..345c7fa 100644 --- a/src/contentmanager.cpp +++ b/src/contentmanager.cpp @@ -187,7 +187,9 @@ void ContentManager::updateModel() auto mp = getBookInfos(bookId, keys); bookList.append(mp); } - managerModel->setBooksData(bookList, m_downloads); + + const DownloadManager& downloadMgr = *this; + managerModel->setBooksData(bookList, downloadMgr); } void ContentManager::onCustomContextMenu(const QPoint &point) diff --git a/src/contentmanagermodel.cpp b/src/contentmanagermodel.cpp index 68c7a34..27e0c2b 100644 --- a/src/contentmanagermodel.cpp +++ b/src/contentmanagermodel.cpp @@ -153,7 +153,7 @@ QVariant ContentManagerModel::headerData(int section, Qt::Orientation orientatio } } -void ContentManagerModel::setBooksData(const BookInfoList& data, const Downloads& downloads) +void ContentManagerModel::setBooksData(const BookInfoList& data, const DownloadManager& downloadMgr) { rootNode = std::shared_ptr(new RowNode({tr("Icon"), tr("Name"), tr("Date"), tr("Size"), tr("Content Type"), tr("Download")}, "", std::weak_ptr())); beginResetModel(); @@ -162,7 +162,7 @@ void ContentManagerModel::setBooksData(const BookInfoList& data, const Downloads const auto rowNode = createNode(bookItem); // Restore download state during model updates (filtering, etc) - rowNode->setDownloadState(downloads.value(rowNode->getBookId())); + rowNode->setDownloadState(downloadMgr.getDownloadState(rowNode->getBookId())); bookIdToRowMap[bookItem["id"].toString()] = rootNode->childCount(); rootNode->appendChild(rowNode); diff --git a/src/contentmanagermodel.h b/src/contentmanagermodel.h index 22ed6a2..ae133e9 100644 --- a/src/contentmanagermodel.h +++ b/src/contentmanagermodel.h @@ -23,8 +23,6 @@ public: // types typedef QMap BookInfo; typedef QList BookInfoList; - typedef DownloadManager::Downloads Downloads; - public: // functions explicit ContentManagerModel(ContentManager* contentMgr); ~ContentManagerModel(); @@ -38,7 +36,7 @@ public: // functions QModelIndex parent(const QModelIndex &index) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; - void setBooksData(const BookInfoList& data, const Downloads& downloads); + void setBooksData(const BookInfoList& data, const DownloadManager& downloadMgr); bool hasChildren(const QModelIndex &parent) const override; void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override; diff --git a/src/downloadmanagement.h b/src/downloadmanagement.h index c4555f2..903a224 100644 --- a/src/downloadmanagement.h +++ b/src/downloadmanagement.h @@ -35,6 +35,7 @@ class DownloadManager : public QObject public: // types typedef std::shared_ptr DownloadStatePtr; +private: // BookId -> DownloadState map class Downloads {