Changed KKJ class to use private member implementation
authorAki Koskinen <maemo@akikoskinen.info>
Sat, 27 Mar 2010 18:03:01 +0000 (20:03 +0200)
committerAki Koskinen <maemo@akikoskinen.info>
Sat, 27 Mar 2010 18:31:20 +0000 (20:31 +0200)
src/kkj.cpp
src/kkj.h
src/kkj_p.h [new file with mode: 0644]
src/src.pro

index d60da50..2724ce0 100644 (file)
@@ -1,9 +1,31 @@
 #include "kkj.h"
+#include "kkj_p.h"
+
+KKJPrivate::~KKJPrivate()
+{
+}
+
+void KKJPrivate::init(unsigned int northing, unsigned int easting)
+{
+    this->northing = northing;
+    this->easting = easting;
+}
+
 
 KKJ::KKJ(unsigned int northing, unsigned int easting) :
-        mNorthing(northing),
-        mEasting(easting)
+        d_ptr(new KKJPrivate)
+{
+    Q_D(KKJ);
+    d->q_ptr = this;
+    d->init(northing, easting);
+}
+
+KKJ::KKJ(KKJPrivate &dd, unsigned int northing, unsigned int easting) :
+        d_ptr(&dd)
 {
+    Q_D(KKJ);
+    d->q_ptr = this;
+    d->init(northing, easting);
 }
 
 KKJ::~KKJ()
@@ -12,10 +34,12 @@ KKJ::~KKJ()
 
 unsigned int KKJ::northing() const
 {
-    return mNorthing;
+    Q_D(const KKJ);
+    return d->northing;
 }
 
 unsigned int KKJ::easting() const
 {
-    return mEasting;
+    Q_D(const KKJ);
+    return d->easting;
 }
index 3afb9b2..ac148fa 100644 (file)
--- a/src/kkj.h
+++ b/src/kkj.h
@@ -1,6 +1,10 @@
 #ifndef KKJ_H
 #define KKJ_H
 
+#include <QtGlobal>
+
+class KKJPrivate;
+
 /**
  * A class representing the Finnish KKJ coordinate.
  */
@@ -31,9 +35,22 @@ public:
      */
     unsigned int easting() const;
 
+protected:
+    /**
+     * Constructs a new KKJ coordinate with the given values.
+     * @param dd a private implementation member.
+     * @param northing the northing coordinate.
+     * @param easting the easting coordinate.
+     */
+    KKJ(KKJPrivate &dd, unsigned int northing, unsigned int easting);
+
+
 private:
-    unsigned int mNorthing;
-    unsigned int mEasting;
+    /// Pointer to the private member
+    KKJPrivate *const d_ptr;
+
+    Q_DECLARE_PRIVATE(KKJ)
+
 };
 
 #endif // KKJ_H
diff --git a/src/kkj_p.h b/src/kkj_p.h
new file mode 100644 (file)
index 0000000..61b7fa5
--- /dev/null
@@ -0,0 +1,40 @@
+#ifndef KKJ_P_H
+#define KKJ_P_H
+
+#include <QtGlobal>
+
+class KKJ;
+
+/**
+ * A private member class for class KKJ.
+ */
+class KKJPrivate
+{
+public:
+    /**
+     * Destructor.
+     */
+    virtual ~KKJPrivate();
+
+private:
+    /**
+     * Initializes the private class.
+     * @param northing the northing of the coordinate.
+     * @param easting the easting of the coordinate.
+     */
+    void init(unsigned int northing, unsigned int easting);
+
+    /// The northing of the coordinate.
+    unsigned int northing;
+
+    /// The easting of the coordinate.
+    unsigned int easting;
+
+    /// The concrete class owning this private implementation member.
+    KKJ *q_ptr;
+
+    Q_DECLARE_PUBLIC(KKJ)
+
+};
+
+#endif // KKJ_P_H
index ec3edc3..854efac 100644 (file)
@@ -1,9 +1,12 @@
 TEMPLATE = lib
 TARGET = ptascommon
 
-INSTALL_HEADERS += \
+INSTALL_HEADERS = \
     kkj.h
+PRIVATE_HEADERS = \
+    kkj_p.h
 HEADERS += \
-    $$INSTALL_HEADERS
+    $$INSTALL_HEADERS \
+    $$PRIVATE_HEADERS
 SOURCES += \
     kkj.cpp