Sidebar: Open Editors: Simplfy code by using Utils::TreeView

Change-Id: Iebd68db3fa0c0a4ca05da2c5c764dda9ef1c8eaa
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
Daniel Teske
2014-04-09 17:59:42 +02:00
parent 406ccbdef5
commit 6097d8e611
2 changed files with 8 additions and 11 deletions

View File

@@ -101,6 +101,7 @@ OpenEditorsWidget::OpenEditorsWidget()
setModel(m_model);
setSelectionMode(QAbstractItemView::SingleSelection);
setSelectionBehavior(QAbstractItemView::SelectRows);
setActivationMode(Utils::SingleClickActivation);
header()->setStretchLastSection(false);
header()->setResizeMode(0, QHeaderView::Stretch);
header()->setResizeMode(1, QHeaderView::Fixed);
@@ -111,8 +112,8 @@ OpenEditorsWidget::OpenEditorsWidget()
connect(EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
this, SLOT(updateCurrentItem(Core::IEditor*)));
connect(this, SIGNAL(clicked(QModelIndex)),
this, SLOT(handleClicked(QModelIndex)));
connect(this, SIGNAL(activated(QModelIndex)),
this, SLOT(handleActivated(QModelIndex)));
connect(this, SIGNAL(pressed(QModelIndex)),
this, SLOT(handlePressed(QModelIndex)));
@@ -143,12 +144,7 @@ bool OpenEditorsWidget::eventFilter(QObject *obj, QEvent *event)
if (obj == this && event->type() == QEvent::KeyPress
&& currentIndex().isValid()) {
QKeyEvent *ke = static_cast<QKeyEvent*>(event);
if ((ke->key() == Qt::Key_Return
|| ke->key() == Qt::Key_Enter)
&& ke->modifiers() == 0) {
activateEditor(currentIndex());
return true;
} else if ((ke->key() == Qt::Key_Delete
if ((ke->key() == Qt::Key_Delete
|| ke->key() == Qt::Key_Backspace)
&& ke->modifiers() == 0) {
closeEditor(currentIndex());
@@ -174,7 +170,7 @@ void OpenEditorsWidget::handlePressed(const QModelIndex &index)
m_delegate->pressedIndex = index;
}
void OpenEditorsWidget::handleClicked(const QModelIndex &index)
void OpenEditorsWidget::handleActivated(const QModelIndex &index)
{
if (index.column() == 0) {
activateEditor(index);

View File

@@ -30,6 +30,7 @@
#ifndef OPENEDITORSVIEW_H
#define OPENEDITORSVIEW_H
#include <utils/itemviews.h>
#include <coreplugin/inavigationwidgetfactory.h>
#include <QAbstractProxyModel>
@@ -80,7 +81,7 @@ public:
mutable QModelIndex pressedIndex;
};
class OpenEditorsWidget : public QTreeView
class OpenEditorsWidget : public Utils::TreeView
{
Q_OBJECT
@@ -91,7 +92,7 @@ public:
bool eventFilter(QObject *obj, QEvent *event);
private slots:
void handleClicked(const QModelIndex &);
void handleActivated(const QModelIndex &);
void handlePressed(const QModelIndex &);
void updateCurrentItem(Core::IEditor*);
void contextMenuRequested(QPoint pos);