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
<dependency name="TextEditor" version="2.1.80"/>
<dependency name="ProjectExplorer" version="2.1.80"/>
<dependency name="Locator" version="2.1.80"/>
<dependency name="Find" version="2.1.80"/>
</dependencyList>
</plugin>
......@@ -31,8 +31,8 @@
using namespace CppTools::Internal;
CppClassesFilter::CppClassesFilter(CppModelManager *manager, Core::EditorManager *editorManager)
: CppLocatorFilter(manager, editorManager)
CppClassesFilter::CppClassesFilter(CppModelManager *manager)
: CppLocatorFilter(manager)
{
setShortcutString("c");
setIncludedByDefault(false);
......
......@@ -40,7 +40,7 @@ class CppClassesFilter : public CppLocatorFilter
Q_OBJECT
public:
CppClassesFilter(CppModelManager *manager, Core::EditorManager *editorManager);
CppClassesFilter(CppModelManager *manager);
~CppClassesFilter();
QString displayName() const { return tr("Classes"); }
......
......@@ -313,7 +313,11 @@ void CppFindReferences::searchFinished()
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 @@
using namespace CppTools::Internal;
CppFunctionsFilter::CppFunctionsFilter(CppModelManager *manager, Core::EditorManager *editorManager)
: CppLocatorFilter(manager, editorManager)
CppFunctionsFilter::CppFunctionsFilter(CppModelManager *manager)
: CppLocatorFilter(manager)
{
setShortcutString(QString(QLatin1Char('m')));
setIncludedByDefault(false);
......
......@@ -40,7 +40,7 @@ class CppFunctionsFilter : public CppLocatorFilter
Q_OBJECT
public:
CppFunctionsFilter(CppModelManager *manager, Core::EditorManager *editorManager);
CppFunctionsFilter(CppModelManager *manager);
~CppFunctionsFilter();
QString displayName() const { return tr("Methods"); }
......
......@@ -30,8 +30,6 @@
#include "cpplocatorfilter.h"
#include "cppmodelmanager.h"
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <texteditor/itexteditor.h>
#include <texteditor/basetexteditor.h>
......@@ -39,9 +37,8 @@
using namespace CppTools::Internal;
CppLocatorFilter::CppLocatorFilter(CppModelManager *manager, Core::EditorManager *editorManager)
CppLocatorFilter::CppLocatorFilter(CppModelManager *manager)
: m_manager(manager),
m_editorManager(editorManager),
m_forceNewSearchList(true)
{
setShortcutString(QString(QLatin1Char(':')));
......
......@@ -34,10 +34,6 @@
#include <locator/ilocatorfilter.h>
namespace Core {
class EditorManager;
}
namespace CppTools {
namespace Internal {
......@@ -47,7 +43,7 @@ class CppLocatorFilter : public Locator::ILocatorFilter
{
Q_OBJECT
public:
CppLocatorFilter(CppModelManager *manager, Core::EditorManager *editorManager);
CppLocatorFilter(CppModelManager *manager);
~CppLocatorFilter();
QString displayName() const { return tr("Classes and Methods"); }
......@@ -66,7 +62,6 @@ private slots:
private:
CppModelManager *m_manager;
Core::EditorManager *m_editorManager;
struct Info {
Info(): dirty(true) {}
......
......@@ -24,7 +24,8 @@ HEADERS += completionsettingspage.h \
cppdoxygen.h \
cppfilesettingspage.h \
cppfindreferences.h \
cppcodeformatter.h
cppcodeformatter.h \
symbolsfindfilter.h
SOURCES += completionsettingspage.cpp \
cppclassesfilter.cpp \
......@@ -40,7 +41,8 @@ SOURCES += completionsettingspage.cpp \
cppfilesettingspage.cpp \
abstracteditorsupport.cpp \
cppfindreferences.cpp \
cppcodeformatter.cpp
cppcodeformatter.cpp \
symbolsfindfilter.cpp
FORMS += completionsettingspage.ui \
cppfilesettingspage.ui
......
include($$IDE_SOURCE_TREE/src/libs/cplusplus/cplusplus.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/find/find.pri)
......@@ -37,6 +37,7 @@
#include "cppmodelmanager.h"
#include "cpptoolsconstants.h"
#include "cpplocatorfilter.h"
#include "symbolsfindfilter.h"
#include <extensionsystem/pluginmanager.h>
......@@ -111,14 +112,13 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
CppCodeCompletion *completion = new CppCodeCompletion(m_modelManager);
addAutoReleasedObject(completion);
CppLocatorFilter *locatorFilter = new CppLocatorFilter(m_modelManager,
core->editorManager());
addAutoReleasedObject(locatorFilter);
addAutoReleasedObject(new CppClassesFilter(m_modelManager, core->editorManager()));
addAutoReleasedObject(new CppFunctionsFilter(m_modelManager, core->editorManager()));
addAutoReleasedObject(new CppLocatorFilter(m_modelManager));
addAutoReleasedObject(new CppClassesFilter(m_modelManager));
addAutoReleasedObject(new CppFunctionsFilter(m_modelManager));
addAutoReleasedObject(new CppCurrentDocumentFilter(m_modelManager, core->editorManager()));
addAutoReleasedObject(new CompletionSettingsPage);
addAutoReleasedObject(new CppFileSettingsPage(m_fileSettings));
addAutoReleasedObject(new SymbolsFindFilter(m_modelManager));
// Menus
Core::ActionContainer *mtools = am->actionContainer(Core::Constants::M_TOOLS);
......
......@@ -32,10 +32,17 @@
#include <Literals.h>
#include <Scope.h>
#include <Names.h>
#include <cplusplus/LookupContext.h>
using namespace CPlusPlus;
using namespace CppTools::Internal;
SearchSymbols::SymbolTypes SearchSymbols::AllTypes =
SearchSymbols::Classes
| SearchSymbols::Functions
| SearchSymbols::Enums
| SearchSymbols::Declarations;
SearchSymbols::SearchSymbols():
symbolsToSearchFor(Classes | Functions | Enums),
separateScope(false)
......@@ -204,13 +211,17 @@ QString SearchSymbols::symbolName(const Symbol *symbol) const
void SearchSymbols::appendItem(const QString &name,
const QString &info,
ModelItemInfo::ItemType type,
const Symbol *symbol)
Symbol *symbol)
{
if (!symbol->name())
return;
QStringList fullyQualifiedName;
foreach (const Name *name, LookupContext::fullyQualifiedName(symbol))
fullyQualifiedName.append(overview.prettyName(name));
const QIcon icon = icons.iconForSymbol(symbol);
items.append(ModelItemInfo(name, info, type,
fullyQualifiedName,
QString::fromUtf8(symbol->fileName(), symbol->fileNameLength()),
symbol->line(),
symbol->column() - 1, // 1-based vs 0-based column
......
......@@ -52,12 +52,14 @@ struct ModelItemInfo
ModelItemInfo()
: type(Declaration),
line(0)
line(0),
column(0)
{ }
ModelItemInfo(const QString &symbolName,
const QString &symbolType,
ItemType type,
QStringList fullyQualifiedName,
const QString &fileName,
int line,
int column,
......@@ -65,15 +67,28 @@ struct ModelItemInfo
: symbolName(symbolName),
symbolType(symbolType),
type(type),
fullyQualifiedName(fullyQualifiedName),
fileName(fileName),
line(line),
column(column),
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 symbolType;
ItemType type;
QStringList fullyQualifiedName;
QString fileName;
int line;
int column;
......@@ -90,8 +105,11 @@ public:
Enums = 0x4,
Declarations = 0x8
};
Q_DECLARE_FLAGS(SymbolTypes, SymbolType)
static SymbolTypes AllTypes;
SearchSymbols();
void setSymbolsToSearchFor(SymbolTypes types);
......@@ -121,7 +139,7 @@ protected:
void appendItem(const QString &name,
const QString &info,
ModelItemInfo::ItemType type,
const CPlusPlus::Symbol *symbol);
CPlusPlus::Symbol *symbol);
private:
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 @@
#include "textfindconstants.h"
#include <QtGui/QTextDocument>
#include <QtGui/QKeySequence>
QT_BEGIN_NAMESPACE
class QKeySequence;
class QWidget;
class QSettings;
QT_END_NAMESPACE
......@@ -53,7 +53,7 @@ public:
virtual QString id() const = 0;
virtual QString displayName() 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 FindFlags supportedFindFlags() const;
......
......@@ -48,53 +48,77 @@ SearchResultTreeItemDelegate::SearchResultTreeItemDelegate(QObject *parent)
void SearchResultTreeItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (index.model()->data(index, ItemDataRoles::TypeRole).toString().compare(QLatin1String("file")) == 0) {
QItemDelegate::paint(painter, option, index);
} else {
painter->save();
painter->save();
QStyleOptionViewItemV3 opt = setOptions(index, option);
painter->setFont(opt.font);
QStyleOptionViewItemV3 opt = setOptions(index, option);
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));
QString displayString = index.model()->data(index, Qt::DisplayRole).toString();
drawMarker(painter, index, displayString, resultRowRect);
int lineNumberAreaWidth = drawLineNumber(painter, opt, resultRowRect, index);
resultRowRect.adjust(lineNumberAreaWidth, 0, 0, 0);
// Draw the text and focus/selection
QItemDelegate::drawDisplay(painter, opt, resultRowRect, displayString);
QItemDelegate::drawFocus(painter, opt, opt.rect);
QString displayString = index.model()->data(index, Qt::DisplayRole).toString();
drawMarker(painter, index, displayString, resultRowRect);
QVariant value = index.data(Qt::CheckStateRole);
if (value.isValid()) {
Qt::CheckState checkState = Qt::Unchecked;
checkState = static_cast<Qt::CheckState>(value.toInt());
QRect checkRect = check(opt, opt.rect, value);
// Show number of subresults in displayString
if (index.model()->hasChildren(index)) {
displayString += QString::fromLatin1(" (")
+ QString::number(index.model()->rowCount(index))
+ QLatin1Char(')');
}
// Draw the text and focus/selection
QItemDelegate::drawDisplay(painter, opt, resultRowRect, displayString);
QItemDelegate::drawFocus(painter, opt, opt.rect);
QRect emptyRect;
doLayout(opt, &checkRect, &emptyRect, &emptyRect, false);
QVariant value = index.data(Qt::CheckStateRole);
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, checkState);
}
painter->restore();
}
int SearchResultTreeItemDelegate::drawIcon(QPainter *painter, const QStyleOptionViewItemV3 &option,
const QRect &rect,
const QModelIndex &index) const
{
static const int iconWidth = 16;
static const int iconPadding = 4;
QIcon icon = index.model()->data(index, ItemDataRoles::ResultIconRole).value<QIcon>();
if (icon.isNull())
return 0;
QRect iconRect = rect.adjusted(iconPadding, 0, /*is set below anyhow*/0, 0);
iconRect.setWidth(iconWidth);
QItemDelegate::drawDecoration(painter, option, iconRect, icon.pixmap(iconWidth));
return iconWidth + iconPadding;
}
int SearchResultTreeItemDelegate::drawLineNumber(QPainter *painter, const QStyleOptionViewItemV3 &option,
const QRect &rect,
const QModelIndex &index) const
{
static const int lineNumberAreaHorizontalPadding = 4;
const bool isSelected = option.state & QStyle::State_Selected;
int lineNumber = index.model()->data(index, ItemDataRoles::ResultLineNumberRole).toInt();
if (lineNumber < 1)
return 0;
const bool isSelected = option.state & QStyle::State_Selected;
int lineNumberDigits = (int)floor(log10((double)lineNumber)) + 1;
int minimumLineNumberDigits = qMax((int)m_minimumLineNumberDigits, lineNumberDigits);
int fontWidth = painter->fontMetrics().width(QString(minimumLineNumberDigits, QLatin1Char('0')));
int lineNumberAreaWidth = lineNumberAreaHorizontalPadding + fontWidth + lineNumberAreaHorizontalPadding;
QRect lineNumberAreaRect(option.rect);
QRect lineNumberAreaRect(rect);
lineNumberAreaRect.setWidth(lineNumberAreaWidth);
QPalette::ColorGroup cg = QPalette::Normal;
......@@ -123,10 +147,12 @@ int SearchResultTreeItemDelegate::drawLineNumber(QPainter *painter, const QStyle
void SearchResultTreeItemDelegate::drawMarker(QPainter *painter, const QModelIndex &index, const QString text,
const QRect &rect) const
{
const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
int searchTermStart = index.model()->data(index, ItemDataRoles::SearchTermStartRole).toInt();
int searchTermStartPixels = painter->fontMetrics().width(text.left(searchTermStart));
int searchTermLength = index.model()->data(index, ItemDataRoles::SearchTermLengthRole).toInt();
if (searchTermStart < 0 || searchTermLength < 1)
return;
const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
int searchTermStartPixels = painter->fontMetrics().width(text.left(searchTermStart));
int searchTermLengthPixels = painter->fontMetrics().width(text.mid(searchTermStart, searchTermLength));
QRect resultHighlightRect(rect);
resultHighlightRect.setLeft(resultHighlightRect.left() + searchTermStartPixels + textMargin - 1); // -1: Cosmetics
......
......@@ -42,7 +42,8 @@ public:
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
private:
int drawLineNumber(QPainter *painter, const QStyleOptionViewItemV3 &option, const QModelIndex &index) const;
int drawIcon(QPainter *painter, const QStyleOptionViewItemV3 &option, const QRect &rect, const QModelIndex &index) const;
int drawLineNumber(QPainter *painter, const QStyleOptionViewItemV3 &option, const QRect &rect, const QModelIndex &index) const;
void drawMarker(QPainter *painter, const QModelIndex &index, const QString text, const QRect &rect) const;
static const int m_minimumLineNumberDigits = 6;
......
......@@ -30,22 +30,21 @@
#ifndef SEARCHRESULTTREEITEMROLES_H
#define SEARCHRESULTTREEITEMROLES_H
#include <QtGui/QAbstractItemView>
namespace Find {
namespace Internal {
namespace ItemDataRoles {
enum Roles
{
TypeRole = Qt::UserRole,
FileNameRole,
ResultLinesCountRole,
ResultIndexRole,
ResultItemRole = Qt::UserRole,
ResultLineRole,
ResultLineNumberRole,
ResultIconRole,
SearchTermStartRole,
SearchTermLengthRole,
RowOfItem, // The ?-th child of its parent is this this item
TextRole // for files == FileNameRole, for results == ResultLineRole
RowOfItem // The ?-th child of its parent is this this item
};
} // namespace Internal
......
......@@ -31,8 +31,13 @@
using namespace Find::Internal;
SearchResultTreeItem::SearchResultTreeItem(SearchResultTreeItem::ItemType type, const SearchResultTreeItem *parent)
: m_type(type), m_parent(parent), m_isUserCheckable(false), m_checkState(Qt::Unchecked)
SearchResultTreeItem::SearchResultTreeItem(const SearchResultItem &item,
const SearchResultTreeItem *parent)
: item(item),
m_parent(parent),
m_isUserCheckable(false),
m_checkState(Qt::Unchecked),
m_isGenerated(false)
{
}
......@@ -41,6 +46,11 @@ SearchResultTreeItem::~SearchResultTreeItem()
clearChildren();
}
bool SearchResultTreeItem::isLeaf() const
{
return childrenCount() == 0 && parent() != 0;
}
bool SearchResultTreeItem::isUserCheckable() const
{
return m_isUserCheckable;
......@@ -67,11 +77,6 @@ void SearchResultTreeItem::clearChildren()
m_children.clear();
}
SearchResultTreeItem::ItemType SearchResultTreeItem::itemType() const
{
return m_type;
}
int SearchResultTreeItem::childrenCount() const
{
return m_children.count();
......@@ -92,85 +97,46 @@ const SearchResultTreeItem *SearchResultTreeItem::parent() const
return m_parent;
}
static bool compareResultFiles(SearchResultTreeItem *a, SearchResultTreeItem *b)
{
return static_cast<SearchResultFile *>(a)->fileName() <
static_cast<SearchResultFile *>(b)->fileName();