diff --git a/sources/qetgraphicsitem/dynamicelementtextitem.cpp b/sources/qetgraphicsitem/dynamicelementtextitem.cpp index a9af725ae..8cd32830a 100644 --- a/sources/qetgraphicsitem/dynamicelementtextitem.cpp +++ b/sources/qetgraphicsitem/dynamicelementtextitem.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include /** @@ -221,8 +222,16 @@ void DynamicElementTextItem::fromXml(const QDomElement &dom_elmt) //Force the update of the displayed text setTextFrom(m_text_from); - QGraphicsTextItem::setPos(dom_elmt.attribute("x", QString::number(0)).toDouble(), - dom_elmt.attribute("y", QString::number(0)).toDouble()); + //QString::toDouble() accepts "nan"/"inf"/"-inf" as a successful + //conversion, so a corrupted or hand-edited file can hand this a + //non-finite position -- fall back to 0 the same way a missing + //attribute already does, rather than letting it reach the scene + //(see the matching comment in Element::valideXml(), the fromXml() + //gate a plain element's position goes through; this text item has + //no such gate to reject the whole item at, so it clamps instead). + double x = dom_elmt.attribute("x", QString::number(0)).toDouble(); + double y = dom_elmt.attribute("y", QString::number(0)).toDouble(); + QGraphicsTextItem::setPos(qIsFinite(x) ? x : 0, qIsFinite(y) ? y : 0); } /** diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 23c9eda42..14b3a8f4f 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -53,6 +53,7 @@ static const QString plcTerminalKeys[] = { #include #include +#include #include class ElementXmlRetroCompatibility @@ -699,11 +700,16 @@ bool Element::valideXml(QDomElement &e) } bool conv_ok; - e.attribute(QStringLiteral("x")).toDouble(&conv_ok); - if (!conv_ok) return(false); + //QString::toDouble() accepts "nan"/"inf"/"-inf" and reports a + //successful conversion for them, so conv_ok alone doesn't reject a + //non-finite coordinate. A NaN position reaching the scene can hang + //QGraphicsScene::addItem() forever inside Qt's own polygon-clipping + //code when an existing conductor's collision test runs against it. + double x = e.attribute(QStringLiteral("x")).toDouble(&conv_ok); + if (!conv_ok || !qIsFinite(x)) return(false); - e.attribute(QStringLiteral("y")).toDouble(&conv_ok); - if (!conv_ok) return(false); + double y = e.attribute(QStringLiteral("y")).toDouble(&conv_ok); + if (!conv_ok || !qIsFinite(y)) return(false); return(true); } diff --git a/sources/qetgraphicsitem/terminal.cpp b/sources/qetgraphicsitem/terminal.cpp index ec862b39c..aa2b3024f 100644 --- a/sources/qetgraphicsitem/terminal.cpp +++ b/sources/qetgraphicsitem/terminal.cpp @@ -25,6 +25,7 @@ #include "../qetgraphicsitem/element.h" #include "conductortextitem.h" +#include #include QColor Terminal::neutralColor = QColor(Qt::blue); @@ -741,13 +742,17 @@ bool Terminal::valideXml(QDomElement &terminal) if (!terminal.hasAttribute("orientation")) return(false); bool conv_ok; + //QString::toDouble() accepts "nan"/"inf"/"-inf" and reports a + //successful conversion for them, so conv_ok alone doesn't reject a + //non-finite coordinate -- see the matching comment in + //Element::valideXml(). // parse l'abscisse - terminal.attribute("x").toDouble(&conv_ok); - if (!conv_ok) return(false); + double x = terminal.attribute("x").toDouble(&conv_ok); + if (!conv_ok || !qIsFinite(x)) return(false); // parse l'ordonnee - terminal.attribute("y").toDouble(&conv_ok); - if (!conv_ok) return(false); + double y = terminal.attribute("y").toDouble(&conv_ok); + if (!conv_ok || !qIsFinite(y)) return(false); // parse l'id terminal.attribute("id").toInt(&conv_ok);