debug operators, minor improvements
This commit is contained in:
parent
d600fe9d7b
commit
42388cb267
@ -4,6 +4,7 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#include "QskLayoutChain.h"
|
#include "QskLayoutChain.h"
|
||||||
|
#include "QskLayoutConstraint.h"
|
||||||
|
|
||||||
#include <qvarlengtharray.h>
|
#include <qvarlengtharray.h>
|
||||||
#include <qvector.h>
|
#include <qvector.h>
|
||||||
@ -39,9 +40,6 @@ void QskLayoutChain::addCell( int index, const Cell& cell )
|
|||||||
|
|
||||||
combinedCell.canGrow |= cell.canGrow;
|
combinedCell.canGrow |= cell.canGrow;
|
||||||
combinedCell.stretch = qMax( combinedCell.stretch, cell.stretch );
|
combinedCell.stretch = qMax( combinedCell.stretch, cell.stretch );
|
||||||
|
|
||||||
m_sumStretches += cell.stretch;
|
|
||||||
|
|
||||||
combinedCell.hint.intersect( cell.hint );
|
combinedCell.hint.intersect( cell.hint );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,24 +49,42 @@ void QskLayoutChain::finish()
|
|||||||
qreal preferred = 0.0;
|
qreal preferred = 0.0;
|
||||||
qreal maximum = 0.0;
|
qreal maximum = 0.0;
|
||||||
|
|
||||||
|
m_sumStretches = 0;
|
||||||
|
|
||||||
if ( !m_cells.empty() )
|
if ( !m_cells.empty() )
|
||||||
{
|
{
|
||||||
for ( auto& cellData : m_cells )
|
const auto maxMaximum = QskLayoutConstraint::unlimited;
|
||||||
{
|
|
||||||
minimum += cellData.hint.minimum();
|
|
||||||
preferred += cellData.hint.preferred();
|
|
||||||
|
|
||||||
if ( cellData.stretch == 0 && !cellData.canGrow )
|
for ( auto& cell : m_cells )
|
||||||
maximum += cellData.hint.preferred();
|
{
|
||||||
else
|
minimum += cell.hint.minimum();
|
||||||
maximum += cellData.hint.maximum(); // overflow ???
|
preferred += cell.hint.preferred();
|
||||||
|
|
||||||
|
if ( maximum < maxMaximum )
|
||||||
|
{
|
||||||
|
if ( cell.stretch == 0 && !cell.canGrow )
|
||||||
|
{
|
||||||
|
maximum += cell.hint.preferred();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( cell.hint.maximum() == maxMaximum )
|
||||||
|
maximum = maxMaximum;
|
||||||
|
else
|
||||||
|
maximum += cell.hint.maximum();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_sumStretches += cell.stretch;
|
||||||
}
|
}
|
||||||
|
|
||||||
const qreal spacing = ( m_cells.size() - 1 ) * m_spacing;
|
const qreal spacing = ( m_cells.size() - 1 ) * m_spacing;
|
||||||
|
|
||||||
minimum += spacing;
|
minimum += spacing;
|
||||||
preferred += spacing;
|
preferred += spacing;
|
||||||
maximum += spacing;
|
|
||||||
|
if ( maximum < maxMaximum )
|
||||||
|
maximum += spacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_boundingHint.setMinimum( minimum );
|
m_boundingHint.setMinimum( minimum );
|
||||||
@ -319,3 +335,30 @@ QVector< QskLayoutChain::Range > QskLayoutChain::preferredStretched( qreal size
|
|||||||
|
|
||||||
return ranges;
|
return ranges;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef QT_NO_DEBUG_STREAM
|
||||||
|
|
||||||
|
#include <qdebug.h>
|
||||||
|
|
||||||
|
QDebug operator<<( QDebug debug, const QskLayoutChain::Range& range )
|
||||||
|
{
|
||||||
|
QDebugStateSaver saver( debug );
|
||||||
|
debug.nospace();
|
||||||
|
|
||||||
|
debug << "( " << range.start << ", " << range.end() << " )";
|
||||||
|
|
||||||
|
return debug;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDebug operator<<( QDebug debug, const QskLayoutChain::Cell& cell )
|
||||||
|
{
|
||||||
|
QDebugStateSaver saver( debug );
|
||||||
|
debug.nospace();
|
||||||
|
|
||||||
|
debug << "( " << cell.hint << ", "
|
||||||
|
<< cell.stretch << ", " << cell.canGrow << " )";
|
||||||
|
return debug;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@ -7,9 +7,12 @@
|
|||||||
#define QSK_LAYOUT_CHAIN_H
|
#define QSK_LAYOUT_CHAIN_H
|
||||||
|
|
||||||
#include <QskLayoutHint.h>
|
#include <QskLayoutHint.h>
|
||||||
|
#include <qglobal.h>
|
||||||
#include <qvector.h>
|
#include <qvector.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
class QDebug;
|
||||||
|
|
||||||
class QskLayoutChain
|
class QskLayoutChain
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -25,6 +28,19 @@ class QskLayoutChain
|
|||||||
class Cell
|
class Cell
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
inline bool operator==( const Cell& other ) const
|
||||||
|
{
|
||||||
|
return ( canGrow == other.canGrow )
|
||||||
|
&& ( stretch == other.stretch )
|
||||||
|
&& ( hint == other.hint );
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator!=( const Cell& other ) const
|
||||||
|
{
|
||||||
|
return !( *this == other );
|
||||||
|
}
|
||||||
|
|
||||||
QskLayoutHint hint;
|
QskLayoutHint hint;
|
||||||
int stretch = 0;
|
int stretch = 0;
|
||||||
bool canGrow = false;
|
bool canGrow = false;
|
||||||
@ -37,9 +53,10 @@ class QskLayoutChain
|
|||||||
|
|
||||||
void reset( int count, qreal constraint );
|
void reset( int count, qreal constraint );
|
||||||
void addCell( int index, const Cell& );
|
void addCell( int index, const Cell& );
|
||||||
Cell cell( int index ) const { return m_cells[ index ]; }
|
|
||||||
void finish();
|
void finish();
|
||||||
|
|
||||||
|
const Cell& cell( int index ) const { return m_cells[ index ]; }
|
||||||
|
|
||||||
bool setSpacing( qreal spacing );
|
bool setSpacing( qreal spacing );
|
||||||
qreal spacing() const { return m_spacing; }
|
qreal spacing() const { return m_spacing; }
|
||||||
|
|
||||||
@ -68,4 +85,14 @@ class QskLayoutChain
|
|||||||
std::vector< Cell > m_cells;
|
std::vector< Cell > m_cells;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifndef QT_NO_DEBUG_STREAM
|
||||||
|
|
||||||
|
QDebug operator<<( QDebug, const QskLayoutChain::Range& );
|
||||||
|
QDebug operator<<( QDebug, const QskLayoutChain::Cell& );
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Q_DECLARE_TYPEINFO( QskLayoutChain::Range, Q_MOVABLE_TYPE );
|
||||||
|
Q_DECLARE_TYPEINFO( QskLayoutChain::Cell, Q_MOVABLE_TYPE );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user