mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 17:35:34 +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
|
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)
|
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)
|
: 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
|
CVariant CAircraftLights::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||||
{
|
{
|
||||||
if (index.isMyself()) { return CVariant::from(*this); }
|
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)
|
switch (i)
|
||||||
{
|
{
|
||||||
case IndexBeacon:
|
case IndexBeacon:
|
||||||
@@ -76,7 +71,9 @@ namespace BlackMisc
|
|||||||
void CAircraftLights::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
void CAircraftLights::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
||||||
{
|
{
|
||||||
if (index.isMyself()) { (*this) = variant.to<CAircraftLights>(); return; }
|
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)
|
switch (i)
|
||||||
{
|
{
|
||||||
case IndexBeacon:
|
case IndexBeacon:
|
||||||
@@ -122,6 +119,5 @@ namespace BlackMisc
|
|||||||
m_strobeOn = false;
|
m_strobeOn = false;
|
||||||
m_taxiOn = false;
|
m_taxiOn = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include "blackmisc/propertyindex.h"
|
#include "blackmisc/propertyindex.h"
|
||||||
#include "blackmisc/valueobject.h"
|
#include "blackmisc/valueobject.h"
|
||||||
#include "blackmisc/variant.h"
|
#include "blackmisc/variant.h"
|
||||||
|
#include "blackmisc/nullable.h"
|
||||||
|
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
@@ -26,7 +27,9 @@ namespace BlackMisc
|
|||||||
namespace Aviation
|
namespace Aviation
|
||||||
{
|
{
|
||||||
//! Value object encapsulating information about aircraft's lights
|
//! 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:
|
public:
|
||||||
//! Properties by index
|
//! Properties by index
|
||||||
@@ -44,17 +47,11 @@ namespace BlackMisc
|
|||||||
CAircraftLights() = default;
|
CAircraftLights() = default;
|
||||||
|
|
||||||
//! Constructor, init to null
|
//! Constructor, init to null
|
||||||
CAircraftLights(std::nullptr_t null);
|
using INullable::INullable;
|
||||||
|
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CAircraftLights(bool strobeOn, bool landingOn, bool taxiOn, bool beaconOn, bool navOn, bool logoOn);
|
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?
|
//! Strobes lights on?
|
||||||
bool isStrobeOn() const { return m_strobeOn; }
|
bool isStrobeOn() const { return m_strobeOn; }
|
||||||
|
|
||||||
@@ -97,8 +94,14 @@ namespace BlackMisc
|
|||||||
//! All off
|
//! All off
|
||||||
void setAllOff();
|
void setAllOff();
|
||||||
|
|
||||||
//! Is null;
|
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
||||||
bool isNull() const { return m_isNull; }
|
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
|
//! Returns object with all lights switched on
|
||||||
static CAircraftLights allLightsOn();
|
static CAircraftLights allLightsOn();
|
||||||
@@ -106,9 +109,6 @@ namespace BlackMisc
|
|||||||
//! Returns object with all lights switched off
|
//! Returns object with all lights switched off
|
||||||
static CAircraftLights allLightsOff();
|
static CAircraftLights allLightsOff();
|
||||||
|
|
||||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
|
||||||
QString convertToQString(bool i18n = false) const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_strobeOn = false;
|
bool m_strobeOn = false;
|
||||||
bool m_landingOn = false;
|
bool m_landingOn = false;
|
||||||
@@ -116,10 +116,10 @@ namespace BlackMisc
|
|||||||
bool m_beaconOn = false;
|
bool m_beaconOn = false;
|
||||||
bool m_navOn = false;
|
bool m_navOn = false;
|
||||||
bool m_logoOn = false;
|
bool m_logoOn = false;
|
||||||
bool m_isNull = false; //!< mark as null
|
|
||||||
|
|
||||||
BLACK_METACLASS(
|
BLACK_METACLASS(
|
||||||
CAircraftLights,
|
CAircraftLights,
|
||||||
|
BLACK_METAMEMBER(isNull, 0, DisabledForJson), // disable since JSON is used for network
|
||||||
BLACK_METAMEMBER_NAMED(strobeOn, "strobe_on"),
|
BLACK_METAMEMBER_NAMED(strobeOn, "strobe_on"),
|
||||||
BLACK_METAMEMBER_NAMED(landingOn, "landing_on"),
|
BLACK_METAMEMBER_NAMED(landingOn, "landing_on"),
|
||||||
BLACK_METAMEMBER_NAMED(taxiOn, "taxi_on"),
|
BLACK_METAMEMBER_NAMED(taxiOn, "taxi_on"),
|
||||||
|
|||||||
69
src/blackmisc/nullable.cpp
Normal file
69
src/blackmisc/nullable.cpp
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
/* Copyright (C) 2017
|
||||||
|
* swift project Community / Contributors
|
||||||
|
*
|
||||||
|
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||||
|
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||||
|
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||||
|
* contained in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "blackmisc/comparefunctions.h"
|
||||||
|
#include "blackmisc/nullable.h"
|
||||||
|
#include "blackmisc/verify.h"
|
||||||
|
|
||||||
|
namespace BlackMisc
|
||||||
|
{
|
||||||
|
INullable::INullable(std::nullptr_t null) : m_isNull(true)
|
||||||
|
{
|
||||||
|
Q_UNUSED(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool INullable::canHandleIndex(const CPropertyIndex &index)
|
||||||
|
{
|
||||||
|
if (index.isEmpty()) { return false; }
|
||||||
|
int i = index.frontCasted<int>();
|
||||||
|
return (i >= static_cast<int>(IndexIsNull)) && (i <= static_cast<int>(IndexIsNull));
|
||||||
|
}
|
||||||
|
|
||||||
|
CVariant INullable::propertyByIndex(const CPropertyIndex &index) const
|
||||||
|
{
|
||||||
|
if (!index.isEmpty())
|
||||||
|
{
|
||||||
|
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||||
|
switch (i)
|
||||||
|
{
|
||||||
|
case IndexIsNull:
|
||||||
|
return CVariant::fromValue(this->isNull());
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const QString m = QString("Cannot handle index %1").arg(index.toQString());
|
||||||
|
BLACK_VERIFY_X(false, Q_FUNC_INFO, qUtf8Printable(m));
|
||||||
|
return CVariant::fromValue(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
void INullable::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
||||||
|
{
|
||||||
|
if (!index.isEmpty())
|
||||||
|
{
|
||||||
|
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||||
|
switch (i)
|
||||||
|
{
|
||||||
|
case IndexIsNull:
|
||||||
|
this->setNull(variant.toBool());
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const QString m = QString("Cannot handle index %1").arg(index.toQString());
|
||||||
|
BLACK_VERIFY_X(false, Q_FUNC_INFO, qUtf8Printable(m));
|
||||||
|
}
|
||||||
|
|
||||||
|
int INullable::comparePropertyByIndex(const CPropertyIndex &index, const INullable &compareValue) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(index);
|
||||||
|
return Compare::compare(this->m_isNull, compareValue.m_isNull);
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
60
src/blackmisc/nullable.h
Normal file
60
src/blackmisc/nullable.h
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/* Copyright (C) 2017
|
||||||
|
* swift project Community / Contributors
|
||||||
|
*
|
||||||
|
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||||
|
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||||
|
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||||
|
* contained in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//! \file
|
||||||
|
|
||||||
|
#ifndef BLACKMISC_NULLABLE_H
|
||||||
|
#define BLACKMISC_NULLABLE_H
|
||||||
|
|
||||||
|
#include "blackmisc/blackmiscexport.h"
|
||||||
|
#include "blackmisc/propertyindex.h"
|
||||||
|
#include "blackmisc/variant.h"
|
||||||
|
|
||||||
|
namespace BlackMisc
|
||||||
|
{
|
||||||
|
//! Nullable value object
|
||||||
|
class BLACKMISC_EXPORT INullable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! Properties by index
|
||||||
|
enum ColumnIndex
|
||||||
|
{
|
||||||
|
IndexIsNull = BlackMisc::CPropertyIndex::GlobalIndexINullable,
|
||||||
|
};
|
||||||
|
|
||||||
|
//! Constructor, init to null
|
||||||
|
INullable(std::nullptr_t null);
|
||||||
|
|
||||||
|
//! Null?
|
||||||
|
bool isNull() const { return m_isNull; }
|
||||||
|
|
||||||
|
//! Null?
|
||||||
|
void setNull(bool null) { m_isNull = null; }
|
||||||
|
|
||||||
|
//! Can given index be handled
|
||||||
|
static bool canHandleIndex(const BlackMisc::CPropertyIndex &index);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
//! Constructor
|
||||||
|
INullable() {}
|
||||||
|
|
||||||
|
//! \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);
|
||||||
|
|
||||||
|
//! Compare for index
|
||||||
|
int comparePropertyByIndex(const CPropertyIndex &index, const INullable &compareValue) const;
|
||||||
|
|
||||||
|
bool m_isNull = false; //!< null?
|
||||||
|
};
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
#endif // guard
|
||||||
@@ -82,9 +82,10 @@ namespace BlackMisc
|
|||||||
GlobalIndexCNameVariantPair = 300,
|
GlobalIndexCNameVariantPair = 300,
|
||||||
GlobalIndexITimestampBased = 400,
|
GlobalIndexITimestampBased = 400,
|
||||||
GlobalIndexIOrderable = 500,
|
GlobalIndexIOrderable = 500,
|
||||||
GlobalIndexCIdentifier = 600,
|
GlobalIndexINullable = 600,
|
||||||
GlobalIndexCRgbColor = 700,
|
GlobalIndexCIdentifier = 700,
|
||||||
GlobalIndexCCountry = 800,
|
GlobalIndexCRgbColor = 800,
|
||||||
|
GlobalIndexCCountry = 900,
|
||||||
GlobalIndexCCallsign = 1000,
|
GlobalIndexCCallsign = 1000,
|
||||||
GlobalIndexCAircraftSituation = 1100,
|
GlobalIndexCAircraftSituation = 1100,
|
||||||
GlobalIndexCAtcStation = 1200,
|
GlobalIndexCAtcStation = 1200,
|
||||||
|
|||||||
Reference in New Issue
Block a user