layout.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /******************************************************************************
  2. *
  3. * package: Log4Qt
  4. * file: layout.h
  5. * created: September 2007
  6. * author: Martin Heinrich
  7. *
  8. *
  9. * Copyright 2007 Martin Heinrich
  10. *
  11. * Licensed under the Apache License, Version 2.0 (the "License");
  12. * you may not use this file except in compliance with the License.
  13. * You may obtain a copy of the License at
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  17. * Unless required by applicable law or agreed to in writing, software
  18. * distributed under the License is distributed on an "AS IS" BASIS,
  19. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. * See the License for the specific language governing permissions and
  21. * limitations under the License.
  22. *
  23. ******************************************************************************/
  24. #ifndef LOG4QT_LAYOUT_H
  25. #define LOG4QT_LAYOUT_H
  26. /******************************************************************************
  27. * Dependencies
  28. ******************************************************************************/
  29. #include "log4qt/helpers/logobject.h"
  30. #include "log4qt/helpers/logobjectptr.h"
  31. #include "log4qt/log4qt.h"
  32. /******************************************************************************
  33. * Declarations
  34. ******************************************************************************/
  35. namespace Log4Qt
  36. {
  37. class LoggingEvent;
  38. /*!
  39. * \brief The class Layout is the base class for all layouts.
  40. *
  41. * \note The ownership and lifetime of objects of this class are managed. See
  42. * \ref Ownership "Object ownership" for more details.
  43. */
  44. class Layout : public LogObject
  45. {
  46. Q_OBJECT
  47. /*!
  48. * The property holds the content type of the layout.
  49. *
  50. * \sa contentType()
  51. */
  52. Q_PROPERTY(QString footercontentType READ contentType)
  53. /*!
  54. * The property holds the footer used by the layout.
  55. *
  56. * \sa footer(), setFooter()
  57. */
  58. Q_PROPERTY(QString footer READ footer WRITE setFooter)
  59. /*!
  60. * The property holds the header used by the layout.
  61. *
  62. * \sa header(), setHeader()
  63. */
  64. Q_PROPERTY(QString header READ header WRITE setHeader)
  65. public:
  66. Layout(QObject *pParent = 0);
  67. virtual ~Layout();
  68. private:
  69. Layout(const Layout &rOther); // Not implemented
  70. Layout &operator=(const Layout &rOther); // Not implemented
  71. public:
  72. virtual QString contentType() const;
  73. QString footer() const;
  74. QString header() const;
  75. // JAVA: virtual bool ignoresThrowable() const;
  76. QString name() const;
  77. void setFooter(const QString &rFooter);
  78. void setHeader(const QString &rHeader);
  79. void setName(const QString &rName);
  80. // JAVA: void setIgnoresThrowable(bool) const;
  81. virtual void activateOptions();
  82. virtual QString format(const LoggingEvent &rEvent) = 0;
  83. /*!
  84. * Returns the end of line seperator for the operating system.
  85. *
  86. * Windows: \\r\\n
  87. * Mac: \\r
  88. * UNIX: \\n
  89. */
  90. static QString endOfLine();
  91. // Member variables
  92. private:
  93. QString mFooter;
  94. QString mHeader;
  95. };
  96. /**************************************************************************
  97. * Operators, Helper
  98. **************************************************************************/
  99. /**************************************************************************
  100. * Inline
  101. **************************************************************************/
  102. inline Layout::Layout(QObject *pParent) :
  103. LogObject(pParent)
  104. {}
  105. inline Layout::~Layout()
  106. {}
  107. inline QString Layout::footer() const
  108. { return mFooter; }
  109. inline QString Layout::header() const
  110. { return mHeader; }
  111. inline QString Layout::name() const
  112. { return objectName(); }
  113. inline void Layout::setFooter(const QString &rFooter)
  114. { mFooter = rFooter; }
  115. inline void Layout::setHeader(const QString &rHeader)
  116. { mHeader = rHeader; }
  117. inline void Layout::setName(const QString &rName)
  118. { setObjectName(rName); }
  119. } // namespace Log4Qt
  120. // Q_DECLARE_TYPEINFO(Log4Qt::Layout, Q_COMPLEX_TYPE); // Use default
  121. Q_DECLARE_TYPEINFO(Log4Qt::LogObjectPtr<Log4Qt::Layout>, Q_MOVABLE_TYPE);
  122. #endif // LOG4QT_LAYOUT_H