1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QVIRTUALKEYBOARDSELECTIONLISTMODEL_H
5#define QVIRTUALKEYBOARDSELECTIONLISTMODEL_H
6
7#include <QtCore/QAbstractListModel>
8#include <QtQml/qqml.h>
9#include <QtVirtualKeyboard/qvirtualkeyboard_global.h>
10
11QT_BEGIN_NAMESPACE
12
13class QVirtualKeyboardAbstractInputMethod;
14class QVirtualKeyboardInputEngine;
15class QVirtualKeyboardSelectionListModelPrivate;
16
17class Q_VIRTUALKEYBOARD_EXPORT QVirtualKeyboardSelectionListModel : public QAbstractListModel
18{
19 Q_OBJECT
20 Q_DECLARE_PRIVATE(QVirtualKeyboardSelectionListModel)
21 Q_PROPERTY(int count READ count NOTIFY countChanged)
22 QML_NAMED_ELEMENT(SelectionListModel)
23 QML_UNCREATABLE("SelectionListModel is only available via InputEngine.wordCandidateListModel")
24 QML_ADDED_IN_VERSION(1, 0)
25 QML_EXTRA_VERSION(2, 0)
26
27 explicit QVirtualKeyboardSelectionListModel(QObject *parent = nullptr);
28
29public:
30 enum class Type
31 {
32 WordCandidateList = 0
33 };
34 Q_ENUM(Type)
35
36 enum class Role
37 {
38 Display = Qt::DisplayRole,
39 DisplayRole = Display,
40 WordCompletionLength = Qt::UserRole + 1,
41 WordCompletionLengthRole = WordCompletionLength,
42 Dictionary,
43 CanRemoveSuggestion
44 };
45 Q_ENUM(Role)
46
47 enum class DictionaryType
48 {
49 Default = 0,
50 User
51 };
52 Q_ENUM(DictionaryType)
53
54 ~QVirtualKeyboardSelectionListModel();
55 void setDataSource(QVirtualKeyboardAbstractInputMethod *dataSource, Type type);
56 QVirtualKeyboardAbstractInputMethod *dataSource() const;
57 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
58 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
59 QHash<int,QByteArray> roleNames() const override;
60
61 int count() const;
62
63 Q_INVOKABLE void selectItem(int index);
64 Q_INVOKABLE void removeItem(int index);
65 Q_INVOKABLE QVariant dataAt(int index, Role role = Role::Display) const;
66
67Q_SIGNALS:
68 void countChanged();
69 void activeItemChanged(int index);
70 void itemSelected(int index);
71
72protected Q_SLOTS:
73 void selectionListChanged(Type type);
74 void selectionListActiveItemChanged(Type type, int index);
75 void dataSourceDestroyed();
76
77private:
78 friend class QVirtualKeyboardInputEngine;
79};
80
81QT_END_NAMESPACE
82
83Q_DECLARE_METATYPE(QVirtualKeyboardSelectionListModel::Type)
84Q_DECLARE_METATYPE(QVirtualKeyboardSelectionListModel::Role)
85Q_DECLARE_METATYPE(QVirtualKeyboardSelectionListModel::DictionaryType)
86
87#endif // QVIRTUALKEYBOARDSELECTIONLISTMODEL_H
88

source code of qtvirtualkeyboard/src/virtualkeyboard/qvirtualkeyboardselectionlistmodel.h