mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-08 21:14:14 +02:00
Read the default border's column width and row height as decimals
BorderProperties::toXml() writes colsize and rowsize with "%1", so a project whose default border has a width such as 60.5 saves it as "60.5". fromXml() read both back with toInt(), which is 0 for a decimal, and the folio clamps 0 to its 5 px minimum. New folios of such a project got 5 px columns and rows. The folio's own reader, BorderTitleBlock::borderFromXml(), already uses toDouble(). Read the two sizes with toDouble(&ok) and keep the previous value when the attribute is missing, not a number, or not finite. No file-format change: toXml() is untouched, and whole-number sizes, which every example project has, load exactly as before. Tests: tst_borderpropertiesxml compiles borderproperties.cpp alone and reads 50, 60.5, 61.3 and 61.7 back, round-trips 60.5/80.25 through toXml(), and leaves the value alone for a missing, text, nan or inf attribute. Seven cases fail on master. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Signed-off-by: Beat Hangartner <beat@hangartners.ch>
This commit is contained in:
@@ -117,9 +117,15 @@ void BorderProperties::toXml(QDomElement &e) const
|
||||
*/
|
||||
void BorderProperties::fromXml(QDomElement &e) {
|
||||
if (e.hasAttribute("cols")) columns_count = e.attribute("cols").toInt();
|
||||
if (e.hasAttribute("colsize")) columns_width = e.attribute("colsize").toInt();
|
||||
if (e.hasAttribute("rows")) rows_count = e.attribute("rows").toInt();
|
||||
if (e.hasAttribute("rowsize")) rows_height = e.attribute("rowsize").toInt();
|
||||
// The sizes are decimals (toXml() writes them with %1), read as
|
||||
// BorderTitleBlock::borderFromXml() does; an unreadable value is
|
||||
// left as it was.
|
||||
bool ok;
|
||||
qreal size = e.attribute("colsize").toDouble(&ok);
|
||||
if (ok && qIsFinite(size)) columns_width = size;
|
||||
size = e.attribute("rowsize").toDouble(&ok);
|
||||
if (ok && qIsFinite(size)) rows_height = size;
|
||||
if (e.hasAttribute("displaycols")) display_columns = e.attribute("displaycols") == "true";
|
||||
if (e.hasAttribute("displayrows")) display_rows = e.attribute("displayrows") == "true";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user