[Kst] branches/work/kst/portto4/kst/src/libkstapp
Mike Fenton
mike at staikos.net
Fri Oct 12 19:50:45 CEST 2007
SVN commit 724568 by fenton:
Implementation of save/restore for LabelItem.
M +2 -0 builtingraphics.cpp
M +64 -0 labelitem.cpp
M +9 -0 labelitem.h
--- branches/work/kst/portto4/kst/src/libkstapp/builtingraphics.cpp #724567:724568
@@ -13,6 +13,7 @@
#include "boxitem.h"
#include "lineitem.h"
#include "ellipseitem.h"
+#include "labelitem.h"
namespace Kst {
namespace Builtins {
@@ -20,6 +21,7 @@
new BoxItemFactory;
new LineItemFactory;
new EllipseItemFactory;
+ new LabelItemFactory;
}
}
}
--- branches/work/kst/portto4/kst/src/libkstapp/labelitem.cpp #724567:724568
@@ -13,6 +13,8 @@
#include <labelparser.h>
#include "labelrenderer.h"
+#include "debug.h"
+
#include <QDebug>
#include <QInputDialog>
#include <QGraphicsItem>
@@ -59,6 +61,14 @@
}
+void LabelItem::save(QXmlStreamWriter &xml) {
+ xml.writeStartElement("label");
+ xml.writeAttribute("text", _text);
+ ViewItem::save(xml);
+ xml.writeEndElement();
+}
+
+
void CreateLabelCommand::createItem() {
bool ok;
QString text = QInputDialog::getText(_view, tr("Kst: Create Label"), tr("Label:"), QLineEdit::Normal, QString::null, &ok);
@@ -73,6 +83,60 @@
}
+LabelItemFactory::LabelItemFactory()
+: GraphicsFactory() {
+ registerFactory("label", this);
}
+
+LabelItemFactory::~LabelItemFactory() {
+}
+
+
+ViewItem* LabelItemFactory::generateGraphics(QXmlStreamReader& xml, View *view, ViewItem *parent) {
+ LabelItem *rc = 0;
+ while (!xml.atEnd()) {
+ bool validTag = true;
+ if (xml.isStartElement()) {
+ if (xml.name().toString() == "label") {
+ QXmlStreamAttributes attrs = xml.attributes();
+ QStringRef av;
+ av = attrs.value("text");
+ if (!av.isNull()) {
+ Q_ASSERT(!rc);
+ rc = new LabelItem(view, av.toString());
+ if (parent) {
+ rc->setParentItem(parent);
+ // TODO add any specialized LabelItem 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() == "label") {
+ break;
+ } else {
+ validTag = false;
+ }
+ }
+ if (!validTag) {
+ qDebug("invalid Tag\n");
+ Debug::self()->log(QObject::tr("Error creating box 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/labelitem.h #724567:724568
@@ -13,6 +13,7 @@
#define LABELITEM_H
#include "viewitem.h"
+#include "graphicsfactory.h"
namespace Label {
struct Parsed;
@@ -26,6 +27,7 @@
LabelItem(View *parent, const QString& labelText);
virtual ~LabelItem();
+ virtual void save(QXmlStreamWriter &xml);
virtual void paint(QPainter *painter);
private:
@@ -42,6 +44,13 @@
virtual void createItem();
};
+class LabelItemFactory : public GraphicsFactory {
+ public:
+ LabelItemFactory();
+ ~LabelItemFactory();
+ ViewItem* generateGraphics(QXmlStreamReader& stream, View *view, ViewItem *parent = 0);
+};
+
}
#endif
More information about the Kst
mailing list