From 359f924ec9e96aa6446a00925bddab1b32cc4f95 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 3 Jan 2016 20:58:03 -0600 Subject: [PATCH] Package variants working. --- src/GUI/AircraftModel.cxx | 24 ++++++++++++++++++++---- src/GUI/QtLauncher.cxx | 7 +++---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/GUI/AircraftModel.cxx b/src/GUI/AircraftModel.cxx index ffcd95a38..0ca5f1ebc 100644 --- a/src/GUI/AircraftModel.cxx +++ b/src/GUI/AircraftModel.cxx @@ -613,15 +613,20 @@ QVariant AircraftItemModel::dataFromPackage(const PackageRef& item, quint32 vari role = AircraftThumbnailRole; // use first thumbnail } + if ((role >= AircraftVariantDescriptionRole) && (role < AircraftThumbnailRole)) { + int variantIndex = role - AircraftVariantDescriptionRole; + return QString::fromStdString(item->nameForVariant(variantIndex)); + } + if (role == Qt::DisplayRole) { - return QString::fromStdString(item->name()); + return QString::fromStdString(item->nameForVariant(variantIndex)); } else if (role == AircraftPathRole) { InstallRef i = item->existingInstall(); if (i.valid()) { return QString::fromStdString(i->primarySetPath().str()); } } else if (role == AircraftPackageIdRole) { - return QString::fromStdString(item->id()); + return QString::fromStdString(item->variants()[variantIndex]); } else if (role == AircraftPackageStatusRole) { InstallRef i = item->existingInstall(); if (i.valid()) { @@ -639,6 +644,10 @@ QVariant AircraftItemModel::dataFromPackage(const PackageRef& item, quint32 vari } else { return PackageNotInstalled; } + } else if (role == AircraftVariantCountRole) { + // this value wants the number of aditional variants, i.e not + // including the primary. Hence the -1 term. + return static_cast(item->variants().size() - 1); } else if (role == AircraftThumbnailSizeRole) { QPixmap pm = packageThumbnail(item, 0, false).value(); if (pm.isNull()) @@ -656,7 +665,7 @@ QVariant AircraftItemModel::dataFromPackage(const PackageRef& item, quint32 vari } else if (role == AircraftPackageSizeRole) { return static_cast(item->fileSizeBytes()); } else if (role == AircraftURIRole) { - return QUrl("package:" + QString::fromStdString(item->qualifiedId())); + return QUrl("package:" + QString::fromStdString(item->qualifiedVariantId(variantIndex))); } else if (role == AircraftHasRatingsRole) { return item->properties()->hasChild("rating"); } else if ((role >= AircraftRatingRole) && (role < AircraftVariantDescriptionRole)) { @@ -714,8 +723,15 @@ QVariant AircraftItemModel::packageThumbnail(PackageRef p, int index, bool downl bool AircraftItemModel::setData(const QModelIndex &index, const QVariant &value, int role) { + int row = index.row(); if (role == AircraftVariantRole) { - m_activeVariant[index.row()] = value.toInt(); + if (row >= m_activeVariant.size()) { + row -= m_activeVariant.size(); + m_packageVariant[row] = value.toInt(); + } else { + m_activeVariant[row] = value.toInt(); + } + emit dataChanged(index, index); return true; } diff --git a/src/GUI/QtLauncher.cxx b/src/GUI/QtLauncher.cxx index 713f51749..53bae459e 100644 --- a/src/GUI/QtLauncher.cxx +++ b/src/GUI/QtLauncher.cxx @@ -656,10 +656,10 @@ void QtLauncher::onRun() setFile.truncate(setFile.count() - 8); // drop the '-set.xml' portion opt->addOption("aircraft", setFile.toStdString()); } else if (m_selectedAircraft.scheme() == "package") { - PackageRef pkg = packageForAircraftURI(m_selectedAircraft); + QString qualifiedId = m_selectedAircraft.path(); // no need to set aircraft-dir, handled by the corresponding code // in fgInitAircraft - opt->addOption("aircraft", pkg->qualifiedId()); + opt->addOption("aircraft", qualifiedId.toStdString()); } else { qWarning() << "unsupported aircraft launch URL" << m_selectedAircraft; } @@ -748,10 +748,9 @@ void QtLauncher::onApply() aircraftDir = setFileInfo.dir().absolutePath().toStdString(); aircraftPropValue = setFile.toStdString(); } else if (m_selectedAircraft.scheme() == "package") { - PackageRef pkg = packageForAircraftURI(m_selectedAircraft); // no need to set aircraft-dir, handled by the corresponding code // in fgInitAircraft - aircraftPropValue = pkg->qualifiedId(); + aircraftPropValue = m_selectedAircraft.path().toStdString(); } else { qWarning() << "unsupported aircraft launch URL" << m_selectedAircraft; } -- 2.39.5