QxDataMember_QObject.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /****************************************************************************
  2. **
  3. ** https://www.qxorm.com/
  4. ** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
  5. **
  6. ** This file is part of the QxOrm library
  7. **
  8. ** This software is provided 'as-is', without any express or implied
  9. ** warranty. In no event will the authors be held liable for any
  10. ** damages arising from the use of this software
  11. **
  12. ** Commercial Usage
  13. ** Licensees holding valid commercial QxOrm licenses may use this file in
  14. ** accordance with the commercial license agreement provided with the
  15. ** Software or, alternatively, in accordance with the terms contained in
  16. ** a written agreement between you and Lionel Marty
  17. **
  18. ** GNU General Public License Usage
  19. ** Alternatively, this file may be used under the terms of the GNU
  20. ** General Public License version 3.0 as published by the Free Software
  21. ** Foundation and appearing in the file 'license.gpl3.txt' included in the
  22. ** packaging of this file. Please review the following information to
  23. ** ensure the GNU General Public License version 3.0 requirements will be
  24. ** met : http://www.gnu.org/copyleft/gpl.html
  25. **
  26. ** If you are unsure which license is appropriate for your use, or
  27. ** if you have questions regarding the use of this file, please contact :
  28. ** contact@qxorm.com
  29. **
  30. ****************************************************************************/
  31. #ifndef _QX_DATA_MEMBER_QOBJECT_H_
  32. #define _QX_DATA_MEMBER_QOBJECT_H_
  33. #ifdef _MSC_VER
  34. #pragma once
  35. #endif
  36. /*!
  37. * \file QxDataMember_QObject.h
  38. * \author Lionel Marty
  39. * \ingroup QxDataMember
  40. * \brief Connect Qt introspection engine (based on QObject class, with QMetaObject type) to QxOrm library introspection engine
  41. */
  42. #include <QtCore/qmetaobject.h>
  43. #include <QtCore/qmetatype.h>
  44. #include <QxDataMember/IxDataMember.h>
  45. #include <QxSerialize/Qt/QxSerialize_QString.h>
  46. #include <QxSerialize/Qt/QxSerialize_QVariant.h>
  47. #define QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(ArchiveInput, ArchiveOutput) \
  48. virtual void toArchive(const void * pOwner, ArchiveOutput & ar) const; \
  49. virtual void fromArchive(void * pOwner, ArchiveInput & ar);
  50. namespace qx {
  51. /*!
  52. * \ingroup QxDataMember
  53. * \brief qx::QxDataMember_QObject : connect Qt introspection engine (based on QObject class, with QMetaObject type) to QxOrm library introspection engine
  54. */
  55. class QX_DLL_EXPORT QxDataMember_QObject : public IxDataMember
  56. {
  57. protected:
  58. const QMetaObject * m_metaObject; //!< Meta-object from introspection engine of Qt library (& MyQObject::staticMetaObject)
  59. QMetaProperty m_metaProperty; //!< Meta-property from introspection engine of Qt library
  60. public:
  61. QxDataMember_QObject(const QMetaObject * pMetaObject, const QString & sKey);
  62. virtual ~QxDataMember_QObject() { ; }
  63. virtual bool isEqual(const void * pOwner1, const void * pOwner2) const;
  64. virtual QVariant toVariant(const void * pOwner, const QString & sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) const;
  65. virtual qx_bool fromVariant(void * pOwner, const QVariant & v, const QString & sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context);
  66. virtual QString getType() const;
  67. #ifndef _QX_NO_JSON
  68. virtual QJsonValue toJson(const void * pOwner, const QString & sFormat) const;
  69. virtual qx_bool fromJson(void * pOwner, const QJsonValue & j, const QString & sFormat);
  70. #endif // _QX_NO_JSON
  71. public:
  72. #ifdef _QX_ENABLE_BOOST_SERIALIZATION
  73. #if _QX_SERIALIZE_POLYMORPHIC
  74. QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::polymorphic_iarchive, boost::archive::polymorphic_oarchive)
  75. #endif // _QX_SERIALIZE_POLYMORPHIC
  76. #if _QX_SERIALIZE_BINARY
  77. QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::binary_iarchive, boost::archive::binary_oarchive)
  78. #endif // _QX_SERIALIZE_BINARY
  79. #if _QX_SERIALIZE_TEXT
  80. QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::text_iarchive, boost::archive::text_oarchive)
  81. #endif // _QX_SERIALIZE_TEXT
  82. #if _QX_SERIALIZE_XML
  83. QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::xml_iarchive, boost::archive::xml_oarchive)
  84. #endif // _QX_SERIALIZE_XML
  85. #if _QX_SERIALIZE_PORTABLE_BINARY
  86. QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(eos::portable_iarchive, eos::portable_oarchive)
  87. #endif // _QX_SERIALIZE_PORTABLE_BINARY
  88. #if _QX_SERIALIZE_WIDE_BINARY
  89. QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::binary_wiarchive, boost::archive::binary_woarchive)
  90. #endif // _QX_SERIALIZE_WIDE_BINARY
  91. #if _QX_SERIALIZE_WIDE_TEXT
  92. QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::text_wiarchive, boost::archive::text_woarchive)
  93. #endif // _QX_SERIALIZE_WIDE_TEXT
  94. #if _QX_SERIALIZE_WIDE_XML
  95. QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::xml_wiarchive, boost::archive::xml_woarchive)
  96. #endif // _QX_SERIALIZE_WIDE_XML
  97. #endif // _QX_ENABLE_BOOST_SERIALIZATION
  98. protected:
  99. virtual qx::any getDataPtr(const void * pOwner) const;
  100. virtual qx::any getDataPtr(void * pOwner);
  101. virtual void * getDataVoidPtr(const void * pOwner) const;
  102. virtual void * getDataVoidPtr(void * pOwner);
  103. };
  104. } // namespace qx
  105. #endif // _QX_DATA_MEMBER_QOBJECT_H_