Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qcompleter.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QCOMPLETER_H
6#define QCOMPLETER_H
7
8#include <QtWidgets/qtwidgetsglobal.h>
9#include <QtCore/qobject.h>
10#include <QtCore/qpoint.h>
11#include <QtCore/qstring.h>
12#include <QtCore/qabstractitemmodel.h>
13#include <QtCore/qrect.h>
14
16
17QT_BEGIN_NAMESPACE
18
19class QCompleterPrivate;
20class QAbstractItemView;
21class QAbstractProxyModel;
22class QWidget;
23
24class Q_WIDGETS_EXPORT QCompleter : public QObject
25{
26 Q_OBJECT
27 Q_PROPERTY(QString completionPrefix READ completionPrefix WRITE setCompletionPrefix)
28 Q_PROPERTY(ModelSorting modelSorting READ modelSorting WRITE setModelSorting)
29 Q_PROPERTY(Qt::MatchFlags filterMode READ filterMode WRITE setFilterMode)
30 Q_PROPERTY(CompletionMode completionMode READ completionMode WRITE setCompletionMode)
31 Q_PROPERTY(int completionColumn READ completionColumn WRITE setCompletionColumn)
32 Q_PROPERTY(int completionRole READ completionRole WRITE setCompletionRole)
33 Q_PROPERTY(int maxVisibleItems READ maxVisibleItems WRITE setMaxVisibleItems)
34 Q_PROPERTY(Qt::CaseSensitivity caseSensitivity READ caseSensitivity WRITE setCaseSensitivity)
35 Q_PROPERTY(bool wrapAround READ wrapAround WRITE setWrapAround)
36
37public:
38 enum CompletionMode {
39 PopupCompletion,
40 UnfilteredPopupCompletion,
41 InlineCompletion
42 };
43 Q_ENUM(CompletionMode)
44
45 enum ModelSorting {
46 UnsortedModel = 0,
47 CaseSensitivelySortedModel,
48 CaseInsensitivelySortedModel
49 };
50 Q_ENUM(ModelSorting)
51
52 QCompleter(QObject *parent = nullptr);
53 QCompleter(QAbstractItemModel *model, QObject *parent = nullptr);
54#if QT_CONFIG(stringlistmodel)
55 QCompleter(const QStringList& completions, QObject *parent = nullptr);
56#endif
57 ~QCompleter() override;
58
59 void setWidget(QWidget *widget);
60 QWidget *widget() const;
61
62 void setModel(QAbstractItemModel *c);
63 QAbstractItemModel *model() const;
64
65 void setCompletionMode(CompletionMode mode);
66 CompletionMode completionMode() const;
67
68 void setFilterMode(Qt::MatchFlags filterMode);
69 Qt::MatchFlags filterMode() const;
70
71 QAbstractItemView *popup() const;
72 void setPopup(QAbstractItemView *popup);
73
74 void setCaseSensitivity(Qt::CaseSensitivity caseSensitivity);
75 Qt::CaseSensitivity caseSensitivity() const;
76
77 void setModelSorting(ModelSorting sorting);
78 ModelSorting modelSorting() const;
79
80 void setCompletionColumn(int column);
81 int completionColumn() const;
82
83 void setCompletionRole(int role);
84 int completionRole() const;
85
86 bool wrapAround() const;
87
88 int maxVisibleItems() const;
89 void setMaxVisibleItems(int maxItems);
90
91 int completionCount() const;
92 bool setCurrentRow(int row);
93 int currentRow() const;
94
95 QModelIndex currentIndex() const;
96 QString currentCompletion() const;
97
98 QAbstractItemModel *completionModel() const;
99
100 QString completionPrefix() const;
101
102public Q_SLOTS:
103 void setCompletionPrefix(const QString &prefix);
104 void complete(const QRect& rect = QRect());
105 void setWrapAround(bool wrap);
106
107public:
108 virtual QString pathFromIndex(const QModelIndex &index) const;
109 virtual QStringList splitPath(const QString &path) const;
110
111protected:
112 bool eventFilter(QObject *o, QEvent *e) override;
113 bool event(QEvent *) override;
114
115Q_SIGNALS:
116 void activated(const QString &text);
117 void activated(const QModelIndex &index);
118 void highlighted(const QString &text);
119 void highlighted(const QModelIndex &index);
120
121private:
122 Q_DISABLE_COPY(QCompleter)
123 Q_DECLARE_PRIVATE(QCompleter)
124
125 Q_PRIVATE_SLOT(d_func(), void _q_complete(QModelIndex))
126 Q_PRIVATE_SLOT(d_func(), void _q_completionSelected(const QItemSelection&))
127 Q_PRIVATE_SLOT(d_func(), void _q_autoResizePopup())
128 Q_PRIVATE_SLOT(d_func(), void _q_fileSystemModelDirectoryLoaded(const QString&))
129};
130
131QT_END_NAMESPACE
132
133#endif // QCOMPLETER_H
QCompleterItemDelegate(QAbstractItemView *view)
void paint(QPainter *p, const QStyleOptionViewItem &opt, const QModelIndex &idx) const override
This pure abstract function must be reimplemented if you want to provide custom rendering.
Qt::CaseSensitivity cs
void setCurrentIndex(QModelIndex, bool=true)
static const QCompleterPrivate * get(const QCompleter *o)
void _q_fileSystemModelDirectoryLoaded(const QString &path)
void _q_completionSelected(const QItemSelection &)
Qt::MatchFlags filterMode
QPointer< QWidget > widget
void init(QAbstractItemModel *model=nullptr)
QAbstractItemView * popup
void _q_complete(QModelIndex, bool=false)
QCompletionModel * proxy
static QCompleterPrivate * get(QCompleter *o)
void showPopup(const QRect &)
The QCompleter class provides completions based on an item model.
Definition qcompleter.h:25
QMatchData historyMatch
QMatchData curMatch
void saveInCache(QString, const QModelIndex &, const QMatchData &)
virtual QMatchData filter(const QString &, const QModelIndex &, int)=0
QModelIndex curParent
void filter(const QStringList &parts)
virtual void filterOnDemand(int)
QMap< QString, QMatchData > CacheItem
int matchCount() const
bool matchHint(const QString &part, const QModelIndex &parent, QMatchData *m) const
QCompletionEngine(QCompleterPrivate *c)
bool lookupCache(const QString &part, const QModelIndex &parent, QMatchData *m) const
virtual ~QCompletionEngine()
QStringList curParts
QMap< QModelIndex, CacheItem > Cache
QCompleterPrivate * c
QMatchData filterHistory()
QModelIndex index(int row, int column, const QModelIndex &=QModelIndex()) const override
Returns the index of the item in the model specified by the given row, column and parent index.
int currentRow() const
int rowCount(const QModelIndex &index=QModelIndex()) const override
Returns the number of rows under the given parent.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
\reimp
void setFiltered(bool)
int completionCount() const
int columnCount(const QModelIndex &index=QModelIndex()) const override
Returns the number of columns for the children of the given parent.
QCompleterPrivate * c
QScopedPointer< QCompletionEngine > engine
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override
Reimplement this function to return the model index in the proxy model that corresponds to the source...
bool hasChildren(const QModelIndex &parent=QModelIndex()) const override
\reimp
QModelIndex parent(const QModelIndex &=QModelIndex()) const override
QModelIndex currentIndex(bool) const
void filter(const QStringList &parts)
QModelIndex mapToSource(const QModelIndex &proxyIndex) const override
Reimplement this function to return the model index in the source model that corresponds to the proxy...
void setSourceModel(QAbstractItemModel *sourceModel) override
Sets the given sourceModel to be processed by the proxy model.
bool setCurrentRow(int row)
int cost() const
bool isValid() const
int from() const
bool isEmpty() const
int indexOf(int x) const
int first() const
void append(int x)
int count() const
int last() const
int operator[](int index) const
QIndexMapper(const QList< int > &vec)
QIndexMapper(int f, int t)
int to() const
friend class QWidget
Definition qpainter.h:431
QSortedModelEngine(QCompleterPrivate *c)
QMatchData filter(const QString &, const QModelIndex &, int) override
Qt::SortOrder sortOrder(const QModelIndex &) const
QIndexMapper indexHint(QString, const QModelIndex &, Qt::SortOrder)
QUnsortedModelEngine(QCompleterPrivate *c)
void filterOnDemand(int) override
QMatchData filter(const QString &, const QModelIndex &, int) override
QT_REQUIRE_CONFIG(animation)
QCompleter * completer
[0]
QMatchData(const QIndexMapper &indices, int em, bool p)
int exactMatchIndex
bool isValid() const
QIndexMapper indices