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