mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-30 14:54:13 +02:00
Merge pull request #1161 from ispyisail/fix/wire-nonfinite-values
Reject non-finite values when loading a wire
This commit is contained in:
@@ -1099,8 +1099,10 @@ bool Conductor::fromXml(QDomElement &dom_element)
|
||||
m_uuid = QUuid::createUuid();
|
||||
}
|
||||
|
||||
setPos(dom_element.attribute("x", nullptr).toDouble(),
|
||||
dom_element.attribute("y", nullptr).toDouble());
|
||||
//"nan" and "inf" parse as numbers; a non-finite position is kept at 0
|
||||
const qreal x = dom_element.attribute("x", nullptr).toDouble();
|
||||
const qreal y = dom_element.attribute("y", nullptr).toDouble();
|
||||
setPos(qIsFinite(x) ? x : 0, qIsFinite(y) ? y : 0);
|
||||
|
||||
bool retval = pathFromXml(dom_element);
|
||||
|
||||
@@ -1229,7 +1231,10 @@ bool Conductor::pathFromXml(const QDomElement &e) {
|
||||
// cette longueur doit etre un reel
|
||||
bool ok;
|
||||
qreal segment_length = current_segment.attribute("length").toDouble(&ok);
|
||||
if (!ok) continue;
|
||||
// toDouble() accepts "nan" and "inf". A NaN length would also pass
|
||||
// the coherence check below (every comparison with NaN is false)
|
||||
// and turn the whole path into NaN.
|
||||
if (!ok || !qIsFinite(segment_length)) continue;
|
||||
|
||||
if (current_segment.attribute("orientation") == "horizontal") {
|
||||
segments_x << segment_length;
|
||||
|
||||
@@ -69,13 +69,17 @@ Conductor *ConductorTextItem::parentConductor() const
|
||||
@param e
|
||||
*/
|
||||
void ConductorTextItem::fromXml(const QDomElement &e) {
|
||||
if (e.hasAttribute("userx")) {
|
||||
setPos(e.attribute("userx").toDouble(),
|
||||
e.attribute("usery").toDouble());
|
||||
//A non-finite ("nan", "inf") position or rotation is ignored,
|
||||
//as if the text had never been moved or rotated
|
||||
const qreal x = e.attribute("userx").toDouble();
|
||||
const qreal y = e.attribute("usery").toDouble();
|
||||
if (e.hasAttribute("userx") && qIsFinite(x) && qIsFinite(y)) {
|
||||
setPos(x, y);
|
||||
moved_by_user_ = true;
|
||||
}
|
||||
if (e.hasAttribute("rotation")) {
|
||||
setRotation(e.attribute("rotation").toDouble());
|
||||
const qreal rotation = e.attribute("rotation").toDouble();
|
||||
if (e.hasAttribute("rotation") && qIsFinite(rotation)) {
|
||||
setRotation(rotation);
|
||||
rotate_by_user_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user