From d127a6ff9ab142be386ab3ed5db4e2c59ce20459 Mon Sep 17 00:00:00 2001 From: James Turner Date: Fri, 8 Dec 2017 22:03:09 +0000 Subject: [PATCH] Launcher: fix on-disk variant enumeration --- src/GUI/AircraftDetailsView.qml | 1 + src/GUI/AircraftModel.cxx | 5 +++-- src/GUI/QmlAircraftInfo.cxx | 31 +++++++++++++++++++++++-------- src/GUI/QmlAircraftInfo.hxx | 3 +++ 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/GUI/AircraftDetailsView.qml b/src/GUI/AircraftDetailsView.qml index b24ac618c..806023e92 100644 --- a/src/GUI/AircraftDetailsView.qml +++ b/src/GUI/AircraftDetailsView.qml @@ -104,6 +104,7 @@ Rectangle { } AircraftDownloadPanel { + visible: aircraft.isPackaged width: parent.width uri: aircraft.uri installStatus: aircraft.installStatus diff --git a/src/GUI/AircraftModel.cxx b/src/GUI/AircraftModel.cxx index 58f3ac952..81d7901c5 100644 --- a/src/GUI/AircraftModel.cxx +++ b/src/GUI/AircraftModel.cxx @@ -611,8 +611,9 @@ QString AircraftItemModel::nameForAircraftURI(QUrl uri) const // check variants too for (int vr=0; vr < item->variants.size(); ++vr) { - if (item->variants.at(vr)->path == path) { - return item->description; + auto variant = item->variants.at(vr); + if (variant->path == path) { + return variant->description; } } } else if (uri.scheme() == "package") { diff --git a/src/GUI/QmlAircraftInfo.cxx b/src/GUI/QmlAircraftInfo.cxx index cd5f833f0..f35526deb 100644 --- a/src/GUI/QmlAircraftInfo.cxx +++ b/src/GUI/QmlAircraftInfo.cxx @@ -89,7 +89,7 @@ QmlAircraftInfo::~QmlAircraftInfo() QUrl QmlAircraftInfo::uri() const { if (_item) { - QUrl::fromLocalFile(resolveItem()->path); + return QUrl::fromLocalFile(resolveItem()->path); } else if (_package) { return QUrl("package:" + QString::fromStdString(_package->qualifiedVariantId(_variant))); } @@ -100,8 +100,10 @@ QUrl QmlAircraftInfo::uri() const int QmlAircraftInfo::numVariants() const { if (_item) { - return _item->variants.size(); + // for on-disk, we don't count the primary item + return _item->variants.size() + 1; } else if (_package) { + // whereas for packaged aircraft we do return _package->variants().size(); } @@ -304,12 +306,11 @@ void QmlAircraftInfo::setUri(QUrl u) if (u.isLocalFile()) { _item = LocalAircraftCache::instance()->findItemWithUri(u); - if (_item->variantOf.isEmpty()) { - _variant = 0; - } else { - _item = LocalAircraftCache::instance()->primaryItemFor(_item); - _variant = _item->indexOfVariant(u); - } + int vindex = _item->indexOfVariant(u); + // we need to offset the variant index to allow for the different + // indexing schemes here (primary included) and in the cache (primary + // is not counted) + _variant = (vindex >= 0) ? vindex + 1 : 0; } else if (u.scheme() == "package") { auto ident = u.path().toStdString(); try { @@ -327,6 +328,14 @@ void QmlAircraftInfo::setUri(QUrl u) void QmlAircraftInfo::setVariant(int variant) { + if (!_item && !_package) + return; + + if ((variant < 0) || (variant >= numVariants())) { + qWarning() << Q_FUNC_INFO << uri() << "variant index out of range:" << variant; + return; + } + if (_variant == variant) return; @@ -409,6 +418,7 @@ QStringList QmlAircraftInfo::variantNames() const { QStringList result; if (_item) { + result.append(_item->description); Q_FOREACH(auto v, _item->variants) { if (v->description.isEmpty()) { qWarning() << Q_FUNC_INFO << "missing description for " << v->path; @@ -425,3 +435,8 @@ QStringList QmlAircraftInfo::variantNames() const } return result; } + +bool QmlAircraftInfo::isPackaged() const +{ + return _package != PackageRef(); +} diff --git a/src/GUI/QmlAircraftInfo.hxx b/src/GUI/QmlAircraftInfo.hxx index 9bbd04532..aca4712c4 100644 --- a/src/GUI/QmlAircraftInfo.hxx +++ b/src/GUI/QmlAircraftInfo.hxx @@ -52,6 +52,7 @@ class QmlAircraftInfo : public QObject Q_PROPERTY(QStringList variantNames READ variantNames NOTIFY infoChanged) + Q_PROPERTY(bool isPackaged READ isPackaged NOTIFY infoChanged) public: explicit QmlAircraftInfo(QObject *parent = nullptr); @@ -92,6 +93,8 @@ public: void setDownloadBytes(int bytes); QStringList variantNames() const; + + bool isPackaged() const; signals: void uriChanged(); void infoChanged();