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:
Klaus Basan
2015-12-13 19:40:04 +01:00
parent ecb4694c7f
commit 1601ca62fd
10 changed files with 156 additions and 30 deletions

View File

@@ -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

View File

@@ -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