1 | // Copyright (C) 2022 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef CODECOMPLETIONMODEL_H |
5 | #define CODECOMPLETIONMODEL_H |
6 | |
7 | #include <QAbstractListModel> |
8 | #include <QList> |
9 | #include <QString> |
10 | #include <QVariant> |
11 | |
12 | class EffectManager; |
13 | |
14 | class CodeCompletionModel : public QAbstractListModel |
15 | { |
16 | Q_OBJECT |
17 | Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged) |
18 | Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) |
19 | |
20 | public: |
21 | struct ModelData { |
22 | QString name; |
23 | int type = 0; |
24 | }; |
25 | |
26 | enum CodeCompletionModelRoles { |
27 | Name = Qt::UserRole + 1, |
28 | Type |
29 | }; |
30 | enum WordTypes { |
31 | TypeArgument, |
32 | TypeTag, |
33 | TypeFunction |
34 | }; |
35 | |
36 | explicit CodeCompletionModel(QObject *effectManager); |
37 | |
38 | int rowCount(const QModelIndex & = QModelIndex()) const final; |
39 | QVariant data(const QModelIndex &index, int role) const final; |
40 | QHash<int, QByteArray> roleNames() const final; |
41 | |
42 | void addItem(const QString &text, int type); |
43 | void clearItems(); |
44 | CodeCompletionModel::ModelData currentItem(); |
45 | int currentIndex() const; |
46 | void setCurrentIndex(int index); |
47 | |
48 | void nextItem(); |
49 | void previousItem(); |
50 | |
51 | signals: |
52 | void rowCountChanged(); |
53 | void currentIndexChanged(); |
54 | |
55 | private: |
56 | friend class CodeHelper; |
57 | QList<ModelData> m_modelList; |
58 | EffectManager *m_effectManager = nullptr; |
59 | int m_currentIndex = 0; |
60 | }; |
61 | |
62 | #endif // CODECOMPLETIONMODEL_H |
63 | |