forked from qt-creator/qt-creator
Use QTableView for the EnvironmentEditModel
* Add annoying code to set the table up in a way that looks decent * On the plus side: Keyboard handling is *much* better now Reviewed-by: dt
This commit is contained in:
@@ -37,7 +37,7 @@
|
|||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
#include <QtGui/QWidget>
|
#include <QtGui/QWidget>
|
||||||
#include <QtGui/QCheckBox>
|
#include <QtGui/QCheckBox>
|
||||||
#include <QtGui/QTreeView>
|
#include <QtGui/QTableView>
|
||||||
#include <QtGui/QPushButton>
|
#include <QtGui/QPushButton>
|
||||||
#include <QtGui/QLabel>
|
#include <QtGui/QLabel>
|
||||||
#include <QtGui/QStackedWidget>
|
#include <QtGui/QStackedWidget>
|
||||||
@@ -392,13 +392,18 @@ EnvironmentWidget::EnvironmentWidget(QWidget *parent, QWidget *additionalDetails
|
|||||||
|
|
||||||
QHBoxLayout *horizontalLayout = new QHBoxLayout();
|
QHBoxLayout *horizontalLayout = new QHBoxLayout();
|
||||||
horizontalLayout->setMargin(0);
|
horizontalLayout->setMargin(0);
|
||||||
m_environmentTreeView = new QTreeView(this);
|
m_environmentView = new QTableView(this);
|
||||||
m_environmentTreeView->setRootIsDecorated(false);
|
m_environmentView->setModel(m_model);
|
||||||
m_environmentTreeView->setHeaderHidden(false);
|
m_environmentView->setMinimumHeight(400);
|
||||||
m_environmentTreeView->setModel(m_model);
|
m_environmentView->setGridStyle(Qt::NoPen);
|
||||||
m_environmentTreeView->header()->resizeSection(0, 250);
|
m_environmentView->horizontalHeader()->setStretchLastSection(true);
|
||||||
m_environmentTreeView->setMinimumHeight(400);
|
m_environmentView->horizontalHeader()->setResizeMode(0, QHeaderView::ResizeToContents);
|
||||||
horizontalLayout->addWidget(m_environmentTreeView);
|
m_environmentView->horizontalHeader()->setHighlightSections(false);
|
||||||
|
m_environmentView->verticalHeader()->hide();
|
||||||
|
QFontMetrics fm(font());
|
||||||
|
m_environmentView->verticalHeader()->setDefaultSectionSize(qMax(static_cast<int>(fm.height() * 1.2), fm.height() + 4));
|
||||||
|
m_environmentView->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
|
horizontalLayout->addWidget(m_environmentView);
|
||||||
|
|
||||||
QVBoxLayout *buttonLayout = new QVBoxLayout();
|
QVBoxLayout *buttonLayout = new QVBoxLayout();
|
||||||
|
|
||||||
@@ -438,7 +443,7 @@ EnvironmentWidget::EnvironmentWidget(QWidget *parent, QWidget *additionalDetails
|
|||||||
this, SLOT(removeEnvironmentButtonClicked()));
|
this, SLOT(removeEnvironmentButtonClicked()));
|
||||||
connect(m_unsetButton, SIGNAL(clicked(bool)),
|
connect(m_unsetButton, SIGNAL(clicked(bool)),
|
||||||
this, SLOT(unsetEnvironmentButtonClicked()));
|
this, SLOT(unsetEnvironmentButtonClicked()));
|
||||||
connect(m_environmentTreeView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
|
connect(m_environmentView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
|
||||||
this, SLOT(environmentCurrentIndexChanged(QModelIndex)));
|
this, SLOT(environmentCurrentIndexChanged(QModelIndex)));
|
||||||
|
|
||||||
connect(m_model, SIGNAL(userChangesChanged()), this, SLOT(updateSummaryText()));
|
connect(m_model, SIGNAL(userChangesChanged()), this, SLOT(updateSummaryText()));
|
||||||
@@ -452,8 +457,8 @@ EnvironmentWidget::~EnvironmentWidget()
|
|||||||
|
|
||||||
void EnvironmentWidget::focusIndex(const QModelIndex &index)
|
void EnvironmentWidget::focusIndex(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
m_environmentTreeView->setCurrentIndex(index);
|
m_environmentView->setCurrentIndex(index);
|
||||||
m_environmentTreeView->setFocus();
|
m_environmentView->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnvironmentWidget::setBaseEnvironment(const ProjectExplorer::Environment &env)
|
void EnvironmentWidget::setBaseEnvironment(const ProjectExplorer::Environment &env)
|
||||||
@@ -502,24 +507,24 @@ void EnvironmentWidget::updateSummaryText()
|
|||||||
|
|
||||||
void EnvironmentWidget::updateButtons()
|
void EnvironmentWidget::updateButtons()
|
||||||
{
|
{
|
||||||
environmentCurrentIndexChanged(m_environmentTreeView->currentIndex());
|
environmentCurrentIndexChanged(m_environmentView->currentIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnvironmentWidget::editEnvironmentButtonClicked()
|
void EnvironmentWidget::editEnvironmentButtonClicked()
|
||||||
{
|
{
|
||||||
m_environmentTreeView->edit(m_environmentTreeView->currentIndex());
|
m_environmentView->edit(m_environmentView->currentIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnvironmentWidget::addEnvironmentButtonClicked()
|
void EnvironmentWidget::addEnvironmentButtonClicked()
|
||||||
{
|
{
|
||||||
QModelIndex index = m_model->addVariable();
|
QModelIndex index = m_model->addVariable();
|
||||||
m_environmentTreeView->setCurrentIndex(index);
|
m_environmentView->setCurrentIndex(index);
|
||||||
m_environmentTreeView->edit(index);
|
m_environmentView->edit(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnvironmentWidget::removeEnvironmentButtonClicked()
|
void EnvironmentWidget::removeEnvironmentButtonClicked()
|
||||||
{
|
{
|
||||||
const QString &name = m_model->indexToVariable(m_environmentTreeView->currentIndex());
|
const QString &name = m_model->indexToVariable(m_environmentView->currentIndex());
|
||||||
m_model->resetVariable(name);
|
m_model->resetVariable(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -527,7 +532,7 @@ void EnvironmentWidget::removeEnvironmentButtonClicked()
|
|||||||
// or remove when it is just a change we added
|
// or remove when it is just a change we added
|
||||||
void EnvironmentWidget::unsetEnvironmentButtonClicked()
|
void EnvironmentWidget::unsetEnvironmentButtonClicked()
|
||||||
{
|
{
|
||||||
const QString &name = m_model->indexToVariable(m_environmentTreeView->currentIndex());
|
const QString &name = m_model->indexToVariable(m_environmentView->currentIndex());
|
||||||
if (!m_model->canReset(name))
|
if (!m_model->canReset(name))
|
||||||
m_model->resetVariable(name);
|
m_model->resetVariable(name);
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
#include <QtGui/QWidget>
|
#include <QtGui/QWidget>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QTreeView;
|
class QTableView;
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
@@ -125,7 +125,7 @@ private:
|
|||||||
EnvironmentModel *m_model;
|
EnvironmentModel *m_model;
|
||||||
QString m_baseEnvironmentText;
|
QString m_baseEnvironmentText;
|
||||||
Utils::DetailsWidget *m_detailsContainer;
|
Utils::DetailsWidget *m_detailsContainer;
|
||||||
QTreeView *m_environmentTreeView;
|
QTableView *m_environmentView;
|
||||||
QPushButton *m_editButton;
|
QPushButton *m_editButton;
|
||||||
QPushButton *m_addButton;
|
QPushButton *m_addButton;
|
||||||
QPushButton *m_resetButton;
|
QPushButton *m_resetButton;
|
||||||
|
|||||||
Reference in New Issue
Block a user