mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 11:05:33 +08:00
* changed CValueObject apply * created CIndexPropertyList * renamed CIndexVariantMap to CPropertyIndexVariantMap
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
#include "blackmisc/avallclasses.h"
|
||||
#include "blackmisc/geoallclasses.h"
|
||||
#include "blackmisc/settingsblackmiscclasses.h"
|
||||
#include "blackmisc/indexvariantmap.h"
|
||||
#include "blackmisc/propertyindexallclasses.h"
|
||||
#include "blackmisc/networkallclasses.h"
|
||||
#include "blackmisc/statusmessagelist.h"
|
||||
#include "blackmisc/statusmessage.h"
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
#include "audioallclasses.h"
|
||||
#include "hwallclasses.h"
|
||||
#include "settingsblackmiscclasses.h"
|
||||
#include "propertyindex.h"
|
||||
#include "indexvariantmap.h"
|
||||
#include "propertyindexlist.h"
|
||||
#include "propertyindexvariantmap.h"
|
||||
#include "namevariantpairlist.h"
|
||||
#include "variant.h"
|
||||
#include "statusmessagelist.h"
|
||||
@@ -27,7 +27,6 @@
|
||||
#include <QProcessEnvironment>
|
||||
#include <QSysInfo>
|
||||
|
||||
|
||||
/*
|
||||
* Metadata for PQs
|
||||
*/
|
||||
@@ -165,7 +164,8 @@ void BlackMisc::registerMetadata()
|
||||
CPropertyIndex::registerMetadata();
|
||||
CVariant::registerMetadata();
|
||||
CPropertyIndex::registerMetadata();
|
||||
CIndexVariantMap::registerMetadata();
|
||||
CPropertyIndexList::registerMetadata();
|
||||
CPropertyIndexVariantMap::registerMetadata();
|
||||
CNameVariantPair::registerMetadata();
|
||||
CNameVariantPairList::registerMetadata();
|
||||
CStatusMessage::registerMetadata();
|
||||
@@ -204,21 +204,18 @@ void BlackMisc::initResources()
|
||||
*/
|
||||
bool BlackMisc::equalQVariants(const QVariant &v1, const QVariant &v2)
|
||||
{
|
||||
// prephase, shortcuts
|
||||
if (v1 == v2) return true; // compares on primitives or on address
|
||||
// Compares this QVariant with v and returns true if they are equal; otherwise returns false.
|
||||
// In the case of custom types, their equalness operators are not called. Instead the values' addresses are compared.
|
||||
if (v1 == v2) return true;
|
||||
|
||||
// shortcuts
|
||||
if (!v1.isValid() || !v2.isValid()) return false;
|
||||
if (v1.type() != v2.type()) return false;
|
||||
if (v1.userType() != v2.userType()) return false;
|
||||
|
||||
// I have same types now
|
||||
const CValueObject *cs1 = CValueObject::fromQVariant(v1);
|
||||
const CValueObject *cs2 = CValueObject::fromQVariant(v2);
|
||||
if (cs1 && cs2)
|
||||
{
|
||||
int c = compare(*cs1, *cs2);
|
||||
return c == 0;
|
||||
}
|
||||
return false;
|
||||
int c = compareQVariants(v1, v2);
|
||||
return c == 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
#include "valueobject.h"
|
||||
#include "range.h"
|
||||
#include "indexvariantmap.h"
|
||||
#include "propertyindexvariantmap.h"
|
||||
#include "blackmiscfreefunctions.h"
|
||||
#include "predicates.h"
|
||||
#include "json.h"
|
||||
|
||||
@@ -143,7 +143,7 @@ namespace BlackMisc
|
||||
/*
|
||||
* Capabilities
|
||||
*/
|
||||
void CClient::setCapabilities(const CIndexVariantMap &capabilities)
|
||||
void CClient::setCapabilities(const CPropertyIndexVariantMap &capabilities)
|
||||
{
|
||||
this->m_capabilities = capabilities;
|
||||
}
|
||||
@@ -220,7 +220,7 @@ namespace BlackMisc
|
||||
switch (i)
|
||||
{
|
||||
case IndexCapabilities:
|
||||
this->m_capabilities = variant.value<CIndexVariantMap>();
|
||||
this->m_capabilities = variant.value<CPropertyIndexVariantMap>();
|
||||
break;
|
||||
case IndexModel:
|
||||
this->m_model.setPropertyByIndex(variant, index.copyFrontRemoved());;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include "nwaircraftmodel.h"
|
||||
#include "nwvoicecapabilities.h"
|
||||
#include "propertyindex.h"
|
||||
#include "indexvariantmap.h"
|
||||
#include "propertyindexvariantmap.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -86,13 +86,13 @@ namespace BlackMisc
|
||||
const BlackMisc::Aviation::CCallsign &getCallsign() const { return this->m_user.getCallsign(); }
|
||||
|
||||
//! Get capabilities
|
||||
CIndexVariantMap getCapabilities() const { return this->m_capabilities; }
|
||||
CPropertyIndexVariantMap getCapabilities() const { return this->m_capabilities; }
|
||||
|
||||
//! Set capability
|
||||
void setCapability(bool hasCapability, Capabilities capability);
|
||||
|
||||
//! Set capabilities
|
||||
void setCapabilities(const CIndexVariantMap &capabilities);
|
||||
void setCapabilities(const CPropertyIndexVariantMap &capabilities);
|
||||
|
||||
//! Get capabilities
|
||||
QString getCapabilitiesAsString() const;
|
||||
@@ -168,7 +168,7 @@ namespace BlackMisc
|
||||
BLACK_ENABLE_TUPLE_CONVERSION(CClient)
|
||||
CUser m_user;
|
||||
CAircraftModel m_model;
|
||||
CIndexVariantMap m_capabilities;
|
||||
CPropertyIndexVariantMap m_capabilities;
|
||||
QString m_server;
|
||||
CVoiceCapabilities m_voiceCapabilities;
|
||||
|
||||
|
||||
17
src/blackmisc/propertyindexallclasses.h
Normal file
17
src/blackmisc/propertyindexallclasses.h
Normal file
@@ -0,0 +1,17 @@
|
||||
/* Copyright (C) 2013
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef BLACKMISC_PROPERTYINDEXALLCLASSES_H
|
||||
#define BLACKMISC_PROPERTYINDEXALLCLASSES_H
|
||||
|
||||
#include "blackmisc/propertyindexlist.h"
|
||||
#include "blackmisc/propertyindexvariantmap.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
|
||||
#endif // guard
|
||||
39
src/blackmisc/propertyindexlist.cpp
Normal file
39
src/blackmisc/propertyindexlist.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
/* Copyright (C) 2013
|
||||
* 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 "propertyindexlist.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
/*
|
||||
* Default constructor
|
||||
*/
|
||||
CPropertyIndexList::CPropertyIndexList() { }
|
||||
|
||||
/*
|
||||
* Construct from base class object
|
||||
*/
|
||||
CPropertyIndexList::CPropertyIndexList(const CSequence<CPropertyIndex> &other) :
|
||||
CSequence<CPropertyIndex>(other)
|
||||
{ }
|
||||
|
||||
/*
|
||||
* Register metadata
|
||||
*/
|
||||
void CPropertyIndexList::registerMetadata()
|
||||
{
|
||||
qRegisterMetaType<BlackMisc::CSequence<CPropertyIndex>>();
|
||||
qDBusRegisterMetaType<BlackMisc::CSequence<CPropertyIndex>>();
|
||||
qRegisterMetaType<BlackMisc::CCollection<CPropertyIndex>>();
|
||||
qDBusRegisterMetaType<BlackMisc::CCollection<CPropertyIndex>>();
|
||||
qRegisterMetaType<CPropertyIndexList>();
|
||||
qDBusRegisterMetaType<CPropertyIndexList>();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
50
src/blackmisc/propertyindexlist.h
Normal file
50
src/blackmisc/propertyindexlist.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/* Copyright (C) 2013
|
||||
* 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_PROPERTYINDEXLIST_H
|
||||
#define BLACKMISC_PROPERTYINDEXLIST_H
|
||||
|
||||
#include "propertyindex.h"
|
||||
#include "collection.h"
|
||||
#include "sequence.h"
|
||||
#include <QList>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
/*!
|
||||
* Value object encapsulating a list of property indexes.
|
||||
*/
|
||||
class CPropertyIndexList : public CSequence<CPropertyIndex>
|
||||
{
|
||||
public:
|
||||
//! Default constructor.
|
||||
CPropertyIndexList();
|
||||
|
||||
//! Construct from a base class object.
|
||||
CPropertyIndexList(const CSequence<CPropertyIndex> &other);
|
||||
|
||||
//! \copydoc CValueObject::toQVariant
|
||||
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); }
|
||||
|
||||
//! \copydoc CValueObject::convertFromQVariant
|
||||
virtual void convertFromQVariant(const QVariant &variant) override { BlackMisc::setFromQVariant(this, variant); }
|
||||
|
||||
//! Register metadata
|
||||
static void registerMetadata();
|
||||
};
|
||||
|
||||
} //namespace
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::CPropertyIndexList)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::CPropertyIndex>)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::CPropertyIndex>)
|
||||
|
||||
#endif //guard
|
||||
@@ -7,21 +7,21 @@
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "indexvariantmap.h"
|
||||
#include "propertyindexvariantmap.h"
|
||||
#include "propertyindexlist.h"
|
||||
#include "blackmiscfreefunctions.h"
|
||||
#include "avaltitude.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
CIndexVariantMap::CIndexVariantMap(bool wildcard) : m_wildcard(wildcard) {}
|
||||
CPropertyIndexVariantMap::CPropertyIndexVariantMap(bool wildcard) : m_wildcard(wildcard) {}
|
||||
|
||||
/*
|
||||
* Constructor single value
|
||||
*/
|
||||
CIndexVariantMap::CIndexVariantMap(const CPropertyIndex &index, const QVariant &value)
|
||||
CPropertyIndexVariantMap::CPropertyIndexVariantMap(const CPropertyIndex &index, const QVariant &value)
|
||||
{
|
||||
this->addValue(index, value);
|
||||
}
|
||||
@@ -29,7 +29,7 @@ namespace BlackMisc
|
||||
/*
|
||||
* ==
|
||||
*/
|
||||
bool CIndexVariantMap::operator ==(const CIndexVariantMap &other) const
|
||||
bool CPropertyIndexVariantMap::operator ==(const CPropertyIndexVariantMap &other) const
|
||||
{
|
||||
return this->m_wildcard == other.m_wildcard && this->m_values == other.m_values;
|
||||
}
|
||||
@@ -37,7 +37,7 @@ namespace BlackMisc
|
||||
/*
|
||||
* !=
|
||||
*/
|
||||
bool CIndexVariantMap::operator !=(const CIndexVariantMap &other) const
|
||||
bool CPropertyIndexVariantMap::operator !=(const CPropertyIndexVariantMap &other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
@@ -45,7 +45,7 @@ namespace BlackMisc
|
||||
/*
|
||||
* Convert to string
|
||||
*/
|
||||
QString CIndexVariantMap::convertToQString(bool i18n) const
|
||||
QString CPropertyIndexVariantMap::convertToQString(bool i18n) const
|
||||
{
|
||||
if (this->isEmpty()) return QString("{wildcard: %1}").arg(this->m_wildcard ? "true" : "false");
|
||||
QString s;
|
||||
@@ -70,24 +70,24 @@ namespace BlackMisc
|
||||
/*
|
||||
* metaTypeId
|
||||
*/
|
||||
int CIndexVariantMap::getMetaTypeId() const
|
||||
int CPropertyIndexVariantMap::getMetaTypeId() const
|
||||
{
|
||||
return qMetaTypeId<CIndexVariantMap>();
|
||||
return qMetaTypeId<CPropertyIndexVariantMap>();
|
||||
}
|
||||
|
||||
/*
|
||||
* is a
|
||||
*/
|
||||
bool CIndexVariantMap::isA(int metaTypeId) const
|
||||
bool CPropertyIndexVariantMap::isA(int metaTypeId) const
|
||||
{
|
||||
if (metaTypeId == qMetaTypeId<CIndexVariantMap>()) { return true; }
|
||||
if (metaTypeId == qMetaTypeId<CPropertyIndexVariantMap>()) { return true; }
|
||||
return this->CValueObject::isA(metaTypeId);
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare
|
||||
*/
|
||||
int CIndexVariantMap::compareImpl(const CValueObject &/*otherBase*/) const
|
||||
int CPropertyIndexVariantMap::compareImpl(const CValueObject &/*otherBase*/) const
|
||||
{
|
||||
qFatal("not implemented");
|
||||
return 0;
|
||||
@@ -96,7 +96,7 @@ namespace BlackMisc
|
||||
/*
|
||||
* Marshall to DBus
|
||||
*/
|
||||
void CIndexVariantMap::marshallToDbus(QDBusArgument &argument) const
|
||||
void CPropertyIndexVariantMap::marshallToDbus(QDBusArgument &argument) const
|
||||
{
|
||||
argument << this->m_values.keys();
|
||||
argument << this->m_values.values();
|
||||
@@ -105,7 +105,7 @@ namespace BlackMisc
|
||||
/*
|
||||
* Unmarshall from DBus
|
||||
*/
|
||||
void CIndexVariantMap::unmarshallFromDbus(const QDBusArgument &argument)
|
||||
void CPropertyIndexVariantMap::unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
QList<CPropertyIndex> indexes;
|
||||
QList<CVariant> values;
|
||||
@@ -124,7 +124,7 @@ namespace BlackMisc
|
||||
/*
|
||||
* Add value
|
||||
*/
|
||||
void CIndexVariantMap::addValue(const CPropertyIndex &index, const QVariant &value)
|
||||
void CPropertyIndexVariantMap::addValue(const CPropertyIndex &index, const QVariant &value)
|
||||
{
|
||||
this->m_values.insert(index, value);
|
||||
}
|
||||
@@ -132,24 +132,32 @@ namespace BlackMisc
|
||||
/*
|
||||
* Add string by literal
|
||||
*/
|
||||
void CIndexVariantMap::addValue(const CPropertyIndex &index, const char *str)
|
||||
void CPropertyIndexVariantMap::addValue(const CPropertyIndex &index, const char *str)
|
||||
{
|
||||
this->addValue(index, QString(str));
|
||||
}
|
||||
|
||||
/*
|
||||
* Indexes
|
||||
*/
|
||||
CPropertyIndexList CPropertyIndexVariantMap::indexes() const
|
||||
{
|
||||
return CPropertyIndexList::fromImpl(this->m_values.keys());
|
||||
}
|
||||
|
||||
/*
|
||||
* Register metadata
|
||||
*/
|
||||
void CIndexVariantMap::registerMetadata()
|
||||
void CPropertyIndexVariantMap::registerMetadata()
|
||||
{
|
||||
qRegisterMetaType<CIndexVariantMap>();
|
||||
qDBusRegisterMetaType<CIndexVariantMap>();
|
||||
qRegisterMetaType<CPropertyIndexVariantMap>();
|
||||
qDBusRegisterMetaType<CPropertyIndexVariantMap>();
|
||||
}
|
||||
|
||||
/*
|
||||
* Hash
|
||||
*/
|
||||
uint CIndexVariantMap::getValueHash() const
|
||||
uint CPropertyIndexVariantMap::getValueHash() const
|
||||
{
|
||||
// there is no hash for map, so I use this workaround here
|
||||
const QString s = this->toQString(false);
|
||||
@@ -10,24 +10,29 @@
|
||||
//! \file
|
||||
|
||||
#include "variant.h"
|
||||
#include "propertyindex.h"
|
||||
#include "valueobject.h"
|
||||
#include "propertyindex.h"
|
||||
|
||||
// a) "propertyindex.h" needed for QMap below, despite forward declaration
|
||||
// b) "propertyindexlist.h" here causes circular dependencies
|
||||
|
||||
#include <QVariantMap>
|
||||
#include <QDBusArgument>
|
||||
|
||||
#ifndef BLACKMISC_INDEXVARIANTMAP_H
|
||||
#define BLACKMISC_INDEXVARIANTMAP_H
|
||||
#ifndef BLACKMISC_PROPERTYINDEXVARIANTMAP_H
|
||||
#define BLACKMISC_PROPERTYINDEXVARIANTMAP_H
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
// Forward declaration
|
||||
// forward declaration
|
||||
class CPropertyIndex;
|
||||
class CPropertyIndexList;
|
||||
|
||||
/*!
|
||||
* Specialized value object compliant map for variants,
|
||||
* based on Column indexes
|
||||
* based on indexes
|
||||
*/
|
||||
class CIndexVariantMap : public CValueObject
|
||||
class CPropertyIndexVariantMap : public CValueObject
|
||||
{
|
||||
|
||||
public:
|
||||
@@ -36,19 +41,19 @@ namespace BlackMisc
|
||||
* Constructor
|
||||
* \param wildcard when used in search, for setting values irrelevant
|
||||
*/
|
||||
CIndexVariantMap(bool wildcard = false);
|
||||
CPropertyIndexVariantMap(bool wildcard = false);
|
||||
|
||||
//! Single value constructor
|
||||
CIndexVariantMap(const CPropertyIndex &index, const QVariant &value);
|
||||
CPropertyIndexVariantMap(const CPropertyIndex &index, const QVariant &value);
|
||||
|
||||
//! Destructor
|
||||
virtual ~CIndexVariantMap() {}
|
||||
virtual ~CPropertyIndexVariantMap() {}
|
||||
|
||||
//! Add a value
|
||||
void addValue(const CPropertyIndex &index, const QVariant &value);
|
||||
|
||||
//! Add QString as literal, disambiguate as I want to add QString
|
||||
void addValue(const CPropertyIndex &index, const char* str);
|
||||
void addValue(const CPropertyIndex &index, const char *str);
|
||||
|
||||
//! Add a value as non QVariant
|
||||
template<class T> void addValue(const CPropertyIndex &index, const T &value) { this->m_values.insert(index, CVariant::fromValue(value)); }
|
||||
@@ -63,7 +68,7 @@ namespace BlackMisc
|
||||
void value(const CPropertyIndex &index, const QVariant &value) { this->m_values.value(index, value); }
|
||||
|
||||
//! Indexes
|
||||
QList<CPropertyIndex> indexes() const { return this->m_values.keys(); }
|
||||
CPropertyIndexList indexes() const;
|
||||
|
||||
//! Contains index?
|
||||
bool contains(const CPropertyIndex &index) const { return this->m_values.contains(index); }
|
||||
@@ -81,10 +86,10 @@ namespace BlackMisc
|
||||
void clear() { this->m_values.clear(); }
|
||||
|
||||
//! Equal operator, required if maps are directly compared, not with CValueObject
|
||||
bool operator ==(const CIndexVariantMap &other) const;
|
||||
bool operator ==(const CPropertyIndexVariantMap &other) const;
|
||||
|
||||
//! Equal operator, required if maps are directly compared, not with CValueObject
|
||||
bool operator !=(const CIndexVariantMap &other) const;
|
||||
bool operator !=(const CPropertyIndexVariantMap &other) const;
|
||||
|
||||
//! Map
|
||||
const QMap<CPropertyIndex, CVariant> &map() const { return this->m_values; }
|
||||
@@ -102,6 +107,7 @@ namespace BlackMisc
|
||||
static void registerMetadata();
|
||||
|
||||
protected:
|
||||
|
||||
QMap<CPropertyIndex, CVariant> m_values; //!< values
|
||||
bool m_wildcard; //!< wildcard
|
||||
|
||||
@@ -125,6 +131,6 @@ namespace BlackMisc
|
||||
};
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::CIndexVariantMap)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CPropertyIndexVariantMap)
|
||||
|
||||
#endif // guard
|
||||
@@ -12,7 +12,7 @@
|
||||
#ifndef BLACKMISC_RANGE_H
|
||||
#define BLACKMISC_RANGE_H
|
||||
|
||||
#include "indexvariantmap.h"
|
||||
#include "propertyindexvariantmap.h"
|
||||
#include "iterator.h"
|
||||
#include "predicates.h"
|
||||
#include <QtGlobal>
|
||||
@@ -73,7 +73,7 @@ namespace BlackMisc
|
||||
/*!
|
||||
* \brief Return a copy containing only those elements matching a given value map.
|
||||
*/
|
||||
inline auto findBy(CIndexVariantMap valueMap) const
|
||||
inline auto findBy(CPropertyIndexVariantMap valueMap) const
|
||||
-> CRange<Iterators::ConditionalIterator<CIt, decltype(BlackMisc::Predicates::Equals(std::move(valueMap)))>>;
|
||||
|
||||
/*!
|
||||
@@ -268,7 +268,7 @@ namespace BlackMisc
|
||||
}
|
||||
|
||||
template <class Derived, class CIt>
|
||||
auto CRangeBase<Derived, CIt>::findBy(CIndexVariantMap valueMap) const
|
||||
auto CRangeBase<Derived, CIt>::findBy(CPropertyIndexVariantMap valueMap) const
|
||||
-> CRange<Iterators::ConditionalIterator<CIt, decltype(BlackMisc::Predicates::Equals(std::move(valueMap)))>>
|
||||
{
|
||||
return findBy(BlackMisc::Predicates::Equals(std::move(valueMap)));
|
||||
|
||||
@@ -7,11 +7,13 @@
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
|
||||
#include "valueobject.h"
|
||||
#include "propertyindexvariantmap.h"
|
||||
#include "propertyindexlist.h"
|
||||
#include "propertyindex.h"
|
||||
#include "indexvariantmap.h"
|
||||
#include "blackmiscfreefunctions.h"
|
||||
#include "iconlist.h"
|
||||
#include "blackmiscfreefunctions.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -100,6 +102,15 @@ namespace BlackMisc
|
||||
return BlackMisc::qVariantToString(qv, i18n);
|
||||
}
|
||||
|
||||
/*
|
||||
* Variant equal property index?
|
||||
*/
|
||||
bool CValueObject::equalPropertyByIndex(const QVariant &compareValue, const CPropertyIndex &index) const
|
||||
{
|
||||
const QVariant myValue = this->propertyByIndex(index);
|
||||
return BlackMisc::equalQVariants(myValue, compareValue);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return backing streamable object (if any)
|
||||
*/
|
||||
@@ -140,17 +151,25 @@ namespace BlackMisc
|
||||
/*
|
||||
* Variant map
|
||||
*/
|
||||
int CValueObject::apply(const BlackMisc::CIndexVariantMap &indexMap)
|
||||
CPropertyIndexList CValueObject::apply(const BlackMisc::CPropertyIndexVariantMap &indexMap, bool skipEqualValues)
|
||||
{
|
||||
if (indexMap.isEmpty()) return 0;
|
||||
int c = 0;
|
||||
CPropertyIndexList changed;
|
||||
if (indexMap.isEmpty()) return changed;
|
||||
|
||||
const auto &map = indexMap.map();
|
||||
for (auto it = map.begin(); it != map.end(); ++it)
|
||||
{
|
||||
this->setPropertyByIndex(it.value().toQVariant(), it.key());
|
||||
const QVariant value = it.value().toQVariant();
|
||||
const CPropertyIndex index = it.key();
|
||||
if (skipEqualValues)
|
||||
{
|
||||
bool equal = this->equalPropertyByIndex(value, index);
|
||||
if (equal) { continue; }
|
||||
}
|
||||
this->setPropertyByIndex(value, index);
|
||||
changed.push_back(index);
|
||||
}
|
||||
return c;
|
||||
return changed;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -172,7 +191,7 @@ namespace BlackMisc
|
||||
/*
|
||||
* Compare with value map
|
||||
*/
|
||||
bool operator==(const CIndexVariantMap &indexMap, const CValueObject &valueObject)
|
||||
bool operator==(const CPropertyIndexVariantMap &indexMap, const CValueObject &valueObject)
|
||||
{
|
||||
if (indexMap.isEmpty()) return indexMap.isWildcard();
|
||||
const auto &map = indexMap.map();
|
||||
@@ -189,7 +208,7 @@ namespace BlackMisc
|
||||
/*
|
||||
* Compare with map
|
||||
*/
|
||||
bool operator!=(const CIndexVariantMap &indexMap, const CValueObject &valueObject)
|
||||
bool operator!=(const CPropertyIndexVariantMap &indexMap, const CValueObject &valueObject)
|
||||
{
|
||||
return !(indexMap == valueObject);
|
||||
}
|
||||
@@ -197,7 +216,7 @@ namespace BlackMisc
|
||||
/*
|
||||
* Compare with map
|
||||
*/
|
||||
bool operator==(const CValueObject &valueObject, const CIndexVariantMap &valueMap)
|
||||
bool operator==(const CValueObject &valueObject, const CPropertyIndexVariantMap &valueMap)
|
||||
{
|
||||
return valueMap == valueObject;
|
||||
}
|
||||
@@ -205,7 +224,7 @@ namespace BlackMisc
|
||||
/*
|
||||
* Compare with map
|
||||
*/
|
||||
bool operator!=(const CValueObject &valueObject, const CIndexVariantMap &valueMap)
|
||||
bool operator!=(const CValueObject &valueObject, const CPropertyIndexVariantMap &valueMap)
|
||||
{
|
||||
return !(valueMap == valueObject);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,8 @@ namespace BlackMisc
|
||||
{
|
||||
// forward declaration
|
||||
class CPropertyIndex;
|
||||
class CIndexVariantMap;
|
||||
class CPropertyIndexList;
|
||||
class CPropertyIndexVariantMap;
|
||||
class CIcon;
|
||||
|
||||
namespace PhysicalQuantities
|
||||
@@ -104,16 +105,16 @@ namespace BlackMisc
|
||||
friend QDBusArgument &operator<<(QDBusArgument &argument, const CValueObject &valueObject);
|
||||
|
||||
//! Operator == with value map
|
||||
friend bool operator==(const CIndexVariantMap &valueMap, const CValueObject &valueObject);
|
||||
friend bool operator==(const CPropertyIndexVariantMap &valueMap, const CValueObject &valueObject);
|
||||
|
||||
//! Operator != with value map
|
||||
friend bool operator!=(const CIndexVariantMap &valueMap, const CValueObject &valueObject);
|
||||
friend bool operator!=(const CPropertyIndexVariantMap &valueMap, const CValueObject &valueObject);
|
||||
|
||||
//! Operator == with value map
|
||||
friend bool operator==(const CValueObject &valueObject, const CIndexVariantMap &valueMap);
|
||||
friend bool operator==(const CValueObject &valueObject, const CPropertyIndexVariantMap &valueMap);
|
||||
|
||||
//! Operator != with value map
|
||||
friend bool operator!=(const CValueObject &valueObject, const CIndexVariantMap &valueMap);
|
||||
friend bool operator!=(const CValueObject &valueObject, const CPropertyIndexVariantMap &valueMap);
|
||||
|
||||
//! Comparison operator to allow valueobjects be used as keys in QMap and std::set.
|
||||
template <class T> friend typename std::enable_if < std::is_base_of<CValueObject, T>::value &&! PhysicalQuantities::IsQuantity<T>::value, bool >::type
|
||||
@@ -182,7 +183,8 @@ namespace BlackMisc
|
||||
std::string toStdString(bool i18n = false) const;
|
||||
|
||||
//! Update by variant map
|
||||
int apply(const BlackMisc::CIndexVariantMap &indexMap);
|
||||
//! \return number of values changed, with skipEqualValues equal values will not be changed
|
||||
CPropertyIndexList apply(const BlackMisc::CPropertyIndexVariantMap &indexMap, bool skipEqualValues = false);
|
||||
|
||||
//! Value hash, allows comparisons between QVariants
|
||||
virtual uint getValueHash() const = 0;
|
||||
@@ -220,6 +222,9 @@ namespace BlackMisc
|
||||
//! Intentionally not abstract, avoiding all classes need to implement this method
|
||||
virtual QString propertyByIndexAsString(const CPropertyIndex &index, bool i18n = false) const;
|
||||
|
||||
//! Is given variant equal to value of property index?
|
||||
virtual bool equalPropertyByIndex(const QVariant &compareValue, const CPropertyIndex &index) const;
|
||||
|
||||
//! The stored object as CValueObject
|
||||
static const CValueObject *fromQVariant(const QVariant &variant);
|
||||
|
||||
@@ -230,9 +235,6 @@ namespace BlackMisc
|
||||
//! Copy constructor
|
||||
CValueObject(const CValueObject &) {}
|
||||
|
||||
//! Copy assignment operator =
|
||||
// CValueObject &operator=(const CValueObject &) { return *this; }
|
||||
|
||||
//! String for streaming operators
|
||||
virtual QString stringForStreaming() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user