forked from qt-creator/qt-creator
CppTools: Introduce LocatorData
Until now the locator filters CppLocatorFilter, CppClassesFilter and CppFunctionsFilter used unnecessarily their own SearchSymbols instance. The results were also saved separately, which was unfavorable since e.g. the functions and classes data could be shared. Starting with this patch an instance of LocatorData will serve all mentioned filters. This saves about 20MB of memory after indexing the Qt Creator project. Change-Id: I8a34b67eb9fe0e5c68ba6e7c8f576389c78efc6f Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com> Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
committed by
Erik Verbruggen
parent
de1ec22424
commit
fc731a3a67
@@ -32,21 +32,24 @@
|
|||||||
using namespace CppTools;
|
using namespace CppTools;
|
||||||
using namespace CppTools::Internal;
|
using namespace CppTools::Internal;
|
||||||
|
|
||||||
CppClassesFilter::CppClassesFilter(CppModelManager *manager)
|
CppClassesFilter::CppClassesFilter(CppLocatorData *locatorData)
|
||||||
: CppLocatorFilter(manager)
|
: CppLocatorFilter(locatorData)
|
||||||
{
|
{
|
||||||
setId("Classes");
|
setId("Classes");
|
||||||
setShortcutString(QLatin1String("c"));
|
setShortcutString(QLatin1String("c"));
|
||||||
setIncludedByDefault(false);
|
setIncludedByDefault(false);
|
||||||
setDisplayName(tr("C++ Classes"));
|
setDisplayName(tr("C++ Classes"));
|
||||||
|
|
||||||
search.setSymbolsToSearchFor(SymbolSearcher::Classes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CppClassesFilter::~CppClassesFilter()
|
CppClassesFilter::~CppClassesFilter()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QList<CppTools::ModelItemInfo> > CppClassesFilter::itemsToMatchUserInputAgainst() const
|
||||||
|
{
|
||||||
|
return QList<QList<CppTools::ModelItemInfo> >() << m_data->classes();
|
||||||
|
}
|
||||||
|
|
||||||
Locator::FilterEntry CppClassesFilter::filterEntryFromModelItemInfo(const ModelItemInfo &info)
|
Locator::FilterEntry CppClassesFilter::filterEntryFromModelItemInfo(const ModelItemInfo &info)
|
||||||
{
|
{
|
||||||
const QVariant id = qVariantFromValue(info);
|
const QVariant id = qVariantFromValue(info);
|
||||||
|
@@ -31,6 +31,7 @@
|
|||||||
#define CPPCLASSESFILTER_H
|
#define CPPCLASSESFILTER_H
|
||||||
|
|
||||||
#include "cpptools_global.h"
|
#include "cpptools_global.h"
|
||||||
|
#include "cpplocatordata.h"
|
||||||
#include "cpplocatorfilter.h"
|
#include "cpplocatorfilter.h"
|
||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
@@ -40,10 +41,11 @@ class CPPTOOLS_EXPORT CppClassesFilter : public Internal::CppLocatorFilter
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CppClassesFilter(Internal::CppModelManager *manager);
|
CppClassesFilter(Internal::CppLocatorData *locatorData);
|
||||||
~CppClassesFilter();
|
~CppClassesFilter();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QList<QList<CppTools::ModelItemInfo> > itemsToMatchUserInputAgainst() const;
|
||||||
Locator::FilterEntry filterEntryFromModelItemInfo(const ModelItemInfo &info);
|
Locator::FilterEntry filterEntryFromModelItemInfo(const ModelItemInfo &info);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -31,21 +31,24 @@
|
|||||||
|
|
||||||
using namespace CppTools::Internal;
|
using namespace CppTools::Internal;
|
||||||
|
|
||||||
CppFunctionsFilter::CppFunctionsFilter(CppModelManager *manager)
|
CppFunctionsFilter::CppFunctionsFilter(CppLocatorData *locatorData)
|
||||||
: CppLocatorFilter(manager)
|
: CppLocatorFilter(locatorData)
|
||||||
{
|
{
|
||||||
setId("Methods");
|
setId("Methods");
|
||||||
setDisplayName(tr("C++ Methods and Functions"));
|
setDisplayName(tr("C++ Methods and Functions"));
|
||||||
setShortcutString(QString(QLatin1Char('m')));
|
setShortcutString(QString(QLatin1Char('m')));
|
||||||
setIncludedByDefault(false);
|
setIncludedByDefault(false);
|
||||||
|
|
||||||
search.setSymbolsToSearchFor(SymbolSearcher::Functions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CppFunctionsFilter::~CppFunctionsFilter()
|
CppFunctionsFilter::~CppFunctionsFilter()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QList<CppTools::ModelItemInfo> > CppFunctionsFilter::itemsToMatchUserInputAgainst() const
|
||||||
|
{
|
||||||
|
return QList<QList<CppTools::ModelItemInfo> >() << m_data->functions();
|
||||||
|
}
|
||||||
|
|
||||||
Locator::FilterEntry CppFunctionsFilter::filterEntryFromModelItemInfo(const CppTools::ModelItemInfo &info)
|
Locator::FilterEntry CppFunctionsFilter::filterEntryFromModelItemInfo(const CppTools::ModelItemInfo &info)
|
||||||
{
|
{
|
||||||
const QVariant id = qVariantFromValue(info);
|
const QVariant id = qVariantFromValue(info);
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
#ifndef CPPFUNCTIONSFILTER_H
|
#ifndef CPPFUNCTIONSFILTER_H
|
||||||
#define CPPFUNCTIONSFILTER_H
|
#define CPPFUNCTIONSFILTER_H
|
||||||
|
|
||||||
|
#include "cpplocatordata.h"
|
||||||
#include "cpplocatorfilter.h"
|
#include "cpplocatorfilter.h"
|
||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
@@ -40,10 +41,11 @@ class CppFunctionsFilter : public CppLocatorFilter
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CppFunctionsFilter(CppModelManager *manager);
|
CppFunctionsFilter(CppLocatorData *locatorData);
|
||||||
~CppFunctionsFilter();
|
~CppFunctionsFilter();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QList<QList<ModelItemInfo> > itemsToMatchUserInputAgainst() const;
|
||||||
Locator::FilterEntry filterEntryFromModelItemInfo(const ModelItemInfo &info);
|
Locator::FilterEntry filterEntryFromModelItemInfo(const ModelItemInfo &info);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
162
src/plugins/cpptools/cpplocatordata.cpp
Normal file
162
src/plugins/cpptools/cpplocatordata.cpp
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 "cpplocatordata.h"
|
||||||
|
|
||||||
|
using namespace CppTools;
|
||||||
|
using namespace CppTools::Internal;
|
||||||
|
|
||||||
|
static const int MaxPendingDocuments = 10;
|
||||||
|
|
||||||
|
CppLocatorData::CppLocatorData(CppModelManager *modelManager)
|
||||||
|
: m_modelManager(modelManager)
|
||||||
|
, m_pendingDocumentsMutex(QMutex::Recursive)
|
||||||
|
{
|
||||||
|
m_search.setSymbolsToSearchFor(SymbolSearcher::Enums
|
||||||
|
| SymbolSearcher::Classes
|
||||||
|
| SymbolSearcher::Functions);
|
||||||
|
m_pendingDocuments.reserve(MaxPendingDocuments);
|
||||||
|
|
||||||
|
connect(m_modelManager, SIGNAL(documentUpdated(CPlusPlus::Document::Ptr)),
|
||||||
|
this, SLOT(onDocumentUpdated(CPlusPlus::Document::Ptr)));
|
||||||
|
|
||||||
|
connect(m_modelManager, SIGNAL(aboutToRemoveFiles(QStringList)),
|
||||||
|
this, SLOT(onAboutToRemoveFiles(QStringList)));
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<ModelItemInfo> CppLocatorData::enums()
|
||||||
|
{
|
||||||
|
flushPendingDocument(true);
|
||||||
|
return allModelItemInfos(m_allEnums);
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<ModelItemInfo> CppLocatorData::classes()
|
||||||
|
{
|
||||||
|
flushPendingDocument(true);
|
||||||
|
return allModelItemInfos(m_allClasses);
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<ModelItemInfo> CppLocatorData::functions()
|
||||||
|
{
|
||||||
|
flushPendingDocument(true);
|
||||||
|
return allModelItemInfos(m_allFunctions);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CppLocatorData::onDocumentUpdated(const CPlusPlus::Document::Ptr &document)
|
||||||
|
{
|
||||||
|
QMutexLocker locker(&m_pendingDocumentsMutex);
|
||||||
|
|
||||||
|
int i = 0, ei = m_pendingDocuments.size();
|
||||||
|
for (; i < ei; ++i) {
|
||||||
|
const CPlusPlus::Document::Ptr &doc = m_pendingDocuments.at(i);
|
||||||
|
if (doc->fileName() == document->fileName()
|
||||||
|
&& doc->revision() < document->revision()) {
|
||||||
|
m_pendingDocuments[i] = document;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == ei)
|
||||||
|
m_pendingDocuments.append(document);
|
||||||
|
|
||||||
|
flushPendingDocument(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CppLocatorData::onAboutToRemoveFiles(const QStringList &files)
|
||||||
|
{
|
||||||
|
QMutexLocker locker(&m_pendingDocumentsMutex);
|
||||||
|
|
||||||
|
for (int i = 0; i < m_pendingDocuments.size(); ) {
|
||||||
|
if (files.contains(m_pendingDocuments.at(i)->fileName()))
|
||||||
|
m_pendingDocuments.remove(i);
|
||||||
|
else
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (const QString &file, files) {
|
||||||
|
m_allEnums.remove(file);
|
||||||
|
m_allClasses.remove(file);
|
||||||
|
m_allFunctions.remove(file);
|
||||||
|
removeFilePath(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CppLocatorData::flushPendingDocument(bool force)
|
||||||
|
{
|
||||||
|
QMutexLocker locker(&m_pendingDocumentsMutex);
|
||||||
|
if (!force && m_pendingDocuments.size() < MaxPendingDocuments)
|
||||||
|
return;
|
||||||
|
|
||||||
|
foreach (CPlusPlus::Document::Ptr doc, m_pendingDocuments) {
|
||||||
|
const QString fileName = findOrInsertFilePath(doc->fileName());
|
||||||
|
|
||||||
|
QList<ModelItemInfo> resultsEnums;
|
||||||
|
QList<ModelItemInfo> resultsClasses;
|
||||||
|
QList<ModelItemInfo> resultsFunctions;
|
||||||
|
|
||||||
|
const int sizeHint = m_allEnums[fileName].size() + m_allClasses[fileName].size()
|
||||||
|
+ m_allFunctions[fileName].size() + 10;
|
||||||
|
const QList<ModelItemInfo> results = m_search(doc, sizeHint);
|
||||||
|
foreach (const ModelItemInfo &info, results) {
|
||||||
|
switch (info.type) {
|
||||||
|
case ModelItemInfo::Enum:
|
||||||
|
resultsEnums.append(info);
|
||||||
|
break;
|
||||||
|
case ModelItemInfo::Class:
|
||||||
|
resultsClasses.append(info);
|
||||||
|
break;
|
||||||
|
case ModelItemInfo::Method:
|
||||||
|
resultsFunctions.append(info);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_allEnums[fileName] = resultsEnums;
|
||||||
|
m_allClasses[fileName] = resultsClasses;
|
||||||
|
m_allFunctions[fileName] = resultsFunctions;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_pendingDocuments.clear();
|
||||||
|
m_pendingDocuments.reserve(MaxPendingDocuments);
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<ModelItemInfo> CppLocatorData::allModelItemInfos(const QHash<QString,
|
||||||
|
QList<ModelItemInfo> > &items) const
|
||||||
|
{
|
||||||
|
QList<ModelItemInfo> result;
|
||||||
|
QHashIterator<QString, QList<ModelItemInfo> > it(items);
|
||||||
|
while (it.hasNext()) {
|
||||||
|
it.next();
|
||||||
|
result.append(it.value());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
87
src/plugins/cpptools/cpplocatordata.h
Normal file
87
src/plugins/cpptools/cpplocatordata.h
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 CPPLOCATORDATA_H
|
||||||
|
#define CPPLOCATORDATA_H
|
||||||
|
|
||||||
|
#include <QHash>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
|
#include <cplusplus/CppDocument.h>
|
||||||
|
|
||||||
|
#include "cppmodelmanager.h"
|
||||||
|
#include "searchsymbols.h"
|
||||||
|
|
||||||
|
namespace CppTools {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
class CppLocatorData : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit CppLocatorData(CppModelManager *modelManager);
|
||||||
|
|
||||||
|
QList<ModelItemInfo> enums();
|
||||||
|
QList<ModelItemInfo> classes();
|
||||||
|
QList<ModelItemInfo> functions();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onDocumentUpdated(const CPlusPlus::Document::Ptr &document);
|
||||||
|
void onAboutToRemoveFiles(const QStringList &files);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void flushPendingDocument(bool force);
|
||||||
|
QList<ModelItemInfo> allModelItemInfos(const QHash<QString,
|
||||||
|
QList<ModelItemInfo> > &items) const;
|
||||||
|
|
||||||
|
QString findOrInsertFilePath(const QString &path)
|
||||||
|
{ return *m_filePaths.insert(path); }
|
||||||
|
|
||||||
|
void removeFilePath(const QString &path)
|
||||||
|
{ m_filePaths.remove(path); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
CppModelManager *m_modelManager;
|
||||||
|
|
||||||
|
QSet<QString> m_filePaths; // Used to avoid QString duplication
|
||||||
|
|
||||||
|
SearchSymbols m_search;
|
||||||
|
QHash<QString, QList<ModelItemInfo> > m_allEnums;
|
||||||
|
QHash<QString, QList<ModelItemInfo> > m_allClasses;
|
||||||
|
QHash<QString, QList<ModelItemInfo> > m_allFunctions;
|
||||||
|
|
||||||
|
mutable QMutex m_pendingDocumentsMutex;
|
||||||
|
QVector<CPlusPlus::Document::Ptr> m_pendingDocuments;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace CppTools
|
||||||
|
|
||||||
|
#endif // CPPLOCATORDATA_H
|
@@ -36,76 +36,17 @@ using namespace CppTools::Internal;
|
|||||||
|
|
||||||
static const int MaxPendingDocuments = 10;
|
static const int MaxPendingDocuments = 10;
|
||||||
|
|
||||||
CppLocatorFilter::CppLocatorFilter(CppModelManager *manager)
|
CppLocatorFilter::CppLocatorFilter(CppLocatorData *locatorData)
|
||||||
: m_manager(manager)
|
: m_data(locatorData)
|
||||||
, m_pendingDocumentsMutex(QMutex::Recursive)
|
|
||||||
{
|
{
|
||||||
setId("Classes and Methods");
|
setId("Classes and Methods");
|
||||||
setDisplayName(tr("C++ Classes and Methods"));
|
setDisplayName(tr("C++ Classes and Methods"));
|
||||||
setShortcutString(QString(QLatin1Char(':')));
|
setShortcutString(QString(QLatin1Char(':')));
|
||||||
setIncludedByDefault(false);
|
setIncludedByDefault(false);
|
||||||
|
|
||||||
m_pendingDocuments.reserve(MaxPendingDocuments);
|
|
||||||
|
|
||||||
connect(manager, SIGNAL(documentUpdated(CPlusPlus::Document::Ptr)),
|
|
||||||
this, SLOT(onDocumentUpdated(CPlusPlus::Document::Ptr)));
|
|
||||||
|
|
||||||
connect(manager, SIGNAL(aboutToRemoveFiles(QStringList)),
|
|
||||||
this, SLOT(onAboutToRemoveFiles(QStringList)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CppLocatorFilter::~CppLocatorFilter()
|
CppLocatorFilter::~CppLocatorFilter()
|
||||||
{ }
|
|
||||||
|
|
||||||
|
|
||||||
void CppLocatorFilter::flushPendingDocument(bool force)
|
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&m_pendingDocumentsMutex);
|
|
||||||
if (!force && m_pendingDocuments.size() < MaxPendingDocuments)
|
|
||||||
return;
|
|
||||||
|
|
||||||
foreach (CPlusPlus::Document::Ptr doc, m_pendingDocuments) {
|
|
||||||
QList<ModelItemInfo> &results = m_searchList[doc->fileName()];
|
|
||||||
results = search(doc, results.size() + 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_pendingDocuments.clear();
|
|
||||||
m_pendingDocuments.reserve(MaxPendingDocuments);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CppLocatorFilter::onDocumentUpdated(CPlusPlus::Document::Ptr updatedDoc)
|
|
||||||
{
|
|
||||||
QMutexLocker locker(&m_pendingDocumentsMutex);
|
|
||||||
|
|
||||||
int i = 0, ei = m_pendingDocuments.size();
|
|
||||||
for (; i < ei; ++i) {
|
|
||||||
const CPlusPlus::Document::Ptr &doc = m_pendingDocuments.at(i);
|
|
||||||
if (doc->fileName() == updatedDoc->fileName()
|
|
||||||
&& doc->revision() < updatedDoc->revision()) {
|
|
||||||
m_pendingDocuments[i] = updatedDoc;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i == ei)
|
|
||||||
m_pendingDocuments.append(updatedDoc);
|
|
||||||
|
|
||||||
flushPendingDocument(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CppLocatorFilter::onAboutToRemoveFiles(const QStringList &files)
|
|
||||||
{
|
|
||||||
QMutexLocker locker(&m_pendingDocumentsMutex);
|
|
||||||
|
|
||||||
for (int i = 0; i < m_pendingDocuments.size(); ) {
|
|
||||||
if (files.contains(m_pendingDocuments.at(i)->fileName()))
|
|
||||||
m_pendingDocuments.remove(i);
|
|
||||||
else
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (const QString &file, files)
|
|
||||||
m_searchList.remove(file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Locator::FilterEntry CppLocatorFilter::filterEntryFromModelItemInfo(const CppTools::ModelItemInfo &info)
|
Locator::FilterEntry CppLocatorFilter::filterEntryFromModelItemInfo(const CppTools::ModelItemInfo &info)
|
||||||
@@ -124,6 +65,14 @@ void CppLocatorFilter::refresh(QFutureInterface<void> &future)
|
|||||||
Q_UNUSED(future)
|
Q_UNUSED(future)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QList<CppTools::ModelItemInfo> > CppLocatorFilter::itemsToMatchUserInputAgainst() const
|
||||||
|
{
|
||||||
|
return QList<QList<CppTools::ModelItemInfo> >()
|
||||||
|
<< m_data->classes()
|
||||||
|
<< m_data->functions()
|
||||||
|
<< m_data->enums();
|
||||||
|
}
|
||||||
|
|
||||||
static bool compareLexigraphically(const Locator::FilterEntry &a,
|
static bool compareLexigraphically(const Locator::FilterEntry &a,
|
||||||
const Locator::FilterEntry &b)
|
const Locator::FilterEntry &b)
|
||||||
{
|
{
|
||||||
@@ -132,8 +81,6 @@ static bool compareLexigraphically(const Locator::FilterEntry &a,
|
|||||||
|
|
||||||
QList<Locator::FilterEntry> CppLocatorFilter::matchesFor(QFutureInterface<Locator::FilterEntry> &future, const QString &origEntry)
|
QList<Locator::FilterEntry> CppLocatorFilter::matchesFor(QFutureInterface<Locator::FilterEntry> &future, const QString &origEntry)
|
||||||
{
|
{
|
||||||
flushPendingDocument(true);
|
|
||||||
|
|
||||||
QString entry = trimWildcards(origEntry);
|
QString entry = trimWildcards(origEntry);
|
||||||
QList<Locator::FilterEntry> goodEntries;
|
QList<Locator::FilterEntry> goodEntries;
|
||||||
QList<Locator::FilterEntry> betterEntries;
|
QList<Locator::FilterEntry> betterEntries;
|
||||||
@@ -146,18 +93,14 @@ QList<Locator::FilterEntry> CppLocatorFilter::matchesFor(QFutureInterface<Locato
|
|||||||
bool hasColonColon = entry.contains(QLatin1String("::"));
|
bool hasColonColon = entry.contains(QLatin1String("::"));
|
||||||
const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry);
|
const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry);
|
||||||
|
|
||||||
QHashIterator<QString, QList<ModelItemInfo> > it(m_searchList);
|
const QList<QList<CppTools::ModelItemInfo> > itemLists = itemsToMatchUserInputAgainst();
|
||||||
while (it.hasNext()) {
|
foreach (const QList<CppTools::ModelItemInfo> &items, itemLists) {
|
||||||
if (future.isCanceled())
|
|
||||||
break;
|
|
||||||
|
|
||||||
it.next();
|
|
||||||
|
|
||||||
const QList<ModelItemInfo> items = it.value();
|
|
||||||
foreach (const ModelItemInfo &info, items) {
|
foreach (const ModelItemInfo &info, items) {
|
||||||
|
if (future.isCanceled())
|
||||||
|
break;
|
||||||
const QString matchString = hasColonColon ? info.scopedSymbolName() : info.symbolName;
|
const QString matchString = hasColonColon ? info.scopedSymbolName() : info.symbolName;
|
||||||
if ((hasWildcard && regexp.exactMatch(matchString))
|
if ((hasWildcard && regexp.exactMatch(matchString))
|
||||||
|| (!hasWildcard && matcher.indexIn(matchString) != -1)) {
|
|| (!hasWildcard && matcher.indexIn(matchString) != -1)) {
|
||||||
const Locator::FilterEntry filterEntry = filterEntryFromModelItemInfo(info);
|
const Locator::FilterEntry filterEntry = filterEntryFromModelItemInfo(info);
|
||||||
if (matchString.startsWith(entry, caseSensitivityForPrefix))
|
if (matchString.startsWith(entry, caseSensitivityForPrefix))
|
||||||
betterEntries.append(filterEntry);
|
betterEntries.append(filterEntry);
|
||||||
@@ -168,9 +111,9 @@ QList<Locator::FilterEntry> CppLocatorFilter::matchesFor(QFutureInterface<Locato
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (goodEntries.size() < 1000)
|
if (goodEntries.size() < 1000)
|
||||||
qSort(goodEntries.begin(), goodEntries.end(), compareLexigraphically);
|
qStableSort(goodEntries.begin(), goodEntries.end(), compareLexigraphically);
|
||||||
if (betterEntries.size() < 1000)
|
if (betterEntries.size() < 1000)
|
||||||
qSort(betterEntries.begin(), betterEntries.end(), compareLexigraphically);
|
qStableSort(betterEntries.begin(), betterEntries.end(), compareLexigraphically);
|
||||||
|
|
||||||
betterEntries += goodEntries;
|
betterEntries += goodEntries;
|
||||||
return betterEntries;
|
return betterEntries;
|
||||||
@@ -181,9 +124,3 @@ void CppLocatorFilter::accept(Locator::FilterEntry selection) const
|
|||||||
ModelItemInfo info = qvariant_cast<CppTools::ModelItemInfo>(selection.internalData);
|
ModelItemInfo info = qvariant_cast<CppTools::ModelItemInfo>(selection.internalData);
|
||||||
Core::EditorManager::openEditorAt(info.fileName, info.line, info.column);
|
Core::EditorManager::openEditorAt(info.fileName, info.line, info.column);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppLocatorFilter::reset()
|
|
||||||
{
|
|
||||||
m_searchList.clear();
|
|
||||||
m_previousEntry.clear();
|
|
||||||
}
|
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
#ifndef CPPLOCATORFILTER_H
|
#ifndef CPPLOCATORFILTER_H
|
||||||
#define CPPLOCATORFILTER_H
|
#define CPPLOCATORFILTER_H
|
||||||
|
|
||||||
|
#include "cpplocatordata.h"
|
||||||
#include "searchsymbols.h"
|
#include "searchsymbols.h"
|
||||||
|
|
||||||
#include <locator/ilocatorfilter.h>
|
#include <locator/ilocatorfilter.h>
|
||||||
@@ -44,35 +45,19 @@ class CppLocatorFilter : public Locator::ILocatorFilter
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CppLocatorFilter(CppModelManager *manager);
|
CppLocatorFilter(CppLocatorData *locatorData);
|
||||||
~CppLocatorFilter();
|
~CppLocatorFilter();
|
||||||
|
|
||||||
QList<Locator::FilterEntry> matchesFor(QFutureInterface<Locator::FilterEntry> &future, const QString &entry);
|
QList<Locator::FilterEntry> matchesFor(QFutureInterface<Locator::FilterEntry> &future, const QString &entry);
|
||||||
void accept(Locator::FilterEntry selection) const;
|
void accept(Locator::FilterEntry selection) const;
|
||||||
void refresh(QFutureInterface<void> &future);
|
void refresh(QFutureInterface<void> &future);
|
||||||
|
|
||||||
void reset();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
SearchSymbols search;
|
|
||||||
|
|
||||||
void flushPendingDocument(bool force);
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void onDocumentUpdated(CPlusPlus::Document::Ptr updatedDoc);
|
|
||||||
void onAboutToRemoveFiles(const QStringList &files);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
virtual QList<QList<ModelItemInfo> > itemsToMatchUserInputAgainst() const;
|
||||||
virtual Locator::FilterEntry filterEntryFromModelItemInfo(const ModelItemInfo &info);
|
virtual Locator::FilterEntry filterEntryFromModelItemInfo(const ModelItemInfo &info);
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
CppModelManager *m_manager;
|
CppLocatorData *m_data;
|
||||||
|
|
||||||
QHash<QString, QList<ModelItemInfo> > m_searchList;
|
|
||||||
QString m_previousEntry;
|
|
||||||
|
|
||||||
mutable QMutex m_pendingDocumentsMutex;
|
|
||||||
QVector<CPlusPlus::Document::Ptr> m_pendingDocuments;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -214,11 +214,11 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data()
|
|||||||
<< _("my")
|
<< _("my")
|
||||||
<< (QList<ResultData>()
|
<< (QList<ResultData>()
|
||||||
<< ResultData(_("MyClass"), testFileShort)
|
<< ResultData(_("MyClass"), testFileShort)
|
||||||
<< ResultData(_("MyClass"), _("()"))
|
<< ResultData(_("MyClass"), testFileShort)
|
||||||
<< ResultData(_("MyClass"), _("()"))
|
|
||||||
<< ResultData(_("MyClass"), testFileShort)
|
<< ResultData(_("MyClass"), testFileShort)
|
||||||
<< ResultData(_("MyClass"), _("()"))
|
<< ResultData(_("MyClass"), _("()"))
|
||||||
<< ResultData(_("MyClass"), testFileShort)
|
<< ResultData(_("MyClass"), _("()"))
|
||||||
|
<< ResultData(_("MyClass"), _("()"))
|
||||||
<< ResultData(_("MyEnum"), testFileShort)
|
<< ResultData(_("MyEnum"), testFileShort)
|
||||||
<< ResultData(_("MyEnum"), testFileShort)
|
<< ResultData(_("MyEnum"), testFileShort)
|
||||||
<< ResultData(_("MyEnum"), testFileShort)
|
<< ResultData(_("MyEnum"), testFileShort)
|
||||||
|
@@ -45,7 +45,8 @@ HEADERS += completionsettingspage.h \
|
|||||||
cpppointerdeclarationformatter.h \
|
cpppointerdeclarationformatter.h \
|
||||||
cppprojectfile.h \
|
cppprojectfile.h \
|
||||||
cpppreprocessor.h \
|
cpppreprocessor.h \
|
||||||
includeutils.h
|
includeutils.h \
|
||||||
|
cpplocatordata.h
|
||||||
|
|
||||||
SOURCES += completionsettingspage.cpp \
|
SOURCES += completionsettingspage.cpp \
|
||||||
cppclassesfilter.cpp \
|
cppclassesfilter.cpp \
|
||||||
@@ -89,7 +90,8 @@ SOURCES += completionsettingspage.cpp \
|
|||||||
cpppointerdeclarationformatter.cpp \
|
cpppointerdeclarationformatter.cpp \
|
||||||
cppprojectfile.cpp \
|
cppprojectfile.cpp \
|
||||||
cpppreprocessor.cpp \
|
cpppreprocessor.cpp \
|
||||||
includeutils.cpp
|
includeutils.cpp \
|
||||||
|
cpplocatordata.cpp
|
||||||
|
|
||||||
FORMS += completionsettingspage.ui \
|
FORMS += completionsettingspage.ui \
|
||||||
cppfilesettingspage.ui \
|
cppfilesettingspage.ui \
|
||||||
|
@@ -64,6 +64,8 @@ QtcPlugin {
|
|||||||
"cppindexingsupport.h",
|
"cppindexingsupport.h",
|
||||||
"cpplocalsymbols.cpp",
|
"cpplocalsymbols.cpp",
|
||||||
"cpplocalsymbols.h",
|
"cpplocalsymbols.h",
|
||||||
|
"cpplocatordata.cpp",
|
||||||
|
"cpplocatordata.h",
|
||||||
"cpplocatorfilter.cpp",
|
"cpplocatorfilter.cpp",
|
||||||
"cpplocatorfilter.h",
|
"cpplocatorfilter.h",
|
||||||
"cppmodelmanager.cpp",
|
"cppmodelmanager.cpp",
|
||||||
|
@@ -40,6 +40,7 @@
|
|||||||
#include "cpptoolssettings.h"
|
#include "cpptoolssettings.h"
|
||||||
#include "cpptoolsreuse.h"
|
#include "cpptoolsreuse.h"
|
||||||
#include "cppprojectfile.h"
|
#include "cppprojectfile.h"
|
||||||
|
#include "cpplocatordata.h"
|
||||||
|
|
||||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||||
#include <coreplugin/actionmanager/actionmanager.h>
|
#include <coreplugin/actionmanager/actionmanager.h>
|
||||||
@@ -101,9 +102,11 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
|
|||||||
connect(Core::DocumentManager::instance(), SIGNAL(filesChangedInternally(QStringList)),
|
connect(Core::DocumentManager::instance(), SIGNAL(filesChangedInternally(QStringList)),
|
||||||
modelManager, SLOT(updateSourceFiles(QStringList)));
|
modelManager, SLOT(updateSourceFiles(QStringList)));
|
||||||
|
|
||||||
addAutoReleasedObject(new CppLocatorFilter(modelManager));
|
CppLocatorData *locatorData = new CppLocatorData(modelManager);
|
||||||
addAutoReleasedObject(new CppClassesFilter(modelManager));
|
addAutoReleasedObject(locatorData);
|
||||||
addAutoReleasedObject(new CppFunctionsFilter(modelManager));
|
addAutoReleasedObject(new CppLocatorFilter(locatorData));
|
||||||
|
addAutoReleasedObject(new CppClassesFilter(locatorData));
|
||||||
|
addAutoReleasedObject(new CppFunctionsFilter(locatorData));
|
||||||
addAutoReleasedObject(new CppCurrentDocumentFilter(modelManager));
|
addAutoReleasedObject(new CppCurrentDocumentFilter(modelManager));
|
||||||
addAutoReleasedObject(new CppFileSettingsPage(m_fileSettings));
|
addAutoReleasedObject(new CppFileSettingsPage(m_fileSettings));
|
||||||
addAutoReleasedObject(new SymbolsFindFilter(modelManager));
|
addAutoReleasedObject(new SymbolsFindFilter(modelManager));
|
||||||
|
@@ -57,18 +57,6 @@ QList<FilterEntry> BasicLocatorFilterTest::matchesFor(const QString &searchText)
|
|||||||
return locatorSearch.results();
|
return locatorSearch.results();
|
||||||
}
|
}
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
namespace QTest {
|
|
||||||
|
|
||||||
template<> char *toString(const Locator::Internal::Tests::ResultData &data)
|
|
||||||
{
|
|
||||||
QByteArray ba = "\"" + data.textColumn1.toUtf8() + "\", \"" + data.textColumn2.toUtf8() + "\"";
|
|
||||||
return qstrdup(ba.data());
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace QTest
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
ResultData::ResultData()
|
ResultData::ResultData()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@@ -83,4 +83,16 @@ typedef ResultData::ResultDataList ResultDataList;
|
|||||||
Q_DECLARE_METATYPE(Locator::Internal::Tests::ResultData)
|
Q_DECLARE_METATYPE(Locator::Internal::Tests::ResultData)
|
||||||
Q_DECLARE_METATYPE(Locator::Internal::Tests::ResultDataList)
|
Q_DECLARE_METATYPE(Locator::Internal::Tests::ResultDataList)
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
namespace QTest {
|
||||||
|
|
||||||
|
template<> inline char *toString(const Locator::Internal::Tests::ResultData &data)
|
||||||
|
{
|
||||||
|
QByteArray ba = "\"" + data.textColumn1.toUtf8() + "\", \"" + data.textColumn2.toUtf8() + "\"";
|
||||||
|
return qstrdup(ba.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace QTest
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
#endif // LOCATORFILTERTEST_H
|
#endif // LOCATORFILTERTEST_H
|
||||||
|
Reference in New Issue
Block a user