summaryrefslogtreecommitdiffstats
path: root/tools/qqem/codecompletionmodel.h
blob: ad5913a8ab303422fa669dea311014ff5e336cb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#ifndef CODECOMPLETIONMODEL_H
#define CODECOMPLETIONMODEL_H

#include <QAbstractListModel>
#include <QList>
#include <QString>
#include <QVariant>

class EffectManager;

class CodeCompletionModel : public QAbstractListModel
{
    Q_OBJECT
    Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged)
    Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)

public:
    struct ModelData {
        QString name;
        int type = 0;
    };

    enum CodeCompletionModelRoles {
        Name = Qt::UserRole + 1,
        Type
    };
    enum WordTypes {
        TypeArgument,
        TypeTag,
        TypeFunction
    };

    explicit CodeCompletionModel(QObject *effectManager);

    int rowCount(const QModelIndex & = QModelIndex()) const final;
    QVariant data(const QModelIndex &index, int role) const final;
    QHash<int, QByteArray> roleNames() const final;

    void addItem(const QString &text, int type);
    void clearItems();
    CodeCompletionModel::ModelData currentItem();
    int currentIndex() const;
    void setCurrentIndex(int index);

    void nextItem();
    void previousItem();

signals:
    void rowCountChanged();
    void currentIndexChanged();

private:
    friend class CodeHelper;
    QList<ModelData> m_modelList;
    EffectManager *m_effectManager = nullptr;
    int m_currentIndex = 0;
};

#endif // CODECOMPLETIONMODEL_H