[kgraphviewer-devel] [KGraphViewer/libkgraphviz] 031e842: Introduce GraphElementPrivate

Kevin Funk krf at electrostorm.net
Thu Dec 16 14:42:38 CET 2010


	A	 src/kgraphviz/graphelement_p.h	 [License: Trivialfile.]

commit 031e842d68b5a88145ca4e7875f1eade8c4aee8f
Author: Kevin Funk <krf at electrostorm.net>
Date:   Thu Dec 16 14:20:16 2010 +0100

    Introduce GraphElementPrivate

diff --git a/src/kgraphviz/graphelement.cpp b/src/kgraphviz/graphelement.cpp
index 9e24ca1..59b69bd 100644
--- a/src/kgraphviz/graphelement.cpp
+++ b/src/kgraphviz/graphelement.cpp
@@ -17,6 +17,8 @@
 */
 
 #include "graphelement.h"
+#include "graphelement_p.h"
+
 #include "canvaselement.h"
 #include "support/dotdefaults.h"
 
@@ -29,15 +31,31 @@
 
 namespace KGraphViz
 {
-  
+
+GraphElementPrivate::GraphElementPrivate() :
+  m_selected(false),
+  m_z(1.0),
+  m_canvasElement(0)
+{
+}
+
+GraphElementPrivate::~GraphElementPrivate()
+{
+}
+
+GraphElementPrivate::GraphElementPrivate(const GraphElementPrivate& other) :
+  m_selected(other.m_selected),
+  m_z(other.m_z),
+  m_renderOperations(other.m_renderOperations),
+  m_canvasElement(other.m_canvasElement)
+{
+}
+
 GraphElement::GraphElement() :
     QObject(),
+    d_ptr(new GraphElementPrivate),
     m_attributes(),
-    m_originalAttributes(),
-    m_ce(0),
-    m_z(1.0),
-    m_renderOperations(),
-    m_selected(false)
+    m_originalAttributes()
 {
 /*  label("");
   id("");
@@ -52,25 +70,82 @@ GraphElement::GraphElement() :
   setFontSize(DOT_DEFAULT_FONTSIZE);
 }
 
-GraphElement::GraphElement(const GraphElement& element) : QObject(),
+GraphElement::GraphElement(const GraphElement& element) :
+  QObject(),
+  d_ptr(element.d_ptr),
   m_attributes(),
-  m_originalAttributes(),
-  m_ce(element.m_ce),
-  m_z(element.m_z),
-  m_renderOperations(),
-  m_selected(element.m_selected)
+  m_originalAttributes()
 {
   kDebug() ;
   updateWithElement(element);
 }
 
+GraphElement::~GraphElement()
+{
+  delete d_ptr;
+}
+
+CanvasElement* GraphElement::canvasElement() const
+{
+  Q_D(const GraphElement);
+  return d->m_canvasElement;
+}
+
+void GraphElement::setCanvasElement(CanvasElement* canvasElement)
+{
+  Q_D(GraphElement);
+  d->m_canvasElement = canvasElement;
+}
+
+bool GraphElement::isSelected() const
+{
+  Q_D(const GraphElement);
+  return d->m_selected;
+}
+
+void GraphElement::setSelected(bool selected)
+{
+  Q_D(GraphElement);
+  d->m_selected = selected;
+}
+
+double GraphElement::z() const
+{
+  Q_D(const GraphElement);
+  return d->m_z;
+}
+
+void GraphElement::setZ(double z)
+{
+  Q_D(GraphElement);
+  d->m_z = z;
+}
+
+DotRenderOpVec& GraphElement::renderOperations()
+{
+  Q_D(GraphElement);
+  return d->m_renderOperations;
+}
+
+DotRenderOpVec GraphElement::renderOperations() const
+{
+  Q_D(const GraphElement);
+  return d->m_renderOperations;
+}
+
+void GraphElement::setRenderOperations(const DotRenderOpVec& dotRenderOpVec)
+{
+  Q_D(GraphElement);
+  d->m_renderOperations = dotRenderOpVec;
+}
+
 void GraphElement::updateWithElement(const GraphElement& element)
 {
   kDebug() << element.id();
   bool modified = false;
-  if (element.z() != m_z)
+  if (element.z() != z())
   {
-    m_z = element.z();
+    setZ(element.z());
     modified = true;
   }
   QMap <QString, QString >::const_iterator it = element.attributes().constBegin();
@@ -91,7 +166,7 @@ void GraphElement::updateWithElement(const GraphElement& element)
   if (modified)
   {
     kDebug() << "modified: update render operations";
-    m_renderOperations = element.m_renderOperations;
+    setRenderOperations(element.renderOperations());
 /*    foreach (DotRenderOp op, m_renderOperations)
     {
       QString msg;
@@ -107,7 +182,7 @@ void GraphElement::updateWithElement(const GraphElement& element)
     kDebug() << "modified: emiting changed";*/
     emit changed();
   }
-  kDebug() << "done" << m_renderOperations.size();
+  kDebug() << "done" << renderOperations().size();
 }
 
 
