Launcher: fix favourites behaviour with variants
Fixes ticket: https://sourceforge.net/p/flightgear/codetickets/2380/ Also add a UI prompt when no favourites are selected.
This commit is contained in:
parent
59e87d0570
commit
b727806bee
3 changed files with 29 additions and 3 deletions
|
@ -248,7 +248,7 @@ QVariant AircraftItemModel::data(const QModelIndex& index, int role) const
|
|||
|
||||
if (role == AircraftIsFavouriteRole) {
|
||||
// recursive call here, hope that's okay
|
||||
const auto uri = data(index, AircraftURIRole).toUrl();
|
||||
const auto uri = data(index, AircraftPrimaryURIRole).toUrl();
|
||||
return FavouriteAircraftData::instance()->isFavourite(uri);
|
||||
}
|
||||
|
||||
|
@ -288,6 +288,10 @@ QVariant AircraftItemModel::dataFromItem(AircraftItemPtr item, const DelegateSta
|
|||
return item->variants.at(variantIndex)->name();
|
||||
}
|
||||
|
||||
if (role == AircraftPrimaryURIRole) {
|
||||
return QUrl::fromLocalFile(item->path);
|
||||
}
|
||||
|
||||
if (state.variant) {
|
||||
if (state.variant <= static_cast<quint32>(item->variants.count())) {
|
||||
// show the selected variant
|
||||
|
@ -401,6 +405,8 @@ QVariant AircraftItemModel::dataFromPackage(const PackageRef& item, const Delega
|
|||
return static_cast<int>(item->fileSizeBytes());
|
||||
} else if (role == AircraftURIRole) {
|
||||
return QUrl("package:" + QString::fromStdString(item->qualifiedVariantId(state.variant)));
|
||||
} else if (role == AircraftPrimaryURIRole) {
|
||||
return QUrl("package:" + QString::fromStdString(item->qualifiedId()));
|
||||
} else if (role == AircraftHasRatingsRole) {
|
||||
return item->properties()->hasChild("rating");
|
||||
} else if ((role >= AircraftRatingRole) && (role < AircraftVariantDescriptionRole)) {
|
||||
|
@ -440,7 +446,7 @@ bool AircraftItemModel::setData(const QModelIndex &index, const QVariant &value,
|
|||
emit dataChanged(index, index);
|
||||
return true;
|
||||
} else if (role == AircraftIsFavouriteRole) {
|
||||
const auto uri = data(index, AircraftURIRole).toUrl();
|
||||
const auto uri = data(index, AircraftPrimaryURIRole).toUrl();
|
||||
bool changed = FavouriteAircraftData::instance()->setFavourite(uri, value.toBool());
|
||||
if (changed) {
|
||||
emit dataChanged(index, index);
|
||||
|
|
|
@ -51,6 +51,7 @@ const int AircraftIsHelicopterRole = Qt::UserRole + 16;
|
|||
const int AircraftIsSeaplaneRole = Qt::UserRole + 17;
|
||||
const int AircraftPackageRefRole = Qt::UserRole + 19;
|
||||
const int AircraftIsFavouriteRole = Qt::UserRole + 20;
|
||||
const int AircraftPrimaryURIRole = Qt::UserRole + 21;
|
||||
|
||||
const int AircraftStatusRole = Qt::UserRole + 22;
|
||||
const int AircraftMinVersionRole = Qt::UserRole + 23;
|
||||
|
|
|
@ -162,6 +162,25 @@ FocusScope
|
|||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: noFavouritesHeader
|
||||
Rectangle {
|
||||
visible: _launcher.favouriteAircraftModel.count === 0
|
||||
width: aircraftContent.width
|
||||
height: Style.strutSize
|
||||
|
||||
StyledText {
|
||||
anchors.fill: parent
|
||||
text: qsTr("No favourite aircraft selected: install some aircraft and mark them as favourites by clicking the \u2605")
|
||||
wrapMode: Text.WordWrap
|
||||
font.pixelSize: Style.headingFontPixelSize
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Component {
|
||||
id: emptyHeaderFooter
|
||||
Item {
|
||||
|
@ -302,7 +321,7 @@ FocusScope
|
|||
PropertyChanges {
|
||||
target: root
|
||||
__model: _launcher.favouriteAircraftModel
|
||||
__header: emptyHeaderFooter
|
||||
__header: noFavouritesHeader
|
||||
__footer: emptyHeaderFooter
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue