From f3724e7972b2507d6ac1202d702186949e1b106e Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 5 Mar 2014 23:36:15 +0100 Subject: [PATCH] refs #74 , simulator class (describing used simulator). Remark: Maybe this will go to BlackMisc someday --- src/blacksim/simulator.cpp | 61 ++++++++++++++++++++++++++ src/blacksim/simulator.h | 89 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 src/blacksim/simulator.cpp create mode 100644 src/blacksim/simulator.h diff --git a/src/blacksim/simulator.cpp b/src/blacksim/simulator.cpp new file mode 100644 index 000000000..4fe64bd87 --- /dev/null +++ b/src/blacksim/simulator.cpp @@ -0,0 +1,61 @@ +#include "simulator.h" +#include "blackmisc/blackmiscfreefunctions.h" + +namespace BlackSim +{ + + CSimulator::CSimulator(const QString &shortname, const QString &fullname) : m_fullname(fullname), m_shortname(shortname) + { } + + CSimulator::CSimulator() : m_fullname("Unknown"), m_shortname("Unknown") + {} + + uint CSimulator::getValueHash() const + { + QList hashs; + hashs << qHash(this->m_fullname); + hashs << qHash(this->m_shortname); + return BlackMisc::calculateHash(hashs, "CSimulator"); + } + + QString CSimulator::convertToQString(bool i18n) const + { + Q_UNUSED(i18n); + return QString(this->m_shortname).append(" (").append(this->m_fullname).append(")"); + } + + int CSimulator::getMetaTypeId() const + { + return qMetaTypeId(); + } + + int CSimulator::compareImpl(const BlackMisc::CValueObject &other) const + { + const CSimulator &otherObj = static_cast(other); + int result; + + if ((result = this->m_shortname.compare(otherObj.m_shortname, Qt::CaseInsensitive))) return result; + return this->m_shortname.compare(otherObj.m_shortname, Qt::CaseInsensitive); + } + + void CSimulator::marshallToDbus(QDBusArgument &argument) const + { + argument << this->m_fullname; + argument << this->m_shortname; + } + + void CSimulator::unmarshallFromDbus(const QDBusArgument &argument) + { + argument >> this->m_fullname; + argument >> this->m_shortname; + } + + /* + * Register metadata + */ + void CSimulator::registerMetadata() + { + qRegisterMetaType(); + qDBusRegisterMetaType(); + } +} diff --git a/src/blacksim/simulator.h b/src/blacksim/simulator.h new file mode 100644 index 000000000..40b7ab0b0 --- /dev/null +++ b/src/blacksim/simulator.h @@ -0,0 +1,89 @@ +#ifndef BLACKSIM_SIMULATOR_H +#define BLACKSIM_SIMULATOR_H + +#include "blackmisc/valueobject.h" + +namespace BlackSim +{ + + /*! + * \brief Describing a simulator + */ + class CSimulator : public BlackMisc::CValueObject + { + public: + //! \brief Default constructor + CSimulator(); + + //! \brief Constructor + CSimulator(const QString &shortname, const QString &fullname); + + //! \brief Unspecified simulator + bool isUnspecified() const { return this->m_shortname.isEmpty() || this->m_shortname.startsWith("Unspecified", Qt::CaseInsensitive); } + + //! \copydoc CValueObject::toQVariant + virtual QVariant toQVariant() const override + { + return QVariant::fromValue(*this); + } + + //! \copydoc CValueObject::getValueHash() + virtual uint getValueHash() const override; + + //! \brief Simulator is FS9 - Microsoft Flight Simulator 2004 + static const CSimulator &FS9() + { + static CSimulator sim("FS9", "Microsoft Flight Simulator 2004"); + return sim; + } + + //! \brief Simulator is FSX Microsoft Flight Simulator X (2006) + static const CSimulator &FSX() + { + static CSimulator sim("FSX", "Microsoft Flight Simulator X (2006)"); + return sim; + } + + + //! \brief Simulator is XPlane 10 + static const CSimulator &XP10() + { + static CSimulator sim("XP10", "XPlane 10 (2011)"); + return sim; + } + + //! \brief Simulator is unspecified + static const CSimulator &UnspecifiedSim() + { + static CSimulator sim("Unspecified", "Unspecified"); + return sim; + } + + //! \brief Register the metatypes + static void registerMetadata(); + + protected: + //! \copydoc CValueObject::convertToQString + virtual QString convertToQString(bool i18n = false) const override; + + //! \copydoc CValueObject::getMetaTypeId + virtual int getMetaTypeId() const override; + + //! \copydoc CValueObject::compareImpl + virtual int compareImpl(const CValueObject &other) const override; + + //! \copydoc CValueObject::marshallToDbus() + virtual void marshallToDbus(QDBusArgument &argument) const override; + + //! \copydoc CValueObject::unmarshallFromDbus() + virtual void unmarshallFromDbus(const QDBusArgument &argument) override; + + private: + QString m_fullname; + QString m_shortname; + }; +} + +Q_DECLARE_METATYPE(BlackSim::CSimulator) + +#endif // guard