Commit 679ccc3b authored by Kai Koehne's avatar Kai Koehne
Browse files

QmlOutline: Add filter for hiding bindings (properties)

parent d764bcac
...@@ -65,5 +65,6 @@ ...@@ -65,5 +65,6 @@
<file>images/category_cpp.png</file> <file>images/category_cpp.png</file>
<file>images/category_vcs.png</file> <file>images/category_vcs.png</file>
<file>images/category_qml.png</file> <file>images/category_qml.png</file>
<file>images/filtericon.png</file>
</qresource> </qresource>
</RCC> </RCC>
...@@ -81,6 +81,11 @@ CppOutlineWidget::CppOutlineWidget(CPPEditor *editor) : ...@@ -81,6 +81,11 @@ CppOutlineWidget::CppOutlineWidget(CPPEditor *editor) :
this, SLOT(updateSelectionInText(QItemSelection))); this, SLOT(updateSelectionInText(QItemSelection)));
} }
QList<QAction*> CppOutlineWidget::filterMenuActions() const
{
return QList<QAction*>();
}
void CppOutlineWidget::setCursorSynchronization(bool syncWithCursor) void CppOutlineWidget::setCursorSynchronization(bool syncWithCursor)
{ {
m_enableCursorSync = syncWithCursor; m_enableCursorSync = syncWithCursor;
......
...@@ -37,6 +37,7 @@ public: ...@@ -37,6 +37,7 @@ public:
CppOutlineWidget(CPPEditor *editor); CppOutlineWidget(CPPEditor *editor);
// IOutlineWidget // IOutlineWidget
virtual QList<QAction*> filterMenuActions() const;
virtual void setCursorSynchronization(bool syncWithCursor); virtual void setCursorSynchronization(bool syncWithCursor);
private slots: private slots:
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
<file>images/closetab.png</file> <file>images/closetab.png</file>
<file>images/debugger_start.png</file> <file>images/debugger_start.png</file>
<file>images/debugger_start_small.png</file> <file>images/debugger_start_small.png</file>
<file>images/filtericon.png</file>
<file>images/projectexplorer.png</file> <file>images/projectexplorer.png</file>
<file>images/rebuild.png</file> <file>images/rebuild.png</file>
<file>images/rebuild_small.png</file> <file>images/rebuild_small.png</file>
......
...@@ -396,7 +396,7 @@ Core::NavigationView ProjectTreeWidgetFactory::createWidget() ...@@ -396,7 +396,7 @@ Core::NavigationView ProjectTreeWidgetFactory::createWidget()
n.widget = ptw; n.widget = ptw;
QToolButton *filter = new QToolButton; QToolButton *filter = new QToolButton;
filter->setIcon(QIcon(":/projectexplorer/images/filtericon.png")); filter->setIcon(QIcon(":/core/images/filtericon.png"));
filter->setToolTip(tr("Filter tree")); filter->setToolTip(tr("Filter tree"));
filter->setPopupMode(QToolButton::InstantPopup); filter->setPopupMode(QToolButton::InstantPopup);
QMenu *filterMenu = new QMenu(filter); QMenu *filterMenu = new QMenu(filter);
......
...@@ -560,7 +560,7 @@ TaskWindow::TaskWindow(TaskHub *taskhub) : d(new TaskWindowPrivate) ...@@ -560,7 +560,7 @@ TaskWindow::TaskWindow(TaskHub *taskhub) : d(new TaskWindowPrivate)
connect(d->m_categoriesMenu, SIGNAL(triggered(QAction*)), this, SLOT(filterCategoryTriggered(QAction*))); connect(d->m_categoriesMenu, SIGNAL(triggered(QAction*)), this, SLOT(filterCategoryTriggered(QAction*)));
d->m_categoriesButton = new QToolButton; d->m_categoriesButton = new QToolButton;
d->m_categoriesButton->setIcon(QIcon(":/projectexplorer/images/filtericon.png")); d->m_categoriesButton->setIcon(QIcon(":/core/images/filtericon.png"));
d->m_categoriesButton->setToolTip(tr("Filter by categories")); d->m_categoriesButton->setToolTip(tr("Filter by categories"));
d->m_categoriesButton->setAutoRaise(true); d->m_categoriesButton->setAutoRaise(true);
d->m_categoriesButton->setPopupMode(QToolButton::InstantPopup); d->m_categoriesButton->setPopupMode(QToolButton::InstantPopup);
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <coreplugin/ifile.h> #include <coreplugin/ifile.h>
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <QtGui/QAction>
#include <QtGui/QVBoxLayout> #include <QtGui/QVBoxLayout>
#include <QDebug> #include <QDebug>
...@@ -29,18 +30,57 @@ QmlJSOutlineTreeView::QmlJSOutlineTreeView(QWidget *parent) : ...@@ -29,18 +30,57 @@ QmlJSOutlineTreeView::QmlJSOutlineTreeView(QWidget *parent) :
setExpandsOnDoubleClick(false); 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) : QmlJSOutlineWidget::QmlJSOutlineWidget(QWidget *parent) :
TextEditor::IOutlineWidget(parent), TextEditor::IOutlineWidget(parent),
m_treeView(new QmlJSOutlineTreeView(this)), m_treeView(new QmlJSOutlineTreeView(this)),
m_filterModel(new QmlJSOutlineFilterModel(this)),
m_enableCursorSync(true), m_enableCursorSync(true),
m_blockCursorSync(false) m_blockCursorSync(false)
{ {
m_treeView->setModel(m_filterModel);
QVBoxLayout *layout = new QVBoxLayout; QVBoxLayout *layout = new QVBoxLayout;
layout->setMargin(0); layout->setMargin(0);
layout->setSpacing(0); layout->setSpacing(0);
layout->addWidget(m_treeView); 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); setLayout(layout);
} }
...@@ -48,7 +88,7 @@ void QmlJSOutlineWidget::setEditor(QmlJSTextEditor *editor) ...@@ -48,7 +88,7 @@ void QmlJSOutlineWidget::setEditor(QmlJSTextEditor *editor)
{ {
m_editor = editor; m_editor = editor;
m_treeView->setModel(m_editor.data()->outlineModel()); m_filterModel->setSourceModel(m_editor.data()->outlineModel());
modelUpdated(); modelUpdated();
connect(m_treeView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), connect(m_treeView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
...@@ -60,6 +100,13 @@ void QmlJSOutlineWidget::setEditor(QmlJSTextEditor *editor) ...@@ -60,6 +100,13 @@ void QmlJSOutlineWidget::setEditor(QmlJSTextEditor *editor)
this, SLOT(modelUpdated())); this, SLOT(modelUpdated()));
} }
QList<QAction*> QmlJSOutlineWidget::filterMenuActions() const
{
QList<QAction*> list;
list.append(m_showBindingsAction);
return list;
}
void QmlJSOutlineWidget::setCursorSynchronization(bool syncWithCursor) void QmlJSOutlineWidget::setCursorSynchronization(bool syncWithCursor)
{ {
m_enableCursorSync = syncWithCursor; m_enableCursorSync = syncWithCursor;
...@@ -78,7 +125,7 @@ void QmlJSOutlineWidget::updateSelectionInTree(const QModelIndex &index) ...@@ -78,7 +125,7 @@ void QmlJSOutlineWidget::updateSelectionInTree(const QModelIndex &index)
return; return;
m_blockCursorSync = true; 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_treeView->scrollTo(index);
m_blockCursorSync = false; m_blockCursorSync = false;
} }
...@@ -105,6 +152,12 @@ void QmlJSOutlineWidget::updateSelectionInText(const QItemSelection &selection) ...@@ -105,6 +152,12 @@ void QmlJSOutlineWidget::updateSelectionInText(const QItemSelection &selection)
} }
} }
void QmlJSOutlineWidget::setShowBindings(bool showBindings)
{
m_filterModel->setFilterBindings(!showBindings);
modelUpdated();
}
bool QmlJSOutlineWidget::syncCursor() bool QmlJSOutlineWidget::syncCursor()
{ {
return m_enableCursorSync && !m_blockCursorSync; return m_enableCursorSync && !m_blockCursorSync;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <texteditor/ioutlinewidget.h> #include <texteditor/ioutlinewidget.h>
#include <QtGui/QTreeView> #include <QtGui/QTreeView>
#include <QtGui/QSortFilterProxyModel>
namespace Core { namespace Core {
class IEditor; class IEditor;
...@@ -25,6 +26,21 @@ public: ...@@ -25,6 +26,21 @@ public:
QmlJSOutlineTreeView(QWidget *parent = 0); QmlJSOutlineTreeView(QWidget *parent = 0);
}; };
class QmlJSOutlineFilterModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
QmlJSOutlineFilterModel(QObject *parent);
// QSortFilterProxyModel
bool filterAcceptsRow(int sourceRow,
const QModelIndex &sourceParent) const;
bool filterBindings() const;
void setFilterBindings(bool filterBindings);
private:
bool m_filterBindings;
};
class QmlJSOutlineWidget : public TextEditor::IOutlineWidget class QmlJSOutlineWidget : public TextEditor::IOutlineWidget
{ {
Q_OBJECT Q_OBJECT
...@@ -34,20 +50,25 @@ public: ...@@ -34,20 +50,25 @@ public:
void setEditor(QmlJSTextEditor *editor); void setEditor(QmlJSTextEditor *editor);
// IOutlineWidget // IOutlineWidget
virtual QList<QAction*> filterMenuActions() const;
virtual void setCursorSynchronization(bool syncWithCursor); virtual void setCursorSynchronization(bool syncWithCursor);
private slots: private slots:
void modelUpdated(); void modelUpdated();
void updateSelectionInTree(const QModelIndex &index); void updateSelectionInTree(const QModelIndex &index);
void updateSelectionInText(const QItemSelection &selection); void updateSelectionInText(const QItemSelection &selection);
void setShowBindings(bool showBindings);
private: private:
bool syncCursor(); bool syncCursor();
private: private:
QmlJSOutlineTreeView *m_treeView; QmlJSOutlineTreeView *m_treeView;
QmlJSOutlineFilterModel *m_filterModel;
QWeakPointer<QmlJSTextEditor> m_editor; QWeakPointer<QmlJSTextEditor> m_editor;
QAction *m_showBindingsAction;
bool m_enableCursorSync; bool m_enableCursorSync;
bool m_blockCursorSync; bool m_blockCursorSync;
}; };
......
...@@ -201,6 +201,22 @@ private: ...@@ -201,6 +201,22 @@ private:
int indent; int indent;
}; };
class OutlineItem : public QStandardItem
{
int type() const
{
return QStandardItem::UserType + 1;
}
QVariant data(int role = Qt::UserRole + 1) const
{
if (role == Qt::ToolTipRole) {
}
return QStandardItem::data(role);
}
};
QmlOutlineModel::QmlOutlineModel(QObject *parent) : QmlOutlineModel::QmlOutlineModel(QObject *parent) :
QStandardItemModel(parent) QStandardItemModel(parent)
{ {
...@@ -238,6 +254,7 @@ QModelIndex QmlOutlineModel::enterElement(const QString &type, const QString &id ...@@ -238,6 +254,7 @@ QModelIndex QmlOutlineModel::enterElement(const QString &type, const QString &id
} }
item->setIcon(icon); item->setIcon(icon);
item->setToolTip(type); item->setToolTip(type);
item->setData(ElementType, ItemTypeRole);
return item->index(); return item->index();
} }
...@@ -255,6 +272,7 @@ QModelIndex QmlOutlineModel::enterProperty(const QString &name, bool isCustomPro ...@@ -255,6 +272,7 @@ QModelIndex QmlOutlineModel::enterProperty(const QString &name, bool isCustomPro
} else { } else {
item->setIcon(m_icons->scriptBindingIcon()); item->setIcon(m_icons->scriptBindingIcon());
} }
item->setData(PropertyType, ItemTypeRole);
return item->index(); return item->index();
} }
......
...@@ -14,7 +14,13 @@ class QmlOutlineModel : public QStandardItemModel ...@@ -14,7 +14,13 @@ class QmlOutlineModel : public QStandardItemModel
Q_OBJECT Q_OBJECT
public: public:
enum CustomRoles { enum CustomRoles {
SourceLocationRole = Qt::UserRole + 1 SourceLocationRole = Qt::UserRole + 1,
ItemTypeRole = SourceLocationRole + 1
};
enum ItemTypes {
ElementType,
PropertyType
}; };
QmlOutlineModel(QObject *parent = 0); QmlOutlineModel(QObject *parent = 0);
......
...@@ -16,6 +16,7 @@ class TEXTEDITOR_EXPORT IOutlineWidget : public QWidget ...@@ -16,6 +16,7 @@ class TEXTEDITOR_EXPORT IOutlineWidget : public QWidget
public: public:
IOutlineWidget(QWidget *parent = 0) : QWidget(parent) {} IOutlineWidget(QWidget *parent = 0) : QWidget(parent) {}
virtual QList<QAction*> filterMenuActions() const = 0;
virtual void setCursorSynchronization(bool syncWithCursor) = 0; virtual void setCursorSynchronization(bool syncWithCursor) = 0;
}; };
......
#include "outlinefactory.h" #include "outlinefactory.h"
#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h> #include <coreplugin/editormanager/ieditor.h>
#include <QVBoxLayout> #include <QVBoxLayout>
...@@ -31,6 +32,14 @@ OutlineWidgetStack::OutlineWidgetStack(OutlineFactory *factory) : ...@@ -31,6 +32,14 @@ OutlineWidgetStack::OutlineWidgetStack(OutlineFactory *factory) :
m_toggleSync->setToolTip(tr("Synchronize with Editor")); m_toggleSync->setToolTip(tr("Synchronize with Editor"));
connect(m_toggleSync, SIGNAL(clicked(bool)), this, SLOT(toggleCursorSynchronization())); connect(m_toggleSync, SIGNAL(clicked(bool)), this, SLOT(toggleCursorSynchronization()));
m_filterButton = new QToolButton;
m_filterButton->setIcon(QIcon(":/core/images/filtericon.png"));
m_filterButton->setToolTip(tr("Filter tree"));
m_filterButton->setPopupMode(QToolButton::InstantPopup);
m_filterMenu = new QMenu(m_filterButton);
m_filterButton->setMenu(m_filterMenu);
connect(m_filterMenu, SIGNAL(aboutToShow()), this, SLOT(updateFilterMenu()));
Core::EditorManager *editorManager = Core::EditorManager::instance(); Core::EditorManager *editorManager = Core::EditorManager::instance();
connect(editorManager, SIGNAL(currentEditorChanged(Core::IEditor*)), connect(editorManager, SIGNAL(currentEditorChanged(Core::IEditor*)),
this, SLOT(updateCurrentEditor(Core::IEditor*))); this, SLOT(updateCurrentEditor(Core::IEditor*)));
...@@ -46,6 +55,11 @@ QToolButton *OutlineWidgetStack::toggleSyncButton() ...@@ -46,6 +55,11 @@ QToolButton *OutlineWidgetStack::toggleSyncButton()
return m_toggleSync; return m_toggleSync;
} }
QToolButton *OutlineWidgetStack::filterButton()
{
return m_filterButton;
}
bool OutlineWidgetStack::isCursorSynchronized() const bool OutlineWidgetStack::isCursorSynchronized() const
{ {
return m_syncWithEditor; return m_syncWithEditor;
...@@ -58,6 +72,16 @@ void OutlineWidgetStack::toggleCursorSynchronization() ...@@ -58,6 +72,16 @@ void OutlineWidgetStack::toggleCursorSynchronization()
outlineWidget->setCursorSynchronization(m_syncWithEditor); outlineWidget->setCursorSynchronization(m_syncWithEditor);
} }
void OutlineWidgetStack::updateFilterMenu()
{
m_filterMenu->clear();
if (IOutlineWidget *outlineWidget = qobject_cast<IOutlineWidget*>(currentWidget())) {
foreach (QAction *filterAction, outlineWidget->filterMenuActions()) {
m_filterMenu->addAction(filterAction);
}
}
}
void OutlineWidgetStack::updateCurrentEditor(Core::IEditor *editor) void OutlineWidgetStack::updateCurrentEditor(Core::IEditor *editor)
{ {
IOutlineWidget *newWidget = 0; IOutlineWidget *newWidget = 0;
...@@ -121,6 +145,7 @@ Core::NavigationView OutlineFactory::createWidget() ...@@ -121,6 +145,7 @@ Core::NavigationView OutlineFactory::createWidget()
OutlineWidgetStack *placeHolder = new OutlineWidgetStack(this); OutlineWidgetStack *placeHolder = new OutlineWidgetStack(this);
n.widget = placeHolder; n.widget = placeHolder;
n.dockToolBarWidgets.append(placeHolder->toggleSyncButton()); n.dockToolBarWidgets.append(placeHolder->toggleSyncButton());
n.dockToolBarWidgets.append(placeHolder->filterButton());
return n; return n;
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <texteditor/ioutlinewidget.h> #include <texteditor/ioutlinewidget.h>
#include <coreplugin/inavigationwidgetfactory.h> #include <coreplugin/inavigationwidgetfactory.h>
#include <QtGui/QStackedWidget> #include <QtGui/QStackedWidget>
#include <QtGui/QMenu>
namespace Core { namespace Core {
class IEditor; class IEditor;
...@@ -22,6 +23,7 @@ public: ...@@ -22,6 +23,7 @@ public:
~OutlineWidgetStack(); ~OutlineWidgetStack();
QToolButton *toggleSyncButton(); QToolButton *toggleSyncButton();
QToolButton *filterButton();
private: private:
bool isCursorSynchronized() const; bool isCursorSynchronized() const;
...@@ -29,12 +31,15 @@ private: ...@@ -29,12 +31,15 @@ private:
private slots: private slots:
void toggleCursorSynchronization(); void toggleCursorSynchronization();
void updateFilterMenu();
void updateCurrentEditor(Core::IEditor *editor); void updateCurrentEditor(Core::IEditor *editor);
private: private:
QStackedWidget *m_widgetStack; QStackedWidget *m_widgetStack;
OutlineFactory *m_factory; OutlineFactory *m_factory;
QToolButton *m_toggleSync; QToolButton *m_toggleSync;
QToolButton *m_filterButton;
QMenu *m_filterMenu;
bool m_syncWithEditor; bool m_syncWithEditor;
}; };
......
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