From f8d364af0f38f36a0eb6685f8f6d488adac06ca8 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Mon, 9 Jul 2012 09:32:00 -0400 Subject: [PATCH] Set source model on proxy model --- src/TomahawkWindow.cpp | 2 ++ src/libtomahawk/jobview/JobStatusModel.cpp | 38 +++++++++++++--------- src/libtomahawk/jobview/JobStatusModel.h | 8 +++-- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/TomahawkWindow.cpp b/src/TomahawkWindow.cpp index 399b687a5..d8ea0ce22 100644 --- a/src/TomahawkWindow.cpp +++ b/src/TomahawkWindow.cpp @@ -266,7 +266,9 @@ TomahawkWindow::setupSideBar() m_sourcetree = new SourceTreeView( this ); JobStatusView* jobsView = new JobStatusView( m_sidebar ); + JobStatusModel* sourceModel = new JobStatusModel( jobsView ); m_jobsModel = new JobStatusSortModel( jobsView ); + m_jobsModel->setJobModel( sourceModel ); jobsView->setModel( m_jobsModel ); m_queueView = new QueueView( m_sidebar ); diff --git a/src/libtomahawk/jobview/JobStatusModel.cpp b/src/libtomahawk/jobview/JobStatusModel.cpp index 3c16810e7..1927946cc 100644 --- a/src/libtomahawk/jobview/JobStatusModel.cpp +++ b/src/libtomahawk/jobview/JobStatusModel.cpp @@ -27,16 +27,8 @@ JobStatusSortModel::JobStatusSortModel( QObject* parent ) : QSortFilterProxyModel( parent ) - , m_sourceModel( this ) { setDynamicSortFilter( true ); - - connect( &m_sourceModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( rowsInsertedSlot( QModelIndex, int, int ) ) ); - connect( &m_sourceModel, SIGNAL( rowsRemoved( QModelIndex, int, int ) ), this, SLOT( rowsRemovedSlot( QModelIndex, int, int ) ) ); - connect( &m_sourceModel, SIGNAL( modelReset() ), this, SLOT( modelResetSlot() ) ); - connect( &m_sourceModel, SIGNAL( customDelegateJobInserted( int, JobStatusItem* ) ), this, SLOT( customDelegateJobInsertedSlot( int, JobStatusItem* ) ) ); - connect( &m_sourceModel, SIGNAL( customDelegateJobRemoved( int ) ), this, SLOT( customDelegateJobRemovedSlot( int ) ) ); - connect( &m_sourceModel, SIGNAL( refreshDelegates() ), this, SLOT( refreshDelegatesSlot() ) ); } @@ -45,11 +37,27 @@ JobStatusSortModel::~JobStatusSortModel() } +void +JobStatusSortModel::setJobModel( JobStatusModel* model ) +{ + setSourceModel( model ); + + m_sourceModel = model; + + connect( m_sourceModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( rowsInsertedSlot( QModelIndex, int, int ) ) ); + connect( m_sourceModel, SIGNAL( rowsRemoved( QModelIndex, int, int ) ), this, SLOT( rowsRemovedSlot( QModelIndex, int, int ) ) ); + connect( m_sourceModel, SIGNAL( modelReset() ), this, SLOT( modelResetSlot() ) ); + connect( m_sourceModel, SIGNAL( customDelegateJobInserted( int, JobStatusItem* ) ), this, SLOT( customDelegateJobInsertedSlot( int, JobStatusItem* ) ) ); + connect( m_sourceModel, SIGNAL( customDelegateJobRemoved( int ) ), this, SLOT( customDelegateJobRemovedSlot( int ) ) ); + connect( m_sourceModel, SIGNAL( refreshDelegates() ), this, SLOT( refreshDelegatesSlot() ) ); +} + + void JobStatusSortModel::addJob( JobStatusItem* item ) { tLog( LOGVERBOSE ) << Q_FUNC_INFO; - m_sourceModel.addJob( item ); + m_sourceModel->addJob( item ); } @@ -81,7 +89,7 @@ void JobStatusSortModel::customDelegateJobInsertedSlot( int row, JobStatusItem* item ) { tLog( LOGVERBOSE ) << Q_FUNC_INFO; - emit customDelegateJobInserted( mapFromSource( m_sourceModel.index( row ) ).row(), item ); + emit customDelegateJobInserted( mapFromSource( m_sourceModel->index( row ) ).row(), item ); } @@ -89,7 +97,7 @@ void JobStatusSortModel::customDelegateJobRemovedSlot( int row ) { tLog( LOGVERBOSE ) << Q_FUNC_INFO; - emit customDelegateJobRemoved( mapFromSource( m_sourceModel.index( row ) ).row() ); + emit customDelegateJobRemoved( mapFromSource( m_sourceModel->index( row ) ).row() ); } @@ -203,9 +211,9 @@ JobStatusModel::data( const QModelIndex& index, int role ) const { case Qt::DecorationRole: return item->icon(); - + case Qt::ToolTipRole: - + case Qt::DisplayRole: { if ( m_collapseCount.contains( item->type() ) ) @@ -213,7 +221,7 @@ JobStatusModel::data( const QModelIndex& index, int role ) const else return item->mainText(); } - + case RightColumnRole: { if ( m_collapseCount.contains( item->type() ) ) @@ -221,7 +229,7 @@ JobStatusModel::data( const QModelIndex& index, int role ) const else return item->rightColumnText(); } - + case AllowMultiLineRole: return item->allowMultiLine(); diff --git a/src/libtomahawk/jobview/JobStatusModel.h b/src/libtomahawk/jobview/JobStatusModel.h index 56188ae8a..a0455f5b5 100644 --- a/src/libtomahawk/jobview/JobStatusModel.h +++ b/src/libtomahawk/jobview/JobStatusModel.h @@ -55,7 +55,7 @@ signals: public slots: /// Takes ownership of job void addJob( JobStatusItem* item ); - + private slots: void itemUpdated(); void itemFinished(); @@ -75,6 +75,8 @@ public: JobStatusSortModel( QObject* parent = 0 ); virtual ~JobStatusSortModel(); + void setJobModel( JobStatusModel* model ); + signals: void checkCount(); void customDelegateJobInserted( int row, JobStatusItem* item ); @@ -92,9 +94,9 @@ public slots: protected: virtual bool lessThan( const QModelIndex & left, const QModelIndex & right ) const; - + private: - JobStatusModel m_sourceModel; + JobStatusModel* m_sourceModel; }; #endif // JOBSTATUSMODEL_H