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

Mike Fenton mike at staikos.net
Fri Oct 12 21:02:26 CEST 2007


SVN commit 724589 by fenton:

Implemention of save/restore for LineItems.
Fixed error in restoring of QPen and QBrush in ViewItem.



 M  +1 -1      boxitem.cpp  
 M  +20 -36    lineitem.cpp  
 M  +1 -0      lineitem.h  
 M  +17 -11    viewitem.cpp  


--- branches/work/kst/portto4/kst/src/libkstapp/boxitem.cpp #724588:724589
@@ -69,8 +69,8 @@
         rc = new BoxItem(view);
         if (parent) {
           rc->setParentItem(parent);
+        }
         // TODO add any specialized BoxItem Properties here.
-        }
       } else {
         Q_ASSERT(rc);
         if (!rc->parse(xml, validTag) && validTag) {
--- branches/work/kst/portto4/kst/src/libkstapp/lineitem.cpp #724588:724589
@@ -35,6 +35,13 @@
 }
 
 
+void LineItem::save(QXmlStreamWriter &xml) {
+  xml.writeStartElement("line");
+  ViewItem::save(xml);
+  xml.writeEndElement();
+}
+
+
 QLineF LineItem::line() const {
   return QLineF(rect().left(), rect().center().y(), rect().right(), rect().center().y());
 }
@@ -198,6 +205,7 @@
   LineItem *rc = 0;
   double x1 = 0., y1 = 0., x2 = 10., y2 = 10.;
   while (!xml.atEnd()) {
+    bool validTag = true;
     if (xml.isStartElement()) {
       if (xml.name().toString() == "line") {
         Q_ASSERT(!rc);
@@ -205,55 +213,31 @@
         if (parent) {
           rc->setParentItem(parent);
         }
-        QXmlStreamAttributes attrs = xml.attributes();
-        QStringRef av;
-        av = attrs.value("thickness");
-        if (!av.isNull()) {
-          QPen p = rc->pen();
-          p.setWidthF(av.toString().toDouble());
-          rc->setPen(p);
-        }
-        av = attrs.value("color");
-        if (!av.isNull()) {
-          QPen p = rc->pen();
-          p.setColor(QColor(av.toString()));
-          rc->setPen(p);
-        }
-        av = attrs.value("x1");
-        if (!av.isNull()) {
-          x1 = av.toString().toDouble();
-        }
-        av = attrs.value("y1");
-        if (!av.isNull()) {
-          y1 = av.toString().toDouble();
-        }
-        av = attrs.value("x2");
-        if (!av.isNull()) {
-          x2 = av.toString().toDouble();
-        }
-        av = attrs.value("y2");
-        if (!av.isNull()) {
-          y2 = av.toString().toDouble();
-        }
+        // TODO add any specialized LineItem Properties here.
       } else {
         Q_ASSERT(rc);
-        ViewItem *i = GraphicsFactory::parse(xml, view, rc);
-        if (!i) {
+        if (!rc->parse(xml, validTag) && validTag) {
+          ViewItem *i = GraphicsFactory::parse(xml, view, rc);
+          if (!i) {
+          }
         }
       }
     } else if (xml.isEndElement()) {
       if (xml.name().toString() == "line") {
         break;
       } else {
-        Debug::self()->log(QObject::tr("Error creating line object from Kst file."), Debug::Warning);
-        delete rc;
-        return 0;
+        validTag = false;
       }
     }
+    if (!validTag) {
+      qDebug("invalid Tag\n");
+      Debug::self()->log(QObject::tr("Error creating line object from Kst file."), Debug::Warning);
+      delete rc;
+      return 0;
+    }
     xml.readNext();
   }
 
-  rc->setLine(QLineF(QPointF(x1, y1), QPointF(x2, y2)));
   return rc;
 }
 
--- branches/work/kst/portto4/kst/src/libkstapp/lineitem.h #724588:724589
@@ -27,6 +27,7 @@
     QLineF line() const;
     void setLine(const QLineF &line);
 
+    virtual void save(QXmlStreamWriter &xml);
     virtual void paint(QPainter *painter);
 
     virtual QPainterPath grips() const;
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #724588:724589
@@ -132,54 +132,60 @@
      setPos(x, y);
     } else if (xml.name().toString() == "brush") {
       knownTag = true;
+      QBrush brush;
       av = attrs.value("color");
       if (!av.isNull()) {
-          brush().setColor(QColor(av.toString()));
+          brush.setColor(QColor(av.toString()));
       }
       av = attrs.value("style");
       if (!av.isNull()) {
-        brush().setStyle((Qt::BrushStyle)av.toString().toInt());
-     }
+        brush.setStyle((Qt::BrushStyle)av.toString().toInt());
+      }
+      setBrush(brush);
     } else if (xml.name().toString() == "pen") {
       knownTag = true;
-      QStringRef av;
+      QPen pen;
       av = attrs.value("style");
       if (!av.isNull()) {
-        pen().setStyle((Qt::PenStyle)av.toString().toInt());
+        pen.setStyle((Qt::PenStyle)av.toString().toInt());
       }
       av = attrs.value("width");
       if (!av.isNull()) {
-        pen().setWidthF(av.toString().toDouble());
+        pen.setWidthF(av.toString().toDouble());
       }
       av = attrs.value("miterlimit");
       if (!av.isNull()) {
-        pen().setMiterLimit(av.toString().toDouble());
+        pen.setMiterLimit(av.toString().toDouble());
       }
       av = attrs.value("cap");
       if (!av.isNull()) {
-        pen().setCapStyle((Qt::PenCapStyle)av.toString().toInt());
+        pen.setCapStyle((Qt::PenCapStyle)av.toString().toInt());
       }
       av = attrs.value("joinstyle");
       if (!av.isNull()) {
-        pen().setJoinStyle((Qt::PenJoinStyle)av.toString().toInt());
+        pen.setJoinStyle((Qt::PenJoinStyle)av.toString().toInt());
       }
       xml.readNext();
       xml.readNext();
       if (xml.isStartElement() && (xml.name().toString() == "brush")) {
+        QBrush penBrush;
+        attrs = xml.attributes();
         av = attrs.value("color");
         if (!av.isNull()) {
-            brush().setColor(QColor(av.toString()));
+            penBrush.setColor(QColor(av.toString()));
         }
         av = attrs.value("style");
         if (!av.isNull()) {
-          brush().setStyle((Qt::BrushStyle)av.toString().toInt());
+          penBrush.setStyle((Qt::BrushStyle)av.toString().toInt());
         }
+        pen.setBrush(penBrush);
         xml.readNext();
         if (!xml.isEndElement() || (xml.name().toString() != "brush")) {
           expectedTag = "InvalidTag";
         }
         xml.readNext();
       }
+      setPen(pen);
     } else if (xml.name().toString() == "rect") {
       knownTag = true;
       double x = 0, y = 0, w = 10, h = 10;


More information about the Kst mailing list