2015-03-10 00:13:55 +00:00
|
|
|
// AircraftModel.hxx - part of GUI launcher using Qt5
|
|
|
|
//
|
|
|
|
// Written by James Turner, started March 2015.
|
|
|
|
//
|
2015-03-13 16:29:20 +00:00
|
|
|
// Copyright (C) 2015 James Turner <zakalawe@mac.com>
|
2015-03-10 00:13:55 +00:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
#ifndef FG_GUI_AIRCRAFT_MODEL
|
|
|
|
#define FG_GUI_AIRCRAFT_MODEL
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QPixmap>
|
2015-03-11 23:20:18 +00:00
|
|
|
#include <QStringList>
|
2015-08-03 20:53:56 +00:00
|
|
|
#include <QUrl>
|
2015-03-10 00:13:55 +00:00
|
|
|
|
2017-10-09 20:53:26 +00:00
|
|
|
#include "LocalAircraftCache.hxx"
|
|
|
|
|
2016-11-08 08:26:54 +00:00
|
|
|
#include <simgear/package/Delegate.hxx>
|
2015-03-10 08:30:55 +00:00
|
|
|
#include <simgear/package/Root.hxx>
|
2016-11-30 21:33:16 +00:00
|
|
|
#include <simgear/package/Catalog.hxx>
|
|
|
|
#include <simgear/package/Package.hxx>
|
2015-03-10 08:30:55 +00:00
|
|
|
|
2015-03-10 00:13:55 +00:00
|
|
|
const int AircraftPathRole = Qt::UserRole + 1;
|
|
|
|
const int AircraftAuthorsRole = Qt::UserRole + 2;
|
|
|
|
const int AircraftVariantRole = Qt::UserRole + 3;
|
|
|
|
const int AircraftVariantCountRole = Qt::UserRole + 4;
|
2015-03-13 16:29:20 +00:00
|
|
|
const int AircraftPackageIdRole = Qt::UserRole + 6;
|
|
|
|
const int AircraftPackageStatusRole = Qt::UserRole + 7;
|
|
|
|
const int AircraftPackageProgressRole = Qt::UserRole + 8;
|
2015-03-16 15:07:44 +00:00
|
|
|
const int AircraftLongDescriptionRole = Qt::UserRole + 9;
|
2015-03-16 16:34:22 +00:00
|
|
|
const int AircraftHasRatingsRole = Qt::UserRole + 10;
|
2015-08-03 20:53:56 +00:00
|
|
|
const int AircraftInstallPercentRole = Qt::UserRole + 11;
|
|
|
|
const int AircraftPackageSizeRole = Qt::UserRole + 12;
|
|
|
|
const int AircraftInstallDownloadedSizeRole = Qt::UserRole + 13;
|
|
|
|
const int AircraftURIRole = Qt::UserRole + 14;
|
2015-11-17 07:36:54 +00:00
|
|
|
const int AircraftIsHelicopterRole = Qt::UserRole + 16;
|
|
|
|
const int AircraftIsSeaplaneRole = Qt::UserRole + 17;
|
2016-11-30 21:33:16 +00:00
|
|
|
const int AircraftPackageRefRole = Qt::UserRole + 19;
|
2017-02-06 14:09:07 +00:00
|
|
|
const int AircraftThumbnailRole = Qt::UserRole + 20;
|
2015-03-13 16:29:20 +00:00
|
|
|
|
2017-06-22 09:45:47 +00:00
|
|
|
const int AircraftStatusRole = Qt::UserRole + 22;
|
|
|
|
const int AircraftMinVersionRole = Qt::UserRole + 23;
|
|
|
|
|
2015-03-10 00:13:55 +00:00
|
|
|
const int AircraftRatingRole = Qt::UserRole + 100;
|
|
|
|
const int AircraftVariantDescriptionRole = Qt::UserRole + 200;
|
|
|
|
|
2015-09-28 00:44:29 +00:00
|
|
|
class PackageDelegate;
|
2015-08-03 20:53:56 +00:00
|
|
|
|
2016-11-30 21:33:16 +00:00
|
|
|
Q_DECLARE_METATYPE(simgear::pkg::PackageRef)
|
|
|
|
|
2015-03-10 00:13:55 +00:00
|
|
|
class AircraftItemModel : public QAbstractListModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2017-06-22 09:45:47 +00:00
|
|
|
|
2015-03-10 00:13:55 +00:00
|
|
|
public:
|
2017-06-22 09:45:47 +00:00
|
|
|
|
2016-03-24 15:10:06 +00:00
|
|
|
AircraftItemModel(QObject* pr);
|
2015-03-10 00:13:55 +00:00
|
|
|
|
2018-10-08 11:31:27 +00:00
|
|
|
~AircraftItemModel() override;
|
2015-03-10 00:13:55 +00:00
|
|
|
|
2016-03-24 15:10:06 +00:00
|
|
|
void setPackageRoot(const simgear::pkg::RootRef& root);
|
|
|
|
|
2017-06-22 09:45:47 +00:00
|
|
|
int rowCount(const QModelIndex& parent) const override;
|
2015-08-03 20:53:56 +00:00
|
|
|
|
2017-06-22 09:45:47 +00:00
|
|
|
QVariant data(const QModelIndex& index, int role) const override;
|
2015-03-10 00:13:55 +00:00
|
|
|
|
2017-06-22 09:45:47 +00:00
|
|
|
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
|
|
|
|
|
|
|
QHash<int, QByteArray> roleNames() const override;
|
2015-03-10 00:13:55 +00:00
|
|
|
|
2015-03-13 16:29:20 +00:00
|
|
|
/**
|
|
|
|
* given a -set.xml path, return the corresponding model index, if one
|
|
|
|
* exists.
|
|
|
|
*/
|
|
|
|
|
2015-08-03 20:53:56 +00:00
|
|
|
QModelIndex indexOfAircraftURI(QUrl uri) const;
|
2016-11-18 16:10:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ensure the appropriate variant index is active in the model, for the
|
|
|
|
* corresponding aircraft URI
|
|
|
|
*/
|
|
|
|
void selectVariantForAircraftURI(QUrl uri);
|
|
|
|
|
2015-08-03 20:53:56 +00:00
|
|
|
/**
|
|
|
|
* return if a given aircraft is ready to be run, or not. Aircraft which
|
|
|
|
* are not installed, or are downloading, are not runnable.
|
|
|
|
*/
|
|
|
|
bool isIndexRunnable(const QModelIndex& index) const;
|
2016-12-18 21:25:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the display name for an aircraft specified by URI, without
|
|
|
|
* changing the current variant state
|
|
|
|
*/
|
|
|
|
QString nameForAircraftURI(QUrl uri) const;
|
2016-03-05 09:35:02 +00:00
|
|
|
|
2015-08-03 20:53:56 +00:00
|
|
|
signals:
|
|
|
|
void aircraftInstallFailed(QModelIndex index, QString errorMessage);
|
|
|
|
|
|
|
|
void aircraftInstallCompleted(QModelIndex index);
|
|
|
|
|
2018-07-23 08:10:08 +00:00
|
|
|
void contentsChanged();
|
2015-03-10 00:13:55 +00:00
|
|
|
private slots:
|
2017-10-09 20:53:26 +00:00
|
|
|
void onScanStarted();
|
|
|
|
void onScanAddedItems(int count);
|
2017-12-15 15:42:36 +00:00
|
|
|
void onLocalCacheCleared();
|
2015-03-10 00:13:55 +00:00
|
|
|
|
|
|
|
private:
|
2015-08-03 20:53:56 +00:00
|
|
|
friend class PackageDelegate;
|
2015-09-28 00:44:29 +00:00
|
|
|
|
2016-11-16 21:27:00 +00:00
|
|
|
/**
|
|
|
|
* struct to record persistent state from the item-delegate, about the
|
|
|
|
* currently visible variant, thumbnail and similar.
|
|
|
|
*/
|
|
|
|
struct DelegateState
|
|
|
|
{
|
|
|
|
quint32 variant = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
QVariant dataFromItem(AircraftItemPtr item, const DelegateState& state, int role) const;
|
2015-03-13 16:29:20 +00:00
|
|
|
|
|
|
|
QVariant dataFromPackage(const simgear::pkg::PackageRef& item,
|
2016-11-16 21:27:00 +00:00
|
|
|
const DelegateState& state, int role) const;
|
2015-03-13 16:29:20 +00:00
|
|
|
|
2018-10-08 11:31:27 +00:00
|
|
|
QVariant packageRating(const simgear::pkg::PackageRef& p, int ratingIndex) const;
|
2016-11-16 21:27:00 +00:00
|
|
|
QVariant packageThumbnail(simgear::pkg::PackageRef p,
|
|
|
|
const DelegateState& state, bool download = true) const;
|
2016-04-15 16:06:53 +00:00
|
|
|
|
2017-02-06 14:09:07 +00:00
|
|
|
QVariant packagePreviews(simgear::pkg::PackageRef p, const DelegateState &ds) const;
|
|
|
|
|
2015-08-03 20:53:56 +00:00
|
|
|
void refreshPackages();
|
2018-06-28 22:45:52 +00:00
|
|
|
|
2015-08-03 20:53:56 +00:00
|
|
|
void installSucceeded(QModelIndex index);
|
|
|
|
void installFailed(QModelIndex index, simgear::pkg::Delegate::StatusCode reason);
|
|
|
|
|
2016-11-07 19:49:33 +00:00
|
|
|
PackageDelegate* m_delegate = nullptr;
|
2016-11-16 21:27:00 +00:00
|
|
|
|
|
|
|
QVector<DelegateState> m_delegateStates;
|
|
|
|
|
2015-03-10 08:30:55 +00:00
|
|
|
simgear::pkg::RootRef m_packageRoot;
|
2015-08-03 20:53:56 +00:00
|
|
|
simgear::pkg::PackageList m_packages;
|
|
|
|
|
2017-02-06 14:09:07 +00:00
|
|
|
mutable QHash<QString, QPixmap> m_downloadedPixmapCache;
|
2017-10-09 20:53:26 +00:00
|
|
|
int m_cachedLocalAircraftCount = 0;
|
2015-03-10 00:13:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // of FG_GUI_AIRCRAFT_MODEL
|