qxtglobal.cpp 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /****************************************************************************
  2. ** Copyright (c) 2006 - 2011, the LibQxt project.
  3. ** See the Qxt AUTHORS file for a list of authors and copyright holders.
  4. ** All rights reserved.
  5. **
  6. ** Redistribution and use in source and binary forms, with or without
  7. ** modification, are permitted provided that the following conditions are met:
  8. ** * Redistributions of source code must retain the above copyright
  9. ** notice, this list of conditions and the following disclaimer.
  10. ** * Redistributions in binary form must reproduce the above copyright
  11. ** notice, this list of conditions and the following disclaimer in the
  12. ** documentation and/or other materials provided with the distribution.
  13. ** * Neither the name of the LibQxt project nor the
  14. ** names of its contributors may be used to endorse or promote products
  15. ** derived from this software without specific prior written permission.
  16. **
  17. ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  18. ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. ** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  21. ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26. ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. **
  28. ** <http://libqxt.org> <foundation@libqxt.org>
  29. *****************************************************************************/
  30. #include "qxtglobal.h"
  31. /*!
  32. \headerfile <QxtGlobal>
  33. \title Global Qxt Declarations
  34. \inmodule QxtCore
  35. \brief The <QxtGlobal> header provides basic declarations and
  36. is included by all other Qxt headers.
  37. */
  38. /*!
  39. \macro QXT_VERSION
  40. \relates <QxtGlobal>
  41. This macro expands a numeric value of the form 0xMMNNPP (MM =
  42. major, NN = minor, PP = patch) that specifies Qxt's version
  43. number. For example, if you compile your application against Qxt
  44. 0.4.0, the QXT_VERSION macro will expand to 0x000400.
  45. You can use QXT_VERSION to use the latest Qt features where
  46. available. For example:
  47. \code
  48. #if QXT_VERSION >= 0x000400
  49. qxtTabWidget->setTabMovementMode(QxtTabWidget::InPlaceMovement);
  50. #endif
  51. \endcode
  52. \sa QXT_VERSION_STR, qxtVersion()
  53. */
  54. /*!
  55. \macro QXT_VERSION_STR
  56. \relates <QxtGlobal>
  57. This macro expands to a string that specifies Qxt's version number
  58. (for example, "0.4.0"). This is the version against which the
  59. application is compiled.
  60. \sa qxtVersion(), QXT_VERSION
  61. */
  62. /*!
  63. \relates <QxtGlobal>
  64. Returns the version number of Qxt at run-time as a string (for
  65. example, "0.4.0"). This may be a different version than the
  66. version the application was compiled against.
  67. \sa QXT_VERSION_STR
  68. */
  69. const char * qxtVersion()
  70. {
  71. return QXT_VERSION_STR;
  72. }
  73. /*!
  74. \headerfile <QxtPimpl>
  75. \title The Qxt private implementation
  76. \inmodule QxtCore
  77. \brief The <QxtPimpl> header provides tools for hiding
  78. details of a class.
  79. Application code generally doesn't have to be concerned about hiding its
  80. implementation details, but when writing library code it is important to
  81. maintain a constant interface, both source and binary. Maintaining a constant
  82. source interface is easy enough, but keeping the binary interface constant
  83. means moving implementation details into a private class. The PIMPL, or
  84. d-pointer, idiom is a common method of implementing this separation. QxtPimpl
  85. offers a convenient way to connect the public and private sides of your class.
  86. \section1 Getting Started
  87. Before you declare the public class, you need to make a forward declaration
  88. of the private class. The private class must have the same name as the public
  89. class, followed by the word Private. For example, a class named MyTest would
  90. declare the private class with:
  91. \code
  92. class MyTestPrivate;
  93. \endcode
  94. \section1 The Public Class
  95. Generally, you shouldn't keep any data members in the public class without a
  96. good reason. Functions that are part of the public interface should be declared
  97. in the public class, and functions that need to be available to subclasses (for
  98. calling or overriding) should be in the protected section of the public class.
  99. To connect the private class to the public class, include the
  100. QXT_DECLARE_PRIVATE macro in the private section of the public class. In the
  101. example above, the private class is connected as follows:
  102. \code
  103. private:
  104. QXT_DECLARE_PRIVATE(MyTest)
  105. \endcode
  106. Additionally, you must include the QXT_INIT_PRIVATE macro in the public class's
  107. constructor. Continuing with the MyTest example, your constructor might look
  108. like this:
  109. \code
  110. MyTest::MyTest() {
  111. // initialization
  112. QXT_INIT_PRIVATE(MyTest);
  113. }
  114. \endcode
  115. \section1 The Private Class
  116. As mentioned above, data members should usually be kept in the private class.
  117. This allows the memory layout of the private class to change without breaking
  118. binary compatibility for the public class. Functions that exist only as
  119. implementation details, or functions that need access to private data members,
  120. should be implemented here.
  121. To define the private class, inherit from the template QxtPrivate class, and
  122. include the QXT_DECLARE_PUBLIC macro in its public section. The template
  123. parameter should be the name of the public class. For example:
  124. \code
  125. class MyTestPrivate : public QxtPrivate<MyTest> {
  126. public:
  127. MyTestPrivate();
  128. QXT_DECLARE_PUBLIC(MyTest)
  129. };
  130. \endcode
  131. \section1 Accessing Private Members
  132. Use the qxt_d() function (actually a function-like object) from functions in
  133. the public class to access the private class. Similarly, functions in the
  134. private class can invoke functions in the public class by using the qxt_p()
  135. function (this one's actually a function).
  136. For example, assume that MyTest has methods named getFoobar and doBaz(),
  137. and MyTestPrivate has a member named foobar and a method named doQuux().
  138. The code might resemble this example:
  139. \code
  140. int MyTest::getFoobar() {
  141. return qxt_d().foobar;
  142. }
  143. void MyTestPrivate::doQuux() {
  144. qxt_p().doBaz(foobar);
  145. }
  146. \endcode
  147. */
  148. /*!
  149. * \macro QXT_DECLARE_PRIVATE(PUB)
  150. * \relates <QxtPimpl>
  151. * Declares that a public class has a related private class.
  152. *
  153. * This shuold be put in the private section of the public class. The
  154. * parameter \a PUB must be the name of the public class.
  155. */
  156. /*!
  157. * \macro QXT_DECLARE_PUBLIC(PUB)
  158. * \relates <QxtPimpl>
  159. * Declares that a private class has a related public class named \a PUB.
  160. *
  161. * This may be put anywhere in the declaration of the private class. The parameter is the name of the public class.
  162. */
  163. /*!
  164. * \macro QXT_INIT_PRIVATE(PUB)
  165. * \relates <QxtPimpl>
  166. * Initializes resources owned by the private class.
  167. *
  168. * This should be called from the public class's constructor,
  169. * before qxt_d() is used for the first time. The parameter \a PUB must be
  170. * the name of the public class.
  171. */
  172. /*!
  173. * \macro QXT_D(PUB)
  174. * \relates <QxtPimpl>
  175. * Returns a reference in the current scope named "d" to the private class
  176. * associated with the public class \a PUB.
  177. *
  178. * This function is only available in a class using QXT_DECLARE_PRIVATE().
  179. */
  180. /*!
  181. * \macro QXT_P(PUB)
  182. * \relates <QxtPimpl>
  183. * Creates a reference in the current scope named "q" to the public class
  184. * named \a PUB.
  185. *
  186. * This macro only works in a class using QXT_DECLARE_PUBLIC().
  187. */
  188. /*!
  189. * \fn QxtPrivate<PUB>& PUB::qxt_d()
  190. * \relates <QxtPimpl>
  191. * Returns a reference to the private class.
  192. *
  193. * This function is only available in a class using \a QXT_DECLARE_PRIVATE.
  194. */
  195. /*!
  196. * \fn const QxtPrivate<PUB>& PUB::qxt_d() const
  197. * \relates <QxtPimpl>
  198. * Returns a const reference to the private class.
  199. *
  200. * This function is only available in a class using \a QXT_DECLARE_PRIVATE.
  201. * This overload will be automatically used in const functions.
  202. */
  203. /*!
  204. * \fn PUB& QxtPrivate::qxt_p()
  205. * \relates <QxtPimpl>
  206. * Returns a reference to the public class.
  207. *
  208. * This function is only available in a class using QXT_DECLARE_PUBLIC().
  209. */
  210. /*!
  211. * \fn const PUB& QxtPrivate::qxt_p() const
  212. * \relates <QxtPimpl>
  213. * Returns a const reference to the public class.
  214. *
  215. * This function is only available in a class using QXT_DECLARE_PUBLIC().
  216. * This overload will be automatically used in const functions.
  217. */