mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-07 12:14:14 +02:00
Fix bugtracker #266: skip shapes with a nan coordinate in the element editor
A symbol with a "nan" or "inf" coordinate (bugtracker #266 had a line with x1="nan" x2="nan") opened with that shape invisible and the view off-centre. Moving the selection then snapped NaN through qRound() to INT_MIN, and saving wrote width="-2147483630", breaking the symbol. The folio already leaves such a shape out (ElementPictureFactory reads it with QET::attributeIsAReal()). Do the same in the element editor, and have --check-elements warn about it. Only geometry attributes are read, so a text whose content is "inf" is not affected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -256,6 +256,34 @@ bool QET::attributeIsAReal(
|
||||
return(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QET::hasNonFiniteGeometry
|
||||
@param shape a shape of an element definition (<line>, <rect>, <text>...)
|
||||
@return true if one of its coordinates or sizes is "nan" or "inf".
|
||||
The folio does not draw such a shape (see attributeIsAReal()), and the
|
||||
element editor cannot show or edit it.
|
||||
*/
|
||||
bool QET::hasNonFiniteGeometry(const QDomElement &shape)
|
||||
{
|
||||
static const QStringList geometry {
|
||||
"x", "y", "x1", "y1", "x2", "y2", "width", "height", "diameter",
|
||||
"rx", "ry", "start", "angle", "rotation", "length1", "length2"};
|
||||
static const QRegularExpression polygon_point("^[xy][0-9]+$");
|
||||
|
||||
const QDomNamedNodeMap attributes = shape.attributes();
|
||||
for (int i = 0 ; i < attributes.count() ; ++i)
|
||||
{
|
||||
const QDomAttr attribute = attributes.item(i).toAttr();
|
||||
if (!geometry.contains(attribute.name())
|
||||
&& !polygon_point.match(attribute.name()).hasMatch())
|
||||
continue;
|
||||
bool ok;
|
||||
const qreal value = attribute.value().toDouble(&ok);
|
||||
if (ok && !std::isfinite(value)) return(true);
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QET::infoFlagIsTrue
|
||||
@see the header comment for why this exists rather than a bare
|
||||
|
||||
Reference in New Issue
Block a user