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())
260 if (row < 0 || !engine->matchCount())
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;
572 if (
value.isValid() && !it2.key().startsWith(part)) {
576 from =
value.indices.first() + 1;
623 while (high - low > 1)
625 probe = (high + low) / 2;
665 while (high - low > 1)
667 probe = (high + low) / 2;
670 const bool startsWith = probeData.
startsWith(part,
c->cs);
689 Q_ASSERT(
n != -1 ||
m->exactMatchIndex == -1);
701 switch (
c->filterMode) {
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())
862 completion =
q->pathFromIndex(si);
863#if QT_CONFIG(filesystemmodel)
874 emit q->highlighted(completion);
877 emit q->activated(completion);
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);
1035 d->widget->installEventFilter(
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)
1229 d->popup->setModel(
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)
1300 d->hiddenBecauseNoMatch =
false;
1301 if (
d->popup &&
d->popup->isVisible())
1309 switch (
e->type()) {
1316 const int key = ke->
key();
1320 d->setCurrentIndex(curIndex);
1335 int rowCount =
d->proxy->rowCount();
1336 QModelIndex lastIndex =
d->proxy->index(rowCount - 1,
d->column);
1337 d->setCurrentIndex(lastIndex);
1339 }
else if (curIndex.
row() == 0) {
1349 d->setCurrentIndex(firstIndex);
1351 }
else if (curIndex.
row() ==
d->proxy->rowCount() - 1) {
1365 d->eatFocusOut =
false;
1366 (
static_cast<QObject *
>(
d->widget))->event(ke);
1367 d->eatFocusOut =
true;
1368 if (!
d->widget ||
e->isAccepted() || !
d->popup->isVisible()) {
1370 if (
d->widget && (!
d->widget->hasFocus()
1371#ifdef QT_KEYPAD_NAVIGATION
1372 || (QApplicationPrivate::keypadNavigationEnabled() && !
d->widget->hasEditFocus())
1376 if (
e->isAccepted())
1381#if QT_CONFIG(shortcut)
1388#ifdef QT_KEYPAD_NAVIGATION
1390 if (!QApplicationPrivate::keypadNavigationEnabled())
1398 d->_q_complete(curIndex);
1417#ifdef QT_KEYPAD_NAVIGATION
1420 if (QApplicationPrivate::keypadNavigationEnabled() && ke->
key() ==
Qt::Key_Back) {
1427 d->eatFocusOut =
false;
1429 d->eatFocusOut =
true;
1436#ifdef QT_KEYPAD_NAVIGATION
1437 if (QApplicationPrivate::keypadNavigationEnabled()) {
1445 d->eatFocusOut =
false;
1447 d->eatFocusOut =
true;
1453 if (!
d->popup->underMouse()) {
1485 d->hiddenBecauseNoMatch =
false;
1488 d->_q_complete(idx,
true);
1497 d->hiddenBecauseNoMatch =
true;
1503 d->setCurrentIndex(idx,
false);
1506 d->popupRect =
rect;
1521 return d->proxy->setCurrentRow(
row);
1532 return d->proxy->currentRow();
1543 return d->proxy->completionCount();
1583 if (
d->sorting == sorting)
1585 d->sorting = sorting;
1586 d->proxy->createEngine();
1587 d->proxy->invalidate();
1612#if QT_CONFIG(listview)
1617 d->proxy->invalidate();
1637 if (
d->role == role)
1640 d->proxy->invalidate();
1659 if (
d->wrap ==
wrap)
1680 return d->maxVisibleItems;
1687 qWarning(
"QCompleter::setMaxVisibleItems: "
1688 "Invalid max visible items (%d) must be >= 0", maxItems);
1691 d->maxVisibleItems = maxItems;
1708 d->proxy->createEngine();
1709 d->proxy->invalidate();
1746 return d->proxy->currentIndex(
false);
1793 if (!
index.isValid())
1799 bool isFsModel =
false;
1800#if QT_CONFIG(filesystemmodel)
1801 isFsModel = qobject_cast<QFileSystemModel *>(
d->proxy->sourceModel()) !=
nullptr;
1810#if QT_CONFIG(filesystemmodel)
1818#if !defined(Q_OS_WIN)
1841 bool isFsModel =
false;
1842#if QT_CONFIG(filesystemmodel)
1844 isFsModel = qobject_cast<QFileSystemModel *>(
d->proxy->sourceModel()) !=
nullptr;
1847 if (!isFsModel ||
path.isEmpty())
1851#if defined(Q_OS_WIN)
1852 if (pathCopy ==
"\\"_L1 || pathCopy ==
"\\\\"_L1)
1854 const bool startsWithDoubleSlash = pathCopy.
startsWith(
"\\\\"_L1);
1855 if (startsWithDoubleSlash)
1856 pathCopy = pathCopy.
mid(2);
1862#if defined(Q_OS_WIN)
1863 if (startsWithDoubleSlash)
1864 parts[0].prepend(
"\\\\"_L1);
1866 if (pathCopy[0] ==
sep)
1909#include "moc_qcompleter.cpp"
1911#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 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)
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)
\inmodule QtCore \reentrant
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.
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
int key() const
Returns the code of the key that was pressed or released.
The QListView class provides a list or icon view onto a model.
void setModelColumn(int column)
qsizetype size() const noexcept
bool isEmpty() 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.
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
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString right(qsizetype n) const
Returns a substring that contains the n rightmost characters of the string.
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.
QStringList split(const QString &sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Splits the string into substrings wherever sep occurs, and returns the list of those strings.
qsizetype size() const
Returns the number of characters in this string.
QString mid(qsizetype position, qsizetype n=-1) const
Returns a string that contains n characters of this string, starting at the specified position index.
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
int compare(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
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
bool isValid() const
Returns true if the storage type of this variant is not QMetaType::UnknownType; otherwise returns fal...
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
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 GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
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)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent