From fd8d7ed2d67393f905a11af9d158cc84890b7943 Mon Sep 17 00:00:00 2001 From: hewenfei Date: Fri, 31 Mar 2023 16:02:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80Data=20Model=E7=9A=84roleName?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commons.cpp | 12 ++++++++++++ src/commons.h | 5 ++++- src/model/app-model.cpp | 10 +++------- src/model/folder-model.cpp | 10 +++------- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/commons.cpp b/src/commons.cpp index 7926f0f..39143c5 100644 --- a/src/commons.cpp +++ b/src/commons.cpp @@ -146,6 +146,18 @@ QString UkuiMenu::DataEntity::extraData() const return m_extraData; } +QHash UkuiMenu::DataEntity::AppRoleNames() +{ + QHash names; + names.insert(DataEntity::Id, "id"); + names.insert(DataEntity::Type, "type"); + names.insert(DataEntity::Icon, "icon"); + names.insert(DataEntity::Name, "name"); + names.insert(DataEntity::Comment, "comment"); + names.insert(DataEntity::ExtraData, "extraData"); + return names; +} + // ====== LabelItem ====== // UkuiMenu::LabelItem::LabelItem(bool disable, int index, QString id, QString displayName) : m_disable(disable), m_index(index), m_id(std::move(id)), m_displayName(std::move(displayName)) {} diff --git a/src/commons.h b/src/commons.h index 003fb5b..a2b3ec0 100644 --- a/src/commons.h +++ b/src/commons.h @@ -92,13 +92,16 @@ class DataEntity // TODO 改用 Q_OBJECT ? Q_GADGET Q_PROPERTY(DataType::Type type READ type WRITE setType) + Q_PROPERTY(QString id READ id) Q_PROPERTY(QString icon READ icon WRITE setIcon) Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(QString comment READ comment WRITE setComment) Q_PROPERTY(QString extraData READ extraData WRITE setExtraData) public: + static QHash AppRoleNames(); enum PropertyName { - Type = 0, + Id = 0, + Type, Icon, Name, Comment, diff --git a/src/model/app-model.cpp b/src/model/app-model.cpp index dbd5e81..8fe9995 100644 --- a/src/model/app-model.cpp +++ b/src/model/app-model.cpp @@ -45,6 +45,8 @@ QVariant AppModel::data(const QModelIndex &index, int role) const } switch (role) { + case DataEntity::Id: + return m_apps.at(i).id(); case DataEntity::Type: return m_apps.at(i).type(); case DataEntity::Icon: @@ -64,13 +66,7 @@ QVariant AppModel::data(const QModelIndex &index, int role) const QHash AppModel::roleNames() const { - QHash names; - names.insert(DataEntity::Type, "type"); - names.insert(DataEntity::Icon, "icon"); - names.insert(DataEntity::Name, "name"); - names.insert(DataEntity::Comment, "comment"); - names.insert(DataEntity::ExtraData, "extraData"); - return names; + return DataEntity::AppRoleNames(); } int AppModel::getLabelIndex(const QString &id) diff --git a/src/model/folder-model.cpp b/src/model/folder-model.cpp index 4c2f9bb..b9f1c65 100644 --- a/src/model/folder-model.cpp +++ b/src/model/folder-model.cpp @@ -77,6 +77,8 @@ QVariant FolderModel::data(const QModelIndex &index, int role) const } switch (role) { + case DataEntity::Id: + return app.id(); case DataEntity::Type: return app.type(); case DataEntity::Icon: @@ -96,13 +98,7 @@ QVariant FolderModel::data(const QModelIndex &index, int role) const QHash FolderModel::roleNames() const { - QHash names; - names.insert(DataEntity::Type, "type"); - names.insert(DataEntity::Icon, "icon"); - names.insert(DataEntity::Name, "name"); - names.insert(DataEntity::Comment, "comment"); - names.insert(DataEntity::ExtraData, "extraData"); - return names; + return DataEntity::AppRoleNames(); } } // UkuiMenu