diff --git a/src/data-entity.cpp b/src/data-entity.cpp index 1a7a33b..ac33904 100644 --- a/src/data-entity.cpp +++ b/src/data-entity.cpp @@ -43,6 +43,7 @@ public: QString comment; // 应用描述 QString extraData; // 额外的数据 QString insertTime; //安装的时间 + QString group; // 分类 }; DataEntity::DataEntity() : d(new DataEntityPrivate) {} @@ -222,7 +223,16 @@ QHash DataEntity::AppRoleNames() names.insert(DataEntity::Name, "name"); names.insert(DataEntity::Comment, "comment"); names.insert(DataEntity::ExtraData, "extraData"); + names.insert(DataEntity::Category, "category"); + names.insert(DataEntity::Group, "group"); + names.insert(DataEntity::FirstLetter, "firstLetter"); + names.insert(DataEntity::InstallationTime, "installationTime"); + names.insert(DataEntity::IsLaunched, "isLaunched"); + names.insert(DataEntity::LaunchTimes, "launchTimes"); + names.insert(DataEntity::IsLocked, "isLocked"); names.insert(DataEntity::Favorite, "favorite"); + names.insert(DataEntity::Top, "top"); + names.insert(DataEntity::RecentInstall, "recentInstall"); return names; } @@ -257,3 +267,111 @@ DataEntity::~DataEntity() d = nullptr; } } + +QVariant DataEntity::getValue(DataEntity::PropertyName property) const +{ + switch (property) { + case Id: + return d->id; + case Type: + return d->type; + case Icon: + return d->icon; + case Name: + return d->name; + case Comment: + return d->comment; + case ExtraData: + return d->extraData; + case Category: + return d->category; + case Group: + return d->group; + case FirstLetter: + return d->firstLetter; + case InstallationTime: + return d->insertTime; + case IsLaunched: + return d->launched; + case LaunchTimes: + return d->launchTimes; + case IsLocked: + return d->lock; + case Favorite: + return d->favorite; + case Top: + return d->top; + case RecentInstall: + return d->recentInstall; + default: + break; + } + + return {}; +} + +void DataEntity::setValue(DataEntity::PropertyName property, const QVariant &value) +{ + switch (property) { + case Id: + d->id = value.toString(); + break; + case Type: + d->type = value.value(); + break; + case Icon: + d->icon = value.toString(); + break; + case Name: + d->name = value.toString(); + break; + case Comment: + d->comment = value.toString(); + break; + case ExtraData: + d->extraData = value.toString(); + break; + case Category: + d->category = value.toString(); + break; + case Group: + d->group = value.toString(); + break; + case FirstLetter: + d->firstLetter = value.toString(); + break; + case InstallationTime: + d->insertTime = value.toString(); + break; + case IsLaunched: + d->launched = value.toBool(); + break; + case LaunchTimes: + d->launchTimes = value.toInt(); + break; + case IsLocked: + d->lock = value.toBool(); + break; + case Favorite: + d->favorite = value.toInt(); + break; + case Top: + d->top = value.toInt(); + break; + case RecentInstall: + d->recentInstall = value.toBool(); + break; + default: + break; + } +} + +void DataEntity::setGroup(const QString &group) +{ + d->group = group; +} + +QString DataEntity::group() const +{ + return d->group; +} diff --git a/src/data-entity.h b/src/data-entity.h index cdbc725..9793106 100644 --- a/src/data-entity.h +++ b/src/data-entity.h @@ -21,6 +21,7 @@ #include #include +#include class DataEntityPrivate; @@ -41,7 +42,6 @@ public: // 应用数据 class DataEntity { - // TODO 改用 Q_OBJECT ? Q_GADGET Q_PROPERTY(DataType::Type type READ type WRITE setType) Q_PROPERTY(QString id READ id) @@ -58,7 +58,16 @@ public: Name, Comment, ExtraData, - Favorite + Category, /**> 应用类别 */ + Group, /**> 应用分组 */ + FirstLetter, /**> 应用名称首字母 */ + InstallationTime, /**> 安装时间 */ + IsLaunched, /**> 是否启动过该程序 */ + LaunchTimes, /**> 应用被启动的次数 */ + IsLocked, /**> 应用是否锁定 */ + Favorite, /**> 是否被收藏及序号, 小于或等于0表示未被收藏 */ + Top, /**> 是否被置顶及序号, 小于或等于0表示未被置顶 */ + RecentInstall }; DataEntity(); DataEntity(DataType::Type type, const QString& name, const QString& icon, const QString& comment, const QString& extraData); @@ -70,6 +79,9 @@ public: DataEntity(DataEntity&& other) noexcept; DataEntity &operator=(DataEntity&& other) noexcept; + QVariant getValue(DataEntity::PropertyName property) const; + void setValue(DataEntity::PropertyName property, const QVariant &value); + int top() const; void setTop(int top); @@ -118,10 +130,15 @@ public: void setExtraData(const QString& extraData); QString extraData() const; + void setGroup(const QString& group); + QString group() const; + private: DataEntityPrivate *d {nullptr}; }; } // UkuiMenu +Q_DECLARE_METATYPE(UkuiMenu::DataType) + #endif //UKUI_MENU_DATA_ENTITY_H