Commit 33465ce2 authored by Tobias Hunger's avatar Tobias Hunger

Use Utils::TreeView in EnvironmentWidget

Change-Id: I43c0a39d102d3cf569b4a3c073af393a0a15c68a
Reviewed-by: default avatarTim Jenssen <tim.jenssen@theqtcompany.com>
parent 4a3b63c1
......@@ -32,6 +32,7 @@
#include <utils/environment.h>
#include <utils/environmentmodel.h>
#include <utils/headerviewstretcher.h>
#include <utils/itemviews.h>
#include <utils/tooltip/tooltip.h>
#include <QString>
......@@ -160,7 +161,10 @@ EnvironmentWidget::EnvironmentWidget(QWidget *parent, QWidget *additionalDetails
QHBoxLayout *horizontalLayout = new QHBoxLayout();
horizontalLayout->setMargin(0);
d->m_environmentView = new Internal::EnvironmentTreeView(this);
auto tree = new Utils::TreeView(this);
connect(tree, &QAbstractItemView::activated,
tree, [tree](const QModelIndex &idx) { tree->edit(idx); });
d->m_environmentView = tree;
d->m_environmentView->setModel(d->m_model);
d->m_environmentView->setItemDelegate(new EnvironmentDelegate(d->m_model, d->m_environmentView));
d->m_environmentView->setMinimumHeight(400);
......@@ -363,48 +367,6 @@ void EnvironmentWidget::invalidateCurrentIndex()
environmentCurrentIndexChanged(QModelIndex());
}
Internal::EnvironmentTreeView::EnvironmentTreeView(QWidget *parent)
: QTreeView(parent)
{
}
QModelIndex Internal::EnvironmentTreeView::moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
{
QModelIndex idx = currentIndex();
int column = idx.column();
int row = idx.row();
if (cursorAction == QAbstractItemView::MoveNext) {
if (column == 0)
return idx.sibling(row, 1);
else if (row + 1 < model()->rowCount())
return idx.sibling(row + 1, 0);
else // On last column in last row
return idx;
} else if (cursorAction == QAbstractItemView::MovePrevious) {
if (column == 1)
return idx.sibling(row, 0);
else if (row - 1 >= 0)
return idx.sibling(row - 1, 1);
else // On first column in first row
return idx;
}
return QTreeView::moveCursor(cursorAction, modifiers);
}
void Internal::EnvironmentTreeView::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
if (!edit(currentIndex(), EditKeyPressed, event))
event->ignore();
return;
}
QTreeView::keyPressEvent(event);
}
} // namespace ProjectExplorer
#include "environmentwidget.moc"
......@@ -28,7 +28,6 @@
#include "projectexplorer_export.h"
#include <QWidget>
#include <QTreeView>
QT_FORWARD_DECLARE_CLASS(QModelIndex)
......@@ -38,16 +37,6 @@ class EnvironmentItem;
} // namespace Utils
namespace ProjectExplorer {
namespace Internal {
class EnvironmentTreeView : public QTreeView
{
public:
EnvironmentTreeView(QWidget *parent);
protected:
QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers);
void keyPressEvent(QKeyEvent *event);
};
} // namespace Internal
class EnvironmentWidgetPrivate;
......
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