mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +08:00
Ref T275, general improvement in value object added comparePropertyByIndex
This commit is contained in:
@@ -185,6 +185,18 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CCoordinateGeodetic::comparePropertyByIndex(const CPropertyIndex &index, const CCoordinateGeodetic &compareValue) const
|
||||||
|
{
|
||||||
|
if (ICoordinateGeodetic::canHandleIndex(index))
|
||||||
|
{
|
||||||
|
return ICoordinateGeodetic::comparePropertyByIndex(index, compareValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return CValueObject::comparePropertyByIndex(index, compareValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CCoordinateGeodetic::CCoordinateGeodetic(const std::array<double, 3> &normalVector)
|
CCoordinateGeodetic::CCoordinateGeodetic(const std::array<double, 3> &normalVector)
|
||||||
{
|
{
|
||||||
this->setNormalVector(normalVector);
|
this->setNormalVector(normalVector);
|
||||||
|
|||||||
@@ -244,6 +244,9 @@ namespace BlackMisc
|
|||||||
//! \copydoc Mixin::Index::setPropertyByIndex
|
//! \copydoc Mixin::Index::setPropertyByIndex
|
||||||
void setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant);
|
void setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant);
|
||||||
|
|
||||||
|
//! \copydoc Mixin::Index::setPropertyByIndex
|
||||||
|
int comparePropertyByIndex(const CPropertyIndex &index, const CCoordinateGeodetic &compareValue) const;
|
||||||
|
|
||||||
//! Switch unit of height
|
//! Switch unit of height
|
||||||
CCoordinateGeodetic &switchUnit(const PhysicalQuantities::CLengthUnit &unit);
|
CCoordinateGeodetic &switchUnit(const PhysicalQuantities::CLengthUnit &unit);
|
||||||
|
|
||||||
|
|||||||
@@ -37,13 +37,13 @@ namespace BlackMisc
|
|||||||
|
|
||||||
bool CPropertyIndexVariantMap::matchesVariant(const CVariant &variant) const
|
bool CPropertyIndexVariantMap::matchesVariant(const CVariant &variant) const
|
||||||
{
|
{
|
||||||
if (this->isEmpty()) return this->isWildcard();
|
if (this->isEmpty()) { return this->isWildcard(); }
|
||||||
const auto &map = this->map();
|
const auto &map = this->map();
|
||||||
for (auto it = map.begin(); it != map.end(); ++it)
|
for (auto it = map.begin(); it != map.end(); ++it)
|
||||||
{
|
{
|
||||||
// QVariant cannot be compared directly
|
// QVariant cannot be compared directly
|
||||||
CVariant p = variant.propertyByIndex(it.key()); // from value object
|
const CVariant p = variant.propertyByIndex(it.key()); // from value object
|
||||||
CVariant v = it.value(); // from map
|
const CVariant v = it.value(); // from map
|
||||||
if (p != v) return false;
|
if (p != v) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -51,14 +51,14 @@ namespace BlackMisc
|
|||||||
|
|
||||||
QString CPropertyIndexVariantMap::convertToQString(bool i18n) const
|
QString CPropertyIndexVariantMap::convertToQString(bool i18n) const
|
||||||
{
|
{
|
||||||
if (this->isEmpty()) return QString("{wildcard: %1}").arg(this->m_wildcard ? "true" : "false");
|
if (this->isEmpty()) return QString("{wildcard: %1}").arg(m_wildcard ? "true" : "false");
|
||||||
QString s;
|
QString s;
|
||||||
for (const CPropertyIndex &index : makeKeysRange(this->m_values))
|
for (const CPropertyIndex &index : makeKeysRange(m_values))
|
||||||
{
|
{
|
||||||
CVariant v = this->m_values.value(index);
|
CVariant v = m_values.value(index);
|
||||||
|
|
||||||
s.isEmpty() ?
|
s.isEmpty() ?
|
||||||
s.append("{wildcard: ").append(this->m_wildcard ? "true" : "false").append(" ") :
|
s.append("{wildcard: ").append(m_wildcard ? "true" : "false").append(" ") :
|
||||||
s.append(", ");
|
s.append(", ");
|
||||||
|
|
||||||
s.append('{').append(index.toQString(i18n)).append(": ");
|
s.append('{').append(index.toQString(i18n)).append(": ");
|
||||||
@@ -73,8 +73,8 @@ namespace BlackMisc
|
|||||||
|
|
||||||
void CPropertyIndexVariantMap::marshallToDbus(QDBusArgument &argument) const
|
void CPropertyIndexVariantMap::marshallToDbus(QDBusArgument &argument) const
|
||||||
{
|
{
|
||||||
argument << this->m_values.keys();
|
argument << m_values.keys();
|
||||||
argument << this->m_values.values();
|
argument << m_values.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPropertyIndexVariantMap::unmarshallFromDbus(const QDBusArgument &argument)
|
void CPropertyIndexVariantMap::unmarshallFromDbus(const QDBusArgument &argument)
|
||||||
@@ -90,12 +90,12 @@ namespace BlackMisc
|
|||||||
newMap.insert(indexes[i], values[i]);
|
newMap.insert(indexes[i], values[i]);
|
||||||
}
|
}
|
||||||
// replace values in one step
|
// replace values in one step
|
||||||
this->m_values.swap(newMap);
|
m_values.swap(newMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPropertyIndexVariantMap::addValue(const CPropertyIndex &index, const CVariant &value)
|
void CPropertyIndexVariantMap::addValue(const CPropertyIndex &index, const CVariant &value)
|
||||||
{
|
{
|
||||||
this->m_values.insert(index, value);
|
m_values.insert(index, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPropertyIndexVariantMap::addValue(const CPropertyIndex &index, const char *str)
|
void CPropertyIndexVariantMap::addValue(const CPropertyIndex &index, const char *str)
|
||||||
@@ -110,19 +110,19 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
CPropertyIndex newPi(pi);
|
CPropertyIndex newPi(pi);
|
||||||
newPi.prepend(index);
|
newPi.prepend(index);
|
||||||
newMap.insert(newPi, this->m_values[pi]);
|
newMap.insert(newPi, m_values[pi]);
|
||||||
}
|
}
|
||||||
this->m_values = newMap;
|
m_values = newMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
CPropertyIndexList CPropertyIndexVariantMap::indexes() const
|
CPropertyIndexList CPropertyIndexVariantMap::indexes() const
|
||||||
{
|
{
|
||||||
return CSequence<CPropertyIndex>(this->m_values.keys());
|
return CSequence<CPropertyIndex>(m_values.keys());
|
||||||
}
|
}
|
||||||
|
|
||||||
int CPropertyIndexVariantMap::size() const
|
int CPropertyIndexVariantMap::size() const
|
||||||
{
|
{
|
||||||
return this->m_values.size();
|
return m_values.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint CPropertyIndexVariantMap::getValueHash() const
|
uint CPropertyIndexVariantMap::getValueHash() const
|
||||||
|
|||||||
@@ -58,17 +58,20 @@ namespace BlackMisc
|
|||||||
|
|
||||||
//! Update by variant map
|
//! Update by variant map
|
||||||
//! \return number of values changed, with skipEqualValues equal values will not be changed
|
//! \return number of values changed, with skipEqualValues equal values will not be changed
|
||||||
CPropertyIndexList apply(const BlackMisc::CPropertyIndexVariantMap &indexMap, bool skipEqualValues = false);
|
CPropertyIndexList apply(const CPropertyIndexVariantMap &indexMap, bool skipEqualValues = false);
|
||||||
|
|
||||||
//! Set property by index
|
//! Set property by index
|
||||||
void setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant);
|
void setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant);
|
||||||
|
|
||||||
//! Property by index
|
//! Property by index
|
||||||
CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
CVariant propertyByIndex(const CPropertyIndex &index) const;
|
||||||
|
|
||||||
//! Property by index as String
|
//! Property by index as String
|
||||||
QString propertyByIndexAsString(const CPropertyIndex &index, bool i18n = false) const;
|
QString propertyByIndexAsString(const CPropertyIndex &index, bool i18n = false) const;
|
||||||
|
|
||||||
|
//! Compare for index
|
||||||
|
int comparePropertyByIndex(const CPropertyIndex &index, const Derived &compareValue) const;
|
||||||
|
|
||||||
//! Is given variant equal to value of property index?
|
//! Is given variant equal to value of property index?
|
||||||
bool equalsPropertyByIndex(const CVariant &compareValue, const CPropertyIndex &index) const;
|
bool equalsPropertyByIndex(const CVariant &compareValue, const CPropertyIndex &index) const;
|
||||||
|
|
||||||
@@ -106,12 +109,15 @@ namespace BlackMisc
|
|||||||
* When a derived class and a base class both inherit from Mixin::Index,
|
* When a derived class and a base class both inherit from Mixin::Index,
|
||||||
* the derived class uses this macro to disambiguate the inherited members.
|
* the derived class uses this macro to disambiguate the inherited members.
|
||||||
*/
|
*/
|
||||||
|
// *INDENT-OFF*
|
||||||
# define BLACKMISC_DECLARE_USING_MIXIN_INDEX(DERIVED) \
|
# define BLACKMISC_DECLARE_USING_MIXIN_INDEX(DERIVED) \
|
||||||
using ::BlackMisc::Mixin::Index<DERIVED>::apply; \
|
using ::BlackMisc::Mixin::Index<DERIVED>::apply; \
|
||||||
using ::BlackMisc::Mixin::Index<DERIVED>::setPropertyByIndex; \
|
using ::BlackMisc::Mixin::Index<DERIVED>::setPropertyByIndex; \
|
||||||
using ::BlackMisc::Mixin::Index<DERIVED>::propertyByIndex; \
|
using ::BlackMisc::Mixin::Index<DERIVED>::propertyByIndex; \
|
||||||
using ::BlackMisc::Mixin::Index<DERIVED>::propertyByIndexAsString; \
|
using ::BlackMisc::Mixin::Index<DERIVED>::propertyByIndexAsString; \
|
||||||
|
using ::BlackMisc::Mixin::Index<DERIVED>::comparePropertyByIndex; \
|
||||||
using ::BlackMisc::Mixin::Index<DERIVED>::equalsPropertyByIndex;
|
using ::BlackMisc::Mixin::Index<DERIVED>::equalsPropertyByIndex;
|
||||||
|
// *INDENT-ON*
|
||||||
|
|
||||||
} // Mixin
|
} // Mixin
|
||||||
|
|
||||||
@@ -142,37 +148,37 @@ namespace BlackMisc
|
|||||||
void addValue(const CPropertyIndex &index, const char *str);
|
void addValue(const CPropertyIndex &index, const char *str);
|
||||||
|
|
||||||
//! Add a value as non CVariant
|
//! Add a value as non CVariant
|
||||||
template<class T> void addValue(const CPropertyIndex &index, const T &value) { this->m_values.insert(index, CVariant::fromValue(value)); }
|
template<class T> void addValue(const CPropertyIndex &index, const T &value) { m_values.insert(index, CVariant::fromValue(value)); }
|
||||||
|
|
||||||
//! Prepend index to all property indexes
|
//! Prepend index to all property indexes
|
||||||
void prependIndex(int index);
|
void prependIndex(int index);
|
||||||
|
|
||||||
//! Is empty?
|
//! Is empty?
|
||||||
bool isEmpty() const { return this->m_values.isEmpty(); }
|
bool isEmpty() const { return m_values.isEmpty(); }
|
||||||
|
|
||||||
//! Value
|
//! Value
|
||||||
CVariant value(const CPropertyIndex &index) const { return this->m_values.value(index); }
|
CVariant value(const CPropertyIndex &index) const { return m_values.value(index); }
|
||||||
|
|
||||||
//! Set value
|
//! Set value
|
||||||
void value(const CPropertyIndex &index, const CVariant &value) { this->m_values.value(index, value); }
|
void value(const CPropertyIndex &index, const CVariant &value) { m_values.value(index, value); }
|
||||||
|
|
||||||
//! Indexes
|
//! Indexes
|
||||||
CPropertyIndexList indexes() const;
|
CPropertyIndexList indexes() const;
|
||||||
|
|
||||||
//! Contains index?
|
//! Contains index?
|
||||||
bool contains(const CPropertyIndex &index) const { return this->m_values.contains(index); }
|
bool contains(const CPropertyIndex &index) const { return m_values.contains(index); }
|
||||||
|
|
||||||
//! values
|
//! values
|
||||||
QList<CVariant> values() const { return this->m_values.values(); }
|
QList<CVariant> values() const { return m_values.values(); }
|
||||||
|
|
||||||
//! Wildcard, only relevant when used in search
|
//! Wildcard, only relevant when used in search
|
||||||
bool isWildcard() const { return this->m_wildcard; }
|
bool isWildcard() const { return m_wildcard; }
|
||||||
|
|
||||||
//! Wildcard, only relevant when used in search
|
//! Wildcard, only relevant when used in search
|
||||||
void setWildcard(bool wildcard) { this->m_wildcard = wildcard; }
|
void setWildcard(bool wildcard) { m_wildcard = wildcard; }
|
||||||
|
|
||||||
//! clear
|
//! clear
|
||||||
void clear() { this->m_values.clear(); }
|
void clear() { m_values.clear(); }
|
||||||
|
|
||||||
//! Number of elements
|
//! Number of elements
|
||||||
int size() const;
|
int size() const;
|
||||||
@@ -190,7 +196,7 @@ namespace BlackMisc
|
|||||||
template <typename T> bool matches(const T &value) const { return matchesVariant(CVariant::from(value)); }
|
template <typename T> bool matches(const T &value) const { return matchesVariant(CVariant::from(value)); }
|
||||||
|
|
||||||
//! Map
|
//! Map
|
||||||
const QMap<CPropertyIndex, CVariant> &map() const { return this->m_values; }
|
const QMap<CPropertyIndex, CVariant> &map() const { return m_values; }
|
||||||
|
|
||||||
//! Hash value
|
//! Hash value
|
||||||
uint getValueHash() const;
|
uint getValueHash() const;
|
||||||
@@ -211,7 +217,6 @@ namespace BlackMisc
|
|||||||
|
|
||||||
//! \copydoc BlackMisc::Mixin::DBusByMetaClass::unmarshallFromDbus
|
//! \copydoc BlackMisc::Mixin::DBusByMetaClass::unmarshallFromDbus
|
||||||
void unmarshallFromDbus(const QDBusArgument &argument);
|
void unmarshallFromDbus(const QDBusArgument &argument);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace Mixin
|
namespace Mixin
|
||||||
@@ -229,7 +234,7 @@ namespace BlackMisc
|
|||||||
const CPropertyIndex index = it.key();
|
const CPropertyIndex index = it.key();
|
||||||
if (skipEqualValues)
|
if (skipEqualValues)
|
||||||
{
|
{
|
||||||
bool equal = derived()->equalsPropertyByIndex(value, index);
|
const bool equal = derived()->equalsPropertyByIndex(value, index);
|
||||||
if (equal) { continue; }
|
if (equal) { continue; }
|
||||||
}
|
}
|
||||||
derived()->setPropertyByIndex(index, value);
|
derived()->setPropertyByIndex(index, value);
|
||||||
@@ -237,6 +242,7 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Derived>
|
template <class Derived>
|
||||||
void Index<Derived>::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
void Index<Derived>::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
||||||
{
|
{
|
||||||
@@ -249,13 +255,11 @@ namespace BlackMisc
|
|||||||
baseSetPropertyByIndex(static_cast<TIndexBaseOfT<Derived> *>(derived()), variant, index);
|
baseSetPropertyByIndex(static_cast<TIndexBaseOfT<Derived> *>(derived()), variant, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Derived>
|
template <class Derived>
|
||||||
CVariant Index<Derived>::propertyByIndex(const CPropertyIndex &index) const
|
CVariant Index<Derived>::propertyByIndex(const CPropertyIndex &index) const
|
||||||
{
|
{
|
||||||
if (index.isMyself())
|
if (index.isMyself()) { return myself<Derived>(); }
|
||||||
{
|
|
||||||
return myself<Derived>();
|
|
||||||
}
|
|
||||||
const auto i = index.frontCasted<ColumnIndex>();
|
const auto i = index.frontCasted<ColumnIndex>();
|
||||||
switch (i)
|
switch (i)
|
||||||
{
|
{
|
||||||
@@ -265,16 +269,34 @@ namespace BlackMisc
|
|||||||
default: return basePropertyByIndex(static_cast<const TIndexBaseOfT<Derived> *>(derived()), index);
|
default: return basePropertyByIndex(static_cast<const TIndexBaseOfT<Derived> *>(derived()), index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Derived>
|
template <class Derived>
|
||||||
QString Index<Derived>::propertyByIndexAsString(const CPropertyIndex &index, bool i18n) const
|
QString Index<Derived>::propertyByIndexAsString(const CPropertyIndex &index, bool i18n) const
|
||||||
{
|
{
|
||||||
return derived()->propertyByIndex(index).toQString(i18n);
|
return derived()->propertyByIndex(index).toQString(i18n);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Derived>
|
template <class Derived>
|
||||||
bool Index<Derived>::equalsPropertyByIndex(const CVariant &compareValue, const CPropertyIndex &index) const
|
bool Index<Derived>::equalsPropertyByIndex(const CVariant &compareValue, const CPropertyIndex &index) const
|
||||||
{
|
{
|
||||||
return derived()->propertyByIndex(index) == compareValue;
|
return derived()->propertyByIndex(index) == compareValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class Derived>
|
||||||
|
int Index<Derived>::comparePropertyByIndex(const CPropertyIndex &index, const Derived &compareValue) const
|
||||||
|
{
|
||||||
|
if (this == &compareValue) { return 0; }
|
||||||
|
const auto i = index.frontCasted<ColumnIndex>();
|
||||||
|
switch (i)
|
||||||
|
{
|
||||||
|
case IndexIcon:
|
||||||
|
case IndexPixmap:
|
||||||
|
case IndexString:
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return derived()->toQString().compare(compareValue.toQString());
|
||||||
|
}
|
||||||
} // Mixin
|
} // Mixin
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
@@ -282,8 +304,7 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
return m_map.matches(value);
|
return m_map.matches(value);
|
||||||
}
|
}
|
||||||
|
} // ns
|
||||||
}
|
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(BlackMisc::CPropertyIndexVariantMap)
|
Q_DECLARE_METATYPE(BlackMisc::CPropertyIndexVariantMap)
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,6 @@
|
|||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Default base class for CValueObject.
|
* Default base class for CValueObject.
|
||||||
*/
|
*/
|
||||||
@@ -113,6 +112,9 @@ namespace BlackMisc
|
|||||||
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
||||||
using Mixin::Index<Derived>::propertyByIndex;
|
using Mixin::Index<Derived>::propertyByIndex;
|
||||||
|
|
||||||
|
//! \copydoc BlackMisc::Mixin::Index::comparePropertyByIndex
|
||||||
|
using Mixin::Index<Derived>::comparePropertyByIndex;
|
||||||
|
|
||||||
//! \copydoc BlackMisc::Mixin::Index::propertyByIndexAsString
|
//! \copydoc BlackMisc::Mixin::Index::propertyByIndexAsString
|
||||||
using Mixin::Index<Derived>::propertyByIndexAsString;
|
using Mixin::Index<Derived>::propertyByIndexAsString;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user