[Kst] branches/work/kst/portto4/kst/src/libkstapp
Mike Fenton
mike at staikos.net
Tue Oct 16 16:15:04 CEST 2007
SVN commit 725903 by fenton:
Add parsing of layoutbox and save/parsing of items associated with the
layoutbox.
M +2 -0 builtingraphics.cpp
M +86 -0 layoutboxitem.cpp
M +9 -0 layoutboxitem.h
--- branches/work/kst/portto4/kst/src/libkstapp/builtingraphics.cpp #725902:725903
@@ -14,6 +14,7 @@
#include "lineitem.h"
#include "ellipseitem.h"
#include "labelitem.h"
+#include "layoutboxitem.h"
#include "pictureitem.h"
#include "plotitem.h"
#include "svgitem.h"
@@ -25,6 +26,7 @@
new LineItemFactory;
new EllipseItemFactory;
new LabelItemFactory;
+ new LayoutBoxItemFactory;
new PictureItemFactory;
new PlotItemFactory;
new SvgItemFactory;
--- branches/work/kst/portto4/kst/src/libkstapp/layoutboxitem.cpp #725902:725903
@@ -14,6 +14,7 @@
#include "viewgridlayout.h"
#include "viewitemzorder.h"
+#include "debug.h"
#include <QDebug>
#include <QMenu>
#include <QTimer>
@@ -55,6 +56,19 @@
void LayoutBoxItem::save(QXmlStreamWriter &xml) {
xml.writeStartElement("layoutbox");
ViewItem::save(xml);
+
+ QList<QGraphicsItem*> list = QGraphicsItem::children();
+ foreach (QGraphicsItem *item, list) {
+ ViewItem *viewItem = qgraphicsitem_cast<ViewItem*>(item);
+ if (!viewItem)
+ continue;
+
+ xml.writeStartElement("layoutitem");
+ //TODO Update this with proper Object Tag's.
+ xml.writeAttribute("name", viewItem->name());
+ xml.writeEndElement();
+ }
+
xml.writeEndElement();
}
@@ -126,6 +140,78 @@
event->ignore();
}
+
+bool LayoutBoxItem::appendItemFromXml(QXmlStreamReader &xml) {
+ bool validTag = false;
+ if (xml.isStartElement() && xml.name().toString() == "layoutitem") {
+ QXmlStreamAttributes attrs = xml.attributes();
+ QStringRef av;
+ av = attrs.value("name");
+ if (!av.isNull()) {
+ //TODO Use ObjectTag to locate the correct item and add it to this layout.
+ }
+ xml.readNext();
+ if (xml.isEndElement() && xml.name().toString() == "layoutitem") {
+ validTag = true;
+ }
+ }
+ return validTag;
}
+
+LayoutBoxItemFactory::LayoutBoxItemFactory()
+: GraphicsFactory() {
+ registerFactory("layoutbox", this);
+}
+
+
+LayoutBoxItemFactory::~LayoutBoxItemFactory() {
+}
+
+
+ViewItem* LayoutBoxItemFactory::generateGraphics(QXmlStreamReader& xml, View *view, ViewItem *parent) {
+ LayoutBoxItem *rc = 0;
+ while (!xml.atEnd()) {
+ bool validTag = true;
+ if (xml.isStartElement()) {
+ if (xml.name().toString() == "layoutbox") {
+ Q_ASSERT(!rc);
+ rc = new LayoutBoxItem(view);
+ if (parent) {
+ rc->setParentItem(parent);
+ }
+ // TODO add any specialized BoxItem Properties here.
+ } else if (xml.name().toString() == "layoutitem") {
+ Q_ASSERT(rc);
+ validTag = rc->appendItemFromXml(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() == "layoutbox") {
+ break;
+ } else {
+ validTag = false;
+ }
+ }
+ if (!validTag) {
+ qDebug("invalid Tag\n");
+ Debug::self()->log(QObject::tr("Error creating layoutbox object from Kst file."), Debug::Warning);
+ delete rc;
+ return 0;
+ }
+ xml.readNext();
+ }
+ //TODO LayoutBoxItem automatically adds itself to the parent. Don't return the item here as it
+ // has already been added to the scene.
+ return 0;
+}
+
+}
+
// vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/layoutboxitem.h #725902:725903
@@ -13,6 +13,7 @@
#define LAYOUTBOXITEM_H
#include "viewitem.h"
+#include "graphicsfactory.h"
namespace Kst {
@@ -24,6 +25,7 @@
virtual ~LayoutBoxItem();
void appendItem(ViewItem *item);
+ bool appendItemFromXml(QXmlStreamReader &xml);
virtual void save(QXmlStreamWriter &xml);
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
@@ -36,6 +38,13 @@
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
};
+class LayoutBoxItemFactory : public GraphicsFactory {
+ public:
+ LayoutBoxItemFactory();
+ ~LayoutBoxItemFactory();
+ ViewItem* generateGraphics(QXmlStreamReader& stream, View *view, ViewItem *parent = 0);
+};
+
}
#endif
More information about the Kst
mailing list