Sayonara Player
ItemModel.h
1 /* ItemModel.h */
2 
3 /* Copyright (C) 2011-2019 Lucio Carreras
4  *
5  * This file is part of sayonara player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef LIBRARYITEMMODEL_H_
22 #define LIBRARYITEMMODEL_H_
23 
24 #include "Gui/Utils/SearchableWidget/SearchableModel.h"
25 #include "Utils/Pimpl.h"
26 
27 namespace Cover
28 {
29  class Location;
30 }
31 
32 namespace Gui
33 {
34  class CustomMimeData;
35 }
36 
37 class AbstractLibrary;
38 
39 namespace Library
40 {
46  class ItemModel :
48  {
49  Q_OBJECT
50  PIMPL(ItemModel)
51 
52  public:
53  ItemModel(QObject* parent, AbstractLibrary* library);
54  virtual ~ItemModel() override;
55 
56  QVariant headerData ( int section, Qt::Orientation orientation, int role=Qt::DisplayRole ) const override;
57  bool set_header_data(const QStringList& names);
58 
59  virtual int columnCount(const QModelIndex& parent=QModelIndex()) const override;
60 
61  QModelIndexList search_results(const QString& substr) override;
62 
63  virtual bool is_selected(int id) const final;
64 
68  virtual const Util::Set<Id>& selections() const=0;
69  virtual IndexSet selected_indexes() const;
70 
75  virtual int searchable_column() const=0;
76 
83  virtual QString searchable_string(int row) const=0;
84 
90  virtual Id id_by_index(int row) const=0;
91 
98  virtual Cover::Location cover(const IndexSet& rows) const=0;
99 
105  virtual const MetaDataList& mimedata_tracks() const=0;
106  Gui::CustomMimeData* custom_mimedata() const;
107 
108  void refresh_data(int* n_rows_before=nullptr, int* n_rows_after=nullptr); //returns the size difference
109 
110  protected:
111  AbstractLibrary* library();
112  const AbstractLibrary* library() const;
113 
114  private:
115  bool removeRows(int position, int rows, const QModelIndex& index=QModelIndex()) override;
116  bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex()) override;
117  };
118 }
119 
120 #endif /* LIBRARYITEMMODEL_H_ */
Mimedata class for drag and dropping metadata.
Definition: CustomMimeData.h:35
virtual const Util::Set< Id > & selections() const =0
returns a set of the selected ids
virtual int searchable_column() const =0
the index of the searchable column. This is the column where the text is searched for a certain searc...
Definition: SearchableModel.h:56
Definition: AbstractLibrary.h:41
The MetaDataList class.
Definition: MetaDataList.h:37
The CoverLocation class.
Definition: CoverLocation.h:42
virtual Id id_by_index(int row) const =0
return the current id for a given row
A set structure. Inherited from std::set with some useful methods. For integer and String this set is...
Definition: Set.h:35
virtual QString searchable_string(int row) const =0
here, the searchable string can even be refined. Maybe we just want to search within a substring indi...
virtual const MetaDataList & mimedata_tracks() const =0
return the tracks which belong to the selections. If an album is selected for example,...
An interface class needed when implementing a library plugin.
Definition: LocalLibraryWatcher.h:32
virtual Cover::Location cover(const IndexSet &rows) const =0
return the cover for multiple rows. if rows.size() > 1, an invalid, default constructed cover locatio...
The ItemModel is intended to abstract the various views. It supports searching, selections and a libr...
Definition: ItemModel.h:46