Commit 0a1c7802 authored by dt's avatar dt

Fixes EnvironmentEditWidget editing variable names

Don't loose focus, don't loose the current index.
Implemented in a not really good way. The model emits a signal after
renaming, which the view respsonds to by setting focus/currentIndex
correctly.
parent 0e3ee9c7
......@@ -178,6 +178,14 @@ int EnvironmentModel::findInChangesInsertPosition(const QString &name) const
return m_items.size();
}
QModelIndex EnvironmentModel::index(const QString &name)
{
int row = findInResult(name);
if (row == -1)
return QModelIndex();
return index(row, 0);
}
int EnvironmentModel::findInResult(const QString &name) const
{
Environment::const_iterator it;
......@@ -230,6 +238,7 @@ bool EnvironmentModel::setData(const QModelIndex &index, const QVariant &value,
removeVariable(old.name);
old.name = newName;
addVariable(old);
emit renamedVariable(newName);
return true;
} else if (index.column() == 1) {
const QString &name = indexToVariable(index);
......@@ -364,6 +373,9 @@ EnvironmentWidget::EnvironmentWidget(QWidget *parent, QWidget *additionalDetails
connect(m_model, SIGNAL(userChangesChanged()),
this, SIGNAL(userChangesChanged()));
connect(m_model, SIGNAL(renamedVariable(QString)),
this, SLOT(renamedVariable(QString)));
QVBoxLayout *vbox = new QVBoxLayout(this);
vbox->setContentsMargins(0, 0, 0, 0);
......@@ -439,6 +451,13 @@ EnvironmentWidget::~EnvironmentWidget()
m_model = 0;
}
void EnvironmentWidget::renamedVariable(const QString& name)
{
QModelIndex idx = m_model->index(name);
m_environmentTreeView->setCurrentIndex(idx);
m_environmentTreeView->setFocus();
}
void EnvironmentWidget::setBaseEnvironment(const ProjectExplorer::Environment &env)
{
m_model->setBaseEnvironment(env);
......
......@@ -75,18 +75,27 @@ public:
bool isInBaseEnvironment(const QString &name);
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
QString indexToVariable(const QModelIndex &index) const;
QModelIndex index(const QString &name);
bool changes(const QString &key) const;
QList<EnvironmentItem> userChanges() const;
void setUserChanges(QList<EnvironmentItem> list);
signals:
void userChangesChanged();
/// Strictly speaking this is a hack to work around
/// the problem that we don't emit the right signals
/// on editing a variable
/// Don't try to fix that with out consulting me
/// In short it's impossible to emit the right signals
/// and to ensure that the model is in a consistent
/// state at each signal emission
void renamedVariable(const QString &newName);
private:
void updateResultEnvironment();
int findInChanges(const QString &name) const;
int findInResult(const QString &name) const;
int findInChangesInsertPosition(const QString &name) const;
int findInResultInsertPosition(const QString &name) const;
int findInResult(const QString &name) const;
ProjectExplorer::Environment m_baseEnvironment;
ProjectExplorer::Environment m_resultEnvironment;
......@@ -119,6 +128,7 @@ private slots:
void unsetEnvironmentButtonClicked();
void environmentCurrentIndexChanged(const QModelIndex &current, const QModelIndex &previous);
void updateSummaryText();
void renamedVariable(const QString &name);
private:
EnvironmentModel *m_model;
......
......@@ -210,7 +210,8 @@ public:
void removeVersion(QtVersion *version);
// Static Methods
static QPair<QtVersion::QmakeBuildConfigs, QStringList> scanMakeFile(const QString &directory, QtVersion::QmakeBuildConfigs defaultBuildConfig);
static QPair<QtVersion::QmakeBuildConfigs, QStringList> scanMakeFile(const QString &directory,
QtVersion::QmakeBuildConfigs defaultBuildConfig);
static QString findQMakeBinaryFromMakefile(const QString &directory);
signals:
void defaultQtVersionChanged();
......@@ -225,8 +226,12 @@ private:
static QString findQMakeLine(const QString &directory);
static QString trimLine(const QString line);
static QStringList splitLine(const QString &line);
static void parseParts(const QStringList &parts, QList<QMakeAssignment> *assignments, QList<QMakeAssignment> *afterAssignments, QStringList *additionalArguments);
static QtVersion::QmakeBuildConfigs qmakeBuildConfigFromCmdArgs(QList<QMakeAssignment> *assignments, QtVersion::QmakeBuildConfigs defaultBuildConfig);
static void parseParts(const QStringList &parts,
QList<QMakeAssignment> *assignments,
QList<QMakeAssignment> *afterAssignments,
QStringList *additionalArguments);
static QtVersion::QmakeBuildConfigs qmakeBuildConfigFromCmdArgs(QList<QMakeAssignment> *assignments,
QtVersion::QmakeBuildConfigs defaultBuildConfig);
// Used by QtOptionsPage
void setNewQtVersions(QList<QtVersion *> newVersions, int newDefaultVersion);
// Used by QtVersion
......
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