division by zero fixed
This commit is contained in:
parent
9f74523b88
commit
f0f2df43c0
|
@ -381,6 +381,9 @@ QskLayoutChain::Segments QskLayoutChain::preferredStretched( qreal size ) const
|
||||||
{
|
{
|
||||||
const int count = m_cells.size();
|
const int count = m_cells.size();
|
||||||
|
|
||||||
|
if ( count == 0 )
|
||||||
|
return Segments();
|
||||||
|
|
||||||
qreal sumFactors = 0.0;
|
qreal sumFactors = 0.0;
|
||||||
|
|
||||||
QVarLengthArray< qreal > factors( count );
|
QVarLengthArray< qreal > factors( count );
|
||||||
|
@ -413,36 +416,41 @@ QskLayoutChain::Segments QskLayoutChain::preferredStretched( qreal size ) const
|
||||||
sumFactors += factors[i];
|
sumFactors += factors[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
auto sumSizes = size - ( m_validCells - 1 ) * m_spacing;
|
qreal sumSizes = 0.0;
|
||||||
|
|
||||||
Q_FOREVER
|
if ( sumFactors > 0.0 )
|
||||||
{
|
{
|
||||||
bool done = true;
|
sumSizes = size - ( m_validCells - 1 ) * m_spacing;
|
||||||
|
|
||||||
for ( int i = 0; i < count; i++ )
|
Q_FOREVER
|
||||||
{
|
{
|
||||||
if ( factors[i] < 0.0 )
|
bool done = true;
|
||||||
continue;
|
|
||||||
|
|
||||||
const auto sz = sumSizes * factors[i] / sumFactors;
|
for ( int i = 0; i < count; i++ )
|
||||||
|
|
||||||
const auto& hint = m_cells[i].metrics;
|
|
||||||
const auto boundedSize =
|
|
||||||
qBound( hint.preferred(), sz, hint.maximum() );
|
|
||||||
|
|
||||||
if ( boundedSize != sz )
|
|
||||||
{
|
{
|
||||||
segments[i].length = boundedSize;
|
if ( factors[i] < 0.0 )
|
||||||
sumSizes -= boundedSize;
|
continue;
|
||||||
sumFactors -= factors[i];
|
|
||||||
factors[i] = -1.0;
|
|
||||||
|
|
||||||
done = false;
|
const auto sz = sumSizes * factors[i] / sumFactors;
|
||||||
|
|
||||||
|
const auto& hint = m_cells[i].metrics;
|
||||||
|
const auto boundedSize =
|
||||||
|
qBound( hint.preferred(), sz, hint.maximum() );
|
||||||
|
|
||||||
|
if ( boundedSize != sz )
|
||||||
|
{
|
||||||
|
segments[i].length = boundedSize;
|
||||||
|
sumSizes -= boundedSize;
|
||||||
|
sumFactors -= factors[i];
|
||||||
|
factors[i] = -1.0;
|
||||||
|
|
||||||
|
done = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ( done )
|
if ( done )
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal offset = 0;
|
qreal offset = 0;
|
||||||
|
|
Loading…
Reference in New Issue