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

Mike Fenton mike at staikos.net
Mon Oct 15 22:24:03 CEST 2007


SVN commit 725614 by fenton:

Initial implementation of save/restore for PlotItem and PlotAxisItem.


 M  +2 -0      builtingraphics.cpp  
 M  +0 -1      lineitem.cpp  
 M  +35 -0     plotaxisitem.cpp  
 M  +3 -0      plotaxisitem.h  
 M  +91 -0     plotitem.cpp  
 M  +9 -0      plotitem.h  


--- branches/work/kst/portto4/kst/src/libkstapp/builtingraphics.cpp #725613:725614
@@ -15,6 +15,7 @@
 #include "ellipseitem.h"
 #include "labelitem.h"
 #include "pictureitem.h"
+#include "plotitem.h"
 #include "svgitem.h"
 
 namespace Kst {
@@ -25,6 +26,7 @@
       new EllipseItemFactory;
       new LabelItemFactory;
       new PictureItemFactory;
+      new PlotItemFactory;
       new SvgItemFactory;
     }
   }
--- branches/work/kst/portto4/kst/src/libkstapp/lineitem.cpp #725613:725614
@@ -207,7 +207,6 @@
 
 ViewItem* LineItemFactory::generateGraphics(QXmlStreamReader& xml, View *view, ViewItem *parent) {
   LineItem *rc = 0;
-  double x1 = 0., y1 = 0., x2 = 10., y2 = 10.;
   while (!xml.atEnd()) {
     bool validTag = true;
     if (xml.isStartElement()) {
--- branches/work/kst/portto4/kst/src/libkstapp/plotaxisitem.cpp #725613:725614
@@ -135,6 +135,41 @@
 }
 
 
+void PlotAxisItem::save(QXmlStreamWriter &xml) {
+    Q_UNUSED(xml);
+}
+
+
+void PlotAxisItem::saveInPlot(QXmlStreamWriter &xml) {
+  xml.writeStartElement("plotaxis");
+  xml.writeAttribute("xtickmode", QVariant(_xAxisMajorTickMode).toString());
+  xml.writeAttribute("ytickmode", QVariant(_yAxisMajorTickMode).toString());
+  xml.writeEndElement();
+}
+
+
+bool PlotAxisItem::configureFromXml(QXmlStreamReader &xml) {
+  bool validTag = false;
+  if (xml.isStartElement() && xml.name().toString() == "plotaxis") {
+    QXmlStreamAttributes attrs = xml.attributes();
+    QStringRef av;
+    av = attrs.value("xtickmode");
+    if (!av.isNull()) {
+      setXAxisMajorTickMode((MajorTickMode)av.toString().toInt());
+    }
+    av = attrs.value("ytickmode");
+    if (!av.isNull()) {
+      setYAxisMajorTickMode((MajorTickMode)av.toString().toInt());
+    }
+    xml.readNext();
+    if (xml.isEndElement() && xml.name().toString() == "plotaxis") {
+      validTag = true;
+    }
+  }
+  return validTag;
+}
+
+
 void PlotAxisItem::paintMajorGridLines(QPainter *painter,
                                        const QList<qreal> &xMajorTicks,
                                        const QList<qreal> &yMajorTicks) {
--- branches/work/kst/portto4/kst/src/libkstapp/plotaxisitem.h #725613:725614
@@ -46,6 +46,9 @@
     qreal marginWidth() const;
     qreal marginHeight() const;
 
+    virtual void save(QXmlStreamWriter &xml);
+    void saveInPlot(QXmlStreamWriter &xml);
+    bool configureFromXml(QXmlStreamReader &xml);
     virtual void paint(QPainter *painter);
 
     virtual void paintMajorGridLines(QPainter *painter,
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #725613:725614
@@ -18,6 +18,7 @@
 
 #include "layoutboxitem.h"
 #include "viewgridlayout.h"
+#include "debug.h"
 
 #include "application.h"
 #include "mainwindow.h"
@@ -64,6 +65,22 @@
 }
 
 
+void PlotItem::save(QXmlStreamWriter &xml) {
+  xml.writeStartElement("plot");
+  xml.writeAttribute("tiedzoom", QVariant(_isTiedZoom).toString());
+  xml.writeAttribute("leftlabelvisible", QVariant(_isLeftLabelVisible).toString());
+  xml.writeAttribute("bottomlabelvisible", QVariant(_isBottomLabelVisible).toString());
+  xml.writeAttribute("rightlabelvisible", QVariant(_isRightLabelVisible).toString());
+  xml.writeAttribute("toplabelvisible", QVariant(_isTopLabelVisible).toString());
+  ViewItem::save(xml);
+  _axisItem->saveInPlot(xml);
+//TODO Save PlotRenderItems.
+  xml.writeEndElement();
+
+
+}
+
+
 QList<PlotRenderItem*> PlotItem::renderItems() const {
   return _renderers.values();
 }
@@ -508,6 +525,80 @@
   creationComplete(); //add to undo stack
 }
 
+
+PlotItemFactory::PlotItemFactory()
+: GraphicsFactory() {
+  registerFactory("plot", this);
 }
 
+
+PlotItemFactory::~PlotItemFactory() {
+}
+
+
+ViewItem* PlotItemFactory::generateGraphics(QXmlStreamReader& xml, View *view, ViewItem *parent) {
+  PlotItem *rc = 0;
+  while (!xml.atEnd()) {
+    bool validTag = true;
+    if (xml.isStartElement()) {
+      if (xml.name().toString() == "plot") {
+        Q_ASSERT(!rc);
+        rc = new PlotItem(view);
+        if (parent) {
+          rc->setParentItem(parent);
+        }
+        QXmlStreamAttributes attrs = xml.attributes();
+        QStringRef av;
+        av = attrs.value("tiedzoom");
+        if (!av.isNull()) {
+          rc->setTiedZoom(QVariant(av.toString()).toBool());
+        }
+        av = attrs.value("leftlabelvisible");
+        if (!av.isNull()) {
+          rc->setLeftLabelVisible(QVariant(av.toString()).toBool());
+        }
+        av = attrs.value("bottomlabelvisible");
+        if (!av.isNull()) {
+          rc->setBottomLabelVisible(QVariant(av.toString()).toBool());
+        }
+        av = attrs.value("rightlabelvisible");
+        if (!av.isNull()) {
+          rc->setRightLabelVisible(QVariant(av.toString()).toBool());
+        }
+        av = attrs.value("toplabelvisible");
+        if (!av.isNull()) {
+          rc->setTopLabelVisible(QVariant(av.toString()).toBool());
+        }
+        // TODO add any specialized PlotItem Properties here.
+      } else if (xml.name().toString() == "plotaxis") {
+        Q_ASSERT(rc);
+        validTag = rc->plotAxisItem()->configureFromXml(xml);
+      } 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() == "plot") {
+        break;
+      } else {
+        validTag = false;
+      }
+    }
+    if (!validTag) {
+      qDebug("invalid Tag\n");
+      Debug::self()->log(QObject::tr("Error creating plot 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/plotitem.h #725613:725614
@@ -13,6 +13,7 @@
 #define PLOTITEM_H
 
 #include "viewitem.h"
+#include "graphicsfactory.h"
 
 #include <QHash>
 
@@ -36,6 +37,7 @@
     QList<PlotRenderItem*> renderItems() const;
     PlotRenderItem *renderItem(PlotRenderItem::RenderType type);
 
+    virtual void save(QXmlStreamWriter &xml);
     virtual void paint(QPainter *painter);
 
     /* This is the rectangle of the PlotAxisItem and includes the axis labels. */
@@ -138,6 +140,13 @@
     bool _appendToLayout;
 };
 
+class PlotItemFactory : public GraphicsFactory {
+  public:
+    PlotItemFactory();
+    ~PlotItemFactory();
+    ViewItem* generateGraphics(QXmlStreamReader& stream, View *view, ViewItem *parent = 0);
+};
+
 }
 
 #endif


More information about the Kst mailing list