1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#ifndef PROJECTINFO_H
6#define PROJECTINFO_H
7
8#include "projectactioninfo.h"
9
10#include <QSet>
11#include <QVariantHash>
12#include <QStandardItem>
13
14namespace dpfservice {
15
16enum
17{
18 ProjectInfoRole = Qt::ItemDataRole::UserRole,
19};
20
21class ProjectInfo
22{
23public:
24 ProjectInfo() : data({}) {}
25 ProjectInfo(const ProjectInfo &other) {data = other.data;}
26
27 bool operator == (const ProjectInfo &other) const {return data == other.data;}
28 bool isEmpty() const {return data.isEmpty();}
29 inline bool hasKey(const QString &key) {return data.keys().contains(key);}
30
31 inline void setProperty(const QString &key, QVariant value) {data[key] = value;}
32 inline QVariant property(const QString &key) const {return data[key];}
33
34 inline void setLanguage(const QString &language) {data["Language"] = language;}
35 inline void setKitName(const QString &kitName) {data["KitName"] = kitName;}
36 inline void setBuildFolder(const QString &buildPath) {data["BuildFolder"] = buildPath;}
37 inline void setWorkspaceFolder(const QString &workspaceFolder) {data["WorkspaceFolder"] = workspaceFolder;}
38 inline void setBuildType(const QString &buildType) {data["BuildType"] = buildType;}
39 inline void setBuildProgram(const QString &program) {data["BuildProgram"] = program;}
40 inline void setConfigCustomArgs(const QStringList &args) {data["ConfigCustomArgs"] = args;}
41 inline void setSourceFiles(const QSet<QString> &files) {data["SourceFiles"] = QVariant::fromValue(files);}
42 inline void setDetailInformation(bool isDetail) {data["DetailInformation"] = isDetail;}
43
44 inline void setBuildCustomArgs(const QStringList &args) {data["BuildCustomArgs"] = args;}
45 inline void setCleanCustomArgs(const QStringList &args) {data["CleanCustomArgs"] = args;}
46 inline void setRunProgram(const QString &program) {data["RunProgram"] = program;}
47 inline void setRunCustomArgs(const QStringList &args) {data["RunCustomArgs"] = args;}
48 inline void setRunWorkspaceDir(const QString &workspaceDir) {data["RunWorkspaceDir"] = workspaceDir;}
49
50 inline QString language() const {return data["Language"].toString();}
51 inline QString kitName() const {return data["KitName"].toString();}
52 inline QString buildFolder() const {return data["BuildFolder"].toString();}
53 inline QString workspaceFolder() const {return data["WorkspaceFolder"].toString();}
54 inline QString buildType() const {return data["BuildType"].toString();}
55 inline QString buildProgram() const {return data["BuildProgram"].toString();}
56 inline QStringList configCustomArgs() const {return data["ConfigCustomArgs"].toStringList();}
57 inline QSet<QString> sourceFiles() const {return qvariant_cast<QSet<QString>>(data["SourceFiles"]);}
58 inline bool detailInformation() const {return data["DetailInformation"].toBool();}
59
60 inline QStringList buildCustomArgs() const {return data["BuildCustomArgs"].toStringList();}
61 inline QStringList cleanCustomArgs() const {return data["CleanCustomArgs"].toStringList();}
62 inline QString runProgram() const {return data["RunProgram"].toString();}
63 inline QStringList runCustomArgs() const {return data["RunCustomArgs"].toStringList();}
64 inline QString runWorkspaceDir() const {return data["RunWorkspaceDir"].toString();}
65
66 inline static void set(QStandardItem *root, const ProjectInfo &info)
67 {
68 if (root)
69 root->setData(QVariant::fromValue(info), ProjectInfoRole);
70 }
71
72 inline static ProjectInfo get(const QModelIndex &root)
73 {
74 if (root.isValid())
75 return qvariant_cast<ProjectInfo>(root.data(ProjectInfoRole));
76 return {};
77 }
78
79 inline static ProjectInfo get(const QStandardItem *root)
80 {
81 if (root)
82 return qvariant_cast<ProjectInfo>(root->data(ProjectInfoRole));
83 return {};
84 }
85
86 inline static void set(QStandardItem *any, const QString &key, const QVariant &value)
87 {
88 if (any) {
89 auto info = get(any);
90 info.setProperty(key, value);
91 set(any, info);
92 }
93 }
94
95 bool isVaild()
96 {
97 if (kitName().isEmpty() || workspaceFolder().isEmpty() || language().isEmpty())
98 return false;
99 return true;
100 }
101
102 bool isSame(const ProjectInfo &other)
103 {
104 if (other.kitName() == kitName()
105 && other.workspaceFolder() == workspaceFolder()
106 && other.language() == language())
107 return true;
108 return false;
109 }
110
111private:
112 QVariantHash data;
113};
114
115} // namespace dpfservice
116
117Q_DECLARE_METATYPE(dpfservice::ProjectInfo)
118
119#endif // PROJECTINFO_H
120