Sayonara Player
ItemModel.h
1 /* ItemModel.h */
2 
3 /* Copyright (C) 2011-2020 Michael Lugmair (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  ~ItemModel() override;
55 
56  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
57  bool setHeaderData(int section, Qt::Orientation orientation, const QVariant& value,
58  int role = Qt::EditRole) override;
59 
60  int columnCount(const QModelIndex& parent = QModelIndex()) const override;
61 
62  QModelIndexList searchResults(const QString& substr) override;
63 
68  virtual int searchableColumn() const = 0;
69 
76  virtual QString searchableString(int row) const = 0;
77 
83  virtual Id mapIndexToId(int row) const = 0;
84 
91  virtual Cover::Location cover(const IndexSet& rows) const = 0;
92 
98  virtual const MetaDataList& selectedMetadata() const = 0;
99  Gui::CustomMimeData* customMimedata() const;
100 
101  void refreshData(int* rowCountBefore = nullptr, int* rowCountAfter = nullptr); //returns the size difference
102 
103  protected:
104  AbstractLibrary* library();
105  const AbstractLibrary* library() const;
106 
107  private:
108  bool removeRows(int position, int rows, const QModelIndex& index = QModelIndex()) override;
109  bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
110  };
111 }
112 
113 #endif /* LIBRARYITEMMODEL_H_ */
Library::ItemModel::searchableColumn
virtual int searchableColumn() const =0
the index of the searchable column. This is the column where the text is searched for a certain searc...
Library::ItemModel::selectedMetadata
virtual const MetaDataList & selectedMetadata() const =0
return the tracks which belong to the selections. If an album is selected for example,...
Gui::CustomMimeData
Mimedata class for drag and dropping metadata.
Definition: CustomMimeData.h:37
MetaDataList
The MetaDataList class.
Definition: MetaDataList.h:37
Library::ItemModel::cover
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...
Util::Set
A set structure. Inherited from std::set with some useful methods. For integer and String this set is...
Definition: Set.h:37
SearchableModel
Definition: SearchableModel.h:58
AbstractLibrary
Definition: AbstractLibrary.h:43
Library::ItemModel
The ItemModel is intended to abstract the various views. It supports searching, selections and a libr...
Definition: ItemModel.h:48
Library
An interface class needed when implementing a library plugin.
Definition: LocalLibraryWatcher.h:31
Library::ItemModel::mapIndexToId
virtual Id mapIndexToId(int row) const =0
return the current id for a given row
Cover::Location
The CoverLocation class.
Definition: CoverLocation.h:39
Library::ItemModel::searchableString
virtual QString searchableString(int row) const =0
here, the searchable string can even be refined. Maybe we just want to search within a substring indi...