2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "environmenteditmodel.h"
|
|
|
|
|
|
2009-10-01 16:38:08 +02:00
|
|
|
#include <utils/detailswidget.h>
|
2009-09-17 13:59:10 +02:00
|
|
|
|
2009-05-26 14:02:16 +02:00
|
|
|
#include <QtGui/QVBoxLayout>
|
|
|
|
|
#include <QtGui/QHeaderView>
|
2009-07-30 17:42:58 +02:00
|
|
|
#include <QtGui/QToolButton>
|
2009-09-29 11:39:55 +02:00
|
|
|
#include <QtCore/QDebug>
|
|
|
|
|
#include <QtGui/QWidget>
|
|
|
|
|
#include <QtGui/QCheckBox>
|
|
|
|
|
#include <QtGui/QTreeView>
|
|
|
|
|
#include <QtGui/QPushButton>
|
|
|
|
|
#include <QtGui/QLabel>
|
|
|
|
|
#include <QtGui/QStackedWidget>
|
2009-05-26 14:02:16 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
|
|
|
|
EnvironmentModel::EnvironmentModel()
|
|
|
|
|
{}
|
2008-12-09 11:07:24 +01:00
|
|
|
|
|
|
|
|
EnvironmentModel::~EnvironmentModel()
|
|
|
|
|
{}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QString EnvironmentModel::indexToVariable(const QModelIndex &index) const
|
|
|
|
|
{
|
2009-12-09 19:29:04 +01:00
|
|
|
return m_resultEnvironment.key(m_resultEnvironment.constBegin() + index.row());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EnvironmentModel::updateResultEnvironment()
|
|
|
|
|
{
|
|
|
|
|
m_resultEnvironment = m_baseEnvironment;
|
|
|
|
|
m_resultEnvironment.modify(m_items);
|
2010-04-19 18:43:17 +02:00
|
|
|
// Add removed variables again and mark them as "<UNSET>" so
|
|
|
|
|
// that the user can actually see those removals:
|
2008-12-02 12:01:29 +01:00
|
|
|
foreach (const EnvironmentItem &item, m_items) {
|
2008-12-09 11:07:24 +01:00
|
|
|
if (item.unset) {
|
2009-08-10 11:34:16 +02:00
|
|
|
m_resultEnvironment.set(item.name, tr("<UNSET>"));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EnvironmentModel::setBaseEnvironment(const ProjectExplorer::Environment &env)
|
|
|
|
|
{
|
2010-04-21 10:15:40 +02:00
|
|
|
if (m_baseEnvironment == env)
|
|
|
|
|
return;
|
2010-04-19 18:43:17 +02:00
|
|
|
beginResetModel();
|
2008-12-02 12:01:29 +01:00
|
|
|
m_baseEnvironment = env;
|
|
|
|
|
updateResultEnvironment();
|
2010-04-19 18:43:17 +02:00
|
|
|
endResetModel();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int EnvironmentModel::rowCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
|
|
|
|
if (parent.isValid())
|
|
|
|
|
return 0;
|
|
|
|
|
|
2009-12-09 19:29:04 +01:00
|
|
|
return m_resultEnvironment.size();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
int EnvironmentModel::columnCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
2010-04-19 18:43:17 +02:00
|
|
|
if (parent.isValid())
|
|
|
|
|
return 0;
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool EnvironmentModel::changes(const QString &name) const
|
|
|
|
|
{
|
2010-04-19 18:43:17 +02:00
|
|
|
return findInChanges(name) >= 0;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant EnvironmentModel::data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
2010-04-19 18:43:17 +02:00
|
|
|
if (!index.isValid())
|
|
|
|
|
return QVariant();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-04-19 18:43:17 +02:00
|
|
|
if ((role == Qt::DisplayRole || role == Qt::EditRole)) {
|
2008-12-09 11:07:24 +01:00
|
|
|
if (index.column() == 0) {
|
2009-12-09 19:29:04 +01:00
|
|
|
return m_resultEnvironment.key(m_resultEnvironment.constBegin() + index.row());
|
2008-12-09 11:07:24 +01:00
|
|
|
} else if (index.column() == 1) {
|
2009-12-09 19:29:04 +01:00
|
|
|
if (role == Qt::EditRole) {
|
|
|
|
|
int pos = findInChanges(indexToVariable(index));
|
|
|
|
|
if (pos != -1)
|
|
|
|
|
return m_items.at(pos).value;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-12-09 19:29:04 +01:00
|
|
|
return m_resultEnvironment.value(m_resultEnvironment.constBegin() + index.row());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
2008-12-09 11:07:24 +01:00
|
|
|
if (role == Qt::FontRole) {
|
2010-01-11 10:22:55 +01:00
|
|
|
// check whether this environment variable exists in m_items
|
2009-12-09 19:29:04 +01:00
|
|
|
if (changes(m_resultEnvironment.key(m_resultEnvironment.constBegin() + index.row()))) {
|
|
|
|
|
QFont f;
|
|
|
|
|
f.setBold(true);
|
|
|
|
|
return QVariant(f);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
return QFont();
|
|
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Qt::ItemFlags EnvironmentModel::flags(const QModelIndex &index) const
|
|
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(index)
|
2008-12-02 12:01:29 +01:00
|
|
|
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant EnvironmentModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
|
{
|
2008-12-09 11:07:24 +01:00
|
|
|
if (orientation == Qt::Vertical || role != Qt::DisplayRole)
|
2008-12-02 12:01:29 +01:00
|
|
|
return QVariant();
|
|
|
|
|
return section == 0 ? tr("Variable") : tr("Value");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// *****************
|
|
|
|
|
/// Utility functions
|
|
|
|
|
/// *****************
|
|
|
|
|
int EnvironmentModel::findInChanges(const QString &name) const
|
|
|
|
|
{
|
2008-12-09 11:07:24 +01:00
|
|
|
for (int i=0; i<m_items.size(); ++i)
|
|
|
|
|
if (m_items.at(i).name == name)
|
2008-12-02 12:01:29 +01:00
|
|
|
return i;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int EnvironmentModel::findInChangesInsertPosition(const QString &name) const
|
|
|
|
|
{
|
2008-12-09 11:07:24 +01:00
|
|
|
for (int i=0; i<m_items.size(); ++i)
|
|
|
|
|
if (m_items.at(i).name > name)
|
2008-12-02 12:01:29 +01:00
|
|
|
return i;
|
|
|
|
|
return m_items.size();
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-19 18:43:17 +02:00
|
|
|
QModelIndex EnvironmentModel::variableToIndex(const QString &name) const
|
2009-12-10 17:58:24 +01:00
|
|
|
{
|
|
|
|
|
int row = findInResult(name);
|
|
|
|
|
if (row == -1)
|
|
|
|
|
return QModelIndex();
|
|
|
|
|
return index(row, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
int EnvironmentModel::findInResult(const QString &name) const
|
|
|
|
|
{
|
|
|
|
|
Environment::const_iterator it;
|
|
|
|
|
int i = 0;
|
2008-12-09 11:07:24 +01:00
|
|
|
for (it = m_resultEnvironment.constBegin(); it != m_resultEnvironment.constEnd(); ++it, ++i)
|
|
|
|
|
if (m_resultEnvironment.key(it) == name)
|
2008-12-02 12:01:29 +01:00
|
|
|
return i;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int EnvironmentModel::findInResultInsertPosition(const QString &name) const
|
|
|
|
|
{
|
|
|
|
|
Environment::const_iterator it;
|
|
|
|
|
int i = 0;
|
2008-12-09 11:07:24 +01:00
|
|
|
for (it = m_resultEnvironment.constBegin(); it != m_resultEnvironment.constEnd(); ++it, ++i)
|
|
|
|
|
if (m_resultEnvironment.key(it) > name)
|
2008-12-02 12:01:29 +01:00
|
|
|
return i;
|
|
|
|
|
return m_resultEnvironment.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool EnvironmentModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
|
|
|
|
{
|
2010-04-19 18:43:17 +02:00
|
|
|
if (!index.isValid())
|
|
|
|
|
return false;
|
|
|
|
|
|
2008-12-09 11:07:24 +01:00
|
|
|
if (role == Qt::EditRole && index.isValid()) {
|
2009-11-19 16:55:27 +01:00
|
|
|
// ignore changes to already set values:
|
|
|
|
|
if (data(index, role) == value)
|
|
|
|
|
return true;
|
|
|
|
|
|
2008-12-09 11:07:24 +01:00
|
|
|
if (index.column() == 0) {
|
2008-12-02 12:01:29 +01:00
|
|
|
//fail if a variable with the same name already exists
|
|
|
|
|
#ifdef Q_OS_WIN
|
2009-11-19 16:55:27 +01:00
|
|
|
const QString &newName = value.toString().toUpper();
|
2008-12-02 12:01:29 +01:00
|
|
|
#else
|
2009-11-19 16:55:27 +01:00
|
|
|
const QString &newName = value.toString();
|
2008-12-02 12:01:29 +01:00
|
|
|
#endif
|
2009-11-19 16:55:27 +01:00
|
|
|
|
|
|
|
|
if (findInChanges(newName) != -1)
|
|
|
|
|
return false;
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
EnvironmentItem old("", "");
|
2009-12-09 19:29:04 +01:00
|
|
|
int pos = findInChanges(indexToVariable(index));
|
|
|
|
|
if (pos != -1) {
|
|
|
|
|
old = m_items.at(pos);
|
2008-12-02 12:01:29 +01:00
|
|
|
} else {
|
2009-12-09 19:29:04 +01:00
|
|
|
old.name = m_resultEnvironment.key(m_resultEnvironment.constBegin() + index.row());
|
|
|
|
|
old.value = m_resultEnvironment.value(m_resultEnvironment.constBegin() + index.row());
|
|
|
|
|
old.unset = false;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-11-19 16:55:27 +01:00
|
|
|
|
2008-12-09 11:07:24 +01:00
|
|
|
if (changes(old.name))
|
2010-04-19 18:51:31 +02:00
|
|
|
resetVariable(old.name);
|
2008-12-02 12:01:29 +01:00
|
|
|
old.name = newName;
|
|
|
|
|
addVariable(old);
|
2009-12-10 17:58:24 +01:00
|
|
|
emit renamedVariable(newName);
|
2008-12-02 12:01:29 +01:00
|
|
|
return true;
|
2008-12-09 11:07:24 +01:00
|
|
|
} else if (index.column() == 1) {
|
2009-12-09 19:29:04 +01:00
|
|
|
const QString &name = indexToVariable(index);
|
|
|
|
|
int pos = findInChanges(name);
|
|
|
|
|
if (pos != -1) {
|
|
|
|
|
m_items[pos].value = value.toString();
|
|
|
|
|
m_items[pos].unset = false;
|
|
|
|
|
updateResultEnvironment();
|
2008-12-02 12:01:29 +01:00
|
|
|
emit dataChanged(index, index);
|
2009-12-03 18:37:27 +01:00
|
|
|
emit userChangesChanged();
|
2008-12-02 12:01:29 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2009-12-09 19:29:04 +01:00
|
|
|
// not found in m_items, so add it as a new variable
|
|
|
|
|
addVariable(EnvironmentItem(name, value.toString()));
|
|
|
|
|
return true;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QModelIndex EnvironmentModel::addVariable()
|
|
|
|
|
{
|
2009-08-10 11:34:16 +02:00
|
|
|
const QString name = tr("<VARIABLE>");
|
2009-12-09 19:29:04 +01:00
|
|
|
int i = findInResult(name);
|
|
|
|
|
if (i != -1)
|
|
|
|
|
return index(i, 0, QModelIndex());
|
2008-12-02 12:01:29 +01:00
|
|
|
// Don't exist, really add them
|
2009-08-10 11:34:16 +02:00
|
|
|
return addVariable(EnvironmentItem(name, tr("<VALUE>")));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QModelIndex EnvironmentModel::addVariable(const EnvironmentItem &item)
|
|
|
|
|
{
|
2010-04-19 18:13:23 +02:00
|
|
|
bool existsInBaseEnvironment = m_baseEnvironment.hasKey(item.name);
|
2009-12-09 19:29:04 +01:00
|
|
|
int rowInResult;
|
|
|
|
|
if (existsInBaseEnvironment)
|
|
|
|
|
rowInResult = findInResult(item.name);
|
|
|
|
|
else
|
|
|
|
|
rowInResult = findInResultInsertPosition(item.name);
|
|
|
|
|
int rowInChanges = findInChangesInsertPosition(item.name);
|
|
|
|
|
|
|
|
|
|
//qDebug() << "addVariable " << item.name << existsInBaseEnvironment << rowInResult << rowInChanges;
|
|
|
|
|
|
|
|
|
|
if (existsInBaseEnvironment) {
|
|
|
|
|
m_items.insert(rowInChanges, item);
|
|
|
|
|
updateResultEnvironment();
|
|
|
|
|
emit dataChanged(index(rowInResult, 0, QModelIndex()), index(rowInResult, 1, QModelIndex()));
|
|
|
|
|
emit userChangesChanged();
|
|
|
|
|
return index(rowInResult, 0, QModelIndex());
|
2008-12-02 12:01:29 +01:00
|
|
|
} else {
|
2009-12-09 19:29:04 +01:00
|
|
|
beginInsertRows(QModelIndex(), rowInResult, rowInResult);
|
|
|
|
|
m_items.insert(rowInChanges, item);
|
|
|
|
|
updateResultEnvironment();
|
2008-12-02 12:01:29 +01:00
|
|
|
endInsertRows();
|
2009-12-03 18:37:27 +01:00
|
|
|
emit userChangesChanged();
|
2009-12-09 19:29:04 +01:00
|
|
|
return index(rowInResult, 0, QModelIndex());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-19 18:51:31 +02:00
|
|
|
void EnvironmentModel::resetVariable(const QString &name)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-12-09 19:29:04 +01:00
|
|
|
int rowInResult = findInResult(name);
|
|
|
|
|
int rowInChanges = findInChanges(name);
|
2010-04-19 18:13:23 +02:00
|
|
|
bool existsInBaseEnvironment = m_baseEnvironment.hasKey(name);
|
2009-12-09 19:29:04 +01:00
|
|
|
if (existsInBaseEnvironment) {
|
|
|
|
|
m_items.removeAt(rowInChanges);
|
|
|
|
|
updateResultEnvironment();
|
|
|
|
|
emit dataChanged(index(rowInResult, 0, QModelIndex()), index(rowInResult, 1, QModelIndex()));
|
|
|
|
|
emit userChangesChanged();
|
2008-12-02 12:01:29 +01:00
|
|
|
} else {
|
2009-12-09 19:29:04 +01:00
|
|
|
beginRemoveRows(QModelIndex(), rowInResult, rowInResult);
|
|
|
|
|
m_items.removeAt(rowInChanges);
|
2008-12-02 12:01:29 +01:00
|
|
|
updateResultEnvironment();
|
|
|
|
|
endRemoveRows();
|
2009-12-03 18:37:27 +01:00
|
|
|
emit userChangesChanged();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-19 18:51:31 +02:00
|
|
|
void EnvironmentModel::unsetVariable(const QString &name)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-12-09 19:29:04 +01:00
|
|
|
int row = findInResult(name);
|
|
|
|
|
// look in m_items for the variable
|
|
|
|
|
int pos = findInChanges(name);
|
|
|
|
|
if (pos != -1) {
|
2008-12-02 12:01:29 +01:00
|
|
|
m_items[pos].unset = true;
|
|
|
|
|
updateResultEnvironment();
|
|
|
|
|
emit dataChanged(index(row, 0, QModelIndex()), index(row, 1, QModelIndex()));
|
2009-12-03 18:37:27 +01:00
|
|
|
emit userChangesChanged();
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2009-12-09 19:29:04 +01:00
|
|
|
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();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-04-19 18:51:31 +02:00
|
|
|
bool EnvironmentModel::canUnset(const QString &name)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
int pos = findInChanges(name);
|
2008-12-09 11:07:24 +01:00
|
|
|
if (pos != -1)
|
2008-12-02 12:01:29 +01:00
|
|
|
return m_items.at(pos).unset;
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-19 18:51:31 +02:00
|
|
|
bool EnvironmentModel::canReset(const QString &name)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-04-19 18:13:23 +02:00
|
|
|
return m_baseEnvironment.hasKey(name);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<EnvironmentItem> EnvironmentModel::userChanges() const
|
|
|
|
|
{
|
|
|
|
|
return m_items;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EnvironmentModel::setUserChanges(QList<EnvironmentItem> list)
|
|
|
|
|
{
|
2010-04-21 10:15:40 +02:00
|
|
|
// We assume nobody is reordering the items here.
|
|
|
|
|
if (list == m_items)
|
|
|
|
|
return;
|
2010-04-19 18:43:17 +02:00
|
|
|
beginResetModel();
|
2008-12-02 12:01:29 +01:00
|
|
|
m_items = list;
|
|
|
|
|
updateResultEnvironment();
|
2010-04-19 18:43:17 +02:00
|
|
|
endResetModel();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-05-26 14:02:16 +02:00
|
|
|
|
|
|
|
|
////
|
|
|
|
|
// EnvironmentWidget::EnvironmentWidget
|
|
|
|
|
////
|
|
|
|
|
|
2009-07-23 15:57:45 +02:00
|
|
|
EnvironmentWidget::EnvironmentWidget(QWidget *parent, QWidget *additionalDetailsWidget)
|
2009-07-30 17:42:58 +02:00
|
|
|
: QWidget(parent)
|
2009-05-26 14:02:16 +02:00
|
|
|
{
|
|
|
|
|
m_model = new EnvironmentModel();
|
2009-12-03 18:37:27 +01:00
|
|
|
connect(m_model, SIGNAL(userChangesChanged()),
|
|
|
|
|
this, SIGNAL(userChangesChanged()));
|
2010-04-21 10:15:40 +02:00
|
|
|
connect(m_model, SIGNAL(modelReset()),
|
|
|
|
|
this, SLOT(invalidateCurrentIndex()));
|
2009-05-26 14:02:16 +02:00
|
|
|
|
2009-12-10 17:58:24 +01:00
|
|
|
connect(m_model, SIGNAL(renamedVariable(QString)),
|
|
|
|
|
this, SLOT(renamedVariable(QString)));
|
2010-04-21 11:02:26 +02:00
|
|
|
connect(m_model, SIGNAL(focusIndex(QModelIndex)),
|
|
|
|
|
this, SLOT(focusIndex(QModelIndex)));
|
2009-12-10 17:58:24 +01:00
|
|
|
|
2009-07-30 17:42:58 +02:00
|
|
|
QVBoxLayout *vbox = new QVBoxLayout(this);
|
2009-10-01 16:09:09 +02:00
|
|
|
vbox->setContentsMargins(0, 0, 0, 0);
|
2009-07-23 15:57:45 +02:00
|
|
|
|
2009-10-01 14:24:44 +02:00
|
|
|
m_detailsContainer = new Utils::DetailsWidget(this);
|
2009-07-20 15:46:11 +02:00
|
|
|
|
2009-10-01 14:24:44 +02:00
|
|
|
QWidget *details = new QWidget(m_detailsContainer);
|
|
|
|
|
m_detailsContainer->setWidget(details);
|
|
|
|
|
details->setVisible(false);
|
2009-07-30 17:42:58 +02:00
|
|
|
|
2009-10-01 14:24:44 +02:00
|
|
|
QVBoxLayout *vbox2 = new QVBoxLayout(details);
|
2009-07-30 17:42:58 +02:00
|
|
|
vbox2->setMargin(0);
|
2009-07-23 15:57:45 +02:00
|
|
|
|
|
|
|
|
if (additionalDetailsWidget)
|
|
|
|
|
vbox2->addWidget(additionalDetailsWidget);
|
2009-07-20 15:46:11 +02:00
|
|
|
|
|
|
|
|
QHBoxLayout *horizontalLayout = new QHBoxLayout();
|
2009-07-23 15:57:45 +02:00
|
|
|
horizontalLayout->setMargin(0);
|
2009-05-26 14:02:16 +02:00
|
|
|
m_environmentTreeView = new QTreeView(this);
|
|
|
|
|
m_environmentTreeView->setRootIsDecorated(false);
|
|
|
|
|
m_environmentTreeView->setHeaderHidden(false);
|
|
|
|
|
m_environmentTreeView->setModel(m_model);
|
|
|
|
|
m_environmentTreeView->header()->resizeSection(0, 250);
|
2009-07-20 15:46:11 +02:00
|
|
|
m_environmentTreeView->setMinimumHeight(400);
|
2009-05-26 14:02:16 +02:00
|
|
|
horizontalLayout->addWidget(m_environmentTreeView);
|
|
|
|
|
|
2009-07-30 17:42:58 +02:00
|
|
|
QVBoxLayout *buttonLayout = new QVBoxLayout();
|
2009-05-26 14:02:16 +02:00
|
|
|
|
|
|
|
|
m_editButton = new QPushButton(this);
|
2009-06-16 12:34:23 +02:00
|
|
|
m_editButton->setText(tr("&Edit"));
|
2009-07-30 17:42:58 +02:00
|
|
|
buttonLayout->addWidget(m_editButton);
|
2009-05-26 14:02:16 +02:00
|
|
|
|
|
|
|
|
m_addButton = new QPushButton(this);
|
2009-06-16 12:34:23 +02:00
|
|
|
m_addButton->setText(tr("&Add"));
|
2009-07-30 17:42:58 +02:00
|
|
|
buttonLayout->addWidget(m_addButton);
|
2009-05-26 14:02:16 +02:00
|
|
|
|
2010-04-19 18:51:31 +02:00
|
|
|
m_resetButton = new QPushButton(this);
|
|
|
|
|
m_resetButton->setEnabled(false);
|
|
|
|
|
m_resetButton->setText(tr("&Reset"));
|
|
|
|
|
buttonLayout->addWidget(m_resetButton);
|
2009-05-26 14:02:16 +02:00
|
|
|
|
|
|
|
|
m_unsetButton = new QPushButton(this);
|
|
|
|
|
m_unsetButton->setEnabled(false);
|
2009-06-16 12:34:23 +02:00
|
|
|
m_unsetButton->setText(tr("&Unset"));
|
2009-07-30 17:42:58 +02:00
|
|
|
buttonLayout->addWidget(m_unsetButton);
|
2009-05-26 14:02:16 +02:00
|
|
|
|
|
|
|
|
QSpacerItem *verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
|
2009-07-30 17:42:58 +02:00
|
|
|
buttonLayout->addItem(verticalSpacer);
|
|
|
|
|
horizontalLayout->addLayout(buttonLayout);
|
2009-07-20 15:46:11 +02:00
|
|
|
vbox2->addLayout(horizontalLayout);
|
2009-07-30 17:42:58 +02:00
|
|
|
|
2009-10-01 14:24:44 +02:00
|
|
|
vbox->addWidget(m_detailsContainer);
|
2010-01-29 21:33:57 +01:00
|
|
|
|
2009-05-26 14:02:16 +02:00
|
|
|
connect(m_model, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
|
|
|
|
|
this, SLOT(updateButtons()));
|
|
|
|
|
|
|
|
|
|
connect(m_editButton, SIGNAL(clicked(bool)),
|
|
|
|
|
this, SLOT(editEnvironmentButtonClicked()));
|
|
|
|
|
connect(m_addButton, SIGNAL(clicked(bool)),
|
|
|
|
|
this, SLOT(addEnvironmentButtonClicked()));
|
2010-04-19 18:51:31 +02:00
|
|
|
connect(m_resetButton, SIGNAL(clicked(bool)),
|
2009-05-26 14:02:16 +02:00
|
|
|
this, SLOT(removeEnvironmentButtonClicked()));
|
|
|
|
|
connect(m_unsetButton, SIGNAL(clicked(bool)),
|
|
|
|
|
this, SLOT(unsetEnvironmentButtonClicked()));
|
2010-04-21 10:14:56 +02:00
|
|
|
connect(m_environmentTreeView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
|
|
|
|
|
this, SLOT(environmentCurrentIndexChanged(QModelIndex)));
|
2009-08-06 17:30:39 +02:00
|
|
|
|
2009-12-03 18:37:27 +01:00
|
|
|
connect(m_model, SIGNAL(userChangesChanged()), this, SLOT(updateSummaryText()));
|
2009-05-26 14:02:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EnvironmentWidget::~EnvironmentWidget()
|
|
|
|
|
{
|
|
|
|
|
delete m_model;
|
|
|
|
|
m_model = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-21 10:54:41 +02:00
|
|
|
void EnvironmentWidget::renamedVariable(const QString &name)
|
2009-12-10 17:58:24 +01:00
|
|
|
{
|
2010-04-19 18:43:17 +02:00
|
|
|
QModelIndex idx = m_model->variableToIndex(name);
|
2009-12-10 17:58:24 +01:00
|
|
|
m_environmentTreeView->setCurrentIndex(idx);
|
|
|
|
|
m_environmentTreeView->setFocus();
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-21 11:02:26 +02:00
|
|
|
void EnvironmentWidget::focusIndex(const QModelIndex &index)
|
|
|
|
|
{
|
|
|
|
|
m_environmentTreeView->setCurrentIndex(index);
|
|
|
|
|
m_environmentTreeView->setFocus();
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-26 14:02:16 +02:00
|
|
|
void EnvironmentWidget::setBaseEnvironment(const ProjectExplorer::Environment &env)
|
|
|
|
|
{
|
|
|
|
|
m_model->setBaseEnvironment(env);
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-14 13:40:17 +01:00
|
|
|
void EnvironmentWidget::setBaseEnvironmentText(const QString &text)
|
|
|
|
|
{
|
|
|
|
|
m_baseEnvironmentText = text;
|
|
|
|
|
updateSummaryText();
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-26 14:02:16 +02:00
|
|
|
QList<EnvironmentItem> EnvironmentWidget::userChanges() const
|
|
|
|
|
{
|
|
|
|
|
return m_model->userChanges();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EnvironmentWidget::setUserChanges(QList<EnvironmentItem> list)
|
|
|
|
|
{
|
|
|
|
|
m_model->setUserChanges(list);
|
2009-07-20 15:46:11 +02:00
|
|
|
updateSummaryText();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EnvironmentWidget::updateSummaryText()
|
|
|
|
|
{
|
|
|
|
|
QString text;
|
|
|
|
|
const QList<EnvironmentItem> &list = m_model->userChanges();
|
|
|
|
|
foreach (const EnvironmentItem &item, list) {
|
2009-12-14 13:40:17 +01:00
|
|
|
if (item.name != EnvironmentModel::tr("<VARIABLE>")) {
|
2009-07-20 15:46:11 +02:00
|
|
|
text.append("<br>");
|
2009-08-10 11:34:16 +02:00
|
|
|
if (item.unset)
|
|
|
|
|
text.append(tr("Unset <b>%1</b>").arg(item.name));
|
|
|
|
|
else
|
|
|
|
|
text.append(tr("Set <b>%1</b> to <b>%2</b>").arg(item.name, item.value));
|
|
|
|
|
}
|
2009-07-20 15:46:11 +02:00
|
|
|
}
|
2009-12-14 13:40:17 +01:00
|
|
|
|
2009-07-20 15:46:11 +02:00
|
|
|
if (text.isEmpty())
|
2009-12-14 13:40:17 +01:00
|
|
|
text.prepend(tr("Using <b>%1</b>").arg(m_baseEnvironmentText));
|
|
|
|
|
else
|
|
|
|
|
text.prepend(tr("Using <b>%1</b> and").arg(m_baseEnvironmentText));
|
|
|
|
|
|
2009-10-01 14:24:44 +02:00
|
|
|
m_detailsContainer->setSummaryText(text);
|
2009-05-26 14:02:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EnvironmentWidget::updateButtons()
|
|
|
|
|
{
|
2010-04-21 10:14:56 +02:00
|
|
|
environmentCurrentIndexChanged(m_environmentTreeView->currentIndex());
|
2009-05-26 14:02:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EnvironmentWidget::editEnvironmentButtonClicked()
|
|
|
|
|
{
|
|
|
|
|
m_environmentTreeView->edit(m_environmentTreeView->currentIndex());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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());
|
2010-04-19 18:51:31 +02:00
|
|
|
m_model->resetVariable(name);
|
2009-05-26 14:02:16 +02:00
|
|
|
updateButtons();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// unset in Merged Environment Mode means, unset if it comes from the base environment
|
|
|
|
|
// or remove when it is just a change we added
|
|
|
|
|
void EnvironmentWidget::unsetEnvironmentButtonClicked()
|
|
|
|
|
{
|
|
|
|
|
const QString &name = m_model->indexToVariable(m_environmentTreeView->currentIndex());
|
2010-04-19 18:51:31 +02:00
|
|
|
if (!m_model->canReset(name))
|
|
|
|
|
m_model->resetVariable(name);
|
2009-05-26 14:02:16 +02:00
|
|
|
else
|
2010-04-19 18:51:31 +02:00
|
|
|
m_model->unsetVariable(name);
|
2009-05-26 14:02:16 +02:00
|
|
|
updateButtons();
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-21 10:14:56 +02:00
|
|
|
void EnvironmentWidget::environmentCurrentIndexChanged(const QModelIndex ¤t)
|
2009-05-26 14:02:16 +02:00
|
|
|
{
|
|
|
|
|
if (current.isValid()) {
|
2009-05-27 14:40:20 +02:00
|
|
|
m_editButton->setEnabled(true);
|
2009-12-09 19:29:04 +01:00
|
|
|
const QString &name = m_model->indexToVariable(current);
|
2010-04-19 18:51:31 +02:00
|
|
|
bool modified = m_model->canReset(name) && m_model->changes(name);
|
|
|
|
|
bool unset = m_model->canUnset(name);
|
|
|
|
|
m_resetButton->setEnabled(modified || unset);
|
2009-12-09 19:29:04 +01:00
|
|
|
m_unsetButton->setEnabled(!unset);
|
2009-05-26 14:02:16 +02:00
|
|
|
} else {
|
2009-05-27 14:40:20 +02:00
|
|
|
m_editButton->setEnabled(false);
|
2010-04-19 18:51:31 +02:00
|
|
|
m_resetButton->setEnabled(false);
|
2009-05-26 14:02:16 +02:00
|
|
|
m_unsetButton->setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-04-21 10:15:40 +02:00
|
|
|
|
|
|
|
|
void EnvironmentWidget::invalidateCurrentIndex()
|
|
|
|
|
{
|
|
|
|
|
environmentCurrentIndexChanged(QModelIndex());
|
|
|
|
|
}
|