refs #893, Modulator added compareByPropertyIndex

This commit is contained in:
Klaus Basan
2017-03-01 05:34:29 +01:00
committed by Mathew Sutcliffe
parent f8b2e4f23f
commit a68f9db2ec
3 changed files with 42 additions and 21 deletions

View File

@@ -8,14 +8,14 @@
*/ */
#include "blackmisc/aviation/modulator.h" #include "blackmisc/aviation/modulator.h"
#include "blackmisc/aviation/comsystem.h"
#include "blackmisc/aviation/navsystem.h"
#include "blackmisc/aviation/adfsystem.h"
#include "blackmisc/math/mathutils.h" #include "blackmisc/math/mathutils.h"
#include "blackmisc/pq/units.h" #include "blackmisc/pq/units.h"
#include "blackmisc/propertyindex.h" #include "blackmisc/propertyindex.h"
#include "blackmisc/variant.h" #include "blackmisc/variant.h"
#include "blackmisc/aviation/comsystem.h" #include "blackmisc/comparefunctions.h"
#include "blackmisc/aviation/navsystem.h"
#include "blackmisc/aviation/adfsystem.h"
#include <QtGlobal> #include <QtGlobal>
using BlackMisc::PhysicalQuantities::CFrequency; using BlackMisc::PhysicalQuantities::CFrequency;
@@ -155,6 +155,30 @@ namespace BlackMisc
} }
} }
template <class AVIO>
int CModulator<AVIO>::comparePropertyByIndex(const CPropertyIndex &index, const AVIO &compareValue) const
{
if (index.isMyself()) { return this->m_frequencyActive.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.m_frequencyActive); }
const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexActiveFrequency:
return this->m_frequencyActive.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.m_frequencyActive);
case IndexStandbyFrequency:
return this->m_frequencyStandby.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.m_frequencyStandby);
case IndexEnabled:
return Compare::compare(this->isEnabled(), compareValue.isEnabled());
case IndexInputVolume:
return Compare::compare(this->getVolumeInput(), compareValue.getVolumeInput());
case IndexOutputVolume:
return Compare::compare(this->getVolumeOutput(), compareValue.getVolumeOutput());
default:
break;
}
Q_ASSERT_X(false, Q_FUNC_INFO, "Compare failed");
return 0;
}
template <class AVIO> template <class AVIO>
CModulator<AVIO>::CModulator() : CModulator<AVIO>::CModulator() :
m_name("default") {} m_name("default") {}
@@ -265,19 +289,7 @@ namespace BlackMisc
return f; return f;
} }
template <class AVIO> // see here for the reason of the forward instantiations
AVIO const *CModulator<AVIO>::derived() const
{
return static_cast<AVIO const *>(this);
}
template <class AVIO>
AVIO *CModulator<AVIO>::derived()
{
return static_cast<AVIO *>(this);
}
// see here for the reason of thess forward instantiations
// https://isocpp.org/wiki/faq/templates#separate-template-fn-defn-from-decl // https://isocpp.org/wiki/faq/templates#separate-template-fn-defn-from-decl
//! \cond PRIVATE //! \cond PRIVATE
template class BLACKMISC_EXPORT_DEFINE_TEMPLATE CModulator<CComSystem>; template class BLACKMISC_EXPORT_DEFINE_TEMPLATE CModulator<CComSystem>;

View File

@@ -81,6 +81,9 @@ namespace BlackMisc
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const CVariant &variant); void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const CVariant &variant);
//! Compare by property index
int comparePropertyByIndex(const BlackMisc::CPropertyIndex &index, const AVIO &compareValue) const;
//! \copydoc BlackMisc::Mixin::String::toQString //! \copydoc BlackMisc::Mixin::String::toQString
QString convertToQString(bool i18n = false) const; QString convertToQString(bool i18n = false) const;
@@ -142,10 +145,16 @@ namespace BlackMisc
bool m_enabled = true; //!< is enabled, used e.g. for mute etc. bool m_enabled = true; //!< is enabled, used e.g. for mute etc.
//! Easy access to derived class (CRTP template parameter) //! Easy access to derived class (CRTP template parameter)
AVIO const *derived() const; AVIO const *derived() const
{
return static_cast<AVIO const *>(this);
}
//! Easy access to derived class (CRTP template parameter) //! Easy access to derived class (CRTP template parameter)
AVIO *derived(); AVIO *derived()
{
return static_cast<AVIO *>(this);
}
BLACK_METACLASS( BLACK_METACLASS(
CModulator, CModulator,

View File

@@ -420,9 +420,9 @@ namespace BlackMisc
case IndexRelativeDistance: case IndexRelativeDistance:
return this->m_relativeDistance.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getRelativeDistance()); return this->m_relativeDistance.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getRelativeDistance());
case IndexCom1System: case IndexCom1System:
return m_com1system.getFrequencyActive().comparePropertyByIndex(CPropertyIndex(), compareValue.getCom1System().getFrequencyActive()); return this->m_com1system.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getCom1System());
case IndexCom2System: case IndexCom2System:
return m_com2system.getFrequencyActive().comparePropertyByIndex(CPropertyIndex(), compareValue.getCom2System().getFrequencyActive()); return this->m_com2system.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getCom2System());
case IndexTransponder: case IndexTransponder:
return Compare::compare(m_transponder.getTransponderCode(), compareValue.getTransponder().getTransponderCode()); return Compare::compare(m_transponder.getTransponderCode(), compareValue.getTransponder().getTransponderCode());
case IndexLivery: case IndexLivery: