]> git.mxchange.org Git - flightgear.git/blob - src/GUI/AircraftModel.hxx
Start wiring package manager into the launcher.
[flightgear.git] / src / GUI / AircraftModel.hxx
1 // AircraftModel.hxx - part of GUI launcher using Qt5
2 //
3 // Written by James Turner, started March 2015.
4 //
5 // Copyright (C) 2014 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_AIRCRAFT_MODEL
22 #define FG_GUI_AIRCRAFT_MODEL
23
24 #include <QAbstractListModel>
25 #include <QDateTime>
26 #include <QDir>
27 #include <QPixmap>
28
29 #include <simgear/package/Root.hxx>
30
31 const int AircraftPathRole = Qt::UserRole + 1;
32 const int AircraftAuthorsRole = Qt::UserRole + 2;
33 const int AircraftVariantRole = Qt::UserRole + 3;
34 const int AircraftVariantCountRole = Qt::UserRole + 4;
35 const int AircraftRatingRole = Qt::UserRole + 100;
36 const int AircraftVariantDescriptionRole = Qt::UserRole + 200;
37
38 class AircraftScanThread;
39 class QDataStream;
40
41 struct AircraftItem
42 {
43     AircraftItem();
44
45     AircraftItem(QDir dir, QString filePath);
46     
47     // the file-name without -set.xml suffix
48     QString baseName() const;
49     
50     void fromDataStream(QDataStream& ds);
51
52     void toDataStream(QDataStream& ds) const;
53
54     QPixmap thumbnail() const;
55
56     QString path;
57     QString description;
58     QString authors;
59     int ratings[4];
60     QString variantOf;
61     QDateTime pathModTime;
62
63     QList<AircraftItem*> variants;
64 private:
65     mutable QPixmap m_thumbnail;
66 };
67
68 class AircraftItemModel : public QAbstractListModel
69 {
70     Q_OBJECT
71 public:
72     AircraftItemModel(QObject* pr, simgear::pkg::RootRef& root);
73
74     ~AircraftItemModel();
75
76     virtual int rowCount(const QModelIndex& parent) const
77     {
78         return m_items.size();
79     }
80
81     virtual QVariant data(const QModelIndex& index, int role) const;
82     
83     virtual bool setData(const QModelIndex &index, const QVariant &value, int role);
84
85   QModelIndex indexOfAircraftPath(QString path) const;
86
87 private slots:
88     void onScanResults();
89     
90     void onScanFinished();
91
92 private:
93     AircraftScanThread* m_scanThread;
94     QList<AircraftItem*> m_items;
95     QList<quint32> m_activeVariant;
96     simgear::pkg::RootRef m_packageRoot;
97 };
98
99 #endif // of FG_GUI_AIRCRAFT_MODEL