Skip to content

Commit

Permalink
fix: should clean-up no longer valid items in fullscreen mode
Browse files Browse the repository at this point in the history
全屏模式中,当图标数量变化时,从图标位置数据源中移除不再有效的图标。
已被卸载的图标将不会再占据位置,因应用卸载导致的图标消失后页面留空
的空白页也会被相应移除。

Issue: linuxdeepin/developer-center#6861
Log:
  • Loading branch information
BLumia committed Jan 12, 2024
1 parent 267f601 commit 7fbbf96
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
20 changes: 20 additions & 0 deletions src/models/itemspage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "itemspage.h"

#include <QSet>

ItemsPage::ItemsPage(const QString &name, int maxItemCountPerPage, QObject *parent)
: QObject(parent)
, m_maxItemCountPerPage(maxItemCountPerPage)
Expand Down Expand Up @@ -157,6 +159,24 @@ bool ItemsPage::removeItem(const QString id, bool removePageIfPageIsEmpty)
return false;
}

void ItemsPage::removeItemsNotIn(const QSet<QString> &itemSet)
{
for (int i = 0; i < m_pages.count(); i++) {
for (int j = m_pages.at(i).count() - 1; j >= 0; j--) {
const QString & item(m_pages.at(i).at(j));
if (itemSet.contains(item)) continue;
if (item.startsWith(QLatin1String("internal/"))) continue;
m_pages[i].removeAt(j);
}
}
removeEmptyPages();
}

void ItemsPage::removeEmptyPages()
{
m_pages.removeAll({});
}

// <page, index>
std::tuple<int, int> ItemsPage::findItem(const QString &id) const
{
Expand Down
2 changes: 2 additions & 0 deletions src/models/itemspage.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class ItemsPage : public QObject
void insertItem(const QString id, int page, int pos = 0);
void moveItem(int from_page, int from_index, int to_page, int to_index);
bool removeItem(const QString id, bool removePageIfPageIsEmpty = true);
void removeItemsNotIn(const QSet<QString> & itemSet);
void removeEmptyPages();

std::tuple<int, int> findItem(const QString & id) const;
bool contains(const QString & id) const;
Expand Down
11 changes: 8 additions & 3 deletions src/models/multipageproxymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,20 +283,25 @@ std::tuple<int, int, int> MultipageProxyModel::findItem(const QString &id, bool

void MultipageProxyModel::onSourceModelChanged()
{
// add all existing ones if they are not already in
QSet<QString> appDesktopIdSet;
int appsCount = AppsModel::instance().rowCount();
for (int i = 0; i < appsCount; i++) {
QString desktopId(AppsModel::instance().data(AppsModel::instance().index(i, 0), AppItem::DesktopIdRole).toString());
appDesktopIdSet.insert(desktopId);
int folder, page, idx;
std::tie(folder, std::ignore, std::ignore) = findItem(desktopId);
// add all existing ones if they are not already in
if (folder == -1) {
findItem(desktopId);
m_topLevel->appendItem(desktopId);
}
}

// TODO: remove the ones that no longer valid out of m_folders

m_topLevel->removeItemsNotIn(appDesktopIdSet);
for (int i = 0; i < m_folderModel.rowCount(); i++) {
const QString & folderId = m_folderModel.index(i, 0).data(AppItem::DesktopIdRole).toString();
m_folders.value(folderId)->removeItemsNotIn(appDesktopIdSet);
}

emit dataChanged(index(0, 0), index(rowCount() - 1, 0), {
PageRole, IndexInPageRole, FolderIdNumberRole, IconsNameRole
Expand Down

0 comments on commit 7fbbf96

Please sign in to comment.