mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
refs #207, renamed CValueMap to CIndexVariantMap.
* The map will be used with CSimulaorInfo to transfer a variable number of setting information about the flight simulator. It is being used, because it is already DBus and tupel compliant. The new name better fits its purpose. * Add == operator for CIndexVariantMap (ambiguity error with tupels)
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
#include "blackmisc/avionavsystem.h"
|
||||
#include "blackmisc/aviotransponder.h"
|
||||
#include "blackmisc/avatcstationlist.h"
|
||||
#include "blackmisc/valuemap.h"
|
||||
#include "blackmisc/indexvariantmap.h"
|
||||
#include "blackmisc/predicates.h"
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include <QDebug>
|
||||
@@ -56,7 +56,7 @@ namespace BlackMiscTest
|
||||
qDebug() << atcList.toQString();
|
||||
|
||||
// put Jane in the tower
|
||||
CValueMap newController;
|
||||
CIndexVariantMap newController;
|
||||
newController.addValue(CAtcStation::IndexController, QVariant::fromValue(CUser("112233", "Jane Doe")));
|
||||
atcList.applyIf(
|
||||
BlackMisc::Predicates::MemberEqual<CAtcStation>(&CAtcStation::getCallsign, CCallsign("eddm_twr")),
|
||||
@@ -65,7 +65,7 @@ namespace BlackMiscTest
|
||||
qDebug() << atcList.toQString();
|
||||
|
||||
// now Jane's time is over
|
||||
CValueMap anotherController;
|
||||
CIndexVariantMap anotherController;
|
||||
anotherController.addValue(CAtcStation::IndexController, QVariant::fromValue(CUser("445566", "Fuzzy")));
|
||||
atcList.applyIf(newController, anotherController);
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "testservice.h"
|
||||
#include "testservice_interface.h"
|
||||
#include "blackcore/dbus_server.h"
|
||||
#include "blackmisc/valuemap.h"
|
||||
#include "blackmisc/indexvariantmap.h"
|
||||
#include "blackmisc/nwserver.h"
|
||||
#include <QTextStream>
|
||||
#include <QString>
|
||||
@@ -320,7 +320,7 @@ namespace BlackMiscTest
|
||||
qDebug() << "Send geo position" << geoPos;
|
||||
|
||||
// Value map
|
||||
CValueMap valueMap;
|
||||
CIndexVariantMap valueMap;
|
||||
valueMap.addValue(1, 111.222);
|
||||
valueMap.addValue(2, callsign);
|
||||
valueMap.addValue(3, alt);
|
||||
|
||||
@@ -208,7 +208,7 @@ namespace BlackMiscTest
|
||||
/*
|
||||
* Receive value map
|
||||
*/
|
||||
void Testservice::receiveValueMap(const BlackMisc::CValueMap &valueMap) const
|
||||
void Testservice::receiveValueMap(const BlackMisc::CIndexVariantMap &valueMap) const
|
||||
{
|
||||
qDebug() << "Pid:" << ServiceTool::getPid() << "Received value map:" << valueMap;
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ namespace BlackMiscTest
|
||||
* \brief Receive an value map
|
||||
* \param valueMap
|
||||
*/
|
||||
void receiveValueMap(const BlackMisc::CValueMap &valueMap) const;
|
||||
void receiveValueMap(const BlackMisc::CIndexVariantMap &valueMap) const;
|
||||
|
||||
/*!
|
||||
* \brief Ping atc list
|
||||
|
||||
@@ -202,7 +202,7 @@ namespace BlackMiscTest
|
||||
return asyncCallWithArgumentList(QLatin1String("receiveTransponder"), argumentList);
|
||||
}
|
||||
|
||||
inline QDBusPendingReply<> receiveValueMap(BlackMisc::CValueMap valueMap)
|
||||
inline QDBusPendingReply<> receiveValueMap(BlackMisc::CIndexVariantMap valueMap)
|
||||
{
|
||||
QList<QVariant> argumentList;
|
||||
argumentList << QVariant::fromValue(valueMap);
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace BlackCore
|
||||
else
|
||||
{
|
||||
// update
|
||||
CValueMap vm(CAircraft::IndexIcao, icaoData.toQVariant());
|
||||
CIndexVariantMap vm(CAircraft::IndexIcao, icaoData.toQVariant());
|
||||
this->m_aircraftsInRange.applyIf(BlackMisc::Predicates::MemberEqual<CAircraft>(&CAircraft::getCallsign, callsign), vm);
|
||||
emit this->changedAircraftsInRange();
|
||||
}
|
||||
@@ -83,7 +83,7 @@ namespace BlackCore
|
||||
// update
|
||||
CLength distance = this->m_ownAircraft.calculcateDistanceToPlane(situation.getPosition());
|
||||
distance.switchUnit(CLengthUnit::NM());
|
||||
CValueMap vm;
|
||||
CIndexVariantMap vm;
|
||||
vm.addValue(CAircraft::IndexTransponder, transponder);
|
||||
vm.addValue(CAircraft::IndexSituation, situation);
|
||||
vm.addValue(CAircraft::IndexDistance, distance);
|
||||
@@ -111,7 +111,7 @@ namespace BlackCore
|
||||
// this->log(Q_FUNC_INFO, callsign.toQString(), frequency.toQString());
|
||||
|
||||
// update
|
||||
CValueMap vm(CAircraft::IndexFrequencyCom1, frequency.toQVariant());
|
||||
CIndexVariantMap vm(CAircraft::IndexFrequencyCom1, frequency.toQVariant());
|
||||
this->m_aircraftsInRange.applyIf(BlackMisc::Predicates::MemberEqual<CAircraft>(&CAircraft::getCallsign, callsign), vm);
|
||||
emit this->changedAircraftsInRange();
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ namespace BlackCore
|
||||
else
|
||||
{
|
||||
// update
|
||||
CValueMap values;
|
||||
CIndexVariantMap values;
|
||||
values.addValue(CAtcStation::IndexFrequency, frequency);
|
||||
values.addValue(CAtcStation::IndexPosition, position);
|
||||
values.addValue(CAtcStation::IndexRange, range);
|
||||
@@ -274,7 +274,7 @@ namespace BlackCore
|
||||
// this->log(Q_FUNC_INFO, callsign.toQString());
|
||||
this->m_atcStationsOnline.removeIf(&CAtcStation::getCallsign, callsign);
|
||||
emit this->changedAtcStationsOnline();
|
||||
this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, CValueMap(CAtcStation::IndexIsOnline, QVariant(false)));
|
||||
this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, CIndexVariantMap(CAtcStation::IndexIsOnline, QVariant(false)));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -284,7 +284,7 @@ namespace BlackCore
|
||||
{
|
||||
// this->log(Q_FUNC_INFO, callsign.toQString(), atisMessage);
|
||||
|
||||
CValueMap vm(CAtcStation::IndexAtis, atisMessage.toQVariant());
|
||||
CIndexVariantMap vm(CAtcStation::IndexAtis, atisMessage.toQVariant());
|
||||
this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm);
|
||||
this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, vm);
|
||||
}
|
||||
@@ -295,7 +295,7 @@ namespace BlackCore
|
||||
void CContextNetwork::psFsdAtisVoiceRoomQueryReceived(const CCallsign &callsign, const QString &url)
|
||||
{
|
||||
QString trimmedUrl = url.trimmed();
|
||||
CValueMap vm(CAtcStation::IndexVoiceRoomUrl, trimmedUrl);
|
||||
CIndexVariantMap vm(CAtcStation::IndexVoiceRoomUrl, trimmedUrl);
|
||||
this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm);
|
||||
this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, vm);
|
||||
}
|
||||
@@ -315,7 +315,7 @@ namespace BlackCore
|
||||
if (!ok) return;
|
||||
QDateTime logoffDateTime = QDateTime::currentDateTimeUtc();
|
||||
logoffDateTime.setTime(QTime(h, m));
|
||||
CValueMap vm(CAtcStation::IndexBookedUntil, logoffDateTime);
|
||||
CIndexVariantMap vm(CAtcStation::IndexBookedUntil, logoffDateTime);
|
||||
this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm);
|
||||
this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, vm);
|
||||
}
|
||||
@@ -334,7 +334,7 @@ namespace BlackCore
|
||||
CInformationMessage metar(CInformationMessage::METAR, metarMessage);
|
||||
|
||||
// add METAR to existing stations
|
||||
CValueMap vm(CAtcStation::IndexMetar, metar.toQVariant());
|
||||
CIndexVariantMap vm(CAtcStation::IndexMetar, metar.toQVariant());
|
||||
this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsignTower, vm);
|
||||
this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsignTower, vm);
|
||||
this->m_metarCache.insert(icaoCode, metar);
|
||||
|
||||
@@ -300,11 +300,11 @@ namespace BlackCore
|
||||
{
|
||||
if (this->getRuntime()->isSlotLogForNetworkEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, callsign.toQString(), realname);
|
||||
if (realname.isEmpty()) return;
|
||||
CValueMap vm(CAtcStation::IndexControllerRealName, realname);
|
||||
CIndexVariantMap vm(CAtcStation::IndexControllerRealName, realname);
|
||||
this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm);
|
||||
this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, vm);
|
||||
|
||||
vm = CValueMap(CAircraft::IndexPilotRealName, realname);
|
||||
vm = CIndexVariantMap(CAircraft::IndexPilotRealName, realname);
|
||||
this->m_aircraftsInRange.applyIf(&CAircraft::getCallsign, callsign, vm);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "blackmisc/avallclasses.h"
|
||||
#include "blackmisc/geoallclasses.h"
|
||||
#include "blackmisc/settingsallclasses.h"
|
||||
#include "blackmisc/valuemap.h"
|
||||
#include "blackmisc/indexvariantmap.h"
|
||||
#include "blackmisc/networkallclasses.h"
|
||||
#include "blackmisc/statusmessagelist.h"
|
||||
#include "blackmisc/statusmessage.h"
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "networkallclasses.h"
|
||||
#include "settingsallclasses.h"
|
||||
#include "hwallclasses.h"
|
||||
#include "valuemap.h"
|
||||
#include "indexvariantmap.h"
|
||||
#include "statusmessagelist.h"
|
||||
#include "audioallclasses.h"
|
||||
|
||||
@@ -129,7 +129,7 @@ void BlackMisc::registerMetadata()
|
||||
{
|
||||
// !! make sure the first id is correctly returned by
|
||||
// !! firstBlackMetaType
|
||||
CValueMap::registerMetadata();
|
||||
CIndexVariantMap::registerMetadata();
|
||||
|
||||
CStatusMessage::registerMetadata();
|
||||
CStatusMessageList::registerMetadata();
|
||||
@@ -151,7 +151,7 @@ void BlackMisc::registerMetadata()
|
||||
int BlackMisc::firstBlackMetaType()
|
||||
{
|
||||
// must be the first registered above
|
||||
return qMetaTypeId<CValueMap>();
|
||||
return qMetaTypeId<CIndexVariantMap>();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#define BLACKMISC_CONTAINERBASE_H
|
||||
|
||||
#include "valueobject.h"
|
||||
#include "valuemap.h"
|
||||
#include "indexvariantmap.h"
|
||||
#include "predicates.h"
|
||||
#include "json.h"
|
||||
#include <algorithm>
|
||||
@@ -93,7 +93,7 @@ namespace BlackMisc
|
||||
/*!
|
||||
* \brief Return a copy containing only those elements matching a given value map.
|
||||
*/
|
||||
C<T> findBy(const CValueMap &valueMap) const
|
||||
C<T> findBy(const CIndexVariantMap &valueMap) const
|
||||
{
|
||||
return findBy([ & ](const T & value) { return value == valueMap; });
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "valuemap.h"
|
||||
#include "indexvariantmap.h"
|
||||
#include "blackmiscfreefunctions.h"
|
||||
#include "avaltitude.h"
|
||||
|
||||
@@ -7,20 +7,36 @@ namespace BlackMisc
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
CValueMap::CValueMap(bool wildcard) : m_wildcard(wildcard) {}
|
||||
CIndexVariantMap::CIndexVariantMap(bool wildcard) : m_wildcard(wildcard) {}
|
||||
|
||||
/*
|
||||
* Constructor single value
|
||||
*/
|
||||
CValueMap::CValueMap(int index, const QVariant &value)
|
||||
CIndexVariantMap::CIndexVariantMap(int index, const QVariant &value)
|
||||
{
|
||||
this->addValue(index, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* ==
|
||||
*/
|
||||
bool CIndexVariantMap::operator ==(const CIndexVariantMap &other) const
|
||||
{
|
||||
return this->m_wildcard == other.m_wildcard && this->m_values == other.m_values;
|
||||
}
|
||||
|
||||
/*
|
||||
* !=
|
||||
*/
|
||||
bool CIndexVariantMap::operator !=(const CIndexVariantMap &other) const
|
||||
{
|
||||
return !(this->operator ==(other));
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert to string
|
||||
*/
|
||||
QString CValueMap::convertToQString(bool i18n) const
|
||||
QString CIndexVariantMap::convertToQString(bool i18n) const
|
||||
{
|
||||
if (this->isEmpty()) return "{}";
|
||||
QString s;
|
||||
@@ -41,17 +57,17 @@ namespace BlackMisc
|
||||
/*
|
||||
* metaTypeId
|
||||
*/
|
||||
int CValueMap::getMetaTypeId() const
|
||||
int CIndexVariantMap::getMetaTypeId() const
|
||||
{
|
||||
return qMetaTypeId<CValueMap>();
|
||||
return qMetaTypeId<CIndexVariantMap>();
|
||||
}
|
||||
|
||||
/*
|
||||
* is a
|
||||
*/
|
||||
bool CValueMap::isA(int metaTypeId) const
|
||||
bool CIndexVariantMap::isA(int metaTypeId) const
|
||||
{
|
||||
if (metaTypeId == qMetaTypeId<CValueMap>()) { return true; }
|
||||
if (metaTypeId == qMetaTypeId<CIndexVariantMap>()) { return true; }
|
||||
|
||||
return this->CValueObject::isA(metaTypeId);
|
||||
}
|
||||
@@ -59,7 +75,7 @@ namespace BlackMisc
|
||||
/*
|
||||
* Compare
|
||||
*/
|
||||
int CValueMap::compareImpl(const CValueObject &/*otherBase*/) const
|
||||
int CIndexVariantMap::compareImpl(const CValueObject &/*otherBase*/) const
|
||||
{
|
||||
qFatal("not implemented");
|
||||
return 0;
|
||||
@@ -68,7 +84,7 @@ namespace BlackMisc
|
||||
/*
|
||||
* Marshall to DBus
|
||||
*/
|
||||
void CValueMap::marshallToDbus(QDBusArgument &argument) const
|
||||
void CIndexVariantMap::marshallToDbus(QDBusArgument &argument) const
|
||||
{
|
||||
// remark, tried both sending as QDbusVariant and QVariant
|
||||
// does not make a difference
|
||||
@@ -87,7 +103,7 @@ namespace BlackMisc
|
||||
/*
|
||||
* Unmarshall from DBus
|
||||
*/
|
||||
void CValueMap::unmarshallFromDbus(const QDBusArgument &argument)
|
||||
void CIndexVariantMap::unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
QList<int> indexes;
|
||||
QList<QDBusVariant> values;
|
||||
@@ -120,7 +136,7 @@ namespace BlackMisc
|
||||
/*
|
||||
* Add value
|
||||
*/
|
||||
void CValueMap::addValue(int index, const QVariant &value)
|
||||
void CIndexVariantMap::addValue(int index, const QVariant &value)
|
||||
{
|
||||
this->m_values.insert(index, value);
|
||||
}
|
||||
@@ -128,16 +144,16 @@ namespace BlackMisc
|
||||
/*
|
||||
* Register metadata
|
||||
*/
|
||||
void CValueMap::registerMetadata()
|
||||
void CIndexVariantMap::registerMetadata()
|
||||
{
|
||||
qRegisterMetaType<CValueMap>();
|
||||
qDBusRegisterMetaType<CValueMap>();
|
||||
qRegisterMetaType<CIndexVariantMap>();
|
||||
qDBusRegisterMetaType<CIndexVariantMap>();
|
||||
}
|
||||
|
||||
/*
|
||||
* Hash
|
||||
*/
|
||||
uint CValueMap::getValueHash() const
|
||||
uint CIndexVariantMap::getValueHash() const
|
||||
{
|
||||
return qHash(this);
|
||||
}
|
||||
@@ -11,15 +11,16 @@
|
||||
#include <QVariantMap>
|
||||
#include <QDBusArgument>
|
||||
|
||||
#ifndef BLACKMISC_VALUEMAP_H
|
||||
#define BLACKMISC_VALUEMAP_H
|
||||
#ifndef BLACKMISC_INDEXVARIANTMAP_H
|
||||
#define BLACKMISC_INDEXVARIANTMAP_H
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
/*!
|
||||
* \brief Value map
|
||||
* Specialized value object compliant map for variants,
|
||||
* based on Column indexes
|
||||
*/
|
||||
class CValueMap : public CValueObject
|
||||
class CIndexVariantMap : public CValueObject
|
||||
{
|
||||
|
||||
public:
|
||||
@@ -28,133 +29,86 @@ namespace BlackMisc
|
||||
* \brief Constructor
|
||||
* \param wildcard when used in search, for setting values irrelevant
|
||||
*/
|
||||
CValueMap(bool wildcard = false);
|
||||
CIndexVariantMap(bool wildcard = false);
|
||||
|
||||
/*!
|
||||
* \brief Single value constructor
|
||||
* \param index
|
||||
* \param value
|
||||
*/
|
||||
CValueMap(int index, const QVariant &value);
|
||||
//! Single value constructor
|
||||
CIndexVariantMap(int index, const QVariant &value);
|
||||
|
||||
/*!
|
||||
* \copydoc CValueObject::toQVariant
|
||||
*/
|
||||
//! \copydoc CValueObject::toQVariant
|
||||
virtual QVariant toQVariant() const override
|
||||
{
|
||||
return QVariant::fromValue(*this);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Destructor
|
||||
*/
|
||||
virtual ~CValueMap() {}
|
||||
//! Destructor
|
||||
virtual ~CIndexVariantMap() {}
|
||||
|
||||
/*!
|
||||
* \brief Add a value
|
||||
* \param index
|
||||
* \param value
|
||||
*/
|
||||
//! Add a value
|
||||
void addValue(int index, const QVariant &value);
|
||||
|
||||
/*!
|
||||
* \brief Add a value as non QVariant
|
||||
* \param index
|
||||
* \param value
|
||||
*/
|
||||
//! Add a value as non QVariant
|
||||
template<class T> void addValue(int index, const T &value)
|
||||
{
|
||||
this->m_values.insert(index, QVariant::fromValue(value));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Is empty
|
||||
* \return
|
||||
*/
|
||||
//! Is empty?
|
||||
bool isEmpty() const { return this->m_values.isEmpty(); }
|
||||
|
||||
/*!
|
||||
* \brief Value
|
||||
* \param index
|
||||
* \return
|
||||
*/
|
||||
//! Value
|
||||
QVariant value(int index) const { return this->m_values.value(index); }
|
||||
|
||||
/*!
|
||||
* \brief Indexes
|
||||
* \return
|
||||
*/
|
||||
//! Indexes
|
||||
QList<int> indexes() const { return this->m_values.keys(); }
|
||||
|
||||
/*!
|
||||
* \brief values
|
||||
* \return
|
||||
*/
|
||||
//! values
|
||||
QList<QVariant> values() const { return this->m_values.values(); }
|
||||
|
||||
/*!
|
||||
* \brief Wildcard, only relevant when used in search
|
||||
* \return
|
||||
*/
|
||||
//! \brief Wildcard, only relevant when used in search
|
||||
bool isWildcard() const { return this->m_wildcard; }
|
||||
|
||||
/*!
|
||||
* \brief clear
|
||||
*/
|
||||
//! clear
|
||||
void clear() { this->m_values.clear(); }
|
||||
|
||||
/*!
|
||||
* \brief Map
|
||||
* \return
|
||||
*/
|
||||
//! Equal operator, required if maps are directly compared, not with CValueObject
|
||||
bool operator ==(const CIndexVariantMap &other) const;
|
||||
|
||||
//! Equal operator, required if maps are directly compared, not with CValueObject
|
||||
bool operator !=(const CIndexVariantMap &other) const;
|
||||
|
||||
//! Map
|
||||
const QMap<int, QVariant> &map() const { return this->m_values; }
|
||||
|
||||
/*!
|
||||
* \copydoc CValueObject::getValueHash
|
||||
*/
|
||||
//! \copydoc CValueObject::getValueHash
|
||||
virtual uint getValueHash() const override;
|
||||
|
||||
/*!
|
||||
* \brief Metadata
|
||||
*/
|
||||
//! register metadata
|
||||
static void registerMetadata();
|
||||
|
||||
protected:
|
||||
QMap<int, QVariant> m_values; //!< values
|
||||
bool m_wildcard; //!< wildcard
|
||||
|
||||
/*!
|
||||
* \copydoc CValueObject::convertToQString
|
||||
*/
|
||||
//! \copydoc CValueObject::convertToQString
|
||||
virtual QString convertToQString(bool i18n = false) const override;
|
||||
|
||||
/*!
|
||||
* \copydoc CValueObject::getMetaTypeId
|
||||
*/
|
||||
//! \copydoc CValueObject::getMetaTypeId
|
||||
virtual int getMetaTypeId() const override;
|
||||
|
||||
/*!
|
||||
* \copydoc CValueObject::isA
|
||||
*/
|
||||
//! \copydoc CValueObject::isA
|
||||
virtual bool isA(int metaTypeId) const override;
|
||||
|
||||
/*!
|
||||
* \copydoc CValueObject::compareImpl
|
||||
*/
|
||||
//! \copydoc CValueObject::compareImpl
|
||||
virtual int compareImpl(const CValueObject &other) const override;
|
||||
|
||||
/*!
|
||||
* \copydoc CValueObject::marshallToDbus
|
||||
*/
|
||||
//! \copydoc CValueObject::marshallToDbus
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const override;
|
||||
|
||||
/*!
|
||||
* \copydoc CValueObject::unmarshallFromDbus
|
||||
*/
|
||||
//! \copydoc CValueObject::unmarshallFromDbus
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
|
||||
};
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::CValueMap)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CIndexVariantMap)
|
||||
|
||||
#endif // guard
|
||||
@@ -234,7 +234,7 @@ namespace BlackMisc
|
||||
* \brief Modify by applying a value map to each element for which a given predicate returns true.
|
||||
*/
|
||||
template <class Predicate>
|
||||
void applyIf(Predicate p, const CValueMap &newValues)
|
||||
void applyIf(Predicate p, const CIndexVariantMap &newValues)
|
||||
{
|
||||
std::for_each(begin(), end(), [ &, p ](T &value) { if (p(value)) { value.apply(newValues); } });
|
||||
}
|
||||
@@ -246,7 +246,7 @@ namespace BlackMisc
|
||||
* \param newValues Values from this map will be put into each matching element.
|
||||
*/
|
||||
template <class K1, class V1>
|
||||
void applyIf(K1 key1, V1 value1, const CValueMap &newValues)
|
||||
void applyIf(K1 key1, V1 value1, const CIndexVariantMap &newValues)
|
||||
{
|
||||
applyIf(BlackMisc::Predicates::MemberEqual<T>(key1, value1), newValues);
|
||||
}
|
||||
@@ -254,7 +254,7 @@ namespace BlackMisc
|
||||
/*!
|
||||
* \brief Modify by applying a value map to each element matching a given value map.
|
||||
*/
|
||||
void applyIf(const CValueMap &pattern, const CValueMap &newValues)
|
||||
void applyIf(const CIndexVariantMap &pattern, const CIndexVariantMap &newValues)
|
||||
{
|
||||
applyIf([ & ](const T &value) { return value == pattern; }, newValues);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "valueobject.h"
|
||||
#include "valuemap.h"
|
||||
#include "indexvariantmap.h"
|
||||
#include "blackmiscfreefunctions.h"
|
||||
|
||||
namespace BlackMisc
|
||||
@@ -104,16 +104,16 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
/*
|
||||
* Variant map
|
||||
*/
|
||||
int CValueObject::apply(const BlackMisc::CValueMap &valueMap)
|
||||
int CValueObject::apply(const BlackMisc::CIndexVariantMap &indexMap)
|
||||
{
|
||||
if (valueMap.isEmpty()) return 0;
|
||||
if (indexMap.isEmpty()) return 0;
|
||||
int c = 0;
|
||||
|
||||
QMap<int, QVariant>::const_iterator it;
|
||||
const QMap<int, QVariant> &map = valueMap.map();
|
||||
const QMap<int, QVariant> &map = indexMap.map();
|
||||
for (it = map.begin(); it != map.end(); ++it)
|
||||
{
|
||||
this->setPropertyByIndex(it.value(), it.key());
|
||||
@@ -124,11 +124,11 @@ namespace BlackMisc
|
||||
/*
|
||||
* Compare with value map
|
||||
*/
|
||||
bool operator==(const CValueMap &valueMap, const CValueObject &valueObject)
|
||||
bool operator==(const CIndexVariantMap &indexMap, const CValueObject &valueObject)
|
||||
{
|
||||
if (valueMap.isEmpty()) return valueMap.isWildcard();
|
||||
if (indexMap.isEmpty()) return indexMap.isWildcard();
|
||||
QMap<int, QVariant>::const_iterator it;
|
||||
const QMap<int, QVariant> &map = valueMap.map();
|
||||
const QMap<int, QVariant> &map = indexMap.map();
|
||||
for (it = map.begin(); it != map.end(); ++it)
|
||||
{
|
||||
// QVariant cannot be compared directly
|
||||
@@ -140,25 +140,25 @@ namespace BlackMisc
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare with value map
|
||||
* Compare with map
|
||||
*/
|
||||
bool operator!=(const CValueMap &valueMap, const CValueObject &valueObject)
|
||||
bool operator!=(const CIndexVariantMap &indexMap, const CValueObject &valueObject)
|
||||
{
|
||||
return !(valueMap == valueObject);
|
||||
return !(indexMap == valueObject);
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare with value map
|
||||
* Compare with map
|
||||
*/
|
||||
bool operator==(const CValueObject &valueObject, const CValueMap &valueMap)
|
||||
bool operator==(const CValueObject &valueObject, const CIndexVariantMap &valueMap)
|
||||
{
|
||||
return valueMap == valueObject;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare with value map
|
||||
* Compare with map
|
||||
*/
|
||||
bool operator!=(const CValueObject &valueObject, const CValueMap &valueMap)
|
||||
bool operator!=(const CValueObject &valueObject, const CIndexVariantMap &valueMap)
|
||||
{
|
||||
return !(valueMap == valueObject);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
namespace BlackMisc
|
||||
{
|
||||
// forward declaration
|
||||
class CValueMap;
|
||||
class CIndexVariantMap;
|
||||
|
||||
/*!
|
||||
* \brief Base class for value objects.
|
||||
@@ -110,7 +110,7 @@ namespace BlackMisc
|
||||
* \param valueObject
|
||||
* \return
|
||||
*/
|
||||
friend bool operator==(const CValueMap &valueMap, const CValueObject &valueObject);
|
||||
friend bool operator==(const CIndexVariantMap &valueMap, const CValueObject &valueObject);
|
||||
|
||||
/*!
|
||||
* \brief Operator != with value map
|
||||
@@ -118,9 +118,7 @@ namespace BlackMisc
|
||||
* \param valueObject
|
||||
* \return
|
||||
*/
|
||||
friend bool operator!=(const CValueMap &valueMap, const CValueObject &valueObject);
|
||||
|
||||
//! \brief Operator == with value map
|
||||
friend bool operator!=(const CIndexVariantMap &valueMap, const CValueObject &valueObject);
|
||||
|
||||
/*!
|
||||
* \brief operator == with value map
|
||||
@@ -128,7 +126,7 @@ namespace BlackMisc
|
||||
* \param valueMap
|
||||
* \return
|
||||
*/
|
||||
friend bool operator==(const CValueObject &valueObject, const CValueMap &valueMap);
|
||||
friend bool operator==(const CValueObject &valueObject, const CIndexVariantMap &valueMap);
|
||||
|
||||
/*!
|
||||
* \brief Operator != with value map
|
||||
@@ -136,7 +134,7 @@ namespace BlackMisc
|
||||
* \param valueMap
|
||||
* \return
|
||||
*/
|
||||
friend bool operator!=(const CValueObject &valueObject, const CValueMap &valueMap);
|
||||
friend bool operator!=(const CValueObject &valueObject, const CIndexVariantMap &valueMap);
|
||||
|
||||
/*!
|
||||
* Compares two instances of related classes
|
||||
@@ -171,7 +169,7 @@ namespace BlackMisc
|
||||
/*!
|
||||
* \brief Update by variant map
|
||||
*/
|
||||
int apply(const BlackMisc::CValueMap &valueMap);
|
||||
int apply(const BlackMisc::CIndexVariantMap &indexMap);
|
||||
|
||||
/*!
|
||||
* \brief Value hash, allows comparisons between QVariants
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#include "testvariantandmap.h"
|
||||
#include "blackmisc/avatcstation.h"
|
||||
#include "blackmisc/valuemap.h"
|
||||
#include "blackmisc/indexvariantmap.h"
|
||||
#include "blackmisc/tuple.h"
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
@@ -77,9 +77,9 @@ namespace BlackMiscTest
|
||||
geoPos, CLength(50, CLengthUnit::km()), false, dtFrom, dtUntil);
|
||||
|
||||
// value maps
|
||||
CValueMap vmWildcard(true);
|
||||
CValueMap vmNoWildcard(false);
|
||||
CValueMap vm;
|
||||
CIndexVariantMap vmWildcard(true);
|
||||
CIndexVariantMap vmNoWildcard(false);
|
||||
CIndexVariantMap vm;
|
||||
|
||||
// remark: Shortcoming here, as the callsign will automatically set for user in station
|
||||
// I have to set this as well, otherwise, not match.
|
||||
@@ -89,6 +89,7 @@ namespace BlackMiscTest
|
||||
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");
|
||||
QVERIFY2(vmWildcard == vmWildcard, "Maps should be equal");
|
||||
}
|
||||
|
||||
} //namespace BlackMiscTest
|
||||
|
||||
Reference in New Issue
Block a user