mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 18:25:37 +08:00
refs #873, nullable interface for value objects
This commit is contained in:
committed by
Mathew Sutcliffe
parent
273427d3d9
commit
f0cbe3b332
@@ -18,12 +18,6 @@ namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
{
|
||||
|
||||
CAircraftLights::CAircraftLights(std::nullptr_t null) : m_isNull(true)
|
||||
{
|
||||
Q_UNUSED(null);
|
||||
}
|
||||
|
||||
CAircraftLights::CAircraftLights(bool strobeOn, bool landingOn, bool taxiOn, bool beaconOn, bool navOn, bool logoOn)
|
||||
: m_strobeOn(strobeOn), m_landingOn(landingOn), m_taxiOn(taxiOn), m_beaconOn(beaconOn), m_navOn(navOn), m_logoOn(logoOn)
|
||||
{ }
|
||||
@@ -52,8 +46,9 @@ namespace BlackMisc
|
||||
CVariant CAircraftLights::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
if (INullable::canHandleIndex(index)) { return INullable::propertyByIndex(index); }
|
||||
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexBeacon:
|
||||
@@ -76,7 +71,9 @@ namespace BlackMisc
|
||||
void CAircraftLights::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CAircraftLights>(); return; }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
if (INullable::canHandleIndex(index)) { INullable::setPropertyByIndex(index, variant); return; }
|
||||
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexBeacon:
|
||||
@@ -122,6 +119,5 @@ namespace BlackMisc
|
||||
m_strobeOn = false;
|
||||
m_taxiOn = false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/valueobject.h"
|
||||
#include "blackmisc/variant.h"
|
||||
#include "blackmisc/nullable.h"
|
||||
|
||||
#include <QMetaType>
|
||||
#include <QString>
|
||||
@@ -26,7 +27,9 @@ namespace BlackMisc
|
||||
namespace Aviation
|
||||
{
|
||||
//! Value object encapsulating information about aircraft's lights
|
||||
class BLACKMISC_EXPORT CAircraftLights : public CValueObject<CAircraftLights>
|
||||
class BLACKMISC_EXPORT CAircraftLights :
|
||||
public CValueObject<CAircraftLights>,
|
||||
public INullable
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
@@ -44,17 +47,11 @@ namespace BlackMisc
|
||||
CAircraftLights() = default;
|
||||
|
||||
//! Constructor, init to null
|
||||
CAircraftLights(std::nullptr_t null);
|
||||
using INullable::INullable;
|
||||
|
||||
//! Constructor
|
||||
CAircraftLights(bool strobeOn, bool landingOn, bool taxiOn, bool beaconOn, bool navOn, bool logoOn);
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
||||
CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
|
||||
void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const CVariant &variant);
|
||||
|
||||
//! Strobes lights on?
|
||||
bool isStrobeOn() const { return m_strobeOn; }
|
||||
|
||||
@@ -97,8 +94,14 @@ namespace BlackMisc
|
||||
//! All off
|
||||
void setAllOff();
|
||||
|
||||
//! Is null;
|
||||
bool isNull() const { return m_isNull; }
|
||||
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
||||
CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
|
||||
void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const CVariant &variant);
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! Returns object with all lights switched on
|
||||
static CAircraftLights allLightsOn();
|
||||
@@ -106,9 +109,6 @@ namespace BlackMisc
|
||||
//! Returns object with all lights switched off
|
||||
static CAircraftLights allLightsOff();
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
private:
|
||||
bool m_strobeOn = false;
|
||||
bool m_landingOn = false;
|
||||
@@ -116,10 +116,10 @@ namespace BlackMisc
|
||||
bool m_beaconOn = false;
|
||||
bool m_navOn = false;
|
||||
bool m_logoOn = false;
|
||||
bool m_isNull = false; //!< mark as null
|
||||
|
||||
BLACK_METACLASS(
|
||||
CAircraftLights,
|
||||
BLACK_METAMEMBER(isNull, 0, DisabledForJson), // disable since JSON is used for network
|
||||
BLACK_METAMEMBER_NAMED(strobeOn, "strobe_on"),
|
||||
BLACK_METAMEMBER_NAMED(landingOn, "landing_on"),
|
||||
BLACK_METAMEMBER_NAMED(taxiOn, "taxi_on"),
|
||||
|
||||
Reference in New Issue
Block a user