summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>2008-12-05 12:21:18 +0100
committerThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>2008-12-05 13:23:04 +0100
commitecfb77d469e3410f06c093a7696fe8939f4f0632 (patch)
tree749b320045d8049a8a659e74e1565fe8bda6af91
parentf2f9e8a8310a05ff088b7122f65bf51ebd5378e5 (diff)
downloadqt-creator-ecfb77d469e3410f06c093a7696fe8939f4f0632.tar.gz
Separate scope in classes quickopen filter
The scope of the classes is now separated and displayed in the second column, and not included in the search.
-rw-r--r--src/libs/cplusplus/Icons.cpp4
-rw-r--r--src/libs/cplusplus/Icons.h2
-rw-r--r--src/libs/utils/pathchooser.h1
-rw-r--r--src/plugins/cpptools/cppclassesfilter.cpp1
-rw-r--r--src/plugins/cpptools/searchsymbols.cpp79
-rw-r--r--src/plugins/cpptools/searchsymbols.h14
6 files changed, 70 insertions, 31 deletions
diff --git a/src/libs/cplusplus/Icons.cpp b/src/libs/cplusplus/Icons.cpp
index 94b6469ea4..3b7ee24da3 100644
--- a/src/libs/cplusplus/Icons.cpp
+++ b/src/libs/cplusplus/Icons.cpp
@@ -61,11 +61,11 @@ Icons::Icons()
{
}
-QIcon Icons::iconForSymbol(Symbol *symbol) const
+QIcon Icons::iconForSymbol(const Symbol *symbol) const
{
if (symbol->isFunction() || (symbol->isDeclaration() && symbol->type()->isFunction()))
{
- Function *function = symbol->asFunction();
+ const Function *function = symbol->asFunction();
if (!function)
function = symbol->type()->asFunction();
diff --git a/src/libs/cplusplus/Icons.h b/src/libs/cplusplus/Icons.h
index c49bcde12d..6d4e0bb25d 100644
--- a/src/libs/cplusplus/Icons.h
+++ b/src/libs/cplusplus/Icons.h
@@ -47,7 +47,7 @@ class CPLUSPLUS_EXPORT Icons
public:
Icons();
- QIcon iconForSymbol(Symbol *symbol) const;
+ QIcon iconForSymbol(const Symbol *symbol) const;
QIcon keywordIcon() const;
QIcon macroIcon() const;
diff --git a/src/libs/utils/pathchooser.h b/src/libs/utils/pathchooser.h
index 7ae60a255b..ab821d5df1 100644
--- a/src/libs/utils/pathchooser.h
+++ b/src/libs/utils/pathchooser.h
@@ -30,6 +30,7 @@
** version 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
+
#ifndef PATHCHOOSER_H
#define PATHCHOOSER_H
diff --git a/src/plugins/cpptools/cppclassesfilter.cpp b/src/plugins/cpptools/cppclassesfilter.cpp
index 3d8da9a738..6aa6734fca 100644
--- a/src/plugins/cpptools/cppclassesfilter.cpp
+++ b/src/plugins/cpptools/cppclassesfilter.cpp
@@ -42,6 +42,7 @@ CppClassesFilter::CppClassesFilter(CppModelManager *manager, Core::EditorManager
setIncludedByDefault(false);
search.setSymbolsToSearchFor(SearchSymbols::Classes);
+ search.setSeparateScope(true);
}
CppClassesFilter::~CppClassesFilter()
diff --git a/src/plugins/cpptools/searchsymbols.cpp b/src/plugins/cpptools/searchsymbols.cpp
index 4b1e48abdf..670d0d6d47 100644
--- a/src/plugins/cpptools/searchsymbols.cpp
+++ b/src/plugins/cpptools/searchsymbols.cpp
@@ -40,7 +40,8 @@ using namespace CPlusPlus;
using namespace CppTools::Internal;
SearchSymbols::SearchSymbols():
- symbolsToSearchFor(Classes | Functions | Enums)
+ symbolsToSearchFor(Classes | Functions | Enums),
+ separateScope(false)
{
}
@@ -49,6 +50,11 @@ void SearchSymbols::setSymbolsToSearchFor(SymbolTypes types)
symbolsToSearchFor = types;
}
+void SearchSymbols::setSeparateScope(bool separateScope)
+{
+ this->separateScope = separateScope;
+}
+
QList<ModelItemInfo> SearchSymbols::operator()(Document::Ptr doc, const QString &scope)
{
QString previousScope = switchScope(scope);
@@ -73,13 +79,12 @@ bool SearchSymbols::visit(Enum *symbol)
return false;
QString name = symbolName(symbol);
- QString previousScope = switchScope(name);
- QIcon icon = icons.iconForSymbol(symbol);
+ QString scopedName = scopedSymbolName(name);
+ QString previousScope = switchScope(scopedName);
+ appendItem(separateScope ? name : scopedName,
+ separateScope ? previousScope : QString(),
+ ModelItemInfo::Enum, symbol);
Scope *members = symbol->members();
- items.append(ModelItemInfo(name, QString(), ModelItemInfo::Enum,
- QString::fromUtf8(symbol->fileName(), symbol->fileNameLength()),
- symbol->line(),
- icon));
for (unsigned i = 0; i < members->symbolCount(); ++i) {
accept(members->symbolAt(i));
}
@@ -93,18 +98,18 @@ bool SearchSymbols::visit(Function *symbol)
return false;
QString name = symbolName(symbol);
- QString type = overview.prettyType(symbol->type());
- QIcon icon = icons.iconForSymbol(symbol);
- items.append(ModelItemInfo(name, type, ModelItemInfo::Method,
- QString::fromUtf8(symbol->fileName(), symbol->fileNameLength()),
- symbol->line(),
- icon));
+ QString scopedName = scopedSymbolName(name);
+ QString type = overview.prettyType(symbol->type(),
+ separateScope ? symbol->name() : 0);
+ appendItem(separateScope ? type : scopedName,
+ separateScope ? _scope : type,
+ ModelItemInfo::Method, symbol);
return false;
}
bool SearchSymbols::visit(Namespace *symbol)
{
- QString name = symbolName(symbol);
+ QString name = findOrInsert(scopedSymbolName(symbol));
QString previousScope = switchScope(name);
Scope *members = symbol->members();
for (unsigned i = 0; i < members->symbolCount(); ++i) {
@@ -118,12 +123,9 @@ bool SearchSymbols::visit(Namespace *symbol)
bool SearchSymbols::visit(Declaration *symbol)
{
if (symbol->type()->isFunction()) {
- QString name = symbolName(symbol);
+ QString name = scopedSymbolName(symbol);
QString type = overview.prettyType(symbol->type());
- //QIcon icon = ...;
- items.append(ModelItemInfo(name, type, ModelItemInfo::Method,
- QString::fromUtf8(symbol->fileName(), symbol->line()),
- symbol->line()));
+ appendItems(name, type, ModelItemInfo::Method, symbol->fileName());
}
return false;
}
@@ -135,12 +137,11 @@ bool SearchSymbols::visit(Class *symbol)
return false;
QString name = symbolName(symbol);
- QString previousScope = switchScope(name);
- QIcon icon = icons.iconForSymbol(symbol);
- items.append(ModelItemInfo(name, QString(), ModelItemInfo::Class,
- QString::fromUtf8(symbol->fileName(), symbol->fileNameLength()),
- symbol->line(),
- icon));
+ QString scopedName = scopedSymbolName(name);
+ QString previousScope = switchScope(scopedName);
+ appendItem(separateScope ? name : scopedName,
+ separateScope ? previousScope : QString(),
+ ModelItemInfo::Class, symbol);
Scope *members = symbol->members();
for (unsigned i = 0; i < members->symbolCount(); ++i) {
accept(members->symbolAt(i));
@@ -149,11 +150,22 @@ bool SearchSymbols::visit(Class *symbol)
return false;
}
-QString SearchSymbols::symbolName(const Symbol *symbol) const
+QString SearchSymbols::scopedSymbolName(const QString &symbolName) const
{
QString name = _scope;
if (! name.isEmpty())
name += QLatin1String("::");
+ name += symbolName;
+ return name;
+}
+
+QString SearchSymbols::scopedSymbolName(const Symbol *symbol) const
+{
+ return scopedSymbolName(symbolName(symbol));
+}
+
+QString SearchSymbols::symbolName(const Symbol *symbol) const
+{
QString symbolName = overview.prettyName(symbol->name());
if (symbolName.isEmpty()) {
QString type;
@@ -176,6 +188,17 @@ QString SearchSymbols::symbolName(const Symbol *symbol) const
symbolName += type;
symbolName += QLatin1String(">");
}
- name += symbolName;
- return name;
+ return symbolName;
+}
+
+void SearchSymbols::appendItem(const QString &name,
+ const QString &info,
+ ModelItemInfo::ItemType type,
+ const CPlusPlus::Symbol *symbol)
+{
+ const QIcon icon = icons.iconForSymbol(symbol);
+ items.append(ModelItemInfo(name, info, type,
+ QString::fromUtf8(symbol->fileName(), symbol->fileNameLength()),
+ symbol->line(),
+ icon));
}
diff --git a/src/plugins/cpptools/searchsymbols.h b/src/plugins/cpptools/searchsymbols.h
index 948f9d78e8..d82f285972 100644
--- a/src/plugins/cpptools/searchsymbols.h
+++ b/src/plugins/cpptools/searchsymbols.h
@@ -90,6 +90,7 @@ public:
SearchSymbols();
void setSymbolsToSearchFor(SymbolTypes types);
+ void setSeparateScope(bool separateScope);
QList<ModelItemInfo> operator()(CPlusPlus::Document::Ptr doc)
{ return operator()(doc, QString()); }
@@ -111,14 +112,27 @@ protected:
virtual bool visit(CPlusPlus::Declaration *symbol);
#endif
virtual bool visit(CPlusPlus::Class *symbol);
+
+ QString scopedSymbolName(const QString &symbolName) const;
+ QString scopedSymbolName(const CPlusPlus::Symbol *symbol) const;
QString symbolName(const CPlusPlus::Symbol *symbol) const;
+ void appendItem(const QString &name,
+ const QString &info,
+ ModelItemInfo::ItemType type,
+ const CPlusPlus::Symbol *symbol);
private:
+ QString findOrInsert(const QString &s)
+ { return *strings.insert(s); }
+
+ QSet<QString> strings; // Used to avoid QString duplication
+
QString _scope;
CPlusPlus::Overview overview;
CPlusPlus::Icons icons;
QList<ModelItemInfo> items;
SymbolTypes symbolsToSearchFor;
+ bool separateScope;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(SearchSymbols::SymbolTypes)