QskLinearLayoutEngine::clear added

This commit is contained in:
Uwe Rathmann 2019-07-13 10:36:12 +02:00
parent e9ff7cca40
commit 7788cdf1c9
2 changed files with 32 additions and 6 deletions

View File

@ -105,6 +105,7 @@ namespace
int spacerAt( int index ) const; int spacerAt( int index ) const;
bool removeAt( int index ); bool removeAt( int index );
bool clear();
bool isIgnoredAt( int index ) const; bool isIgnoredAt( int index ) const;
@ -302,9 +303,27 @@ void EntryTable::insertSpacer( int index, qreal spacing )
bool EntryTable::removeAt( int index ) bool EntryTable::removeAt( int index )
{ {
if ( index >= 0 && index < count() ) auto entry = entryAt( index );
if ( entry == nullptr )
return false;
if ( entry->isIgnored() )
m_sumIgnored--;
const auto itemType = QskLayoutConstraint::constraintType( entry->item() );
if ( itemType > QskLayoutConstraint::Unconstrained )
m_constraintType = -1;
m_entries.erase( m_entries.begin() + index );
return true;
}
bool EntryTable::clear()
{
if ( count() > 0 )
{ {
m_entries.erase( m_entries.begin() + index ); m_entries.clear();
invalidate(); invalidate();
return true; return true;
@ -454,15 +473,15 @@ QskLayoutConstraint::Type EntryTable::constraintType() const
for ( const auto& entry : m_entries ) for ( const auto& entry : m_entries )
{ {
const auto entryType = QskLayoutConstraint::constraintType( entry.item() ); const auto itemType = QskLayoutConstraint::constraintType( entry.item() );
if ( entryType != QskLayoutConstraint::Unconstrained ) if ( itemType != QskLayoutConstraint::Unconstrained )
{ {
if ( m_constraintType == QskLayoutConstraint::Unconstrained ) if ( m_constraintType == QskLayoutConstraint::Unconstrained )
{ {
m_constraintType = entryType; m_constraintType = itemType;
} }
else if ( m_constraintType != entryType ) else if ( m_constraintType != itemType )
{ {
qWarning( "QskLinearLayoutEngine: conflicting constraints"); qWarning( "QskLinearLayoutEngine: conflicting constraints");
m_constraintType = QskLayoutConstraint::Unconstrained; m_constraintType = QskLayoutConstraint::Unconstrained;
@ -810,6 +829,12 @@ void QskLinearLayoutEngine::removeAt( int index )
invalidate( CellCache | LayoutCache ); invalidate( CellCache | LayoutCache );
} }
void QskLinearLayoutEngine::clear()
{
if ( m_data->entryTable.clear() )
invalidate( CellCache | LayoutCache );
}
QQuickItem* QskLinearLayoutEngine::itemAt( int index ) const QQuickItem* QskLinearLayoutEngine::itemAt( int index ) const
{ {
return m_data->entryTable.itemAt( index ); return m_data->entryTable.itemAt( index );

View File

@ -50,6 +50,7 @@ class QskLinearLayoutEngine
void addSpacer( qreal spacing ); void addSpacer( qreal spacing );
void removeAt( int index ); void removeAt( int index );
void clear();
QQuickItem* itemAt( int index ) const; QQuickItem* itemAt( int index ) const;
int spacerAt( int index ) const; int spacerAt( int index ) const;