Commit 95896519 authored by hjk's avatar hjk

toolchainoptionpage: make name editable next to other fields

Change-Id: I35bc69c9c26a0cf4a8ed4e1e6044428d24cdb003
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 6f32b8e2
......@@ -339,6 +339,16 @@ QWidget *DetailsWidget::widget() const
return d->m_widget;
}
QWidget *DetailsWidget::takeWidget()
{
QWidget *widget = d->m_widget;
d->m_widget = 0;
d->m_grid->removeWidget(widget);
if (widget)
widget->setParent(0);
return widget;
}
void DetailsWidget::setWidget(QWidget *widget)
{
if (d->m_widget == widget)
......
......@@ -72,6 +72,7 @@ public:
void setWidget(QWidget *widget);
QWidget *widget() const;
QWidget *takeWidget();
void setToolWidget(Utils::FadingPanel *widget);
QWidget *toolWidget() const;
......
......@@ -44,6 +44,7 @@
#include <utils/environment.h>
#include <QDir>
#include <QFormLayout>
#include <QLabel>
#include <QVBoxLayout>
......@@ -204,25 +205,8 @@ QList<Abi> AndroidToolChain::detectSupportedAbis() const
AndroidToolChainConfigWidget::AndroidToolChainConfigWidget(AndroidToolChain *tc) :
ToolChainConfigWidget(tc)
{
QVBoxLayout *layout = new QVBoxLayout(this);
QLabel *label = new QLabel;
label->setText(tr("NDK Root: %1").arg(AndroidConfigurations::instance().config().ndkLocation.toUserOutput()));
layout->addWidget(label);
}
void AndroidToolChainConfigWidget::apply()
{
// nothing to do!
}
void AndroidToolChainConfigWidget::discard()
{
// nothing to do!
}
bool AndroidToolChainConfigWidget::isDirty() const
{
return false;
QLabel *label = new QLabel(AndroidConfigurations::instance().config().ndkLocation.toUserOutput());
m_mainLayout->addRow(tr("NDK Root:"), label);
}
// --------------------------------------------------------------------------
......
......@@ -80,9 +80,11 @@ class AndroidToolChainConfigWidget : public ProjectExplorer::ToolChainConfigWidg
public:
AndroidToolChainConfigWidget(AndroidToolChain *);
void apply();
void discard();
bool isDirty() const;
private:
void applyImpl() {}
void discardImpl() {}
bool isDirtyImpl() const { return false; }
void makeReadOnlyImpl() {}
};
......
......@@ -676,25 +676,13 @@ Internal::GccToolChainConfigWidget::GccToolChainConfigWidget(GccToolChain *tc) :
{
Q_ASSERT(tc);
Utils::DetailsWidget *details = new Utils::DetailsWidget(this);
details->setState(Utils::DetailsWidget::NoSummary);
QVBoxLayout *box = new QVBoxLayout(this);
box->setMargin(0);
box->addWidget(details);
QWidget *widget = new QWidget(details);
details->setWidget(widget);
QFormLayout *layout = new QFormLayout(widget);
const QStringList gnuVersionArgs = QStringList(QLatin1String("--version"));
m_compilerCommand->setExpectedKind(Utils::PathChooser::ExistingCommand);
m_compilerCommand->setCommandVersionArguments(gnuVersionArgs);
layout->addRow(tr("&Compiler path:"), m_compilerCommand);
layout->addRow(tr("&ABI:"), m_abiWidget);
m_mainLayout->addRow(tr("&Compiler path:"), m_compilerCommand);
m_mainLayout->addRow(tr("&ABI:"), m_abiWidget);
m_abiWidget->setEnabled(false);
addErrorLabel(layout);
addErrorLabel();
setFromToolchain();
......@@ -702,7 +690,7 @@ Internal::GccToolChainConfigWidget::GccToolChainConfigWidget(GccToolChain *tc) :
connect(m_abiWidget, SIGNAL(abiChanged()), this, SIGNAL(dirty()));
}
void Internal::GccToolChainConfigWidget::apply()
void Internal::GccToolChainConfigWidget::applyImpl()
{
if (toolChain()->isAutoDetected())
return;
......@@ -727,7 +715,7 @@ void Internal::GccToolChainConfigWidget::setFromToolchain()
blockSignals(blocked);
}
bool Internal::GccToolChainConfigWidget::isDirty() const
bool Internal::GccToolChainConfigWidget::isDirtyImpl() const
{
GccToolChain *tc = static_cast<GccToolChain *>(toolChain());
Q_ASSERT(tc);
......@@ -735,12 +723,11 @@ bool Internal::GccToolChainConfigWidget::isDirty() const
|| m_abiWidget->currentAbi() != tc->targetAbi();
}
void Internal::GccToolChainConfigWidget::makeReadOnly()
void Internal::GccToolChainConfigWidget::makeReadOnlyImpl()
{
m_compilerCommand->setEnabled(false);
m_abiWidget->setEnabled(false);
m_isReadOnly = true;
ToolChainConfigWidget::makeReadOnly();
}
void Internal::GccToolChainConfigWidget::handleCompilerCommandChange()
......
......@@ -85,15 +85,16 @@ class GccToolChainConfigWidget : public ToolChainConfigWidget
public:
GccToolChainConfigWidget(GccToolChain *);
void apply();
void discard() { setFromToolchain(); }
bool isDirty() const;
void makeReadOnly();
private slots:
void handleCompilerCommandChange();
private:
void applyImpl();
void discardImpl() { setFromToolchain(); }
bool isDirtyImpl() const;
void makeReadOnlyImpl();
void setFromToolchain();
Utils::PathChooser *m_compilerCommand;
......
......@@ -405,17 +405,13 @@ MsvcToolChainConfigWidget::MsvcToolChainConfigWidget(ToolChain *tc) :
ToolChainConfigWidget(tc),
m_varsBatDisplayLabel(new QLabel(this))
{
QFormLayout *formLayout = new QFormLayout(this);
formLayout->addRow(new QLabel(tc->displayName()));
m_mainLayout->addRow(new QLabel(tc->displayName()));
m_varsBatDisplayLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
formLayout->addRow(tr("Initialization:"), m_varsBatDisplayLabel);
addErrorLabel(formLayout);
m_mainLayout->addRow(tr("Initialization:"), m_varsBatDisplayLabel);
addErrorLabel();
setFromToolChain();
}
void MsvcToolChainConfigWidget::apply()
{ }
void MsvcToolChainConfigWidget::setFromToolChain()
{
MsvcToolChain *tc = static_cast<MsvcToolChain *>(toolChain());
......@@ -428,11 +424,6 @@ void MsvcToolChainConfigWidget::setFromToolChain()
m_varsBatDisplayLabel->setText(varsBatDisplay);
}
bool MsvcToolChainConfigWidget::isDirty() const
{
return false;
}
// --------------------------------------------------------------------------
// MsvcToolChainFactory
// --------------------------------------------------------------------------
......
......@@ -115,11 +115,12 @@ class MsvcToolChainConfigWidget : public ToolChainConfigWidget
public:
MsvcToolChainConfigWidget(ToolChain *);
void apply();
void discard() { setFromToolChain(); }
bool isDirty() const;
private:
void applyImpl() {}
void discardImpl() { setFromToolChain(); }
bool isDirtyImpl() const { return false; }
void makeReadOnlyImpl() {}
void setFromToolChain();
QLabel *m_varsBatDisplayLabel;
......
......@@ -47,11 +47,29 @@ ToolChainConfigWidget::ToolChainConfigWidget(ToolChain *tc) :
m_toolChain(tc), m_errorLabel(0)
{
QTC_CHECK(tc);
m_nameLineEdit = new QLineEdit(this);
m_nameLineEdit->setText(tc->displayName());
m_mainLayout = new QFormLayout(this);
m_mainLayout->addRow(tr("Name:"), m_nameLineEdit);
connect(m_nameLineEdit, SIGNAL(textChanged(QString)), SIGNAL(dirty()));
}
void ToolChainConfigWidget::apply()
{
m_toolChain->setDisplayName(m_nameLineEdit->text());
applyImpl();
}
void ToolChainConfigWidget::discard()
{
m_nameLineEdit->setText(m_toolChain->displayName());
discardImpl();
}
void ToolChainConfigWidget::setDisplayName(const QString &name)
bool ToolChainConfigWidget::isDirty() const
{
m_toolChain->setDisplayName(name);
return m_nameLineEdit->text() != m_toolChain->displayName() || isDirtyImpl();
}
ToolChain *ToolChainConfigWidget::toolChain() const
......@@ -60,24 +78,18 @@ ToolChain *ToolChainConfigWidget::toolChain() const
}
void ToolChainConfigWidget::makeReadOnly()
{ }
void ToolChainConfigWidget::addErrorLabel(QFormLayout *lt)
{
if (!m_errorLabel) {
m_errorLabel = new QLabel;
m_errorLabel->setVisible(false);
}
lt->addRow(m_errorLabel);
m_nameLineEdit->setEnabled(false);
makeReadOnlyImpl();
}
void ToolChainConfigWidget::addErrorLabel(QGridLayout *lt, int row, int column, int colSpan)
void ToolChainConfigWidget::addErrorLabel()
{
if (!m_errorLabel) {
m_errorLabel = new QLabel;
m_errorLabel->setVisible(false);
}
lt->addWidget(m_errorLabel, row, column, 1, colSpan);
m_mainLayout->addRow(m_errorLabel);
}
void ToolChainConfigWidget::setErrorMessage(const QString &m)
......
......@@ -40,6 +40,7 @@
QT_BEGIN_NAMESPACE
class QFormLayout;
class QGridLayout;
class QLineEdit;
class QLabel;
QT_END_NAMESPACE
......@@ -58,14 +59,12 @@ class PROJECTEXPLORER_EXPORT ToolChainConfigWidget : public QWidget
public:
ToolChainConfigWidget(ProjectExplorer::ToolChain *);
void setDisplayName(const QString &);
virtual void apply() = 0;
virtual void discard() = 0;
virtual bool isDirty() const = 0;
ProjectExplorer::ToolChain *toolChain() const;
virtual void makeReadOnly();
void apply();
void discard();
bool isDirty() const;
void makeReadOnly();
signals:
void dirty();
......@@ -75,8 +74,14 @@ protected slots:
void clearErrorMessage();
protected:
void addErrorLabel(QFormLayout *lt);
void addErrorLabel(QGridLayout *lt, int row = 0, int column = 0, int colSpan = 1);
virtual void applyImpl() = 0;
virtual void discardImpl() = 0;
virtual bool isDirtyImpl() const = 0;
virtual void makeReadOnlyImpl() = 0;
void addErrorLabel();
QFormLayout *m_mainLayout;
QLineEdit *m_nameLineEdit;
private:
ToolChain *m_toolChain;
......
......@@ -38,6 +38,7 @@
#include <coreplugin/icore.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/detailswidget.h>
#include <utils/qtcassert.h>
#include <QAction>
......@@ -67,11 +68,8 @@ public:
if (p)
p->childNodes.append(this);
widget = tc ? tc->configurationWidget() : 0;
if (widget) {
if (tc && tc->isAutoDetected())
widget->makeReadOnly();
widget->setVisible(false);
}
if (widget && tc->isAutoDetected())
widget->makeReadOnly();
}
~ToolChainNode()
......@@ -86,7 +84,6 @@ public:
}
ToolChainNode *parent;
QString newName;
QList<ToolChainNode *> childNodes;
ToolChain *toolChain;
ToolChainConfigWidget *widget;
......@@ -97,12 +94,9 @@ public:
// ToolChainModel
// --------------------------------------------------------------------------
ToolChainModel::ToolChainModel(QBoxLayout *parentLayout, QObject *parent) :
QAbstractItemModel(parent),
m_parentLayout(parentLayout)
ToolChainModel::ToolChainModel(QObject *parent) :
QAbstractItemModel(parent)
{
Q_ASSERT(m_parentLayout);
connect(ToolChainManager::instance(), SIGNAL(toolChainAdded(ProjectExplorer::ToolChain*)),
this, SLOT(addToolChain(ProjectExplorer::ToolChain*)));
connect(ToolChainManager::instance(), SIGNAL(toolChainRemoved(ProjectExplorer::ToolChain*)),
......@@ -189,16 +183,13 @@ QVariant ToolChainModel::data(const QModelIndex &index, int role) const
if (node->toolChain) {
if (role == Qt::FontRole) {
QFont f = QApplication::font();
if (node->changed) {
if (node->changed)
f.setBold(true);
}
return f;
}
if (role == Qt::DisplayRole || role == Qt::EditRole) {
if (index.column() == 0) {
return node->newName.isEmpty() ?
node->toolChain->displayName() : node->newName;
}
if (role == Qt::DisplayRole) {
if (index.column() == 0)
return node->toolChain->displayName();
return node->toolChain->typeDisplayName();
}
if (role == Qt::ToolTipRole) {
......@@ -209,21 +200,6 @@ QVariant ToolChainModel::data(const QModelIndex &index, int role) const
return QVariant();
}
bool ToolChainModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!index.isValid())
return false;
ToolChainNode *node = static_cast<ToolChainNode *>(index.internalPointer());
Q_ASSERT(node);
if (index.column() != 0 || !node->toolChain || role != Qt::EditRole)
return false;
node->newName = value.toString();
if (!node->newName.isEmpty() && node->newName != node->toolChain->displayName())
node->changed = true;
return true;
}
Qt::ItemFlags ToolChainModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
......@@ -234,12 +210,7 @@ Qt::ItemFlags ToolChainModel::flags(const QModelIndex &index) const
if (!node->toolChain)
return Qt::ItemIsEnabled;
if (node->toolChain->isAutoDetected())
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
else if (index.column() == 0)
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
else
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
QVariant ToolChainModel::headerData(int section, Qt::Orientation orientation, int role) const
......@@ -316,10 +287,6 @@ void ToolChainModel::apply()
Q_ASSERT(n);
if (n->changed) {
Q_ASSERT(n->toolChain);
if (!n->newName.isEmpty()) {
n->toolChain->setDisplayName(n->newName);
n->newName.clear();
}
if (n->widget)
n->widget->apply();
n->changed = false;
......@@ -408,10 +375,8 @@ QModelIndex ToolChainModel::index(ToolChainNode *node, int column) const
ToolChainNode *ToolChainModel::createNode(ToolChainNode *parent, ToolChain *tc, bool changed)
{
ToolChainNode *node = new ToolChainNode(parent, tc, changed);
if (node->widget) {
m_parentLayout->addWidget(node->widget);
if (node->widget)
connect(node->widget, SIGNAL(dirty()), this, SLOT(setDirty()));
}
return node;
}
......@@ -475,8 +440,8 @@ void ToolChainModel::removeToolChain(ToolChain *tc)
// --------------------------------------------------------------------------
ToolChainOptionsPage::ToolChainOptionsPage() :
m_model(0), m_selectionModel(0), m_currentTcWidget(0),
m_toolChainView(0), m_addButton(0), m_cloneButton(0), m_delButton(0)
m_model(0), m_selectionModel(0), m_toolChainView(0), m_container(0),
m_addButton(0), m_cloneButton(0), m_delButton(0)
{
setId(QLatin1String(Constants::TOOLCHAIN_SETTINGS_PAGE_ID));
setDisplayName(tr("Tool Chains"));
......@@ -491,8 +456,6 @@ QWidget *ToolChainOptionsPage::createPage(QWidget *parent)
// Actual page setup:
m_configWidget = new QWidget(parent);
m_currentTcWidget = 0;
m_toolChainView = new QTreeView(m_configWidget);
m_toolChainView->setUniformRowHeights(true);
m_toolChainView->header()->setStretchLastSection(false);
......@@ -501,6 +464,10 @@ QWidget *ToolChainOptionsPage::createPage(QWidget *parent)
m_cloneButton = new QPushButton(tr("Clone"), m_configWidget);
m_delButton = new QPushButton(tr("Remove"), m_configWidget);
m_container = new Utils::DetailsWidget(m_configWidget);
m_container->setState(Utils::DetailsWidget::NoSummary);
m_container->setVisible(false);
QVBoxLayout *buttonLayout = new QVBoxLayout();
buttonLayout->setSpacing(6);
buttonLayout->setContentsMargins(0, 0, 0, 0);
......@@ -511,6 +478,7 @@ QWidget *ToolChainOptionsPage::createPage(QWidget *parent)
QVBoxLayout *verticalLayout = new QVBoxLayout();
verticalLayout->addWidget(m_toolChainView);
verticalLayout->addWidget(m_container);
QHBoxLayout *horizontalLayout = new QHBoxLayout(m_configWidget);
horizontalLayout->addLayout(verticalLayout);
......@@ -587,7 +555,6 @@ void ToolChainOptionsPage::finish()
m_configWidget = 0; // deleted by settingsdialog
m_selectionModel = 0; // child of m_configWidget
m_currentTcWidget = 0; // deleted by the model
// childs of m_configWidget
m_toolChainView = 0;
m_addButton = 0;
......@@ -602,14 +569,11 @@ bool ToolChainOptionsPage::matches(const QString &s) const
void ToolChainOptionsPage::toolChainSelectionChanged()
{
if (m_currentTcWidget)
m_currentTcWidget->setVisible(false);
QModelIndex current = currentIndex();
m_currentTcWidget = current.isValid() ? m_model->widget(current) : 0;
if (m_currentTcWidget)
m_currentTcWidget->setVisible(true);
(void)m_container->takeWidget(); // Prevent deletion.
QWidget *currentTcWidget = current.isValid() ? m_model->widget(current) : 0;
m_container->setWidget(currentTcWidget);
m_container->setVisible(currentTcWidget != 0);
updateState();
}
......
......@@ -43,6 +43,8 @@ class QTreeView;
class QTreeWidgetItem;
QT_END_NAMESPACE
namespace Utils { class DetailsWidget; }
namespace ProjectExplorer {
class ToolChain;
......@@ -62,7 +64,7 @@ class ToolChainModel : public QAbstractItemModel
Q_OBJECT
public:
explicit ToolChainModel(QBoxLayout *parentLayout, QObject *parent = 0);
explicit ToolChainModel(QObject *parent = 0);
~ToolChainModel();
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
......@@ -72,7 +74,6 @@ public:
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
Qt::ItemFlags flags(const QModelIndex &index) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
......@@ -107,8 +108,6 @@ private:
QList<ToolChainNode *> m_toAddList;
QList<ToolChainNode *> m_toRemoveList;
QBoxLayout *m_parentLayout;
};
// --------------------------------------------------------------------------
......@@ -142,8 +141,8 @@ private:
ToolChainModel *m_model;
QList<ToolChainFactory *> m_factories;
QItemSelectionModel * m_selectionModel;
ToolChainConfigWidget *m_currentTcWidget;
QTreeView *m_toolChainView;
Utils::DetailsWidget *m_container;
QPushButton *m_addButton;
QPushButton *m_cloneButton;
QPushButton *m_delButton;
......
......@@ -469,11 +469,10 @@ WinCEToolChainConfigWidget::WinCEToolChainConfigWidget(ToolChain *tc) :
WinCEToolChain *toolChain = static_cast<WinCEToolChain *>(tc);
QTC_ASSERT(tc, return);
QFormLayout *formLayout = new QFormLayout(this);
formLayout->addRow(tr("SDK:"), new QLabel(toolChain->displayName()));
formLayout->addRow(tr("WinCE Version:"), new QLabel(toolChain->ceVer()));
formLayout->addRow(tr("ABI:"), new QLabel(toolChain->targetAbi().toString()));
addErrorLabel(formLayout);
m_mainLayout->addRow(tr("SDK:"), new QLabel(toolChain->displayName()));
m_mainLayout->addRow(tr("WinCE Version:"), new QLabel(toolChain->ceVer()));
m_mainLayout->addRow(tr("ABI:"), new QLabel(toolChain->targetAbi().toString()));
addErrorLabel();
}
} // namespace Internal
......
......@@ -99,10 +99,11 @@ class WinCEToolChainConfigWidget : public ToolChainConfigWidget
public:
WinCEToolChainConfigWidget(ToolChain *);
void apply() {}
void discard() { }
bool isDirty() const {return false;}
private:
void applyImpl() {}
void discardImpl() { }
bool isDirtyImpl() const {return false;}
void makeReadOnlyImpl() {}
};
class WinCEToolChainFactory : public ToolChainFactory
......
......@@ -380,7 +380,7 @@ RvctToolChainConfigWidget::~RvctToolChainConfigWidget()
delete m_ui;
}
void RvctToolChainConfigWidget::apply()
void RvctToolChainConfigWidget::applyImpl()
{
RvctToolChain *tc = static_cast<RvctToolChain *>(toolChain());
Q_ASSERT(tc);
......@@ -404,7 +404,7 @@ void RvctToolChainConfigWidget::setFromToolChain()
m_ui->versionComboBox->setCurrentIndex(static_cast<int>(tc->armVersion()));
}
bool RvctToolChainConfigWidget::isDirty() const
bool RvctToolChainConfigWidget::isDirtyImpl() const
{
RvctToolChain *tc = static_cast<RvctToolChain *>(toolChain());
Q_ASSERT(tc);
......@@ -414,12 +414,11 @@ bool RvctToolChainConfigWidget::isDirty() const
|| tc->environmentChanges() != environmentChanges();
}
void RvctToolChainConfigWidget::makeReadOnly()
void RvctToolChainConfigWidget::makeReadOnlyImpl()
{
m_ui->versionComboBox->setEnabled(false);
m_ui->compilerPath->setEnabled(false);
m_ui->environmentView->setEditTriggers(QAbstractItemView::NoEditTriggers);
ProjectExplorer::ToolChainConfigWidget::makeReadOnly();
}
QList<Utils::EnvironmentItem> RvctToolChainConfigWidget::environmentChanges() const
......
......@@ -139,13 +139,13 @@ public:
RvctToolChainConfigWidget(RvctToolChain *tc);
~RvctToolChainConfigWidget();
void apply();
void discard() { setFromToolChain(); }
bool isDirty() const;
void makeReadOnly();
private:
void applyImpl();
void discardImpl() { setFromToolChain(); }
bool isDirtyImpl() const;
void makeReadOnlyImpl();
void changeEvent(QEvent *ev);