mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-08-13 10:04:13 +02:00
Fixing minimum width calculation for title block which could lead to division by zero and subsequent program crash if opening a template with only relative sized columns.
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QRegularExpressionMatch>
|
#include <QRegularExpressionMatch>
|
||||||
|
#include <limits>
|
||||||
/**
|
/**
|
||||||
@brief TitleBlockTemplate::TitleBlockTemplate
|
@brief TitleBlockTemplate::TitleBlockTemplate
|
||||||
Constructor
|
Constructor
|
||||||
@@ -973,14 +974,20 @@ int TitleBlockTemplate::minimumWidth()
|
|||||||
// => (1 - (sum(REL)/100))TOT >= sum(ABS)
|
// => (1 - (sum(REL)/100))TOT >= sum(ABS)
|
||||||
// => TOT >= sum(ABS) / (1 - (sum(REL)/100))
|
// => TOT >= sum(ABS) / (1 - (sum(REL)/100))
|
||||||
// => TOT >= sum(ABS) / ((100 - sum(REL))/100))
|
// => TOT >= sum(ABS) / ((100 - sum(REL))/100))
|
||||||
return(
|
int abs_total = columnTypeTotal(QET::Absolute);
|
||||||
qRound(
|
qreal denominator = (100.0 - columnTypeTotal(QET::RelativeToTotalLength)) / 100.0;
|
||||||
columnTypeTotal(QET::Absolute)
|
|
||||||
/
|
if (denominator <= 0.0) {
|
||||||
((100.0 - columnTypeTotal(QET::RelativeToTotalLength))
|
// The relative-to-total-length columns alone already consume
|
||||||
/ 100.0)
|
// 100% (or more) of the available width, so the formula above
|
||||||
)
|
// would divide by zero (or go negative). If there are no
|
||||||
);
|
// absolute-width columns, there is no meaningful minimum width
|
||||||
|
// to enforce; if there are, the template is asking for more
|
||||||
|
// than 100% of its own width, which cannot be satisfied.
|
||||||
|
return abs_total > 0 ? std::numeric_limits<int>::max() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return(qRound(abs_total / denominator));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user