From 5ab93b7d6d64f9e868b797298d8bb7a993bdd708 Mon Sep 17 00:00:00 2001 From: keke <243768648@qq.com> Date: Mon, 1 Aug 2022 23:39:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=BF=9D=E6=8C=81?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=BA=94=E7=94=A8=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- appmanagerwidget.cpp | 92 +++++++++++++++++++++++++++++++++++++++----- appmanagerwidget.h | 5 ++- 2 files changed, 87 insertions(+), 10 deletions(-) diff --git a/appmanagerwidget.cpp b/appmanagerwidget.cpp index b647ca3..02edbbe 100644 --- a/appmanagerwidget.cpp +++ b/appmanagerwidget.cpp @@ -43,6 +43,7 @@ AppManagerWidget::AppManagerWidget(AppManagerModel *model, QWidget *parent) , m_showInstalledAppAction(nullptr) , m_showGuiAppAction(nullptr) , m_showSearchedAppAction(nullptr) + , m_showVerHeldAppAction(nullptr) , m_displayRangeType(DisplayRangeType::All) , m_appListModel(nullptr) , m_appListView(nullptr) @@ -122,6 +123,9 @@ AppManagerWidget::AppManagerWidget(AppManagerModel *model, QWidget *parent) m_showSearchedAppAction = new QAction("搜索结果"); m_showSearchedAppAction->setCheckable(true); m_filterMenu->addAction(m_showSearchedAppAction); + m_showVerHeldAppAction = new QAction("已保持版本"); + m_showVerHeldAppAction->setCheckable(true); + m_filterMenu->addAction(m_showVerHeldAppAction); filterBtn->setMenu(m_filterMenu); // 应用列表 @@ -273,6 +277,7 @@ AppManagerWidget::AppManagerWidget(AppManagerModel *model, QWidget *parent) m_showInstalledAppAction->setChecked(false); m_showGuiAppAction->setChecked(false); m_showSearchedAppAction->setChecked(false); + m_showVerHeldAppAction->setChecked(false); if (m_showAllAppAction == action) { m_showAllAppAction->setChecked(true); this->showAllAppInfoList(); @@ -285,6 +290,9 @@ AppManagerWidget::AppManagerWidget(AppManagerModel *model, QWidget *parent) } else if (m_showSearchedAppAction == action) { m_showSearchedAppAction->setChecked(true); this->showSearchedAppInfoList(); + } else if (m_showVerHeldAppAction == action) { + m_showVerHeldAppAction->setChecked(true); + this->showVerHeldAppInfoList(); } }); @@ -520,11 +528,19 @@ void AppManagerWidget::onAppInstalled(const AM::AppInfo &appInfo) } break; } + case VerHeld: + if (appInfo.installedPkgInfo.isHoldVersion) { + m_showingInfoList.insert(0, appInfo); + m_appListModel->insertRow(0, createViewItemList(appInfo)); + } + break; } // 刷新右侧显示内容 if (appInfo.pkgName == m_showingAppInfo.pkgName) { - showAppInfo(appInfo); + // 更改后,显示列表当前选中应用 + AppInfo currentAppInfo = m_showingInfoList.at(m_appListView->currentIndex().row()); + showAppInfo(currentAppInfo); } // 更新应用个数标签 updateAppCountLabel(); @@ -582,7 +598,48 @@ void AppManagerWidget::onAppUpdated(const AM::AppInfo &appInfo) // 根据操作类型,更新界面和缓存列表 if (0 == operateType) { - m_appInfoList.insert(0, appInfo); + m_showingInfoList.insert(0, appInfo); + m_appListModel->insertRow(0, createViewItemList(appInfo)); + } else if (1 == operateType) { + for (int i = m_appListModel->rowCount() - 1; i >= 0 ; --i) { + QStandardItem *item = m_appListModel->item(i, 0); + if (appInfo.pkgName == item->data(AM_LIST_VIEW_ITEM_DATA_ROLE_PKG_NAME).toString()) { + m_appListModel->removeRow(i); + break; + } + } + } else if (2 == operateType) { + for (int i = m_appListModel->rowCount() - 1; i >= 0 ; --i) { + QStandardItem *item = m_appListModel->item(i, 0); + if (appInfo.pkgName == item->data(AM_LIST_VIEW_ITEM_DATA_ROLE_PKG_NAME).toString()) { + updateItemFromAppInfo(item, appInfo); + break; + } + } + } + break; + } + case VerHeld: { + int operateType = 0; // 0 - add, 1 - remove, 2 - update + for (QList::iterator iter = m_showingInfoList.end() - 1; + iter != m_showingInfoList.begin() - 1; --iter) { + if (appInfo.pkgName != iter->pkgName) { + continue; + } + + if (!appInfo.installedPkgInfo.isHoldVersion) { + operateType = 1; + m_showingInfoList.removeOne(*iter); + } else { + operateType = 2; + *iter = appInfo; + } + break; + } + + // 根据操作类型,更新界面和缓存列表 + if (0 == operateType) { + m_showingInfoList.insert(0, appInfo); m_appListModel->insertRow(0, createViewItemList(appInfo)); } else if (1 == operateType) { for (int i = m_appListModel->rowCount() - 1; i >= 0 ; --i) { @@ -607,7 +664,9 @@ void AppManagerWidget::onAppUpdated(const AM::AppInfo &appInfo) // 刷新右侧显示内容 if (appInfo.pkgName == m_showingAppInfo.pkgName) { - showAppInfo(appInfo); + // 更改后,显示列表当前选中应用 + AppInfo currentAppInfo = m_showingInfoList.at(m_appListView->currentIndex().row()); + showAppInfo(currentAppInfo); } // 更新应用个数标签 updateAppCountLabel(); @@ -645,7 +704,8 @@ void AppManagerWidget::onAppUninstalled(const AM::AppInfo &appInfo) break; } case Installed: - case Gui: { + case Gui: + case VerHeld: { for (QList::iterator iter = m_showingInfoList.end() - 1; iter != m_showingInfoList.begin() - 1; --iter) { if (appInfo.pkgName == iter->pkgName) { @@ -719,11 +779,6 @@ void AppManagerWidget::setItemModelFromAppInfoList(const QList &appInfo // 更新正在显示的应用列表 m_showingInfoList = appInfoList; - if (!m_showingInfoList.isEmpty()) { - m_appListView->setCurrentIndex(m_appListModel->index(0, 0)); - showAppInfo(m_showingInfoList[0]); - } - // 更新应用个数标签 updateAppCountLabel(); @@ -746,6 +801,11 @@ void AppManagerWidget::setItemModelFromAppInfoList(const QList &appInfo item->setData(info.pkgName, AM_LIST_VIEW_ITEM_DATA_ROLE_PKG_NAME); m_appListModel->appendRow(QList {item}); } + + if (!m_showingInfoList.isEmpty()) { + m_appListView->setCurrentIndex(m_appListModel->index(0, 0)); + showAppInfo(m_showingInfoList[0]); + } } void AppManagerWidget::showAllAppInfoList() @@ -790,6 +850,20 @@ void AppManagerWidget::showSearchedAppInfoList() setItemModelFromAppInfoList(searchedList); } +void AppManagerWidget::showVerHeldAppInfoList() +{ + m_displayRangeType = VerHeld; + QList verHeldAppInfoList; + for (const AppInfo &info : m_appInfoList) { + if (!info.installedPkgInfo.isHoldVersion) { + continue; + } + verHeldAppInfoList.append(info); + } + + setItemModelFromAppInfoList(verHeldAppInfoList); +} + void AppManagerWidget::setLoading(bool loading) { if (loading) { diff --git a/appmanagerwidget.h b/appmanagerwidget.h index 13ab46f..4add385 100644 --- a/appmanagerwidget.h +++ b/appmanagerwidget.h @@ -35,7 +35,8 @@ public: All = 0, Installed, Gui, - Searched + Searched, + VerHeld //保持版本 }; AppManagerWidget(AppManagerModel *model, QWidget *parent = nullptr); @@ -60,6 +61,7 @@ private: void onlyShowInstalledAppInfoList(); void onlyShowUIAppInfoList(); void showSearchedAppInfoList(); + void showVerHeldAppInfoList(); void setLoading(bool loading); QList createViewItemList(const AM::AppInfo &appInfo); @@ -83,6 +85,7 @@ private: QAction *m_showInstalledAppAction; QAction *m_showGuiAppAction; QAction *m_showSearchedAppAction; + QAction *m_showVerHeldAppAction; // 保持版本的app过滤按钮 DisplayRangeType m_displayRangeType; // 显示范围类型 QStandardItemModel *m_appListModel; -- Gitee