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;
|
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,42 +97,28 @@ 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());
|
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 (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();
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
@@ -250,7 +217,6 @@ 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);
|
||||||
@@ -259,9 +225,6 @@ bool EnvironmentModel::setData(const QModelIndex &index, const QVariant &value,
|
|||||||
old.value = m_resultEnvironment.value(m_resultEnvironment.constBegin() + index.row());
|
old.value = m_resultEnvironment.value(m_resultEnvironment.constBegin() + index.row());
|
||||||
old.unset = false;
|
old.unset = false;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
old = m_items.at(index.row());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (changes(old.name))
|
if (changes(old.name))
|
||||||
removeVariable(old.name);
|
removeVariable(old.name);
|
||||||
@@ -269,7 +232,6 @@ 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) {
|
||||||
@@ -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
|
// not found in m_items, so add it as a new variable
|
||||||
addVariable(EnvironmentItem(name, value.toString()));
|
addVariable(EnvironmentItem(name, value.toString()));
|
||||||
return true;
|
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;
|
return false;
|
||||||
@@ -298,22 +253,15 @@ 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)
|
||||||
@@ -338,19 +286,10 @@ QModelIndex EnvironmentModel::addVariable(const EnvironmentItem &item)
|
|||||||
emit userChangesChanged();
|
emit userChangesChanged();
|
||||||
return index(rowInResult, 0, QModelIndex());
|
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)
|
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();
|
||||||
@@ -366,19 +305,10 @@ void EnvironmentModel::removeVariable(const QString &name)
|
|||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
emit userChangesChanged();
|
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)
|
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);
|
||||||
@@ -395,14 +325,6 @@ void EnvironmentModel::unset(const QString &name)
|
|||||||
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;
|
|
||||||
} 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)
|
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 ¤
|
|||||||
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);
|
||||||
|
@@ -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
|
||||||
|
Reference in New Issue
Block a user