Debian Codegraph @

src/ui/NhekoMenuVisibilityFilter.h

raw symbols SCIP
1 // SPDX-FileCopyrightText: Nheko Contributors
2 //
3 // SPDX-License-Identifier: GPL-3.0-or-later
4
5 #pragma once
6
7 #include <QQmlComponent>
8 #include <QQmlEngine>
9 #include <QQmlListProperty>
10 #include <QQmlProperty>
11 #include <QQmlPropertyValueSource>
12 #include <QVariantList>
13
14 class NhekoMenuVisibilityFilter
15 : public QObject
16 , public QQmlPropertyValueSource
17 {
18 Q_OBJECT
19 Q_INTERFACES(QQmlPropertyValueSource)
20 Q_CLASSINFO("DefaultProperty", "items")
21 Q_PROPERTY(QQmlListProperty<QQmlComponent> items READ items CONSTANT FINAL)
22 Q_PROPERTY(QQmlComponent *delegate MEMBER delegate FINAL)
23 Q_PROPERTY(QVariantList model MEMBER model FINAL)
24 QML_ELEMENT
25
26 public:
27 NhekoMenuVisibilityFilter(QObject *parent = nullptr)
28 : QObject(parent)
29 {
30 }
31
32 QQmlListProperty<QQmlComponent> items();
33
34 void setTarget(const QQmlProperty &prop) override;
35
36 private:
37 QQmlProperty targetProperty;
38 QList<QQmlComponent *> items_;
39 QQmlComponent *delegate = nullptr;
40 QVariantList model;
41
42 static void appendItem(QQmlListProperty<QQmlComponent> *, QQmlComponent *);
43 static qsizetype itemCount(QQmlListProperty<QQmlComponent> *);
44 static QQmlComponent *getItem(QQmlListProperty<QQmlComponent> *, qsizetype index);
45 static void clearItems(QQmlListProperty<QQmlComponent> *);
46 static void replaceItem(QQmlListProperty<QQmlComponent> *, qsizetype index, QQmlComponent *);
47 static void removeLast(QQmlListProperty<QQmlComponent> *);
48
49 public slots:
50 // call this before showing the menu. We don't want to update elsewhere to prevent jumping menus
51 // and useless work
52 void updateTarget();
53 };