Commit f8810811 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Make renaming of kits consistent with other areas



Do not use double-click on the name in the table for renaming.
Add a line edit to the kit details instead.

Task-number: QTCREATORBUG-7805
Change-Id: I6fac275b095c9000c765609a4cee1963d8e80380
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent ffea02d5
......@@ -48,12 +48,6 @@ class PROJECTEXPLORER_EXPORT KitConfigWidget : public QWidget
Q_OBJECT
public:
enum LayoutColumns {
LabelColumn,
WidgetColumn,
ButtonColumn
};
KitConfigWidget(QWidget *parent = 0) : QWidget(parent)
{ }
......@@ -66,14 +60,8 @@ public:
virtual QWidget *buttonWidget() const { return 0; }
virtual void addToLayout(QGridLayout *layout, int row);
signals:
void dirty();
protected:
void addLabel(QGridLayout *layout, int row);
void addButtonWidget(QGridLayout *layout, int row);
};
} // namespace ProjectExplorer
......
......@@ -367,7 +367,7 @@ QList<KitInformation *> KitManager::kitInformation() const
return d->m_informationList;
}
KitConfigWidget *KitManager::createConfigWidget(Kit *k) const
Internal::KitManagerConfigWidget *KitManager::createConfigWidget(Kit *k) const
{
if (!k)
return 0;
......
......@@ -48,6 +48,7 @@ class Kit;
class KitConfigWidget;
namespace Internal {
class KitManagerConfigWidget;
class KitManagerPrivate;
class KitModel;
} // namespace Internal
......@@ -110,7 +111,7 @@ public:
QList<KitInformation *> kitInformation() const;
KitConfigWidget *createConfigWidget(Kit *k) const;
Internal::KitManagerConfigWidget *createConfigWidget(Kit *k) const;
public slots:
bool registerKit(ProjectExplorer::Kit *k);
......
......@@ -38,6 +38,7 @@
#include <QFileDialog>
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
#include <QToolButton>
#include <QScrollArea>
#include <QSizePolicy>
......@@ -45,43 +46,15 @@
namespace ProjectExplorer {
void KitConfigWidget::addToLayout(QGridLayout *layout, int row)
{
addLabel(layout, row);
layout->addWidget(this, row, WidgetColumn);
addButtonWidget(layout, row);
}
void KitConfigWidget::addLabel(QGridLayout *layout, int row)
{
static const Qt::Alignment alignment
= static_cast<Qt::Alignment>(style()->styleHint(QStyle::SH_FormLayoutLabelAlignment));
QLabel *label = new QLabel(displayName());
label->setToolTip(toolTip());
layout->addWidget(label, row, LabelColumn, alignment);
}
void KitConfigWidget::addButtonWidget(QGridLayout *layout, int row)
{
if (QWidget *button = buttonWidget()) {
if (button->toolTip().isEmpty())
button->setToolTip(toolTip());
layout->addWidget(button, row, ButtonColumn);
}
}
namespace Internal {
KitManagerConfigWidget::KitManagerConfigWidget(Kit *k, QWidget *parent) :
KitConfigWidget(parent),
m_layout(new QGridLayout),
m_iconButton(new QToolButton),
m_nameEdit(new QLineEdit),
m_kit(k)
{
m_layout->setMargin(0);
m_layout->setSpacing(6);
m_layout->setContentsMargins(0, 0, 0, 0);
QVBoxLayout *top = new QVBoxLayout(this);
top->setMargin(0);
......@@ -96,27 +69,25 @@ KitManagerConfigWidget::KitManagerConfigWidget(Kit *k, QWidget *parent) :
scroll->setWidget(details);
QWidget *widget = new QWidget;
details->setWidget(widget);
QVBoxLayout *iconLayout = new QVBoxLayout;
iconLayout->addWidget(m_iconButton);
iconLayout->addStretch();
m_layout->setMargin(0);
m_layout->setSpacing(6);
m_layout->setContentsMargins(6, 0, 6, 0);
m_layout->setRowStretch(1, 1);
widget->setLayout(m_layout);
QGridLayout *masterLayout = new QGridLayout(widget);
masterLayout->setMargin(0);
masterLayout->setContentsMargins(6, 0, 6, 0);
masterLayout->addLayout(iconLayout, 0, 0);
masterLayout->addLayout(m_layout, 0, 1);
masterLayout->setRowStretch(1, 1);
details->setWidget(widget);
addToLayout(tr("Name:"), tr("Kit name and icon."), m_nameEdit, m_iconButton);
discard();
connect(m_iconButton, SIGNAL(clicked()), this, SLOT(setIcon()));
connect(m_nameEdit, SIGNAL(textChanged(QString)), this, SIGNAL(dirty()));
}
QString KitManagerConfigWidget::displayName() const
{
return tr("Kits");
return m_nameEdit->text();
}
void KitManagerConfigWidget::apply()
......@@ -124,6 +95,7 @@ void KitManagerConfigWidget::apply()
foreach (KitConfigWidget *w, m_widgets)
w->apply();
m_kit->setIconPath(m_iconPath);
m_kit->setDisplayName(m_nameEdit->text());
}
void KitManagerConfigWidget::discard()
......@@ -132,6 +104,7 @@ void KitManagerConfigWidget::discard()
w->discard();
m_iconButton->setIcon(m_kit->icon());
m_iconPath = m_kit->iconPath();
m_nameEdit->setText(m_kit->displayName());
}
bool KitManagerConfigWidget::isDirty() const
......@@ -139,7 +112,7 @@ bool KitManagerConfigWidget::isDirty() const
foreach (KitConfigWidget *w, m_widgets)
if (w->isDirty())
return true;
return m_kit->iconPath() != m_iconPath;
return (m_kit->iconPath() != m_iconPath) || (m_kit->displayName() != m_nameEdit->text());
}
void KitManagerConfigWidget::addConfigWidget(ProjectExplorer::KitConfigWidget *widget)
......@@ -148,7 +121,8 @@ void KitManagerConfigWidget::addConfigWidget(ProjectExplorer::KitConfigWidget *w
Q_ASSERT(!m_widgets.contains(widget));
connect(widget, SIGNAL(dirty()), this, SIGNAL(dirty()));
widget->addToLayout(m_layout, m_layout->rowCount());
addToLayout(widget->displayName(), widget->toolTip(), widget, widget->buttonWidget());
m_widgets.append(widget);
}
......@@ -157,11 +131,12 @@ void KitManagerConfigWidget::makeReadOnly()
foreach (KitConfigWidget *w, m_widgets)
w->makeReadOnly();
m_iconButton->setEnabled(false);
m_nameEdit->setEnabled(false);
}
void KitManagerConfigWidget::setIcon()
{
const QString path = QFileDialog::getOpenFileName(0, tr("Select Icon"), m_iconPath, tr("Images (*.png *.xpm *.jpg)"));
const QString path = QFileDialog::getOpenFileName(this, tr("Select Icon"), m_iconPath, tr("Images (*.png *.xpm *.jpg)"));
if (path.isEmpty())
return;
......@@ -174,5 +149,32 @@ void KitManagerConfigWidget::setIcon()
emit dirty();
}
void KitManagerConfigWidget::addToLayout(const QString &name, const QString &toolTip,
QWidget *widget, QWidget *button)
{
int row = m_layout->rowCount();
addLabel(name, toolTip, row);
m_layout->addWidget(widget, row, WidgetColumn);
addButtonWidget(button, toolTip, row);
}
void KitManagerConfigWidget::addLabel(const QString &name, const QString &toolTip, int row)
{
static const Qt::Alignment alignment
= static_cast<Qt::Alignment>(style()->styleHint(QStyle::SH_FormLayoutLabelAlignment));
QLabel *label = new QLabel(name);
label->setToolTip(toolTip);
m_layout->addWidget(label, row, LabelColumn, alignment);
}
void KitManagerConfigWidget::addButtonWidget(QWidget *button, const QString &toolTip, int row)
{
if (!button)
return;
if (button->toolTip().isEmpty())
button->setToolTip(toolTip);
m_layout->addWidget(button, row, ButtonColumn);
}
} // namespace Internal
} // namespace ProjectExplorer
......@@ -36,6 +36,7 @@
QT_BEGIN_NAMESPACE
class QHBoxLayout;
class QGridLayout;
class QLineEdit;
class QToolButton;
QT_END_NAMESPACE
......@@ -63,8 +64,21 @@ private slots:
void setIcon();
private:
enum LayoutColumns {
LabelColumn,
WidgetColumn,
ButtonColumn
};
void addToLayout(const QString &name, const QString &toolTip, QWidget *widget, QWidget *button = 0);
void addLabel(const QString &name, const QString &toolTip, int row);
void addButtonWidget(QWidget *button, const QString &toolTip, int row);
QGridLayout *m_layout;
QToolButton *m_iconButton;
QLineEdit *m_nameEdit;
QList<KitConfigWidget *> m_widgets;
Kit *m_kit;
QString m_iconPath;
......
......@@ -31,7 +31,7 @@
#include "kitmodel.h"
#include "kit.h"
#include "kitconfigwidget.h"
#include "kitmanagerconfigwidget.h"
#include "kitmanager.h"
#include <utils/qtcassert.h>
......@@ -72,10 +72,9 @@ public:
}
KitNode *parent;
QString newName;
QList<KitNode *> childNodes;
Kit *kit;
KitConfigWidget *widget;
KitManagerConfigWidget *widget;
bool changed;
};
......@@ -173,13 +172,11 @@ QVariant KitModel::data(const QModelIndex &index, int role) const
f.setItalic(f.style() != QFont::StyleItalic);
return f;
} else if (role == Qt::DisplayRole) {
QString baseName = node->newName.isEmpty() ? node->kit->displayName() : node->newName;
QString baseName = node->widget->displayName();
if (node == m_defaultNode)
//: Mark up a kit as the default one.
baseName = tr("%1 (default)").arg(baseName);
return baseName;
} else if (role == Qt::EditRole) {
return node->newName.isEmpty() ? node->kit->displayName() : node->newName;
} else if (role == Qt::DecorationRole) {
return node->kit->isValid() ? QIcon() : warningIcon;
} else if (role == Qt::ToolTipRole) {
......@@ -189,21 +186,6 @@ QVariant KitModel::data(const QModelIndex &index, int role) const
return QVariant();
}
bool KitModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!index.isValid())
return false;
KitNode *node = static_cast<KitNode *>(index.internalPointer());
Q_ASSERT(node);
if (index.column() != 0 || !node->kit || role != Qt::EditRole)
return false;
node->newName = value.toString();
if (!node->newName.isEmpty() && node->newName != node->kit->displayName())
node->changed = true;
return true;
}
Qt::ItemFlags KitModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
......@@ -214,10 +196,7 @@ Qt::ItemFlags KitModel::flags(const QModelIndex &index) const
if (!node->kit)
return Qt::ItemIsEnabled;
if (node->kit->isAutoDetected())
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
QVariant KitModel::headerData(int section, Qt::Orientation orientation, int role) const
......@@ -309,10 +288,6 @@ void KitModel::apply()
Q_ASSERT(n->kit);
if (n->changed) {
KitManager::instance()->blockSignals(true);
if (!n->newName.isEmpty()) {
n->kit->setDisplayName(n->newName);
n->newName.clear();
}
if (n->widget)
n->widget->apply();
n->changed = false;
......
......@@ -69,7 +69,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;
......
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