File indexing completed on 2024-05-05 04:48:44

0001 /****************************************************************************************
0002  * Copyright (c) 2009 Téo Mrnjavac <teo@kde.org>                                        *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 #ifndef AMAROK_PLAYLISTMODELSTACK_H
0018 #define AMAROK_PLAYLISTMODELSTACK_H
0019 
0020 #include "proxymodels/AbstractModel.h"
0021 #include "PlaylistModel.h"
0022 #include "proxymodels/SortFilterProxy.h"
0023 #include "proxymodels/SearchProxy.h"
0024 #include "proxymodels/GroupingProxy.h"
0025 
0026 // THE PLAYLIST MODELS ARCHITECTURE
0027 // Amarok's playlist uses Qt's Model-View design pattern, so we have
0028 // * 1 source model which feeds the tracks data: Playlist::Model
0029 // * 3 proxies which modify the rows: SortFilterProxy==>SearchProxy==>GroupingProxy
0030 // * 1 or more views, such as Playlist::PrettyListView.
0031 // At any time a view should ONLY talk to the topmost proxy model, exposed by Playlist::
0032 // ModelStack::instance()->groupingProxy() or The::playlist() for short.
0033 // External classes that talk to the playlist should only talk to The::playlist(),
0034 // exceptionally to Playlist::ModelStack::instance()->bottom() if they really really need
0035 // the source model.
0036 //
0037 // Each playlist model implements the interface defined in Playlist::AbstractModel.
0038 // Each playlist proxy is a subclass od QSortFilterProxyModel through Playlist::ProxyBase,
0039 // and uses the default implementations of AbstractModel methods defined in ProxyBase.
0040 // To add a new proxy the recommended procedure is to subclass ProxyBase (which drags in
0041 // QSortFilterProxyModel, this is no problem because QSortFilterProxyModel is transparent
0042 // and fast by default), reimplement the relevant methods from ProxyBase and insert it in
0043 // the right place in the ModelStack constructor.
0044 //      --Téo 13/8/2009
0045 
0046 namespace Playlist
0047 {
0048 
0049 /**
0050  * Singleton class that handles and wraps around the Playlist models architecture.
0051  * To talk to the playlist, use The::playlist(). Playlist::ModelStack::instance()->bottom()
0052  * should only be used internally or in very specific situations.
0053  * @author Téo Mrnjavac <teo@kde.org>
0054  */
0055 class AMAROK_EXPORT ModelStack : public QObject
0056 {
0057     Q_OBJECT
0058 public:
0059     /**
0060      * Accessor for the singleton pattern.
0061      * @return a pointer to the only instance of Playlist::ModelStack.
0062      */
0063     static ModelStack *instance();
0064 
0065     /**
0066      * Singleton destructor.
0067      */
0068     static void destroy();
0069 
0070     /**
0071      * Use the 'The::playlist()' model unless you have a specific need for a lower model.
0072      */
0073     GroupingProxy           *groupingProxy();
0074     SortFilterProxy         *sortProxy();
0075     SortFilterProxy         *filterProxy();
0076     Playlist::Model         *bottom();
0077 
0078 private:
0079     /**
0080      * Constructor.
0081      */
0082     ModelStack();
0083 
0084     /**
0085      * Destructor.
0086      */
0087     ~ModelStack() override;
0088 
0089     static ModelStack *s_instance;       //!< Instance member.
0090 
0091     GroupingProxy   *m_grouping;
0092     SearchProxy     *m_search;
0093     SortFilterProxy *m_sortfilter;
0094     Model           *m_model;
0095 };
0096 
0097 }   //namespace Playlist
0098 
0099 namespace The
0100 {
0101     AMAROK_EXPORT Playlist::AbstractModel* playlist();
0102 }
0103 
0104 #endif  //AMAROK_PLAYLISTMODELSTACK_H