forked from qt-creator/qt-creator
Locator filters: Fix various thread-safety issues
Introduces a "prepareSearch" method for locator filters that is called on the UI thread prior to the threaded matching. Fix various small thread-safety issues in the various filters. Change-Id: If5ae7d205e126d367420936a93f8d9a84496edb8 Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
@@ -59,16 +59,19 @@ HelpIndexFilter::~HelpIndexFilter()
|
||||
{
|
||||
}
|
||||
|
||||
void HelpIndexFilter::prepareSearch(const QString &entry)
|
||||
{
|
||||
if (entry.length() < 2)
|
||||
m_keywords = Core::HelpManager::findKeywords(entry, caseSensitivity(entry), 200);
|
||||
else
|
||||
m_keywords = Core::HelpManager::findKeywords(entry, caseSensitivity(entry));
|
||||
}
|
||||
|
||||
QList<LocatorFilterEntry> HelpIndexFilter::matchesFor(QFutureInterface<LocatorFilterEntry> &future, const QString &entry)
|
||||
{
|
||||
QStringList keywords;
|
||||
if (entry.length() < 2)
|
||||
keywords = Core::HelpManager::findKeywords(entry, caseSensitivity(entry), 200);
|
||||
else
|
||||
keywords = Core::HelpManager::findKeywords(entry, caseSensitivity(entry));
|
||||
|
||||
Q_UNUSED(entry) // search is already done in the GUI thread in prepareSearch
|
||||
QList<LocatorFilterEntry> entries;
|
||||
foreach (const QString &keyword, keywords) {
|
||||
foreach (const QString &keyword, m_keywords) {
|
||||
if (future.isCanceled())
|
||||
break;
|
||||
entries.append(LocatorFilterEntry(this, keyword, QVariant(), m_icon));
|
||||
|
||||
@@ -46,6 +46,7 @@ public:
|
||||
~HelpIndexFilter();
|
||||
|
||||
// ILocatorFilter
|
||||
void prepareSearch(const QString &entry);
|
||||
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future, const QString &entry);
|
||||
void accept(Core::LocatorFilterEntry selection) const;
|
||||
void refresh(QFutureInterface<void> &future);
|
||||
@@ -55,6 +56,7 @@ signals:
|
||||
|
||||
private:
|
||||
QIcon m_icon;
|
||||
QStringList m_keywords;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
#include "remotehelpfilter.h"
|
||||
|
||||
#include <QMutexLocker>
|
||||
#include <QUrl>
|
||||
|
||||
namespace Help {
|
||||
@@ -99,7 +100,7 @@ RemoteHelpFilter::~RemoteHelpFilter()
|
||||
QList<Core::LocatorFilterEntry> RemoteHelpFilter::matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future, const QString &pattern)
|
||||
{
|
||||
QList<Core::LocatorFilterEntry> entries;
|
||||
foreach (const QString &url, m_remoteUrls) {
|
||||
foreach (const QString &url, remoteUrls()) {
|
||||
if (future.isCanceled())
|
||||
break;
|
||||
|
||||
@@ -156,6 +157,7 @@ bool RemoteHelpFilter::openConfigDialog(QWidget *parent, bool &needsRefresh)
|
||||
Q_UNUSED(needsRefresh)
|
||||
RemoteFilterOptions optionsDialog(this, parent);
|
||||
if (optionsDialog.exec() == QDialog::Accepted) {
|
||||
QMutexLocker lock(&m_mutex); Q_UNUSED(lock)
|
||||
m_remoteUrls.clear();
|
||||
setIncludedByDefault(!optionsDialog.m_ui.limitCheck->isChecked());
|
||||
setShortcutString(optionsDialog.m_ui.shortcutEdit->text().trimmed());
|
||||
@@ -166,5 +168,11 @@ bool RemoteHelpFilter::openConfigDialog(QWidget *parent, bool &needsRefresh)
|
||||
return true;
|
||||
}
|
||||
|
||||
QStringList RemoteHelpFilter::remoteUrls() const
|
||||
{
|
||||
QMutexLocker lock(&m_mutex); Q_UNUSED(lock)
|
||||
return m_remoteUrls;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Help
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include <coreplugin/locator/ilocatorfilter.h>
|
||||
|
||||
#include <QIcon>
|
||||
#include <QMutex>
|
||||
|
||||
namespace Help {
|
||||
namespace Internal {
|
||||
@@ -54,7 +55,7 @@ public:
|
||||
bool restoreState(const QByteArray &state);
|
||||
bool openConfigDialog(QWidget *parent, bool &needsRefresh);
|
||||
|
||||
QStringList remoteUrls() const { return m_remoteUrls; }
|
||||
QStringList remoteUrls() const;
|
||||
|
||||
signals:
|
||||
void linkActivated(const QUrl &url) const;
|
||||
@@ -62,6 +63,7 @@ signals:
|
||||
private:
|
||||
QIcon m_icon;
|
||||
QStringList m_remoteUrls;
|
||||
mutable QMutex m_mutex;
|
||||
};
|
||||
|
||||
class RemoteFilterOptions : public QDialog
|
||||
|
||||
Reference in New Issue
Block a user