FlightGear next
AddonsModel.hxx
Go to the documentation of this file.
1// AddonsModel.hxx - part of GUI launcher using Qt5
2//
3// Written by Dan Wickstrom, started February 2019.
4//
5// Copyright (C) 2019 Daniel Wickstrom <daniel.c.wickstrom@gmail.com>
6//
7// This program is free software; you can redistribute it and/or
8// modify it under the terms of the GNU General Public License as
9// published by the Free Software Foundation; either version 2 of the
10// License, or (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful, but
13// WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15// General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program; if not, write to the Free Software
19// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
21#ifndef FG_GUI_METADATA_LIST_MODEL
22#define FG_GUI_METADATA_LIST_MODEL
23
24#include <QAbstractListModel>
25#include <QDateTime>
26#include <QDir>
27#include <QPixmap>
28#include <QStringList>
29#include <set>
30#include <simgear/package/Root.hxx>
31#include <simgear/package/Catalog.hxx>
32#include "Add-ons/addon_fwd.hxx"
33#include "Add-ons/Addon.hxx"
35
36
37
38class AddonsModel : public QAbstractListModel
39{
40 Q_OBJECT
41
42 using AddonsMeta = struct { bool enable; flightgear::addons::AddonRef addon; };
43 using AddonsMap = QHash<QString, AddonsMeta>;
44public:
45
46 AddonsModel(QObject* pr);
47
49
50 int rowCount(const QModelIndex& parent) const override;
51
52 QVariant data(const QModelIndex& index, int role) const override;
53 Q_INVOKABLE QVariant get(int index, int role) const;
54 Q_INVOKABLE QVariant get(int index, QString role) const;
55
56 bool setData(const QModelIndex &index, const QVariant &value, int role) override;
57
58 Qt::ItemFlags flags(const QModelIndex &index) const override;
59
60 QHash<int, QByteArray> roleNames() const override;
61
62 bool append(QString path, flightgear::addons::AddonRef& addon, bool enable);
63
64 void resetData(const QStringList& ndata);
65
66 Q_INVOKABLE bool checkVersion(QString path) const;
67
68 bool getPathEnable(const QString& path) { return m_addonsMap[path].enable; }
69 bool containsPath(const QString& path) { return m_addonsMap.contains(path); }
70
71 Q_INVOKABLE void enable(int index, bool enable);
72
73 // this must stay in sync with m_roles stringlist
95
96 Q_ENUMS(AddonRoles)
97
98signals:
100
101private:
102 // this must stay in sync with MetaRoles enum
103 const QStringList m_roles = {
104 "id",
105 "name",
106 "path",
107 "version",
108 "authors",
109 "maintainers",
110 "short_description",
111 "long_description",
112 "license_designation",
113 "license_url",
114 "tags",
115 "minversion_fg",
116 "maxversion_fg",
117 "homepage",
118 "download_url",
119 "support_url",
120 "coderepo_url",
121 "enable"
122 };
123
124 QStringList m_addonsList;
125 AddonsMap m_addonsMap;
126 QHash<int, QByteArray> m_roleToName;
127 QHash<QString, int> m_nameToRole;
128};
129
130#endif // of Metadata_LIST_MODEL
bool getPathEnable(const QString &path)
Q_INVOKABLE bool checkVersion(QString path) const
bool containsPath(const QString &path)
Q_INVOKABLE void enable(int index, bool enable)
bool append(QString path, flightgear::addons::AddonRef &addon, bool enable)
AddonsModel(QObject *pr)
bool setData(const QModelIndex &index, const QVariant &value, int role) override
void resetData(const QStringList &ndata)
void modulesChanged()
Qt::ItemFlags flags(const QModelIndex &index) const override
QHash< int, QByteArray > roleNames() const override
int rowCount(const QModelIndex &parent) const override
QVariant data(const QModelIndex &index, int role) const override
Q_INVOKABLE QVariant get(int index, int role) const
SGSharedPtr< Addon > AddonRef
Definition addon_fwd.hxx:46