Commit 48b97475 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

Vcs: Allow multiple flags in parameter widgets

Refactor combobox values to use %1 as a placeholder for values

Change-Id: I9a9bb6b9ba5c21bcaad4a3047d322856225892bc
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 0b0f84c6
......@@ -278,7 +278,7 @@ public:
<< ComboBoxItem(tr("Moderately short"), QLatin1String("short"))
<< ComboBoxItem(tr("One line"), QLatin1String("line"))
<< ComboBoxItem(tr("GNU ChangeLog"), QLatin1String("gnu-changelog"));
mapSetting(addComboBox(QLatin1String("--log-format"), logChoices),
mapSetting(addComboBox(QStringList(QLatin1String("--log-format=%1")), logChoices),
m_client->settings()->stringPointer(BazaarSettings::logFormatKey));
}
......
......@@ -187,7 +187,7 @@ public:
<< ComboBoxItem(tr("fuller"), QLatin1String("fuller"))
<< ComboBoxItem(tr("email"), QLatin1String("email"))
<< ComboBoxItem(tr("raw"), QLatin1String("raw"));
mapSetting(addComboBox(QLatin1String("--pretty"), prettyChoices),
mapSetting(addComboBox(QStringList(QLatin1String("--pretty=%1")), prettyChoices),
m_client->settings()->intPointer(GitSettings::showPrettyFormatKey));
}
......
......@@ -82,14 +82,13 @@ class VcsBaseEditorParameterWidgetPrivate
{
public:
VcsBaseEditorParameterWidgetPrivate() :
m_layout(0), m_comboBoxOptionTemplate(QLatin1String("%{option}=%{value}"))
m_layout(0)
{ }
QStringList m_baseArguments;
QHBoxLayout *m_layout;
QList<VcsBaseEditorParameterWidget::OptionMapping> m_optionMappings;
QHash<QWidget*, SettingMappingData> m_settingMapping;
QStringList m_comboBoxOptionTemplate;
};
} // namespace Internal
......@@ -147,19 +146,24 @@ QStringList VcsBaseEditorParameterWidget::arguments() const
QToolButton *VcsBaseEditorParameterWidget::addToggleButton(const QString &option,
const QString &label,
const QString &toolTip)
const QString &tooltip)
{
return addToggleButton(QStringList(option), label, tooltip);
}
QToolButton *VcsBaseEditorParameterWidget::addToggleButton(const QStringList &options, const QString &label, const QString &tooltip)
{
QToolButton *tb = new QToolButton;
tb->setText(label);
tb->setToolTip(toolTip);
tb->setToolTip(tooltip);
tb->setCheckable(true);
connect(tb, SIGNAL(toggled(bool)), this, SIGNAL(argumentsChanged()));
d->m_layout->addWidget(tb);
d->m_optionMappings.append(OptionMapping(option, tb));
d->m_optionMappings.append(OptionMapping(options, tb));
return tb;
}
QComboBox *VcsBaseEditorParameterWidget::addComboBox(const QString &option,
QComboBox *VcsBaseEditorParameterWidget::addComboBox(const QStringList &options,
const QList<ComboBoxItem> &items)
{
QComboBox *cb = new QComboBox;
......@@ -167,7 +171,7 @@ QComboBox *VcsBaseEditorParameterWidget::addComboBox(const QString &option,
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));
d->m_optionMappings.append(OptionMapping(options, cb));
return cb;
}
......@@ -212,30 +216,6 @@ void VcsBaseEditorParameterWidget::mapSetting(QComboBox *comboBox, int *setting)
comboBox->blockSignals(false);
}
/*!
\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;
}
void VcsBaseEditorParameterWidget::executeCommand()
{
}
......@@ -251,8 +231,16 @@ VcsBaseEditorParameterWidget::OptionMapping::OptionMapping() :
{
}
VcsBaseEditorParameterWidget::OptionMapping::OptionMapping(const QString &optName, QWidget *w) :
optionName(optName), widget(w)
VcsBaseEditorParameterWidget::OptionMapping::OptionMapping(const QString &option, QWidget *w) :
widget(w)
{
if (!option.isEmpty())
options << option;
}
VcsBaseEditorParameterWidget::OptionMapping::OptionMapping(const QStringList &optionList, QWidget *w) :
options(optionList),
widget(w)
{
}
......@@ -264,23 +252,15 @@ const QList<VcsBaseEditorParameterWidget::OptionMapping> &VcsBaseEditorParameter
QStringList VcsBaseEditorParameterWidget::argumentsForOption(const OptionMapping &mapping) const
{
const QToolButton *tb = qobject_cast<const QToolButton *>(mapping.widget);
if (tb && tb->isChecked()) {
if (!mapping.optionName.isEmpty())
return QStringList(mapping.optionName);
else
return QStringList();
}
if (tb && tb->isChecked())
return mapping.options;
const QComboBox *cb = qobject_cast<const QComboBox *>(mapping.widget);
if (cb) {
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;
}
foreach (const QString &option, mapping.options)
args << option.arg(value);
return args;
}
......
......@@ -67,15 +67,14 @@ public:
QToolButton *addToggleButton(const QString &option, const QString &label,
const QString &tooltip = QString());
QComboBox *addComboBox(const QString &option, const QList<ComboBoxItem> &items);
QToolButton *addToggleButton(const QStringList &options, const QString &label,
const QString &tooltip = QString());
QComboBox *addComboBox(const QStringList &options, const QList<ComboBoxItem> &items);
void mapSetting(QToolButton *button, bool *setting);
void mapSetting(QComboBox *comboBox, QString *setting);
void mapSetting(QComboBox *comboBox, int *setting);
QStringList comboBoxOptionTemplate() const;
void setComboBoxOptionTemplate(const QStringList &optTemplate) const;
// Return the effective arguments according to setting.
virtual QStringList arguments() const;
......@@ -91,8 +90,9 @@ protected:
struct OptionMapping
{
OptionMapping();
OptionMapping(const QString &optName, QWidget *w);
QString optionName;
OptionMapping(const QString &option, QWidget *w);
OptionMapping(const QStringList &optionList, QWidget *w);
QStringList options;
QWidget *widget;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment