mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 21:15:33 +08:00
Ref T172, ecosystem value class
This commit is contained in:
120
src/blackmisc/network/ecosystem.cpp
Normal file
120
src/blackmisc/network/ecosystem.cpp
Normal file
@@ -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<ColumnIndex>();
|
||||
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<CEcosystem>(); return; }
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
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<ColumnIndex>();
|
||||
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
|
||||
111
src/blackmisc/network/ecosystem.h
Normal file
111
src/blackmisc/network/ecosystem.h
Normal file
@@ -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 <QMetaType>
|
||||
#include <QString>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Network
|
||||
{
|
||||
//! Ecosystem of server belonging together.
|
||||
class BLACKMISC_EXPORT CEcosystem : public CValueObject<CEcosystem>
|
||||
{
|
||||
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<int>(s)) {}
|
||||
|
||||
//! Get system
|
||||
System getSystem() const { return static_cast<System>(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<int>(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<int>(Unspecified);
|
||||
|
||||
BLACK_METACLASS(
|
||||
CEcosystem,
|
||||
BLACK_METAMEMBER(system)
|
||||
);
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Network::CEcosystem)
|
||||
Q_DECLARE_METATYPE(BlackMisc::Network::CEcosystem::System)
|
||||
|
||||
#endif // guard
|
||||
37
src/blackmisc/network/ecosystemlist.cpp
Normal file
37
src/blackmisc/network/ecosystemlist.cpp
Normal file
@@ -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<CEcosystem>(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
|
||||
54
src/blackmisc/network/ecosystemlist.h
Normal file
54
src/blackmisc/network/ecosystemlist.h
Normal file
@@ -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 <QStringList>
|
||||
#include <QMetaType>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Network
|
||||
{
|
||||
//! Value object encapsulating a list of voice rooms.
|
||||
class BLACKMISC_EXPORT CEcosystemList :
|
||||
public CSequence<CEcosystem>,
|
||||
public BlackMisc::Mixin::MetaType<CEcosystemList>
|
||||
{
|
||||
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<BlackMisc::Network::CEcosystem>)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::Network::CEcosystem>)
|
||||
|
||||
#endif //guard
|
||||
@@ -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"
|
||||
|
||||
@@ -19,6 +19,8 @@ namespace BlackMisc
|
||||
CAuthenticatedUser::registerMetadata();
|
||||
CClient::registerMetadata();
|
||||
CClientList::registerMetadata();
|
||||
CEcosystem::registerMetadata();
|
||||
CEcosystemList::registerMetadata();
|
||||
CEntityFlags::registerMetadata();
|
||||
CFsdSetup::registerMetadata();
|
||||
CRemoteFile::registerMetadata();
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user