Parcourir la source

Add code example to the Qt Pimpl tutorial

Julien Finet il y a 15 ans
Parent
commit
bd3816f4c0
1 fichiers modifiés avec 59 ajouts et 0 suppressions
  1. 59 0
      Libs/Core/ctkPimpl.h

+ 59 - 0
Libs/Core/ctkPimpl.h

@@ -46,6 +46,65 @@ Use the Q_D() macros from functions in
 the public class to access the private class. Similarly, functions in the
 the public class to access the private class. Similarly, functions in the
 private class can invoke functions in the public class by using the Q_Q()
 private class can invoke functions in the public class by using the Q_Q()
 macro.
 macro.
+\section example Example
+Header file (ctkFooObject.h):
+\code
+// Qt includes
+#include <QObject>
+
+// CTK includes
+#include "ctkCoreExport.h"
+class ctkFooObjectPrivate;
+
+class CTK_CORE_EXPORT ctkFooObject: public QObject
+{
+public:
+  ctkFooObject(QObject* parent = 0);
+  virtual ~ctkFooObject();
+
+  void setProperty(double property);
+  double property()const;
+
+protected:
+  QScopedPointer<ctkFooObjectPrivate> d_ptr;
+ 
+private:
+  Q_DECLARE_PRIVATE(ctkFooObject);
+  Q_DISABLE_COPY(ctkFooObject);
+};
+\endcode
+Implementation file (ctkFooObject.cpp):
+\code
+// CTK includes
+#include "ctkFooObject.h"
+
+class ctkFooObjectPrivate
+{
+public:
+  void processSomething();
+
+  double MyProperty;
+};
+
+ctkFooObject::ctkFooObject(QObject* parentObject)
+  : d_ptr(new ctkFooObjectPrivate)
+{
+  Q_D(ctkFooObject);
+  d->MyProperty = 10.;
+}
+
+void ctkFooObject::setProperty(double newProperty)
+{
+  Q_D(ctkFooObject);
+  d->MyProperty = newProperty;
+}
+
+double ctkFooObject::property()const
+{
+  Q_D(const ctkFooObject);
+  return d->MyProperty;
+}
+\endcode
 */
 */
 
 
 #ifndef __ctkPimpl_h
 #ifndef __ctkPimpl_h