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