QxInvalidValue.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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_VALIDATOR_INVALID_VALUE_H_
  32. #define _QX_VALIDATOR_INVALID_VALUE_H_
  33. #ifdef _MSC_VER
  34. #pragma once
  35. #endif
  36. /*!
  37. * \file QxInvalidValue.h
  38. * \author Lionel Marty
  39. * \ingroup QxValidator
  40. * \brief Invalid value when a property fails to pass a constraint
  41. */
  42. #ifdef _QX_ENABLE_BOOST_SERIALIZATION
  43. #include <boost/serialization/serialization.hpp>
  44. #include <boost/serialization/nvp.hpp>
  45. #endif // _QX_ENABLE_BOOST_SERIALIZATION
  46. #ifndef _QX_NO_JSON
  47. #include <QtCore/qjsonvalue.h>
  48. #endif // _QX_NO_JSON
  49. #include <QxSerialize/boost/QxSerialize_shared_ptr.h>
  50. #include <QxSerialize/Qt/QxSerialize_QString.h>
  51. #include <QxSerialize/Qt/QxSerialize_QVariant.h>
  52. #include <QxSerialize/Qt/QxSerialize_QHash.h>
  53. #include <QxConvert/QxConvert.h>
  54. #include <QxTraits/get_class_name.h>
  55. #include <QxCommon/QxPropertyBag.h>
  56. namespace qx {
  57. class IxValidator;
  58. class QxInvalidValue;
  59. } // namespace qx
  60. QX_DLL_EXPORT QDataStream & operator<< (QDataStream & stream, const qx::QxInvalidValue & t) QX_USED;
  61. QX_DLL_EXPORT QDataStream & operator>> (QDataStream & stream, qx::QxInvalidValue & t) QX_USED;
  62. #ifndef _QX_NO_JSON
  63. namespace qx {
  64. namespace cvt {
  65. namespace detail {
  66. template <> struct QxConvert_ToJson< qx::QxInvalidValue >;
  67. template <> struct QxConvert_FromJson< qx::QxInvalidValue >;
  68. QX_DLL_EXPORT QJsonValue QxConvert_ToJson_Helper(const qx::QxInvalidValue & t, const QString & format) QX_USED;
  69. QX_DLL_EXPORT qx_bool QxConvert_FromJson_Helper(const QJsonValue & j, qx::QxInvalidValue & t, const QString & format) QX_USED;
  70. } // namespace detail
  71. } // namespace cvt
  72. } // namespace qx
  73. #endif // _QX_NO_JSON
  74. namespace qx {
  75. /*!
  76. * \ingroup QxValidator
  77. * \brief qx::QxInvalidValue : invalid value when a property fails to pass a constraint
  78. *
  79. * For more informations about <b>QxValidator module</b>, <a href="https://www.qxorm.com/qxorm_en/faq.html#faq_250" target="_blank">goto the FAQ of QxOrm website</a> :
  80. * <a href="https://www.qxorm.com/qxorm_en/faq.html#faq_250" target="_blank">https://www.qxorm.com/qxorm_en/faq.html#faq_250</a>
  81. */
  82. class QX_DLL_EXPORT QxInvalidValue : public QxPropertyBag
  83. {
  84. #ifdef _QX_ENABLE_BOOST_SERIALIZATION
  85. friend class boost::serialization::access;
  86. #endif // _QX_ENABLE_BOOST_SERIALIZATION
  87. friend QX_DLL_EXPORT QDataStream & ::operator<< (QDataStream & stream, const qx::QxInvalidValue & t);
  88. friend QX_DLL_EXPORT QDataStream & ::operator>> (QDataStream & stream, qx::QxInvalidValue & t);
  89. #ifndef _QX_NO_JSON
  90. friend struct qx::cvt::detail::QxConvert_ToJson< qx::QxInvalidValue >;
  91. friend struct qx::cvt::detail::QxConvert_FromJson< qx::QxInvalidValue >;
  92. friend QX_DLL_EXPORT QJsonValue qx::cvt::detail::QxConvert_ToJson_Helper(const qx::QxInvalidValue & t, const QString & format);
  93. friend QX_DLL_EXPORT qx_bool qx::cvt::detail::QxConvert_FromJson_Helper(const QJsonValue & j, qx::QxInvalidValue & t, const QString & format);
  94. #endif // _QX_NO_JSON
  95. protected:
  96. QString m_sMessage; //!< Message associated to the invalid value
  97. QString m_sPropertyName; //!< Property name failing to pass the constraint
  98. QString m_sPath; //!< Path of property failing to pass the constraint
  99. const IxValidator * m_pValidator; //!< IxValidator class associated to the invalid value
  100. public:
  101. QxInvalidValue();
  102. virtual ~QxInvalidValue();
  103. QString getMessage() const { return m_sMessage; }
  104. QString getPropertyName() const { return m_sPropertyName; }
  105. QString getPath() const { return m_sPath; }
  106. QString getFullName() const;
  107. const IxValidator * getValidator() const;
  108. void setMessage(const QString & s) { m_sMessage = s; }
  109. void setPropertyName(const QString & s) { m_sPropertyName = s; }
  110. void setPath(const QString & s) { m_sPath = s; }
  111. void setValidator(const IxValidator * p);
  112. private:
  113. #ifdef _QX_ENABLE_BOOST_SERIALIZATION
  114. template <class Archive>
  115. void serialize(Archive & ar, const unsigned int file_version)
  116. {
  117. Q_UNUSED(file_version);
  118. ar & boost::serialization::make_nvp("message", m_sMessage);
  119. ar & boost::serialization::make_nvp("property_name", m_sPropertyName);
  120. ar & boost::serialization::make_nvp("path", m_sPath);
  121. ar & boost::serialization::make_nvp("list_property_bag", this->m_lstPropertyBag);
  122. }
  123. #endif // _QX_ENABLE_BOOST_SERIALIZATION
  124. };
  125. } // namespace qx
  126. QX_REGISTER_CLASS_NAME(qx::QxInvalidValue)
  127. #endif // _QX_VALIDATOR_INVALID_VALUE_H_