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