2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-01-13 11:41:45 +01:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-01-13 11:41:45 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-01-13 11:41:45 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2011-01-13 11:41:45 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02: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.
|
2011-01-13 11:41:45 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-01-13 11:41:45 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-01-13 11:41:45 +01:00
|
|
|
|
|
|
|
|
#include "environmentwidget.h"
|
2011-12-06 16:45:07 +01:00
|
|
|
#include "environmentitemswidget.h"
|
2011-01-13 11:41:45 +01:00
|
|
|
|
|
|
|
|
#include <utils/detailswidget.h>
|
|
|
|
|
#include <utils/environment.h>
|
|
|
|
|
#include <utils/environmentmodel.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QString>
|
|
|
|
|
#include <QHeaderView>
|
|
|
|
|
#include <QPushButton>
|
|
|
|
|
#include <QTableView>
|
|
|
|
|
#include <QTextDocument> // for Qt::escape
|
|
|
|
|
#include <QVBoxLayout>
|
2011-01-13 11:41:45 +01:00
|
|
|
|
|
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
|
|
|
|
|
////
|
|
|
|
|
// EnvironmentWidget::EnvironmentWidget
|
|
|
|
|
////
|
|
|
|
|
|
|
|
|
|
class EnvironmentWidgetPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Utils::EnvironmentModel *m_model;
|
|
|
|
|
|
|
|
|
|
QString m_baseEnvironmentText;
|
|
|
|
|
Utils::DetailsWidget *m_detailsContainer;
|
|
|
|
|
QTableView *m_environmentView;
|
|
|
|
|
QPushButton *m_editButton;
|
|
|
|
|
QPushButton *m_addButton;
|
|
|
|
|
QPushButton *m_resetButton;
|
|
|
|
|
QPushButton *m_unsetButton;
|
2011-12-06 16:45:07 +01:00
|
|
|
QPushButton *m_batchEditButton;
|
2011-01-13 11:41:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
EnvironmentWidget::EnvironmentWidget(QWidget *parent, QWidget *additionalDetailsWidget)
|
|
|
|
|
: QWidget(parent), d(new EnvironmentWidgetPrivate)
|
|
|
|
|
{
|
|
|
|
|
d->m_model = new Utils::EnvironmentModel();
|
|
|
|
|
connect(d->m_model, SIGNAL(userChangesChanged()),
|
|
|
|
|
this, SIGNAL(userChangesChanged()));
|
|
|
|
|
connect(d->m_model, SIGNAL(modelReset()),
|
|
|
|
|
this, SLOT(invalidateCurrentIndex()));
|
|
|
|
|
|
|
|
|
|
connect(d->m_model, SIGNAL(focusIndex(QModelIndex)),
|
|
|
|
|
this, SLOT(focusIndex(QModelIndex)));
|
|
|
|
|
|
|
|
|
|
QVBoxLayout *vbox = new QVBoxLayout(this);
|
|
|
|
|
vbox->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
|
|
|
|
d->m_detailsContainer = new Utils::DetailsWidget(this);
|
|
|
|
|
|
|
|
|
|
QWidget *details = new QWidget(d->m_detailsContainer);
|
|
|
|
|
d->m_detailsContainer->setWidget(details);
|
|
|
|
|
details->setVisible(false);
|
|
|
|
|
|
|
|
|
|
QVBoxLayout *vbox2 = new QVBoxLayout(details);
|
|
|
|
|
vbox2->setMargin(0);
|
|
|
|
|
|
|
|
|
|
if (additionalDetailsWidget)
|
|
|
|
|
vbox2->addWidget(additionalDetailsWidget);
|
|
|
|
|
|
|
|
|
|
QHBoxLayout *horizontalLayout = new QHBoxLayout();
|
|
|
|
|
horizontalLayout->setMargin(0);
|
|
|
|
|
d->m_environmentView = new QTableView(this);
|
|
|
|
|
d->m_environmentView->setModel(d->m_model);
|
|
|
|
|
d->m_environmentView->setMinimumHeight(400);
|
|
|
|
|
d->m_environmentView->setGridStyle(Qt::NoPen);
|
|
|
|
|
d->m_environmentView->horizontalHeader()->setStretchLastSection(true);
|
|
|
|
|
d->m_environmentView->horizontalHeader()->setResizeMode(0, QHeaderView::ResizeToContents);
|
|
|
|
|
d->m_environmentView->horizontalHeader()->setHighlightSections(false);
|
|
|
|
|
d->m_environmentView->verticalHeader()->hide();
|
|
|
|
|
QFontMetrics fm(font());
|
|
|
|
|
d->m_environmentView->verticalHeader()->setDefaultSectionSize(qMax(static_cast<int>(fm.height() * 1.2), fm.height() + 4));
|
|
|
|
|
d->m_environmentView->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
|
horizontalLayout->addWidget(d->m_environmentView);
|
|
|
|
|
|
|
|
|
|
QVBoxLayout *buttonLayout = new QVBoxLayout();
|
|
|
|
|
|
|
|
|
|
d->m_editButton = new QPushButton(this);
|
|
|
|
|
d->m_editButton->setText(tr("&Edit"));
|
|
|
|
|
buttonLayout->addWidget(d->m_editButton);
|
|
|
|
|
|
|
|
|
|
d->m_addButton = new QPushButton(this);
|
|
|
|
|
d->m_addButton->setText(tr("&Add"));
|
|
|
|
|
buttonLayout->addWidget(d->m_addButton);
|
|
|
|
|
|
|
|
|
|
d->m_resetButton = new QPushButton(this);
|
|
|
|
|
d->m_resetButton->setEnabled(false);
|
|
|
|
|
d->m_resetButton->setText(tr("&Reset"));
|
|
|
|
|
buttonLayout->addWidget(d->m_resetButton);
|
|
|
|
|
|
|
|
|
|
d->m_unsetButton = new QPushButton(this);
|
|
|
|
|
d->m_unsetButton->setEnabled(false);
|
|
|
|
|
d->m_unsetButton->setText(tr("&Unset"));
|
|
|
|
|
buttonLayout->addWidget(d->m_unsetButton);
|
|
|
|
|
|
|
|
|
|
QSpacerItem *verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
|
|
|
|
|
buttonLayout->addItem(verticalSpacer);
|
2011-12-06 16:45:07 +01:00
|
|
|
|
|
|
|
|
d->m_batchEditButton = new QPushButton(this);
|
|
|
|
|
d->m_batchEditButton->setText(tr("&Batch Edit..."));
|
|
|
|
|
buttonLayout->addWidget(d->m_batchEditButton);
|
|
|
|
|
|
2011-01-13 11:41:45 +01:00
|
|
|
horizontalLayout->addLayout(buttonLayout);
|
|
|
|
|
vbox2->addLayout(horizontalLayout);
|
|
|
|
|
|
|
|
|
|
vbox->addWidget(d->m_detailsContainer);
|
|
|
|
|
|
2012-03-05 22:30:59 +01:00
|
|
|
connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
2011-01-13 11:41:45 +01:00
|
|
|
this, SLOT(updateButtons()));
|
|
|
|
|
|
|
|
|
|
connect(d->m_editButton, SIGNAL(clicked(bool)),
|
|
|
|
|
this, SLOT(editEnvironmentButtonClicked()));
|
|
|
|
|
connect(d->m_addButton, SIGNAL(clicked(bool)),
|
|
|
|
|
this, SLOT(addEnvironmentButtonClicked()));
|
|
|
|
|
connect(d->m_resetButton, SIGNAL(clicked(bool)),
|
|
|
|
|
this, SLOT(removeEnvironmentButtonClicked()));
|
|
|
|
|
connect(d->m_unsetButton, SIGNAL(clicked(bool)),
|
|
|
|
|
this, SLOT(unsetEnvironmentButtonClicked()));
|
2011-12-06 16:45:07 +01:00
|
|
|
connect(d->m_batchEditButton, SIGNAL(clicked(bool)),
|
|
|
|
|
this, SLOT(batchEditEnvironmentButtonClicked()));
|
2011-01-13 11:41:45 +01:00
|
|
|
connect(d->m_environmentView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
|
|
|
|
|
this, SLOT(environmentCurrentIndexChanged(QModelIndex)));
|
|
|
|
|
|
2011-03-28 17:57:17 +02:00
|
|
|
connect(d->m_detailsContainer, SIGNAL(linkActivated(QString)),
|
|
|
|
|
this, SLOT(linkActivated(QString)));
|
|
|
|
|
|
2011-01-13 11:41:45 +01:00
|
|
|
connect(d->m_model, SIGNAL(userChangesChanged()), this, SLOT(updateSummaryText()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EnvironmentWidget::~EnvironmentWidget()
|
|
|
|
|
{
|
|
|
|
|
delete d->m_model;
|
|
|
|
|
d->m_model = 0;
|
2011-09-16 15:00:41 +02:00
|
|
|
delete d;
|
2011-01-13 11:41:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EnvironmentWidget::focusIndex(const QModelIndex &index)
|
|
|
|
|
{
|
|
|
|
|
d->m_environmentView->setCurrentIndex(index);
|
|
|
|
|
d->m_environmentView->setFocus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EnvironmentWidget::setBaseEnvironment(const Utils::Environment &env)
|
|
|
|
|
{
|
|
|
|
|
d->m_model->setBaseEnvironment(env);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EnvironmentWidget::setBaseEnvironmentText(const QString &text)
|
|
|
|
|
{
|
|
|
|
|
d->m_baseEnvironmentText = text;
|
|
|
|
|
updateSummaryText();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<Utils::EnvironmentItem> EnvironmentWidget::userChanges() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_model->userChanges();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EnvironmentWidget::setUserChanges(const QList<Utils::EnvironmentItem> &list)
|
|
|
|
|
{
|
|
|
|
|
d->m_model->setUserChanges(list);
|
|
|
|
|
updateSummaryText();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EnvironmentWidget::updateSummaryText()
|
|
|
|
|
{
|
2011-03-01 19:47:11 +01:00
|
|
|
QList<Utils::EnvironmentItem> list = d->m_model->userChanges();
|
2011-12-06 16:45:07 +01:00
|
|
|
Utils::EnvironmentItem::sort(&list);
|
2011-03-01 19:47:11 +01:00
|
|
|
|
2011-01-13 11:41:45 +01:00
|
|
|
QString text;
|
|
|
|
|
foreach (const Utils::EnvironmentItem &item, list) {
|
|
|
|
|
if (item.name != Utils::EnvironmentModel::tr("<VARIABLE>")) {
|
2012-01-09 16:30:33 +01:00
|
|
|
text.append(QLatin1String("<br>"));
|
2011-01-13 11:41:45 +01:00
|
|
|
if (item.unset)
|
2011-03-28 17:57:17 +02:00
|
|
|
text.append(tr("Unset <a href=\"%1\"><b>%1</b></a>").arg(Qt::escape(item.name)));
|
2011-01-13 11:41:45 +01:00
|
|
|
else
|
2011-03-28 17:57:17 +02:00
|
|
|
text.append(tr("Set <a href=\"%1\"><b>%1</b></a> to <b>%2</b>").arg(Qt::escape(item.name), Qt::escape(item.value)));
|
2011-01-13 11:41:45 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-22 17:01:34 +01:00
|
|
|
if (text.isEmpty()) {
|
|
|
|
|
//: %1 is "System Environment" or some such.
|
|
|
|
|
text.prepend(tr("Use <b>%1</b>").arg(d->m_baseEnvironmentText));
|
|
|
|
|
} else {
|
|
|
|
|
//: Yup, word puzzle. The Set/Unset phrases above are appended to this.
|
|
|
|
|
//: %1 is "System Environment" or some such.
|
|
|
|
|
text.prepend(tr("Use <b>%1</b> and").arg(d->m_baseEnvironmentText));
|
|
|
|
|
}
|
2011-01-13 11:41:45 +01:00
|
|
|
|
|
|
|
|
d->m_detailsContainer->setSummaryText(text);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-28 17:57:17 +02:00
|
|
|
void EnvironmentWidget::linkActivated(const QString &link)
|
|
|
|
|
{
|
|
|
|
|
d->m_detailsContainer->setState(Utils::DetailsWidget::Expanded);
|
|
|
|
|
QModelIndex idx = d->m_model->variableToIndex(link);
|
|
|
|
|
focusIndex(idx);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-13 11:41:45 +01:00
|
|
|
void EnvironmentWidget::updateButtons()
|
|
|
|
|
{
|
|
|
|
|
environmentCurrentIndexChanged(d->m_environmentView->currentIndex());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EnvironmentWidget::editEnvironmentButtonClicked()
|
|
|
|
|
{
|
|
|
|
|
d->m_environmentView->edit(d->m_environmentView->currentIndex());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EnvironmentWidget::addEnvironmentButtonClicked()
|
|
|
|
|
{
|
|
|
|
|
QModelIndex index = d->m_model->addVariable();
|
|
|
|
|
d->m_environmentView->setCurrentIndex(index);
|
|
|
|
|
d->m_environmentView->edit(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EnvironmentWidget::removeEnvironmentButtonClicked()
|
|
|
|
|
{
|
|
|
|
|
const QString &name = d->m_model->indexToVariable(d->m_environmentView->currentIndex());
|
|
|
|
|
d->m_model->resetVariable(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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 = d->m_model->indexToVariable(d->m_environmentView->currentIndex());
|
|
|
|
|
if (!d->m_model->canReset(name))
|
|
|
|
|
d->m_model->resetVariable(name);
|
|
|
|
|
else
|
|
|
|
|
d->m_model->unsetVariable(name);
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-06 16:45:07 +01:00
|
|
|
void EnvironmentWidget::batchEditEnvironmentButtonClicked()
|
|
|
|
|
{
|
|
|
|
|
const QList<Utils::EnvironmentItem> changes = d->m_model->userChanges();
|
|
|
|
|
|
|
|
|
|
bool ok;
|
|
|
|
|
const QList<Utils::EnvironmentItem> newChanges = EnvironmentItemsDialog::getEnvironmentItems(this, changes, &ok);
|
|
|
|
|
if (ok)
|
|
|
|
|
d->m_model->setUserChanges(newChanges);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-13 11:41:45 +01:00
|
|
|
void EnvironmentWidget::environmentCurrentIndexChanged(const QModelIndex ¤t)
|
|
|
|
|
{
|
|
|
|
|
if (current.isValid()) {
|
|
|
|
|
d->m_editButton->setEnabled(true);
|
|
|
|
|
const QString &name = d->m_model->indexToVariable(current);
|
|
|
|
|
bool modified = d->m_model->canReset(name) && d->m_model->changes(name);
|
|
|
|
|
bool unset = d->m_model->canUnset(name);
|
|
|
|
|
d->m_resetButton->setEnabled(modified || unset);
|
|
|
|
|
d->m_unsetButton->setEnabled(!unset);
|
|
|
|
|
} else {
|
|
|
|
|
d->m_editButton->setEnabled(false);
|
|
|
|
|
d->m_resetButton->setEnabled(false);
|
|
|
|
|
d->m_unsetButton->setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EnvironmentWidget::invalidateCurrentIndex()
|
|
|
|
|
{
|
|
|
|
|
environmentCurrentIndexChanged(QModelIndex());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace ProjectExplorer
|