From 089e5d38409ad387bfb1788420f5c19bc260df1e Mon Sep 17 00:00:00 2001
From: Tobias Hunger <tobias.hunger@nokia.com>
Date: Wed, 21 Apr 2010 11:40:22 +0200
Subject: [PATCH] Cleanup EnvironmentEditModel

 * Remove now unused code
 * Make updateButtons private
 * Remove unnecessary calls to update Button

Reviewed-by: dt
---
 .../buildenvironmentwidget.cpp                |  1 -
 .../projectexplorer/environmenteditmodel.cpp  | 20 -------------------
 .../projectexplorer/environmenteditmodel.h    | 15 +++-----------
 3 files changed, 3 insertions(+), 33 deletions(-)

diff --git a/src/plugins/projectexplorer/buildenvironmentwidget.cpp b/src/plugins/projectexplorer/buildenvironmentwidget.cpp
index e7f741f9351..c0a65cfd25a 100644
--- a/src/plugins/projectexplorer/buildenvironmentwidget.cpp
+++ b/src/plugins/projectexplorer/buildenvironmentwidget.cpp
@@ -85,7 +85,6 @@ void BuildEnvironmentWidget::init(BuildConfiguration *bc)
     m_buildEnvironmentWidget->setBaseEnvironment(m_buildConfiguration->baseEnvironment());
     m_buildEnvironmentWidget->setBaseEnvironmentText(m_buildConfiguration->baseEnvironmentText());
     m_buildEnvironmentWidget->setUserChanges(m_buildConfiguration->userEnvironmentChanges());
-    m_buildEnvironmentWidget->updateButtons();
 }
 
 void BuildEnvironmentWidget::environmentModelUserChangesChanged()
diff --git a/src/plugins/projectexplorer/environmenteditmodel.cpp b/src/plugins/projectexplorer/environmenteditmodel.cpp
index f50df4de923..3481e324302 100644
--- a/src/plugins/projectexplorer/environmenteditmodel.cpp
+++ b/src/plugins/projectexplorer/environmenteditmodel.cpp
@@ -152,14 +152,6 @@ int EnvironmentModel::findInChanges(const QString &name) const
     return -1;
 }
 
-int EnvironmentModel::findInChangesInsertPosition(const QString &name) const
-{
-    for (int i=0; i<m_items.size(); ++i)
-        if (m_items.at(i).name > name)
-            return i;
-    return m_items.size();
-}
-
 QModelIndex EnvironmentModel::variableToIndex(const QString &name) const
 {
     int row = findInResult(name);
@@ -380,8 +372,6 @@ EnvironmentWidget::EnvironmentWidget(QWidget *parent, QWidget *additionalDetails
     connect(m_model, SIGNAL(modelReset()),
             this, SLOT(invalidateCurrentIndex()));
 
-    connect(m_model, SIGNAL(renamedVariable(QString)),
-            this, SLOT(renamedVariable(QString)));
     connect(m_model, SIGNAL(focusIndex(QModelIndex)),
             this, SLOT(focusIndex(QModelIndex)));
 
@@ -460,13 +450,6 @@ EnvironmentWidget::~EnvironmentWidget()
     m_model = 0;
 }
 
-void EnvironmentWidget::renamedVariable(const QString &name)
-{
-    QModelIndex index = m_model->variableToIndex(name);
-    m_environmentTreeView->setCurrentIndex(index);
-    m_environmentTreeView->setFocus();
-}
-
 void EnvironmentWidget::focusIndex(const QModelIndex &index)
 {
     m_environmentTreeView->setCurrentIndex(index);
@@ -532,14 +515,12 @@ void EnvironmentWidget::addEnvironmentButtonClicked()
     QModelIndex index = m_model->addVariable();
     m_environmentTreeView->setCurrentIndex(index);
     m_environmentTreeView->edit(index);
-    updateButtons();
 }
 
 void EnvironmentWidget::removeEnvironmentButtonClicked()
 {
     const QString &name = m_model->indexToVariable(m_environmentTreeView->currentIndex());
     m_model->resetVariable(name);
-    updateButtons();
 }
 
 // unset in Merged Environment Mode means, unset if it comes from the base environment
@@ -551,7 +532,6 @@ void EnvironmentWidget::unsetEnvironmentButtonClicked()
         m_model->resetVariable(name);
     else
         m_model->unsetVariable(name);
-    updateButtons();
 }
 
 void EnvironmentWidget::environmentCurrentIndexChanged(const QModelIndex &current)
diff --git a/src/plugins/projectexplorer/environmenteditmodel.h b/src/plugins/projectexplorer/environmenteditmodel.h
index 485f02360d6..6aafe946026 100644
--- a/src/plugins/projectexplorer/environmenteditmodel.h
+++ b/src/plugins/projectexplorer/environmenteditmodel.h
@@ -76,21 +76,14 @@ public:
 
 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);
     /// Hint to the view where it should make sense to focus on next
+    // This is a hack since there is no way for a model to suggest
+    // the next interesting place to focus on to the view.
     void focusIndex(const QModelIndex &index);
 
 private:
     void updateResultEnvironment();
     int findInChanges(const QString &name) const;
-    int findInChangesInsertPosition(const QString &name) const;
     int findInResultInsertPosition(const QString &name) const;
     int findInResult(const QString &name) const;
 
@@ -112,8 +105,6 @@ public:
     QList<EnvironmentItem> userChanges() const;
     void setUserChanges(QList<EnvironmentItem> list);
 
-public slots:
-    void updateButtons();
 
 signals:
     void userChangesChanged();
@@ -127,8 +118,8 @@ private slots:
     void environmentCurrentIndexChanged(const QModelIndex &current);
     void invalidateCurrentIndex();
     void updateSummaryText();
-    void renamedVariable(const QString &name);
     void focusIndex(const QModelIndex &index);
+    void updateButtons();
 
 private:
     EnvironmentModel *m_model;
-- 
GitLab