mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 19:30:21 +02:00
* Auto-expand grouped PlayableModels.
This commit is contained in:
@@ -711,6 +711,8 @@ PlayableModel::insertInternal( const QList< T >& items, int row, const QList< To
|
|||||||
|
|
||||||
emit endInsertRows();
|
emit endInsertRows();
|
||||||
emit itemCountChanged( rowCount( QModelIndex() ) );
|
emit itemCountChanged( rowCount( QModelIndex() ) );
|
||||||
|
if ( parent.isValid() )
|
||||||
|
emit expandRequest( parent );
|
||||||
|
|
||||||
finishLoading();
|
finishLoading();
|
||||||
}
|
}
|
||||||
|
@@ -147,6 +147,8 @@ signals:
|
|||||||
void changed();
|
void changed();
|
||||||
void currentIndexChanged();
|
void currentIndexChanged();
|
||||||
|
|
||||||
|
void expandRequest( const QPersistentModelIndex& index );
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void setCurrentIndex( const QModelIndex& index );
|
virtual void setCurrentIndex( const QModelIndex& index );
|
||||||
|
|
||||||
|
@@ -112,6 +112,7 @@ PlayableProxyModel::setSourcePlayableModel( PlayableModel* sourceModel )
|
|||||||
disconnect( m_model, SIGNAL( indexPlayable( QModelIndex ) ), this, SLOT( onIndexPlayable( QModelIndex ) ) );
|
disconnect( m_model, SIGNAL( indexPlayable( QModelIndex ) ), this, SLOT( onIndexPlayable( QModelIndex ) ) );
|
||||||
disconnect( m_model, SIGNAL( indexResolved( QModelIndex ) ), this, SLOT( onIndexResolved( QModelIndex ) ) );
|
disconnect( m_model, SIGNAL( indexResolved( QModelIndex ) ), this, SLOT( onIndexResolved( QModelIndex ) ) );
|
||||||
disconnect( m_model, SIGNAL( currentIndexChanged() ), this, SIGNAL( currentIndexChanged() ) );
|
disconnect( m_model, SIGNAL( currentIndexChanged() ), this, SIGNAL( currentIndexChanged() ) );
|
||||||
|
disconnect( m_model, SIGNAL( expandRequest( QPersistentModelIndex ) ), this, SLOT( expandRequested( QPersistentModelIndex ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_model = sourceModel;
|
m_model = sourceModel;
|
||||||
@@ -124,6 +125,7 @@ PlayableProxyModel::setSourcePlayableModel( PlayableModel* sourceModel )
|
|||||||
connect( m_model, SIGNAL( indexPlayable( QModelIndex ) ), SLOT( onIndexPlayable( QModelIndex ) ) );
|
connect( m_model, SIGNAL( indexPlayable( QModelIndex ) ), SLOT( onIndexPlayable( QModelIndex ) ) );
|
||||||
connect( m_model, SIGNAL( indexResolved( QModelIndex ) ), SLOT( onIndexResolved( QModelIndex ) ) );
|
connect( m_model, SIGNAL( indexResolved( QModelIndex ) ), SLOT( onIndexResolved( QModelIndex ) ) );
|
||||||
connect( m_model, SIGNAL( currentIndexChanged() ), SIGNAL( currentIndexChanged() ) );
|
connect( m_model, SIGNAL( currentIndexChanged() ), SIGNAL( currentIndexChanged() ) );
|
||||||
|
connect( m_model, SIGNAL( expandRequest( QPersistentModelIndex ) ), SLOT( expandRequested( QPersistentModelIndex ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
QSortFilterProxyModel::setSourceModel( m_model );
|
QSortFilterProxyModel::setSourceModel( m_model );
|
||||||
@@ -660,3 +662,10 @@ PlayableProxyModel::onIndexResolved( const QModelIndex& index )
|
|||||||
{
|
{
|
||||||
emit indexResolved( mapFromSource( index ) );
|
emit indexResolved( mapFromSource( index ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlayableProxyModel::expandRequested( const QPersistentModelIndex& idx )
|
||||||
|
{
|
||||||
|
emit expandRequest( QPersistentModelIndex( mapFromSource( idx ) ) );
|
||||||
|
}
|
||||||
|
@@ -99,6 +99,8 @@ signals:
|
|||||||
|
|
||||||
void itemCountChanged( unsigned int items );
|
void itemCountChanged( unsigned int items );
|
||||||
|
|
||||||
|
void expandRequest( const QPersistentModelIndex& index );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const;
|
virtual bool filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const;
|
||||||
virtual bool lessThan( const QModelIndex& left, const QModelIndex& right ) const;
|
virtual bool lessThan( const QModelIndex& left, const QModelIndex& right ) const;
|
||||||
@@ -109,6 +111,8 @@ private slots:
|
|||||||
void onIndexPlayable( const QModelIndex& index );
|
void onIndexPlayable( const QModelIndex& index );
|
||||||
void onIndexResolved( const QModelIndex& index );
|
void onIndexResolved( const QModelIndex& index );
|
||||||
|
|
||||||
|
void expandRequested( const QPersistentModelIndex& index );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool lessThan( int column, const Tomahawk::query_ptr& left, const Tomahawk::query_ptr& right ) const;
|
virtual bool lessThan( int column, const Tomahawk::query_ptr& left, const Tomahawk::query_ptr& right ) const;
|
||||||
|
|
||||||
|
@@ -331,6 +331,8 @@ PlaylistModel::insertEntries( const QList< Tomahawk::plentry_ptr >& entries, int
|
|||||||
|
|
||||||
emit endInsertRows();
|
emit endInsertRows();
|
||||||
emit itemCountChanged( rowCount( QModelIndex() ) );
|
emit itemCountChanged( rowCount( QModelIndex() ) );
|
||||||
|
if ( parent.isValid() )
|
||||||
|
emit expandRequest( parent );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -63,6 +63,7 @@ TrackView::TrackView( QWidget* parent )
|
|||||||
, m_dragging( false )
|
, m_dragging( false )
|
||||||
, m_updateContextView( true )
|
, m_updateContextView( true )
|
||||||
, m_alternatingRowColors( false )
|
, m_alternatingRowColors( false )
|
||||||
|
, m_autoExpanding( true )
|
||||||
, m_contextMenu( new ContextMenu( this ) )
|
, m_contextMenu( new ContextMenu( this ) )
|
||||||
{
|
{
|
||||||
setFrameShape( QFrame::NoFrame );
|
setFrameShape( QFrame::NoFrame );
|
||||||
@@ -162,6 +163,7 @@ TrackView::setProxyModel( PlayableProxyModel* model )
|
|||||||
disconnect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( onViewChanged() ) );
|
disconnect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( onViewChanged() ) );
|
||||||
disconnect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( verifySize() ) );
|
disconnect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( verifySize() ) );
|
||||||
disconnect( m_proxyModel, SIGNAL( rowsRemoved( QModelIndex, int, int ) ), this, SLOT( verifySize() ) );
|
disconnect( m_proxyModel, SIGNAL( rowsRemoved( QModelIndex, int, int ) ), this, SLOT( verifySize() ) );
|
||||||
|
disconnect( m_proxyModel, SIGNAL( expandRequest( QPersistentModelIndex ) ), this, SLOT( expand( QPersistentModelIndex ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_proxyModel = model;
|
m_proxyModel = model;
|
||||||
@@ -172,6 +174,7 @@ TrackView::setProxyModel( PlayableProxyModel* model )
|
|||||||
connect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( onViewChanged() ) );
|
connect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( onViewChanged() ) );
|
||||||
connect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( verifySize() ) );
|
connect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( verifySize() ) );
|
||||||
connect( m_proxyModel, SIGNAL( rowsRemoved( QModelIndex, int, int ) ), SLOT( verifySize() ) );
|
connect( m_proxyModel, SIGNAL( rowsRemoved( QModelIndex, int, int ) ), SLOT( verifySize() ) );
|
||||||
|
connect( m_proxyModel, SIGNAL( expandRequest( QPersistentModelIndex ) ), SLOT( expand( QPersistentModelIndex ) ) );
|
||||||
|
|
||||||
m_delegate = new PlaylistItemDelegate( this, m_proxyModel );
|
m_delegate = new PlaylistItemDelegate( this, m_proxyModel );
|
||||||
QTreeView::setItemDelegate( m_delegate );
|
QTreeView::setItemDelegate( m_delegate );
|
||||||
@@ -205,11 +208,8 @@ void
|
|||||||
TrackView::setPlayableModel( PlayableModel* model )
|
TrackView::setPlayableModel( PlayableModel* model )
|
||||||
{
|
{
|
||||||
if ( m_model ) {
|
if ( m_model ) {
|
||||||
disconnect( m_model, SIGNAL( loadingStarted() ),
|
disconnect( m_model, SIGNAL( loadingStarted() ), m_loadingSpinner, SLOT( fadeIn() ) );
|
||||||
m_loadingSpinner, SLOT( fadeIn() ) );
|
disconnect( m_model, SIGNAL( loadingFinished() ), m_loadingSpinner, SLOT( fadeOut() ) );
|
||||||
disconnect( m_model, SIGNAL( loadingFinished() ),
|
|
||||||
m_loadingSpinner, SLOT( fadeOut() ) );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_model = model;
|
m_model = model;
|
||||||
@@ -236,10 +236,13 @@ TrackView::setPlayableModel( PlayableModel* model )
|
|||||||
setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
|
setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
|
||||||
}
|
}
|
||||||
|
|
||||||
connect( m_model, SIGNAL( loadingStarted() ),
|
connect( m_model, SIGNAL( loadingStarted() ), m_loadingSpinner, SLOT( fadeIn() ) );
|
||||||
m_loadingSpinner, SLOT( fadeIn() ) );
|
connect( m_model, SIGNAL( loadingFinished() ), m_loadingSpinner, SLOT( fadeOut() ) );
|
||||||
connect( m_model, SIGNAL( loadingFinished() ),
|
|
||||||
m_loadingSpinner, SLOT( fadeOut() ) );
|
if ( m_autoExpanding )
|
||||||
|
{
|
||||||
|
expandAll();
|
||||||
|
}
|
||||||
|
|
||||||
onViewChanged();
|
onViewChanged();
|
||||||
emit modelChanged();
|
emit modelChanged();
|
||||||
@@ -842,3 +845,10 @@ TrackView::setAlternatingRowColors( bool enable )
|
|||||||
m_alternatingRowColors = enable;
|
m_alternatingRowColors = enable;
|
||||||
QTreeView::setAlternatingRowColors( enable );
|
QTreeView::setAlternatingRowColors( enable );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TrackView::expand( const QPersistentModelIndex& idx )
|
||||||
|
{
|
||||||
|
QTreeView::expand( idx );
|
||||||
|
}
|
||||||
|
@@ -85,6 +85,7 @@ public:
|
|||||||
void setAutoResize( bool b );
|
void setAutoResize( bool b );
|
||||||
|
|
||||||
void setAlternatingRowColors( bool enable );
|
void setAlternatingRowColors( bool enable );
|
||||||
|
void setAutoExpanding( bool enable );
|
||||||
|
|
||||||
// Starts playing from the beginning if resolved, or waits until a track is playable
|
// Starts playing from the beginning if resolved, or waits until a track is playable
|
||||||
void startPlayingFromStart();
|
void startPlayingFromStart();
|
||||||
@@ -100,6 +101,8 @@ public slots:
|
|||||||
void onViewChanged();
|
void onViewChanged();
|
||||||
void onScrollTimeout();
|
void onScrollTimeout();
|
||||||
|
|
||||||
|
void expand( const QPersistentModelIndex& idx );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void itemActivated( const QModelIndex& index );
|
void itemActivated( const QModelIndex& index );
|
||||||
void querySelected( const Tomahawk::query_ptr& query );
|
void querySelected( const Tomahawk::query_ptr& query );
|
||||||
@@ -155,6 +158,7 @@ private:
|
|||||||
bool m_updateContextView;
|
bool m_updateContextView;
|
||||||
bool m_autoResize;
|
bool m_autoResize;
|
||||||
bool m_alternatingRowColors;
|
bool m_alternatingRowColors;
|
||||||
|
bool m_autoExpanding;
|
||||||
|
|
||||||
QModelIndex m_contextMenuIndex;
|
QModelIndex m_contextMenuIndex;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user