QmlOutline: Add filter for hiding bindings (properties)

This commit is contained in:
Kai Koehne
2010-07-14 16:46:54 +02:00
parent d764bcac39
commit 679ccc3b74
14 changed files with 141 additions and 6 deletions

View File

@@ -3,6 +3,7 @@
#include <coreplugin/ifile.h>
#include <coreplugin/editormanager/editormanager.h>
#include <QtGui/QAction>
#include <QtGui/QVBoxLayout>
#include <QDebug>
@@ -29,18 +30,57 @@ QmlJSOutlineTreeView::QmlJSOutlineTreeView(QWidget *parent) :
setExpandsOnDoubleClick(false);
}
QmlJSOutlineFilterModel::QmlJSOutlineFilterModel(QObject *parent) :
QSortFilterProxyModel(parent)
{
}
bool QmlJSOutlineFilterModel::filterAcceptsRow(int sourceRow,
const QModelIndex &sourceParent) const
{
if (m_filterBindings) {
QModelIndex sourceIndex = sourceModel()->index(sourceRow, 0, sourceParent);
if (sourceIndex.data(QmlOutlineModel::ItemTypeRole) == QmlOutlineModel::PropertyType) {
return false;
}
}
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
}
bool QmlJSOutlineFilterModel::filterBindings() const
{
return m_filterBindings;
}
void QmlJSOutlineFilterModel::setFilterBindings(bool filterBindings)
{
if (m_filterBindings != filterBindings) {
m_filterBindings = filterBindings;
invalidateFilter();
}
}
QmlJSOutlineWidget::QmlJSOutlineWidget(QWidget *parent) :
TextEditor::IOutlineWidget(parent),
m_treeView(new QmlJSOutlineTreeView(this)),
m_filterModel(new QmlJSOutlineFilterModel(this)),
m_enableCursorSync(true),
m_blockCursorSync(false)
{
m_treeView->setModel(m_filterModel);
QVBoxLayout *layout = new QVBoxLayout;
layout->setMargin(0);
layout->setSpacing(0);
layout->addWidget(m_treeView);
m_showBindingsAction = new QAction(this);
m_showBindingsAction->setText(tr("Show bindings"));
m_showBindingsAction->setCheckable(true);
m_showBindingsAction->setChecked(true);
connect(m_showBindingsAction, SIGNAL(triggered(bool)), this, SLOT(setShowBindings(bool)));
setLayout(layout);
}
@@ -48,7 +88,7 @@ void QmlJSOutlineWidget::setEditor(QmlJSTextEditor *editor)
{
m_editor = editor;
m_treeView->setModel(m_editor.data()->outlineModel());
m_filterModel->setSourceModel(m_editor.data()->outlineModel());
modelUpdated();
connect(m_treeView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
@@ -60,6 +100,13 @@ void QmlJSOutlineWidget::setEditor(QmlJSTextEditor *editor)
this, SLOT(modelUpdated()));
}
QList<QAction*> QmlJSOutlineWidget::filterMenuActions() const
{
QList<QAction*> list;
list.append(m_showBindingsAction);
return list;
}
void QmlJSOutlineWidget::setCursorSynchronization(bool syncWithCursor)
{
m_enableCursorSync = syncWithCursor;
@@ -78,7 +125,7 @@ void QmlJSOutlineWidget::updateSelectionInTree(const QModelIndex &index)
return;
m_blockCursorSync = true;
m_treeView->selectionModel()->select(index, QItemSelectionModel::ClearAndSelect);
m_treeView->selectionModel()->select(m_filterModel->mapFromSource(index), QItemSelectionModel::ClearAndSelect);
m_treeView->scrollTo(index);
m_blockCursorSync = false;
}
@@ -105,6 +152,12 @@ void QmlJSOutlineWidget::updateSelectionInText(const QItemSelection &selection)
}
}
void QmlJSOutlineWidget::setShowBindings(bool showBindings)
{
m_filterModel->setFilterBindings(!showBindings);
modelUpdated();
}
bool QmlJSOutlineWidget::syncCursor()
{
return m_enableCursorSync && !m_blockCursorSync;