Qt 6.x
The Qt SDK
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#include "private/qabstractproxymodel_p.h"
29
31
33
35
37{
38 Q_DECLARE_PUBLIC(QCompleter)
39
40public:
43 void init(QAbstractItemModel *model = nullptr);
44
49 Qt::MatchFlags filterMode;
50
53 int role;
54 int column;
57 bool wrap;
58
62
63 void showPopup(const QRect&);
64 void _q_complete(QModelIndex, bool = false);
66 void _q_autoResizePopup();
68 void setCurrentIndex(QModelIndex, bool = true);
69
70 static QCompleterPrivate *get(QCompleter *o) { return o->d_func(); }
71 static const QCompleterPrivate *get(const QCompleter *o) { return o->d_func(); }
72};
73
75{
76public:
77 QIndexMapper() : v(false), f(0), t(-1) { }
78 QIndexMapper(int f, int t) : v(false), f(f), t(t) { }
79 QIndexMapper(const QList<int> &vec) : v(true), vector(vec), f(-1), t(-1) { }
80
81 inline int count() const { return v ? vector.size() : t - f + 1; }
82 inline int operator[] (int index) const { return v ? vector[index] : f + index; }
83 inline int indexOf(int x) const { return v ? vector.indexOf(x) : ((t < f) ? -1 : x - f); }
84 inline bool isValid() const { return !isEmpty(); }
85 inline bool isEmpty() const { return v ? vector.isEmpty() : (t < f); }
86 inline void append(int x) { Q_ASSERT(v); vector.append(x); }
87 inline int first() const { return v ? vector.first() : f; }
88 inline int last() const { return v ? vector.last() : t; }
89 inline int from() const { Q_ASSERT(!v); return f; }
90 inline int to() const { Q_ASSERT(!v); return t; }
91 inline int cost() const { return vector.size()+2; }
92
93private:
94 bool v;
95 QList<int> vector;
96 int f, t;
97};
98
99struct QMatchData {
101 QMatchData(const QIndexMapper& indices, int em, bool p) :
104 inline bool isValid() const { return indices.isValid(); }
107};
108
110{
111public:
114
116 virtual ~QCompletionEngine() { }
117
118 void filter(const QStringList &parts);
119
121 bool matchHint(const QString &part, const QModelIndex &parent, QMatchData *m) const;
122
123 void saveInCache(QString, const QModelIndex&, const QMatchData&);
124 bool lookupCache(const QString &part, const QModelIndex &parent, QMatchData *m) const;
125
126 virtual void filterOnDemand(int) { }
127 virtual QMatchData filter(const QString&, const QModelIndex&, int) = 0;
128
130
136
138 int cost;
139};
140
142{
143public:
145 QMatchData filter(const QString&, const QModelIndex&, int) override;
147 Qt::SortOrder sortOrder(const QModelIndex&) const;
148};
149
151{
152public:
154
155 void filterOnDemand(int) override;
156 QMatchData filter(const QString&, const QModelIndex&, int) override;
157private:
158 int buildIndices(const QString& str, const QModelIndex& parent, int n,
159 const QIndexMapper& iv, QMatchData* m);
160};
161
163{
164public:
167 void paint(QPainter *p, const QStyleOptionViewItem& opt, const QModelIndex& idx) const override {
168 QStyleOptionViewItem optCopy = opt;
169 optCopy.showDecorationSelected = true;
170 if (view->currentIndex() == idx)
171 optCopy.state |= QStyle::State_HasFocus;
172 QStyledItemDelegate::paint(p, optCopy, idx);
173 }
174
175private:
176 QAbstractItemView *view;
177};
178
180
182{
184
185public:
187
188 void createEngine();
189 void setFiltered(bool);
190 void filter(const QStringList& parts);
191 int completionCount() const;
192 int currentRow() const { return engine->curRow; }
193 bool setCurrentRow(int row);
194 QModelIndex currentIndex(bool) const;
195
196 QModelIndex index(int row, int column, const QModelIndex & = QModelIndex()) const override;
197 int rowCount(const QModelIndex &index = QModelIndex()) const override;
198 int columnCount(const QModelIndex &index = QModelIndex()) const override;
199 bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
200 QModelIndex parent(const QModelIndex & = QModelIndex()) const override { return QModelIndex(); }
201 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
202
204 QModelIndex mapToSource(const QModelIndex& proxyIndex) const override;
205 QModelIndex mapFromSource(const QModelIndex& sourceIndex) const override;
206
210
211 Q_DECLARE_PRIVATE(QCompletionModel)
212
213signals:
214 void rowsAdded();
215
216public Q_SLOTS:
217 void invalidate();
218 void rowsInserted();
219 void modelDestroyed();
220};
221
223{
224 Q_DECLARE_PUBLIC(QCompletionModel)
225};
226
228
229#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...
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
Definition qlist.h:74
qsizetype size() const noexcept
Definition qlist.h:386
bool isEmpty() const noexcept
Definition qlist.h:390
T & first()
Definition qlist.h:628
T & last()
Definition qlist.h:631
void append(parameter_type t)
Definition qlist.h:441
Definition qmap.h:186
\inmodule QtCore
\inmodule QtCore
Definition qobject.h:90
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
\inmodule QtCore
Definition qpointer.h:18
\inmodule QtCore\reentrant
Definition qrect.h:30
\inmodule QtCore
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:127
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:64
QString str
[2]
QStyleOptionButton opt
Combined button and popup list for selecting options.
@ DisplayRole
SortOrder
Definition qnamespace.h:120
CaseSensitivity
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
const GLfloat * m
GLuint index
[2]
GLfloat GLfloat f
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
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:955
QMatchData(const QIndexMapper &indices, int em, bool p)
int exactMatchIndex
bool isValid() const
QIndexMapper indices
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent