From 8724e3dc3ab8d30b78915d2d476b045147a0d5c8 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 28 Dec 2017 18:14:24 +0100 Subject: [PATCH] Ref T172, ecosystem value class --- src/blackmisc/network/ecosystem.cpp | 120 ++++++++++++++++++ src/blackmisc/network/ecosystem.h | 111 ++++++++++++++++ src/blackmisc/network/ecosystemlist.cpp | 37 ++++++ src/blackmisc/network/ecosystemlist.h | 54 ++++++++ src/blackmisc/network/network.h | 2 + .../network/registermetadatanetwork.cpp | 2 + src/blackmisc/propertyindex.h | 25 ++-- 7 files changed, 339 insertions(+), 12 deletions(-) create mode 100644 src/blackmisc/network/ecosystem.cpp create mode 100644 src/blackmisc/network/ecosystem.h create mode 100644 src/blackmisc/network/ecosystemlist.cpp create mode 100644 src/blackmisc/network/ecosystemlist.h diff --git a/src/blackmisc/network/ecosystem.cpp b/src/blackmisc/network/ecosystem.cpp new file mode 100644 index 000000000..711e2e640 --- /dev/null +++ b/src/blackmisc/network/ecosystem.cpp @@ -0,0 +1,120 @@ +/* Copyright (C) 2017 + * 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 "ecosystem.h" +#include "blackmisc/icon.h" +#include "blackmisc/verify.h" +#include "blackmisc/comparefunctions.h" + +namespace BlackMisc +{ + namespace Network + { + QString CEcosystem::convertToQString(bool i18n) const + { + Q_UNUSED(i18n); + return this->getSystemString(); + } + + const CEcosystem &CEcosystem::vatsim() + { + static const CEcosystem e(VATSIM); + return e; + } + + const CEcosystem &CEcosystem::swift() + { + static const CEcosystem e(Swift); + return e; + } + + const CEcosystem &CEcosystem::swiftTest() + { + static const CEcosystem e(SwiftTest); + return e; + } + + const CEcosystem &CEcosystem::privateFsd() + { + static const CEcosystem e(PrivateFSD); + return e; + } + + const QString &CEcosystem::getSystemString() const + { + static const QString u("unknown"); + static const QString v("VATSIM"); + static const QString s("swift"); + static const QString st("swift (testing)"); + static const QString fsd("FSD (private)"); + static const QString no("no system"); + + switch (this->getSystem()) + { + case VATSIM: return v; + case Swift: return s; + case SwiftTest: return st; + case PrivateFSD: return fsd; + case NoSystem: return no; + case Unspecified: + default: return u; + } + } + + CIcon CEcosystem::toIcon() const + { + switch (this->getSystem()) + { + case VATSIM: return CIconList::allIcons().findByIndex(CIcons::NetworkVatsimLogo); + case Swift: return CIconList::allIcons().findByIndex(CIcons::Swift24); + case SwiftTest: return CIconList::allIcons().findByIndex(CIcons::Swift24); + case PrivateFSD: return CIconList::allIcons().findByIndex(CIcons::StandardIconAppAircraft16); + case NoSystem: return CIconList::allIcons().findByIndex(CIcons::StandardIconCrossCircle16); + case Unspecified: + default: return CIconList::allIcons().findByIndex(CIcons::StandardIconUnknown16); + } + } + + CVariant CEcosystem::propertyByIndex(const BlackMisc::CPropertyIndex &index) const + { + if (index.isMyself()) { return CVariant::from(*this); } + const ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexSystem: return CVariant::fromValue(m_system); + case IndexSystemString: return CVariant::fromValue(this->getSystemString()); + default: return CValueObject::propertyByIndex(index); + } + } + + void CEcosystem::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) + { + if (index.isMyself()) { (*this) = variant.to(); return; } + const ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexSystem: m_system = variant.toInt(); break; + default: CValueObject::setPropertyByIndex(index, variant); break; + } + } + + int CEcosystem::comparePropertyByIndex(const CPropertyIndex &index, const CEcosystem &compareValue) const + { + if (index.isMyself()) { return Compare::compare(this->m_system, compareValue.m_system); } + const ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexSystem: return Compare::compare(this->m_system, compareValue.m_system); + default: break; + } + BLACK_VERIFY_X(false, Q_FUNC_INFO, qUtf8Printable("No comparison for index " + index.toQString())); + return 0; + } + } // namespace +} // namespace diff --git a/src/blackmisc/network/ecosystem.h b/src/blackmisc/network/ecosystem.h new file mode 100644 index 000000000..7fdb047e9 --- /dev/null +++ b/src/blackmisc/network/ecosystem.h @@ -0,0 +1,111 @@ +/* Copyright (C) 2017 + * 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_NETWORK_ECOSYSTEM_H +#define BLACKMISC_NETWORK_ECOSYSTEM_H + +#include "blackmisc/blackmiscexport.h" +#include "blackmisc/icon.h" +#include "blackmisc/valueobject.h" +#include "blackmisc/variant.h" + +#include +#include + +namespace BlackMisc +{ + namespace Network + { + //! Ecosystem of server belonging together. + class BLACKMISC_EXPORT CEcosystem : public CValueObject + { + public: + //! Properties by index + enum ColumnIndex + { + IndexSystem = CPropertyIndex::GlobalIndexCEcosystem, + IndexSystemString + }; + + //! Known system + enum System + { + Unspecified, //!< unspecified + NoSystem, //!< no relevant ecosystem + VATSIM, //!< VATSIM + SwiftTest, //!< swift test server + Swift, //!< Future usage + PrivateFSD //!< Private FSD environment + }; + + //! Default constructor + CEcosystem() {} + + //! Constructor + CEcosystem(System s) : m_system(static_cast(s)) {} + + //! Get system + System getSystem() const { return static_cast(m_system); } + + //! Unknown system? + bool isUnspecified() const { return this->getSystem() == Unspecified; } + + //! Is system? + bool isSystem(System s) const { return this->getSystem() == s; } + + //! Set the system + void setSystem(System system) { m_system = static_cast(system); } + + //! Get the system string + const QString &getSystemString() const; + + //! \copydoc BlackMisc::Mixin::Icon::toIcon() + CIcon toIcon() const; + + //! \copydoc BlackMisc::Mixin::Index::propertyByIndex + CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const; + + //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex + void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const CVariant &variant); + + //! Compare by index + int comparePropertyByIndex(const CPropertyIndex &index, const CEcosystem &compareValue) const; + + //! \copydoc BlackMisc::Mixin::String::toQString + QString convertToQString(bool i18n = false) const; + + //! VATSIM eco system + static const CEcosystem &vatsim(); + + //! swift eco system + static const CEcosystem &swift(); + + //! swift test eco system + static const CEcosystem &swiftTest(); + + //! FSD private + static const CEcosystem &privateFsd(); + + private: + int m_system = static_cast(Unspecified); + + BLACK_METACLASS( + CEcosystem, + BLACK_METAMEMBER(system) + ); + }; + } // namespace +} // namespace + +Q_DECLARE_METATYPE(BlackMisc::Network::CEcosystem) +Q_DECLARE_METATYPE(BlackMisc::Network::CEcosystem::System) + +#endif // guard diff --git a/src/blackmisc/network/ecosystemlist.cpp b/src/blackmisc/network/ecosystemlist.cpp new file mode 100644 index 000000000..60001cd32 --- /dev/null +++ b/src/blackmisc/network/ecosystemlist.cpp @@ -0,0 +1,37 @@ +/* Copyright (C) 2017 + * 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 "ecosystemlist.h" + +namespace BlackMisc +{ + namespace Network + { + CEcosystemList::CEcosystemList() { } + + CEcosystemList::CEcosystemList(const CSequence &other) : CSequence(other) + { } + + QStringList CEcosystemList::allSystemStrings() const + { + QStringList l; + for (const CEcosystem &e : *this) + { + l.push_back(e.getSystemString()); + } + return l; + } + + const CEcosystemList &CEcosystemList::allKnownSystems() + { + static const CEcosystemList s({ CEcosystem::vatsim(), CEcosystem::swift(), CEcosystem::swiftTest(), CEcosystem::privateFsd() }); + return s; + } + } // namespace +} // namespace diff --git a/src/blackmisc/network/ecosystemlist.h b/src/blackmisc/network/ecosystemlist.h new file mode 100644 index 000000000..4b862eb06 --- /dev/null +++ b/src/blackmisc/network/ecosystemlist.h @@ -0,0 +1,54 @@ +/* Copyright (C) 2017 + * 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_NETWORK_ECOSYSTEMLIST_H +#define BLACKMISC_NETWORK_ECOSYSTEMLIST_H + +#include "ecosystem.h" +#include "blackmisc/blackmiscexport.h" +#include "blackmisc/collection.h" +#include "blackmisc/sequence.h" +#include "blackmisc/variant.h" +#include +#include + +namespace BlackMisc +{ + namespace Network + { + //! Value object encapsulating a list of voice rooms. + class BLACKMISC_EXPORT CEcosystemList : + public CSequence, + public BlackMisc::Mixin::MetaType + { + public: + BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CEcosystemList) + + //! Default constructor. + CEcosystemList(); + + //! Construct from a base class object. + CEcosystemList(const CSequence &other); + + //! All system strings + QStringList allSystemStrings() const; + + //! All systems + static const CEcosystemList &allKnownSystems(); + }; + } //namespace +} // namespace + +Q_DECLARE_METATYPE(BlackMisc::Network::CEcosystemList) +Q_DECLARE_METATYPE(BlackMisc::CCollection) +Q_DECLARE_METATYPE(BlackMisc::CSequence) + +#endif //guard diff --git a/src/blackmisc/network/network.h b/src/blackmisc/network/network.h index f5ec3d07c..0fdcf7b40 100644 --- a/src/blackmisc/network/network.h +++ b/src/blackmisc/network/network.h @@ -20,6 +20,8 @@ #include "blackmisc/network/authenticateduser.h" #include "blackmisc/network/client.h" #include "blackmisc/network/clientlist.h" +#include "blackmisc/network/ecosystem.h" +#include "blackmisc/network/ecosystemlist.h" #include "blackmisc/network/entityflags.h" #include "blackmisc/network/fsdsetup.h" #include "blackmisc/network/role.h" diff --git a/src/blackmisc/network/registermetadatanetwork.cpp b/src/blackmisc/network/registermetadatanetwork.cpp index 4922011b5..9bb4d35cd 100644 --- a/src/blackmisc/network/registermetadatanetwork.cpp +++ b/src/blackmisc/network/registermetadatanetwork.cpp @@ -19,6 +19,8 @@ namespace BlackMisc CAuthenticatedUser::registerMetadata(); CClient::registerMetadata(); CClientList::registerMetadata(); + CEcosystem::registerMetadata(); + CEcosystemList::registerMetadata(); CEntityFlags::registerMetadata(); CFsdSetup::registerMetadata(); CRemoteFile::registerMetadata(); diff --git a/src/blackmisc/propertyindex.h b/src/blackmisc/propertyindex.h index eb2718907..c7e83c131 100644 --- a/src/blackmisc/propertyindex.h +++ b/src/blackmisc/propertyindex.h @@ -124,18 +124,19 @@ namespace BlackMisc GlobalIndexCUrl = 6700, GlobalIndexCUrlLog = 6800, GlobalIndexCRemoteFile = 6900, - GlobalIndexCAircraftModel = 7000, - GlobalIndexCSimulatedAircraft = 7100, - GlobalIndexCTextMessage = 7200, - GlobalIndexCSimulatorInternals = 7300, - GlobalIndexCSimulatorSettings = 7400, - GlobalIndexCSwiftPluignSettings = 7500, - GlobalIndexCSimulatorMessageSettings = 7600, - GlobalIndexCModelSettings = 7700, - GlobalIndexCAircraftCfgEntries = 7800, - GlobalIndexCDistributor = 7900, - GlobalIndexCMatchingStatisticsEntry = 8000, - GlobalIndexCVPilotModelRule = 9000, + GlobalIndexCEcosystem = 7000, + GlobalIndexCAircraftModel = 8000, + GlobalIndexCSimulatedAircraft = 8100, + GlobalIndexCTextMessage = 8200, + GlobalIndexCSimulatorInternals = 8300, + GlobalIndexCSimulatorSettings = 8400, + GlobalIndexCSwiftPluignSettings = 8500, + GlobalIndexCSimulatorMessageSettings = 8600, + GlobalIndexCModelSettings = 8700, + GlobalIndexCAircraftCfgEntries = 8800, + GlobalIndexCDistributor = 8900, + GlobalIndexCMatchingStatisticsEntry = 9000, + GlobalIndexCVPilotModelRule = 9100, GlobalIndexCVoiceRoom = 10000, GlobalIndexCSettingKeyboardHotkey = 11000, GlobalIndexIDatastoreInteger = 12000,