From 8f9afcd7966e2b49c2e4c8c57e8a0bf093b96033 Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 2 Jul 2018 14:11:01 +0100 Subject: [PATCH] Fix jumping aircraft when selecting variants Always sort on the primary aircraft name, otherwise select a variant triggers a re-sort of the list which is confusing for the user. --- src/GUI/AircraftModel.cxx | 7 ++++++- src/GUI/AircraftSearchFilterModel.cxx | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/GUI/AircraftModel.cxx b/src/GUI/AircraftModel.cxx index beeb26d9c..54ca58ea8 100644 --- a/src/GUI/AircraftModel.cxx +++ b/src/GUI/AircraftModel.cxx @@ -289,6 +289,11 @@ QVariant AircraftItemModel::dataFromItem(AircraftItemPtr item, const DelegateSta if (role >= AircraftVariantDescriptionRole) { int variantIndex = role - AircraftVariantDescriptionRole; + if (variantIndex == 0) { + return item->description; + } + + Q_ASSERT(variantIndex < item->variants.size()); return item->variants.at(variantIndex)->description; } @@ -471,7 +476,7 @@ QVariant AircraftItemModel::packageThumbnail(PackageRef p, const DelegateState& bool AircraftItemModel::setData(const QModelIndex &index, const QVariant &value, int role) { int row = index.row(); - int newValue = value.toInt(); + quint32 newValue = value.toUInt(); if (role == AircraftVariantRole) { if (m_delegateStates[row].variant == newValue) { diff --git a/src/GUI/AircraftSearchFilterModel.cxx b/src/GUI/AircraftSearchFilterModel.cxx index bd26107c0..a906f5cd0 100644 --- a/src/GUI/AircraftSearchFilterModel.cxx +++ b/src/GUI/AircraftSearchFilterModel.cxx @@ -10,7 +10,11 @@ AircraftProxyModel::AircraftProxyModel(QObject *pr, QAbstractItemModel * source) setSourceModel(source); setSortCaseSensitivity(Qt::CaseInsensitive); setFilterCaseSensitivity(Qt::CaseInsensitive); - setSortRole(Qt::DisplayRole); + + // important we sort on the primary name role and not Qt::DisplayRole + // otherwise the aircraft jump when switching variant + setSortRole(AircraftVariantDescriptionRole); + setDynamicSortFilter(true); // kick off initial sort