forked from qt-creator/qt-creator
Outline: Add context menu for collapsing/expanding tree
Task-number: QTCREATORBUG-2976
This commit is contained in:
@@ -8,8 +8,9 @@
|
||||
#include <cplusplus/OverviewModel.h>
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtGui/QVBoxLayout>
|
||||
#include <QtCore/QTimer>
|
||||
#include <QtGui/QVBoxLayout>
|
||||
#include <QtGui/QMenu>
|
||||
|
||||
using namespace CppEditor::Internal;
|
||||
|
||||
@@ -25,6 +26,21 @@ CppOutlineTreeView::CppOutlineTreeView(QWidget *parent) :
|
||||
setExpandsOnDoubleClick(false);
|
||||
}
|
||||
|
||||
void CppOutlineTreeView::contextMenuEvent(QContextMenuEvent *event)
|
||||
{
|
||||
if (!event)
|
||||
return;
|
||||
|
||||
QMenu contextMenu;
|
||||
|
||||
contextMenu.addAction(tr("Expand All"), this, SLOT(expandAll()));
|
||||
contextMenu.addAction(tr("Collapse All"), this, SLOT(collapseAll()));
|
||||
|
||||
contextMenu.exec(event->globalPos());
|
||||
|
||||
event->accept();
|
||||
}
|
||||
|
||||
CppOutlineFilterModel::CppOutlineFilterModel(CPlusPlus::OverviewModel *sourceModel, QObject *parent) :
|
||||
QSortFilterProxyModel(parent),
|
||||
m_sourceModel(sourceModel)
|
||||
|
||||
@@ -17,6 +17,8 @@ class CppOutlineTreeView : public Utils::NavigationTreeView
|
||||
Q_OBJECT
|
||||
public:
|
||||
CppOutlineTreeView(QWidget *parent);
|
||||
|
||||
void contextMenuEvent(QContextMenuEvent *event);
|
||||
};
|
||||
|
||||
class CppOutlineFilterModel : public QSortFilterProxyModel
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user