[Kst] branches/work/kst/portto4/kst/src/libkstapp
Mike Fenton
mike at staikos.net
Tue Oct 16 21:04:24 CEST 2007
SVN commit 725973 by fenton:
Add save/partial restore (without relations) of CartesianRenderItem and
the baseclass PlotRenderItem.
M +19 -0 cartesianrenderitem.cpp
M +3 -0 cartesianrenderitem.h
M +9 -1 plotitem.cpp
M +97 -1 plotrenderitem.cpp
M +3 -0 plotrenderitem.h
--- branches/work/kst/portto4/kst/src/libkstapp/cartesianrenderitem.cpp #725972:725973
@@ -91,6 +91,25 @@
painter->restore();
}
+
+void CartesianRenderItem::saveInPlot(QXmlStreamWriter &xml) {
+ xml.writeStartElement("cartesianrender");
+ PlotRenderItem::saveInPlot(xml);
+ xml.writeEndElement();
}
+
+bool CartesianRenderItem::configureFromXml(QXmlStreamReader &xml) {
+ bool validTag = false;
+ if (xml.isStartElement() && xml.name().toString() == "cartesianrender") {
+ validTag = PlotRenderItem::configureFromXml(xml);
+ if (validTag && xml.isEndElement() && xml.name().toString() == "cartesianrender") {
+ validTag = true;
+ }
+ }
+ return validTag;
+}
+
+}
+
// vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/cartesianrenderitem.h #725972:725973
@@ -23,7 +23,10 @@
CartesianRenderItem(PlotItem *parentItem);
virtual ~CartesianRenderItem();
+ virtual void saveInPlot(QXmlStreamWriter &xml);
virtual void paintRelations(QPainter *painter);
+
+ bool configureFromXml(QXmlStreamReader &xml);
};
}
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #725972:725973
@@ -74,7 +74,9 @@
xml.writeAttribute("toplabelvisible", QVariant(_isTopLabelVisible).toString());
ViewItem::save(xml);
_axisItem->saveInPlot(xml);
-//TODO Save PlotRenderItems.
+ foreach (PlotRenderItem *renderer, renderItems()) {
+ renderer->saveInPlot(xml);
+ }
xml.writeEndElement();
@@ -573,6 +575,12 @@
} else if (xml.name().toString() == "plotaxis") {
Q_ASSERT(rc);
validTag = rc->plotAxisItem()->configureFromXml(xml);
+ } else if (xml.name().toString() == "cartesianrender") {
+ Q_ASSERT(rc);
+ PlotRenderItem * renderItem = rc->renderItem(PlotRenderItem::Cartesian);
+ if (renderItem) {
+ validTag = renderItem->configureFromXml(xml);
+ }
} else {
Q_ASSERT(rc);
if (!rc->parse(xml, validTag) && validTag) {
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderitem.cpp #725972:725973
@@ -198,10 +198,106 @@
void PlotRenderItem::save(QXmlStreamWriter &xml) {
- Q_UNUSED(xml);
+ Q_UNUSED(xml);
}
+void PlotRenderItem::saveInPlot(QXmlStreamWriter &xml) {
+ //TODO Update with proper Object Tag.
+ //xml.writeAttribute("name", name());
+ xml.writeAttribute("type", QVariant(_type).toString());
+ xml.writeAttribute("xzoommode", QVariant(_xAxisZoomMode).toString());
+ xml.writeAttribute("yzoommode", QVariant(_yAxisZoomMode).toString());
+ xml.writeAttribute("xlog", QVariant(_isXAxisLog).toString());
+ xml.writeAttribute("ylog", QVariant(_isYAxisLog).toString());
+ xml.writeAttribute("xlogbase", QVariant(_xLogBase).toString());
+ xml.writeAttribute("ylogbase", QVariant(_yLogBase).toString());
+ xml.writeStartElement("rect");
+ xml.writeAttribute("x", QVariant(projectionRect().x()).toString());
+ xml.writeAttribute("y", QVariant(projectionRect().y()).toString());
+ xml.writeAttribute("width", QVariant(projectionRect().width()).toString());
+ xml.writeAttribute("height", QVariant(projectionRect().height()).toString());
+ xml.writeEndElement();
+ foreach (RelationPtr relation, relationList()) {
+ xml.writeStartElement("relation");
+ //TODO replace with with a valid object tag to correctly identify the relations.
+ xml.writeAttribute("name", relation->name());
+ xml.writeEndElement();
+ }
+}
+
+
+bool PlotRenderItem::configureFromXml(QXmlStreamReader &xml) {
+ bool validTag = true;
+ QString primaryTag = xml.name().toString();
+ QXmlStreamAttributes attrs = xml.attributes();
+ QStringRef av;
+ av = attrs.value("type");
+ if (!av.isNull()) {
+ setType((RenderType)av.toString().toInt());
+ }
+ av = attrs.value("xzoommode");
+ if (!av.isNull()) {
+ setXAxisZoomMode((ZoomMode)av.toString().toInt());
+ }
+ av = attrs.value("yzoommode");
+ if (!av.isNull()) {
+ setYAxisZoomMode((ZoomMode)av.toString().toInt());
+ }
+ av = attrs.value("xlog");
+ if (!av.isNull()) {
+ setXAxisLog(QVariant(av.toString()).toBool());
+ }
+ av = attrs.value("ylog");
+ if (!av.isNull()) {
+ setYAxisLog(QVariant(av.toString()).toBool());
+ }
+ av = attrs.value("xlogbase");
+ if (!av.isNull()) {
+ setXLogBase(av.toString().toDouble());
+ }
+ av = attrs.value("ylogbase");
+ if (!av.isNull()) {
+ setYLogBase(av.toString().toDouble());
+ }
+
+ QString expectedEnd;
+ while (!(xml.isEndElement() && (xml.name().toString() == primaryTag))) {
+ if (xml.isStartElement() && xml.name().toString() == "rect") {
+ expectedEnd = xml.name().toString();
+ double x = 0, y = 0, w = 10, h = 10;
+ av = attrs.value("width");
+ if (!av.isNull()) {
+ w = av.toString().toDouble();
+ }
+ av = attrs.value("height");
+ if (!av.isNull()) {
+ h = av.toString().toDouble();
+ }
+ av = attrs.value("x");
+ if (!av.isNull()) {
+ x = av.toString().toDouble();
+ }
+ av = attrs.value("y");
+ if (!av.isNull()) {
+ y = av.toString().toDouble();
+ }
+ setProjectionRect(QRectF(QPointF(x, y), QSizeF(w, h)));
+ } else if (xml.isStartElement() && xml.name().toString() == "relation") {
+ expectedEnd = xml.name().toString();
+ // TODO Process the relation.
+ } else if (xml.isEndElement()) {
+ if (xml.name().toString() != expectedEnd) {
+ validTag = false;
+ break;
+ }
+ }
+ xml.readNext();
+ }
+ return validTag;
+}
+
+
void PlotRenderItem::paint(QPainter *painter) {
painter->setRenderHint(QPainter::Antialiasing, false);
painter->drawRect(rect());
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderitem.h #725972:725973
@@ -83,9 +83,12 @@
void clearRelations();
virtual void save(QXmlStreamWriter &xml);
+ virtual void saveInPlot(QXmlStreamWriter &xml);
virtual void paint(QPainter *painter);
virtual void paintRelations(QPainter *painter) = 0;
+ virtual bool configureFromXml(QXmlStreamReader &xml);
+
QString leftLabel() const;
QString bottomLabel() const;
QString rightLabel() const;
More information about the Kst
mailing list