mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 16:56:53 +08:00
refs #535, updated aircraft model / view
* add functions to apply changes to selected objects * allow to highlight models by their model strings * Utility function to show which parts come from DB * model strings can be obtained sorted/unsorted
This commit is contained in:
@@ -302,7 +302,7 @@ namespace BlackGui
|
||||
this->ui->tvp_AircraftModels->updateContainer(ml);
|
||||
|
||||
// model completer
|
||||
this->m_modelCompleter->setModel(new QStringListModel(ml.getSortedModelStrings(), this->m_modelCompleter));
|
||||
this->m_modelCompleter->setModel(new QStringListModel(ml.getModelStrings(), this->m_modelCompleter));
|
||||
this->m_modelCompleter->setModelSorting(QCompleter::CaseInsensitivelySortedModel);
|
||||
this->m_modelCompleter->setCaseSensitivity(Qt::CaseInsensitive);
|
||||
this->m_modelCompleter->setWrapAround(true);
|
||||
|
||||
@@ -42,20 +42,25 @@ namespace BlackGui
|
||||
case OwnSimulatorModel:
|
||||
case StashModel:
|
||||
this->m_columns.addColumn(CColumn::standardString("model", { CAircraftModel::IndexModelString}));
|
||||
this->m_columns.addColumn(CColumn::standardString("DB", "parts from DB", { CAircraftModel::IndexPartsDbStatus}));
|
||||
this->m_columns.addColumn(CColumn::standardString("description", { CAircraftModel::IndexDescription}));
|
||||
this->m_columns.addColumn(CColumn::standardString("name", { CAircraftModel::IndexName}));
|
||||
this->m_columns.addColumn(CColumn::standardString("filename", { CAircraftModel::IndexFileName}));
|
||||
this->m_columns.addColumn(CColumn::standardString("sim.", "simulator supported", CAircraftModel::IndexSimulatorInfoAsString));
|
||||
|
||||
this->m_columns.addColumn(CColumn::standardString("dist.", "distributor", { CAircraftModel::IndexDistributor, CDistributor::IndexDbStringKey}));
|
||||
|
||||
this->m_columns.addColumn(CColumn::standardString("aircraft", { CAircraftModel::IndexAircraftIcaoCode, CAircraftIcaoCode::IndexDesignatorManufacturer}));
|
||||
this->m_columns.addColumn(CColumn::standardString("livery", { CAircraftModel::IndexLivery, CLivery::IndexCombinedCode}));
|
||||
this->m_columns.addColumn(CColumn::standardString("airline", { CAircraftModel::IndexLivery, CLivery::IndexAirlineIcaoCode, CAirlineIcaoCode::IndexDesignatorNameCountry}));
|
||||
|
||||
this->m_columns.addColumn(CColumn::standardString("name", { CAircraftModel::IndexName}));
|
||||
this->m_columns.addColumn(CColumn::standardString("filename", { CAircraftModel::IndexFileName}));
|
||||
|
||||
// default sort order
|
||||
this->setSortColumnByPropertyIndex(CAircraftModel::IndexModelString);
|
||||
this->m_sortOrder = Qt::AscendingOrder;
|
||||
break;
|
||||
|
||||
case MappedModel:
|
||||
case OwnSimulatorModelMapping:
|
||||
this->m_columns.addColumn(CColumn::standardValueObject("call", "callsign", CAircraftModel::IndexCallsign));
|
||||
this->m_columns.addColumn(CColumn::standardString("model", CAircraftModel::IndexModelString));
|
||||
this->m_columns.addColumn(CColumn::standardString("ac", "aircraft ICAO", { CAircraftModel::IndexAircraftIcaoCode, CAircraftIcaoCode::IndexAircraftDesignator}));
|
||||
@@ -120,19 +125,50 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
QStringList CAircraftModelListModel::getModelStrings(bool sort) const
|
||||
{
|
||||
if (this->isEmpty()) { return QStringList(); }
|
||||
return this->container().getModelStrings(sort);
|
||||
}
|
||||
|
||||
void CAircraftModelListModel::replaceOrAddByModelString(const CAircraftModelList &models)
|
||||
{
|
||||
if (models.isEmpty()) { return; }
|
||||
CAircraftModelList currentModels(container());
|
||||
currentModels.removeModelsWithString(models.getModelStrings(true), Qt::CaseInsensitive);
|
||||
currentModels.push_back(models);
|
||||
this->updateContainerMaybeAsync(currentModels);
|
||||
}
|
||||
|
||||
QVariant CAircraftModelListModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!m_highlightDbData || role != Qt::BackgroundRole) { return CListModelBase::data(index, role); }
|
||||
if (role != Qt::BackgroundRole) { return CListModelBase::data(index, role); }
|
||||
bool db = highlightDbData();
|
||||
bool ms = highlightGivenModelStrings() && !m_highlightStrings.isEmpty();
|
||||
if (!db && !ms) { return CListModelBase::data(index, role); }
|
||||
|
||||
CAircraftModel model(this->at(index));
|
||||
if (model.hasValidDbKey())
|
||||
{
|
||||
static const QBrush b(Qt::green);
|
||||
return b;
|
||||
}
|
||||
else
|
||||
// highlight stashed first
|
||||
if (ms)
|
||||
{
|
||||
if (m_highlightStrings.contains(model.getModelString(), Qt::CaseInsensitive))
|
||||
{
|
||||
static const QBrush b(Qt::yellow);
|
||||
return b;
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
// highlight DB models
|
||||
if (db)
|
||||
{
|
||||
if (model.hasValidDbKey())
|
||||
{
|
||||
static const QBrush b(Qt::green);
|
||||
return b;
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -13,8 +13,9 @@
|
||||
#define BLACKGUI_AIRCRAFTMODELLISTMODEL_H
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackmisc/simulation/aircraftmodellist.h"
|
||||
#include "blackgui/models/modelswithdbkey.h"
|
||||
#include "blackmisc/simulation/aircraftmodellist.h"
|
||||
#include <QStringList>
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
namespace BlackGui
|
||||
@@ -33,7 +34,6 @@ namespace BlackGui
|
||||
NotSet,
|
||||
OwnSimulatorModel, ///< models existing for my simulator
|
||||
OwnSimulatorModelMapping, ///< models of my simulator, but in mapping mode
|
||||
MappedModel, ///< model based on mapping operation
|
||||
Database, ///< Database entry
|
||||
VPilotRuleModel, ///< vPilot rule turned into model
|
||||
StashModel ///< stashed models
|
||||
@@ -57,20 +57,30 @@ namespace BlackGui
|
||||
//! Highlight the DB models
|
||||
void setHighlightDbData(bool highlightDbData) { m_highlightDbData = highlightDbData; }
|
||||
|
||||
//! Highlight stashed models
|
||||
bool highlightStashedModels() const { return m_highlightStashedData; }
|
||||
//! Highlight models
|
||||
bool highlightGivenModelStrings() const { return m_highlightModelStrings; }
|
||||
|
||||
//! Highlight stashed models
|
||||
void setHighlightStashedModels(bool highlightStashedModels) { m_highlightStashedData = highlightStashedModels; }
|
||||
//! Highlight models
|
||||
void setHighlightModelsStrings(const QStringList &modelStrings = QStringList()) { m_highlightStrings = modelStrings; }
|
||||
|
||||
//! Highlight models
|
||||
void setHighlightModelsStrings(bool highlightModelStrings) { m_highlightModelStrings = highlightModelStrings; }
|
||||
|
||||
//! Model strings
|
||||
QStringList getModelStrings(bool sort) const;
|
||||
|
||||
//! Replace models with same model string, or just add
|
||||
void replaceOrAddByModelString(const BlackMisc::Simulation::CAircraftModelList &models);
|
||||
|
||||
protected:
|
||||
//! \copydoc QAbstractItemModel::data
|
||||
virtual QVariant data(const QModelIndex &index, int role) const override;
|
||||
|
||||
private:
|
||||
AircraftModelMode m_mode = NotSet; //!< current mode
|
||||
bool m_highlightDbData = false;
|
||||
bool m_highlightStashedData = false;
|
||||
AircraftModelMode m_mode = NotSet; //!< current mode
|
||||
bool m_highlightDbData = false; //!< highlight if DB data entry (valid key)
|
||||
bool m_highlightModelStrings = false; //!< highlight in in model strings
|
||||
QStringList m_highlightStrings; //!< model strings to highlight
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Simulation;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackGui::Models;
|
||||
using namespace BlackGui::Filters;
|
||||
|
||||
@@ -56,7 +57,7 @@ namespace BlackGui
|
||||
break;
|
||||
case CAircraftModelListModel::VPilotRuleModel:
|
||||
this->m_withMenuItemClear = false;
|
||||
this->m_withMenuItemRefresh = false;
|
||||
this->m_withMenuItemRefresh = true;
|
||||
this->m_withMenuItemBackend = false;
|
||||
this->setCustomMenu(new CHighlightDbModelsMenu(this, true));
|
||||
this->setCustomMenu(new CHighlightStashedModelsMenu(this, true));
|
||||
@@ -80,6 +81,25 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
void CAircraftModelView::applyToSelected(const CLivery &livery)
|
||||
{
|
||||
if (!hasSelection()) { return; }
|
||||
int c = this->updateSelected(CVariant::from(livery), CAircraftModel::IndexLivery);
|
||||
// this->updateContainer(models);
|
||||
}
|
||||
|
||||
void CAircraftModelView::applyToSelected(const CAircraftIcaoCode &icao)
|
||||
{
|
||||
if (!hasSelection()) { return; }
|
||||
int c = this->updateSelected(CVariant::from(icao), CAircraftModel::IndexAircraftIcaoCode);
|
||||
}
|
||||
|
||||
void CAircraftModelView::applyToSelected(const CDistributor &distributor)
|
||||
{
|
||||
if (!hasSelection()) { return; }
|
||||
int c = this->updateSelected(CVariant::from(distributor), CAircraftModel::IndexDistributor);
|
||||
}
|
||||
|
||||
void CAircraftModelView::ps_toggleHighlightDbModels()
|
||||
{
|
||||
bool h = derivedModel()->highlightDbData();
|
||||
@@ -88,8 +108,8 @@ namespace BlackGui
|
||||
|
||||
void CAircraftModelView::ps_toggleHighlightStashedModels()
|
||||
{
|
||||
bool h = derivedModel()->highlightStashedModels();
|
||||
derivedModel()->setHighlightStashedModels(!h);
|
||||
bool h = derivedModel()->highlightGivenModelStrings();
|
||||
derivedModel()->setHighlightModelsStrings(!h);
|
||||
}
|
||||
|
||||
void CAircraftModelView::CHighlightDbModelsMenu::customMenu(QMenu &menu) const
|
||||
@@ -108,7 +128,7 @@ namespace BlackGui
|
||||
Q_ASSERT_X(mv, Q_FUNC_INFO, "no view");
|
||||
QAction *a = menu.addAction(CIcons::appDbStash16(), "Highlight stashed models", mv, SLOT(ps_toggleHighlightStashedModels()));
|
||||
a->setCheckable(true);
|
||||
a->setChecked(mv->derivedModel()->highlightStashedModels());
|
||||
a->setChecked(mv->derivedModel()->highlightGivenModelStrings());
|
||||
this->nestedCustomMenu(menu);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,15 @@ namespace BlackGui
|
||||
//! Set display mode
|
||||
void setAircraftModelMode(Models::CAircraftModelListModel::AircraftModelMode mode);
|
||||
|
||||
//! Apply to selected objects
|
||||
void applyToSelected(const BlackMisc::Aviation::CLivery &livery);
|
||||
|
||||
//! Apply to selected objects
|
||||
void applyToSelected(const BlackMisc::Aviation::CAircraftIcaoCode &icao);
|
||||
|
||||
//! Apply to selected objects
|
||||
void applyToSelected(const BlackMisc::Simulation::CDistributor &distributor);
|
||||
|
||||
signals:
|
||||
//! Request to load VPilot data
|
||||
void requestVPilotRules();
|
||||
|
||||
@@ -132,7 +132,7 @@ namespace BlackMisc
|
||||
|
||||
int CAircraftMatcher::synchronize()
|
||||
{
|
||||
return synchronizeWithExistingModels(m_installedModels.getSortedModelStrings());
|
||||
return synchronizeWithExistingModels(m_installedModels.getModelStrings());
|
||||
}
|
||||
|
||||
void CAircraftMatcher::cancelInit()
|
||||
|
||||
@@ -92,6 +92,8 @@ namespace BlackMisc
|
||||
return m_livery.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexCallsign:
|
||||
return m_callsign.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexPartsDbStatus:
|
||||
return getPartsDbStatus();
|
||||
default:
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
@@ -179,6 +181,8 @@ namespace BlackMisc
|
||||
return Compare::compare(this->m_modelType, compareValue.getModelType());
|
||||
case IndexModelMode:
|
||||
return Compare::compare(this->m_modelMode, compareValue.getModelMode());
|
||||
case IndexPartsDbStatus:
|
||||
return getPartsDbStatus().compare(compareValue.getPartsDbStatus());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -255,6 +259,16 @@ namespace BlackMisc
|
||||
return m_simulator.isAnySimulator();
|
||||
}
|
||||
|
||||
QString CAircraftModel::getPartsDbStatus() const
|
||||
{
|
||||
QString s(hasValidDbKey() ? "M" : "m");
|
||||
s = s.append(getDistributor().hasValidDbKey() ? 'D' : 'd');
|
||||
s = s.append(getAircraftIcaoCode().hasValidDbKey() ? 'A' : 'a');
|
||||
s = s.append(getLivery().hasValidDbKey() ? 'L' : 'l');
|
||||
s = s.append(getLivery().getAirlineIcaoCode().hasValidDbKey() ? 'A' : 'a');
|
||||
return s;
|
||||
}
|
||||
|
||||
bool CAircraftModel::matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const
|
||||
{
|
||||
if (sensitivity == Qt::CaseSensitive)
|
||||
|
||||
@@ -70,7 +70,8 @@ namespace BlackMisc
|
||||
IndexModelTypeAsString,
|
||||
IndexModelMode,
|
||||
IndexModelModeAsString,
|
||||
IndexHasQueriedModelString
|
||||
IndexHasQueriedModelString,
|
||||
IndexPartsDbStatus
|
||||
};
|
||||
|
||||
//! \copydoc BlackMisc::CValueObject::registerMetadata
|
||||
@@ -199,7 +200,7 @@ namespace BlackMisc
|
||||
//! Set simulator info
|
||||
void setSimulatorInfo(const CSimulatorInfo &simulator) { this->m_simulator = simulator; }
|
||||
|
||||
//! File name (corresponding data for simulator, only available if representing simulator model=
|
||||
//! File name (corresponding data for simulator, only available if representing simulator model
|
||||
QString getFileName() const { return m_fileName; }
|
||||
|
||||
//! File name?
|
||||
@@ -226,6 +227,9 @@ namespace BlackMisc
|
||||
//! Valid simulator
|
||||
bool hasValidSimulator() const;
|
||||
|
||||
//! Info, which parts/subparts (Livery, Aircraft ICAO, ...) are already based on DB data
|
||||
QString getPartsDbStatus() const;
|
||||
|
||||
//! Matches model string?
|
||||
bool matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const;
|
||||
|
||||
|
||||
@@ -138,16 +138,40 @@ namespace BlackMisc
|
||||
});
|
||||
}
|
||||
|
||||
QStringList CAircraftModelList::getSortedModelStrings() const
|
||||
QStringList CAircraftModelList::getModelStrings(bool sort) const
|
||||
{
|
||||
QStringList ms;
|
||||
for (const CAircraftModel &model : (*this))
|
||||
{
|
||||
ms.append(model.getModelString());
|
||||
}
|
||||
ms.sort(Qt::CaseInsensitive);
|
||||
if (sort) { ms.sort(Qt::CaseInsensitive); }
|
||||
return ms;
|
||||
}
|
||||
|
||||
void CAircraftModelList::updateDistributor(const CDistributor &distributor)
|
||||
{
|
||||
for (CAircraftModel &model : *this)
|
||||
{
|
||||
model.setDistributor(distributor);
|
||||
}
|
||||
}
|
||||
|
||||
void CAircraftModelList::updateAircraftIcao(const CAircraftIcaoCode &icao)
|
||||
{
|
||||
for (CAircraftModel &model : *this)
|
||||
{
|
||||
model.setAircraftIcaoCode(icao);
|
||||
}
|
||||
}
|
||||
|
||||
void CAircraftModelList::updateLivery(const CLivery &livery)
|
||||
{
|
||||
for (CAircraftModel &model : *this)
|
||||
{
|
||||
model.setLivery(livery);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -76,7 +76,16 @@ namespace BlackMisc
|
||||
int removeModelsWithString(const QStringList &modelStrings, Qt::CaseSensitivity sensitivity);
|
||||
|
||||
//! Model strings
|
||||
QStringList getSortedModelStrings() const;
|
||||
QStringList getModelStrings(bool sort = true) const;
|
||||
|
||||
//! Update distributors
|
||||
void updateDistributor(const CDistributor &distributor);
|
||||
|
||||
//! Update aircraft ICAO
|
||||
void updateAircraftIcao(const BlackMisc::Aviation::CAircraftIcaoCode &icao);
|
||||
|
||||
//! Update livery
|
||||
void updateLivery(const BlackMisc::Aviation::CLivery &livery);
|
||||
};
|
||||
|
||||
} //namespace
|
||||
|
||||
Reference in New Issue
Block a user