110#include "QtWidgets/qscrollbar.h"
111#include "QtCore/qdir.h"
112#if QT_CONFIG(stringlistmodel)
113#include "QtCore/qstringlistmodel.h"
115#if QT_CONFIG(filesystemmodel)
116#include "QtGui/qfilesystemmodel.h"
118#include "QtWidgets/qheaderview.h"
119#if QT_CONFIG(listview)
120#include "QtWidgets/qlistview.h"
122#include "QtWidgets/qapplication.h"
123#include "QtGui/qevent.h"
124#include <private/qapplication_p.h>
125#include <private/qwidget_p.h>
126#if QT_CONFIG(lineedit)
127#include "QtWidgets/qlineedit.h"
129#include "QtCore/qdir.h"
145 return d->model->columnCount();
174 bool sortedEngine =
false;
176 switch (
c->sorting) {
178 sortedEngine =
false;
198 if (!
index.isValid())
208 if (
index.row() < rootIndices.count()) {
236 row = rootIndices.indexOf(idx.
row());
260 if (row < 0 || !engine->matchCount())
416 int emi =
filter(part, parent, -1).exactMatchIndex;
438#if QT_CONFIG(filesystemmodel)
439 const bool isFsModel = (qobject_cast<QFileSystemModel *>(
source) !=
nullptr);
441 const bool isFsModel =
false;
448 for (
int i = 0;
i <
source->rowCount();
i++) {
451#
if !defined(Q_OS_WIN)
471 const auto mapEnd =
map.
end();
475 while (!
key.isEmpty()) {
515 if (
cost *
sizeof(
int) > 1024 * 1024) {
519 int sz = ci.size()/2;
522 while (it2 != ci.end() &&
i < sz) {
527 if (ci.size() == 0) {
536 part = std::move(part).
toLower();
546 part = std::move(part).
toLower();
559 if (
value.isValid()) {
563 to =
value.indices.first() - 1;
570 for(CacheItem::const_iterator it2 =
it; it2 !=
map.
constEnd(); ++it2) {
572 if (
value.isValid() && !it2.key().startsWith(part)) {
576 from =
value.indices.first() + 1;
623 while (high - low > 1)
625 probe = (high + low) / 2;
626 probeIndex =
model->
index(probe,
c->column, parent);
645 if (!probeData.startsWith(part,
c->
cs)) {
665 while (high - low > 1)
667 probe = (high + low) / 2;
668 probeIndex =
model->
index(probe,
c->column, parent);
670 const bool startsWith = probeData.startsWith(part,
c->
cs);
689 Q_ASSERT(
n != -1 ||
m->exactMatchIndex == -1);
701 switch (
c->filterMode) {
765 if (!foundInCache && !
hint.isValid()) {
768 int lastIndex = buildIndices(part, parent,
n, all, &
m);
769 m.partial = (lastIndex != lastRow);
772 buildIndices(part, parent, INT_MAX,
hint.indices, &
m);
773 m.partial =
hint.partial;
775 if (
m.partial && ((
n == -1 &&
m.exactMatchIndex == -1) || (
m.indices.count() <
n))) {
779 int want =
n == -1 ? -1 :
n -
m.indices.count();
780 int lastIndex = buildIndices(part, parent, want, rest, &
m);
781 m.partial = (lastRow != lastIndex);
794 filterMode(
Qt::MatchStartsWith),
795 cs(
Qt::CaseSensitive),
802 hiddenBecauseNoMatch(
false)
812#if !QT_CONFIG(listview)
827 if (!
index.isValid())
834 if (!
index.isValid())
844 index = indexes.first();
862 completion =
q->pathFromIndex(si);
863#if QT_CONFIG(filesystemmodel)
874 emit q->highlighted(completion);
877 emit q->activated(completion);
896 if (hsb && hsb->isVisible())
897 h +=
popup->horizontalScrollBar()->sizeHint().height();
899 if (
rect.isValid()) {
923 pos.setY(
pos.y() -
h - rh + 2);
928 if (!
popup->isVisible())
932#if QT_CONFIG(filesystemmodel)
944 const auto pathSize =
path.size();
950 return path.compare(prefix, caseSensitivity) == 0 && isRoot(
model,
path);
952 const auto separator = u
'/';
953 return prefix.
startsWith(
path, caseSensitivity) && prefix.
at(pathSize) == separator
996#if QT_CONFIG(stringlistmodel)
1032 d->widget->removeEventFilter(
this);
1039 d->popup->setFocusProxy(
d->widget);
1069 if (oldModel ==
model)
1071#if QT_CONFIG(filesystemmodel)
1072 if (qobject_cast<const QFileSystemModel *>(oldModel))
1075 d->proxy->setSourceModel(
model);
1078 if (oldModel && oldModel->QObject::parent() ==
this)
1080#if QT_CONFIG(filesystemmodel)
1083#if defined(Q_OS_WIN)
1102 return d->proxy->sourceModel();
1131 d->widget->removeEventFilter(
this);
1133 d->popup->deleteLater();
1138 d->widget->installEventFilter(
this);
1178 qWarning(
"Unhandled QCompleter::filterMode flag is used.");
1183 d->proxy->createEngine();
1184 d->proxy->invalidate();
1190 return d->filterMode;
1228 if (
d->popup->model() !=
d->proxy)
1237 d->popup->setParent(
nullptr);
1241 d->widget->setFocusPolicy(origPolicy);
1243 d->popup->setFocusProxy(
d->widget);
1244 d->popup->installEventFilter(
this);
1246#if QT_CONFIG(listview)
1269#if QT_CONFIG(listview)
1299 if (
o ==
d->widget) {
1300 switch (e->
type()) {
1302 if (
d->eatFocusOut) {
1303 d->hiddenBecauseNoMatch =
false;
1304 if (
d->popup &&
d->popup->isVisible())
1320 switch (e->
type()) {
1327 const int key = ke->key();
1331 d->setCurrentIndex(curIndex);
1345 if (!curIndex.isValid()) {
1346 int rowCount =
d->proxy->rowCount();
1347 QModelIndex lastIndex =
d->proxy->index(rowCount - 1,
d->column);
1348 d->setCurrentIndex(lastIndex);
1350 }
else if (curIndex.row() == 0) {
1358 if (!curIndex.isValid()) {
1360 d->setCurrentIndex(firstIndex);
1362 }
else if (curIndex.row() ==
d->proxy->rowCount() - 1) {
1376 d->eatFocusOut =
false;
1377 (
static_cast<QObject *
>(
d->widget))->event(ke);
1378 d->eatFocusOut =
true;
1379 if (!
d->widget || e->
isAccepted() || !
d->popup->isVisible()) {
1381 if (
d->widget && (!
d->widget->hasFocus()
1382#ifdef QT_KEYPAD_NAVIGATION
1383 || (QApplicationPrivate::keypadNavigationEnabled() && !
d->widget->hasEditFocus())
1392#if QT_CONFIG(shortcut)
1399#ifdef QT_KEYPAD_NAVIGATION
1401 if (!QApplicationPrivate::keypadNavigationEnabled())
1408 if (curIndex.isValid())
1409 d->_q_complete(curIndex);
1428#ifdef QT_KEYPAD_NAVIGATION
1431 if (QApplicationPrivate::keypadNavigationEnabled() && ke->key() ==
Qt::Key_Back) {
1438 d->eatFocusOut =
false;
1440 d->eatFocusOut =
true;
1447#ifdef QT_KEYPAD_NAVIGATION
1448 if (QApplicationPrivate::keypadNavigationEnabled()) {
1456 d->eatFocusOut =
false;
1458 d->eatFocusOut =
true;
1464 if (!
d->popup->underMouse()) {
1496 d->hiddenBecauseNoMatch =
false;
1499 d->_q_complete(idx,
true);
1508 d->hiddenBecauseNoMatch =
true;
1514 d->setCurrentIndex(idx,
false);
1517 d->popupRect =
rect;
1532 return d->proxy->setCurrentRow(
row);
1543 return d->proxy->currentRow();
1554 return d->proxy->completionCount();
1594 if (
d->sorting == sorting)
1596 d->sorting = sorting;
1597 d->proxy->createEngine();
1598 d->proxy->invalidate();
1623#if QT_CONFIG(listview)
1628 d->proxy->invalidate();
1648 if (
d->role == role)
1651 d->proxy->invalidate();
1670 if (
d->wrap ==
wrap)
1691 return d->maxVisibleItems;
1698 qWarning(
"QCompleter::setMaxVisibleItems: "
1699 "Invalid max visible items (%d) must be >= 0", maxItems);
1702 d->maxVisibleItems = maxItems;
1719 d->proxy->createEngine();
1720 d->proxy->invalidate();
1757 return d->proxy->currentIndex(
false);
1804 if (!
index.isValid())
1810 bool isFsModel =
false;
1811#if QT_CONFIG(filesystemmodel)
1812 isFsModel = qobject_cast<QFileSystemModel *>(
d->proxy->sourceModel()) !=
nullptr;
1815 return sourceModel->
data(
index,
d->role).toString();
1821#if QT_CONFIG(filesystemmodel)
1829#if !defined(Q_OS_WIN)
1852 bool isFsModel =
false;
1853#if QT_CONFIG(filesystemmodel)
1855 isFsModel = qobject_cast<QFileSystemModel *>(
d->proxy->sourceModel()) !=
nullptr;
1858 if (!isFsModel ||
path.isEmpty())
1862#if defined(Q_OS_WIN)
1863 if (pathCopy ==
"\\"_L1 || pathCopy ==
"\\\\"_L1)
1865 const bool startsWithDoubleSlash = pathCopy.startsWith(
"\\\\"_L1);
1866 if (startsWithDoubleSlash)
1867 pathCopy = pathCopy.mid(2);
1873#if defined(Q_OS_WIN)
1874 if (startsWithDoubleSlash)
1875 parts[0].prepend(
"\\\\"_L1);
1877 if (pathCopy[0] ==
sep)
1920#include "moc_qcompleter.cpp"
1922#include "moc_qcompleter_p.cpp"
Q_INVOKABLE int const QModelIndex & parent
Returns the parent of the model item with the given index.
void endResetModel()
Completes a model reset operation.
void columnsRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted after columns have been removed from the model.
void modelReset(QPrivateSignal)
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >())
This signal is emitted whenever the data in an existing item changes.
virtual Q_INVOKABLE int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
void layoutChanged(const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
void beginResetModel()
Begins a model reset operation.
QModelIndex createIndex(int row, int column, const void *data=nullptr) const
Creates a model index for the given row and column with the internal pointer ptr.
void columnsInserted(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted after columns have been inserted into the model.
virtual Q_INVOKABLE QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const =0
Returns the data stored under the given role for the item referred to by the index.
void rowsRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted after rows have been removed from the model.
The QAbstractItemView class provides the basic functionality for item view classes.
void setEditTriggers(EditTriggers triggers)
QAbstractItemModel * model() const
Returns the model that this view is presenting.
void setSelectionBehavior(QAbstractItemView::SelectionBehavior behavior)
virtual void setModel(QAbstractItemModel *model)
Sets the model for the view to present.
virtual void scrollTo(const QModelIndex &index, ScrollHint hint=EnsureVisible)=0
Scrolls the view if necessary to ensure that the item at index is visible.
QItemSelectionModel * selectionModel() const
Returns the current selection model.
void setSelectionMode(QAbstractItemView::SelectionMode mode)
virtual int sizeHintForRow(int row) const
Returns the height size hint for the specified row or -1 if there is no model.
The QAbstractProxyModel class provides a base class for proxy item models that can do sorting,...
QAbstractItemModel * sourceModel
the source model of this proxy model.
virtual void setSourceModel(QAbstractItemModel *sourceModel)
Sets the given sourceModel to be processed by the proxy model.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Returns the index of the data in row and column with parent.
Qt::ItemFlags flags(const QModelIndex &index) const override
\reimp
static QWidget * widgetAt(const QPoint &p)
Returns the widget at global screen position point, or \nullptr if there is no Qt widget there.
void setCurrentIndex(QModelIndex, bool=true)
void _q_fileSystemModelDirectoryLoaded(const QString &path)
bool hiddenBecauseNoMatch
void _q_completionSelected(const QItemSelection &)
void _q_autoResizePopup()
QPointer< QWidget > widget
void init(QAbstractItemModel *model=nullptr)
QAbstractItemView * popup
void _q_complete(QModelIndex, bool=false)
void showPopup(const QRect &)
The QCompleter class provides completions based on an item model.
void setCompletionColumn(int column)
QAbstractItemModel * model() const
Returns the model that provides completion strings.
void setModelSorting(ModelSorting sorting)
QWidget * widget() const
Returns the widget for which the completer object is providing completions.
~QCompleter() override
Destroys the completer object.
int completionCount() const
Returns the number of completions for the current prefix.
int completionColumn
the column in the model in which completions are searched for.
void setFilterMode(Qt::MatchFlags filterMode)
CompletionMode
This enum specifies how completions are provided to the user.
@ UnfilteredPopupCompletion
int maxVisibleItems
the maximum allowed size on screen of the completer, measured in items
void setCompletionMode(CompletionMode mode)
bool wrapAround
the completions wrap around when navigating through items
QCompleter(QObject *parent=nullptr)
Constructs a completer object with the given parent.
Qt::MatchFlags filterMode
This property controls how filtering is performed.
virtual QStringList splitPath(const QString &path) const
Splits the given path into strings that are used to match at each level in the model().
QString completionPrefix
the completion prefix used to provide completions.
QAbstractItemView * popup() const
Returns the popup used to display completions.
virtual QString pathFromIndex(const QModelIndex &index) const
Returns the path for the given index.
void setCompletionRole(int role)
bool setCurrentRow(int row)
Sets the current row to the row specified.
Qt::CaseSensitivity caseSensitivity
the case sensitivity of the matching
void setPopup(QAbstractItemView *popup)
Sets the popup used to display completions to popup.
void complete(const QRect &rect=QRect())
For QCompleter::PopupCompletion and QCompletion::UnfilteredPopupCompletion modes, calling this functi...
ModelSorting
This enum specifies how the items in the model are sorted.
@ CaseSensitivelySortedModel
@ CaseInsensitivelySortedModel
ModelSorting modelSorting
the way the model is sorted
void setModel(QAbstractItemModel *c)
Sets the model which provides completions to model.
QModelIndex currentIndex() const
Returns the model index of the current completion in the completionModel().
bool event(QEvent *) override
\reimp
void setWidget(QWidget *widget)
Sets the widget for which completion are provided for to widget.
bool eventFilter(QObject *o, QEvent *e) override
\reimp
QString currentCompletion() const
Returns the current completion string.
void setCaseSensitivity(Qt::CaseSensitivity caseSensitivity)
CompletionMode completionMode
how the completions are provided to the user
void setCompletionPrefix(const QString &prefix)
QAbstractItemModel * completionModel() const
Returns the completion model.
int currentRow() const
Returns the current row.
void setWrapAround(bool wrap)
void setMaxVisibleItems(int maxItems)
void activated(const QString &text)
This signal is sent when an item in the popup() is activated by the user (by clicking or pressing ret...
int completionRole
the item role to be used to query the contents of items for matching.
void saveInCache(QString, const QModelIndex &, const QMatchData &)
void filter(const QStringList &parts)
virtual void filterOnDemand(int)
QMap< QString, QMatchData > CacheItem
bool matchHint(const QString &part, const QModelIndex &parent, QMatchData *m) const
bool lookupCache(const QString &part, const QModelIndex &parent, QMatchData *m) const
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 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
int completionCount() const
int columnCount(const QModelIndex &index=QModelIndex()) const override
Returns the number of columns for the children of the given parent.
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 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...
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)
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
static QString fromNativeSeparators(const QString &pathName)
static QChar separator()
Returns the native directory separator: "/" under Unix and "\\" under Windows.
static QString toNativeSeparators(const QString &pathName)
Type type() const
Returns the event type.
The QFileSystemModel class provides a data model for the local filesystem.
virtual void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Sets the model item index to be the current item, and emits currentChanged().
virtual void clear()
Clears the selection model.
Q_CORE_EXPORT QModelIndexList indexes() const
Returns a list of model indexes that correspond to the selected items.
The QKeyEvent class describes a key event.
The QListView class provides a list or icon view onto a model.
void setModelColumn(int column)
qsizetype size() const noexcept
void prepend(rvalue_ref t)
iterator erase(const_iterator it)
iterator find(const Key &key)
iterator lowerBound(const Key &key)
const_iterator constBegin() const
const_iterator constEnd() const
constexpr int row() const noexcept
Returns the row this model index refers to.
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
constexpr int column() const noexcept
Returns the column this model index refers to.
constexpr bool isValid() const noexcept
Returns {true} if this model index is valid; otherwise returns {false}.
QModelIndex sibling(int row, int column) const
Returns the sibling at row and column.
void installEventFilter(QObject *filterObj)
Installs an event filter filterObj on this object.
QObject * parent() const
Returns a pointer to the parent object.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
virtual bool event(QEvent *event)
This virtual function receives events to an object and should return true if the event e was recogniz...
virtual bool eventFilter(QObject *watched, QEvent *event)
Filters events if this object has been installed as an event filter for the watched object.
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
void reset(T *other=nullptr) noexcept(noexcept(Cleanup::cleanup(std::declval< T * >())))
Deletes the existing object it is pointing to (if any), and sets its pointer to other.
QRect availableGeometry
the screen's available geometry in pixels
QMatchData filter(const QString &, const QModelIndex &, int) override
Qt::SortOrder sortOrder(const QModelIndex &) const
QIndexMapper indexHint(QString, const QModelIndex &, Qt::SortOrder)
QVariant data(const QModelIndex &item, int role=Qt::DisplayRole) const override
Returns the value for the specified item and role.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
If the database supports returning the size of a query (see QSqlDriver::hasFeature()),...
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
void chop(qsizetype n)
Removes n characters from the end of the string.
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
QString right(qsizetype n) const &
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
int compare(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
static QString static QString qsizetype Qt::CaseSensitivity cs
QString toLower() const &
QChar * data()
Returns a pointer to the data stored in the QString.
bool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
void filterOnDemand(int) override
QMatchData filter(const QString &, const QModelIndex &, int) override
QString toString() const
Returns the variant as a QString if the variant has a userType() including, but not limited to:
QMap< QString, QString > map
[6]
QSet< QString >::iterator it
Combined button and popup list for selecting options.
static const int prefixSize
QList< QString > QStringList
Constructs a string list that contains the given string, str.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
GLsizei const GLfloat * v
[13]
GLfloat GLfloat GLfloat w
[0]
GLdouble GLdouble GLdouble GLdouble top
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
GLsizei GLenum const void * indices
GLfloat GLfloat GLfloat GLfloat h
GLsizei GLsizei GLchar * source
GLenum GLenum GLsizei void GLsizei void * column
GLdouble GLdouble GLdouble GLdouble q
GLsizei const GLchar *const * path
GLenum GLenum GLsizei void * row
GLfixed GLfixed GLint GLint order
static constexpr QChar sep
static QT_BEGIN_NAMESPACE QAsn1Element wrap(quint8 type, const QAsn1Element &child)
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
QSqlQueryModel * model
[16]
QItemSelection * selection
[0]
selection select(topLeft, bottomRight)