refs #325, refs #330 fixed apply method to return list of changed properties

* changed CValueObject apply
* created CIndexPropertyList
* renamed CIndexVariantMap to CPropertyIndexVariantMap
This commit is contained in:
Klaus Basan
2014-10-02 15:57:33 +02:00
parent 88951318de
commit 4b50134d2a
26 changed files with 276 additions and 132 deletions

View File

@@ -11,7 +11,7 @@
#include "blackcore/blackcorefreefunctions.h"
#include "blackmisc/project.h"
#include "blackmisc/testing.h"
#include "blackmisc/indexvariantmap.h"
#include "blackmisc/propertyindexallclasses.h"
namespace BlackCore
{
@@ -231,15 +231,15 @@ namespace BlackCore
void CAirspaceMonitor::ps_realNameReplyReceived(const CCallsign &callsign, const QString &realname)
{
if (realname.isEmpty()) return;
CIndexVariantMap vm({CAtcStation::IndexController, CUser::IndexRealName}, realname);
CPropertyIndexVariantMap vm({CAtcStation::IndexController, CUser::IndexRealName}, realname);
this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm);
this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, vm);
vm = CIndexVariantMap({CAircraft::IndexPilot, CUser::IndexRealName}, realname);
vm = CPropertyIndexVariantMap({CAircraft::IndexPilot, CUser::IndexRealName}, realname);
this->m_aircraftsInRange.applyIf(&CAircraft::getCallsign, callsign, vm);
// Client
vm = CIndexVariantMap({CClient::IndexUser, CUser::IndexRealName}, realname);
vm = CPropertyIndexVariantMap({CClient::IndexUser, CUser::IndexRealName}, realname);
this->addVoiceCapabilitiesFromDataFile(vm, callsign);
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm);
}
@@ -247,11 +247,11 @@ namespace BlackCore
void CAirspaceMonitor::ps_capabilitiesReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, quint32 flags)
{
if (callsign.isEmpty()) return;
CIndexVariantMap capabilities;
CPropertyIndexVariantMap capabilities;
capabilities.addValue(CClient::FsdAtisCanBeReceived, (flags & INetwork::AcceptsAtisResponses));
capabilities.addValue(CClient::FsdWithInterimPositions, (flags & INetwork::SupportsInterimPosUpdates));
capabilities.addValue(CClient::FsdWithModelDescription, (flags & INetwork::SupportsModelDescriptions));
CIndexVariantMap vm(CClient::IndexCapabilities, capabilities.toQVariant());
CPropertyIndexVariantMap vm(CClient::IndexCapabilities, capabilities.toQVariant());
this->addVoiceCapabilitiesFromDataFile(vm, callsign);
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm);
}
@@ -261,7 +261,7 @@ namespace BlackCore
if (callsign.isEmpty() || model.isEmpty()) return;
// Request of other client, I can get the other's model from that
CIndexVariantMap vm({ CClient::IndexModel, CAircraftModel::IndexModelString }, QVariant(model));
CPropertyIndexVariantMap vm({ CClient::IndexModel, CAircraftModel::IndexModelString }, QVariant(model));
vm.addValue({ CClient::IndexModel, CAircraftModel::IndexIsQueriedModelString }, QVariant(true));
if (!this->m_otherClients.contains(&CClient::getCallsign, callsign))
{
@@ -276,7 +276,7 @@ namespace BlackCore
void CAirspaceMonitor::ps_serverReplyReceived(const CCallsign &callsign, const QString &server)
{
if (callsign.isEmpty() || server.isEmpty()) return;
CIndexVariantMap vm(CClient::IndexServer, QVariant(server));
CPropertyIndexVariantMap vm(CClient::IndexServer, QVariant(server));
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm);
}
@@ -289,7 +289,7 @@ namespace BlackCore
CInformationMessage metar(CInformationMessage::METAR, metarMessage);
// add METAR to existing stations
CIndexVariantMap vm(CAtcStation::IndexMetar, metar.toQVariant());
CPropertyIndexVariantMap 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);
@@ -322,7 +322,7 @@ namespace BlackCore
this->m_network->sendFsipirCustomPacket(recipientCallsign, icao.getAirlineDesignator(), icao.getAircraftDesignator(), icao.getAircraftCombinedType(), modelString);
}
void CAirspaceMonitor::addVoiceCapabilitiesFromDataFile(CIndexVariantMap &vm, const CCallsign &callsign)
void CAirspaceMonitor::addVoiceCapabilitiesFromDataFile(CPropertyIndexVariantMap &vm, const CCallsign &callsign)
{
Q_ASSERT(this->m_vatsimDataFileReader);
if (callsign.isEmpty()) return;
@@ -394,7 +394,7 @@ namespace BlackCore
else
{
// update
CIndexVariantMap values;
CPropertyIndexVariantMap values;
values.addValue(CAtcStation::IndexFrequency, frequency);
values.addValue(CAtcStation::IndexPosition, position);
values.addValue(CAtcStation::IndexRange, range);
@@ -415,15 +415,15 @@ namespace BlackCore
}
// booked
this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, CIndexVariantMap(CAtcStation::IndexIsOnline, QVariant(false)));
this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, CPropertyIndexVariantMap(CAtcStation::IndexIsOnline, QVariant(false)));
}
void CAirspaceMonitor::ps_atisReceived(const CCallsign &callsign, const CInformationMessage &atisMessage)
{
Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this));
if (callsign.isEmpty()) return;
CIndexVariantMap vm(CAtcStation::IndexAtis, atisMessage.toQVariant());
this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm);
CPropertyIndexVariantMap vm(CAtcStation::IndexAtis, atisMessage.toQVariant());
int changedOnline = this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm);
// receiving an ATIS means station is online, update in bookings
vm.addValue(CAtcStation::IndexIsOnline, true);
@@ -436,8 +436,9 @@ namespace BlackCore
{
Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this));
QString trimmedUrl = url.trimmed();
CIndexVariantMap vm({ CAtcStation::IndexVoiceRoom, CVoiceRoom::IndexUrl }, trimmedUrl);
if (this->m_atcStationsOnline.contains(&CAtcStation::getCallsign, callsign))
CPropertyIndexVariantMap vm({ CAtcStation::IndexVoiceRoom, CVoiceRoom::IndexUrl }, trimmedUrl);
int changedOnline = this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm);
if (changedOnline > 0)
{
this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm);
CAtcStation station = this->m_atcStationsOnline.findFirstByCallsign(callsign);
@@ -453,8 +454,11 @@ namespace BlackCore
}
// receiving voice room means ATC has voice
vm = CIndexVariantMap(CClient::IndexVoiceCapabilities, CVoiceCapabilities::fromVoiceCapabilities(CVoiceCapabilities::Voice).toQVariant());
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm);
if (changedOnline > 0)
{
vm = CPropertyIndexVariantMap(CClient::IndexVoiceCapabilities, CVoiceCapabilities::fromVoiceCapabilities(CVoiceCapabilities::Voice).toQVariant());
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm);
}
}
void CAirspaceMonitor::ps_atisLogoffTimeReceived(const CCallsign &callsign, const QString &zuluTime)
@@ -470,11 +474,13 @@ namespace BlackCore
if (!ok) { return; }
QDateTime logoffDateTime = QDateTime::currentDateTimeUtc();
logoffDateTime.setTime(QTime(h, m));
CIndexVariantMap vm(CAtcStation::IndexBookedUntil, logoffDateTime);
this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm);
this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, vm);
if (this->m_atcStationsOnline.contains(&CAtcStation::getCallsign, callsign)) { emit this->changedAtcStationsOnline(); }
if (this->m_atcStationsBooked.contains(&CAtcStation::getCallsign, callsign)) { emit this->changedAtcStationsBooked(); }
CPropertyIndexVariantMap vm(CAtcStation::IndexBookedUntil, logoffDateTime);
int changedOnline = this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm);
int changedBooked = this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, vm);
if (changedOnline > 0) { emit changedAtcStationsOnline(); }
if (changedBooked > 0) { emit changedAtcStationsBooked(); }
}
}
@@ -483,14 +489,14 @@ namespace BlackCore
Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this));
// update
CIndexVariantMap vm(CAircraft::IndexIcao, icaoData.toQVariant());
CPropertyIndexVariantMap vm(CAircraft::IndexIcao, icaoData.toQVariant());
if (!icaoData.hasAircraftDesignator())
{
// empty so far, try to fetch from data file
qDebug() << "Empty ICAO info for " << callsign << icaoData;
CAircraftIcao icaoDataDataFile = this->m_vatsimDataFileReader->getIcaoInfo(callsign);
if (!icaoDataDataFile.hasAircraftDesignator()) return; // give up!
vm = CIndexVariantMap(CAircraft::IndexIcao, icaoData.toQVariant());
vm = CPropertyIndexVariantMap(CAircraft::IndexIcao, icaoData.toQVariant());
}
this->m_aircraftsInRange.applyIf(BlackMisc::Predicates::MemberEqual(&CAircraft::getCallsign, callsign), vm);
emit this->changedAircraftsInRange();
@@ -538,7 +544,7 @@ namespace BlackCore
// update
CLength distance = this->m_ownAircraft.calculcateDistanceToPosition(situation.getPosition());
distance.switchUnit(CLengthUnit::NM());
CIndexVariantMap vm;
CPropertyIndexVariantMap vm;
vm.addValue(CAircraft::IndexTransponder, transponder);
vm.addValue(CAircraft::IndexSituation, situation);
vm.addValue(CAircraft::IndexDistance, distance);
@@ -570,7 +576,7 @@ namespace BlackCore
Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this));
// update
CIndexVariantMap vm({CAircraft::IndexCom1System, CComSystem::IndexActiveFrequency}, frequency.toQVariant());
CPropertyIndexVariantMap vm({CAircraft::IndexCom1System, CComSystem::IndexActiveFrequency}, frequency.toQVariant());
this->m_aircraftsInRange.applyIf(BlackMisc::Predicates::MemberEqual(&CAircraft::getCallsign, callsign), vm);
emit this->changedAircraftsInRange();
}

