PageRenderTime 23ms CodeModel.GetById 10ms app.highlight 9ms 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
 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
20#ifndef TREEPROXYMODEL_H
21#define TREEPROXYMODEL_H
22
23#include "PlaylistInterface.h"
24#include "TreeModel.h"
25#include "PlayableProxyModel.h"
26
27#include "DllMacro.h"
28
29namespace Tomahawk
30{
31    class ArtistsRequest;
32    class TreeProxyModelPlaylistInterface;
33}
34
35class DLLEXPORT TreeProxyModel : public PlayableProxyModel
36{
37Q_OBJECT
38
39public:
40    explicit TreeProxyModel( QObject* parent = 0 );
41    virtual ~TreeProxyModel() {}
42
43    virtual void setSourcePlayableModel( TreeModel* model );
44    // workaround overloaded-virtual warning
45    virtual void setSourcePlayableModel( PlayableModel* ) { Q_ASSERT( false ); }
46
47    virtual void setFilter( const QString& pattern );
48    virtual QString filter() const;
49
50    QModelIndex indexFromArtist( const Tomahawk::artist_ptr& artist ) const;
51    QModelIndex indexFromAlbum( const Tomahawk::album_ptr& album ) const;
52    QModelIndex indexFromResult( const Tomahawk::result_ptr& result ) const;
53    QModelIndex indexFromQuery( const Tomahawk::query_ptr& query ) const;
54
55protected:
56    bool filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const;
57
58    bool lessThan( const QModelIndex& left, const QModelIndex& right ) const;
59    // workaround overloaded-virtual warning: using this would lead to serious weirdness in release mode, sometimes an assert is simply not enough
60    bool lessThan( int, const Tomahawk::query_ptr&, const Tomahawk::query_ptr& ) const {  Q_ASSERT( false ); TomahawkUtils::crash(); return false; }
61
62private slots:
63    void onRowsInserted( const QModelIndex& parent, int start, int end );
64
65    void onFilterArtists( const QList<Tomahawk::artist_ptr>& artists );
66    void onFilterAlbums( const QList<Tomahawk::album_ptr>& albums );
67
68    void onModelReset();
69
70private:
71    void filterFinished();
72    QString textForItem( PlayableItem* item ) const;
73
74    mutable QMap< QPersistentModelIndex, Tomahawk::query_ptr > m_cache;
75
76    QList<Tomahawk::artist_ptr> m_artistsFilter;
77    QList<Tomahawk::album_ptr> m_albumsFilter;
78    Tomahawk::ArtistsRequest* m_artistsFilterCmd;
79
80    QString m_filter;
81    QPointer<TreeModel> m_model;
82};
83
84#endif // TREEPROXYMODEL_H