mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 05:26:45 +08:00
refs #314, new propertyBy methods (nested indexes)
This commit is contained in:
@@ -59,29 +59,60 @@ namespace BlackSim
|
||||
/*
|
||||
* Get particular column
|
||||
*/
|
||||
QVariant CAircraftCfgEntries::propertyByIndex(int index) const
|
||||
QVariant CAircraftCfgEntries::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||
{
|
||||
switch (index)
|
||||
if (index.isMyself()) { return this->toQVariant(); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexFilePath:
|
||||
return this->m_filePath;
|
||||
return QVariant(this->m_filePath);
|
||||
case IndexTitle:
|
||||
return this->m_title;
|
||||
return QVariant(this->m_title);
|
||||
case IndexAtcType:
|
||||
return this->m_atcType;
|
||||
return QVariant(this->m_atcType);
|
||||
case IndexAtcModel:
|
||||
return this->m_atcModel;
|
||||
return QVariant(this->m_atcModel);
|
||||
case IndexParkingCode:
|
||||
return this->m_atcParkingCode;
|
||||
return QVariant(this->m_atcParkingCode);
|
||||
case IndexEntryIndex:
|
||||
return this->m_index;
|
||||
return QVariant(this->m_index);
|
||||
default:
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Set property as index
|
||||
*/
|
||||
void CAircraftCfgEntries::setPropertyByIndex(const QVariant &variant, const BlackMisc::CPropertyIndex &index)
|
||||
{
|
||||
if (index.isMyself()) { this->fromQVariant(variant); return; }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexAtcModel:
|
||||
this->setAtcModel(variant.toString());
|
||||
break;
|
||||
case IndexAtcType:
|
||||
this->setAtcType(variant.toString());
|
||||
break;
|
||||
case IndexEntryIndex:
|
||||
this->setIndex(variant.toInt());
|
||||
break;
|
||||
case IndexFilePath:
|
||||
this->setFilePath(variant.toString());
|
||||
break;
|
||||
case IndexParkingCode:
|
||||
this->setAtcParkingCode(variant.toString());
|
||||
break;
|
||||
case IndexTitle:
|
||||
this->setTitle(variant.toString());
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(variant, index);
|
||||
break;
|
||||
}
|
||||
|
||||
Q_ASSERT_X(false, "CAircraftCfgEntries", "index unknown");
|
||||
QString m = QString("no property, index ").append(QString::number(index));
|
||||
return QVariant::fromValue(m);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -64,9 +64,6 @@ namespace BlackSim
|
||||
//! operator !=
|
||||
bool operator !=(const CAircraftCfgEntries &other) const;
|
||||
|
||||
//! \copydoc CValueObject::propertyByIndex
|
||||
QVariant propertyByIndex(int index) const;
|
||||
|
||||
//! Filepath
|
||||
QString getFilePath() const { return this->m_filePath; }
|
||||
|
||||
@@ -115,6 +112,12 @@ namespace BlackSim
|
||||
//! \copydoc CValueObject::fromJson
|
||||
virtual void fromJson(const QJsonObject &json) override;
|
||||
|
||||
//! \copydoc CValueObject::propertyByIndex
|
||||
virtual QVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const override;
|
||||
|
||||
//! \copydoc CValueObject::setPropertyByIndex
|
||||
virtual void setPropertyByIndex(const QVariant &variant, const BlackMisc::CPropertyIndex &index) override;
|
||||
|
||||
//! Register the metatypes
|
||||
static void registerMetadata();
|
||||
|
||||
|
||||
@@ -120,95 +120,86 @@ namespace BlackSim
|
||||
/*
|
||||
* Get column
|
||||
*/
|
||||
QVariant CAircraftMapping::propertyByIndex(int index) const
|
||||
QVariant CAircraftMapping::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||
{
|
||||
// non throwing implementation
|
||||
switch (index)
|
||||
if (index.isMyself()) { return this->toQVariant(); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexMappingId:
|
||||
return this->m_mappingId;
|
||||
return QVariant(this->m_mappingId);
|
||||
case IndexProposalId:
|
||||
return m_proposalId;
|
||||
return QVariant(m_proposalId);
|
||||
case IndexAircraftKey:
|
||||
return m_fsAircraftKey;
|
||||
return QVariant(m_fsAircraftKey);
|
||||
case IndexAircraftDesignator:
|
||||
return m_aircraftDesignator;
|
||||
return QVariant(m_aircraftDesignator);
|
||||
case IndexAirlineDesignator:
|
||||
return m_airlineDesignator;
|
||||
return QVariant(m_airlineDesignator);
|
||||
case IndexAircraftCombinedType:
|
||||
return m_aircraftCombinedType;
|
||||
return QVariant(m_aircraftCombinedType);
|
||||
case IndexWakeTurbulenceCategory:
|
||||
return m_wakeTurbulenceCategory;
|
||||
return QVariant(m_wakeTurbulenceCategory);
|
||||
case IndexAirlineColor:
|
||||
return this->m_aircraftColor;
|
||||
return QVariant(this->m_aircraftColor);
|
||||
case IndexLastChanged:
|
||||
return this->getLastChangedFormatted();
|
||||
return QVariant(this->getLastChangedFormatted());
|
||||
case IndexSimulatorInfo:
|
||||
return this->m_simulatorInfo.toQVariant();
|
||||
return this->m_simulatorInfo.propertyByIndex(index.copyFrontRemoved());
|
||||
default:
|
||||
break;
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
|
||||
Q_ASSERT_X(false, "CAircraftMapping", "index unknown");
|
||||
QString m = QString("no property, index ").append(QString::number(index));
|
||||
return QVariant::fromValue(m);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set column's value
|
||||
*/
|
||||
void CAircraftMapping::setPropertyByIndex(const QVariant &value, int index)
|
||||
void CAircraftMapping::setPropertyByIndex(const QVariant &variant, const BlackMisc::CPropertyIndex &index)
|
||||
{
|
||||
// non throwing implementation
|
||||
bool changed;
|
||||
|
||||
switch (index)
|
||||
if (index.isMyself())
|
||||
{
|
||||
this->setPropertyByIndex(variant, index);
|
||||
return;
|
||||
}
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexMappingId:
|
||||
{
|
||||
bool ok = false;
|
||||
qint32 id = value.toInt(&ok);
|
||||
qint32 id = variant.toInt(&ok);
|
||||
this->m_mappingId = ok ? id : CAircraftMapping::InvalidId;
|
||||
}
|
||||
changed = true;
|
||||
break;
|
||||
case IndexProposalId:
|
||||
{
|
||||
bool ok = false;
|
||||
qint32 id = value.toInt(&ok);
|
||||
qint32 id = variant.toInt(&ok);
|
||||
this->m_proposalId = ok ? id : CAircraftMapping::InvalidId;
|
||||
}
|
||||
changed = true;
|
||||
break;
|
||||
case IndexAircraftKey:
|
||||
m_fsAircraftKey = value.toString();
|
||||
changed = true;
|
||||
m_fsAircraftKey = variant.toString();
|
||||
break;
|
||||
case IndexAircraftDesignator:
|
||||
this->setAircraftDesignator(value.toString());
|
||||
changed = true;
|
||||
this->setAircraftDesignator(variant.toString());
|
||||
break;
|
||||
case IndexAirlineDesignator:
|
||||
this->setAirlineDesignator(value.toString());
|
||||
changed = true;
|
||||
this->setAirlineDesignator(variant.toString());
|
||||
break;
|
||||
case IndexAircraftCombinedType:
|
||||
this->setAircraftCombinedType(value.toString());
|
||||
changed = true;
|
||||
this->setAircraftCombinedType(variant.toString());
|
||||
break;
|
||||
case IndexWakeTurbulenceCategory:
|
||||
this->setWakeTurbulenceCategory(value.toString());
|
||||
changed = true;
|
||||
this->setWakeTurbulenceCategory(variant.toString());
|
||||
break;
|
||||
case IndexAirlineColor:
|
||||
this->m_aircraftColor = value.toString();
|
||||
changed = true;
|
||||
this->m_aircraftColor = variant.toString();
|
||||
break;
|
||||
default:
|
||||
changed = false;
|
||||
CValueObject::setPropertyByIndex(variant, index);
|
||||
break;
|
||||
}
|
||||
if (changed) this->setChanged(changed);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace BlackSim
|
||||
//! Columns
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexMappingId = 0,
|
||||
IndexMappingId = BlackMisc::CPropertyIndex::GlobalIndexCAircraftMapping,
|
||||
IndexProposalId,
|
||||
IndexAircraftKey,
|
||||
IndexAircraftDesignator,
|
||||
@@ -184,7 +184,7 @@ namespace BlackSim
|
||||
void setSimulatorText(const QString &simulator);
|
||||
|
||||
//! \copydoc CValueObject::propertyByIndex
|
||||
QVariant propertyByIndex(int index) const override;
|
||||
QVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const override;
|
||||
|
||||
//! \copydoc CValueObject::setPropertyByIndex()
|
||||
void setPropertyByIndex(const QVariant &value, const BlackMisc::CPropertyIndex &index) override;
|
||||
|
||||
Reference in New Issue
Block a user