Skip to content

Commit

Permalink
fix: appItem without icon field clicking to start causing crash
Browse files Browse the repository at this point in the history
Show default icon when icon is empty, and add a field to distinguish between folders and appitems

Issue: linuxdeepin/developer-center#8396
  • Loading branch information
mhduiy authored and FeiWang1119 committed May 7, 2024
1 parent 96e875b commit 5360224
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
6 changes: 3 additions & 3 deletions qml/IconItemDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ Control {
TapHandler {
acceptedButtons: Qt.LeftButton
onTapped: {
if (root.icons) {
if (model.itemType === ItemArrangementProxyModel.FolderItemType) {
root.folderClicked()
} else {
root.itemClicked()
Expand All @@ -210,15 +210,15 @@ Control {
background: DebugBounding { }

Keys.onSpacePressed: {
if (root.icons !== undefined) {
if (model.itemType === ItemArrangementProxyModel.FolderItemType) {
root.folderClicked()
} else {
root.itemClicked()
}
}

Keys.onReturnPressed: {
if (root.icons !== undefined) {
if (model.itemType === ItemArrangementProxyModel.FolderItemType) {
root.folderClicked()
} else {
root.itemClicked()
Expand Down
4 changes: 2 additions & 2 deletions qml/windowed/FreeSortListView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Item {
id: itemDelegate
text: model.display.startsWith("internal/category/") ? getCategoryName(model.display.substring(18)) : model.display
checkable: false
icon.name: iconName === undefined ? "folder" : iconName
icon.name: itemType === ItemArrangementProxyModel.FolderItemType ? "folder" : iconName
DciIcon.mode: DTK.NormalState
anchors.fill: parent
anchors.leftMargin: 10
Expand Down Expand Up @@ -182,7 +182,7 @@ Item {
if (iconName)
showContextMenu(itemDelegate, model, false, false, false)
} else {
if (!iconName) {
if (itemType === ItemArrangementProxyModel.FolderItemType) {
console.log("freesort view folder clicked:", desktopId);
let idStr = model.desktopId
let strFolderId = Number(idStr.replace("internal/folders/", ""))
Expand Down
2 changes: 1 addition & 1 deletion src/models/appitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const QString AppItem::iconName() const

void AppItem::setIconName(const QString &iconName)
{
setData(iconName, AppItem::IconNameRole);
setData(iconName.isEmpty() ? "application-x-desktop" : iconName, AppItem::IconNameRole);
}

const QStringList AppItem::categories() const
Expand Down
13 changes: 11 additions & 2 deletions src/models/itemarrangementproxymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ int ItemArrangementProxyModel::pageCount(int folderId) const
QString fullId("internal/folders/" + QString::number(folderId));
Q_ASSERT(m_folders.contains(fullId));

return m_folders.value(fullId)->pageCount();
if (auto itemPage = m_folders.value(fullId); itemPage) {
return itemPage->pageCount();
} else {
qWarning() << "itemPage is null, return 0. fullId is" << fullId;
return 0;
}
}

void ItemArrangementProxyModel::updateFolderName(int folderId, const QString &name)
Expand Down Expand Up @@ -152,6 +157,8 @@ QVariant ItemArrangementProxyModel::data(const QModelIndex &index, int role) con
return folder;
case IconsNameRole:
return QVariant();
case ItemTypeRole:
return AppItemType;
}
} else {
// a folder
Expand Down Expand Up @@ -184,16 +191,18 @@ QVariant ItemArrangementProxyModel::data(const QModelIndex &index, int role) con
}
return icons;//QStringList({"deepin-music"});
}
case ItemTypeRole:
return FolderItemType;
}
}

return QConcatenateTablesProxyModel::data(index, role);
}

QHash<int, QByteArray> ItemArrangementProxyModel::roleNames() const
{
auto existingRoleNames = AppsModel::instance().roleNames();
existingRoleNames.insert(IconsNameRole, QByteArrayLiteral("folderIcons"));
existingRoleNames.insert(ItemTypeRole, QByteArrayLiteral("itemType"));
return existingRoleNames;
}

Expand Down
9 changes: 8 additions & 1 deletion src/models/itemarrangementproxymodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ class ItemArrangementProxyModel : public QConcatenateTablesProxyModel
QML_NAMED_ELEMENT(ItemArrangementProxyModel)
QML_SINGLETON
public:
enum ItemType{
AppItemType = 0,
FolderItemType = 1
};
Q_ENUM(ItemType)

enum Roles {
PageRole = AppsModel::ProxyModelExtendedRole,
IndexInPageRole,
FolderIdNumberRole,
IconsNameRole
IconsNameRole,
ItemTypeRole
};
Q_ENUM(Roles)

Expand Down

0 comments on commit 5360224

Please sign in to comment.