PageRenderTime 17ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/src/libtomahawk/playlist/TreeProxyModel.h

http://github.com/tomahawk-player/tomahawk
C Header | 84 lines | 45 code | 19 blank | 20 comment | 0 complexity | d2bbf8e519319e12773e090139720d98 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, GPL-3.0, GPL-2.0
  1. /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2. *
  3. * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4. * Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
  5. *
  6. * Tomahawk is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Tomahawk is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef TREEPROXYMODEL_H
  20. #define TREEPROXYMODEL_H
  21. #include "PlaylistInterface.h"
  22. #include "TreeModel.h"
  23. #include "PlayableProxyModel.h"
  24. #include "DllMacro.h"
  25. namespace Tomahawk
  26. {
  27. class ArtistsRequest;
  28. class TreeProxyModelPlaylistInterface;
  29. }
  30. class DLLEXPORT TreeProxyModel : public PlayableProxyModel
  31. {
  32. Q_OBJECT
  33. public:
  34. explicit TreeProxyModel( QObject* parent = 0 );
  35. virtual ~TreeProxyModel() {}
  36. virtual void setSourcePlayableModel( TreeModel* model );
  37. // workaround overloaded-virtual warning
  38. virtual void setSourcePlayableModel( PlayableModel* ) { Q_ASSERT( false ); }
  39. virtual void setFilter( const QString& pattern );
  40. virtual QString filter() const;
  41. QModelIndex indexFromArtist( const Tomahawk::artist_ptr& artist ) const;
  42. QModelIndex indexFromAlbum( const Tomahawk::album_ptr& album ) const;
  43. QModelIndex indexFromResult( const Tomahawk::result_ptr& result ) const;
  44. QModelIndex indexFromQuery( const Tomahawk::query_ptr& query ) const;
  45. protected:
  46. bool filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const;
  47. bool lessThan( const QModelIndex& left, const QModelIndex& right ) const;
  48. // workaround overloaded-virtual warning: using this would lead to serious weirdness in release mode, sometimes an assert is simply not enough
  49. bool lessThan( int, const Tomahawk::query_ptr&, const Tomahawk::query_ptr& ) const { Q_ASSERT( false ); TomahawkUtils::crash(); return false; }
  50. private slots:
  51. void onRowsInserted( const QModelIndex& parent, int start, int end );
  52. void onFilterArtists( const QList<Tomahawk::artist_ptr>& artists );
  53. void onFilterAlbums( const QList<Tomahawk::album_ptr>& albums );
  54. void onModelReset();
  55. private:
  56. void filterFinished();
  57. QString textForItem( PlayableItem* item ) const;
  58. mutable QMap< QPersistentModelIndex, Tomahawk::query_ptr > m_cache;
  59. QList<Tomahawk::artist_ptr> m_artistsFilter;
  60. QList<Tomahawk::album_ptr> m_albumsFilter;
  61. Tomahawk::ArtistsRequest* m_artistsFilterCmd;
  62. QString m_filter;
  63. QPointer<TreeModel> m_model;
  64. };
  65. #endif // TREEPROXYMODEL_H