-
Notifications
You must be signed in to change notification settings - Fork 4
/
packagemodel.h
66 lines (51 loc) · 1.76 KB
/
packagemodel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef PACKAGEMODEL_H
#define PACKAGEMODEL_H
#include <QAbstractListModel>
#include <QSettings>
struct PackageData {
QString packageName;
QString packageDesc;
QString category;
bool isInstalled;
bool isChecked;
};
class PackageModel : public QAbstractListModel
{
Q_OBJECT
public:
explicit PackageModel(QObject *parent = nullptr);
enum {
NameRole = Qt::UserRole,
DescriptionRole,
CategoryRole,
IsInstalledRole,
IsCheckedRole
};
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex &index, const QVariant &value,
int role = Qt::EditRole) override;
Qt::ItemFlags flags(const QModelIndex& index) const override;
virtual QHash<int, QByteArray> roleNames() const override;
/*
* Populates the model from @p settings. Each group except general is treated
* as a category, each key is a package and each value a description. All
* packages are set as unchecked initially. To set isInstalled the package
* names are compared to @p installedPackageList
*
* Returns true on success, false otherwise
*/
bool loadModel(QSettings &settings, const QStringList &installedPackageList);
/*
* Refreshes the model by unchecking all items in the model and revaluating
* each items installed status against @p installedPackageList
*/
void refresh(const QStringList &installedPackageList);
/*
* Returns a QStringList of package names for package which is checked
*/
const QStringList getCheckedPackages();
private:
QList<PackageData> m_model;
};
#endif // PACKAGEMODEL_H