View File

@@ -140,7 +140,7 @@ namespace BlackCore
QStringList createFsipiCustomPacketData() const;
//! Helper method, add voice capabilites if available
void addVoiceCapabilitiesFromDataFile(BlackMisc::CIndexVariantMap &vm, const BlackMisc::Aviation::CCallsign &callsign);
void addVoiceCapabilitiesFromDataFile(BlackMisc::CPropertyIndexVariantMap &vm, const BlackMisc::Aviation::CCallsign &callsign);
private slots:
void ps_realNameReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &realname);

View File

@@ -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"

View File

@@ -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;
}
/*

View File

@@ -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"

View File

@@ -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());;

View File

@@ -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;

View 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

View 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

View 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

View File

@@ -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);

View File

@@ -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

View File

@@ -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)));

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -37,7 +37,7 @@ namespace BlackSim
CFsxSimulatorSetup() : BlackSim::CSimulatorSetup() {}
//! Constructor
CFsxSimulatorSetup(const BlackMisc::CIndexVariantMap &map) : BlackSim::CSimulatorSetup(map) {}
CFsxSimulatorSetup(const BlackMisc::CPropertyIndexVariantMap &map) : BlackSim::CSimulatorSetup(map) {}
//! Init, to be used where FSX runs
void init();

View File

@@ -28,7 +28,7 @@ namespace BlackSim
return qv.toString();
}
void CSimulatorInfo::setSimulatorSetup(const BlackMisc::CIndexVariantMap &setup)
void CSimulatorInfo::setSimulatorSetup(const BlackMisc::CPropertyIndexVariantMap &setup)
{
this->m_simsetup = setup;
}

View File

@@ -1,7 +1,7 @@
#ifndef BLACKSIM_SIMULATORINFO_H
#define BLACKSIM_SIMULATORINFO_H
#include "blackmisc/indexvariantmap.h"
#include "blackmisc/propertyindexvariantmap.h"
#include "blackmisc/valueobject.h"
namespace BlackSim
@@ -32,7 +32,7 @@ namespace BlackSim
QString getSimulatorSetupValueAsString(int index) const;
//! Set single settings
void setSimulatorSetup(const BlackMisc::CIndexVariantMap &setup);
void setSimulatorSetup(const BlackMisc::CPropertyIndexVariantMap &setup);
//! Short name
const QString &getShortName() const { return m_shortName; }
@@ -112,7 +112,7 @@ namespace BlackSim
BLACK_ENABLE_TUPLE_CONVERSION(CSimulatorInfo)
QString m_fullName;
QString m_shortName;
BlackMisc::CIndexVariantMap m_simsetup; //!< allows to access simulator keys requried on remote side
BlackMisc::CPropertyIndexVariantMap m_simsetup; //!< allows to access simulator keys requried on remote side
};
}

View File

@@ -2,7 +2,7 @@
namespace BlackSim
{
void CSimulatorSetup::setSettings(const BlackMisc::CIndexVariantMap &map)
void CSimulatorSetup::setSettings(const BlackMisc::CPropertyIndexVariantMap &map)
{
this->m_setup = map;
}

View File

@@ -12,7 +12,7 @@
#ifndef BLACKSIM_SIMSETUP_H
#define BLACKSIM_SIMSETUP_H
#include "blackmisc/indexvariantmap.h"
#include "blackmisc/propertyindexvariantmap.h"
#include <QMap>
#include <QString>
@@ -26,14 +26,14 @@ namespace BlackSim
class CSimulatorSetup
{
protected:
BlackMisc::CIndexVariantMap m_setup; //!< values describing the simulator setup (path, config files)
BlackMisc::CPropertyIndexVariantMap m_setup; //!< values describing the simulator setup (path, config files)
protected:
//! Default constructor
CSimulatorSetup() {}
//! Constructor
CSimulatorSetup(const BlackMisc::CIndexVariantMap &map) : m_setup(map) {}
CSimulatorSetup(const BlackMisc::CPropertyIndexVariantMap &map) : m_setup(map) {}
public:
//! Specific values
@@ -43,10 +43,10 @@ namespace BlackSim
};
//! Settings
BlackMisc::CIndexVariantMap getSettings() const { return this->m_setup;}
BlackMisc::CPropertyIndexVariantMap getSettings() const { return this->m_setup;}
//! Settings
void setSettings(const BlackMisc::CIndexVariantMap &map);
void setSettings(const BlackMisc::CPropertyIndexVariantMap &map);
//! Init, to be used where simulator runs
void init();

View File

@@ -1,6 +1,6 @@
#include "tool.h"
#include "blackcore/context_all_interfaces.h"
#include "blackmisc/indexvariantmap.h"
#include "blackmisc/propertyindexallclasses.h"
#include "blackmisc/avallclasses.h"
#include "blackmisc/pqallquantities.h"
#include "blackmisc/loghandler.h"