/* 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_TESTVALUEOBJECT_H #define BLACKMISC_TESTVALUEOBJECT_H #include "blackmisc/propertyindex.h" #include "blackmisc/sequence.h" #include "blackmisc/collection.h" #include "blackmisc/dictionary.h" namespace BlackMisc { //! Test value object class CTestValueObject : public BlackMisc::CValueObject { public: //! Properties by index enum ColumnIndex { IndexName = 10000, IndexDescription, }; //! Default constructor. CTestValueObject() {} //! Constructor. CTestValueObject(const QString &name, const QString &description) : m_name(name), m_description(description) {} //! Get name const QString &getName() const { return m_name; } //! Set name void setName(const QString &name) { m_name = name; } //! Get description const QString &getDescription() const { return m_description; } //! Set description void setDescription(const QString &description) { m_description = description; } //! \copydoc CValueObject::propertyByIndex CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const; //! \copydoc CValueObject::setPropertyByIndex void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index); //! \copydoc CValueObject::convertToQString() QString convertToQString(bool i18n = false) const; private: BLACK_ENABLE_TUPLE_CONVERSION(CTestValueObject) QString m_name; QString m_description; }; //! \cond NO_DOXYGEN struct CNotHashable { int n; bool operator <(const CNotHashable &other) const { return n < other.n; } QString toQString(bool = false) const { return {}; } }; inline QJsonArray &operator <<(QJsonArray &a, const CNotHashable &) { return a; } inline const QJsonValueRef &operator >>(const QJsonValueRef &v, CNotHashable &) { return v; } inline QDBusArgument &operator <<(QDBusArgument &a, const CNotHashable &) { return a; } inline const QDBusArgument &operator >>(const QDBusArgument &a, const CNotHashable &) { return a; } //! \endcond } // namespace BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::CTestValueObject, (o.m_name, o.m_description)) Q_DECLARE_METATYPE(BlackMisc::CTestValueObject) Q_DECLARE_METATYPE(BlackMisc::CCollection) Q_DECLARE_METATYPE(BlackMisc::CSequence) Q_DECLARE_METATYPE(BlackMisc::CNotHashable) // We need to typedef because 'commas' confuse the Q_DECLARE_METATYPE macro // https://bugreports.qt-project.org/browse/QTBUG-11485 typedef BlackMisc::CDictionary CValueObjectDictionary; typedef BlackMisc::CDictionary CValueObjectHashDictionary; typedef BlackMisc::CDictionary CNotHashableDictionary; typedef BlackMisc::CDictionary CNotHashableMapDictionary; Q_DECLARE_METATYPE(CValueObjectDictionary) Q_DECLARE_METATYPE(CNotHashableDictionary) // MSVC has trouble with these checks #if !defined(Q_CC_MSVC) static_assert(std::is_same::value, "Expected CValueObjectDictionary to use QHash"); static_assert(std::is_same::value, "Expected CDictionary to use QMap"); #endif // ! Q_CC_MSVC #endif // guard