diff options
author | Kai Koehne <kai.koehne@nokia.com> | 2010-12-20 09:15:49 +0100 |
---|---|---|
committer | Kai Koehne <kai.koehne@nokia.com> | 2010-12-20 09:19:56 +0100 |
commit | 32f69b9b7790a71f182e4676337f98b0c1f181b0 (patch) | |
tree | 1f4d9ac4437bbfbf2b6cdadaea28a9be44bcf7b4 /src/plugins/qmljseditor | |
parent | befd304ca14385f459e746dc6cf8125884d358c1 (diff) | |
download | qt-creator-32f69b9b7790a71f182e4676337f98b0c1f181b0.tar.gz |
Outline: Add context menu for collapsing/expanding tree
Task-number: QTCREATORBUG-2976
Diffstat (limited to 'src/plugins/qmljseditor')
-rw-r--r-- | src/plugins/qmljseditor/qmljsoutlinetreeview.cpp | 27 | ||||
-rw-r--r-- | src/plugins/qmljseditor/qmljsoutlinetreeview.h | 5 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/plugins/qmljseditor/qmljsoutlinetreeview.cpp b/src/plugins/qmljseditor/qmljsoutlinetreeview.cpp index e0828ab840..b4da65cce6 100644 --- a/src/plugins/qmljseditor/qmljsoutlinetreeview.cpp +++ b/src/plugins/qmljseditor/qmljsoutlinetreeview.cpp @@ -2,6 +2,7 @@ #include "qmloutlinemodel.h" #include <utils/annotateditemdelegate.h> +#include <QtGui/QMenu> namespace QmlJSEditor { namespace Internal { @@ -26,5 +27,31 @@ QmlJSOutlineTreeView::QmlJSOutlineTreeView(QWidget *parent) : setItemDelegateForColumn(0, itemDelegate); } +void QmlJSOutlineTreeView::contextMenuEvent(QContextMenuEvent *event) +{ + if (!event) + return; + + QMenu contextMenu; + + contextMenu.addAction(tr("Expand All"), this, SLOT(expandAll())); + contextMenu.addAction(tr("Collapse All"), this, SLOT(collapseAllExceptRoot())); + + contextMenu.exec(event->globalPos()); + + event->accept(); +} + +void QmlJSOutlineTreeView::collapseAllExceptRoot() +{ + if (!model()) + return; + const QModelIndex rootElementIndex = model()->index(0, 0, rootIndex()); + int rowCount = model()->rowCount(rootElementIndex); + for (int i = 0; i < rowCount; ++i) { + collapse(model()->index(i, 0, rootElementIndex)); + } +} + } // namespace Internal } // namespace QmlJSEditor diff --git a/src/plugins/qmljseditor/qmljsoutlinetreeview.h b/src/plugins/qmljseditor/qmljsoutlinetreeview.h index a16afad081..8e337de321 100644 --- a/src/plugins/qmljseditor/qmljsoutlinetreeview.h +++ b/src/plugins/qmljseditor/qmljsoutlinetreeview.h @@ -11,6 +11,11 @@ class QmlJSOutlineTreeView : public Utils::NavigationTreeView Q_OBJECT public: explicit QmlJSOutlineTreeView(QWidget *parent = 0); + + void contextMenuEvent(QContextMenuEvent *event); + +private slots: + void collapseAllExceptRoot(); }; } // namespace Internal |