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.
This commit is contained in:
Thorbjørn Lindeijer
2008-12-05 12:21:18 +01:00
parent f2f9e8a831
commit ecfb77d469
6 changed files with 70 additions and 31 deletions

View File

@@ -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())) if (symbol->isFunction() || (symbol->isDeclaration() && symbol->type()->isFunction()))
{ {
Function *function = symbol->asFunction(); const Function *function = symbol->asFunction();
if (!function) if (!function)
function = symbol->type()->asFunction(); function = symbol->type()->asFunction();

View File

@@ -47,7 +47,7 @@ class CPLUSPLUS_EXPORT Icons
public: public:
Icons(); Icons();
QIcon iconForSymbol(Symbol *symbol) const; QIcon iconForSymbol(const Symbol *symbol) const;
QIcon keywordIcon() const; QIcon keywordIcon() const;
QIcon macroIcon() const; QIcon macroIcon() const;

View File

@@ -30,6 +30,7 @@
** version 1.2, included in the file GPL_EXCEPTION.txt in this package. ** version 1.2, included in the file GPL_EXCEPTION.txt in this package.
** **
***************************************************************************/ ***************************************************************************/
#ifndef PATHCHOOSER_H #ifndef PATHCHOOSER_H
#define PATHCHOOSER_H #define PATHCHOOSER_H

View File

@@ -42,6 +42,7 @@ CppClassesFilter::CppClassesFilter(CppModelManager *manager, Core::EditorManager
setIncludedByDefault(false); setIncludedByDefault(false);
search.setSymbolsToSearchFor(SearchSymbols::Classes); search.setSymbolsToSearchFor(SearchSymbols::Classes);
search.setSeparateScope(true);
} }
CppClassesFilter::~CppClassesFilter() CppClassesFilter::~CppClassesFilter()

View File

@@ -40,7 +40,8 @@ using namespace CPlusPlus;
using namespace CppTools::Internal; using namespace CppTools::Internal;
SearchSymbols::SearchSymbols(): SearchSymbols::SearchSymbols():
symbolsToSearchFor(Classes | Functions | Enums) symbolsToSearchFor(Classes | Functions | Enums),
separateScope(false)
{ {
} }
@@ -49,6 +50,11 @@ void SearchSymbols::setSymbolsToSearchFor(SymbolTypes types)
symbolsToSearchFor = types; symbolsToSearchFor = types;
} }
void SearchSymbols::setSeparateScope(bool separateScope)
{
this->separateScope = separateScope;
}
QList<ModelItemInfo> SearchSymbols::operator()(Document::Ptr doc, const QString &scope) QList<ModelItemInfo> SearchSymbols::operator()(Document::Ptr doc, const QString &scope)
{ {
QString previousScope = switchScope(scope); QString previousScope = switchScope(scope);
@@ -73,13 +79,12 @@ bool SearchSymbols::visit(Enum *symbol)
return false; return false;
QString name = symbolName(symbol); QString name = symbolName(symbol);
QString previousScope = switchScope(name); QString scopedName = scopedSymbolName(name);
QIcon icon = icons.iconForSymbol(symbol); QString previousScope = switchScope(scopedName);
appendItem(separateScope ? name : scopedName,
separateScope ? previousScope : QString(),
ModelItemInfo::Enum, symbol);
Scope *members = symbol->members(); 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) { for (unsigned i = 0; i < members->symbolCount(); ++i) {
accept(members->symbolAt(i)); accept(members->symbolAt(i));
} }
@@ -93,18 +98,18 @@ bool SearchSymbols::visit(Function *symbol)
return false; return false;
QString name = symbolName(symbol); QString name = symbolName(symbol);
QString type = overview.prettyType(symbol->type()); QString scopedName = scopedSymbolName(name);
QIcon icon = icons.iconForSymbol(symbol); QString type = overview.prettyType(symbol->type(),
items.append(ModelItemInfo(name, type, ModelItemInfo::Method, separateScope ? symbol->name() : 0);
QString::fromUtf8(symbol->fileName(), symbol->fileNameLength()), appendItem(separateScope ? type : scopedName,
symbol->line(), separateScope ? _scope : type,
icon)); ModelItemInfo::Method, symbol);
return false; return false;
} }
bool SearchSymbols::visit(Namespace *symbol) bool SearchSymbols::visit(Namespace *symbol)
{ {
QString name = symbolName(symbol); QString name = findOrInsert(scopedSymbolName(symbol));
QString previousScope = switchScope(name); QString previousScope = switchScope(name);
Scope *members = symbol->members(); Scope *members = symbol->members();
for (unsigned i = 0; i < members->symbolCount(); ++i) { for (unsigned i = 0; i < members->symbolCount(); ++i) {
@@ -118,12 +123,9 @@ bool SearchSymbols::visit(Namespace *symbol)
bool SearchSymbols::visit(Declaration *symbol) bool SearchSymbols::visit(Declaration *symbol)
{ {
if (symbol->type()->isFunction()) { if (symbol->type()->isFunction()) {
QString name = symbolName(symbol); QString name = scopedSymbolName(symbol);
QString type = overview.prettyType(symbol->type()); QString type = overview.prettyType(symbol->type());
//QIcon icon = ...; appendItems(name, type, ModelItemInfo::Method, symbol->fileName());
items.append(ModelItemInfo(name, type, ModelItemInfo::Method,
QString::fromUtf8(symbol->fileName(), symbol->line()),
symbol->line()));
} }
return false; return false;
} }
@@ -135,12 +137,11 @@ bool SearchSymbols::visit(Class *symbol)
return false; return false;
QString name = symbolName(symbol); QString name = symbolName(symbol);
QString previousScope = switchScope(name); QString scopedName = scopedSymbolName(name);
QIcon icon = icons.iconForSymbol(symbol); QString previousScope = switchScope(scopedName);
items.append(ModelItemInfo(name, QString(), ModelItemInfo::Class, appendItem(separateScope ? name : scopedName,
QString::fromUtf8(symbol->fileName(), symbol->fileNameLength()), separateScope ? previousScope : QString(),
symbol->line(), ModelItemInfo::Class, symbol);
icon));
Scope *members = symbol->members(); Scope *members = symbol->members();
for (unsigned i = 0; i < members->symbolCount(); ++i) { for (unsigned i = 0; i < members->symbolCount(); ++i) {
accept(members->symbolAt(i)); accept(members->symbolAt(i));
@@ -149,11 +150,22 @@ bool SearchSymbols::visit(Class *symbol)
return false; return false;
} }
QString SearchSymbols::symbolName(const Symbol *symbol) const QString SearchSymbols::scopedSymbolName(const QString &symbolName) const
{ {
QString name = _scope; QString name = _scope;
if (! name.isEmpty()) if (! name.isEmpty())
name += QLatin1String("::"); 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()); QString symbolName = overview.prettyName(symbol->name());
if (symbolName.isEmpty()) { if (symbolName.isEmpty()) {
QString type; QString type;
@@ -176,6 +188,17 @@ QString SearchSymbols::symbolName(const Symbol *symbol) const
symbolName += type; symbolName += type;
symbolName += QLatin1String(">"); symbolName += QLatin1String(">");
} }
name += symbolName; return symbolName;
return name; }
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));
} }

