Sayonara Player
CoverModel.h
1 /* CoverModel.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 ALBUMCOVERMODEL_H
22 #define ALBUMCOVERMODEL_H
23 
24 #include "Gui/Library/ItemModel.h"
25 #include "Utils/Pimpl.h"
26 #include <QtGlobal>
27 
28 class Album;
29 class AlbumList;
30 
31 class QSize;
32 
33 namespace Cover
34 {
35  class Location;
36  class Lookup;
37 }
38 
39 namespace Library
40 {
45  class CoverModel :
46  public ItemModel
47  {
48  Q_OBJECT
49  PIMPL(CoverModel)
50 
51  public:
52  enum Role
53  {
54  AlbumRole=Qt::UserRole,
55  ArtistRole=Qt::UserRole + 1,
56  CoverRole=Qt::UserRole + 2
57  };
58 
59  explicit CoverModel(QObject* parent, AbstractLibrary* library);
60  ~CoverModel() override;
61 
62  public:
63  int rowCount(const QModelIndex& parent=QModelIndex()) const override;
64  int columnCount(const QModelIndex& paren=QModelIndex()) const override;
65  QVariant data(const QModelIndex& index, int role) const override;
66  Qt::ItemFlags flags(const QModelIndex& index) const override;
67 
68  QSize itemSize() const;
69  int zoom() const;
70 
71  protected:
72  // ItemModel
73  const MetaDataList& selectedMetadata() const override;
74 
75  QModelIndexList searchResults(const QString& substr) override;
76 
77  int searchableColumn() const override;
78  QString searchableString(int idx) const override;
79  int mapIndexToId(int idx) const override;
80  Cover::Location cover(const IndexSet& indexes) const override;
81 
82  private:
83  const AlbumList& albums() const;
84  bool insertRows(int row, int count, const QModelIndex& parent=QModelIndex()) override;
85  bool removeRows(int row, int count, const QModelIndex& parent=QModelIndex()) override;
86  bool insertColumns(int column, int count, const QModelIndex& parent=QModelIndex()) override;
87  bool removeColumns(int column, int count, const QModelIndex& parent=QModelIndex()) override;
88  void refreshData();
89 
90  public slots:
91  void setZoom(int zoom, const QSize& view_size);
92  void reload();
93  void clear();
94 
95  private slots:
96  void nextHash();
97  void coverLookupFinished(bool success);
98  void showArtistsChanged();
99  };
100 }
101 
102 #endif // ALBUMCOVERMODEL_H
Library::CoverModel
The CoverModel class.
Definition: CoverModel.h:47
Library::CoverModel::cover
Cover::Location cover(const IndexSet &indexes) const override
return the cover for multiple rows. if rows.size() > 1, an invalid, default constructed cover locatio...
Library::CoverModel::searchableColumn
int searchableColumn() const override
the index of the searchable column. This is the column where the text is searched for a certain searc...
MetaDataList
The MetaDataList class.
Definition: MetaDataList.h:37
Util::Set
A set structure. Inherited from std::set with some useful methods. For integer and String this set is...
Definition: Set.h:37
Library::CoverModel::mapIndexToId
int mapIndexToId(int idx) const override
return the current id for a given row
Album
The Album class.
Definition: Album.h:41
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::CoverModel::searchableString
QString searchableString(int idx) const override
here, the searchable string can even be refined. Maybe we just want to search within a substring indi...
Library::CoverModel::selectedMetadata
const MetaDataList & selectedMetadata() const override
return the tracks which belong to the selections. If an album is selected for example,...
AlbumList
The AlbumList class.
Definition: Album.h:100
Cover::Location
The CoverLocation class.
Definition: CoverLocation.h:39