From f5ff0c45585c5bb27776de038e7e7fe1c00fe0d1 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 14 Nov 2012 07:26:04 +0100 Subject: [PATCH] * Restore a view's state if the model's guid changed. --- src/libtomahawk/playlist/ViewHeader.cpp | 25 +++++++++++++++++++++---- src/libtomahawk/playlist/ViewHeader.h | 2 +- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/libtomahawk/playlist/ViewHeader.cpp b/src/libtomahawk/playlist/ViewHeader.cpp index 96d9020aa..51ab8a340 100644 --- a/src/libtomahawk/playlist/ViewHeader.cpp +++ b/src/libtomahawk/playlist/ViewHeader.cpp @@ -72,17 +72,22 @@ ViewHeader::checkState() if ( !count() || m_init ) return false; + disconnect( this, SIGNAL( sectionMoved( int, int, int ) ), this, SLOT( onSectionsChanged() ) ); + disconnect( this, SIGNAL( sectionResized( int, int, int ) ), this, SLOT( onSectionsChanged() ) ); + QByteArray state; + tDebug( LOGVERBOSE ) << "Restoring columns state for view:" << m_guid; + if ( !m_guid.isEmpty() ) state = TomahawkSettings::instance()->playlistColumnSizes( m_guid ); if ( !state.isEmpty() ) { - tDebug( LOGVERBOSE ) << "Restoring columns state for view:" << m_guid; restoreState( state ); } else { + tDebug( LOGVERBOSE ) << "Giving columns initial weighting:" << m_columnWeights; for ( int i = 0; i < count() - 1; i++ ) { if ( isSectionHidden( i ) ) @@ -95,10 +100,10 @@ ViewHeader::checkState() } } - m_init = true; connect( this, SIGNAL( sectionMoved( int, int, int ) ), SLOT( onSectionsChanged() ) ); connect( this, SIGNAL( sectionResized( int, int, int ) ), SLOT( onSectionsChanged() ) ); + m_init = true; return true; } @@ -139,10 +144,22 @@ ViewHeader::onToggleResizeColumns() void ViewHeader::toggleVisibility( int index ) { - qDebug() << Q_FUNC_INFO << index; - if ( isSectionHidden( index ) ) showSection( index ); else hideSection( index ); } + + +void ViewHeader::setGuid( const QString& guid ) +{ + m_guid = guid; + + // If we are _not_ initialized yet, this means we're still waiting for the view to resize initially. + // We need to wait with restoring our state (column sizes) until that has happened. + if ( m_init ) + { + m_init = false; + checkState(); + } +} diff --git a/src/libtomahawk/playlist/ViewHeader.h b/src/libtomahawk/playlist/ViewHeader.h index 39bb78c66..002f65379 100644 --- a/src/libtomahawk/playlist/ViewHeader.h +++ b/src/libtomahawk/playlist/ViewHeader.h @@ -37,7 +37,7 @@ public: void setDefaultColumnWeights( QList weights ) { m_columnWeights = weights; } QString guid() const { return m_guid; } - void setGuid( const QString& guid ) { m_guid = guid; } + void setGuid( const QString& guid ); public slots: void toggleVisibility( int index );