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-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@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-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@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-06-10 10:40:42 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
2011-10-06 16:20:12 +02:00
|
|
|
class SettingMappingData
|
2011-06-10 10:40:42 +02:00
|
|
|
{
|
2011-10-06 16:20:12 +02:00
|
|
|
public:
|
2011-06-10 10:40:42 +02:00
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
Invalid,
|
|
|
|
Bool,
|
2011-10-06 16:20:12 +02:00
|
|
|
String,
|
|
|
|
Int
|
2011-06-10 10:40:42 +02:00
|
|
|
};
|
|
|
|
|
2011-10-06 16:20:12 +02:00
|
|
|
SettingMappingData() : boolSetting(0), m_type(Invalid)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
SettingMappingData(bool *setting) : boolSetting(setting), m_type(Bool)
|
2011-06-10 10:40:42 +02:00
|
|
|
{ }
|
|
|
|
|
2011-10-06 16:20:12 +02:00
|
|
|
SettingMappingData(QString *setting) : stringSetting(setting), m_type(String)
|
2011-06-10 10:40:42 +02:00
|
|
|
{ }
|
|
|
|
|
2011-10-06 16:20:12 +02:00
|
|
|
SettingMappingData(int *setting) : intSetting(setting), m_type(Int)
|
2011-06-10 10:40:42 +02:00
|
|
|
{ }
|
|
|
|
|
|
|
|
Type type() const
|
|
|
|
{
|
2011-10-06 16:20:12 +02:00
|
|
|
return m_type;
|
2011-06-10 10:40:42 +02:00
|
|
|
}
|
|
|
|
|
2011-10-06 16:20:12 +02:00
|
|
|
union {
|
|
|
|
bool *boolSetting;
|
|
|
|
QString *stringSetting;
|
|
|
|
int *intSetting;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
Type m_type;
|
2011-06-10 10:40:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
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() :
|
2011-05-31 10:12:24 +00:00
|
|
|
m_layout(0), m_comboBoxOptionTemplate(QLatin1String("%{option}=%{value}"))
|
|
|
|
{ }
|
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-06-10 10:40:42 +02:00
|
|
|
QHash<QWidget*, Internal::SettingMappingData> m_settingMapping;
|
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()
|
|
|
|
{
|
2011-09-16 15:00:41 +02:00
|
|
|
delete d;
|
2011-03-25 16:39:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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: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;
|
|
|
|
}
|
|
|
|
|
2011-06-10 10:40:42 +02:00
|
|
|
void VCSBaseEditorParameterWidget::mapSetting(QToolButton *button, bool *setting)
|
|
|
|
{
|
|
|
|
if (!d->m_settingMapping.contains(button) && button) {
|
|
|
|
d->m_settingMapping.insert(button, Internal::SettingMappingData(setting));
|
|
|
|
if (setting) {
|
|
|
|
button->blockSignals(true);
|
|
|
|
button->setChecked(*setting);
|
|
|
|
button->blockSignals(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VCSBaseEditorParameterWidget::mapSetting(QComboBox *comboBox, QString *setting)
|
|
|
|
{
|
|
|
|
if (!d->m_settingMapping.contains(comboBox) && comboBox) {
|
|
|
|
d->m_settingMapping.insert(comboBox, Internal::SettingMappingData(setting));
|
|
|
|
if (setting) {
|
|
|
|
comboBox->blockSignals(true);
|
2011-10-06 13:13:01 +02:00
|
|
|
const int itemIndex = setting ? comboBox->findData(*setting) : -1;
|
2011-06-10 10:40:42 +02:00
|
|
|
if (itemIndex != -1)
|
|
|
|
comboBox->setCurrentIndex(itemIndex);
|
|
|
|
comboBox->blockSignals(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-06 16:20:12 +02:00
|
|
|
void VCSBaseEditorParameterWidget::mapSetting(QComboBox *comboBox, int *setting)
|
|
|
|
{
|
|
|
|
if (d->m_settingMapping.contains(comboBox) || !comboBox)
|
|
|
|
return;
|
|
|
|
|
|
|
|
d->m_settingMapping.insert(comboBox, Internal::SettingMappingData(setting));
|
|
|
|
|
|
|
|
if (!setting || *setting < 0 || *setting >= comboBox->count())
|
|
|
|
return;
|
|
|
|
|
|
|
|
comboBox->blockSignals(true);
|
|
|
|
comboBox->setCurrentIndex(*setting);
|
|
|
|
comboBox->blockSignals(false);
|
|
|
|
}
|
|
|
|
|
2011-05-31 08:31:26 +00:00
|
|
|
/*!
|
|
|
|
\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-05-31 08:31:25 +00:00
|
|
|
void VCSBaseEditorParameterWidget::executeCommand()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void VCSBaseEditorParameterWidget::handleArgumentsChanged()
|
|
|
|
{
|
2011-06-10 10:40:42 +02:00
|
|
|
updateMappedSettings();
|
2011-05-31 08:31:25 +00:00
|
|
|
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);
|
2011-10-06 18:21:39 +02:00
|
|
|
if (tb && tb->isChecked()) {
|
|
|
|
if (!mapping.optionName.isEmpty())
|
|
|
|
return QStringList(mapping.optionName);
|
|
|
|
else
|
|
|
|
return QStringList();
|
|
|
|
}
|
2011-05-31 08:31:26 +00:00
|
|
|
|
|
|
|
const QComboBox *cb = qobject_cast<const QComboBox *>(mapping.widget);
|
2011-06-10 10:40:42 +02:00
|
|
|
if (cb) {
|
2011-05-31 08:31:26 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-06-10 10:40:42 +02:00
|
|
|
void VCSBaseEditorParameterWidget::updateMappedSettings()
|
|
|
|
{
|
|
|
|
foreach (const OptionMapping &optMapping, d->m_optionMappings) {
|
|
|
|
if (d->m_settingMapping.contains(optMapping.widget)) {
|
|
|
|
Internal::SettingMappingData& settingData = d->m_settingMapping[optMapping.widget];
|
|
|
|
switch (settingData.type()) {
|
|
|
|
case Internal::SettingMappingData::Bool :
|
|
|
|
{
|
|
|
|
const QToolButton *tb = qobject_cast<const QToolButton *>(optMapping.widget);
|
|
|
|
if (tb)
|
|
|
|
*settingData.boolSetting = tb->isChecked();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Internal::SettingMappingData::String :
|
|
|
|
{
|
|
|
|
const QComboBox *cb = qobject_cast<const QComboBox *>(optMapping.widget);
|
|
|
|
if (cb && cb->currentIndex() != -1)
|
|
|
|
*settingData.stringSetting = cb->itemData(cb->currentIndex()).toString();
|
|
|
|
break;
|
|
|
|
}
|
2011-10-06 16:20:12 +02:00
|
|
|
case Internal::SettingMappingData::Int:
|
|
|
|
{
|
|
|
|
const QComboBox *cb = qobject_cast<const QComboBox *>(optMapping.widget);
|
|
|
|
if (cb && cb->currentIndex() != -1)
|
|
|
|
*settingData.intSetting = cb->currentIndex();
|
|
|
|
break;
|
|
|
|
}
|
2011-06-10 10:40:42 +02:00
|
|
|
case Internal::SettingMappingData::Invalid : break;
|
|
|
|
} // end switch ()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-31 08:31:25 +00:00
|
|
|
} // namespace VCSBase
|