aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2017-06-19 12:16:56 +0200
committerEike Ziller <eike.ziller@qt.io>2017-06-23 11:36:12 +0000
commita9eb1d39c8bfd4133da030bc9c0a4b9c9cbee476 (patch)
tree018d24e14993b0e1ce93c7619af4f6c209159a5d
parentfc8dee46752494791c489173ffd04f5ef31a7dfa (diff)
Locator: Reduce interdependency between item list and input field
By not getting the currently selected row at arbitrary times. This introduces a slight behavior change for an improbable edge case, which could be viewed as an improvement: If there are multiple filters active, and the first, higher priority one could finished much faster than the second, lower priority one, the following sequence Wait for results from first filter Press return Move up or down Second filter finishes/cancels without this patch did not select the item where you pressed return, but the item that was selected when the second filter finished. Change-Id: Iba2c72e2494824de961782ba3fe0bb1041072614 Reviewed-by: David Schulz <david.schulz@qt.io>
-rw-r--r--src/plugins/coreplugin/locator/locatorwidget.cpp32
-rw-r--r--src/plugins/coreplugin/locator/locatorwidget.h6
2 files changed, 22 insertions, 16 deletions
diff --git a/src/plugins/coreplugin/locator/locatorwidget.cpp b/src/plugins/coreplugin/locator/locatorwidget.cpp
index 30981372d8..84c1c73ce0 100644
--- a/src/plugins/coreplugin/locator/locatorwidget.cpp
+++ b/src/plugins/coreplugin/locator/locatorwidget.cpp
@@ -42,6 +42,7 @@
#include <utils/asconst.h>
#include <utils/fancylineedit.h>
#include <utils/hostosinfo.h>
+#include <utils/itemviews.h>
#include <utils/progressindicator.h>
#include <utils/qtcassert.h>
#include <utils/runextensions.h>
@@ -96,7 +97,7 @@ private:
QColor mBackgroundColor;
};
-class CompletionList : public QTreeView
+class CompletionList : public Utils::TreeView
{
public:
CompletionList(QWidget *parent = 0);
@@ -229,7 +230,7 @@ void LocatorModel::addEntries(const QList<LocatorFilterEntry> &entries)
// =========== CompletionList ===========
CompletionList::CompletionList(QWidget *parent)
- : QTreeView(parent)
+ : Utils::TreeView(parent)
{
setItemDelegate(new SearchResultTreeItemDelegate(0, this));
setRootIsDecorated(false);
@@ -321,7 +322,7 @@ LocatorWidget::LocatorWidget(Locator *locator) :
connect(m_fileLineEdit, &QLineEdit::textChanged,
this, &LocatorWidget::showPopup);
connect(m_completionList, &QAbstractItemView::activated,
- this, &LocatorWidget::scheduleAcceptCurrentEntry);
+ this, &LocatorWidget::scheduleAcceptEntry);
m_entriesWatcher = new QFutureWatcher<LocatorFilterEntry>(this);
connect(m_entriesWatcher, &QFutureWatcher<LocatorFilterEntry>::resultsReadyAt,
@@ -415,7 +416,7 @@ bool LocatorWidget::eventFilter(QObject *obj, QEvent *event)
break;
case Qt::Key_Enter:
case Qt::Key_Return:
- scheduleAcceptCurrentEntry();
+ QApplication::sendEvent(m_completionList, event);
return true;
case Qt::Key_Escape:
m_completionList->hide();
@@ -599,8 +600,9 @@ void LocatorWidget::handleSearchFinished()
m_showProgressTimer.stop();
setProgressIndicatorVisible(false);
m_updateRequested = false;
- if (m_acceptRequested) {
- acceptCurrentEntry();
+ if (m_rowRequestedForAccept >= 0) {
+ acceptEntry(m_rowRequestedForAccept);
+ m_rowRequestedForAccept = -1;
return;
}
if (m_entriesWatcher->future().isCanceled()) {
@@ -616,25 +618,26 @@ void LocatorWidget::handleSearchFinished()
}
}
-void LocatorWidget::scheduleAcceptCurrentEntry()
+void LocatorWidget::scheduleAcceptEntry(const QModelIndex &index)
{
if (m_updateRequested) {
// don't just accept the selected entry, since the list is not up to date
// accept will be called after the update finished
- m_acceptRequested = true;
+ m_rowRequestedForAccept = index.row();
// do not wait for the rest of the search to finish
m_entriesWatcher->future().cancel();
} else {
- acceptCurrentEntry();
+ acceptEntry(index.row());
}
}
-void LocatorWidget::acceptCurrentEntry()
+void LocatorWidget::acceptEntry(int row)
{
- m_acceptRequested = false;
if (!m_completionList->isVisible())
return;
- const QModelIndex index = m_completionList->currentIndex();
+ if (row >= m_locatorModel->rowCount())
+ return;
+ const QModelIndex index = m_locatorModel->index(row, 0);
if (!index.isValid())
return;
const LocatorFilterEntry entry = m_locatorModel->data(index, ItemDataRoles::ResultItemRole).value<LocatorFilterEntry>();
@@ -689,8 +692,11 @@ void LocatorWidget::addSearchResults(int firstIndex, int endIndex)
for (int i = firstIndex; i < endIndex; ++i)
entries.append(m_entriesWatcher->resultAt(i));
m_locatorModel->addEntries(entries);
- if (selectFirst)
+ if (selectFirst) {
m_completionList->setCurrentIndex(m_locatorModel->index(0, 0));
+ if (m_rowRequestedForAccept >= 0)
+ m_rowRequestedForAccept = 0;
+ }
}
} // namespace Internal
diff --git a/src/plugins/coreplugin/locator/locatorwidget.h b/src/plugins/coreplugin/locator/locatorwidget.h
index 83a45e1031..8a053e135f 100644
--- a/src/plugins/coreplugin/locator/locatorwidget.h
+++ b/src/plugins/coreplugin/locator/locatorwidget.h
@@ -64,11 +64,11 @@ public:
private:
void showPopup();
void showPopupNow();
- void acceptCurrentEntry();
+ void acceptEntry(int row);
void showConfigureDialog();
void addSearchResults(int firstIndex, int endIndex);
void handleSearchFinished();
- void scheduleAcceptCurrentEntry();
+ void scheduleAcceptEntry(const QModelIndex &index);
void setFocusToCurrentMode();
bool eventFilter(QObject *obj, QEvent *event);
@@ -90,8 +90,8 @@ private:
QString m_requestedCompletionText;
bool m_needsClearResult = true;
bool m_updateRequested = false;
- bool m_acceptRequested = false;
bool m_possibleToolTipRequest = false;
+ int m_rowRequestedForAccept = -1;
QWidget *m_progressIndicator;
QPointer<QWidget> m_window;
QTimer m_showProgressTimer;