diff --git a/src/blackmisc/aviocomsystem.h b/src/blackmisc/aviocomsystem.h index 4a03b0acf..c158acf48 100644 --- a/src/blackmisc/aviocomsystem.h +++ b/src/blackmisc/aviocomsystem.h @@ -135,181 +135,52 @@ namespace BlackMisc //! \copydoc CValueObject::fromJson virtual void fromJson(const QJsonObject &json) override; - /*! - * Try to get a COM unit with given name and frequency. Returns true in case an object - * has been sucessfully created, otherwise returns a default object. - * \param[out] o_comSystem - * \param name - * \param activeFrequencyMHz - * \param standbyFrequencyMHz - * \return - */ - static bool tryGetComSystem(CComSystem &o_comSystem, const QString &name, double activeFrequencyMHz, double standbyFrequencyMHz = -1) - { - o_comSystem = CComSystem(false, name, BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz())); - bool s; - if (!(s = o_comSystem.validate(false))) o_comSystem = CComSystem(); // reset to default - return s; - } + //! \brief Members + static const QStringList &jsonMembers(); - /*! - * Try to get a COM unit with given name and frequency. Returns true in case an object - * has been sucessfully created, otherwise returns a default object. - * \param[out] o_comSystem - * \param name - * \param activeFrequency - * \param standbyFrequency - * \return - */ - static bool tryGetComSystem(CComSystem &o_comSystem, const QString &name, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) - { - o_comSystem = CComSystem(false, name, activeFrequency, standbyFrequency); - bool s; - if (!(s = o_comSystem.validate(false))) o_comSystem = CComSystem(); // reset to default - return s; - } + //! \brief operator == + bool operator ==(const CComSystem &other) const; - /*! - * \brief COM1 unit - * \param activeFrequencyMHz - * \param standbyFrequencyMHz - * \return - */ + //! \brief operator != + bool operator !=(const CComSystem &other) const; + + //! \brief COM1 unit static CComSystem getCom1System(double activeFrequencyMHz, double standbyFrequencyMHz = -1) { return CComSystem(CModulator::NameCom1(), BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz())); } - /*! - * \brief COM1 unit - * \param activeFrequency - * \param standbyFrequency - * \return - */ + //! \brief COM1 unit static CComSystem getCom1System(BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { return CComSystem(CModulator::NameCom1(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); } - /*! - * \brief Try to get COM unit - * \param[out] o_comSystem - * \param activeFrequencyMHz - * \param standbyFrequencyMHz - * \return - */ - static bool tryGetCom1Unit(CComSystem &o_comSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) - { - return CComSystem::tryGetComSystem(o_comSystem, CModulator::NameCom1(), activeFrequencyMHz, standbyFrequencyMHz); - } - - /*! - * \brief Try to get COM unit - * \param[out] o_comSystem - * \param activeFrequency - * \param standbyFrequency - * \return - */ - static bool tryGetCom1Unit(CComSystem &o_comSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) - { - return CComSystem::tryGetComSystem(o_comSystem, CModulator::NameCom1(), activeFrequency, standbyFrequency); - } - - /*! - * \brief COM2 unit - * \param activeFrequencyMHz - * \param standbyFrequencyMHz - * \return - */ + //! \brief COM2 unit static CComSystem getCom2System(double activeFrequencyMHz, double standbyFrequencyMHz = -1) { return CComSystem(CModulator::NameCom2(), BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz())); } - /*! - * \brief COM2 unit - * \param activeFrequency - * \param standbyFrequency - * \return - */ + //! \brief COM2 unit static CComSystem getCom2System(BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { return CComSystem(CModulator::NameCom2(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); } - /*! - * \brief Try to get COM unit - * \param[out] o_comSystem - * \param activeFrequencyMHz - * \param standbyFrequencyMHz - * \return - */ - static bool tryGetCom2System(CComSystem &o_comSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) - { - return CComSystem::tryGetComSystem(o_comSystem, CModulator::NameCom2(), activeFrequencyMHz, standbyFrequencyMHz); - } - - /*! - * \brief Try to get COM unit - * \param[out] o_comSystem - * \param activeFrequency - * \param standbyFrequency - * \return - */ - static bool tryGetCom2System(CComSystem &o_comSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) - { - return CComSystem::tryGetComSystem(o_comSystem, CModulator::NameCom2(), activeFrequency, standbyFrequency); - } - - /*! - * \brief COM3 unit - * \param activeFrequencyMHz - * \param standbyFrequencyMHz - * \return - */ + //! \brief COM3 unit static CComSystem getCom3System(double activeFrequencyMHz, double standbyFrequencyMHz = -1) { return CComSystem(CModulator::NameCom3(), BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz())); } - /*! - * \brief COM3 unit - * \param activeFrequency - * \param standbyFrequency - * \return - */ + //! \brief COM3 unit static CComSystem getCom3System(BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) { return CComSystem(CModulator::NameCom3(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency); } - /*! - * \brief Try to get COM unit - * \param[out] o_comSystem - * \param activeFrequencyMHz - * \param standbyFrequencyMHz - * \return - */ - static bool tryGetCom3System(CComSystem &o_comSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) - { - return CComSystem::tryGetComSystem(o_comSystem, CModulator::NameCom3(), activeFrequencyMHz, standbyFrequencyMHz); - } - - /*! - * \brief Try to get COM unit - * \param[out] o_comSystem - * \param activeFrequency - * \param standbyFrequency - * \return - */ - static bool tryGetCom3System(CComSystem &o_comSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) - { - return CComSystem::tryGetComSystem(o_comSystem, CModulator::NameCom3(), activeFrequency, standbyFrequency); - } - - /*! - * \brief Valid civil aviation frequency? - */ + //! \brief Valid civil aviation frequency? static bool isValidCivilAviationFrequency(const BlackMisc::PhysicalQuantities::CFrequency &f) { double fr = f.valueRounded(BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz(), 3); diff --git a/src/blackmisc/aviotransponder.h b/src/blackmisc/aviotransponder.h index 8e8eab62b..57019ac14 100644 --- a/src/blackmisc/aviotransponder.h +++ b/src/blackmisc/aviotransponder.h @@ -34,45 +34,8 @@ namespace BlackMisc qint32 m_transponderCode; //validate(validate); - } - - /*! - * \brief Constructor for validation - * \param validate - * \param name - * \param transponderCode - * \param transponderMode - */ - CTransponder(bool validate, const QString &name, const QString transponderCode, TransponderMode transponderMode) : - CAvionicsBase(name), m_transponderCode(0), m_transponderMode(transponderMode) - { - bool ok = false; - this->m_transponderCode = transponderCode.toUInt(&ok); - if (!ok) this->m_transponderCode = -1; // will cause assert / exception - this->validate(validate); - } - protected: - /*! - * \copydoc CAvionicsBase::validValues - */ - virtual bool validValues() const override; - - /*! - * \brief Default value - * \return - */ + //! \brief Default value? virtual bool isDefaultValue() const { return this->m_transponderCode == 0; @@ -100,36 +63,21 @@ namespace BlackMisc virtual int compareImpl(const CValueObject &other) const override; public: - /*! - * Default constructor - */ + //! \brief Default constructor CTransponder() : CAvionicsBase("transponder"), m_transponderCode(0), m_transponderMode(ModeS) {} - /*! - * \brief Copy constructor - * \param other - */ + //! \brief Copy constructor CTransponder(const CTransponder &other) : CAvionicsBase(other.getName()), m_transponderCode(other.m_transponderCode), m_transponderMode(other.m_transponderMode) {} - /*! - * \brief Constructor - * \param name - * \param transponderCode - * \param transponderMode - */ + //! \brief Constructor CTransponder(const QString &name, qint32 transponderCode, TransponderMode transponderMode) : CAvionicsBase(name), m_transponderCode(transponderCode), m_transponderMode(transponderMode) { this->validate(true); } - /*! - * \brief Constructor - * \param name - * \param transponderCode - * \param transponderMode - */ + //! \brief Constructor with transponder mode as string CTransponder(const QString &name, qint32 transponderCode, QString transponderMode) : CAvionicsBase(name), m_transponderCode(transponderCode), m_transponderMode(StateStandby) { @@ -137,12 +85,7 @@ namespace BlackMisc this->validate(true); } - /*! - * \brief Constructor - * \param name - * \param transponderCode - * \param transponderMode - */ + //! \brief Constructor, code as string CTransponder(const QString &name, QString transponderCode, TransponderMode transponderMode) : CAvionicsBase(name), m_transponderCode(0), m_transponderMode(transponderMode) { @@ -152,12 +95,7 @@ namespace BlackMisc this->validate(true); } - /*! - * \brief Constructor - * \param name - * \param transponderCode - * \param transponderMode - */ + //! \brief Constructor CTransponder(const QString &name, QString transponderCode, QString transponderMode) : CAvionicsBase(name), m_transponderCode(0), m_transponderMode(StateStandby) { @@ -168,9 +106,27 @@ namespace BlackMisc this->validate(true); } - /*! - * \copydoc CValueObject::toQVariant - */ + //! \brief Constructor for validation, used with test cases + CTransponder(bool validate, const QString &name, qint32 transponderCode, TransponderMode transponderMode) : + CAvionicsBase(name), m_transponderCode(transponderCode), m_transponderMode(transponderMode) + { + this->validate(validate); + } + + //! \brief Constructor for validation, used with test cases + CTransponder(bool validate, const QString &name, const QString transponderCode, TransponderMode transponderMode) : + CAvionicsBase(name), m_transponderCode(0), m_transponderMode(transponderMode) + { + bool ok = false; + this->m_transponderCode = transponderCode.toUInt(&ok); + if (!ok) this->m_transponderCode = -1; // will cause assert / exception + this->validate(validate); + } + + //! \copydoc CAvionicsBase::validValues + virtual bool validValues() const override; + + //! \copydoc CValueObject::toQVariant virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); @@ -250,75 +206,12 @@ namespace BlackMisc return !((*this) == other); } - /*! - * Try to get a Transponder unit with given name and code. Returns true in case an object - * has been sucessfully created, otherwise returns a default object. - * \param[out] o_transponder - * \param name - * \param transponderCode - * \param mode - * \return - */ - static bool tryGetTransponder(CTransponder &o_transponder, const QString &name, qint32 transponderCode, TransponderMode mode) - { - o_transponder = CTransponder(false, name, transponderCode, mode); - bool s; - if (!(s = o_transponder.validate(false))) o_transponder = CTransponder(); // reset to default - return s; - } - - /*! - * Try to get a Transponder unit with given name and code. Returns true in case an object - * has been sucessfully created, otherwise returns a default object. - * \param[out] o_transponder - * \param name - * \param transponderCode - * \param mode - * \return - */ - static bool tryGetTransponder(CTransponder &o_transponder, const QString &name, const QString &transponderCode, TransponderMode mode) - { - o_transponder = CTransponder(false, name, transponderCode, mode); - bool s; - if (!(s = o_transponder.validate(false))) o_transponder = CTransponder(); // reset to default - return s; - } - - /*! - * \brief Transponder unit - * \param transponderCode - * \param mode - * \return - */ + //! \brief Transponder unit static CTransponder getStandardTransponder(qint32 transponderCode, TransponderMode mode) { return CTransponder("Transponder", transponderCode, mode); } - /*! - * \brief Try to get Transponder unit - * \param[out] o_transponder - * \param transponderCode - * \param mode - * \return - */ - static bool tryGetStandardTransponder(CTransponder &o_transponder, qint32 transponderCode, TransponderMode mode) - { - return CTransponder::tryGetTransponder(o_transponder, "Transponder", transponderCode, mode); - } - - /*! - * \brief Try to get Transponder unit - * \param[out] o_transponder - * \param transponderCode - * \param mode - * \return - */ - static bool tryGetStandardTransponder(CTransponder &o_transponder, const QString &transponderCode, TransponderMode mode) - { - return CTransponder::tryGetTransponder(o_transponder, "Transponder", transponderCode, mode); - } - //! \copydoc CValueObject::getValueHash() virtual uint getValueHash() const override; @@ -343,7 +236,7 @@ namespace BlackMisc } // namespace } // namespace -BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CTransponder, (o.m_transponderCode)) +BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CTransponder, (o.m_transponderCode, o.m_transponderMode)) Q_DECLARE_METATYPE(BlackMisc::Aviation::CTransponder) #endif // guard diff --git a/src/blackmisc/blackmiscfreefunctions.cpp b/src/blackmisc/blackmiscfreefunctions.cpp index 902f31ae9..3a6b454b3 100644 --- a/src/blackmisc/blackmiscfreefunctions.cpp +++ b/src/blackmisc/blackmiscfreefunctions.cpp @@ -177,7 +177,8 @@ bool BlackMisc::equalQVariants(const QVariant &v1, const QVariant &v2) const CValueObject *cs2 = CValueObject::fromQVariant(v2); if (cs1 && cs2) { - return compare(*cs1, *cs2) == 0; + int c = compare(*cs1, *cs2); + return c == 0; } return false; } diff --git a/tests/blackmisc/testaviation.cpp b/tests/blackmisc/testaviation.cpp index dd3509a20..df5e81fc3 100644 --- a/tests/blackmisc/testaviation.cpp +++ b/tests/blackmisc/testaviation.cpp @@ -69,7 +69,6 @@ namespace BlackMiscTest c1 = c2; QVERIFY2(c1 == c2, "COM system shall be equal"); CFrequency f(100.0, CFrequencyUnit::MHz()); - QVERIFY2(!CComSystem::tryGetComSystem(c1, "no valid unit", f), "Expect not to get COM system"); CNavSystem nav1; QVERIFY2(CNavSystem::tryGetNav1System(nav1, 110.0), "Expect NAV system"); QVERIFY2(!CNavSystem::tryGetNav1System(nav1, 200.0), "Expect no NAV system"); @@ -85,12 +84,16 @@ namespace BlackMiscTest QVERIFY2(t1 == t2, "Transponders shall be equal"); t2.setTransponderMode(CTransponder::ModeC); QVERIFY2(t1 != t2, "Transponders shall not be equal"); - QVERIFY2(!CTransponder::tryGetStandardTransponder(t1, 8888, CTransponder::StateStandby), "No valid transponder"); - QVERIFY2(!CTransponder::tryGetStandardTransponder(t1, 781, CTransponder::StateStandby), "No valid transponder"); - QVERIFY2(!CTransponder::tryGetStandardTransponder(t1, "0781", CTransponder::StateStandby), "No valid transponder"); - QVERIFY2(CTransponder::tryGetStandardTransponder(t1, "7211", CTransponder::StateStandby), "No valid transponder"); - QVERIFY2(!CTransponder::tryGetStandardTransponder(t1, "schnitzel", CTransponder::StateStandby), "No valid transponder"); - + CTransponder tv = CTransponder(false, "transponder", 8888, CTransponder::StateStandby); + QVERIFY2(!tv.validValues(), "No valid transponder"); + tv = CTransponder(false, "transponder", 781, CTransponder::StateStandby); + QVERIFY2(!tv.validValues(), "No valid transponder"); + tv = CTransponder(false, "transponder", "0781", CTransponder::StateStandby); + QVERIFY2(!tv.validValues(), "No valid transponder"); + tv = CTransponder(false, "transponder", "7211", CTransponder::StateStandby); + QVERIFY2(tv.validValues(), "No valid transponder"); + tv = CTransponder(false, "transponder", "schnitzel", CTransponder::StateStandby); + QVERIFY2(!tv.validValues(), "No valid transponder"); } /* diff --git a/tests/blackmisc/testvariantandmap.cpp b/tests/blackmisc/testvariantandmap.cpp index 77d0b5458..315d6ac7e 100644 --- a/tests/blackmisc/testvariantandmap.cpp +++ b/tests/blackmisc/testvariantandmap.cpp @@ -71,13 +71,15 @@ namespace BlackMiscTest CValueMap vmWildcard(true); CValueMap vmNoWildcard(false); CValueMap vm; - vm.addValue(CAtcStation::IndexController, CUser("123456", "Joe Doe")); + + // remark: Shortcoming here, as the callsign will automatically set for user in station + // I have to set this as well, otherwise, not match. + vm.addValue(CAtcStation::IndexController, CUser("123456", "Joe Doe", CCallsign("EDDMTWR"))); // compare QVERIFY2(vmWildcard == station1, "Station should be equal to wildcard"); QVERIFY2(station1 != vmNoWildcard, "Station should not be equal to empty list"); QVERIFY2(station1 == vm, "Controller should match"); - } } //namespace BlackMiscTest