Commit d3c4f329 authored by Kai Koehne's avatar Kai Koehne

CppEditor: Don't show 'generated' symbols in the outline

Don't show e.g. all the methods that are defined by the Q_OBJECT
macro in the outline. We skip these by checking for Symbol->isGenerated
in the two proxy models used.
parent 82497a95
......@@ -189,6 +189,32 @@ public:
}
};
class OverviewProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
OverviewProxyModel(CPlusPlus::OverviewModel *sourceModel, QObject *parent) :
QSortFilterProxyModel(parent),
m_sourceModel(sourceModel)
{
setSourceModel(m_sourceModel);
}
bool filterAcceptsRow(int sourceRow,const QModelIndex &sourceParent) const
{
// ignore generated symbols, e.g. by macro expansion (Q_OBJECT)
const QModelIndex sourceIndex = m_sourceModel->index(sourceRow, 0, sourceParent);
CPlusPlus::Symbol *symbol = m_sourceModel->symbolFromIndex(sourceIndex);
if (symbol && symbol->isGenerated())
return false;
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
}
private:
CPlusPlus::OverviewModel *m_sourceModel;
};
class FindLocalUses: protected ASTVisitor
{
Scope *_functionScope;
......@@ -653,8 +679,7 @@ void CPPEditor::createToolBar(CPPEditorEditable *editable)
m_methodCombo->setMaxVisibleItems(20);
m_overviewModel = new OverviewModel(this);
m_proxyModel = new QSortFilterProxyModel(this);
m_proxyModel->setSourceModel(m_overviewModel);
m_proxyModel = new OverviewProxyModel(m_overviewModel, this);
if (CppPlugin::instance()->sortedMethodOverview())
m_proxyModel->sort(0, Qt::AscendingOrder);
else
......@@ -2189,3 +2214,5 @@ QModelIndex CPPEditor::indexForPosition(int line, int column, const QModelIndex
return lastIndex;
}
#include "cppeditor.moc"
......@@ -30,9 +30,11 @@ CppOutlineTreeView::CppOutlineTreeView(QWidget *parent) :
setExpandsOnDoubleClick(false);
}
CppOutlineFilterModel::CppOutlineFilterModel(QObject *parent) :
QSortFilterProxyModel(parent)
CppOutlineFilterModel::CppOutlineFilterModel(CPlusPlus::OverviewModel *sourceModel, QObject *parent) :
QSortFilterProxyModel(parent),
m_sourceModel(sourceModel)
{
setSourceModel(m_sourceModel);
}
bool CppOutlineFilterModel::filterAcceptsRow(int sourceRow,
......@@ -42,6 +44,12 @@ bool CppOutlineFilterModel::filterAcceptsRow(int sourceRow,
if (!sourceParent.isValid() && sourceRow == 0) {
return false;
}
// ignore generated symbols, e.g. by macro expansion (Q_OBJECT)
const QModelIndex sourceIndex = m_sourceModel->index(sourceRow, 0, sourceParent);
CPlusPlus::Symbol *symbol = m_sourceModel->symbolFromIndex(sourceIndex);
if (symbol && symbol->isGenerated())
return false;
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
}
......@@ -51,7 +59,7 @@ CppOutlineWidget::CppOutlineWidget(CPPEditor *editor) :
m_editor(editor),
m_treeView(new CppOutlineTreeView(this)),
m_model(m_editor->overviewModel()),
m_proxyModel(new CppOutlineFilterModel(this)),
m_proxyModel(new CppOutlineFilterModel(m_model, this)),
m_enableCursorSync(true),
m_blockCursorSync(false)
{
......@@ -61,7 +69,6 @@ CppOutlineWidget::CppOutlineWidget(CPPEditor *editor) :
layout->addWidget(m_treeView);
setLayout(layout);
m_proxyModel->setSourceModel(m_model);
m_treeView->setModel(m_proxyModel);
connect(m_model, SIGNAL(modelReset()), this, SLOT(modelUpdated()));
......
......@@ -22,10 +22,12 @@ class CppOutlineFilterModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
CppOutlineFilterModel(QObject *parent);
CppOutlineFilterModel(CPlusPlus::OverviewModel *sourceModel, QObject *parent);
// QSortFilterProxyModel
bool filterAcceptsRow(int sourceRow,
const QModelIndex &sourceParent) const;
private:
CPlusPlus::OverviewModel *m_sourceModel;
};
class CppOutlineWidget : public TextEditor::IOutlineWidget
......
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