summaryrefslogtreecommitdiffstats
path: root/src/widgets/util
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2019-05-27 15:34:10 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2019-05-27 15:34:10 +0200
commit518cf3312c101ea1c5ae5199611ebda46a74dadd (patch)
treefe580d423d8938caad9d6705c7ef9da13d2d8e14 /src/widgets/util
parent59937de098dd86472e73146bd0c84e980022e24d (diff)
parent65cfac73bd1c09eafadf57a3b7161f52b186c37d (diff)
Merge remote-tracking branch 'origin/5.13' into dev
Diffstat (limited to 'src/widgets/util')
-rw-r--r--src/widgets/util/qcompleter.cpp40
1 files changed, 35 insertions, 5 deletions
diff --git a/src/widgets/util/qcompleter.cpp b/src/widgets/util/qcompleter.cpp
index 0daa4a4b41..e41f7e7573 100644
--- a/src/widgets/util/qcompleter.cpp
+++ b/src/widgets/util/qcompleter.cpp
@@ -976,18 +976,48 @@ void QCompleterPrivate::showPopup(const QRect& rect)
popup->show();
}
+#if QT_CONFIG(filesystemmodel)
+static bool isRoot(const QFileSystemModel *model, const QString &path)
+{
+ const auto index = model->index(path);
+ return index.isValid() && model->fileInfo(index).isRoot();
+}
+
+static bool completeOnLoaded(const QFileSystemModel *model,
+ const QString &nativePrefix,
+ const QString &path,
+ Qt::CaseSensitivity caseSensitivity)
+{
+ const auto pathSize = path.size();
+ const auto prefixSize = nativePrefix.size();
+ if (prefixSize < pathSize)
+ return false;
+ const QString prefix = QDir::fromNativeSeparators(nativePrefix);
+ if (prefixSize == pathSize)
+ return path.compare(prefix, caseSensitivity) == 0 && isRoot(model, path);
+ // The user is typing something within that directory and is not in a subdirectory yet.
+ const auto separator = QLatin1Char('/');
+ return prefix.startsWith(path, caseSensitivity) && prefix.at(pathSize) == separator
+ && !prefix.rightRef(prefixSize - pathSize - 1).contains(separator);
+}
+
void QCompleterPrivate::_q_fileSystemModelDirectoryLoaded(const QString &path)
{
Q_Q(QCompleter);
// Slot called when QFileSystemModel has finished loading.
// If we hide the popup because there was no match because the model was not loaded yet,
- // we re-start the completion when we get the results
- if (hiddenBecauseNoMatch
- && prefix.startsWith(path) && prefix != (path + QLatin1Char('/'))
- && widget) {
- q->complete();
+ // we re-start the completion when we get the results (unless triggered by
+ // something else, see QTBUG-14292).
+ if (hiddenBecauseNoMatch && widget) {
+ if (auto model = qobject_cast<const QFileSystemModel *>(proxy->sourceModel())) {
+ if (completeOnLoaded(model, prefix, path, cs))
+ q->complete();
+ }
}
}
+#else // QT_CONFIG(filesystemmodel)
+void QCompleterPrivate::_q_fileSystemModelDirectoryLoaded(const QString &) {}
+#endif
/*!
Constructs a completer object with the given \a parent.