forked from openkylin/ukui-menu
统一Data Model的roleName
This commit is contained in:
parent
218ffacbfe
commit
fd8d7ed2d6
|
@ -146,6 +146,18 @@ QString UkuiMenu::DataEntity::extraData() const
|
|||
return m_extraData;
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> UkuiMenu::DataEntity::AppRoleNames()
|
||||
{
|
||||
QHash<int, QByteArray> 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)) {}
|
||||
|
|
|
@ -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<int, QByteArray> AppRoleNames();
|
||||
enum PropertyName {
|
||||
Type = 0,
|
||||
Id = 0,
|
||||
Type,
|
||||
Icon,
|
||||
Name,
|
||||
Comment,
|
||||
|
|
|
@ -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<int, QByteArray> AppModel::roleNames() const
|
||||
{
|
||||
QHash<int, QByteArray> 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)
|
||||
|
|
|
@ -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<int, QByteArray> FolderModel::roleNames() const
|
||||
{
|
||||
QHash<int, QByteArray> 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
|
||||
|
|
Loading…
Reference in New Issue