mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-18 03:15:34 +08:00
refs #345 Second wave of value classes using the CValueObjectStdTuple CRTP class template, with inheritance.
This commit is contained in:
@@ -23,7 +23,7 @@ namespace BlackMisc
|
||||
/*!
|
||||
* ADF system ("for NDBs")
|
||||
*/
|
||||
class CAdfSystem : public CModulator<CAdfSystem>
|
||||
class CAdfSystem : public CValueObjectStdTuple<CAdfSystem, CModulator<CAdfSystem>>
|
||||
{
|
||||
public:
|
||||
//! Default constructor
|
||||
@@ -31,7 +31,7 @@ namespace BlackMisc
|
||||
|
||||
//! Constructor
|
||||
CAdfSystem(const QString &name, const PhysicalQuantities::CFrequency &activeFrequency, const PhysicalQuantities::CFrequency &standbyFrequency = CModulator::FrequencyNotSet()):
|
||||
CModulator(name, activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency)
|
||||
CValueObjectStdTuple(name, activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency)
|
||||
{ }
|
||||
|
||||
//! Valid aviation frequency?
|
||||
@@ -41,19 +41,6 @@ namespace BlackMisc
|
||||
return fr >= 190.0 && fr <= 1750.0;
|
||||
}
|
||||
|
||||
//! Equal operator ==
|
||||
bool operator ==(const CAdfSystem &otherSystem) const
|
||||
{
|
||||
return this->CModulator::operator ==(otherSystem);
|
||||
}
|
||||
|
||||
//! Equal operator !=
|
||||
bool operator !=(const CAdfSystem &otherSystem) const
|
||||
{
|
||||
return this->CModulator::operator !=(otherSystem);
|
||||
}
|
||||
|
||||
|
||||
//! ADF1 unit
|
||||
static CAdfSystem GetAdf1System(double activeFrequencyKHz, double standbyFrequencyKHz = -1)
|
||||
{
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
#include "aviobase.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
{
|
||||
bool CAvionicsBase::operator ==(const CAvionicsBase &other) const
|
||||
{
|
||||
if (this == &other) return true;
|
||||
return TupleConverter<CAvionicsBase>::toTuple(*this) == TupleConverter<CAvionicsBase>::toTuple(other);
|
||||
}
|
||||
|
||||
int CAvionicsBase::compareImpl(const CValueObject &otherBase) const
|
||||
{
|
||||
const auto &other = static_cast<const CAvionicsBase &>(otherBase);
|
||||
return compare(TupleConverter<CAvionicsBase>::toTuple(*this), TupleConverter<CAvionicsBase>::toTuple(other));
|
||||
}
|
||||
|
||||
void CAvionicsBase::marshallToDbus(QDBusArgument &argument) const
|
||||
{
|
||||
argument << TupleConverter<CAvionicsBase>::toTuple(*this);
|
||||
}
|
||||
|
||||
void CAvionicsBase::unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
argument >> TupleConverter<CAvionicsBase>::toTuple(*this);
|
||||
}
|
||||
|
||||
uint CAvionicsBase::getValueHash() const
|
||||
{
|
||||
return qHash(TupleConverter<CAvionicsBase>::toTuple(*this));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ namespace BlackMisc
|
||||
{
|
||||
|
||||
//! \brief Base class for avionics
|
||||
class CAvionicsBase : public BlackMisc::CValueObject
|
||||
class CAvionicsBase : public CValueObjectStdTuple<CAvionicsBase>
|
||||
{
|
||||
protected:
|
||||
QString m_name; //!< name of the unit
|
||||
@@ -32,32 +32,8 @@ namespace BlackMisc
|
||||
this->m_name = name;
|
||||
}
|
||||
|
||||
//! \brief operator ==
|
||||
bool operator ==(const CAvionicsBase &other) const;
|
||||
|
||||
//! \brief operator !=
|
||||
bool operator !=(const CAvionicsBase &other) const
|
||||
{
|
||||
return !(other == (*this));
|
||||
}
|
||||
|
||||
//! \copydoc CValueObject::getMetaTypeId
|
||||
virtual int getMetaTypeId() const override { return 0; }
|
||||
|
||||
//! \copydoc CValueObject::isA
|
||||
virtual bool isA(int metaTypeId) const override { return this->CValueObject::isA(metaTypeId); }
|
||||
|
||||
//! \copydoc CValueObject::compareImpl(otherBase)
|
||||
virtual int compareImpl(const CValueObject &otherBase) const override;
|
||||
|
||||
//! \copydoc CValueObject::marshallToDbus()
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const override;
|
||||
|
||||
//! \copydoc CValueObject::unmarshallFromDbus()
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
|
||||
|
||||
//! \copydoc CValueObject::getValueHash()
|
||||
virtual uint getValueHash() const override;
|
||||
//! \copydoc CValueObject::convertToQString
|
||||
virtual QString convertToQString(bool i18n = false) const override { Q_UNUSED(i18n); return ""; }
|
||||
|
||||
public:
|
||||
//! \brief Name
|
||||
|
||||
@@ -46,83 +46,6 @@ namespace BlackMisc
|
||||
CModulator::setFrequencyStandby(f);
|
||||
}
|
||||
|
||||
/*
|
||||
* Marshall
|
||||
*/
|
||||
void CComSystem::marshallToDbus(QDBusArgument &argument) const
|
||||
{
|
||||
CModulator::marshallToDbus(argument);
|
||||
argument << TupleConverter<CComSystem>::toTuple(*this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Unmarshall
|
||||
*/
|
||||
void CComSystem::unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
CModulator::unmarshallFromDbus(argument);
|
||||
argument >> TupleConverter<CComSystem>::toTuple(*this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Hash
|
||||
*/
|
||||
uint CComSystem::getValueHash() const
|
||||
{
|
||||
QList<uint> hashs;
|
||||
hashs << CModulator::getValueHash();
|
||||
hashs << qHash(TupleConverter<CComSystem>::toTuple(*this));
|
||||
return BlackMisc::calculateHash(hashs, "CComSystem");
|
||||
}
|
||||
|
||||
/*
|
||||
* To JSON
|
||||
*/
|
||||
QJsonObject CComSystem::toJson() const
|
||||
{
|
||||
QJsonObject json = BlackMisc::serializeJson(CComSystem::jsonMembers(), TupleConverter<CComSystem>::toTuple(*this));
|
||||
return BlackMisc::Json::appendJsonObject(json, CModulator::toJson());
|
||||
}
|
||||
|
||||
/*
|
||||
* To JSON
|
||||
*/
|
||||
void CComSystem::convertFromJson(const QJsonObject &json)
|
||||
{
|
||||
CModulator::convertFromJson(json);
|
||||
BlackMisc::deserializeJson(json, CComSystem::jsonMembers(), TupleConverter<CComSystem>::toTuple(*this));
|
||||
}
|
||||
|
||||
/*
|
||||
* Members
|
||||
*/
|
||||
const QStringList &CComSystem::jsonMembers()
|
||||
{
|
||||
return TupleConverter<CComSystem>::jsonMembers();
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare
|
||||
*/
|
||||
int CComSystem::compareImpl(const CValueObject &otherBase) const
|
||||
{
|
||||
const auto &other = static_cast<const CComSystem &>(otherBase);
|
||||
int result = compare(TupleConverter<CComSystem>::toTuple(*this), TupleConverter<CComSystem>::toTuple(other));
|
||||
return result == 0 ? CModulator::compareImpl(otherBase) : result;
|
||||
}
|
||||
|
||||
bool CComSystem::operator ==(const CComSystem &other) const
|
||||
{
|
||||
if (this == &other) return true;
|
||||
if (!CModulator::operator ==(other)) return false;
|
||||
return TupleConverter<CComSystem>::toTuple(*this) == TupleConverter<CComSystem>::toTuple(other);
|
||||
}
|
||||
|
||||
bool CComSystem::operator !=(const CComSystem &other) const
|
||||
{
|
||||
return !((*this) == other);
|
||||
}
|
||||
|
||||
/*
|
||||
* Round to channel spacing
|
||||
*/
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace BlackMisc
|
||||
/*!
|
||||
* COM system (aka "radio")
|
||||
*/
|
||||
class CComSystem : public CModulator<CComSystem>
|
||||
class CComSystem : public CValueObjectStdTuple<CComSystem, CModulator<CComSystem>>
|
||||
{
|
||||
public:
|
||||
//! Channel spacing frequency
|
||||
@@ -36,7 +36,7 @@ namespace BlackMisc
|
||||
|
||||
//! Constructor
|
||||
CComSystem(const QString &name, const BlackMisc::PhysicalQuantities::CFrequency &activeFrequency, const BlackMisc::PhysicalQuantities::CFrequency &standbyFrequency = CModulator::FrequencyNotSet()):
|
||||
CModulator(name, activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency), m_channelSpacing(ChannelSpacing25KHz)
|
||||
CValueObjectStdTuple(name, activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency), m_channelSpacing(ChannelSpacing25KHz)
|
||||
{ }
|
||||
|
||||
//! Set active frequency
|
||||
@@ -73,24 +73,6 @@ namespace BlackMisc
|
||||
this->setFrequencyActive(BlackMisc::PhysicalQuantities::CPhysicalQuantitiesConstants::FrequencyInternationalAirDistress());
|
||||
}
|
||||
|
||||
//! \copydoc CValueObject::getValueHash
|
||||
virtual uint getValueHash() const override;
|
||||
|
||||
//! \copydoc CValueObject::toJson
|
||||
virtual QJsonObject toJson() const override;
|
||||
|
||||
//! \copydoc CValueObject::convertFromJson
|
||||
virtual void convertFromJson(const QJsonObject &json) override;
|
||||
|
||||
//! Members
|
||||
static const QStringList &jsonMembers();
|
||||
|
||||
//! operator ==
|
||||
bool operator ==(const CComSystem &other) const;
|
||||
|
||||
//! operator !=
|
||||
bool operator !=(const CComSystem &other) const;
|
||||
|
||||
//! COM1 unit
|
||||
static CComSystem getCom1System(double activeFrequencyMHz, double standbyFrequencyMHz = -1)
|
||||
{
|
||||
@@ -162,15 +144,6 @@ namespace BlackMisc
|
||||
//! \copydoc CAvionicsBase::validValues
|
||||
virtual bool validValues() const override;
|
||||
|
||||
//! \copydoc CValueObject::marshallFromDbus()
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const override;
|
||||
|
||||
//! \copydoc CValueObject::unmarshallFromDbus()
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
|
||||
|
||||
//! \copydoc CValueObject::compareImpl
|
||||
virtual int compareImpl(const CValueObject &other) const override;
|
||||
|
||||
private:
|
||||
BLACK_ENABLE_TUPLE_CONVERSION(CComSystem)
|
||||
ChannelSpacing m_channelSpacing;
|
||||
|
||||
@@ -31,31 +31,6 @@ namespace BlackMisc
|
||||
this->m_frequencyStandby = a;
|
||||
}
|
||||
|
||||
/*
|
||||
* Register metadata
|
||||
*/
|
||||
template <class AVIO> void CModulator<AVIO>::registerMetadata()
|
||||
{
|
||||
qRegisterMetaType<AVIO>();
|
||||
qDBusRegisterMetaType<AVIO>();
|
||||
}
|
||||
|
||||
/*
|
||||
* To JSON
|
||||
*/
|
||||
template <class AVIO> QJsonObject CModulator<AVIO>::toJson() const
|
||||
{
|
||||
return BlackMisc::serializeJson(CModulator::jsonMembers(), TupleConverter<CModulator>::toTuple(*this));
|
||||
}
|
||||
|
||||
/*
|
||||
* To JSON
|
||||
*/
|
||||
template <class AVIO> void CModulator<AVIO>::convertFromJson(const QJsonObject &json)
|
||||
{
|
||||
BlackMisc::deserializeJson(json, CModulator::jsonMembers(), TupleConverter<CModulator>::toTuple(*this));
|
||||
}
|
||||
|
||||
/*
|
||||
* Property by index
|
||||
*/
|
||||
@@ -114,71 +89,6 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Members
|
||||
*/
|
||||
template <class AVIO> const QStringList &CModulator<AVIO>::jsonMembers()
|
||||
{
|
||||
return TupleConverter<CModulator>::jsonMembers();
|
||||
}
|
||||
|
||||
/*
|
||||
* Equal operator ==
|
||||
*/
|
||||
template <class AVIO> bool CModulator<AVIO>::operator ==(const CModulator<AVIO> &other) const
|
||||
{
|
||||
if (this == &other) return true;
|
||||
if (!CAvionicsBase::operator ==(other)) return false;
|
||||
return TupleConverter<CModulator>::toTuple(*this) == TupleConverter<CModulator>::toTuple(other);
|
||||
}
|
||||
|
||||
/*
|
||||
* Equal operator !=
|
||||
*/
|
||||
template <class AVIO> bool CModulator<AVIO>::operator !=(const CModulator<AVIO> &other) const
|
||||
{
|
||||
return !(other == (*this));
|
||||
}
|
||||
|
||||
/*
|
||||
* To DBus
|
||||
*/
|
||||
template <class AVIO> void CModulator<AVIO>::marshallToDbus(QDBusArgument &argument) const
|
||||
{
|
||||
CAvionicsBase::marshallToDbus(argument);
|
||||
argument << TupleConverter<CModulator>::toTuple(*this);
|
||||
}
|
||||
|
||||
/*
|
||||
* From DBus
|
||||
*/
|
||||
template <class AVIO> void CModulator<AVIO>::unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
CAvionicsBase::unmarshallFromDbus(argument);
|
||||
argument >> TupleConverter<CModulator>::toTuple(*this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare
|
||||
*/
|
||||
template <class AVIO> int CModulator<AVIO>::compareImpl(const CValueObject &otherBase) const
|
||||
{
|
||||
const auto &other = static_cast<const CModulator &>(otherBase);
|
||||
int result = compare(TupleConverter<CModulator>::toTuple(*this), TupleConverter<CModulator>::toTuple(other));
|
||||
return result == 0 ? CAvionicsBase::compareImpl(otherBase) : result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Value hash
|
||||
*/
|
||||
template <class AVIO> uint CModulator<AVIO>::getValueHash() const
|
||||
{
|
||||
QList<uint> hashs;
|
||||
hashs << CAvionicsBase::getValueHash();
|
||||
hashs << qHash(TupleConverter<CModulator>::toTuple(*this));
|
||||
return BlackMisc::calculateHash(hashs, "CModulator");
|
||||
}
|
||||
|
||||
// see here for the reason of thess forward instantiations
|
||||
// http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html
|
||||
template class CModulator<CComSystem>;
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace BlackMisc
|
||||
/*!
|
||||
* Base class for COM, NAV, Squawk units.
|
||||
*/
|
||||
template <class AVIO> class CModulator : public CAvionicsBase
|
||||
template <class AVIO> class CModulator : public CValueObjectStdTuple<CModulator<AVIO>, CAvionicsBase>
|
||||
{
|
||||
public:
|
||||
//! Column indexes
|
||||
@@ -89,38 +89,20 @@ namespace BlackMisc
|
||||
//! Enabled?
|
||||
void setEnabled(bool enable) { this->m_enabled = enable;}
|
||||
|
||||
//! \copydoc CValueObject::toQVariant
|
||||
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this->derived()); }
|
||||
|
||||
//! \copydoc CValueObject::convertFromQVariant
|
||||
virtual void convertFromQVariant(const QVariant &variant) override { BlackMisc::setFromQVariant(derived(), variant); }
|
||||
|
||||
//! \copydoc CValueObject::toJson
|
||||
virtual QJsonObject toJson() const override;
|
||||
|
||||
//! \copydoc CValueObject::convertFromJson
|
||||
virtual void convertFromJson(const QJsonObject &json) override;
|
||||
|
||||
//! \copydoc CValueObject::propertyByIndex
|
||||
virtual QVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const override;
|
||||
|
||||
//! \copydoc CValueObject::setPropertyByIndex(variant, index)
|
||||
virtual void setPropertyByIndex(const QVariant &variant, const BlackMisc::CPropertyIndex &index) override;
|
||||
|
||||
//! Register metadata
|
||||
static void registerMetadata();
|
||||
|
||||
//! Members
|
||||
static const QStringList &jsonMembers();
|
||||
|
||||
protected:
|
||||
//! Default constructor
|
||||
CModulator() :
|
||||
CAvionicsBase("default") {}
|
||||
CModulator::CValueObjectStdTuple("default") {}
|
||||
|
||||
//! Constructor
|
||||
CModulator(const QString &name, const BlackMisc::PhysicalQuantities::CFrequency &activeFrequency, const BlackMisc::PhysicalQuantities::CFrequency &standbyFrequency) :
|
||||
CAvionicsBase(name), m_frequencyActive(activeFrequency), m_frequencyStandby(standbyFrequency) {}
|
||||
CModulator::CValueObjectStdTuple(name), m_frequencyActive(activeFrequency), m_frequencyStandby(standbyFrequency) {}
|
||||
|
||||
//! \copydoc CValueObject::convertToQString
|
||||
virtual QString convertToQString(bool i18n = false) const override
|
||||
@@ -157,15 +139,6 @@ namespace BlackMisc
|
||||
this->m_frequencyStandby = BlackMisc::PhysicalQuantities::CFrequency(frequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz());
|
||||
}
|
||||
|
||||
//! operator ==
|
||||
bool operator ==(const CModulator &other) const;
|
||||
|
||||
//! operator !=
|
||||
bool operator !=(const CModulator &other) const;
|
||||
|
||||
//! \copydoc CValueObject::compareImpl(otherBase)
|
||||
virtual int compareImpl(const CValueObject &otherBase) const override;
|
||||
|
||||
//! COM1
|
||||
static const QString &NameCom1()
|
||||
{
|
||||
@@ -229,15 +202,6 @@ namespace BlackMisc
|
||||
return f;
|
||||
}
|
||||
|
||||
//! \copydoc CValueObject::marshallFromDbus()
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const override;
|
||||
|
||||
//! \copydoc CValueObject::unmarshallFromDbus()
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
|
||||
|
||||
//! \copydoc CValueObject::getValueHash()
|
||||
virtual uint getValueHash() const override;
|
||||
|
||||
private:
|
||||
BLACK_ENABLE_TUPLE_CONVERSION(CModulator)
|
||||
BlackMisc::PhysicalQuantities::CFrequency m_frequencyActive; //!< active frequency
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace BlackMisc
|
||||
namespace Aviation
|
||||
{
|
||||
//! NAV system (radio navigation)
|
||||
class CNavSystem : public CModulator<CNavSystem>
|
||||
class CNavSystem : public CValueObjectStdTuple<CNavSystem, CModulator<CNavSystem>>
|
||||
{
|
||||
public:
|
||||
//! Default constructor
|
||||
@@ -27,7 +27,7 @@ namespace BlackMisc
|
||||
|
||||
//! Constructor
|
||||
CNavSystem(const QString &name, const BlackMisc::PhysicalQuantities::CFrequency &activeFrequency, const BlackMisc::PhysicalQuantities::CFrequency &standbyFrequency):
|
||||
CModulator(name, activeFrequency, standbyFrequency)
|
||||
CValueObjectStdTuple(name, activeFrequency, standbyFrequency)
|
||||
{ }
|
||||
|
||||
//! Set active frequency
|
||||
@@ -42,18 +42,6 @@ namespace BlackMisc
|
||||
this->CModulator::setFrequencyStandbyMHz(frequencyMHz);
|
||||
}
|
||||
|
||||
//! Equal operator ==
|
||||
bool operator ==(const CNavSystem &other) const
|
||||
{
|
||||
return this->CModulator::operator ==(other);
|
||||
}
|
||||
|
||||
//! Unequal operator !=
|
||||
bool operator !=(const CNavSystem &other) const
|
||||
{
|
||||
return this->CModulator::operator !=(other);
|
||||
}
|
||||
|
||||
//! Valid civil aviation frequency?
|
||||
static bool isValidCivilNavigationFrequency(BlackMisc::PhysicalQuantities::CFrequency f)
|
||||
{
|
||||
|
||||
@@ -111,54 +111,6 @@ namespace BlackMisc
|
||||
return CTransponder::isValidTransponderCode(QString::number(transponderCode));
|
||||
}
|
||||
|
||||
/*
|
||||
* Marshall
|
||||
*/
|
||||
void CTransponder::marshallToDbus(QDBusArgument &argument) const
|
||||
{
|
||||
CAvionicsBase::marshallToDbus(argument);
|
||||
argument << TupleConverter<CTransponder>::toTuple(*this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Unmarshall
|
||||
*/
|
||||
void CTransponder::unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
CAvionicsBase::unmarshallFromDbus(argument);
|
||||
argument >> TupleConverter<CTransponder>::toTuple(*this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Hash
|
||||
*/
|
||||
uint CTransponder::getValueHash() const
|
||||
{
|
||||
QList<uint> hashs;
|
||||
hashs << CAvionicsBase::getValueHash();
|
||||
hashs << qHash(TupleConverter<CTransponder>::toTuple(*this));
|
||||
return BlackMisc::calculateHash(hashs, "CTransponder");
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare
|
||||
*/
|
||||
int CTransponder::compareImpl(const CValueObject &otherBase) const
|
||||
{
|
||||
const auto &other = static_cast<const CTransponder &>(otherBase);
|
||||
int result = compare(TupleConverter<CTransponder>::toTuple(*this), TupleConverter<CTransponder>::toTuple(other));
|
||||
return result == 0 ? CAvionicsBase::compareImpl(otherBase) : result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Register metadata of unit and quantity
|
||||
*/
|
||||
void CTransponder::registerMetadata()
|
||||
{
|
||||
qRegisterMetaType<CTransponder>();
|
||||
qDBusRegisterMetaType<CTransponder>();
|
||||
}
|
||||
|
||||
/*
|
||||
* Mode as readable string
|
||||
*/
|
||||
@@ -200,30 +152,6 @@ namespace BlackMisc
|
||||
return m;
|
||||
}
|
||||
|
||||
/*
|
||||
* Members
|
||||
*/
|
||||
const QStringList &CTransponder::jsonMembers()
|
||||
{
|
||||
return TupleConverter<CTransponder>::jsonMembers();
|
||||
}
|
||||
|
||||
/*
|
||||
* To JSON
|
||||
*/
|
||||
QJsonObject CTransponder::toJson() const
|
||||
{
|
||||
return BlackMisc::serializeJson(CTransponder::jsonMembers(), TupleConverter<CTransponder>::toTuple(*this));
|
||||
}
|
||||
|
||||
/*
|
||||
* From Json
|
||||
*/
|
||||
void CTransponder::convertFromJson(const QJsonObject &json)
|
||||
{
|
||||
BlackMisc::deserializeJson(json, CTransponder::jsonMembers(), TupleConverter<CTransponder>::toTuple(*this));
|
||||
}
|
||||
|
||||
/*
|
||||
* Property
|
||||
*/
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace BlackMisc
|
||||
/*!
|
||||
* Transponder
|
||||
*/
|
||||
class CTransponder : public CAvionicsBase
|
||||
class CTransponder : public CValueObjectStdTuple<CTransponder, CAvionicsBase>
|
||||
{
|
||||
public:
|
||||
//! Transponder codes
|
||||
@@ -46,23 +46,23 @@ namespace BlackMisc
|
||||
};
|
||||
|
||||
//! Default constructor
|
||||
CTransponder() : CAvionicsBase("transponder"), m_transponderCode(0), m_transponderMode(StateStandby) {}
|
||||
CTransponder() : CValueObjectStdTuple("transponder"), m_transponderCode(0), m_transponderMode(StateStandby) {}
|
||||
|
||||
//! Constructor
|
||||
CTransponder(const QString &name, qint32 transponderCode, TransponderMode transponderMode) :
|
||||
CAvionicsBase(name), m_transponderCode(transponderCode), m_transponderMode(transponderMode)
|
||||
CValueObjectStdTuple(name), m_transponderCode(transponderCode), m_transponderMode(transponderMode)
|
||||
{ }
|
||||
|
||||
//! Constructor with transponder mode as string
|
||||
CTransponder(const QString &name, qint32 transponderCode, QString transponderMode) :
|
||||
CAvionicsBase(name), m_transponderCode(transponderCode), m_transponderMode(StateStandby)
|
||||
CValueObjectStdTuple(name), m_transponderCode(transponderCode), m_transponderMode(StateStandby)
|
||||
{
|
||||
this->setModeAsString(transponderMode);
|
||||
}
|
||||
|
||||
//! Constructor, code as string
|
||||
CTransponder(const QString &name, QString transponderCode, TransponderMode transponderMode) :
|
||||
CAvionicsBase(name), m_transponderCode(0), m_transponderMode(transponderMode)
|
||||
CValueObjectStdTuple(name), m_transponderCode(0), m_transponderMode(transponderMode)
|
||||
{
|
||||
bool ok = false;
|
||||
this->m_transponderCode = transponderCode.toUInt(&ok);
|
||||
@@ -71,7 +71,7 @@ namespace BlackMisc
|
||||
|
||||
//! Constructor
|
||||
CTransponder(const QString &name, QString transponderCode, QString transponderMode) :
|
||||
CAvionicsBase(name), m_transponderCode(0), m_transponderMode(StateStandby)
|
||||
CValueObjectStdTuple(name), m_transponderCode(0), m_transponderMode(StateStandby)
|
||||
{
|
||||
bool ok = false;
|
||||
this->m_transponderCode = transponderCode.toUInt(&ok);
|
||||
@@ -136,57 +136,24 @@ namespace BlackMisc
|
||||
//! Set IFR
|
||||
void setIFR() { this->m_transponderCode = 2000; }
|
||||
|
||||
//! operator ==
|
||||
bool operator ==(const CTransponder &other) const
|
||||
{
|
||||
return
|
||||
this->m_transponderCode == other.m_transponderCode &&
|
||||
this->getTransponderMode() == other.getTransponderMode() &&
|
||||
this->CAvionicsBase::operator ==(other);
|
||||
}
|
||||
|
||||
//! operator !=
|
||||
bool operator !=(const CTransponder &other) const { return !((*this) == other); }
|
||||
|
||||
//! Transponder unit
|
||||
static CTransponder getStandardTransponder(qint32 transponderCode, TransponderMode mode)
|
||||
{
|
||||
return CTransponder("Transponder", transponderCode, mode);
|
||||
}
|
||||
|
||||
//! \copydoc CValueObject::getValueHash()
|
||||
virtual uint getValueHash() const override;
|
||||
|
||||
//! \copydoc CValueObject::toJson
|
||||
virtual QJsonObject toJson() const override;
|
||||
|
||||
//! \copydoc CValueObject::convertFromJson
|
||||
virtual void convertFromJson(const QJsonObject &json) override;
|
||||
|
||||
//! \copydoc CValueObject::toQVariant
|
||||
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); }
|
||||
|
||||
//! \copydoc CValueObject::convertFromQVariant
|
||||
virtual void convertFromQVariant(const QVariant &variant) override { BlackMisc::setFromQVariant(this, variant); }
|
||||
|
||||
//! \copydoc CValueObject::propertyByIndex
|
||||
virtual QVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const override;
|
||||
|
||||
//! \copydoc CValueObject::setPropertyByIndex(variant, index)
|
||||
virtual void setPropertyByIndex(const QVariant &variant, const BlackMisc::CPropertyIndex &index) override;
|
||||
|
||||
//! JSON member names
|
||||
static const QStringList &jsonMembers();
|
||||
|
||||
//! Is valid transponder code?
|
||||
static bool isValidTransponderCode(const QString &transponderCode);
|
||||
|
||||
//! Is valid transponder code?
|
||||
static bool isValidTransponderCode(qint32 transponderMode);
|
||||
|
||||
//! Register metadata
|
||||
static void registerMetadata();
|
||||
|
||||
protected:
|
||||
//! Default value?
|
||||
virtual bool isDefaultValue() const { return this->m_transponderCode == 0; }
|
||||
@@ -194,15 +161,6 @@ namespace BlackMisc
|
||||
//! \copydoc CValueObject::convertToQString
|
||||
virtual QString convertToQString(bool i18n = false) const override;
|
||||
|
||||
//! \copydoc CValueObject::marshallFromDbus()
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const override;
|
||||
|
||||
//! \copydoc CValueObject::unmarshallFromDbus()
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
|
||||
|
||||
//! \copydoc CValueObject::compareImpl
|
||||
virtual int compareImpl(const CValueObject &other) const override;
|
||||
|
||||
private:
|
||||
BLACK_ENABLE_TUPLE_CONVERSION(CTransponder)
|
||||
qint32 m_transponderCode; //!< Transponder code
|
||||
|
||||
Reference in New Issue
Block a user