diff --git a/samples/blackmiscdbus/servicetool.cpp b/samples/blackmiscdbus/servicetool.cpp index feb09f114..fa121219c 100644 --- a/samples/blackmiscdbus/servicetool.cpp +++ b/samples/blackmiscdbus/servicetool.cpp @@ -338,7 +338,7 @@ namespace BlackMiscTest pi = testserviceInterface.pingPropertyIndex(pi); qDebug() << "Pinged properties via interface" << pi; - CIndexVariantMap ivm; + CPropertyIndexVariantMap ivm; ivm.addValue(1, "one"); ivm.addValue(2, "two"); ivm.addValue(3, "three"); @@ -399,7 +399,7 @@ namespace BlackMiscTest // Value map qDebug() << "----------------- index variant map ----------------"; - CIndexVariantMap valueMap; + CPropertyIndexVariantMap valueMap; valueMap.addValue(1, 111.222); valueMap.addValue(2, callsign); valueMap.addValue(3, alt); diff --git a/samples/blackmiscdbus/testservice.cpp b/samples/blackmiscdbus/testservice.cpp index c6176091f..6037398d3 100644 --- a/samples/blackmiscdbus/testservice.cpp +++ b/samples/blackmiscdbus/testservice.cpp @@ -196,7 +196,7 @@ namespace BlackMiscTest /* * Receive value map */ - void Testservice::receiveValueMap(const BlackMisc::CIndexVariantMap &valueMap) const + void Testservice::receiveValueMap(const BlackMisc::CPropertyIndexVariantMap &valueMap) const { qDebug() << "Pid:" << ServiceTool::getPid() << "Received value map:" << valueMap; } @@ -269,7 +269,7 @@ namespace BlackMiscTest /* * Ping index variant map */ - CIndexVariantMap Testservice::pingIndexVariantMap(const CIndexVariantMap &indexVariantMap) + CPropertyIndexVariantMap Testservice::pingIndexVariantMap(const CPropertyIndexVariantMap &indexVariantMap) { qDebug() << "Pid:" << ServiceTool::getPid() << "ping properties:" << indexVariantMap; return indexVariantMap; diff --git a/samples/blackmiscdbus/testservice.h b/samples/blackmiscdbus/testservice.h index 8f2eafa5a..ef1d40807 100644 --- a/samples/blackmiscdbus/testservice.h +++ b/samples/blackmiscdbus/testservice.h @@ -99,7 +99,7 @@ namespace BlackMiscTest void receiveAtcStationList(const BlackMisc::Aviation::CAtcStationList &atcStationList) const; //! Receive an value map - void receiveValueMap(const BlackMisc::CIndexVariantMap &valueMap) const; + void receiveValueMap(const BlackMisc::CPropertyIndexVariantMap &valueMap) const; //! Receive speed BlackMisc::PhysicalQuantities::CSpeed pingSpeed(const BlackMisc::PhysicalQuantities::CSpeed &speed); @@ -129,7 +129,7 @@ namespace BlackMiscTest BlackMisc::CPropertyIndex pingPropertyIndex(const BlackMisc::CPropertyIndex &properties); //! Ping index variant map - BlackMisc::CIndexVariantMap pingIndexVariantMap(const BlackMisc::CIndexVariantMap &indexVariantMap); + BlackMisc::CPropertyIndexVariantMap pingIndexVariantMap(const BlackMisc::CPropertyIndexVariantMap &indexVariantMap); //! Ping client BlackMisc::Network::CClient pingClient(const BlackMisc::Network::CClient &client); diff --git a/samples/blackmiscdbus/testservice_interface.h b/samples/blackmiscdbus/testservice_interface.h index ec5f8c494..64b44e4ba 100644 --- a/samples/blackmiscdbus/testservice_interface.h +++ b/samples/blackmiscdbus/testservice_interface.h @@ -150,7 +150,7 @@ namespace BlackMiscTest return asyncCallWithArgumentList(QLatin1String("pingPropertyIndex"), argumentList); } - inline QDBusPendingReply pingIndexVariantMap(BlackMisc::CIndexVariantMap indexVariantMap) + inline QDBusPendingReply pingIndexVariantMap(BlackMisc::CPropertyIndexVariantMap indexVariantMap) { QList argumentList; argumentList << indexVariantMap.toQVariant(); @@ -262,7 +262,7 @@ namespace BlackMiscTest return asyncCallWithArgumentList(QLatin1String("receiveTransponder"), argumentList); } - inline QDBusPendingReply<> receiveValueMap(BlackMisc::CIndexVariantMap valueMap) + inline QDBusPendingReply<> receiveValueMap(BlackMisc::CPropertyIndexVariantMap valueMap) { QList argumentList; argumentList << QVariant::fromValue(valueMap); diff --git a/src/blackcore/airspace_monitor.cpp b/src/blackcore/airspace_monitor.cpp index 71823b266..3d119a969 100644 --- a/src/blackcore/airspace_monitor.cpp +++ b/src/blackcore/airspace_monitor.cpp @@ -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(); } diff --git a/src/blackcore/airspace_monitor.h b/src/blackcore/airspace_monitor.h index 209a2c763..3d7d5f095 100644 --- a/src/blackcore/airspace_monitor.h +++ b/src/blackcore/airspace_monitor.h @@ -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); diff --git a/src/blackmisc/blackmiscallvalueclasses.h b/src/blackmisc/blackmiscallvalueclasses.h index 7a1924731..84b2accdd 100644 --- a/src/blackmisc/blackmiscallvalueclasses.h +++ b/src/blackmisc/blackmiscallvalueclasses.h @@ -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" diff --git a/src/blackmisc/blackmiscfreefunctions.cpp b/src/blackmisc/blackmiscfreefunctions.cpp index d6ba2081f..3f06a6f53 100644 --- a/src/blackmisc/blackmiscfreefunctions.cpp +++ b/src/blackmisc/blackmiscfreefunctions.cpp @@ -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 #include - /* * 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; } /* diff --git a/src/blackmisc/containerbase.h b/src/blackmisc/containerbase.h index 20b78c767..1c0ef1a46 100644 --- a/src/blackmisc/containerbase.h +++ b/src/blackmisc/containerbase.h @@ -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" diff --git a/src/blackmisc/nwclient.cpp b/src/blackmisc/nwclient.cpp index b91527e06..71b347997 100644 --- a/src/blackmisc/nwclient.cpp +++ b/src/blackmisc/nwclient.cpp @@ -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(); + this->m_capabilities = variant.value(); break; case IndexModel: this->m_model.setPropertyByIndex(variant, index.copyFrontRemoved());; diff --git a/src/blackmisc/nwclient.h b/src/blackmisc/nwclient.h index 14c89a3b6..eefceef07 100644 --- a/src/blackmisc/nwclient.h +++ b/src/blackmisc/nwclient.h @@ -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; diff --git a/src/blackmisc/propertyindexallclasses.h b/src/blackmisc/propertyindexallclasses.h new file mode 100644 index 000000000..6a7d02219 --- /dev/null +++ b/src/blackmisc/propertyindexallclasses.h @@ -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 diff --git a/src/blackmisc/propertyindexlist.cpp b/src/blackmisc/propertyindexlist.cpp new file mode 100644 index 000000000..88bdcd91c --- /dev/null +++ b/src/blackmisc/propertyindexlist.cpp @@ -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 &other) : + CSequence(other) + { } + + /* + * Register metadata + */ + void CPropertyIndexList::registerMetadata() + { + qRegisterMetaType>(); + qDBusRegisterMetaType>(); + qRegisterMetaType>(); + qDBusRegisterMetaType>(); + qRegisterMetaType(); + qDBusRegisterMetaType(); + } + +} // namespace diff --git a/src/blackmisc/propertyindexlist.h b/src/blackmisc/propertyindexlist.h new file mode 100644 index 000000000..343d1b8d6 --- /dev/null +++ b/src/blackmisc/propertyindexlist.h @@ -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 + +namespace BlackMisc +{ + /*! + * Value object encapsulating a list of property indexes. + */ + class CPropertyIndexList : public CSequence + { + public: + //! Default constructor. + CPropertyIndexList(); + + //! Construct from a base class object. + CPropertyIndexList(const CSequence &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) +Q_DECLARE_METATYPE(BlackMisc::CSequence) + +#endif //guard diff --git a/src/blackmisc/indexvariantmap.cpp b/src/blackmisc/propertyindexvariantmap.cpp similarity index 64% rename from src/blackmisc/indexvariantmap.cpp rename to src/blackmisc/propertyindexvariantmap.cpp index e1b19b76d..f9c9875be 100644 --- a/src/blackmisc/indexvariantmap.cpp +++ b/src/blackmisc/propertyindexvariantmap.cpp @@ -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(); + return qMetaTypeId(); } /* * is a */ - bool CIndexVariantMap::isA(int metaTypeId) const + bool CPropertyIndexVariantMap::isA(int metaTypeId) const { - if (metaTypeId == qMetaTypeId()) { return true; } + if (metaTypeId == qMetaTypeId()) { 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 indexes; QList 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(); - qDBusRegisterMetaType(); + qRegisterMetaType(); + qDBusRegisterMetaType(); } /* * 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); diff --git a/src/blackmisc/indexvariantmap.h b/src/blackmisc/propertyindexvariantmap.h similarity index 81% rename from src/blackmisc/indexvariantmap.h rename to src/blackmisc/propertyindexvariantmap.h index e810edb1f..cd72c8ed8 100644 --- a/src/blackmisc/indexvariantmap.h +++ b/src/blackmisc/propertyindexvariantmap.h @@ -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 #include -#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 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 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 &map() const { return this->m_values; } @@ -102,6 +107,7 @@ namespace BlackMisc static void registerMetadata(); protected: + QMap 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 diff --git a/src/blackmisc/range.h b/src/blackmisc/range.h index 24bfcdbec..d1b781a85 100644 --- a/src/blackmisc/range.h +++ b/src/blackmisc/range.h @@ -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 @@ -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>; /*! @@ -268,7 +268,7 @@ namespace BlackMisc } template - auto CRangeBase::findBy(CIndexVariantMap valueMap) const + auto CRangeBase::findBy(CPropertyIndexVariantMap valueMap) const -> CRange> { return findBy(BlackMisc::Predicates::Equals(std::move(valueMap))); diff --git a/src/blackmisc/valueobject.cpp b/src/blackmisc/valueobject.cpp index 8705c4cdb..292a44584 100644 --- a/src/blackmisc/valueobject.cpp +++ b/src/blackmisc/valueobject.cpp @@ -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); } diff --git a/src/blackmisc/valueobject.h b/src/blackmisc/valueobject.h index d80401130..7ab11c7b5 100644 --- a/src/blackmisc/valueobject.h +++ b/src/blackmisc/valueobject.h @@ -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 friend typename std::enable_if < std::is_base_of::value &&! PhysicalQuantities::IsQuantity::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; diff --git a/src/blacksim/fsx/fsxsimulatorsetup.h b/src/blacksim/fsx/fsxsimulatorsetup.h index 3fac6989f..c3496080a 100644 --- a/src/blacksim/fsx/fsxsimulatorsetup.h +++ b/src/blacksim/fsx/fsxsimulatorsetup.h @@ -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(); diff --git a/src/blacksim/simulatorinfo.cpp b/src/blacksim/simulatorinfo.cpp index ef34de23e..7ae2506e0 100644 --- a/src/blacksim/simulatorinfo.cpp +++ b/src/blacksim/simulatorinfo.cpp @@ -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; } diff --git a/src/blacksim/simulatorinfo.h b/src/blacksim/simulatorinfo.h index 1fb7f8b9e..8a5da01b3 100644 --- a/src/blacksim/simulatorinfo.h +++ b/src/blacksim/simulatorinfo.h @@ -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 }; } diff --git a/src/blacksim/simulatorsetup.cpp b/src/blacksim/simulatorsetup.cpp index abb93775a..3b6bd9abf 100644 --- a/src/blacksim/simulatorsetup.cpp +++ b/src/blacksim/simulatorsetup.cpp @@ -2,7 +2,7 @@ namespace BlackSim { - void CSimulatorSetup::setSettings(const BlackMisc::CIndexVariantMap &map) + void CSimulatorSetup::setSettings(const BlackMisc::CPropertyIndexVariantMap &map) { this->m_setup = map; } diff --git a/src/blacksim/simulatorsetup.h b/src/blacksim/simulatorsetup.h index 67bf060e0..70b34ac6c 100644 --- a/src/blacksim/simulatorsetup.h +++ b/src/blacksim/simulatorsetup.h @@ -12,7 +12,7 @@ #ifndef BLACKSIM_SIMSETUP_H #define BLACKSIM_SIMSETUP_H -#include "blackmisc/indexvariantmap.h" +#include "blackmisc/propertyindexvariantmap.h" #include #include @@ -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(); diff --git a/src/swiftcore/tool.cpp b/src/swiftcore/tool.cpp index e15331899..d2c7c3e7b 100644 --- a/src/swiftcore/tool.cpp +++ b/src/swiftcore/tool.cpp @@ -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" diff --git a/tests/blackmisc/testvariantandmap.cpp b/tests/blackmisc/testvariantandmap.cpp index ba0566929..9742a3be8 100644 --- a/tests/blackmisc/testvariantandmap.cpp +++ b/tests/blackmisc/testvariantandmap.cpp @@ -5,7 +5,7 @@ #include "testvariantandmap.h" #include "blackmisc/avatcstation.h" -#include "blackmisc/indexvariantmap.h" +#include "blackmisc/propertyindexallclasses.h" #include "blackmisc/tuple.h" #include #include @@ -85,10 +85,10 @@ namespace BlackMiscTest geoPos, CLength(50, CLengthUnit::km()), false, dtFrom, dtUntil); // value maps - CIndexVariantMap vmWildcard(true); - CIndexVariantMap vmNoWildcard(false); - CIndexVariantMap vm; - CIndexVariantMap vmCopy(vmWildcard); + CPropertyIndexVariantMap vmWildcard(true); + CPropertyIndexVariantMap vmNoWildcard(false); + CPropertyIndexVariantMap vm; + CPropertyIndexVariantMap vmCopy(vmWildcard); // remark: Shortcoming here, as the callsign will automatically set for user in station // I have to set this as well, otherwise, not match.