forked from qt-creator/qt-creator
Remove no longer used code from EnviromentEditModel/Widget
That is unmerged environments
This commit is contained in:
@@ -45,7 +45,6 @@
|
||||
using namespace ProjectExplorer;
|
||||
|
||||
EnvironmentModel::EnvironmentModel()
|
||||
: m_mergedEnvironments(false)
|
||||
{}
|
||||
|
||||
EnvironmentModel::~EnvironmentModel()
|
||||
@@ -53,10 +52,7 @@ EnvironmentModel::~EnvironmentModel()
|
||||
|
||||
QString EnvironmentModel::indexToVariable(const QModelIndex &index) const
|
||||
{
|
||||
if (m_mergedEnvironments)
|
||||
return m_resultEnvironment.key(m_resultEnvironment.constBegin() + index.row());
|
||||
else
|
||||
return m_items.at(index.row()).name;
|
||||
}
|
||||
|
||||
void EnvironmentModel::updateResultEnvironment()
|
||||
@@ -77,27 +73,12 @@ void EnvironmentModel::setBaseEnvironment(const ProjectExplorer::Environment &en
|
||||
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
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
|
||||
return m_mergedEnvironments ? m_resultEnvironment.size() : m_items.count();
|
||||
return m_resultEnvironment.size();
|
||||
}
|
||||
int EnvironmentModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
@@ -116,42 +97,28 @@ bool EnvironmentModel::changes(const QString &name) const
|
||||
QVariant EnvironmentModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if ((role == Qt::DisplayRole || role == Qt::EditRole) && index.isValid()) {
|
||||
if ((m_mergedEnvironments && index.row() >= m_resultEnvironment.size()) ||
|
||||
(!m_mergedEnvironments && index.row() >= m_items.count())) {
|
||||
if (index.row() >= m_resultEnvironment.size()) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
if (index.column() == 0) {
|
||||
if (m_mergedEnvironments) {
|
||||
return m_resultEnvironment.key(m_resultEnvironment.constBegin() + index.row());
|
||||
} else {
|
||||
return m_items.at(index.row()).name;
|
||||
}
|
||||
} else if (index.column() == 1) {
|
||||
if (m_mergedEnvironments) {
|
||||
if (role == Qt::EditRole) {
|
||||
int pos = findInChanges(indexToVariable(index));
|
||||
if (pos != -1)
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (role == Qt::FontRole) {
|
||||
if (m_mergedEnvironments) {
|
||||
// check wheter this environment variable exists in m_items
|
||||
if (changes(m_resultEnvironment.key(m_resultEnvironment.constBegin() + index.row()))) {
|
||||
QFont f;
|
||||
f.setBold(true);
|
||||
return QVariant(f);
|
||||
}
|
||||
}
|
||||
return QFont();
|
||||
}
|
||||
return QVariant();
|
||||
@@ -250,7 +217,6 @@ bool EnvironmentModel::setData(const QModelIndex &index, const QVariant &value,
|
||||
return false;
|
||||
|
||||
EnvironmentItem old("", "");
|
||||
if (m_mergedEnvironments) {
|
||||
int pos = findInChanges(indexToVariable(index));
|
||||
if (pos != -1) {
|
||||
old = m_items.at(pos);
|
||||
@@ -259,9 +225,6 @@ bool EnvironmentModel::setData(const QModelIndex &index, const QVariant &value,
|
||||
old.value = m_resultEnvironment.value(m_resultEnvironment.constBegin() + index.row());
|
||||
old.unset = false;
|
||||
}
|
||||
} else {
|
||||
old = m_items.at(index.row());
|
||||
}
|
||||
|
||||
if (changes(old.name))
|
||||
removeVariable(old.name);
|
||||
@@ -269,7 +232,6 @@ bool EnvironmentModel::setData(const QModelIndex &index, const QVariant &value,
|
||||
addVariable(old);
|
||||
return true;
|
||||
} else if (index.column() == 1) {
|
||||
if (m_mergedEnvironments) {
|
||||
const QString &name = indexToVariable(index);
|
||||
int pos = findInChanges(name);
|
||||
if (pos != -1) {
|
||||
@@ -283,13 +245,6 @@ bool EnvironmentModel::setData(const QModelIndex &index, const QVariant &value,
|
||||
// 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 userChangesChanged();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -298,22 +253,15 @@ bool EnvironmentModel::setData(const QModelIndex &index, const QVariant &value,
|
||||
QModelIndex EnvironmentModel::addVariable()
|
||||
{
|
||||
const QString name = tr("<VARIABLE>");
|
||||
if (m_mergedEnvironments) {
|
||||
int i = findInResult(name);
|
||||
if (i != -1)
|
||||
return index(i, 0, QModelIndex());
|
||||
} else {
|
||||
int i = findInChanges(name);
|
||||
if (i != -1)
|
||||
return index(i, 0, QModelIndex());
|
||||
}
|
||||
// Don't exist, really add them
|
||||
return addVariable(EnvironmentItem(name, tr("<VALUE>")));
|
||||
}
|
||||
|
||||
QModelIndex EnvironmentModel::addVariable(const EnvironmentItem &item)
|
||||
{
|
||||
if (m_mergedEnvironments) {
|
||||
bool existsInBaseEnvironment = (m_baseEnvironment.find(item.name) != m_baseEnvironment.constEnd());
|
||||
int rowInResult;
|
||||
if (existsInBaseEnvironment)
|
||||
@@ -338,19 +286,10 @@ QModelIndex EnvironmentModel::addVariable(const EnvironmentItem &item)
|
||||
emit userChangesChanged();
|
||||
return index(rowInResult, 0, QModelIndex());
|
||||
}
|
||||
} else {
|
||||
int newPos = findInChangesInsertPosition(item.name);
|
||||
beginInsertRows(QModelIndex(), newPos, newPos);
|
||||
m_items.insert(newPos, item);
|
||||
endInsertRows();
|
||||
emit userChangesChanged();
|
||||
return index(newPos, 0, QModelIndex());
|
||||
}
|
||||
}
|
||||
|
||||
void EnvironmentModel::removeVariable(const QString &name)
|
||||
{
|
||||
if (m_mergedEnvironments) {
|
||||
int rowInResult = findInResult(name);
|
||||
int rowInChanges = findInChanges(name);
|
||||
bool existsInBaseEnvironment = m_baseEnvironment.find(name) != m_baseEnvironment.constEnd();
|
||||
@@ -366,19 +305,10 @@ void EnvironmentModel::removeVariable(const QString &name)
|
||||
endRemoveRows();
|
||||
emit userChangesChanged();
|
||||
}
|
||||
} else {
|
||||
int removePos = findInChanges(name);
|
||||
beginRemoveRows(QModelIndex(), removePos, removePos);
|
||||
m_items.removeAt(removePos);
|
||||
updateResultEnvironment();
|
||||
endRemoveRows();
|
||||
emit userChangesChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void EnvironmentModel::unset(const QString &name)
|
||||
{
|
||||
if (m_mergedEnvironments) {
|
||||
int row = findInResult(name);
|
||||
// look in m_items for the variable
|
||||
int pos = findInChanges(name);
|
||||
@@ -395,14 +325,6 @@ void EnvironmentModel::unset(const QString &name)
|
||||
updateResultEnvironment();
|
||||
emit dataChanged(index(row, 0, QModelIndex()), index(row, 1, QModelIndex()));
|
||||
emit userChangesChanged();
|
||||
return;
|
||||
} else {
|
||||
int pos = findInChanges(name);
|
||||
m_items[pos].unset = true;
|
||||
emit dataChanged(index(pos, 1, QModelIndex()), index(pos, 1, QModelIndex()));
|
||||
emit userChangesChanged();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool EnvironmentModel::isUnset(const QString &name)
|
||||
@@ -439,7 +361,6 @@ EnvironmentWidget::EnvironmentWidget(QWidget *parent, QWidget *additionalDetails
|
||||
: QWidget(parent)
|
||||
{
|
||||
m_model = new EnvironmentModel();
|
||||
m_model->setMergedEnvironments(true);
|
||||
connect(m_model, SIGNAL(userChangesChanged()),
|
||||
this, SIGNAL(userChangesChanged()));
|
||||
|
||||
@@ -523,16 +444,6 @@ void EnvironmentWidget::setBaseEnvironment(const ProjectExplorer::Environment &e
|
||||
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
|
||||
{
|
||||
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
|
||||
// or remove when it is just a change we added
|
||||
// unset in changes view, means just unset
|
||||
void EnvironmentWidget::unsetEnvironmentButtonClicked()
|
||||
{
|
||||
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);
|
||||
else
|
||||
m_model->unset(name);
|
||||
@@ -606,16 +516,11 @@ void EnvironmentWidget::environmentCurrentIndexChanged(const QModelIndex ¤
|
||||
Q_UNUSED(previous)
|
||||
if (current.isValid()) {
|
||||
m_editButton->setEnabled(true);
|
||||
if (m_model->mergedEnvironments()) {
|
||||
const QString &name = m_model->indexToVariable(current);
|
||||
bool modified = m_model->isInBaseEnvironment(name) && m_model->changes(name);
|
||||
bool unset = m_model->isUnset(name);
|
||||
m_removeButton->setEnabled(modified || unset);
|
||||
m_unsetButton->setEnabled(!unset);
|
||||
} else {
|
||||
m_removeButton->setEnabled(true);
|
||||
m_unsetButton->setEnabled(!m_model->isUnset(m_model->indexToVariable(current)));
|
||||
}
|
||||
} else {
|
||||
m_editButton->setEnabled(false);
|
||||
m_removeButton->setEnabled(false);
|
||||
|
@@ -58,8 +58,6 @@ public:
|
||||
EnvironmentModel();
|
||||
~EnvironmentModel();
|
||||
void setBaseEnvironment(const ProjectExplorer::Environment &env);
|
||||
void setMergedEnvironments(bool b);
|
||||
bool mergedEnvironments();
|
||||
int rowCount(const QModelIndex &parent) const;
|
||||
int columnCount(const QModelIndex &parent) const;
|
||||
|
||||
@@ -93,7 +91,6 @@ private:
|
||||
ProjectExplorer::Environment m_baseEnvironment;
|
||||
ProjectExplorer::Environment m_resultEnvironment;
|
||||
QList<EnvironmentItem> m_items;
|
||||
bool m_mergedEnvironments;
|
||||
};
|
||||
|
||||
class PROJECTEXPLORER_EXPORT EnvironmentWidget : public QWidget
|
||||
@@ -105,9 +102,6 @@ public:
|
||||
|
||||
void setBaseEnvironment(const ProjectExplorer::Environment &env);
|
||||
|
||||
void setMergedEnvironments(bool b);
|
||||
bool mergedEnvironments();
|
||||
|
||||
QList<EnvironmentItem> userChanges() const;
|
||||
void setUserChanges(QList<EnvironmentItem> list);
|
||||
|
||||
@@ -134,8 +128,6 @@ private:
|
||||
QPushButton *m_addButton;
|
||||
QPushButton *m_removeButton;
|
||||
QPushButton *m_unsetButton;
|
||||
|
||||
|
||||
};
|
||||
|
||||
} // namespace ProjectExplorer
|
||||
|
Reference in New Issue
Block a user