View File

@@ -90,6 +90,7 @@ public:
SearchSymbols(); SearchSymbols();
void setSymbolsToSearchFor(SymbolTypes types); void setSymbolsToSearchFor(SymbolTypes types);
void setSeparateScope(bool separateScope);
QList<ModelItemInfo> operator()(CPlusPlus::Document::Ptr doc) QList<ModelItemInfo> operator()(CPlusPlus::Document::Ptr doc)
{ return operator()(doc, QString()); } { return operator()(doc, QString()); }
@@ -111,14 +112,27 @@ protected:
virtual bool visit(CPlusPlus::Declaration *symbol); virtual bool visit(CPlusPlus::Declaration *symbol);
#endif #endif
virtual bool visit(CPlusPlus::Class *symbol); 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; QString symbolName(const CPlusPlus::Symbol *symbol) const;
void appendItem(const QString &name,
const QString &info,
ModelItemInfo::ItemType type,
const CPlusPlus::Symbol *symbol);
private: private:
QString findOrInsert(const QString &s)
{ return *strings.insert(s); }
QSet<QString> strings; // Used to avoid QString duplication
QString _scope; QString _scope;
CPlusPlus::Overview overview; CPlusPlus::Overview overview;
CPlusPlus::Icons icons; CPlusPlus::Icons icons;
QList<ModelItemInfo> items; QList<ModelItemInfo> items;
SymbolTypes symbolsToSearchFor; SymbolTypes symbolsToSearchFor;
bool separateScope;
}; };
Q_DECLARE_OPERATORS_FOR_FLAGS(SearchSymbols::SymbolTypes) Q_DECLARE_OPERATORS_FOR_FLAGS(SearchSymbols::SymbolTypes)