2011-03-25 16:39:33 +01:00
|
|
|
/**************************************************************************
|
|
|
|
**
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
**
|
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
**
|
2011-05-06 15:05:37 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2011-03-25 16:39:33 +01:00
|
|
|
**
|
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
**
|
2011-05-06 15:05:37 +02:00
|
|
|
** 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-03-25 16:39:33 +01:00
|
|
|
**
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-05-06 15:05:37 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2011-03-25 16:39:33 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-05-06 15:05:37 +02:00
|
|
|
** Other Usage
|
|
|
|
**
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
**
|
2011-03-25 16:39:33 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-05-06 15:05:37 +02:00
|
|
|
** Nokia at info@qt.nokia.com.
|
2011-03-25 16:39:33 +01:00
|
|
|
**
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
#include "vcsbaseeditorparameterwidget.h"
|
|
|
|
|
2011-05-31 08:31:26 +00:00
|
|
|
#include <QtGui/QComboBox>
|
2011-03-25 16:39:33 +01:00
|
|
|
#include <QtGui/QToolButton>
|
|
|
|
#include <QtGui/QHBoxLayout>
|
|
|
|
|
|
|
|
#include <QtCore/QDebug>
|
|
|
|
|
|
|
|
namespace VCSBase {
|
|
|
|
|
2011-05-31 08:31:26 +00:00
|
|
|
VCSBaseEditorParameterWidget::ComboBoxItem::ComboBoxItem()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
VCSBaseEditorParameterWidget::ComboBoxItem::ComboBoxItem(const QString &text,
|
|
|
|
const QVariant &val) :
|
|
|
|
displayText(text),
|
|
|
|
value(val)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-25 16:39:33 +01:00
|
|
|
class VCSBaseEditorParameterWidgetPrivate
|
|
|
|
{
|
|
|
|
public:
|
2011-05-31 08:31:26 +00:00
|
|
|
VCSBaseEditorParameterWidgetPrivate() :
|
|
|
|
m_layout(0), m_comboBoxOptionTemplate(QLatin1String("%1=%2")) {}
|
2011-03-25 16:39:33 +01:00
|
|
|
|
|
|
|
QStringList m_baseArguments;
|
|
|
|
QHBoxLayout *m_layout;
|
2011-05-31 08:31:25 +00:00
|
|
|
QList<VCSBaseEditorParameterWidget::OptionMapping> m_optionMappings;
|
2011-05-31 08:31:26 +00:00
|
|
|
QStringList m_comboBoxOptionTemplate;
|
2011-03-25 16:39:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\class VCSBase::VCSBaseEditorParameterWidget
|
|
|
|
|
|
|
|
\brief A toolbar-like widget for use with VCSBase::VCSBaseEditor::setConfigurationWidget()
|
|
|
|
influencing for example the generation of VCS diff output.
|
|
|
|
|
|
|
|
The widget maintains a list of command line arguments (starting from baseArguments())
|
|
|
|
which are set according to the state of the inside widgets. A change signal is provided
|
|
|
|
that should trigger the rerun of the VCS operation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
VCSBaseEditorParameterWidget::VCSBaseEditorParameterWidget(QWidget *parent) :
|
|
|
|
QWidget(parent), d(new VCSBaseEditorParameterWidgetPrivate)
|
|
|
|
{
|
|
|
|
d->m_layout = new QHBoxLayout(this);
|
|
|
|
d->m_layout->setContentsMargins(3, 0, 3, 0);
|
|
|
|
d->m_layout->setSpacing(2);
|
2011-05-31 08:31:25 +00:00
|
|
|
connect(this, SIGNAL(argumentsChanged()), this, SLOT(handleArgumentsChanged()));
|
2011-03-25 16:39:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
VCSBaseEditorParameterWidget::~VCSBaseEditorParameterWidget()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList VCSBaseEditorParameterWidget::baseArguments() const
|
|
|
|
{
|
|
|
|
return d->m_baseArguments;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VCSBaseEditorParameterWidget::setBaseArguments(const QStringList &b)
|
|
|
|
{
|
|
|
|
d->m_baseArguments = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList VCSBaseEditorParameterWidget::arguments() const
|
|
|
|
{
|
|
|
|
// Compile effective arguments
|
2011-05-31 08:31:25 +00:00
|
|
|
QStringList args = baseArguments();
|
|
|
|
foreach (const OptionMapping &mapping, optionMappings())
|
|
|
|
args += argumentsForOption(mapping);
|
2011-03-25 16:39:33 +01:00
|
|
|
return args;
|
|
|
|
}
|
|
|
|
|
2011-05-31 08:31:25 +00:00
|
|
|
QToolButton *VCSBaseEditorParameterWidget::addToggleButton(const QString &option,
|
|
|
|
const QString &label,
|
|
|
|
const QString &toolTip)
|
2011-03-25 16:39:33 +01:00
|
|
|
{
|
2011-05-31 08:31:25 +00:00
|
|
|
QToolButton *tb = new QToolButton;
|
2011-03-25 16:39:33 +01:00
|
|
|
tb->setText(label);
|
|
|
|
tb->setToolTip(toolTip);
|
2011-05-31 08:31:25 +00:00
|
|
|
tb->setCheckable(true);
|
|
|
|
connect(tb, SIGNAL(toggled(bool)), this, SIGNAL(argumentsChanged()));
|
2011-03-25 16:39:33 +01:00
|
|
|
d->m_layout->addWidget(tb);
|
2011-05-31 08:31:25 +00:00
|
|
|
d->m_optionMappings.append(OptionMapping(option, tb));
|
|
|
|
return tb;
|
2011-03-25 16:39:33 +01:00
|
|
|
}
|
|
|
|
|
2011-05-31 08:31:25 +00:00
|
|
|
QToolButton *VCSBaseEditorParameterWidget::addIgnoreWhiteSpaceButton(const QString &option)
|
2011-03-25 16:39:33 +01:00
|
|
|
{
|
2011-05-31 08:31:25 +00:00
|
|
|
return addToggleButton(option, msgIgnoreWhiteSpaceLabel(), msgIgnoreWhiteSpaceToolTip());
|
2011-03-25 16:39:33 +01:00
|
|
|
}
|
|
|
|
|
2011-05-31 08:31:25 +00:00
|
|
|
QToolButton *VCSBaseEditorParameterWidget::addIgnoreBlankLinesButton(const QString &option)
|
2011-03-25 16:39:33 +01:00
|
|
|
{
|
2011-05-31 08:31:25 +00:00
|
|
|
return addToggleButton(option, msgIgnoreBlankLinesLabel(), msgIgnoreBlankLinesToolTip());
|
2011-03-25 16:39:33 +01:00
|
|
|
}
|
|
|
|
|
2011-05-31 08:31:26 +00:00
|
|
|
QComboBox *VCSBaseEditorParameterWidget::addComboBox(const QString &option,
|
|
|
|
const QList<ComboBoxItem> &items)
|
|
|
|
{
|
|
|
|
QComboBox *cb = new QComboBox;
|
|
|
|
foreach (const ComboBoxItem &item, items)
|
|
|
|
cb->addItem(item.displayText, item.value);
|
|
|
|
connect(cb, SIGNAL(currentIndexChanged(int)), this, SIGNAL(argumentsChanged()));
|
|
|
|
d->m_layout->addWidget(cb);
|
|
|
|
d->m_optionMappings.append(OptionMapping(option, cb));
|
|
|
|
return cb;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief This property holds the format (template) of assignable command line
|
|
|
|
options (like --file=<file> for example)
|
|
|
|
|
|
|
|
The option's name and its actual value are specified with place markers
|
|
|
|
within the template :
|
|
|
|
\li %{option} for the option
|
|
|
|
\li %{value} for the actual value
|
|
|
|
|
|
|
|
\code
|
|
|
|
QStringList("%{option}=%{value}"); // eg --file=a.out
|
|
|
|
QStringList() << "%{option}" << "%{value}"; // eg --file a.out (two distinct arguments)
|
|
|
|
\endcode
|
|
|
|
*/
|
|
|
|
QStringList VCSBaseEditorParameterWidget::comboBoxOptionTemplate() const
|
|
|
|
{
|
|
|
|
return d->m_comboBoxOptionTemplate;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VCSBaseEditorParameterWidget::setComboBoxOptionTemplate(const QStringList &optTemplate) const
|
|
|
|
{
|
|
|
|
d->m_comboBoxOptionTemplate = optTemplate;
|
|
|
|
}
|
|
|
|
|
2011-03-25 16:39:33 +01:00
|
|
|
QString VCSBaseEditorParameterWidget::msgIgnoreWhiteSpaceLabel()
|
|
|
|
{
|
|
|
|
return tr("Ignore whitespace");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString VCSBaseEditorParameterWidget::msgIgnoreWhiteSpaceToolTip()
|
|
|
|
{
|
|
|
|
return tr("Ignore whitespace only changes");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString VCSBaseEditorParameterWidget::msgIgnoreBlankLinesLabel()
|
|
|
|
{
|
|
|
|
return tr("Ignore blank lines ");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString VCSBaseEditorParameterWidget::msgIgnoreBlankLinesToolTip()
|
|
|
|
{
|
|
|
|
return tr("Ignore changes in blank lines");
|
|
|
|
}
|
|
|
|
|
2011-05-31 08:31:25 +00:00
|
|
|
void VCSBaseEditorParameterWidget::executeCommand()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void VCSBaseEditorParameterWidget::handleArgumentsChanged()
|
|
|
|
{
|
|
|
|
executeCommand();
|
|
|
|
}
|
|
|
|
|
2011-05-31 08:31:25 +00:00
|
|
|
VCSBaseEditorParameterWidget::OptionMapping::OptionMapping() :
|
|
|
|
widget(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
VCSBaseEditorParameterWidget::OptionMapping::OptionMapping(const QString &optName, QWidget *w) :
|
|
|
|
optionName(optName), widget(w)
|
|
|
|
{
|
|
|
|
}
|
2011-03-25 16:39:33 +01:00
|
|
|
|
2011-05-31 08:31:25 +00:00
|
|
|
const QList<VCSBaseEditorParameterWidget::OptionMapping> &VCSBaseEditorParameterWidget::optionMappings() const
|
|
|
|
{
|
|
|
|
return d->m_optionMappings;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList VCSBaseEditorParameterWidget::argumentsForOption(const OptionMapping &mapping) const
|
|
|
|
{
|
|
|
|
const QToolButton *tb = qobject_cast<const QToolButton *>(mapping.widget);
|
|
|
|
if (tb != 0 && tb->isChecked())
|
2011-05-31 08:31:26 +00:00
|
|
|
return QStringList(mapping.optionName);
|
|
|
|
|
|
|
|
const QComboBox *cb = qobject_cast<const QComboBox *>(mapping.widget);
|
|
|
|
if (cb != 0) {
|
|
|
|
const QString value = cb->itemData(cb->currentIndex()).toString();
|
|
|
|
QStringList args;
|
|
|
|
foreach (const QString &t, d->m_comboBoxOptionTemplate) {
|
|
|
|
QString a = t;
|
|
|
|
a.replace(QLatin1String("%{option}"), mapping.optionName);
|
|
|
|
a.replace(QLatin1String("%{value}"), value);
|
|
|
|
args += a;
|
|
|
|
}
|
|
|
|
return args;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QStringList();
|
2011-05-31 08:31:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace VCSBase
|