[Kst] branches/work/kst/portto4/kst/src/libkstapp

Mike Fenton mike at staikos.net
Fri Oct 12 18:30:04 CEST 2007


SVN commit 724553 by fenton:

Implementation of EllipseItem save/restore.


 M  +2 -0      builtingraphics.cpp  
 M  +58 -0     ellipseitem.cpp  
 M  +8 -0      ellipseitem.h  


--- branches/work/kst/portto4/kst/src/libkstapp/builtingraphics.cpp #724552:724553
@@ -12,12 +12,14 @@
 #include "builtingraphics.h"
 #include "boxitem.h"
 #include "lineitem.h"
+#include "ellipseitem.h"
 
 namespace Kst {
   namespace Builtins {
     void initGraphics() {
       new BoxItemFactory;
       new LineItemFactory;
+      new EllipseItemFactory;
     }
   }
 }
--- branches/work/kst/portto4/kst/src/libkstapp/ellipseitem.cpp #724552:724553
@@ -15,6 +15,8 @@
 #include <QGraphicsItem>
 #include <QGraphicsScene>
 
+#include <debug.h>
+
 namespace Kst {
 
 EllipseItem::EllipseItem(View *parent)
@@ -28,6 +30,13 @@
 }
 
 
+void EllipseItem::save(QXmlStreamWriter &xml) {
+  xml.writeStartElement("ellipse");
+  ViewItem::save(xml);
+  xml.writeEndElement();
+}
+
+
 QPainterPath EllipseItem::itemShape() const {
   QPainterPath path;
   path.addEllipse(rect());
@@ -48,6 +57,55 @@
   CreateCommand::createItem();
 }
 
+
+EllipseItemFactory::EllipseItemFactory()
+: GraphicsFactory() {
+  registerFactory("ellipse", this);
 }
 
+
+EllipseItemFactory::~EllipseItemFactory() {
+}
+
+
+ViewItem* EllipseItemFactory::generateGraphics(QXmlStreamReader& xml, View *view, ViewItem *parent) {
+  EllipseItem *rc = 0;
+  while (!xml.atEnd()) {
+    bool validTag = true;
+    if (xml.isStartElement()) {
+      if (xml.name().toString() == "ellipse") {
+        Q_ASSERT(!rc);
+        rc = new EllipseItem(view);
+        if (parent) {
+          rc->setParentItem(parent);
+        // TODO add any specialized BoxItem Properties here.
+        }
+      } else {
+        Q_ASSERT(rc);
+        if (!rc->parse(xml, validTag) && validTag) {
+          ViewItem *i = GraphicsFactory::parse(xml, view, rc);
+          if (!i) {
+          }
+        }
+      }
+    } else if (xml.isEndElement()) {
+      if (xml.name().toString() == "ellipse") {
+        break;
+      } else {
+        validTag = false;
+      }
+    }
+    if (!validTag) {
+      qDebug("invalid Tag\n");
+      Debug::self()->log(QObject::tr("Error creating ellipse object from Kst file."), Debug::Warning);
+      delete rc;
+      return 0;
+    }
+    xml.readNext();
+  }
+  return rc;
+}
+
+}
+
 // vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/ellipseitem.h #724552:724553
@@ -13,6 +13,7 @@
 #define ELLIPSEITEM_H
 
 #include "viewitem.h"
+#include "graphicsfactory.h"
 
 namespace Kst {
 
@@ -23,6 +24,7 @@
     EllipseItem(View *parent);
     virtual ~EllipseItem();
 
+    virtual void save(QXmlStreamWriter &xml);
     virtual QPainterPath itemShape() const;
     virtual void paint(QPainter *painter);
 };
@@ -36,6 +38,12 @@
     virtual void createItem();
 };
 
+class EllipseItemFactory : public GraphicsFactory {
+  public:
+    EllipseItemFactory();
+    ~EllipseItemFactory();
+    ViewItem* generateGraphics(QXmlStreamReader& stream, View *view, ViewItem *parent = 0);
+};
 }
 
 #endif


More information about the Kst mailing list