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 /line.cpp | |
| parent | 45813562e266cf8e58ea9cb04f655bbb542a555e (diff) | |
| download | GUI_SS2015-d847e6bf7929c8565bff4e17d9fd077b8e0ca74d.tar.gz GUI_SS2015-d847e6bf7929c8565bff4e17d9fd077b8e0ca74d.zip | |
Add XML files for reading and writing
Diffstat (limited to 'line.cpp')
| -rw-r--r-- | line.cpp | 77 |
1 files changed, 72 insertions, 5 deletions
@@ -1,7 +1,7 @@ #include "line.h" Line::Line() - :QLine() + : QLine() { m_selected = true; } @@ -25,7 +25,7 @@ void Line::setSelected(bool selected) void Line::draw(QPainter *painter) { - if(m_selected) + if (m_selected) { QPen penTemp(Qt::DotLine); penTemp.setColor(Qt::red); @@ -47,15 +47,16 @@ void Line::draw(QPainter *painter) void Line::move(const QPoint &oldPoint, const QPoint &newPoint) { - if(m_selected) + if (m_selected) { QPoint offset = newPoint - oldPoint; QVector3D vecOld(oldPoint); - if(vecOld.distanceToPoint(QVector3D(p1())) < 5) + + if (vecOld.distanceToPoint(QVector3D(p1())) < 5) { setP1(p1() + offset); } - else if(vecOld.distanceToPoint(QVector3D(p2())) < 5) + else if (vecOld.distanceToPoint(QVector3D(p2())) < 5) { setP2(p2() + offset); } @@ -66,3 +67,69 @@ void Line::move(const QPoint &oldPoint, const QPoint &newPoint) } } } + +QDomElement Line::toDomElement(QDomDocument *doc) +{ + QDomElement e = doc->createElement(className()); + attributesToDom(doc, e); + return e; +} + +bool Line::attributesToDom(QDomDocument *doc, QDomElement &e) +{ + if (e.isNull()) + { + qDebug() << className() << "::attributesToDom Error: NULL element passed."; + return false; + } + else + { + e.setAttribute("x1", p1().rx()); + e.setAttribute("y1", p1().ry()); + e.setAttribute("x2", p2().rx()); + e.setAttribute("y2", p2().ry()); + + return true; + } +} + +bool Line::fromDomElement(const QDomElement &e) +{ + if (e.isNull()) + { + qDebug() << className() << "::fromQDomElement Error: NULL element passed."; + return false; + } + + if (className() != e.tagName()) + { + qDebug() << className() << "::fromQDomElement Error: Invalid element type: " << + e.tagName() << " instead of " << className(); + return false; + } + + return attributesFromDom(e); +} + +bool Line::attributesFromDom(const QDomElement &e) +{ + if (e.isNull()) + { + qDebug() << className() << "::attributesFromDom Error: NULL element passed."; + return false; + } + else + { + QPoint newP1(e.attribute("x1", "0").toInt(), e.attribute("y1", "0").toInt()); + QPoint newP2(e.attribute("x2", "0").toInt(), e.attribute("y2", "0").toInt()); + + setPoints(newP1, newP2); + + return true; + } +} + +QString Line::className() +{ + return "Line"; +} |
