Restore active aircraft variant also.
This commit is contained in:
parent
4db129cb01
commit
780e0f5a02
3 changed files with 67 additions and 2 deletions
|
@ -879,6 +879,60 @@ QModelIndex AircraftItemModel::indexOfAircraftURI(QUrl uri) const
|
|||
return QModelIndex();
|
||||
}
|
||||
|
||||
void AircraftItemModel::selectVariantForAircraftURI(QUrl uri)
|
||||
{
|
||||
if (uri.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int variantIndex = 0;
|
||||
QModelIndex modelIndex;
|
||||
|
||||
if (uri.isLocalFile()) {
|
||||
QString path = uri.toLocalFile();
|
||||
for (int row=0; row <m_items.size(); ++row) {
|
||||
const AircraftItemPtr item(m_items.at(row));
|
||||
if (item->path == path) {
|
||||
modelIndex = index(row);
|
||||
variantIndex = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
// check variants too
|
||||
for (int vr=0; vr < item->variants.size(); ++vr) {
|
||||
if (item->variants.at(vr)->path == path) {
|
||||
modelIndex = index(row);
|
||||
variantIndex = vr + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (uri.scheme() == "package") {
|
||||
QString ident = uri.path();
|
||||
int rowOffset = m_items.size();
|
||||
|
||||
PackageRef pkg = m_packageRoot->getPackageById(ident.toStdString());
|
||||
if (pkg) {
|
||||
for (size_t i=0; i < m_packages.size(); ++i) {
|
||||
if (m_packages[i] == pkg) {
|
||||
modelIndex = index(rowOffset + i);
|
||||
variantIndex = pkg->indexOfVariant(ident.toStdString());
|
||||
break;
|
||||
}
|
||||
} // of linear package scan
|
||||
}
|
||||
} else {
|
||||
qWarning() << "Unknown aircraft URI scheme" << uri << uri.scheme();
|
||||
return;
|
||||
}
|
||||
|
||||
if (modelIndex.isValid()) {
|
||||
qDebug() << "selected variant index" << variantIndex << "at" << modelIndex
|
||||
<< "for variant" << uri;
|
||||
setData(modelIndex, variantIndex, AircraftVariantRole);
|
||||
}
|
||||
}
|
||||
|
||||
void AircraftItemModel::onScanResults()
|
||||
{
|
||||
QVector<AircraftItemPtr> newItems = m_scanThread->items();
|
||||
|
|
|
@ -127,7 +127,13 @@ public:
|
|||
*/
|
||||
|
||||
QModelIndex indexOfAircraftURI(QUrl uri) const;
|
||||
|
||||
|
||||
/**
|
||||
* ensure the appropriate variant index is active in the model, for the
|
||||
* corresponding aircraft URI
|
||||
*/
|
||||
void selectVariantForAircraftURI(QUrl uri);
|
||||
|
||||
/**
|
||||
* return if a given aircraft is ready to be run, or not. Aircraft which
|
||||
* are not installed, or are downloading, are not runnable.
|
||||
|
|
|
@ -869,6 +869,9 @@ void QtLauncher::maybeRestoreAircraftSelection()
|
|||
m_ui->aircraftList->selectionModel()->select(proxyIndex,
|
||||
QItemSelectionModel::ClearAndSelect);
|
||||
m_ui->aircraftList->scrollTo(proxyIndex);
|
||||
|
||||
// and also select the correct variant on the model
|
||||
m_aircraftModel->selectVariantForAircraftURI(m_selectedAircraft);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1340,11 +1343,13 @@ void QtLauncher::onPopupAircraftHistory()
|
|||
QPoint popupPos = m_ui->aircraftHistory->mapToGlobal(m_ui->aircraftHistory->rect().bottomLeft());
|
||||
QAction* triggered = m.exec(popupPos);
|
||||
if (triggered) {
|
||||
m_selectedAircraft = triggered->data().toUrl();
|
||||
const QUrl uri = triggered->data().toUrl();
|
||||
m_selectedAircraft = uri;
|
||||
QModelIndex index = proxyIndexForAircraftURI(m_selectedAircraft);
|
||||
m_ui->aircraftList->selectionModel()->setCurrentIndex(index,
|
||||
QItemSelectionModel::ClearAndSelect);
|
||||
m_ui->aircraftFilter->clear();
|
||||
m_aircraftModel->selectVariantForAircraftURI(uri);
|
||||
updateSelectedAircraft();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue