Commit aa1aeeaf authored by Nikolai Kosjar's avatar Nikolai Kosjar

CppTools: Locator: Match also against qualified names

If the user input contains "::", match against the qualified symbol
name. Otherwise, as before, match against the unqualified symbol name.

This applies to the function and class filters and allows to narrow down
the results by using a namespace prefix, e.g. "c core::*category".

Change-Id: Id152f412740e27f2f2d001dc7008dba8a92a37ce
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent e8801167
...@@ -47,8 +47,11 @@ CppClassesFilter::~CppClassesFilter() ...@@ -47,8 +47,11 @@ CppClassesFilter::~CppClassesFilter()
{ {
} }
QString CppClassesFilter::stringToMatchUserInputAgainst(const ModelItemInfo &info) QString CppClassesFilter::stringToMatchUserInputAgainst(const ModelItemInfo &info,
bool userInputContainsColonColon)
{ {
if (userInputContainsColonColon)
return info.scopedSymbolName();
return info.symbolName; return info.symbolName;
} }
......
...@@ -44,7 +44,8 @@ public: ...@@ -44,7 +44,8 @@ public:
~CppClassesFilter(); ~CppClassesFilter();
private: private:
QString stringToMatchUserInputAgainst(const ModelItemInfo &info); QString stringToMatchUserInputAgainst(const ModelItemInfo &info,
bool userInputContainsColonColon);
Locator::FilterEntry filterEntryFromModelItemInfo(const ModelItemInfo &info); Locator::FilterEntry filterEntryFromModelItemInfo(const ModelItemInfo &info);
}; };
......
...@@ -46,8 +46,11 @@ CppFunctionsFilter::~CppFunctionsFilter() ...@@ -46,8 +46,11 @@ CppFunctionsFilter::~CppFunctionsFilter()
{ {
} }
QString CppFunctionsFilter::stringToMatchUserInputAgainst(const CppTools::ModelItemInfo &info) QString CppFunctionsFilter::stringToMatchUserInputAgainst(const CppTools::ModelItemInfo &info,
bool userInputContainsColonColon)
{ {
if (userInputContainsColonColon)
return info.scopedSymbolName();
return info.symbolName; return info.symbolName;
} }
......
...@@ -44,7 +44,8 @@ public: ...@@ -44,7 +44,8 @@ public:
~CppFunctionsFilter(); ~CppFunctionsFilter();
private: private:
QString stringToMatchUserInputAgainst(const ModelItemInfo &info); QString stringToMatchUserInputAgainst(const ModelItemInfo &info,
bool userInputContainsColonColon);
Locator::FilterEntry filterEntryFromModelItemInfo(const ModelItemInfo &info); Locator::FilterEntry filterEntryFromModelItemInfo(const ModelItemInfo &info);
}; };
......
...@@ -108,8 +108,10 @@ void CppLocatorFilter::onAboutToRemoveFiles(const QStringList &files) ...@@ -108,8 +108,10 @@ void CppLocatorFilter::onAboutToRemoveFiles(const QStringList &files)
m_searchList.remove(file); m_searchList.remove(file);
} }
QString CppLocatorFilter::stringToMatchUserInputAgainst(const CppTools::ModelItemInfo &info) QString CppLocatorFilter::stringToMatchUserInputAgainst(const CppTools::ModelItemInfo &info,
bool userInputContainsColonColon)
{ {
Q_UNUSED(userInputContainsColonColon)
return info.scopedSymbolName(); return info.scopedSymbolName();
} }
...@@ -149,6 +151,7 @@ QList<Locator::FilterEntry> CppLocatorFilter::matchesFor(QFutureInterface<Locato ...@@ -149,6 +151,7 @@ QList<Locator::FilterEntry> CppLocatorFilter::matchesFor(QFutureInterface<Locato
if (!regexp.isValid()) if (!regexp.isValid())
return goodEntries; return goodEntries;
bool hasWildcard = (entry.contains(asterisk) || entry.contains(QLatin1Char('?'))); bool hasWildcard = (entry.contains(asterisk) || entry.contains(QLatin1Char('?')));
bool hasColonColon = entry.contains(QLatin1String("::"));
const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry); const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry);
QHashIterator<QString, QList<ModelItemInfo> > it(m_searchList); QHashIterator<QString, QList<ModelItemInfo> > it(m_searchList);
...@@ -160,7 +163,7 @@ QList<Locator::FilterEntry> CppLocatorFilter::matchesFor(QFutureInterface<Locato ...@@ -160,7 +163,7 @@ QList<Locator::FilterEntry> CppLocatorFilter::matchesFor(QFutureInterface<Locato
const QList<ModelItemInfo> items = it.value(); const QList<ModelItemInfo> items = it.value();
foreach (const ModelItemInfo &info, items) { foreach (const ModelItemInfo &info, items) {
const QString matchString = stringToMatchUserInputAgainst(info); const QString matchString = stringToMatchUserInputAgainst(info, hasColonColon);
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);
......
...@@ -63,7 +63,8 @@ private slots: ...@@ -63,7 +63,8 @@ private slots:
void onAboutToRemoveFiles(const QStringList &files); void onAboutToRemoveFiles(const QStringList &files);
private: private:
virtual QString stringToMatchUserInputAgainst(const ModelItemInfo &info); virtual QString stringToMatchUserInputAgainst(const ModelItemInfo &info,
bool userInputContainsColonColon);
virtual Locator::FilterEntry filterEntryFromModelItemInfo(const ModelItemInfo &info); virtual Locator::FilterEntry filterEntryFromModelItemInfo(const ModelItemInfo &info);
private: private:
......
...@@ -180,6 +180,16 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data() ...@@ -180,6 +180,16 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data()
<< ResultData(_("myFunction(bool, int)"), _("<anonymous namespace>")) << ResultData(_("myFunction(bool, int)"), _("<anonymous namespace>"))
); );
QTest::newRow("CppFunctionsFilter-WithNamespacePrefix")
<< testFile
<< cppFunctionsFilter
<< _("mynamespace::")
<< (QList<ResultData>()
<< ResultData(_("MyClass()"), _("MyNamespace::MyClass"))
<< ResultData(_("function2(bool, int)"), _("MyNamespace::MyClass"))
<< ResultData(_("myFunction(bool, int)"), _("MyNamespace"))
);
QTest::newRow("CppClassesFilter") QTest::newRow("CppClassesFilter")
<< testFile << testFile
<< cppClassesFilter << cppClassesFilter
...@@ -190,6 +200,14 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data() ...@@ -190,6 +200,14 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data()
<< ResultData(_("MyClass"), _("<anonymous namespace>")) << ResultData(_("MyClass"), _("<anonymous namespace>"))
); );
QTest::newRow("CppClassesFilter-WithNamespacePrefix")
<< testFile
<< cppClassesFilter
<< _("mynamespace::")
<< (QList<ResultData>()
<< ResultData(_("MyClass"), _("MyNamespace"))
);
QTest::newRow("CppLocatorFilter") QTest::newRow("CppLocatorFilter")
<< testFile << testFile
<< cppLocatorFilter << cppLocatorFilter
......
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