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 /polygon.cpp | |
| parent | 45813562e266cf8e58ea9cb04f655bbb542a555e (diff) | |
| download | GUI_SS2015-d847e6bf7929c8565bff4e17d9fd077b8e0ca74d.tar.gz GUI_SS2015-d847e6bf7929c8565bff4e17d9fd077b8e0ca74d.zip | |
Add XML files for reading and writing
Diffstat (limited to 'polygon.cpp')
| -rw-r--r-- | polygon.cpp | 65 |
1 files changed, 61 insertions, 4 deletions
diff --git a/polygon.cpp b/polygon.cpp index d8b71b7..c785e7b 100644 --- a/polygon.cpp +++ b/polygon.cpp @@ -38,19 +38,20 @@ void Polygon::draw(QPainter *painter) void Polygon::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_polygon.point(0))) < 5) + + if (vecOld.distanceToPoint(QVector3D(m_polygon.point(0))) < 5) { m_polygon.replace(0, m_polygon.point(0) + offset); } - else if(vecOld.distanceToPoint(QVector3D(m_polygon.point(1))) < 5) + else if (vecOld.distanceToPoint(QVector3D(m_polygon.point(1))) < 5) { m_polygon.replace(1, m_polygon.point(1) + offset); } - else if(vecOld.distanceToPoint(QVector3D(m_polygon.point(2))) < 5) + else if (vecOld.distanceToPoint(QVector3D(m_polygon.point(2))) < 5) { m_polygon.replace(2, m_polygon.point(2) + offset); } @@ -62,3 +63,59 @@ void Polygon::move(const QPoint &oldPoint, const QPoint &newPoint) } } } + +bool Polygon::attributesToDom(QDomDocument *doc, QDomElement &e) +{ + if (e.isNull()) + { + qDebug() << className() << "::attributesToDom Error: NULL element passed."; + return false; + } + else + { + QDomElement tmp; + + foreach(QPoint point, m_polygon.toList()) + { + tmp = doc->createElement("Point"); + + tmp.setAttribute("x", point.rx()); + tmp.setAttribute("y", point.ry()); + + e.appendChild(tmp); + } + + return true; + } +} + +bool Polygon::attributesFromDom(const QDomElement &e) +{ + if (e.isNull()) + { + qDebug() << className() << "::attributesFromDom Error: NULL element passed."; + return false; + } + else + { + QDomElement child = e.firstChildElement("Point"); + + m_polygon.clear(); + + while(!child.isNull()) + { + QPoint tmp(child.attribute("x", "0").toInt(), child.attribute("y", "0").toInt()); + + m_polygon.append(tmp); + + child = child.nextSiblingElement("Point"); + } + + return true; + } +} + +QString Polygon::className() +{ + return "Polygon"; +} |
