1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-17 19:37:09 +02:00

Stop crashing when changing shown collection in qml

This commit is contained in:
Dominik Schmidt
2011-09-10 05:12:09 +02:00
parent 6df1b9462f
commit 45cc0652d9
2 changed files with 27 additions and 6 deletions

View File

@@ -78,10 +78,21 @@ void TomahawkTouchWindow::activateItem(const QModelIndex& index)
tLog() << "Activate collectionItem!"; tLog() << "Activate collectionItem!";
Tomahawk::collection_ptr collection = collectionItem->source()->collection(); Tomahawk::collection_ptr collection = collectionItem->source()->collection();
delete m_currentPlaylistTreeModel; TreeModel* model = ViewManager::instance()->treeModelForCollection( collection );
m_currentPlaylistTreeModel = new TreeProxyModel(); TreeProxyModel* proxyModel = m_modelProxyModels.value( model );
m_currentPlaylistTreeModel->setSourceTreeModel( ViewManager::instance()->treeModelForCollection( collection ) ); if( !proxyModel )
m_view->rootContext()->setContextProperty( "currentPlaylistTreeModel", m_currentPlaylistTreeModel ); {
proxyModel = new TreeProxyModel();
//m_currentPlaylistTreeModel->setDynamicSortFilter( true );
proxyModel->setSourceTreeModel( model );
proxyModel->sort(TreeModel::Name, Qt::AscendingOrder );
//m_currentPlaylistTreeModel->setShowModes( false );
//m_currentPlaylistTreeModel->setSortRole( );
}
m_currentPlaylistTreeModel = proxyModel;
emit currentTreeModelChanged();
//m_view->rootContext()->setContextProperty( "currentPlaylistTreeModel", m_currentPlaylistTreeModel );
} }
} }
@@ -92,6 +103,7 @@ TomahawkTouchWindow::loadQml()
{ {
tLog() << Q_FUNC_INFO; tLog() << Q_FUNC_INFO;
qmlRegisterType<AudioEngine>("org.tomahawkplayer.qmlcomponents", 1, 0, "AudioEngine"); qmlRegisterType<AudioEngine>("org.tomahawkplayer.qmlcomponents", 1, 0, "AudioEngine");
qmlRegisterType<TreeProxyModel>("org.tomahawkplayer.qmlcomponents", 1, 0, "TreeProxyModel");
if( !m_view ) if( !m_view )
{ {
@@ -114,8 +126,8 @@ TomahawkTouchWindow::loadQml()
context->setContextProperty( "sourcesModel", s_sourcesModel ); context->setContextProperty( "sourcesModel", s_sourcesModel );
// don't start in an undefined state // don't start in an undefined state
delete m_currentPlaylistTreeModel; m_currentPlaylistTreeModel = 0;
context->setContextProperty( "currentPlaylistTreeModel", m_currentPlaylistTreeModel ); //context->setContextProperty( "currentPlaylistTreeModel", m_currentPlaylistTreeModel );
tLog()<< Q_FUNC_INFO << "set source"; tLog()<< Q_FUNC_INFO << "set source";
m_view->setSource( QUrl::fromLocalFile( QMLGUI "/main.qml" ) ); m_view->setSource( QUrl::fromLocalFile( QMLGUI "/main.qml" ) );

View File

@@ -25,11 +25,13 @@
class TomahawkTouchWindow; class TomahawkTouchWindow;
class QFileSystemWatcher; class QFileSystemWatcher;
class TreeModel;
class TreeProxyModel; class TreeProxyModel;
class TomahawkTouchWindow : public TomahawkWindow class TomahawkTouchWindow : public TomahawkWindow
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY( TreeProxyModel* currentTreeModel READ currentTreeModel NOTIFY currentTreeModelChanged )
public: public:
TomahawkTouchWindow(); TomahawkTouchWindow();
@@ -39,14 +41,21 @@ public:
Q_INVOKABLE void play( const QModelIndex& index ); Q_INVOKABLE void play( const QModelIndex& index );
Q_INVOKABLE void activateItem( const QModelIndex& index ); Q_INVOKABLE void activateItem( const QModelIndex& index );
signals:
void currentTreeModelChanged();
private slots: private slots:
void loadQml(); void loadQml();
private: private:
TreeProxyModel* currentTreeModel() { return m_currentPlaylistTreeModel; }
QDeclarativeView* m_view; QDeclarativeView* m_view;
QFileSystemWatcher* m_watcher; QFileSystemWatcher* m_watcher;
TreeProxyModel* m_currentPlaylistTreeModel; TreeProxyModel* m_currentPlaylistTreeModel;
QHash< TreeModel*, TreeProxyModel* > m_modelProxyModels;
}; };
#endif // TOMAHAWKTOUCHWINDOW_H #endif // TOMAHAWKTOUCHWINDOW_H