From 0812855b6089e605e8e32c2f9387536f16df4363 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 20 Oct 2014 03:51:38 +0200 Subject: [PATCH] Store model pointers in a QPointer for safety. --- src/libtomahawk/playlist/GridView.cpp | 7 +++++++ src/libtomahawk/playlist/GridView.h | 4 ++-- src/libtomahawk/playlist/PlayableProxyModel.h | 2 +- src/libtomahawk/playlist/TrackView.cpp | 7 +++++++ src/libtomahawk/playlist/TrackView.h | 4 ++-- src/libtomahawk/playlist/TreeProxyModel.cpp | 4 ++-- src/libtomahawk/playlist/TreeProxyModel.h | 2 +- 7 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/libtomahawk/playlist/GridView.cpp b/src/libtomahawk/playlist/GridView.cpp index c6da323ae..94d88de70 100644 --- a/src/libtomahawk/playlist/GridView.cpp +++ b/src/libtomahawk/playlist/GridView.cpp @@ -566,3 +566,10 @@ GridView::onScrollTimeout() m_proxyModel->updateDetailedInfo( m_proxyModel->index( i, 0 ) ); } } + + +PlayableModel* +GridView::model() const +{ + return m_model.data(); +} diff --git a/src/libtomahawk/playlist/GridView.h b/src/libtomahawk/playlist/GridView.h index dc9e051c1..cdc116080 100644 --- a/src/libtomahawk/playlist/GridView.h +++ b/src/libtomahawk/playlist/GridView.h @@ -52,7 +52,7 @@ public: void setProxyModel( PlayableProxyModel* model ); - PlayableModel* model() const { return m_model; } + PlayableModel* model() const; PlayableProxyModel* proxyModel() const { return m_proxyModel; } GridItemDelegate* delegate() const { return m_delegate; } @@ -117,7 +117,7 @@ private slots: void verifySize(); private: - PlayableModel* m_model; + QPointer m_model; PlayableProxyModel* m_proxyModel; GridItemDelegate* m_delegate; AnimatedSpinner* m_loadingSpinner; diff --git a/src/libtomahawk/playlist/PlayableProxyModel.h b/src/libtomahawk/playlist/PlayableProxyModel.h index 86a92dceb..44245293f 100644 --- a/src/libtomahawk/playlist/PlayableProxyModel.h +++ b/src/libtomahawk/playlist/PlayableProxyModel.h @@ -137,7 +137,7 @@ private: bool visibilityFilterAcceptsRow( int sourceRow, const QModelIndex& sourceParent, PlayableProxyModelFilterMemo& memo ) const; bool lessThan( int column, const Tomahawk::query_ptr& left, const Tomahawk::query_ptr& right ) const; - PlayableModel* m_model; + QPointer m_model; bool m_showOfflineResults; bool m_hideEmptyParents; diff --git a/src/libtomahawk/playlist/TrackView.cpp b/src/libtomahawk/playlist/TrackView.cpp index 4d3be16b2..3298d420e 100644 --- a/src/libtomahawk/playlist/TrackView.cpp +++ b/src/libtomahawk/playlist/TrackView.cpp @@ -941,3 +941,10 @@ TrackView::selectFirstTrack() currentChanged( idx, QModelIndex() ); } } + + +PlayableModel* +TrackView::model() const +{ + return m_model.data(); +} diff --git a/src/libtomahawk/playlist/TrackView.h b/src/libtomahawk/playlist/TrackView.h index 55069efe6..fd323d55a 100644 --- a/src/libtomahawk/playlist/TrackView.h +++ b/src/libtomahawk/playlist/TrackView.h @@ -53,7 +53,7 @@ public: virtual void setModel( QAbstractItemModel* model ); void setProxyModel( PlayableProxyModel* model ); - virtual PlayableModel* model() const { return m_model; } + virtual PlayableModel* model() const; PlayableProxyModel* proxyModel() const { return m_proxyModel; } PlaylistItemDelegate* delegate() const { return m_delegate; } ViewHeader* header() const { return m_header; } @@ -143,7 +143,7 @@ private: void updateHoverIndex( const QPoint& pos ); QString m_guid; - PlayableModel* m_model; + QPointer m_model; PlayableProxyModel* m_proxyModel; PlaylistItemDelegate* m_delegate; ViewHeader* m_header; diff --git a/src/libtomahawk/playlist/TreeProxyModel.cpp b/src/libtomahawk/playlist/TreeProxyModel.cpp index 6aea92c4d..21ae669af 100644 --- a/src/libtomahawk/playlist/TreeProxyModel.cpp +++ b/src/libtomahawk/playlist/TreeProxyModel.cpp @@ -45,7 +45,7 @@ TreeProxyModel::TreeProxyModel( QObject* parent ) void TreeProxyModel::setSourcePlayableModel( TreeModel* model ) { - if ( sourceModel() ) + if ( m_model ) { disconnect( m_model, SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( onRowsInserted( QModelIndex, int, int ) ) ); disconnect( m_model, SIGNAL( modelReset() ), this, SLOT( onModelReset() ) ); @@ -54,7 +54,7 @@ TreeProxyModel::setSourcePlayableModel( TreeModel* model ) PlayableProxyModel::setSourcePlayableModel( model ); m_model = model; - if ( sourceModel() ) + if ( m_model ) { connect( m_model, SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( onRowsInserted( QModelIndex, int, int ) ) ); connect( m_model, SIGNAL( modelReset() ), SLOT( onModelReset() ) ); diff --git a/src/libtomahawk/playlist/TreeProxyModel.h b/src/libtomahawk/playlist/TreeProxyModel.h index 3f93cfdea..ad50cf3f4 100644 --- a/src/libtomahawk/playlist/TreeProxyModel.h +++ b/src/libtomahawk/playlist/TreeProxyModel.h @@ -78,7 +78,7 @@ private: Tomahawk::ArtistsRequest* m_artistsFilterCmd; QString m_filter; - TreeModel* m_model; + QPointer m_model; }; #endif // TREEPROXYMODEL_H