diff --git a/src/kgraphviz/graphelement.h b/src/kgraphviz/graphelement.h
index 7a5efb4..4121297 100644
--- a/src/kgraphviz/graphelement.h
+++ b/src/kgraphviz/graphelement.h
@@ -28,8 +28,9 @@
 
 namespace KGraphViz
 {
-  
+
 class CanvasElement;
+class GraphElementPrivate;
 
 /**
  * The base of all GraphViz dot graph elements (nodes, edges, subgraphs,
@@ -38,11 +39,12 @@ class CanvasElement;
 class KGRAPHVIZ_EXPORT GraphElement: public QObject
 {
   Q_OBJECT
+
 public:
   GraphElement();
   GraphElement(const GraphElement& element);
-  
-  virtual ~GraphElement() {}
+
+  virtual ~GraphElement();
   
   inline void setId(const QString& id) {m_attributes["id"]=id;}
   inline void setStyle(const QString& ls) {m_attributes["style"]=ls;}
@@ -68,13 +70,10 @@ public:
   inline QString fontColor() const {return m_attributes["fontcolor"];}
   inline void setFontColor(const QString& fc) {m_attributes["fontcolor"] = fc;}
 
-  inline DotRenderOpVec& renderOperations() {return m_renderOperations;};
-  inline const DotRenderOpVec& renderOperations() const {return m_renderOperations;};
-  inline void setRenderOperations(DotRenderOpVec& drov) {m_renderOperations = drov;};
-  
-  inline double z() const {return m_z;}
-  inline void setZ(double thez) {m_z = thez;}
-  
+  DotRenderOpVec& renderOperations();
+  DotRenderOpVec renderOperations() const;
+  void setRenderOperations(const DotRenderOpVec& dotRenderOpVec);
+
   inline QString shapeFile() const {return m_attributes["shapefile"];}
   inline void setShapeFile(const QString& sf) {m_attributes["shapefile"] = sf;}
   
@@ -93,12 +92,14 @@ public:
 
   virtual void removeAttribute(const QString& attribName);
 
-  inline CanvasElement* canvasElement() {return m_ce;}
-  inline const CanvasElement* canvasElement() const {return m_ce;}
-  inline void setCanvasElement(CanvasElement* ce) {m_ce = ce;}
+  CanvasElement* canvasElement() const;
+  void setCanvasElement(CanvasElement* canvasElement);
+
+  double z() const;
+  void setZ(double z);
 
-  inline void setSelected(bool s) {m_selected=s;}
-  inline bool isSelected() {return m_selected;}
+  void setSelected(bool selected);
+  bool isSelected() const;
 
   void exportToGraphviz(void* element)  const;
 
@@ -108,15 +109,10 @@ Q_SIGNALS:
 protected:
   QMap<QString,QString> m_attributes;
   QList<QString> m_originalAttributes;
-  
-  CanvasElement* m_ce;
 
 private:
-  double m_z;
-
-  DotRenderOpVec m_renderOperations;
-
-  bool m_selected;
+  Q_DECLARE_PRIVATE(GraphElement);
+  GraphElementPrivate* const d_ptr;
 };
 
 
diff --git a/src/kgraphviz/graphelement_p.h b/src/kgraphviz/graphelement_p.h
new file mode 100644
index 0000000..414ee8d
--- /dev/null
+++ b/src/kgraphviz/graphelement_p.h
@@ -0,0 +1,45 @@
+/*
+    Copyright (C) 2010 Kevin Funk <krf at electrostorm.net>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+
+#ifndef GRAPHELEMENT_P_H
+#define GRAPHELEMENT_P_H
+
+#include "graphelement.h"
+
+namespace KGraphViz
+{
+
+class GraphElementPrivate
+{
+public:
+  GraphElementPrivate();
+  GraphElementPrivate(const GraphElementPrivate& other);
+  
+  ~GraphElementPrivate();
+
+  bool m_selected;
+  double m_z;
+
+  DotRenderOpVec m_renderOperations;
+  CanvasElement* m_canvasElement;
+};
+
+}
+
+#endif
\ No newline at end of file


More information about the kgraphviewer-devel mailing list