Basic Shapes: XML export/import added.

Many files were changed, so debugging required.
Minor Bug exists: 
If we export to xml first time, it is OK. But if we then add another shape and then export, then the new shape is not added in XML.
Reason: UndoAction not implemented at present for basi shape addition.


git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2888 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
abhishekm71
2014-02-28 14:30:59 +00:00
parent dce76e46c9
commit 092c638868
11 changed files with 195 additions and 31 deletions

View File

@@ -1,10 +1,12 @@
#include "qetshapeitem.h"
QetShapeItem::QetShapeItem(QPointF p1, QPointF p2, ShapeType type, bool lineAngle,QGraphicsItem *parent) :
QetGraphicsItem(parent),
_shapeStyle(Qt::DashLine),
_lineAngle(lineAngle),
_isFullyBuilt(false)
_isFullyBuilt(false),
_writingXml(false)
{
_shapeType = type;
_boundingRect = QRectF(p1, p2);
@@ -96,24 +98,63 @@ QPainterPath QetShapeItem::shape() const
void QetShapeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter -> setRenderHint(QPainter::Antialiasing, false);
QRectF rec = boundingRect();
QPen pen(Qt::black);
if (isSelected())
pen.setColor(Qt::red);
pen.setStyle(_shapeStyle);
painter->setPen(pen);
switch(_shapeType) {
case Line:
if (_lineAngle)
painter -> drawLine(rec.topRight(), rec.bottomLeft());
else
painter -> drawLine(rec.topLeft(), rec.bottomRight());
break;
case Rectangle:
painter -> drawRect(rec);
break;
default: //(case Ellipse:)
painter ->drawEllipse(rec);
if (!_writingXml) {
painter -> setRenderHint(QPainter::Antialiasing, false);
QRectF rec = boundingRect();
QPen pen(Qt::black);
if (isSelected())
pen.setColor(Qt::red);
pen.setStyle(_shapeStyle);
painter->setPen(pen);
switch(_shapeType) {
case Line:
if (_lineAngle)
painter -> drawLine(rec.topRight(), rec.bottomLeft());
else
painter -> drawLine(rec.topLeft(), rec.bottomRight());
break;
case Rectangle:
painter -> drawRect(rec);
break;
default: //(case Ellipse:)
painter ->drawEllipse(rec);
}
}
}
bool QetShapeItem::fromXml(const QDomElement &e)
{
if (!_writingXml) {
if (e.tagName() != "shape") return (false);
_shapeType = QetShapeItem::ShapeType(e.attribute("type","0").toInt());
_shapeStyle = Qt::PenStyle(e.attribute("style","0").toInt());
_lineAngle = e.attribute("lineAngle","0").toInt();
qreal x = e.attribute("x","0").toDouble();
qreal y = e.attribute("y","0").toDouble();
qreal w = e.attribute("w","0").toDouble();
qreal h = e.attribute("h","0").toDouble();
setBoundingRect(QRectF(x, y, w, h));
setFullyBuilt(true);
}
return (true);
}
QDomElement QetShapeItem::toXml(QDomDocument &document) const {
QDomElement result = document.createElement("shape");
QRectF rec = boundingRect();
//write some attribute
result.setAttribute("type", QString::number(_shapeType));
result.setAttribute("x", QString::number(rec.topLeft().x()));
result.setAttribute("y", QString::number(rec.topLeft().y()));
result.setAttribute("w", QString::number(rec.width()));
result.setAttribute("h", QString::number(rec.height()));
result.setAttribute("lineAngle", QString::number(_lineAngle));
result.setAttribute("style", QString::number(_shapeStyle));
return(result);
}