diff --git a/src/active/tomahawktouchwindow.cpp b/src/active/tomahawktouchwindow.cpp index ad96b3f7a..e6b45b51b 100644 --- a/src/active/tomahawktouchwindow.cpp +++ b/src/active/tomahawktouchwindow.cpp @@ -78,10 +78,21 @@ void TomahawkTouchWindow::activateItem(const QModelIndex& index) tLog() << "Activate collectionItem!"; Tomahawk::collection_ptr collection = collectionItem->source()->collection(); - delete m_currentPlaylistTreeModel; - m_currentPlaylistTreeModel = new TreeProxyModel(); - m_currentPlaylistTreeModel->setSourceTreeModel( ViewManager::instance()->treeModelForCollection( collection ) ); - m_view->rootContext()->setContextProperty( "currentPlaylistTreeModel", m_currentPlaylistTreeModel ); + TreeModel* model = ViewManager::instance()->treeModelForCollection( collection ); + TreeProxyModel* proxyModel = m_modelProxyModels.value( model ); + if( !proxyModel ) + { + 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; qmlRegisterType("org.tomahawkplayer.qmlcomponents", 1, 0, "AudioEngine"); + qmlRegisterType("org.tomahawkplayer.qmlcomponents", 1, 0, "TreeProxyModel"); if( !m_view ) { @@ -114,8 +126,8 @@ TomahawkTouchWindow::loadQml() context->setContextProperty( "sourcesModel", s_sourcesModel ); // don't start in an undefined state - delete m_currentPlaylistTreeModel; - context->setContextProperty( "currentPlaylistTreeModel", m_currentPlaylistTreeModel ); + m_currentPlaylistTreeModel = 0; + //context->setContextProperty( "currentPlaylistTreeModel", m_currentPlaylistTreeModel ); tLog()<< Q_FUNC_INFO << "set source"; m_view->setSource( QUrl::fromLocalFile( QMLGUI "/main.qml" ) ); diff --git a/src/active/tomahawktouchwindow.h b/src/active/tomahawktouchwindow.h index d191521f6..d7b32f769 100644 --- a/src/active/tomahawktouchwindow.h +++ b/src/active/tomahawktouchwindow.h @@ -25,11 +25,13 @@ class TomahawkTouchWindow; class QFileSystemWatcher; +class TreeModel; class TreeProxyModel; class TomahawkTouchWindow : public TomahawkWindow { Q_OBJECT + Q_PROPERTY( TreeProxyModel* currentTreeModel READ currentTreeModel NOTIFY currentTreeModelChanged ) public: TomahawkTouchWindow(); @@ -39,14 +41,21 @@ public: Q_INVOKABLE void play( const QModelIndex& index ); Q_INVOKABLE void activateItem( const QModelIndex& index ); +signals: + void currentTreeModelChanged(); + private slots: void loadQml(); private: + TreeProxyModel* currentTreeModel() { return m_currentPlaylistTreeModel; } + + QDeclarativeView* m_view; QFileSystemWatcher* m_watcher; TreeProxyModel* m_currentPlaylistTreeModel; + QHash< TreeModel*, TreeProxyModel* > m_modelProxyModels; }; #endif // TOMAHAWKTOUCHWINDOW_H