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
79 enum ModelSorting {
80 UnsortedModel = 0,
81 CaseSensitivelySortedModel,
82 CaseInsensitivelySortedModel
83 };
84
85 QCompleter(QObject *parent = nullptr);
86 QCompleter(QAbstractItemModel *model, QObject *parent = nullptr);
87#if QT_CONFIG(stringlistmodel)
88 QCompleter(const QStringList& completions, QObject *parent = nullptr);
89#endif
90 ~QCompleter() override;
91
92 void setWidget(QWidget *widget);
93 QWidget *widget() const;
94
95 void setModel(QAbstractItemModel *c);
96 QAbstractItemModel *model() const;
97
98 void setCompletionMode(CompletionMode mode);
99 CompletionMode completionMode() const;
100
101 void setFilterMode(Qt::MatchFlags filterMode);
102 Qt::MatchFlags filterMode() const;
103
104 QAbstractItemView *popup() const;
105 void setPopup(QAbstractItemView *popup);
106
107 void setCaseSensitivity(Qt::CaseSensitivity caseSensitivity);
108 Qt::CaseSensitivity caseSensitivity() const;
109
110 void setModelSorting(ModelSorting sorting);
111 ModelSorting modelSorting() const;
112
113 void setCompletionColumn(int column);
114 int completionColumn() const;
115
116 void setCompletionRole(int role);
117 int completionRole() const;
118
119 bool wrapAround() const;
120
121 int maxVisibleItems() const;
122 void setMaxVisibleItems(int maxItems);
123
124 int completionCount() const;
125 bool setCurrentRow(int row);
126 int currentRow() const;
127
128 QModelIndex currentIndex() const;
129 QString currentCompletion() const;
130
131 QAbstractItemModel *completionModel() const;
132
133 QString completionPrefix() const;
134
135public Q_SLOTS:
136 void setCompletionPrefix(const QString &prefix);
137 void complete(const QRect& rect = QRect());
138 void setWrapAround(bool wrap);
139
140public:
141 virtual QString pathFromIndex(const QModelIndex &index) const;
142 virtual QStringList splitPath(const QString &path) const;
143
144protected:
145 bool eventFilter(QObject *o, QEvent *e) override;
146 bool event(QEvent *) override;
147
148Q_SIGNALS:
149 void activated(const QString &text);
150 void activated(const QModelIndex &index);
151 void highlighted(const QString &text);
152 void highlighted(const QModelIndex &index);
153
154private:
155 Q_DISABLE_COPY(QCompleter)
156 Q_DECLARE_PRIVATE(QCompleter)
157
158 Q_PRIVATE_SLOT(d_func(), void _q_complete(QModelIndex))
159 Q_PRIVATE_SLOT(d_func(), void _q_completionSelected(const QItemSelection&))
160 Q_PRIVATE_SLOT(d_func(), void _q_autoResizePopup())
161 Q_PRIVATE_SLOT(d_func(), void _q_fileSystemModelDirectoryLoaded(const QString&))
162};
163
164QT_END_NAMESPACE
165
166#endif // QCOMPLETER_H
167