CuteLogger
Fast and simple logging solution for Qt based applications
metadatamodel.h
1 /*
2  * Copyright (c) 2014-2024 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 <QSortFilterProxyModel>
22 #include <QList>
23 
24 class QmlMetadata;
25 
26 class MetadataModel : public QSortFilterProxyModel
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  PluginTypeRole,
43  };
44 
45  enum MetadataFilter {
46  NoFilter,
47  FavoritesFilter,
48  VideoFilter,
49  AudioFilter,
50  LinkFilter,
51  FilterSetFilter,
52  GPUFilter,
53  };
54 
55  enum FilterMaskBits {
56  HiddenMaskBit = 1 << 0,
57  clipOnlyMaskBit = 1 << 1,
58  gpuIncompatibleMaskBit = 1 << 2,
59  gpuAlternativeMaskBit = 1 << 3,
60  needsGPUMaskBit = 1 << 4,
61  linkMaskBit = 1 << 5,
62  trackOnlyMaskBit = 1 << 6,
63  outputOnlyMaskBit = 1 << 7,
64  reverseMaskBit = 1 << 8,
65  };
66 
67  explicit MetadataModel(QObject *parent = 0);
68 
69  Q_INVOKABLE int rowCount(const QModelIndex &parent = QModelIndex()) const;
70  int sourceRowCount(const QModelIndex &parent = QModelIndex()) const;
71  void add(QmlMetadata *data);
72  Q_INVOKABLE QmlMetadata *get(int row) const;
73  QmlMetadata *getFromSource(int index) const;
74  Q_INVOKABLE void saveFilterSet(const QString &name);
75  Q_INVOKABLE void deleteFilterSet(const QString &name);
76  MetadataFilter filter() const
77  {
78  return m_filter;
79  }
80  void setFilter(MetadataFilter);
81  void updateFilterMask(bool isClipProducer, bool isChainProducer, bool isTrackProducer,
82  bool isOutputProducer, bool isReverseSupported);
83  QString search() const
84  {
85  return m_search;
86  }
87  void setSearch(const QString &search);
88 
89 signals:
90  void filterChanged();
91  void searchChanged();
92 
93 protected:
94  bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
95 
96 private:
97  MetadataFilter m_filter;
98  unsigned m_filterMask;
99  QString m_search;
100  bool m_isClipProducer;
101  bool m_isChainProducer;
102  bool m_isTrackProducer;
103  bool m_isOutputProducer;
104  bool m_isReverseSupported;
105 };
106 
107 class InternalMetadataModel : public QAbstractListModel
108 {
109 public:
110  explicit InternalMetadataModel(QObject *parent = 0) : QAbstractListModel(parent) {};
111 
112  // Implement QAbstractListModel
113  int rowCount(const QModelIndex &parent = QModelIndex()) const;
114  QVariant data(const QModelIndex &index, int role) const;
115  bool setData(const QModelIndex &index, const QVariant &value, int role);
116  QHash<int, QByteArray> roleNames() const;
117  Qt::ItemFlags flags(const QModelIndex &index) const;
118 
119  // Direct access to QmlMetadata
120  void add(QmlMetadata *data);
121  QmlMetadata *get(int index) const;
122  QList<QmlMetadata *> &list()
123  {
124  return m_list;
125  }
126  void remove(int index);
127 
128 private:
129  typedef QList<QmlMetadata *> MetadataList;
130  MetadataList m_list;
131 
132  unsigned computeFilterMask(const QmlMetadata *meta);
133 };
134 
135 #endif // METADATAMODEL_H