diff options
| author | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-06-08 10:27:31 +0200 |
|---|---|---|
| committer | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-06-08 10:27:31 +0200 |
| commit | d847e6bf7929c8565bff4e17d9fd077b8e0ca74d (patch) | |
| tree | b3b06f5ecb08251d7ea1660ce5318a7eb38271b5 /rectangle.cpp | |
| parent | 45813562e266cf8e58ea9cb04f655bbb542a555e (diff) | |
| download | GUI_SS2015-d847e6bf7929c8565bff4e17d9fd077b8e0ca74d.tar.gz GUI_SS2015-d847e6bf7929c8565bff4e17d9fd077b8e0ca74d.zip | |
Add XML files for reading and writing
Diffstat (limited to 'rectangle.cpp')
| -rw-r--r-- | rectangle.cpp | 53 |
1 files changed, 48 insertions, 5 deletions
diff --git a/rectangle.cpp b/rectangle.cpp index 1a58add..edc8749 100644 --- a/rectangle.cpp +++ b/rectangle.cpp @@ -40,23 +40,24 @@ void Rectangle::draw(QPainter *painter) void Rectangle::move(const QPoint &oldPoint, const QPoint &newPoint) { - if(m_selected) + if (m_selected) { QPoint offset = newPoint - oldPoint; QVector3D vecOld(oldPoint); - if(vecOld.distanceToPoint(QVector3D(m_rectangle.topLeft())) < 5) + + if (vecOld.distanceToPoint(QVector3D(m_rectangle.topLeft())) < 5) { m_rectangle.setTopLeft(m_rectangle.topLeft() + offset); } - else if(vecOld.distanceToPoint(QVector3D(m_rectangle.topRight())) < 5) + else if (vecOld.distanceToPoint(QVector3D(m_rectangle.topRight())) < 5) { m_rectangle.setTopRight(m_rectangle.topRight() + offset); } - else if(vecOld.distanceToPoint(QVector3D(m_rectangle.bottomLeft())) < 5) + else if (vecOld.distanceToPoint(QVector3D(m_rectangle.bottomLeft())) < 5) { m_rectangle.setBottomLeft(m_rectangle.bottomLeft() + offset); } - else if(vecOld.distanceToPoint(QVector3D(m_rectangle.bottomRight())) < 5) + else if (vecOld.distanceToPoint(QVector3D(m_rectangle.bottomRight())) < 5) { m_rectangle.setBottomRight(m_rectangle.bottomRight() + offset); } @@ -67,3 +68,45 @@ void Rectangle::move(const QPoint &oldPoint, const QPoint &newPoint) } } } + + +bool Rectangle::attributesToDom(QDomDocument *doc, QDomElement &e) +{ + if (e.isNull()) + { + qDebug() << className() << "::attributesToDom Error: NULL element passed."; + return false; + } + else + { + e.setAttribute("x1", m_rectangle.topLeft().rx()); + e.setAttribute("y1", m_rectangle.topLeft().ry()); + e.setAttribute("x2", m_rectangle.bottomRight().rx()); + e.setAttribute("y2", m_rectangle.bottomRight().ry()); + + return true; + } +} + +bool Rectangle::attributesFromDom(const QDomElement &e) +{ + if (e.isNull()) + { + qDebug() << className() << "::attributesFromDom Error: NULL element passed."; + return false; + } + else + { + m_rectangle.setTopLeft(QPoint(e.attribute("x1", "0").toInt(), + e.attribute("y1", "0").toInt())); + m_rectangle.setBottomRight(QPoint(e.attribute("x2", "0").toInt(), + e.attribute("y2", "0").toInt())); + + return true; + } +} + +QString Rectangle::className() +{ + return "Rectangle"; +} |
