CuteLogger
Fast and simple logging solution for Qt based applications
metadatamodel.h
1 /*
2  * Copyright (c) 2014-2020 Meltytech, LLC
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef METADATAMODEL_H
19 #define METADATAMODEL_H
20 
21 #include <QAbstractListModel>
22 #include <QList>
23 
24 class QmlMetadata;
25 
26 class MetadataModel : public QAbstractListModel
27 {
28  Q_OBJECT
29  Q_ENUMS(MetadataFilter)
30  Q_PROPERTY(MetadataFilter filter READ filter WRITE setFilter NOTIFY filterChanged)
31  Q_PROPERTY(QString search READ search WRITE setSearch NOTIFY searchChanged)
32 
33 public:
34 
35  enum ModelRoles {
36  NameRole = Qt::UserRole + 1,
37  HiddenRole,
38  FavoriteRole,
39  ServiceRole,
40  IsAudioRole,
41  NeedsGpuRole,
42  VisibleRole
43  };
44 
45  enum MetadataFilter {
46  NoFilter,
47  FavoritesFilter,
48  VideoFilter,
49  AudioFilter
50  };
51 
52  enum FilterMaskBits {
53  HiddenMaskBit = 1 << 0,
54  clipOnlyMaskBit = 1 << 1,
55  gpuIncompatibleMaskBit = 1 << 2,
56  gpuAlternativeMaskBit = 1 << 3,
57  needsGPUMaskBit = 1 << 4,
58  };
59 
60  explicit MetadataModel(QObject *parent = 0);
61 
62  // Implement QAbstractListModel
63  Q_INVOKABLE int rowCount(const QModelIndex &parent = QModelIndex()) const;
64  QVariant data(const QModelIndex &index, int role) const;
65  bool setData(const QModelIndex &index, const QVariant &value, int role);
66  QHash<int, QByteArray> roleNames() const;
67  Qt::ItemFlags flags(const QModelIndex &index) const;
68 
69  // Direct access to QmlMetadata
70  void add(QmlMetadata* data);
71  Q_INVOKABLE QmlMetadata* get(int index) const;
72  MetadataFilter filter() const { return m_filter; }
73  void setFilter(MetadataFilter);
74  QString search() const { return m_search; }
75  void setSearch(const QString& search);
76  Q_INVOKABLE bool isVisible(int row) const;
77  void setIsClipProducer(bool isClipProducer);
78 
79 signals:
80  void filterChanged();
81  void searchChanged();
82 
83 private:
84  typedef QList<QmlMetadata*> MetadataList;
85  MetadataList m_list;
86  MetadataFilter m_filter;
87  bool m_isClipProducer;
88  QString m_search;
89  unsigned m_filterMask;
90 
91  unsigned computeFilterMask(const QmlMetadata* meta);
92 };
93 
94 #endif // METADATAMODEL_H