1 // AircraftModel.hxx - part of GUI launcher using Qt5
3 // Written by James Turner, started March 2015.
5 // Copyright (C) 2015 James Turner <zakalawe@mac.com>
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.
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.
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.
21 #ifndef FG_GUI_AIRCRAFT_MODEL
22 #define FG_GUI_AIRCRAFT_MODEL
24 #include <QAbstractListModel>
28 #include <QStringList>
30 #include <simgear/package/Root.hxx>
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 AircraftThumbnailCountRole = Qt::UserRole + 5;
37 const int AircraftPackageIdRole = Qt::UserRole + 6;
38 const int AircraftPackageStatusRole = Qt::UserRole + 7;
39 const int AircraftPackageProgressRole = Qt::UserRole + 8;
40 const int AircraftLongDescriptionRole = Qt::UserRole + 9;
41 const int AircraftHasRatingsRole = Qt::UserRole + 10;
43 const int AircraftRatingRole = Qt::UserRole + 100;
44 const int AircraftVariantDescriptionRole = Qt::UserRole + 200;
45 const int AircraftThumbnailRole = Qt::UserRole + 300;
47 class AircraftScanThread;
54 AircraftItem(QDir dir, QString filePath);
56 // the file-name without -set.xml suffix
57 QString baseName() const;
59 void fromDataStream(QDataStream& ds);
61 void toDataStream(QDataStream& ds) const;
63 QPixmap thumbnail() const;
71 QDateTime pathModTime;
73 QList<AircraftItem*> variants;
75 mutable QPixmap m_thumbnail;
79 enum AircraftItemStatus {
82 PackageUpdateAvailable,
86 class AircraftItemModel : public QAbstractListModel
90 AircraftItemModel(QObject* pr, simgear::pkg::RootRef& root);
94 void setPaths(QStringList paths);
98 virtual int rowCount(const QModelIndex& parent) const
100 return m_items.size();
103 virtual QVariant data(const QModelIndex& index, int role) const;
105 virtual bool setData(const QModelIndex &index, const QVariant &value, int role);
108 * given a -set.xml path, return the corresponding model index, if one
111 QModelIndex indexOfAircraftPath(QString path) const;
114 void onScanResults();
116 void onScanFinished();
119 QVariant dataFromItem(const AircraftItem* item, quint32 variantIndex, int role) const;
121 QVariant dataFromPackage(const simgear::pkg::PackageRef& item,
122 quint32 variantIndex, int role) const;
124 void abandonCurrentScan();
127 AircraftScanThread* m_scanThread;
128 QList<AircraftItem*> m_items;
129 QList<quint32> m_activeVariant;
130 simgear::pkg::RootRef m_packageRoot;
133 #endif // of FG_GUI_AIRCRAFT_MODEL