From f6cfed8f2cb30ffa689ee1ed5e9b7ceee62f4866 Mon Sep 17 00:00:00 2001 From: "David A. Cuadrado" Date: Sat, 1 Dec 2007 17:45:14 -0500 Subject: [PATCH] Modified text and path XML format --- yamf/item/builder.cpp | 28 +++++++++++++++++----------- yamf/item/path.cpp | 2 +- yamf/item/serializer.cpp | 26 +++++++++++++------------- yamf/item/text.cpp | 5 ++--- 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/yamf/item/builder.cpp b/yamf/item/builder.cpp index 4ab1eee..25a42c7 100644 --- a/yamf/item/builder.cpp +++ b/yamf/item/builder.cpp @@ -169,7 +169,13 @@ bool Builder::startTag( const QString& qname, const QXmlAttributes& atts) D_FUNCINFOX("items") << qname; if ( qname == "path" ) { - QPainterPath path = DGraphics::PathHelper::fromString( atts.value("d") ); + QString data = atts.value("data"); + if( data.isNull() ) + { + data = atts.value("d"); + } + + QPainterPath path = DGraphics::PathHelper::fromString( data ); if ( d->addToGroup ) { @@ -252,7 +258,8 @@ bool Builder::startTag( const QString& qname, const QXmlAttributes& atts) else if ( qname == "text" ) { double width = atts.value("width").toDouble(); - QColor textColor(atts.value("textcolor")); + QColor textColor(atts.value("text-color")); + QString text = atts.value("data"); if( d->addToGroup ) { @@ -260,6 +267,7 @@ bool Builder::startTag( const QString& qname, const QXmlAttributes& atts) item->setTextWidth(width); item->setDefaultTextColor(textColor); + item->setPlainText(text); d->objects.push(item); } @@ -268,14 +276,17 @@ bool Builder::startTag( const QString& qname, const QXmlAttributes& atts) if ( !d->item ) d->item = createItem( qname ); - qgraphicsitem_cast(d->item)->setTextWidth(width); - qgraphicsitem_cast(d->item)->setDefaultTextColor(textColor); + Text *item = qgraphicsitem_cast(d->item); + + item->setTextWidth(width); + item->setDefaultTextColor(textColor); + item->setPlainText(text); d->objects.push(d->item); } - setReadText(true); - d->textReaded = ""; +// setReadText(true); +// d->textReaded = ""; } else if ( qname == "line" ) { @@ -469,11 +480,6 @@ bool Builder::endTag(const QString& qname) { d->groups.last()->addToGroup(d->objects.last()); } - - if(Text *text = qgraphicsitem_cast(d->objects.last()) ) - { - text->setPlainText(d->textReaded); - } d->objects.pop(); } else if ( qname == "group" ) diff --git a/yamf/item/path.cpp b/yamf/item/path.cpp index fccb003..8d459f1 100644 --- a/yamf/item/path.cpp +++ b/yamf/item/path.cpp @@ -79,7 +79,7 @@ QDomElement Path::toXml(QDomDocument &doc) const QDomElement root = doc.createElement("path"); QString strPath = DGraphics::PathHelper::toString(path()); - root.setAttribute( "d", strPath); + root.setAttribute( "data", strPath); root.appendChild(Serializer::properties( this, doc)); diff --git a/yamf/item/serializer.cpp b/yamf/item/serializer.cpp index c1fb8b8..de9e289 100644 --- a/yamf/item/serializer.cpp +++ b/yamf/item/serializer.cpp @@ -56,7 +56,7 @@ QDomElement Serializer::properties(const QGraphicsItem *item, QDomDocument &doc) properties.setAttribute("z", item->zValue()); properties.setAttribute( "enabled", item->isEnabled()); - properties.setAttribute( "flags", item->flags()); +// properties.setAttribute( "flags", item->flags()); return properties; @@ -78,7 +78,7 @@ void Serializer::properties(const QGraphicsItem *item, QXmlStreamWriter *writer) writer->writeAttribute( "enabled", item->isEnabled() ? "1" : "0" ); - writer->writeAttribute( "flags", QString::number(item->flags()) ); +// writer->writeAttribute( "flags", QString::number(item->flags()) ); writer->writeEndElement(); } @@ -100,7 +100,7 @@ void Serializer::loadProperties(QGraphicsItem *item, const QXmlAttributes &atts) item->setEnabled(atts.value("enabled") != "0"); // default true - item->setFlags( static_cast(atts.value("flags").toInt()) ); +// item->setFlags( static_cast(atts.value("flags").toInt()) ); item->setZValue( atts.value("z").toDouble() ); } @@ -125,7 +125,7 @@ void Serializer::loadProperties(QGraphicsItem *item, const QDomElement &element) item->setEnabled(element.attribute("enabled") != "0"); - item->setFlags( QGraphicsItem::GraphicsItemFlags(element.attribute("flags").toInt()) ); +// item->setFlags( QGraphicsItem::GraphicsItemFlags(element.attribute("flags").toInt()) ); item->setZValue( element.attribute("z").toDouble() ); } @@ -186,10 +186,10 @@ void Serializer::loadProperties(QGraphicsItem *item, QXmlStreamReader *reader) { item->setEnabled(att.value().toString() != "0"); } - else if( name == "flags" ) - { - item->setFlags( QGraphicsItem::GraphicsItemFlags(att.value().toString().toInt()) ); - } +// else if( name == "flags" ) +// { +// item->setFlags( QGraphicsItem::GraphicsItemFlags(att.value().toString().toInt()) ); +// } else if( name == "z" ) { item->setZValue( att.value().toString().toDouble() ); @@ -819,7 +819,7 @@ QDomElement Serializer::font(const QFont &font, QDomDocument &doc) QDomElement fontElement = doc.createElement("font"); fontElement.setAttribute( "family", font.family()); - fontElement.setAttribute( "pointsize", font.pointSize()); + fontElement.setAttribute( "point-size", font.pointSize()); fontElement.setAttribute( "weight", font.weight()); fontElement.setAttribute( "italic", font.italic()); fontElement.setAttribute( "bold", font.bold()); @@ -852,7 +852,7 @@ void Serializer::font(const QFont &_font, QXmlStreamWriter *writer) writer->writeStartElement("font"); writer->writeAttribute( "family", _font.family()); - writer->writeAttribute( "pointsize", QString::number(_font.pointSize())); + writer->writeAttribute( "point-size", QString::number(_font.pointSize())); writer->writeAttribute( "weight", QString::number(_font.weight())); writer->writeAttribute( "italic", QString::number(_font.italic())); writer->writeAttribute( "bold", QString::number(_font.bold())); @@ -870,7 +870,7 @@ void Serializer::font(const QFont &_font, QXmlStreamWriter *writer) */ void Serializer::loadFont(QFont &font, const QDomElement &e) { - font = QFont(e.attribute( "family" ), e.attribute( "pointsize", "-1").toInt(), e.attribute( "weight", "-1").toInt(), e.attribute( "italic", "0").toInt()); + font = QFont(e.attribute( "family" ), e.attribute( "point-size", "-1").toInt(), e.attribute( "weight", "-1").toInt(), e.attribute( "italic", "0").toInt()); font.setBold( e.attribute( "bold", "0").toInt( ) ); font.setStyle( QFont::Style(e.attribute( "style").toInt()) ); @@ -886,7 +886,7 @@ void Serializer::loadFont(QFont &font, const QDomElement &e) */ void Serializer::loadFont(QFont &font, const QXmlAttributes &atts) { - font = QFont(atts.value( "family" ), atts.value( "pointsize", "-1").toInt(), atts.value( "weight", "-1").toInt(), atts.value( "italic", "0").toInt()); + font = QFont(atts.value( "family" ), atts.value( "point-size", "-1").toInt(), atts.value( "weight", "-1").toInt(), atts.value( "italic", "0").toInt()); font.setBold( atts.value( "bold", "0").toInt( ) ); font.setStyle( QFont::Style(atts.value( "style").toInt()) ); @@ -939,7 +939,7 @@ void Serializer::loadFont(QFont &font, QXmlStreamReader *reader) { font.setFamily(att.value().toString()); } - else if(name == "pointsize") + else if(name == "point-size") { font.setPointSize(att.value().toString().toInt()); } diff --git a/yamf/item/text.cpp b/yamf/item/text.cpp index 68e8976..9afa73b 100644 --- a/yamf/item/text.cpp +++ b/yamf/item/text.cpp @@ -78,10 +78,9 @@ QDomElement Text::toXml(QDomDocument &doc) const { QDomElement root = doc.createElement("text"); root.setAttribute("width", textWidth() ); - root.setAttribute("textcolor", defaultTextColor().name() ); + root.setAttribute("text-color", defaultTextColor().name() ); - QDomText text = doc.createTextNode( toPlainText() ); - root.appendChild( text ); + root.setAttribute("data", toPlainText() ); root.appendChild( Serializer::properties( this, doc)); QFont font = this->font(); -- 2.11.4.GIT