diff --git a/src/blacksim/simulator.cpp b/src/blacksim/simulator.cpp deleted file mode 100644 index 4fe64bd87..000000000 --- a/src/blacksim/simulator.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#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/simulatorinfo.cpp b/src/blacksim/simulatorinfo.cpp new file mode 100644 index 000000000..1c61fbb46 --- /dev/null +++ b/src/blacksim/simulatorinfo.cpp @@ -0,0 +1,63 @@ +#include "simulatorinfo.h" +#include "blackmisc/blackmiscfreefunctions.h" + +using namespace BlackMisc; + +namespace BlackSim +{ + + CSimulatorInfo::CSimulatorInfo(const QString &shortname, const QString &fullname) : m_fullname(fullname), m_shortname(shortname) + { } + + CSimulatorInfo::CSimulatorInfo() : m_fullname("Unknown"), m_shortname("Unknown") + {} + + uint CSimulatorInfo::getValueHash() const + { + return qHash(TupleConverter::toTuple(*this)); + } + + QString CSimulatorInfo::convertToQString(bool i18n) const + { + Q_UNUSED(i18n); + return QString(this->m_shortname).append(" (").append(this->m_fullname).append(")"); + } + + int CSimulatorInfo::getMetaTypeId() const + { + return qMetaTypeId(); + } + + bool CSimulatorInfo::operator ==(const CSimulatorInfo &other) const + { + if (this == &other) return true; + return TupleConverter::toTuple(*this) == TupleConverter::toTuple(other); + } + + bool CSimulatorInfo::operator !=(const CSimulatorInfo &other) const + { + return !((*this) == other); + } + + int CSimulatorInfo::compareImpl(const BlackMisc::CValueObject &otherBase) const + { + const auto &other = static_cast(otherBase); + return compare(TupleConverter::toTuple(*this), TupleConverter::toTuple(other)); + } + + void CSimulatorInfo::marshallToDbus(QDBusArgument &argument) const + { + argument << TupleConverter::toTuple(*this); + } + + void CSimulatorInfo::unmarshallFromDbus(const QDBusArgument &argument) + { + argument >> TupleConverter::toTuple(*this); + } + + void CSimulatorInfo::registerMetadata() + { + qRegisterMetaType(); + qDBusRegisterMetaType(); + } +} diff --git a/src/blacksim/simulator.h b/src/blacksim/simulatorinfo.h similarity index 59% rename from src/blacksim/simulator.h rename to src/blacksim/simulatorinfo.h index 40b7ab0b0..5bf9d7526 100644 --- a/src/blacksim/simulator.h +++ b/src/blacksim/simulatorinfo.h @@ -1,22 +1,20 @@ -#ifndef BLACKSIM_SIMULATOR_H -#define BLACKSIM_SIMULATOR_H +#ifndef BLACKSIM_SIMULATORINFO_H +#define BLACKSIM_SIMULATORINFO_H #include "blackmisc/valueobject.h" namespace BlackSim { - /*! - * \brief Describing a simulator - */ - class CSimulator : public BlackMisc::CValueObject + //! \brief Describing a simulator + class CSimulatorInfo : public BlackMisc::CValueObject { public: //! \brief Default constructor - CSimulator(); + CSimulatorInfo(); //! \brief Constructor - CSimulator(const QString &shortname, const QString &fullname); + CSimulatorInfo(const QString &shortname, const QString &fullname); //! \brief Unspecified simulator bool isUnspecified() const { return this->m_shortname.isEmpty() || this->m_shortname.startsWith("Unspecified", Qt::CaseInsensitive); } @@ -27,35 +25,40 @@ namespace BlackSim return QVariant::fromValue(*this); } + //! \brief Equal operator == + bool operator ==(const CSimulatorInfo &other) const; + + //! \brief Unequal operator != + bool operator !=(const CSimulatorInfo &other) const; + //! \copydoc CValueObject::getValueHash() virtual uint getValueHash() const override; //! \brief Simulator is FS9 - Microsoft Flight Simulator 2004 - static const CSimulator &FS9() + static const CSimulatorInfo &FS9() { - static CSimulator sim("FS9", "Microsoft Flight Simulator 2004"); + static CSimulatorInfo sim("FS9", "Microsoft Flight Simulator 2004"); return sim; } //! \brief Simulator is FSX Microsoft Flight Simulator X (2006) - static const CSimulator &FSX() + static const CSimulatorInfo &FSX() { - static CSimulator sim("FSX", "Microsoft Flight Simulator X (2006)"); + static CSimulatorInfo sim("FSX", "Microsoft Flight Simulator X (2006)"); return sim; } - //! \brief Simulator is XPlane 10 - static const CSimulator &XP10() + static const CSimulatorInfo &XP10() { - static CSimulator sim("XP10", "XPlane 10 (2011)"); + static CSimulatorInfo sim("XP10", "XPlane 10 (2011)"); return sim; } //! \brief Simulator is unspecified - static const CSimulator &UnspecifiedSim() + static const CSimulatorInfo &UnspecifiedSim() { - static CSimulator sim("Unspecified", "Unspecified"); + static CSimulatorInfo sim("Unspecified", "Unspecified"); return sim; } @@ -70,7 +73,7 @@ namespace BlackSim virtual int getMetaTypeId() const override; //! \copydoc CValueObject::compareImpl - virtual int compareImpl(const CValueObject &other) const override; + virtual int compareImpl(const CValueObject &otherBase) const override; //! \copydoc CValueObject::marshallToDbus() virtual void marshallToDbus(QDBusArgument &argument) const override; @@ -79,11 +82,13 @@ namespace BlackSim virtual void unmarshallFromDbus(const QDBusArgument &argument) override; private: + BLACK_ENABLE_TUPLE_CONVERSION(CSimulatorInfo) QString m_fullname; QString m_shortname; }; } -Q_DECLARE_METATYPE(BlackSim::CSimulator) +BLACK_DECLARE_TUPLE_CONVERSION(BlackSim::CSimulatorInfo, (o.m_fullname, o.m_shortname)) +Q_DECLARE_METATYPE(BlackSim::CSimulatorInfo) #endif // guard