FlightGear next
CatalogListModel.hxx
Go to the documentation of this file.
1// CatalogListModel.hxx - part of GUI launcher using Qt5
2//
3// Written by James Turner, started March 2015.
4//
5// Copyright (C) 2015 James Turner <zakalawe@mac.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_CATALOG_LIST_MODEL
22#define FG_GUI_CATALOG_LIST_MODEL
23
24#include <QAbstractListModel>
25#include <QDateTime>
26#include <QDir>
27#include <QPixmap>
28#include <QStringList>
29#include <QUrl>
30
31#include <simgear/package/Root.hxx>
32#include <simgear/package/Catalog.hxx>
33
34const int CatalogUrlRole = Qt::UserRole + 1;
35const int CatalogIdRole = Qt::UserRole + 2;
36const int CatalogPackageCountRole = Qt::UserRole + 3;
37const int CatalogInstallCountRole = Qt::UserRole + 4;
38const int CatalogStatusRole = Qt::UserRole + 5;
39const int CatalogDescriptionRole = Qt::UserRole + 6;
40const int CatalogNameRole = Qt::UserRole + 7;
41const int CatalogIsNewlyAdded = Qt::UserRole + 8;
42const int CatalogEnabled = Qt::UserRole + 9;
43
44class CatalogDelegate;
45
46class CatalogListModel : public QAbstractListModel
47{
48 Q_OBJECT
49
52public:
53 CatalogListModel(QObject* pr, const simgear::pkg::RootRef& root);
54
56
57 int rowCount(const QModelIndex& parent) const override;
58
59 QVariant data(const QModelIndex& index, int role) const override;
60
61 bool setData(const QModelIndex &index, const QVariant &value, int role) override;
62
63 Qt::ItemFlags flags(const QModelIndex &index) const override;
64
65 QHash<int, QByteArray> roleNames() const override;
66
67 Q_INVOKABLE void removeCatalog(int index);
68
69 Q_INVOKABLE void refreshCatalog(int index);
70
71 Q_INVOKABLE void installDefaultCatalog(bool showAddFeedback);
72
73 // returns the index of the new catalog
74 Q_INVOKABLE void addCatalogByUrl(QUrl url);
75
76 Q_INVOKABLE void finalizeAddCatalog();
77
78 Q_INVOKABLE void abandonAddCatalog();
79
80 bool isAddingCatalog() const;
81
94
95 Q_ENUMS(CatalogStatus)
96
97 void onCatalogStatusChanged(simgear::pkg::Catalog *cat);
98
100
101signals:
104
106
107public slots:
108 void resetData();
109
110private slots:
111
112private:
113 simgear::pkg::RootRef m_packageRoot;
114 simgear::pkg::CatalogList m_catalogs;
115
116 simgear::pkg::CatalogRef m_newlyAddedCatalog;
117
118 int indexOf(QUrl url);
119
120 CatalogDelegate* m_delegate;
121
122 CatalogStatus translateStatusForCatalog(simgear::pkg::CatalogRef cat) const;
123};
124
125#endif // of FG_GUI_CATALOG_LIST_MODEL
const int CatalogNameRole
const int CatalogUrlRole
const int CatalogDescriptionRole
const int CatalogIdRole
const int CatalogEnabled
const int CatalogInstallCountRole
const int CatalogIsNewlyAdded
const int CatalogPackageCountRole
const int CatalogStatusRole
Q_INVOKABLE void abandonAddCatalog()
void catalogsChanged()
Q_INVOKABLE void finalizeAddCatalog()
int rowCount(const QModelIndex &parent) const override
Qt::ItemFlags flags(const QModelIndex &index) const override
CatalogListModel(QObject *pr, const simgear::pkg::RootRef &root)
QVariant data(const QModelIndex &index, int role) const override
void isAddingCatalogChanged()
void onCatalogStatusChanged(simgear::pkg::Catalog *cat)
CatalogStatus statusOfAddingCatalog
Q_INVOKABLE void refreshCatalog(int index)
Q_INVOKABLE void installDefaultCatalog(bool showAddFeedback)
QHash< int, QByteArray > roleNames() const override
Q_INVOKABLE void addCatalogByUrl(QUrl url)
Q_INVOKABLE void removeCatalog(int index)
bool setData(const QModelIndex &index, const QVariant &value, int role) override
void statusOfAddingCatalogChanged()