Skip to content
Browse files

Stop crashing when changing shown collection in qml

  • Loading branch information...
1 parent 6df1b94 commit 45cc0652d9a20aaa6a26d328a646c05b81c7b814 @dschmidt dschmidt committed Sep 10, 2011
Showing with 27 additions and 6 deletions.
  1. +18 −6 src/active/tomahawktouchwindow.cpp
  2. +9 −0 src/active/tomahawktouchwindow.h
View
24 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<AudioEngine>("org.tomahawkplayer.qmlcomponents", 1, 0, "AudioEngine");
+ qmlRegisterType<TreeProxyModel>("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" ) );
View
9 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 @@ class TomahawkTouchWindow : public TomahawkWindow
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

0 comments on commit 45cc065

Please sign in to comment.
Something went wrong with that request. Please try again.