Commit 2bda8675 authored by con's avatar con

C++ symbols find filter for advanced find.

Required refactoring of the search result window to show real trees of
search results.

The backend is the backend from the Locator filter, which is a bit
outdated now.
parent 80d85e28
...@@ -17,5 +17,6 @@ Alternatively, this plugin may be used under the terms of the GNU Lesser General ...@@ -17,5 +17,6 @@ Alternatively, this plugin may be used under the terms of the GNU Lesser General
<dependency name="TextEditor" version="2.1.80"/> <dependency name="TextEditor" version="2.1.80"/>
<dependency name="ProjectExplorer" version="2.1.80"/> <dependency name="ProjectExplorer" version="2.1.80"/>
<dependency name="Locator" version="2.1.80"/> <dependency name="Locator" version="2.1.80"/>
<dependency name="Find" version="2.1.80"/>
</dependencyList> </dependencyList>
</plugin> </plugin>
...@@ -31,8 +31,8 @@ ...@@ -31,8 +31,8 @@
using namespace CppTools::Internal; using namespace CppTools::Internal;
CppClassesFilter::CppClassesFilter(CppModelManager *manager, Core::EditorManager *editorManager) CppClassesFilter::CppClassesFilter(CppModelManager *manager)
: CppLocatorFilter(manager, editorManager) : CppLocatorFilter(manager)
{ {
setShortcutString("c"); setShortcutString("c");
setIncludedByDefault(false); setIncludedByDefault(false);
......
...@@ -40,7 +40,7 @@ class CppClassesFilter : public CppLocatorFilter ...@@ -40,7 +40,7 @@ class CppClassesFilter : public CppLocatorFilter
Q_OBJECT Q_OBJECT
public: public:
CppClassesFilter(CppModelManager *manager, Core::EditorManager *editorManager); CppClassesFilter(CppModelManager *manager);
~CppClassesFilter(); ~CppClassesFilter();
QString displayName() const { return tr("Classes"); } QString displayName() const { return tr("Classes"); }
......
...@@ -313,7 +313,11 @@ void CppFindReferences::searchFinished() ...@@ -313,7 +313,11 @@ void CppFindReferences::searchFinished()
void CppFindReferences::openEditor(const Find::SearchResultItem &item) void CppFindReferences::openEditor(const Find::SearchResultItem &item)
{ {
TextEditor::BaseTextEditor::openEditorAt(item.fileName, item.lineNumber, item.searchTermStart); if (item.path.size() > 0) {
TextEditor::BaseTextEditor::openEditorAt(item.path.first(), item.lineNumber, item.textMarkPos);
} else {
Core::EditorManager::instance()->openEditor(item.text);
}
} }
......
...@@ -31,8 +31,8 @@ ...@@ -31,8 +31,8 @@
using namespace CppTools::Internal; using namespace CppTools::Internal;
CppFunctionsFilter::CppFunctionsFilter(CppModelManager *manager, Core::EditorManager *editorManager) CppFunctionsFilter::CppFunctionsFilter(CppModelManager *manager)
: CppLocatorFilter(manager, editorManager) : CppLocatorFilter(manager)
{ {
setShortcutString(QString(QLatin1Char('m'))); setShortcutString(QString(QLatin1Char('m')));
setIncludedByDefault(false); setIncludedByDefault(false);
......
...@@ -40,7 +40,7 @@ class CppFunctionsFilter : public CppLocatorFilter ...@@ -40,7 +40,7 @@ class CppFunctionsFilter : public CppLocatorFilter
Q_OBJECT Q_OBJECT
public: public:
CppFunctionsFilter(CppModelManager *manager, Core::EditorManager *editorManager); CppFunctionsFilter(CppModelManager *manager);
~CppFunctionsFilter(); ~CppFunctionsFilter();
QString displayName() const { return tr("Methods"); } QString displayName() const { return tr("Methods"); }
......
...@@ -30,8 +30,6 @@ ...@@ -30,8 +30,6 @@
#include "cpplocatorfilter.h" #include "cpplocatorfilter.h"
#include "cppmodelmanager.h" #include "cppmodelmanager.h"
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <texteditor/itexteditor.h> #include <texteditor/itexteditor.h>
#include <texteditor/basetexteditor.h> #include <texteditor/basetexteditor.h>
...@@ -39,9 +37,8 @@ ...@@ -39,9 +37,8 @@
using namespace CppTools::Internal; using namespace CppTools::Internal;
CppLocatorFilter::CppLocatorFilter(CppModelManager *manager, Core::EditorManager *editorManager) CppLocatorFilter::CppLocatorFilter(CppModelManager *manager)
: m_manager(manager), : m_manager(manager),
m_editorManager(editorManager),
m_forceNewSearchList(true) m_forceNewSearchList(true)
{ {
setShortcutString(QString(QLatin1Char(':'))); setShortcutString(QString(QLatin1Char(':')));
......
...@@ -34,10 +34,6 @@ ...@@ -34,10 +34,6 @@
#include <locator/ilocatorfilter.h> #include <locator/ilocatorfilter.h>
namespace Core {
class EditorManager;
}
namespace CppTools { namespace CppTools {
namespace Internal { namespace Internal {
...@@ -47,7 +43,7 @@ class CppLocatorFilter : public Locator::ILocatorFilter ...@@ -47,7 +43,7 @@ class CppLocatorFilter : public Locator::ILocatorFilter
{ {
Q_OBJECT Q_OBJECT
public: public:
CppLocatorFilter(CppModelManager *manager, Core::EditorManager *editorManager); CppLocatorFilter(CppModelManager *manager);
~CppLocatorFilter(); ~CppLocatorFilter();
QString displayName() const { return tr("Classes and Methods"); } QString displayName() const { return tr("Classes and Methods"); }
...@@ -66,7 +62,6 @@ private slots: ...@@ -66,7 +62,6 @@ private slots:
private: private:
CppModelManager *m_manager; CppModelManager *m_manager;
Core::EditorManager *m_editorManager;
struct Info { struct Info {
Info(): dirty(true) {} Info(): dirty(true) {}
......
...@@ -24,7 +24,8 @@ HEADERS += completionsettingspage.h \ ...@@ -24,7 +24,8 @@ HEADERS += completionsettingspage.h \
cppdoxygen.h \ cppdoxygen.h \
cppfilesettingspage.h \ cppfilesettingspage.h \
cppfindreferences.h \ cppfindreferences.h \
cppcodeformatter.h cppcodeformatter.h \
symbolsfindfilter.h
SOURCES += completionsettingspage.cpp \ SOURCES += completionsettingspage.cpp \
cppclassesfilter.cpp \ cppclassesfilter.cpp \
...@@ -40,7 +41,8 @@ SOURCES += completionsettingspage.cpp \ ...@@ -40,7 +41,8 @@ SOURCES += completionsettingspage.cpp \
cppfilesettingspage.cpp \ cppfilesettingspage.cpp \
abstracteditorsupport.cpp \ abstracteditorsupport.cpp \
cppfindreferences.cpp \ cppfindreferences.cpp \
cppcodeformatter.cpp cppcodeformatter.cpp \
symbolsfindfilter.cpp
FORMS += completionsettingspage.ui \ FORMS += completionsettingspage.ui \
cppfilesettingspage.ui cppfilesettingspage.ui
......
include($$IDE_SOURCE_TREE/src/libs/cplusplus/cplusplus.pri) include($$IDE_SOURCE_TREE/src/libs/cplusplus/cplusplus.pri)
include($$IDE_SOURCE_TREE/src/plugins/projectexplorer/projectexplorer.pri) include($$IDE_SOURCE_TREE/src/plugins/projectexplorer/projectexplorer.pri)
include($$IDE_SOURCE_TREE/src/plugins/texteditor/texteditor.pri) include($$IDE_SOURCE_TREE/src/plugins/texteditor/texteditor.pri)
include($$IDE_SOURCE_TREE/src/plugins/find/find.pri)
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "cppmodelmanager.h" #include "cppmodelmanager.h"
#include "cpptoolsconstants.h" #include "cpptoolsconstants.h"
#include "cpplocatorfilter.h" #include "cpplocatorfilter.h"
#include "symbolsfindfilter.h"
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
...@@ -111,14 +112,13 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error) ...@@ -111,14 +112,13 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
CppCodeCompletion *completion = new CppCodeCompletion(m_modelManager); CppCodeCompletion *completion = new CppCodeCompletion(m_modelManager);
addAutoReleasedObject(completion); addAutoReleasedObject(completion);
CppLocatorFilter *locatorFilter = new CppLocatorFilter(m_modelManager, addAutoReleasedObject(new CppLocatorFilter(m_modelManager));
core->editorManager()); addAutoReleasedObject(new CppClassesFilter(m_modelManager));
addAutoReleasedObject(locatorFilter); addAutoReleasedObject(new CppFunctionsFilter(m_modelManager));
addAutoReleasedObject(new CppClassesFilter(m_modelManager, core->editorManager()));
addAutoReleasedObject(new CppFunctionsFilter(m_modelManager, core->editorManager()));
addAutoReleasedObject(new CppCurrentDocumentFilter(m_modelManager, core->editorManager())); addAutoReleasedObject(new CppCurrentDocumentFilter(m_modelManager, core->editorManager()));
addAutoReleasedObject(new CompletionSettingsPage); addAutoReleasedObject(new CompletionSettingsPage);
addAutoReleasedObject(new CppFileSettingsPage(m_fileSettings)); addAutoReleasedObject(new CppFileSettingsPage(m_fileSettings));
addAutoReleasedObject(new SymbolsFindFilter(m_modelManager));
// Menus // Menus
Core::ActionContainer *mtools = am->actionContainer(Core::Constants::M_TOOLS); Core::ActionContainer *mtools = am->actionContainer(Core::Constants::M_TOOLS);
......
...@@ -32,10 +32,17 @@ ...@@ -32,10 +32,17 @@
#include <Literals.h> #include <Literals.h>
#include <Scope.h> #include <Scope.h>
#include <Names.h> #include <Names.h>
#include <cplusplus/LookupContext.h>
using namespace CPlusPlus; using namespace CPlusPlus;
using namespace CppTools::Internal; using namespace CppTools::Internal;
SearchSymbols::SymbolTypes SearchSymbols::AllTypes =
SearchSymbols::Classes
| SearchSymbols::Functions
| SearchSymbols::Enums
| SearchSymbols::Declarations;
SearchSymbols::SearchSymbols(): SearchSymbols::SearchSymbols():
symbolsToSearchFor(Classes | Functions | Enums), symbolsToSearchFor(Classes | Functions | Enums),
separateScope(false) separateScope(false)
...@@ -204,13 +211,17 @@ QString SearchSymbols::symbolName(const Symbol *symbol) const ...@@ -204,13 +211,17 @@ QString SearchSymbols::symbolName(const Symbol *symbol) const
void SearchSymbols::appendItem(const QString &name, void SearchSymbols::appendItem(const QString &name,
const QString &info, const QString &info,
ModelItemInfo::ItemType type, ModelItemInfo::ItemType type,
const Symbol *symbol) Symbol *symbol)
{ {
if (!symbol->name()) if (!symbol->name())
return; return;
QStringList fullyQualifiedName;
foreach (const Name *name, LookupContext::fullyQualifiedName(symbol))
fullyQualifiedName.append(overview.prettyName(name));
const QIcon icon = icons.iconForSymbol(symbol); const QIcon icon = icons.iconForSymbol(symbol);
items.append(ModelItemInfo(name, info, type, items.append(ModelItemInfo(name, info, type,
fullyQualifiedName,
QString::fromUtf8(symbol->fileName(), symbol->fileNameLength()), QString::fromUtf8(symbol->fileName(), symbol->fileNameLength()),
symbol->line(), symbol->line(),
symbol->column() - 1, // 1-based vs 0-based column symbol->column() - 1, // 1-based vs 0-based column
......
...@@ -52,12 +52,14 @@ struct ModelItemInfo ...@@ -52,12 +52,14 @@ struct ModelItemInfo
ModelItemInfo() ModelItemInfo()
: type(Declaration), : type(Declaration),
line(0) line(0),
column(0)
{ } { }
ModelItemInfo(const QString &symbolName, ModelItemInfo(const QString &symbolName,
const QString &symbolType, const QString &symbolType,
ItemType type, ItemType type,
QStringList fullyQualifiedName,
const QString &fileName, const QString &fileName,
int line, int line,
int column, int column,
...@@ -65,15 +67,28 @@ struct ModelItemInfo ...@@ -65,15 +67,28 @@ struct ModelItemInfo
: symbolName(symbolName), : symbolName(symbolName),
symbolType(symbolType), symbolType(symbolType),
type(type), type(type),
fullyQualifiedName(fullyQualifiedName),
fileName(fileName), fileName(fileName),
line(line), line(line),
column(column), column(column),
icon(icon) icon(icon)
{ } { }
ModelItemInfo(const ModelItemInfo &otherInfo)
: symbolName(otherInfo.symbolName),
symbolType(otherInfo.symbolType),
type(otherInfo.type),
fullyQualifiedName(otherInfo.fullyQualifiedName),
fileName(otherInfo.fileName),
line(otherInfo.line),
column(otherInfo.column),
icon(otherInfo.icon)
{ }
QString symbolName; QString symbolName;
QString symbolType; QString symbolType;
ItemType type; ItemType type;
QStringList fullyQualifiedName;
QString fileName; QString fileName;
int line; int line;
int column; int column;
...@@ -90,8 +105,11 @@ public: ...@@ -90,8 +105,11 @@ public:
Enums = 0x4, Enums = 0x4,
Declarations = 0x8 Declarations = 0x8
}; };
Q_DECLARE_FLAGS(SymbolTypes, SymbolType) Q_DECLARE_FLAGS(SymbolTypes, SymbolType)
static SymbolTypes AllTypes;
SearchSymbols(); SearchSymbols();
void setSymbolsToSearchFor(SymbolTypes types); void setSymbolsToSearchFor(SymbolTypes types);
...@@ -121,7 +139,7 @@ protected: ...@@ -121,7 +139,7 @@ protected:
void appendItem(const QString &name, void appendItem(const QString &name,
const QString &info, const QString &info,
ModelItemInfo::ItemType type, ModelItemInfo::ItemType type,
const CPlusPlus::Symbol *symbol); CPlusPlus::Symbol *symbol);
private: private:
QString findOrInsert(const QString &s) QString findOrInsert(const QString &s)
......
This diff is collapsed.
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef SYMBOLSFINDFILTER_H
#define SYMBOLSFINDFILTER_H
#include "searchsymbols.h"
#include <find/ifindfilter.h>
#include <find/searchresultwindow.h>
#include <QtCore/QFutureInterface>
#include <QtCore/QFutureWatcher>
#include <QtGui/QWidget>
#include <QtGui/QCheckBox>
#include <QtGui/QRadioButton>
namespace CppTools {
namespace Internal {
class CppModelManager;
class SymbolsFindFilter : public Find::IFindFilter
{
Q_OBJECT
public:
enum SearchScope {
SearchProjectsOnly,
SearchGlobal
};
explicit SymbolsFindFilter(CppModelManager *manager);
QString id() const;
QString displayName() const;
bool isEnabled() const;
Find::FindFlags supportedFindFlags() const;
void findAll(const QString &txt, Find::FindFlags findFlags);
QWidget *createConfigWidget();
void writeSettings(QSettings *settings);
void readSettings(QSettings *settings);
void setSymbolsToSearch(SearchSymbols::SymbolTypes types) { m_symbolsToSearch = types; }
SearchSymbols::SymbolTypes symbolsToSearch() const { return m_symbolsToSearch; }
void setSearchScope(SearchScope scope) { m_scope = scope; }
SearchScope searchScope() const { return m_scope; }
signals:
void symbolsToSearchChanged();
private slots:
void openEditor(const Find::SearchResultItem &item);
void addResults(int begin, int end);
void finish();
void onTaskStarted(const QString &type);
void onAllTasksFinished(const QString &type);
private:
CppModelManager *m_manager;
bool m_isRunning;
bool m_enabled;
QFutureWatcher<Find::SearchResultItem> m_watcher;
SearchSymbols::SymbolTypes m_symbolsToSearch;
SearchSymbols m_search;
SearchScope m_scope;
};
class SymbolsFindFilterConfigWidget : public QWidget
{
Q_OBJECT
public:
SymbolsFindFilterConfigWidget(SymbolsFindFilter *filter);
private slots:
void setState() const;
void getState();
private:
SymbolsFindFilter *m_filter;
QCheckBox *m_typeClasses;
QCheckBox *m_typeMethods;
QCheckBox *m_typeEnums;
QCheckBox *m_typeDeclarations;
QRadioButton *m_searchGlobal;
QRadioButton *m_searchProjectsOnly;
QButtonGroup *m_searchGroup;
};
} // Internal
} // CppTools
#endif // SYMBOLSFINDFILTER_H
...@@ -34,9 +34,9 @@ ...@@ -34,9 +34,9 @@
#include "textfindconstants.h" #include "textfindconstants.h"
#include <QtGui/QTextDocument> #include <QtGui/QTextDocument>
#include <QtGui/QKeySequence>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QKeySequence;
class QWidget; class QWidget;
class QSettings; class QSettings;
QT_END_NAMESPACE QT_END_NAMESPACE
...@@ -53,7 +53,7 @@ public: ...@@ -53,7 +53,7 @@ public:
virtual QString id() const = 0; virtual QString id() const = 0;
virtual QString displayName() const = 0; virtual QString displayName() const = 0;
virtual bool isEnabled() const = 0; virtual bool isEnabled() const = 0;
virtual QKeySequence defaultShortcut() const = 0; virtual QKeySequence defaultShortcut() const { return QKeySequence(); }
virtual bool isReplaceSupported() const { return false; } virtual bool isReplaceSupported() const { return false; }
virtual FindFlags supportedFindFlags() const; virtual FindFlags supportedFindFlags() const;
......
...@@ -48,53 +48,77 @@ SearchResultTreeItemDelegate::SearchResultTreeItemDelegate(QObject *parent) ...@@ -48,53 +48,77 @@ SearchResultTreeItemDelegate::SearchResultTreeItemDelegate(QObject *parent)
void SearchResultTreeItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const void SearchResultTreeItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{ {
if (index.model()->data(index, ItemDataRoles::TypeRole).toString().compare(QLatin1String("file")) == 0) { painter->save();
QItemDelegate::paint(painter, option, index);
} else {
painter->save();
QStyleOptionViewItemV3 opt = setOptions(index, option); QStyleOptionViewItemV3 opt = setOptions(index, option);
painter->setFont(opt.font); painter->setFont(opt.font);
QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawBackground(painter, opt, index);
int lineNumberAreaWidth = drawLineNumber(painter, opt, index); int iconAreaWidth = drawIcon(painter, opt, opt.rect, index);
QRect resultRowRect(opt.rect.adjusted(iconAreaWidth, 0, 0, 0));
QRect resultRowRect(opt.rect.adjusted(lineNumberAreaWidth, 0, 0, 0)); int lineNumberAreaWidth = drawLineNumber(painter, opt, resultRowRect, index);
QString displayString = index.model()->data(index, Qt::DisplayRole).toString(); resultRowRect.adjust(lineNumberAreaWidth, 0, 0, 0);
drawMarker(painter, index, displayString, resultRowRect);
// Draw the text and focus/selection QString displayString = index.model()->data(index, Qt::DisplayRole).toString();
QItemDelegate::drawDisplay(painter, opt, resultRowRect, displayString); drawMarker(painter, index, displayString, resultRowRect);
QItemDelegate::drawFocus(painter, opt, opt.rect);
QVariant value = index.data(Qt::CheckStateRole); // Show number of subresults in displayString
if (value.isValid()) { if (index.model()->hasChildren(index)) {
Qt::CheckState checkState = Qt::Unchecked; displayString += QString::fromLatin1(" (")
checkState = static_cast<Qt::CheckState>(value.toInt()); + QString::number(index.model()->rowCount(index))
QRect checkRect = check(opt, opt.rect, value); + QLatin1Char(')');
}
// Draw the text and focus/selection
QItemDelegate::drawDisplay(painter, opt, resultRowRect, displayString);
QItemDelegate::drawFocus(painter, opt, opt.rect);
QRect emptyRect; QVariant value = index.data(Qt::CheckStateRole);
doLayout(opt, &checkRect, &emptyRect, &emptyRect, false); if (value.isValid()) {
Qt::CheckState checkState = Qt::Unchecked;
checkState = static_cast<Qt::CheckState>(value.toInt());
QRect checkRect = check(opt, opt.rect, value);
QItemDelegate::drawCheck(painter, opt, checkRect, checkState); QRect emptyRect;
} doLayout(opt, &checkRect, &emptyRect, &emptyRect, false);
painter->restore(); QItemDelegate::drawCheck(painter, opt, checkRect