forked from qt-creator/qt-creator
vcsbase: support of combo boxes in EditorParameterWidget
VCSBaseEditorParameterWidget supports "choice-based" options through mapping of QComboBox. Change-Id: I46e1205e1b6f56b16782d9f0d81ec6f1d4961f1a Merge-request: 331 Reviewed-by: Tobias Hunger <tobias.hunger@nokia.com> Reviewed-on: http://codereview.qt.nokia.com/255 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
This commit is contained in:
@@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#include "vcsbaseeditorparameterwidget.h"
|
#include "vcsbaseeditorparameterwidget.h"
|
||||||
|
|
||||||
|
#include <QtGui/QComboBox>
|
||||||
#include <QtGui/QToolButton>
|
#include <QtGui/QToolButton>
|
||||||
#include <QtGui/QHBoxLayout>
|
#include <QtGui/QHBoxLayout>
|
||||||
|
|
||||||
@@ -39,14 +40,27 @@
|
|||||||
|
|
||||||
namespace VCSBase {
|
namespace VCSBase {
|
||||||
|
|
||||||
|
VCSBaseEditorParameterWidget::ComboBoxItem::ComboBoxItem()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
VCSBaseEditorParameterWidget::ComboBoxItem::ComboBoxItem(const QString &text,
|
||||||
|
const QVariant &val) :
|
||||||
|
displayText(text),
|
||||||
|
value(val)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
class VCSBaseEditorParameterWidgetPrivate
|
class VCSBaseEditorParameterWidgetPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
VCSBaseEditorParameterWidgetPrivate() : m_layout(0) {}
|
VCSBaseEditorParameterWidgetPrivate() :
|
||||||
|
m_layout(0), m_comboBoxOptionTemplate(QLatin1String("%1=%2")) {}
|
||||||
|
|
||||||
QStringList m_baseArguments;
|
QStringList m_baseArguments;
|
||||||
QHBoxLayout *m_layout;
|
QHBoxLayout *m_layout;
|
||||||
QList<VCSBaseEditorParameterWidget::OptionMapping> m_optionMappings;
|
QList<VCSBaseEditorParameterWidget::OptionMapping> m_optionMappings;
|
||||||
|
QStringList m_comboBoxOptionTemplate;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -116,6 +130,42 @@ QToolButton *VCSBaseEditorParameterWidget::addIgnoreBlankLinesButton(const QStri
|
|||||||
return addToggleButton(option, msgIgnoreBlankLinesLabel(), msgIgnoreBlankLinesToolTip());
|
return addToggleButton(option, msgIgnoreBlankLinesLabel(), msgIgnoreBlankLinesToolTip());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
QString VCSBaseEditorParameterWidget::msgIgnoreWhiteSpaceLabel()
|
QString VCSBaseEditorParameterWidget::msgIgnoreWhiteSpaceLabel()
|
||||||
{
|
{
|
||||||
return tr("Ignore whitespace");
|
return tr("Ignore whitespace");
|
||||||
@@ -162,11 +212,24 @@ const QList<VCSBaseEditorParameterWidget::OptionMapping> &VCSBaseEditorParameter
|
|||||||
|
|
||||||
QStringList VCSBaseEditorParameterWidget::argumentsForOption(const OptionMapping &mapping) const
|
QStringList VCSBaseEditorParameterWidget::argumentsForOption(const OptionMapping &mapping) const
|
||||||
{
|
{
|
||||||
QStringList args;
|
|
||||||
const QToolButton *tb = qobject_cast<const QToolButton *>(mapping.widget);
|
const QToolButton *tb = qobject_cast<const QToolButton *>(mapping.widget);
|
||||||
if (tb != 0 && tb->isChecked())
|
if (tb != 0 && tb->isChecked())
|
||||||
args += mapping.optionName;
|
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 args;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QStringList();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace VCSBase
|
} // namespace VCSBase
|
||||||
|
@@ -37,8 +37,10 @@
|
|||||||
|
|
||||||
#include <QtGui/QWidget>
|
#include <QtGui/QWidget>
|
||||||
#include <QtCore/QStringList>
|
#include <QtCore/QStringList>
|
||||||
|
#include <QtCore/QVariant>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QComboBox;
|
||||||
class QToolButton;
|
class QToolButton;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
@@ -50,6 +52,14 @@ class VCSBASE_EXPORT VCSBaseEditorParameterWidget : public QWidget
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
struct ComboBoxItem
|
||||||
|
{
|
||||||
|
ComboBoxItem();
|
||||||
|
ComboBoxItem(const QString &text, const QVariant &val);
|
||||||
|
QString displayText;
|
||||||
|
QVariant value;
|
||||||
|
};
|
||||||
|
|
||||||
explicit VCSBaseEditorParameterWidget(QWidget *parent = 0);
|
explicit VCSBaseEditorParameterWidget(QWidget *parent = 0);
|
||||||
~VCSBaseEditorParameterWidget();
|
~VCSBaseEditorParameterWidget();
|
||||||
|
|
||||||
@@ -60,6 +70,10 @@ public:
|
|||||||
const QString &tooltip = QString());
|
const QString &tooltip = QString());
|
||||||
QToolButton *addIgnoreWhiteSpaceButton(const QString &option);
|
QToolButton *addIgnoreWhiteSpaceButton(const QString &option);
|
||||||
QToolButton *addIgnoreBlankLinesButton(const QString &option);
|
QToolButton *addIgnoreBlankLinesButton(const QString &option);
|
||||||
|
QComboBox *addComboBox(const QString &option, const QList<ComboBoxItem> &items);
|
||||||
|
|
||||||
|
QStringList comboBoxOptionTemplate() const;
|
||||||
|
void setComboBoxOptionTemplate(const QStringList &optTemplate) const;
|
||||||
|
|
||||||
// Return the effective arguments according to setting.
|
// Return the effective arguments according to setting.
|
||||||
virtual QStringList arguments() const;
|
virtual QStringList arguments() const;
|
||||||
|
Reference in New Issue
Block a user