Remove no longer used code from EnviromentEditModel/Widget

That is unmerged environments
This commit is contained in:
dt
2009-12-09 19:29:04 +01:00
parent b661cb9992
commit 73602b48be
2 changed files with 76 additions and 179 deletions

View File

@@ -45,7 +45,6 @@
using namespace ProjectExplorer; using namespace ProjectExplorer;
EnvironmentModel::EnvironmentModel() EnvironmentModel::EnvironmentModel()
: m_mergedEnvironments(false)
{} {}
EnvironmentModel::~EnvironmentModel() EnvironmentModel::~EnvironmentModel()
@@ -53,10 +52,7 @@ EnvironmentModel::~EnvironmentModel()
QString EnvironmentModel::indexToVariable(const QModelIndex &index) const QString EnvironmentModel::indexToVariable(const QModelIndex &index) const
{ {
if (m_mergedEnvironments) return m_resultEnvironment.key(m_resultEnvironment.constBegin() + index.row());
return m_resultEnvironment.key(m_resultEnvironment.constBegin() + index.row());
else
return m_items.at(index.row()).name;
} }
void EnvironmentModel::updateResultEnvironment() void EnvironmentModel::updateResultEnvironment()
@@ -77,27 +73,12 @@ void EnvironmentModel::setBaseEnvironment(const ProjectExplorer::Environment &en
reset(); reset();
} }
void EnvironmentModel::setMergedEnvironments(bool b)
{
if (m_mergedEnvironments == b)
return;
m_mergedEnvironments = b;
if (b)
updateResultEnvironment();
reset();
}
bool EnvironmentModel::mergedEnvironments()
{
return m_mergedEnvironments;
}
int EnvironmentModel::rowCount(const QModelIndex &parent) const int EnvironmentModel::rowCount(const QModelIndex &parent) const
{ {
if (parent.isValid()) if (parent.isValid())
return 0; return 0;
return m_mergedEnvironments ? m_resultEnvironment.size() : m_items.count(); return m_resultEnvironment.size();
} }
int EnvironmentModel::columnCount(const QModelIndex &parent) const int EnvironmentModel::columnCount(const QModelIndex &parent) const
{ {
@@ -116,41 +97,27 @@ bool EnvironmentModel::changes(const QString &name) const
QVariant EnvironmentModel::data(const QModelIndex &index, int role) const QVariant EnvironmentModel::data(const QModelIndex &index, int role) const
{ {
if ((role == Qt::DisplayRole || role == Qt::EditRole) && index.isValid()) { if ((role == Qt::DisplayRole || role == Qt::EditRole) && index.isValid()) {
if ((m_mergedEnvironments && index.row() >= m_resultEnvironment.size()) || if (index.row() >= m_resultEnvironment.size()) {
(!m_mergedEnvironments && index.row() >= m_items.count())) {
return QVariant(); return QVariant();
} }
if (index.column() == 0) { if (index.column() == 0) {
if (m_mergedEnvironments) { return m_resultEnvironment.key(m_resultEnvironment.constBegin() + index.row());
return m_resultEnvironment.key(m_resultEnvironment.constBegin() + index.row());
} else {
return m_items.at(index.row()).name;
}
} else if (index.column() == 1) { } else if (index.column() == 1) {
if (m_mergedEnvironments) { if (role == Qt::EditRole) {
if (role == Qt::EditRole) { int pos = findInChanges(indexToVariable(index));
int pos = findInChanges(indexToVariable(index)); if (pos != -1)
if (pos != -1) return m_items.at(pos).value;
return m_items.at(pos).value;
}
return m_resultEnvironment.value(m_resultEnvironment.constBegin() + index.row());
} else {
if (m_items.at(index.row()).unset)
return tr("<UNSET>");
else
return m_items.at(index.row()).value;
} }
return m_resultEnvironment.value(m_resultEnvironment.constBegin() + index.row());
} }
} }
if (role == Qt::FontRole) { if (role == Qt::FontRole) {
if (m_mergedEnvironments) { // check wheter this environment variable exists in m_items
// check wheter this environment variable exists in m_items if (changes(m_resultEnvironment.key(m_resultEnvironment.constBegin() + index.row()))) {
if (changes(m_resultEnvironment.key(m_resultEnvironment.constBegin() + index.row()))) { QFont f;
QFont f; f.setBold(true);
f.setBold(true); return QVariant(f);
return QVariant(f);
}
} }
return QFont(); return QFont();
} }
@@ -250,17 +217,13 @@ bool EnvironmentModel::setData(const QModelIndex &index, const QVariant &value,
return false; return false;
EnvironmentItem old("", ""); EnvironmentItem old("", "");
if (m_mergedEnvironments) { int pos = findInChanges(indexToVariable(index));
int pos = findInChanges(indexToVariable(index)); if (pos != -1) {
if (pos != -1) { old = m_items.at(pos);
old = m_items.at(pos);
} else {
old.name = m_resultEnvironment.key(m_resultEnvironment.constBegin() + index.row());
old.value = m_resultEnvironment.value(m_resultEnvironment.constBegin() + index.row());
old.unset = false;
}
} else { } else {
old = m_items.at(index.row()); old.name = m_resultEnvironment.key(m_resultEnvironment.constBegin() + index.row());
old.value = m_resultEnvironment.value(m_resultEnvironment.constBegin() + index.row());
old.unset = false;
} }
if (changes(old.name)) if (changes(old.name))
@@ -269,27 +232,19 @@ bool EnvironmentModel::setData(const QModelIndex &index, const QVariant &value,
addVariable(old); addVariable(old);
return true; return true;
} else if (index.column() == 1) { } else if (index.column() == 1) {
if (m_mergedEnvironments) { const QString &name = indexToVariable(index);
const QString &name = indexToVariable(index); int pos = findInChanges(name);
int pos = findInChanges(name); if (pos != -1) {
if (pos != -1) { m_items[pos].value = value.toString();
m_items[pos].value = value.toString(); m_items[pos].unset = false;
m_items[pos].unset = false; updateResultEnvironment();
updateResultEnvironment();
emit dataChanged(index, index);
emit userChangesChanged();
return true;
}
// not found in m_items, so add it as a new variable
addVariable(EnvironmentItem(name, value.toString()));
return true;
} else {
m_items[index.row()].value = value.toString();
m_items[index.row()].unset = false;
emit dataChanged(index, index); emit dataChanged(index, index);
emit userChangesChanged(); emit userChangesChanged();
return true; return true;
} }
// not found in m_items, so add it as a new variable
addVariable(EnvironmentItem(name, value.toString()));
return true;
} }
} }
return false; return false;
@@ -298,78 +253,54 @@ bool EnvironmentModel::setData(const QModelIndex &index, const QVariant &value,
QModelIndex EnvironmentModel::addVariable() QModelIndex EnvironmentModel::addVariable()
{ {
const QString name = tr("<VARIABLE>"); const QString name = tr("<VARIABLE>");
if (m_mergedEnvironments) { int i = findInResult(name);
int i = findInResult(name); if (i != -1)
if (i != -1) return index(i, 0, QModelIndex());
return index(i, 0, QModelIndex());
} else {
int i = findInChanges(name);
if (i != -1)
return index(i, 0, QModelIndex());
}
// Don't exist, really add them // Don't exist, really add them
return addVariable(EnvironmentItem(name, tr("<VALUE>"))); return addVariable(EnvironmentItem(name, tr("<VALUE>")));
} }
QModelIndex EnvironmentModel::addVariable(const EnvironmentItem &item) QModelIndex EnvironmentModel::addVariable(const EnvironmentItem &item)
{ {
if (m_mergedEnvironments) { bool existsInBaseEnvironment = (m_baseEnvironment.find(item.name) != m_baseEnvironment.constEnd());
bool existsInBaseEnvironment = (m_baseEnvironment.find(item.name) != m_baseEnvironment.constEnd()); int rowInResult;
int rowInResult; if (existsInBaseEnvironment)
if (existsInBaseEnvironment) rowInResult = findInResult(item.name);
rowInResult = findInResult(item.name); else
else rowInResult = findInResultInsertPosition(item.name);
rowInResult = findInResultInsertPosition(item.name); int rowInChanges = findInChangesInsertPosition(item.name);
int rowInChanges = findInChangesInsertPosition(item.name);
//qDebug() << "addVariable " << item.name << existsInBaseEnvironment << rowInResult << rowInChanges; //qDebug() << "addVariable " << item.name << existsInBaseEnvironment << rowInResult << rowInChanges;
if (existsInBaseEnvironment) { if (existsInBaseEnvironment) {
m_items.insert(rowInChanges, item); m_items.insert(rowInChanges, item);
updateResultEnvironment(); updateResultEnvironment();
emit dataChanged(index(rowInResult, 0, QModelIndex()), index(rowInResult, 1, QModelIndex())); emit dataChanged(index(rowInResult, 0, QModelIndex()), index(rowInResult, 1, QModelIndex()));
emit userChangesChanged(); emit userChangesChanged();
return index(rowInResult, 0, QModelIndex()); return index(rowInResult, 0, QModelIndex());
} else {
beginInsertRows(QModelIndex(), rowInResult, rowInResult);
m_items.insert(rowInChanges, item);
updateResultEnvironment();
endInsertRows();
emit userChangesChanged();
return index(rowInResult, 0, QModelIndex());
}
} else { } else {
int newPos = findInChangesInsertPosition(item.name); beginInsertRows(QModelIndex(), rowInResult, rowInResult);
beginInsertRows(QModelIndex(), newPos, newPos); m_items.insert(rowInChanges, item);
m_items.insert(newPos, item); updateResultEnvironment();
endInsertRows(); endInsertRows();
emit userChangesChanged(); emit userChangesChanged();
return index(newPos, 0, QModelIndex()); return index(rowInResult, 0, QModelIndex());
} }
} }
void EnvironmentModel::removeVariable(const QString &name) void EnvironmentModel::removeVariable(const QString &name)
{ {
if (m_mergedEnvironments) { int rowInResult = findInResult(name);
int rowInResult = findInResult(name); int rowInChanges = findInChanges(name);
int rowInChanges = findInChanges(name); bool existsInBaseEnvironment = m_baseEnvironment.find(name) != m_baseEnvironment.constEnd();
bool existsInBaseEnvironment = m_baseEnvironment.find(name) != m_baseEnvironment.constEnd(); if (existsInBaseEnvironment) {
if (existsInBaseEnvironment) { m_items.removeAt(rowInChanges);
m_items.removeAt(rowInChanges); updateResultEnvironment();
updateResultEnvironment(); emit dataChanged(index(rowInResult, 0, QModelIndex()), index(rowInResult, 1, QModelIndex()));
emit dataChanged(index(rowInResult, 0, QModelIndex()), index(rowInResult, 1, QModelIndex())); emit userChangesChanged();
emit userChangesChanged();
} else {
beginRemoveRows(QModelIndex(), rowInResult, rowInResult);
m_items.removeAt(rowInChanges);
updateResultEnvironment();
endRemoveRows();
emit userChangesChanged();
}
} else { } else {
int removePos = findInChanges(name); beginRemoveRows(QModelIndex(), rowInResult, rowInResult);
beginRemoveRows(QModelIndex(), removePos, removePos); m_items.removeAt(rowInChanges);
m_items.removeAt(removePos);
updateResultEnvironment(); updateResultEnvironment();
endRemoveRows(); endRemoveRows();
emit userChangesChanged(); emit userChangesChanged();
@@ -378,31 +309,22 @@ void EnvironmentModel::removeVariable(const QString &name)
void EnvironmentModel::unset(const QString &name) void EnvironmentModel::unset(const QString &name)
{ {
if (m_mergedEnvironments) { int row = findInResult(name);
int row = findInResult(name); // look in m_items for the variable
// look in m_items for the variable int pos = findInChanges(name);
int pos = findInChanges(name); if (pos != -1) {
if (pos != -1) {
m_items[pos].unset = true;
updateResultEnvironment();
emit dataChanged(index(row, 0, QModelIndex()), index(row, 1, QModelIndex()));
emit userChangesChanged();
return;
}
pos = findInChangesInsertPosition(name);
m_items.insert(pos, EnvironmentItem(name, ""));
m_items[pos].unset = true; m_items[pos].unset = true;
updateResultEnvironment(); updateResultEnvironment();
emit dataChanged(index(row, 0, QModelIndex()), index(row, 1, QModelIndex())); emit dataChanged(index(row, 0, QModelIndex()), index(row, 1, QModelIndex()));
emit userChangesChanged(); emit userChangesChanged();
return; return;
} else {
int pos = findInChanges(name);
m_items[pos].unset = true;
emit dataChanged(index(pos, 1, QModelIndex()), index(pos, 1, QModelIndex()));
emit userChangesChanged();
return;
} }
pos = findInChangesInsertPosition(name);
m_items.insert(pos, EnvironmentItem(name, ""));
m_items[pos].unset = true;
updateResultEnvironment();
emit dataChanged(index(row, 0, QModelIndex()), index(row, 1, QModelIndex()));
emit userChangesChanged();
} }
bool EnvironmentModel::isUnset(const QString &name) bool EnvironmentModel::isUnset(const QString &name)
@@ -439,7 +361,6 @@ EnvironmentWidget::EnvironmentWidget(QWidget *parent, QWidget *additionalDetails
: QWidget(parent) : QWidget(parent)
{ {
m_model = new EnvironmentModel(); m_model = new EnvironmentModel();
m_model->setMergedEnvironments(true);
connect(m_model, SIGNAL(userChangesChanged()), connect(m_model, SIGNAL(userChangesChanged()),
this, SIGNAL(userChangesChanged())); this, SIGNAL(userChangesChanged()));
@@ -523,16 +444,6 @@ void EnvironmentWidget::setBaseEnvironment(const ProjectExplorer::Environment &e
m_model->setBaseEnvironment(env); m_model->setBaseEnvironment(env);
} }
void EnvironmentWidget::setMergedEnvironments(bool b)
{
m_model->setMergedEnvironments(b);
}
bool EnvironmentWidget::mergedEnvironments()
{
return m_model->mergedEnvironments();
}
QList<EnvironmentItem> EnvironmentWidget::userChanges() const QList<EnvironmentItem> EnvironmentWidget::userChanges() const
{ {
return m_model->userChanges(); return m_model->userChanges();
@@ -590,11 +501,10 @@ void EnvironmentWidget::removeEnvironmentButtonClicked()
// unset in Merged Environment Mode means, unset if it comes from the base environment // unset in Merged Environment Mode means, unset if it comes from the base environment
// or remove when it is just a change we added // or remove when it is just a change we added
// unset in changes view, means just unset
void EnvironmentWidget::unsetEnvironmentButtonClicked() void EnvironmentWidget::unsetEnvironmentButtonClicked()
{ {
const QString &name = m_model->indexToVariable(m_environmentTreeView->currentIndex()); const QString &name = m_model->indexToVariable(m_environmentTreeView->currentIndex());
if (!m_model->isInBaseEnvironment(name) && m_model->mergedEnvironments()) if (!m_model->isInBaseEnvironment(name))
m_model->removeVariable(name); m_model->removeVariable(name);
else else
m_model->unset(name); m_model->unset(name);
@@ -606,16 +516,11 @@ void EnvironmentWidget::environmentCurrentIndexChanged(const QModelIndex &curren
Q_UNUSED(previous) Q_UNUSED(previous)
if (current.isValid()) { if (current.isValid()) {
m_editButton->setEnabled(true); m_editButton->setEnabled(true);
if (m_model->mergedEnvironments()) { const QString &name = m_model->indexToVariable(current);
const QString &name = m_model->indexToVariable(current); bool modified = m_model->isInBaseEnvironment(name) && m_model->changes(name);
bool modified = m_model->isInBaseEnvironment(name) && m_model->changes(name); bool unset = m_model->isUnset(name);
bool unset = m_model->isUnset(name); m_removeButton->setEnabled(modified || unset);
m_removeButton->setEnabled(modified || unset); m_unsetButton->setEnabled(!unset);
m_unsetButton->setEnabled(!unset);
} else {
m_removeButton->setEnabled(true);
m_unsetButton->setEnabled(!m_model->isUnset(m_model->indexToVariable(current)));
}
} else { } else {
m_editButton->setEnabled(false); m_editButton->setEnabled(false);
m_removeButton->setEnabled(false); m_removeButton->setEnabled(false);

View File

@@ -58,8 +58,6 @@ public:
EnvironmentModel(); EnvironmentModel();
~EnvironmentModel(); ~EnvironmentModel();
void setBaseEnvironment(const ProjectExplorer::Environment &env); void setBaseEnvironment(const ProjectExplorer::Environment &env);
void setMergedEnvironments(bool b);
bool mergedEnvironments();
int rowCount(const QModelIndex &parent) const; int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const; int columnCount(const QModelIndex &parent) const;
@@ -93,7 +91,6 @@ private:
ProjectExplorer::Environment m_baseEnvironment; ProjectExplorer::Environment m_baseEnvironment;
ProjectExplorer::Environment m_resultEnvironment; ProjectExplorer::Environment m_resultEnvironment;
QList<EnvironmentItem> m_items; QList<EnvironmentItem> m_items;
bool m_mergedEnvironments;
}; };
class PROJECTEXPLORER_EXPORT EnvironmentWidget : public QWidget class PROJECTEXPLORER_EXPORT EnvironmentWidget : public QWidget
@@ -105,9 +102,6 @@ public:
void setBaseEnvironment(const ProjectExplorer::Environment &env); void setBaseEnvironment(const ProjectExplorer::Environment &env);
void setMergedEnvironments(bool b);
bool mergedEnvironments();
QList<EnvironmentItem> userChanges() const; QList<EnvironmentItem> userChanges() const;
void setUserChanges(QList<EnvironmentItem> list); void setUserChanges(QList<EnvironmentItem> list);
@@ -134,8 +128,6 @@ private:
QPushButton *m_addButton; QPushButton *m_addButton;
QPushButton *m_removeButton; QPushButton *m_removeButton;
QPushButton *m_unsetButton; QPushButton *m_unsetButton;
}; };
} // namespace ProjectExplorer } // namespace ProjectExplorer