Skip to content

Commit

Permalink
* Restore a view's state if the model's guid changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Nov 14, 2012
1 parent 55821c6 commit f5ff0c4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 21 additions & 4 deletions src/libtomahawk/playlist/ViewHeader.cpp
Expand Up @@ -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 ) )
Expand All @@ -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;
}

Expand Down Expand Up @@ -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();
}
}
2 changes: 1 addition & 1 deletion src/libtomahawk/playlist/ViewHeader.h
Expand Up @@ -37,7 +37,7 @@ Q_OBJECT
void setDefaultColumnWeights( QList<double> 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 );
Expand Down

0 comments on commit f5ff0c4

Please sign in to comment.