1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtWidgets module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QCOMPLETER_H
41#define QCOMPLETER_H
42
43#include <QtWidgets/qtwidgetsglobal.h>
44#include <QtCore/qobject.h>
45#include <QtCore/qpoint.h>
46#include <QtCore/qstring.h>
47#include <QtCore/qabstractitemmodel.h>
48#include <QtCore/qrect.h>
49
50QT_REQUIRE_CONFIG(completer);
51
52QT_BEGIN_NAMESPACE
53
54class QCompleterPrivate;
55class QAbstractItemView;
56class QAbstractProxyModel;
57class QWidget;
58
59class Q_WIDGETS_EXPORT QCompleter : public QObject
60{
61 Q_OBJECT
62 Q_PROPERTY(QString completionPrefix READ completionPrefix WRITE setCompletionPrefix)
63 Q_PROPERTY(ModelSorting modelSorting READ modelSorting WRITE setModelSorting)
64 Q_PROPERTY(Qt::MatchFlags filterMode READ filterMode WRITE setFilterMode)
65 Q_PROPERTY(CompletionMode completionMode READ completionMode WRITE setCompletionMode)
66 Q_PROPERTY(int completionColumn READ completionColumn WRITE setCompletionColumn)
67 Q_PROPERTY(int completionRole READ completionRole WRITE setCompletionRole)
68 Q_PROPERTY(int maxVisibleItems READ maxVisibleItems WRITE setMaxVisibleItems)
69 Q_PROPERTY(Qt::CaseSensitivity caseSensitivity READ caseSensitivity WRITE setCaseSensitivity)
70 Q_PROPERTY(bool wrapAround READ wrapAround WRITE setWrapAround)
71
72public:
73 enum CompletionMode {
74 PopupCompletion,
75 UnfilteredPopupCompletion,
76 InlineCompletion
77 };
78 Q_ENUM(CompletionMode)
79
80 enum ModelSorting {
81 UnsortedModel = 0,
82 CaseSensitivelySortedModel,
83 CaseInsensitivelySortedModel
84 };
85 Q_ENUM(ModelSorting)
86
87 QCompleter(QObject *parent = nullptr);
88 QCompleter(QAbstractItemModel *model, QObject *parent = nullptr);
89#if QT_CONFIG(stringlistmodel)
90 QCompleter(const QStringList& completions, QObject *parent = nullptr);
91#endif
92 ~QCompleter() override;
93
94 void setWidget(QWidget *widget);
95 QWidget *widget() const;
96
97 void setModel(QAbstractItemModel *c);
98 QAbstractItemModel *model() const;
99
100 void setCompletionMode(CompletionMode mode);
101 CompletionMode completionMode() const;
102
103 void setFilterMode(Qt::MatchFlags filterMode);
104 Qt::MatchFlags filterMode() const;
105
106 QAbstractItemView *popup() const;
107 void setPopup(QAbstractItemView *popup);
108
109 void setCaseSensitivity(Qt::CaseSensitivity caseSensitivity);
110 Qt::CaseSensitivity caseSensitivity() const;
111
112 void setModelSorting(ModelSorting sorting);
113 ModelSorting modelSorting() const;
114
115 void setCompletionColumn(int column);
116 int completionColumn() const;
117
118 void setCompletionRole(int role);
119 int completionRole() const;
120
121 bool wrapAround() const;
122
123 int maxVisibleItems() const;
124 void setMaxVisibleItems(int maxItems);
125
126 int completionCount() const;
127 bool setCurrentRow(int row);
128 int currentRow() const;
129
130 QModelIndex currentIndex() const;
131 QString currentCompletion() const;
132
133 QAbstractItemModel *completionModel() const;
134
135 QString completionPrefix() const;
136
137public Q_SLOTS:
138 void setCompletionPrefix(const QString &prefix);
139 void complete(const QRect& rect = QRect());
140 void setWrapAround(bool wrap);
141
142public:
143 virtual QString pathFromIndex(const QModelIndex &index) const;
144 virtual QStringList splitPath(const QString &path) const;
145
146protected:
147 bool eventFilter(QObject *o, QEvent *e) override;
148 bool event(QEvent *) override;
149
150Q_SIGNALS:
151 void activated(const QString &text);
152 void activated(const QModelIndex &index);
153 void highlighted(const QString &text);
154 void highlighted(const QModelIndex &index);
155
156private:
157 Q_DISABLE_COPY(QCompleter)
158 Q_DECLARE_PRIVATE(QCompleter)
159
160 Q_PRIVATE_SLOT(d_func(), void _q_complete(QModelIndex))
161 Q_PRIVATE_SLOT(d_func(), void _q_completionSelected(const QItemSelection&))
162 Q_PRIVATE_SLOT(d_func(), void _q_autoResizePopup())
163 Q_PRIVATE_SLOT(d_func(), void _q_fileSystemModelDirectoryLoaded(const QString&))
164};
165
166QT_END_NAMESPACE
167
168#endif // QCOMPLETER_H
169

source code of qtbase/src/widgets/util/qcompleter.h