summaryrefslogtreecommitdiffstats
path: root/src/widgets/util/qcompleter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/util/qcompleter.cpp')
-rw-r--r--src/widgets/util/qcompleter.cpp61
1 files changed, 33 insertions, 28 deletions
diff --git a/src/widgets/util/qcompleter.cpp b/src/widgets/util/qcompleter.cpp
index abf3566e1c..394a968aad 100644
--- a/src/widgets/util/qcompleter.cpp
+++ b/src/widgets/util/qcompleter.cpp
@@ -326,7 +326,7 @@ int QCompletionModel::rowCount(const QModelIndex &parent) const
if (showAll) {
// Show all items below current parent, even if we have no valid matches
- if (engine->curParts.count() != 1 && !engine->matchCount()
+ if (engine->curParts.size() != 1 && !engine->matchCount()
&& !engine->curParent.isValid())
return 0;
return d->model->rowCount(engine->curParent);
@@ -411,7 +411,7 @@ void QCompletionEngine::filter(const QStringList& parts)
return;
QModelIndex parent;
- for (int i = 0; i < curParts.count() - 1; i++) {
+ for (int i = 0; i < curParts.size() - 1; i++) {
QString part = curParts.at(i);
int emi = filter(part, parent, -1).exactMatchIndex;
if (emi == -1)
@@ -432,7 +432,7 @@ void QCompletionEngine::filter(const QStringList& parts)
QMatchData QCompletionEngine::filterHistory()
{
QAbstractItemModel *source = c->proxy->sourceModel();
- if (curParts.count() <= 1 || c->proxy->showAll || !source)
+ if (curParts.size() <= 1 || c->proxy->showAll || !source)
return QMatchData();
#if QT_CONFIG(filesystemmodel)
@@ -516,7 +516,7 @@ void QCompletionEngine::saveInCache(QString part, const QModelIndex& parent, con
QMap<QModelIndex, CacheItem>::iterator it1 = cache.begin();
while (it1 != cache.end()) {
CacheItem& ci = it1.value();
- int sz = ci.count()/2;
+ int sz = ci.size()/2;
QMap<QString, QMatchData>::iterator it2 = ci.begin();
int i = 0;
while (it2 != ci.end() && i < sz) {
@@ -524,7 +524,7 @@ void QCompletionEngine::saveInCache(QString part, const QModelIndex& parent, con
it2 = ci.erase(it2);
i++;
}
- if (ci.count() == 0) {
+ if (ci.size() == 0) {
it1 = cache.erase(it1);
} else {
++it1;
@@ -840,8 +840,8 @@ void QCompleterPrivate::setCurrentIndex(QModelIndex index, bool select)
void QCompleterPrivate::_q_completionSelected(const QItemSelection& selection)
{
QModelIndex index;
- if (!selection.indexes().isEmpty())
- index = selection.indexes().first();
+ if (const auto indexes = selection.indexes(); !indexes.isEmpty())
+ index = indexes.first();
_q_complete(index, true);
}
@@ -1207,50 +1207,55 @@ Qt::MatchFlags QCompleter::filterMode() const
*/
void QCompleter::setPopup(QAbstractItemView *popup)
{
+ Q_ASSERT(popup);
Q_D(QCompleter);
- Q_ASSERT(popup != nullptr);
+ if (popup == d->popup)
+ return;
+
+ // Remember existing widget's focus policy, default to NoFocus
+ const Qt::FocusPolicy origPolicy = d->widget ? d->widget->focusPolicy()
+ : Qt::NoFocus;
+
+ // If popup existed already, disconnect signals and delete object
if (d->popup) {
QObject::disconnect(d->popup->selectionModel(), nullptr, this, nullptr);
QObject::disconnect(d->popup, nullptr, this, nullptr);
- }
- if (d->popup != popup)
delete d->popup;
- if (popup->model() != d->proxy)
- popup->setModel(d->proxy);
- popup->hide();
+ }
- Qt::FocusPolicy origPolicy = Qt::NoFocus;
- if (d->widget)
- origPolicy = d->widget->focusPolicy();
+ // Assign new object, set model and hide
+ d->popup = popup;
+ if (d->popup->model() != d->proxy)
+ d->popup->setModel(d->proxy);
+ d->popup->hide();
// Mark the widget window as a popup, so that if the last non-popup window is closed by the
// user, the application should not be prevented from exiting. It needs to be set explicitly via
// setWindowFlag(), because passing the flag via setParent(parent, windowFlags) does not call
// QWidgetPrivate::adjustQuitOnCloseAttribute(), and causes an application not to exit if the
// popup ends up being the last window.
- popup->setParent(nullptr);
- popup->setWindowFlag(Qt::Popup);
- popup->setFocusPolicy(Qt::NoFocus);
+ d->popup->setParent(nullptr);
+ d->popup->setWindowFlag(Qt::Popup);
+ d->popup->setFocusPolicy(Qt::NoFocus);
if (d->widget)
d->widget->setFocusPolicy(origPolicy);
- popup->setFocusProxy(d->widget);
- popup->installEventFilter(this);
- popup->setItemDelegate(new QCompleterItemDelegate(popup));
+ d->popup->setFocusProxy(d->widget);
+ d->popup->installEventFilter(this);
+ d->popup->setItemDelegate(new QCompleterItemDelegate(d->popup));
#if QT_CONFIG(listview)
- if (QListView *listView = qobject_cast<QListView *>(popup)) {
+ if (QListView *listView = qobject_cast<QListView *>(d->popup)) {
listView->setModelColumn(d->column);
}
#endif
- QObject::connect(popup, SIGNAL(clicked(QModelIndex)),
+ QObject::connect(d->popup, SIGNAL(clicked(QModelIndex)),
this, SLOT(_q_complete(QModelIndex)));
QObject::connect(this, SIGNAL(activated(QModelIndex)),
- popup, SLOT(hide()));
+ d->popup, SLOT(hide()));
- QObject::connect(popup->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
+ QObject::connect(d->popup->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
this, SLOT(_q_completionSelected(QItemSelection)));
- d->popup = popup;
}
/*!
@@ -1811,7 +1816,7 @@ QString QCompleter::pathFromIndex(const QModelIndex& index) const
} while (idx.isValid());
#if !defined(Q_OS_WIN)
- if (list.count() == 1) // only the separator or some other text
+ if (list.size() == 1) // only the separator or some other text
return list[0];
list[0].clear() ; // the join below will provide the separator
#endif