Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qcompleter_p.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
4#ifndef QCOMPLETER_P_H
5#define QCOMPLETER_P_H
6
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtWidgets/private/qtwidgetsglobal_p.h>
20#include "private/qobject_p.h"
21
22#include "QtWidgets/qabstractitemview.h"
23#include "QtCore/qabstractproxymodel.h"
24#include "QtCore/qmap.h"
25#include "qcompleter.h"
26#include "qstyleditemdelegate.h"
27#include "QtGui/qpainter.h"
28
29#include "private/qabstractproxymodel_p.h"
30#include <QtCore/qpointer.h>
31
33
35
37
39{
40 Q_DECLARE_PUBLIC(QCompleter)
41
42public:
45 void init(QAbstractItemModel *model = nullptr);
46
47 QPointer<QWidget> widget;
51 Qt::MatchFlags filterMode;
52
55 int role;
56 int column;
59 bool wrap;
60
64
65 void showPopup(const QRect&);
66 void _q_complete(QModelIndex, bool = false);
68 void _q_autoResizePopup();
70 void setCurrentIndex(QModelIndex, bool = true);
71
72 static QCompleterPrivate *get(QCompleter *o) { return o->d_func(); }
73 static const QCompleterPrivate *get(const QCompleter *o) { return o->d_func(); }
74};
75
77{
78public:
79 QIndexMapper() : v(false), f(0), t(-1) { }
80 QIndexMapper(int f, int t) : v(false), f(f), t(t) { }
81 QIndexMapper(const QList<int> &vec) : v(true), vector(vec), f(-1), t(-1) { }
82
83 inline int count() const { return v ? vector.size() : t - f + 1; }
84 inline int operator[] (int index) const { return v ? vector[index] : f + index; }
85 inline int indexOf(int x) const { return v ? vector.indexOf(x) : ((t < f) ? -1 : x - f); }
86 inline bool isValid() const { return !isEmpty(); }
87 inline bool isEmpty() const { return v ? vector.isEmpty() : (t < f); }
88 inline void append(int x) { Q_ASSERT(v); vector.append(x); }
89 inline int first() const { return v ? vector.first() : f; }
90 inline int last() const { return v ? vector.last() : t; }
91 inline int from() const { Q_ASSERT(!v); return f; }
92 inline int to() const { Q_ASSERT(!v); return t; }
93 inline int cost() const { return vector.size()+2; }
94
95private:
96 bool v;
97 QList<int> vector;
98 int f, t;
99};
100
103 QMatchData(const QIndexMapper& indices, int em, bool p) :
106 inline bool isValid() const { return indices.isValid(); }
109};
110
112{
113public:
114 typedef QMap<QString, QMatchData> CacheItem;
115 typedef QMap<QModelIndex, CacheItem> Cache;
116
118 virtual ~QCompletionEngine() { }
119
120 void filter(const QStringList &parts);
121
123 bool matchHint(const QString &part, const QModelIndex &parent, QMatchData *m) const;
124
125 void saveInCache(QString, const QModelIndex&, const QMatchData&);
126 bool lookupCache(const QString &part, const QModelIndex &parent, QMatchData *m) const;
127
128 virtual void filterOnDemand(int) { }
129 virtual QMatchData filter(const QString&, const QModelIndex&, int) = 0;
130
132
138
140 int cost;
141};
142
151
153{
154public:
156
157 void filterOnDemand(int) override;
158 QMatchData filter(const QString&, const QModelIndex&, int) override;
159private:
160 int buildIndices(const QString& str, const QModelIndex& parent, int n,
161 const QIndexMapper& iv, QMatchData* m);
162};
163
165{
166public:
169 void paint(QPainter *p, const QStyleOptionViewItem& opt, const QModelIndex& idx) const override {
170 QStyleOptionViewItem optCopy = opt;
171 optCopy.showDecorationSelected = true;
172 if (view->currentIndex() == idx)
173 optCopy.state |= QStyle::State_HasFocus;
174 QStyledItemDelegate::paint(p, optCopy, idx);
175 }
176
177private:
178 QAbstractItemView *view;
179};
180
182
184{
186
187public:
189
190 void createEngine();
191 void setFiltered(bool);
192 void filter(const QStringList& parts);
193 int completionCount() const;
194 int currentRow() const { return engine->curRow; }
195 bool setCurrentRow(int row);
196 QModelIndex currentIndex(bool) const;
197
198 QModelIndex index(int row, int column, const QModelIndex & = QModelIndex()) const override;
199 int rowCount(const QModelIndex &index = QModelIndex()) const override;
200 int columnCount(const QModelIndex &index = QModelIndex()) const override;
201 bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
202 QModelIndex parent(const QModelIndex & = QModelIndex()) const override { return QModelIndex(); }
203 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
204
206 QModelIndex mapToSource(const QModelIndex& proxyIndex) const override;
207 QModelIndex mapFromSource(const QModelIndex& sourceIndex) const override;
208
210 QScopedPointer<QCompletionEngine> engine;
212
213 Q_DECLARE_PRIVATE(QCompletionModel)
214
215signals:
216 void rowsAdded();
217
218public Q_SLOTS:
219 void invalidate();
220 void rowsInserted();
221 void modelDestroyed();
222};
223
225{
226 Q_DECLARE_PUBLIC(QCompletionModel)
227};
228
230
231#endif // QCOMPLETER_P_H
Q_INVOKABLE int const QModelIndex & parent
Returns the parent of the model item with the given index.
The QAbstractItemView class provides the basic functionality for item view classes.
QModelIndex currentIndex() const
Returns the model index of the current item.
The QAbstractProxyModel class provides a base class for proxy item models that can do sorting,...
QAbstractItemModel * sourceModel
the source model of this proxy model.
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)
QCompleter::CompletionMode mode
QCompleter::ModelSorting sorting
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:24
CompletionMode
This enum specifies how completions are provided to the user.
Definition qcompleter.h:37
ModelSorting
This enum specifies how the items in the model are sorted.
Definition qcompleter.h:44
QMatchData historyMatch
QMatchData curMatch
void saveInCache(QString, const QModelIndex &, const QMatchData &)
virtual QMatchData filter(const QString &, const QModelIndex &, int)=0
QModelIndex curParent
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()
int currentRow() const
int rowCount(const QModelIndex &index=QModelIndex()) const override
Returns the number of rows under the given parent.
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
QModelIndex mapToSource(const QModelIndex &proxyIndex) const override
Reimplement this function to return the model index in the source model that corresponds to the proxy...
QCompletionModel(QCompleterPrivate *c, QObject *parent)
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
\inmodule QtCore
qsizetype size() const noexcept
Definition qlist.h:397
bool isEmpty() const noexcept
Definition qlist.h:401
T & first()
Definition qlist.h:645
T & last()
Definition qlist.h:648
void append(parameter_type t)
Definition qlist.h:458
\inmodule QtCore
\inmodule QtCore
Definition qobject.h:103
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
\inmodule QtCore\reentrant
Definition qrect.h:30
QSortedModelEngine(QCompleterPrivate *c)
Qt::SortOrder sortOrder(const QModelIndex &) const
QIndexMapper indexHint(QString, const QModelIndex &, Qt::SortOrder)
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QStyle::State state
@ State_HasFocus
Definition qstyle.h:75
The QStyledItemDelegate class provides display and editing facilities for data items from a model.
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Renders the delegate using the given painter and style option for the item specified by index.
QUnsortedModelEngine(QCompleterPrivate *c)
void filterOnDemand(int) override
\inmodule QtCore
Definition qvariant.h:65
QString str
[2]
QStyleOptionButton opt
Combined button and popup list for selecting options.
@ DisplayRole
SortOrder
Definition qnamespace.h:121
CaseSensitivity
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
const GLfloat * m
GLuint index
[2]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLfloat GLfloat f
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
GLfloat n
GLsizei GLenum const void * indices
GLenum GLenum GLsizei void GLsizei void * column
const GLubyte * c
GLdouble GLdouble t
Definition qopenglext.h:243
GLsizei const GLchar *const * path
GLenum GLenum GLsizei void * row
GLfloat GLfloat p
[1]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define QT_REQUIRE_CONFIG(feature)
#define Q_OBJECT
#define Q_SLOTS
#define signals
QSqlQueryModel * model
[16]
QCompleter * completer
[0]
QQuickView * view
[0]
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept
Definition qlist.h:962
QMatchData(const QIndexMapper &indices, int em, bool p)
int exactMatchIndex
bool isValid() const
QIndexMapper indices