Skip to content

Commit ded6410

Browse files
committed
WIP: Add package manager view
1 parent fd36e44 commit ded6410

16 files changed

Lines changed: 1447 additions & 0 deletions
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
#include "PackageListProxyModel_p.h"
2+
3+
#include <uishell/USDef.h>
4+
5+
namespace UIShell {
6+
7+
PackageListProxyModel::PackageListProxyModel(QObject *parent)
8+
: QIdentityProxyModel(parent) {
9+
}
10+
11+
PackageListProxyModel::~PackageListProxyModel() = default;
12+
13+
QHash<int, QByteArray> PackageListProxyModel::roleNames() const {
14+
static const QHash<int, QByteArray> m{
15+
{USDef::PR_IdRole, "id"},
16+
{USDef::PR_VersionRole, "version"},
17+
{USDef::PR_PathRole, "path"},
18+
{USDef::PR_InstallationTimeRole, "installationTime"},
19+
{USDef::PR_NameRole, "name"},
20+
{USDef::PR_DescriptionRole, "description"},
21+
{USDef::PR_VendorRole, "vendor"},
22+
{USDef::PR_ReadmePathRole, "readmePath"},
23+
{USDef::PR_LicensePathRole, "licensePath"},
24+
{USDef::PR_UrlRole, "url"},
25+
{USDef::PR_ClassNameRole, "className"},
26+
{USDef::PR_AvatarPathRole, "avatarPath"},
27+
{USDef::PR_BackgroundPathRole, "backgroundPath"},
28+
{USDef::PR_ImportInferenceIdRole, "importInferenceId"},
29+
};
30+
return m;
31+
}
32+
33+
QModelIndex PackageListProxyModel::packageModelIndex(int index) const {
34+
return this->index(index, 0);
35+
}
36+
37+
QModelIndex PackageListProxyModel::entryIndex(const QModelIndex &index) const {
38+
const auto singerRootIndex = this->singerRootIndexForIndex(index);
39+
if (!singerRootIndex.isValid() || rowCount(singerRootIndex) == 0) {
40+
const auto inferenceRootIndex = this->inferenceRootIndexForIndex(index);
41+
if (!inferenceRootIndex.isValid() || rowCount(inferenceRootIndex) == 0) {
42+
return singerRootIndex;
43+
}
44+
return inferenceRootIndex;
45+
}
46+
return this->index(0, 0, singerRootIndex);
47+
}
48+
49+
QModelIndex PackageListProxyModel::singerModelIndexForIndex(const QModelIndex &index) const {
50+
if (isSingerIndex(index)) {
51+
return index;
52+
}
53+
54+
const auto singerRootIndex = this->singerRootIndexForIndex(index);
55+
if (!singerRootIndex.isValid() || rowCount(singerRootIndex) == 0) {
56+
return singerRootIndex;
57+
}
58+
59+
return this->index(0, 0, singerRootIndex);
60+
}
61+
62+
QModelIndex PackageListProxyModel::packageModelIndexForIndex(const QModelIndex &index) const {
63+
if (!index.isValid() || index.model() != this) {
64+
return {};
65+
}
66+
67+
auto packageIndex = index;
68+
while (packageIndex.parent().isValid()) {
69+
packageIndex = packageIndex.parent();
70+
}
71+
72+
return packageIndex;
73+
}
74+
75+
QModelIndex PackageListProxyModel::dependencyRootIndexForIndex(const QModelIndex &index) const {
76+
const auto packageIndex = packageModelIndexForIndex(index);
77+
return packageIndex.isValid() ? this->index(USDef::PI_Dependencies, 0, packageIndex) : QModelIndex();
78+
}
79+
80+
QModelIndex PackageListProxyModel::singerRootIndexForIndex(const QModelIndex &index) const {
81+
const auto packageIndex = packageModelIndexForIndex(index);
82+
return packageIndex.isValid() ? this->index(USDef::PI_Singers, 0, packageIndex) : QModelIndex();
83+
}
84+
85+
QModelIndex PackageListProxyModel::inferenceRootIndexForIndex(const QModelIndex &index) const {
86+
const auto packageIndex = packageModelIndexForIndex(index);
87+
return packageIndex.isValid() ? this->index(USDef::PI_Inferences, 0, packageIndex) : QModelIndex();
88+
}
89+
90+
QModelIndex PackageListProxyModel::importRootIndexForSingerIndex(const QModelIndex &index) const {
91+
return isSingerIndex(index) ? this->index(USDef::PI_SingerImports, 0, index) : QModelIndex();
92+
}
93+
94+
QModelIndex PackageListProxyModel::demoAudioRootIndexForSingerIndex(const QModelIndex &index) const {
95+
return isSingerIndex(index) ? this->index(USDef::PI_SingerDemoAudioList, 0, index) : QModelIndex();
96+
}
97+
98+
bool PackageListProxyModel::isSingerOrSingerRootIndex(const QModelIndex &index) const {
99+
if (!index.isValid() || index.model() != this) {
100+
return false;
101+
}
102+
103+
if (isSingerIndex(index)) {
104+
return true;
105+
}
106+
107+
return index.row() == USDef::PI_Singers &&
108+
index.parent().isValid() &&
109+
!index.parent().parent().isValid();
110+
}
111+
112+
bool PackageListProxyModel::isInferenceOrInferenceRootIndex(const QModelIndex &index) const {
113+
if (!index.isValid() || index.model() != this) {
114+
return false;
115+
}
116+
117+
if (isInferenceIndex(index)) {
118+
return true;
119+
}
120+
121+
return index.row() == USDef::PI_Inferences &&
122+
index.parent().isValid() &&
123+
!index.parent().parent().isValid();
124+
}
125+
126+
bool PackageListProxyModel::isPackageIndex(const QModelIndex &index) const {
127+
return index.isValid() &&
128+
index.model() == this &&
129+
!index.parent().isValid();
130+
}
131+
132+
bool PackageListProxyModel::isDependencyRootIndex(const QModelIndex &index) const {
133+
return index.isValid() &&
134+
index.model() == this &&
135+
index.row() == USDef::PI_Dependencies &&
136+
index.parent().isValid() &&
137+
!index.parent().parent().isValid();
138+
}
139+
140+
int PackageListProxyModel::findPackageIndex(const QString &id, const QString &version) const {
141+
for (int i = 0; i < rowCount(); ++i) {
142+
const auto packageIndex = index(i, 0);
143+
if (data(packageIndex, USDef::PR_IdRole).toString() == id &&
144+
data(packageIndex, USDef::PR_VersionRole).toString() == version) {
145+
return i;
146+
}
147+
}
148+
return -1;
149+
}
150+
151+
QModelIndex PackageListProxyModel::findInferenceIndex(const QString &id, const QString &version, const QString &inferenceId) const {
152+
const int packageRow = findPackageIndex(id, version);
153+
if (packageRow < 0) {
154+
return {};
155+
}
156+
157+
const auto packageIndex = index(packageRow, 0);
158+
const auto inferencesIndex = index(USDef::PI_Inferences, 0, packageIndex);
159+
if (!inferencesIndex.isValid()) {
160+
return {};
161+
}
162+
163+
for (int i = 0; i < rowCount(inferencesIndex); ++i) {
164+
const auto inferenceIndex = index(i, 0, inferencesIndex);
165+
if (data(inferenceIndex, USDef::PR_IdRole).toString() == inferenceId) {
166+
return inferenceIndex;
167+
}
168+
}
169+
170+
return {};
171+
}
172+
173+
int PackageListProxyModel::packageIndexForIndex(const QModelIndex &index) const {
174+
if (!index.isValid() || index.model() != this) {
175+
return -1;
176+
}
177+
178+
auto packageIndex = index;
179+
while (packageIndex.parent().isValid()) {
180+
packageIndex = packageIndex.parent();
181+
}
182+
183+
return packageIndex.row();
184+
}
185+
186+
bool PackageListProxyModel::isSingerIndex(const QModelIndex &index) const {
187+
if (!index.isValid() || index.model() != this) {
188+
return false;
189+
}
190+
191+
const auto parentIndex = index.parent();
192+
return parentIndex.isValid() &&
193+
parentIndex.row() == USDef::PI_Singers &&
194+
parentIndex.parent().isValid() &&
195+
!parentIndex.parent().parent().isValid();
196+
}
197+
198+
bool PackageListProxyModel::isInferenceIndex(const QModelIndex &index) const {
199+
if (!index.isValid() || index.model() != this) {
200+
return false;
201+
}
202+
203+
const auto parentIndex = index.parent();
204+
return parentIndex.isValid() &&
205+
parentIndex.row() == USDef::PI_Inferences &&
206+
parentIndex.parent().isValid() &&
207+
!parentIndex.parent().parent().isValid();
208+
}
209+
210+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#ifndef UISHELL_PACKAGELISTPROXYMODEL_P_H
2+
#define UISHELL_PACKAGELISTPROXYMODEL_P_H
3+
4+
#include <qqmlintegration.h>
5+
6+
#include <QIdentityProxyModel>
7+
#include <QString>
8+
9+
namespace UIShell {
10+
11+
class PackageListProxyModel : public QIdentityProxyModel {
12+
Q_OBJECT
13+
QML_NAMED_ELEMENT(PackageListProxyModel)
14+
public:
15+
explicit PackageListProxyModel(QObject *parent = nullptr);
16+
~PackageListProxyModel() override;
17+
18+
QHash<int, QByteArray> roleNames() const override;
19+
20+
Q_INVOKABLE static QModelIndex invalidIndex() {
21+
return QModelIndex();
22+
}
23+
Q_INVOKABLE QModelIndex packageModelIndex(int index) const;
24+
25+
Q_INVOKABLE QModelIndex entryIndex(const QModelIndex &index) const;
26+
Q_INVOKABLE QModelIndex singerModelIndexForIndex(const QModelIndex &index) const;
27+
28+
Q_INVOKABLE QModelIndex packageModelIndexForIndex(const QModelIndex &index) const;
29+
Q_INVOKABLE QModelIndex dependencyRootIndexForIndex(const QModelIndex &index) const;
30+
Q_INVOKABLE QModelIndex singerRootIndexForIndex(const QModelIndex &index) const;
31+
Q_INVOKABLE QModelIndex inferenceRootIndexForIndex(const QModelIndex &index) const;
32+
Q_INVOKABLE QModelIndex importRootIndexForSingerIndex(const QModelIndex &index) const;
33+
Q_INVOKABLE QModelIndex demoAudioRootIndexForSingerIndex(const QModelIndex &index) const;
34+
35+
Q_INVOKABLE bool isSingerOrSingerRootIndex(const QModelIndex &index) const;
36+
Q_INVOKABLE bool isInferenceOrInferenceRootIndex(const QModelIndex &index) const;
37+
Q_INVOKABLE bool isPackageIndex(const QModelIndex &index) const;
38+
Q_INVOKABLE bool isDependencyRootIndex(const QModelIndex &index) const;
39+
40+
Q_INVOKABLE int findPackageIndex(const QString &id, const QString &version) const;
41+
Q_INVOKABLE QModelIndex findInferenceIndex(const QString &id, const QString &version, const QString &inferenceId) const;
42+
43+
Q_INVOKABLE int packageIndexForIndex(const QModelIndex &index) const;
44+
45+
private:
46+
bool isSingerIndex(const QModelIndex &index) const;
47+
bool isInferenceIndex(const QModelIndex &index) const;
48+
};
49+
50+
}
51+
52+
#endif // UISHELL_PACKAGELISTPROXYMODEL_P_H

src/libs/application/uishell/src/USDef.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,34 @@ namespace UIShell {
3535
};
3636
Q_ENUM_NS(AchievementRole)
3737

38+
enum PackageRole {
39+
PR_IdRole = Qt::UserRole + 1,
40+
PR_VersionRole,
41+
PR_PathRole,
42+
PR_InstallationTimeRole,
43+
PR_NameRole,
44+
PR_DescriptionRole,
45+
PR_VendorRole,
46+
PR_ReadmePathRole,
47+
PR_LicensePathRole,
48+
PR_UrlRole,
49+
PR_ClassNameRole,
50+
PR_AvatarPathRole,
51+
PR_BackgroundPathRole,
52+
PR_ImportInferenceIdRole,
53+
};
54+
Q_ENUM_NS(PackageRole)
55+
56+
enum PackageIndex {
57+
PI_Dependencies = 0,
58+
PI_Inferences = 1,
59+
PI_Singers = 2,
60+
61+
PI_SingerImports = 0,
62+
PI_SingerDemoAudioList = 1,
63+
};
64+
Q_ENUM_NS(PackageIndex)
65+
3866
}
3967

4068
}

0 commit comments

Comments
 (0)