Commit e666da62 authored by Nikolai Kosjar's avatar Nikolai Kosjar

Locator: Refactor out filter_helper for tests

...and rename it to runSearch.

Change-Id: I12482b62751a234982f41cafb7e63a641012bc30
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
parent d45b6d78
...@@ -13,7 +13,8 @@ HEADERS += locatorplugin.h \ ...@@ -13,7 +13,8 @@ HEADERS += locatorplugin.h \
locatormanager.h \ locatormanager.h \
basefilefilter.h \ basefilefilter.h \
locator_global.h \ locator_global.h \
executefilter.h executefilter.h \
locatorsearchutils.h
SOURCES += locatorplugin.cpp \ SOURCES += locatorplugin.cpp \
commandlocator.cpp \ commandlocator.cpp \
locatorwidget.cpp \ locatorwidget.cpp \
...@@ -25,7 +26,8 @@ SOURCES += locatorplugin.cpp \ ...@@ -25,7 +26,8 @@ SOURCES += locatorplugin.cpp \
locatormanager.cpp \ locatormanager.cpp \
basefilefilter.cpp \ basefilefilter.cpp \
ilocatorfilter.cpp \ ilocatorfilter.cpp \
executefilter.cpp executefilter.cpp \
locatorsearchutils.cpp
FORMS += settingspage.ui \ FORMS += settingspage.ui \
filesystemfilter.ui \ filesystemfilter.ui \
......
...@@ -39,6 +39,8 @@ QtcPlugin { ...@@ -39,6 +39,8 @@ QtcPlugin {
"locatormanager.h", "locatormanager.h",
"locatorplugin.cpp", "locatorplugin.cpp",
"locatorplugin.h", "locatorplugin.h",
"locatorsearchutils.cpp",
"locatorsearchutils.h",
"locatorwidget.cpp", "locatorwidget.cpp",
"locatorwidget.h", "locatorwidget.h",
"opendocumentsfilter.cpp", "opendocumentsfilter.cpp",
......
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "locatorsearchutils.h"
#include <QSet>
#include <QString>
#include <QVariant>
namespace Locator {
uint qHash(const Locator::FilterEntry &entry)
{
if (entry.internalData.canConvert(QVariant::String))
return QT_PREPEND_NAMESPACE(qHash)(entry.internalData.toString());
return QT_PREPEND_NAMESPACE(qHash)(entry.internalData.constData());
}
} // namespace Locator
void Locator::Internal::runSearch(QFutureInterface<Locator::FilterEntry> &entries,
QList<ILocatorFilter *> filters, QString searchText)
{
QSet<FilterEntry> alreadyAdded;
const bool checkDuplicates = (filters.size() > 1);
foreach (ILocatorFilter *filter, filters) {
if (entries.isCanceled())
break;
foreach (const FilterEntry &entry, filter->matchesFor(entries, searchText)) {
if (checkDuplicates && alreadyAdded.contains(entry))
continue;
entries.reportResult(entry);
if (checkDuplicates)
alreadyAdded.insert(entry);
}
}
}
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef LOCATORSEARCHUTILS_H
#define LOCATORSEARCHUTILS_H
#include "locator_global.h"
#include "ilocatorfilter.h"
namespace Locator {
namespace Internal {
void LOCATOR_EXPORT runSearch(QFutureInterface<Locator::FilterEntry> &entries,
QList<ILocatorFilter *> filters,
QString searchText);
} // namespace Internal
} // namespace Locator
#endif // LOCATORSEARCHUTILS_H
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "locatorwidget.h" #include "locatorwidget.h"
#include "locatorplugin.h" #include "locatorplugin.h"
#include "locatorconstants.h" #include "locatorconstants.h"
#include "locatorsearchutils.h"
#include "ilocatorfilter.h" #include "ilocatorfilter.h"
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
...@@ -130,12 +131,7 @@ private: ...@@ -130,12 +131,7 @@ private:
} // namespace Internal } // namespace Internal
uint qHash(const FilterEntry &entry)
{
if (entry.internalData.canConvert(QVariant::String))
return QT_PREPEND_NAMESPACE(qHash)(entry.internalData.toString());
return QT_PREPEND_NAMESPACE(qHash)(entry.internalData.constData());
}
} // namespace Locator } // namespace Locator
...@@ -491,24 +487,6 @@ QList<ILocatorFilter*> LocatorWidget::filtersFor(const QString &text, QString &s ...@@ -491,24 +487,6 @@ QList<ILocatorFilter*> LocatorWidget::filtersFor(const QString &text, QString &s
return activeFilters; return activeFilters;
} }
static void filter_helper(QFutureInterface<Locator::FilterEntry> &entries, QList<ILocatorFilter *> filters, QString searchText)
{
QSet<FilterEntry> alreadyAdded;
const bool checkDuplicates = (filters.size() > 1);
foreach (ILocatorFilter *filter, filters) {
if (entries.isCanceled())
break;
foreach (const FilterEntry &entry, filter->matchesFor(entries, searchText)) {
if (checkDuplicates && alreadyAdded.contains(entry))
continue;
entries.reportResult(entry);
if (checkDuplicates)
alreadyAdded.insert(entry);
}
}
}
void LocatorWidget::updateCompletionList(const QString &text) void LocatorWidget::updateCompletionList(const QString &text)
{ {
m_updateRequested = true; m_updateRequested = true;
...@@ -519,7 +497,7 @@ void LocatorWidget::updateCompletionList(const QString &text) ...@@ -519,7 +497,7 @@ void LocatorWidget::updateCompletionList(const QString &text)
m_entriesWatcher->future().cancel(); m_entriesWatcher->future().cancel();
m_entriesWatcher->future().waitForFinished(); m_entriesWatcher->future().waitForFinished();
QFuture<FilterEntry> future = QtConcurrent::run(filter_helper, filters, searchText); QFuture<FilterEntry> future = QtConcurrent::run(runSearch, filters, searchText);
m_entriesWatcher->setFuture(future); m_entriesWatcher->setFuture(future);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment