summaryrefslogtreecommitdiff
path: root/ui/qt5/pkgmodel.hh
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-12-14 12:57:55 -0600
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-12-14 12:57:55 -0600
commit217893db033788ed0770927141e27990762fefb4 (patch)
tree635bd9eab52052526f0718af8c85941692e296b0 /ui/qt5/pkgmodel.hh
parentdf550933fb33ad6ed8bbbf7559afa1f6d797ac85 (diff)
downloadhorizon-217893db033788ed0770927141e27990762fefb4.tar.gz
horizon-217893db033788ed0770927141e27990762fefb4.tar.bz2
horizon-217893db033788ed0770927141e27990762fefb4.tar.xz
horizon-217893db033788ed0770927141e27990762fefb4.zip
Qt UI: Implement custom package selection
Diffstat (limited to 'ui/qt5/pkgmodel.hh')
-rw-r--r--ui/qt5/pkgmodel.hh76
1 files changed, 76 insertions, 0 deletions
diff --git a/ui/qt5/pkgmodel.hh b/ui/qt5/pkgmodel.hh
new file mode 100644
index 0000000..85070ee
--- /dev/null
+++ b/ui/qt5/pkgmodel.hh
@@ -0,0 +1,76 @@
+/*
+ * pkgmodel.hh - Definition of the custom package selection model classes
+ * horizon-qt5, the Qt 5 user interface for
+ * Project Horizon
+ *
+ * Copyright (c) 2019 Adélie Linux and contributors. All rights reserved.
+ * This code is licensed under the AGPL 3.0 license, as noted in the
+ * LICENSE-code file in the root directory of this repository.
+ *
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+#ifndef PKGMODEL_HH
+#define PKGMODEL_HH
+
+#include <QAbstractItemModel>
+
+class PkgItem {
+public:
+ explicit PkgItem(PkgItem *parent, QString friendly, QString internal,
+ QString description, QString icon = "");
+ ~PkgItem();
+
+ void addChild(PkgItem *pkg);
+ PkgItem *child(int row);
+ int childCount() const;
+ QVariant data(int column, int role);
+ QStringList internalNames() const;
+ int row() const;
+ PkgItem *parent();
+
+private:
+ QVector<PkgItem *> _children;
+ PkgItem *_parent;
+ /*! The "friendly" or displayed name for this item. */
+ QString _friendly;
+ /*! The internal name. Typically the APK package name. */
+ QString _internal;
+ /*! The description of the item. */
+ QString _desc;
+ /*! The icon to display for this item. Defaults to internal. */
+ QString _icon;
+};
+
+class PkgItemModel : public QAbstractItemModel {
+Q_OBJECT
+public:
+ explicit PkgItemModel(QStringList *pkgList = nullptr,
+ QObject *parent = nullptr);
+ ~PkgItemModel();
+
+ QVariant data(const QModelIndex &index,
+ int role = Qt::DisplayRole) const override;
+ Qt::ItemFlags flags(const QModelIndex &index) const override;
+ QVariant headerData(int section, Qt::Orientation orientation,
+ int role = Qt::DisplayRole) const override;
+ QModelIndex index(int row, int column,
+ const QModelIndex &parent = QModelIndex()) const override;
+ QModelIndex parent(const QModelIndex &child) const override;
+ int rowCount(const QModelIndex &parent = QModelIndex()) const override;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const override;
+ bool setData(const QModelIndex &index, const QVariant &value,
+ int role = Qt::EditRole) override;
+ void setPackageList(QStringList *pkgList);
+
+private:
+ void loadPackages();
+ /*! The list of packages that will be installed.
+ * Determines which packages are ticked. */
+ QStringList *_packages;
+ /*! The special root item, which all other items have as an eventual
+ * parent. */
+ PkgItem *_root;
+};
+
+#endif /* !PKGMODEL_HH */