]> git.mxchange.org Git - flightgear.git/commitdiff
Package variants working.
authorJames Turner <zakalawe@mac.com>
Mon, 4 Jan 2016 02:58:03 +0000 (20:58 -0600)
committerJames Turner <zakalawe@mac.com>
Mon, 4 Jan 2016 02:58:03 +0000 (20:58 -0600)
src/GUI/AircraftModel.cxx
src/GUI/QtLauncher.cxx

index ffcd95a38a3dbb51464013c37546cfa1a924b436..0ca5f1ebcfdc10953d9a4a9dc9176c9f98e68cef 100644 (file)
@@ -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<quint32>(item->variants().size() - 1);
     } else if (role == AircraftThumbnailSizeRole) {
         QPixmap pm = packageThumbnail(item, 0, false).value<QPixmap>();
         if (pm.isNull())
@@ -656,7 +665,7 @@ QVariant AircraftItemModel::dataFromPackage(const PackageRef& item, quint32 vari
     } else if (role == AircraftPackageSizeRole) {
         return static_cast<int>(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;
       }
index 713f51749eb8420b15fc387b9c698cba90a519a1..53bae459e1d7c57e15e510a2aeb7b7b555c63ed6 100644 (file)
@@ -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;
         }