summaryrefslogtreecommitdiff
path: root/src/plugins/vcsbase/vcsbaseeditorparameterwidget.cpp
diff options
context:
space:
mode:
authorcerf <delorme.hugues@gmail.com>2011-05-31 08:31:25 +0000
committerTobias Hunger <tobias.hunger@nokia.com>2011-05-31 10:44:47 +0200
commit05c0c2f4d80f05717e19560d280b95fe187d59af (patch)
treee050b027265212915c108d1d121276701ef8284a /src/plugins/vcsbase/vcsbaseeditorparameterwidget.cpp
parent6adf2c82a4e5716a8814dc59e5b537999cf42ff9 (diff)
downloadqt-creator-05c0c2f4d80f05717e19560d280b95fe187d59af.tar.gz
vcsbase: simplify mapping of toggle buttons in EditorParameterWidget
Change-Id: I9fee337731999f9ed4820cd2b449e1d3db661f65 Merge-request: 331 Reviewed-by: Tobias Hunger <tobias.hunger@nokia.com> Reviewed-on: http://codereview.qt.nokia.com/254 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Diffstat (limited to 'src/plugins/vcsbase/vcsbaseeditorparameterwidget.cpp')
-rw-r--r--src/plugins/vcsbase/vcsbaseeditorparameterwidget.cpp109
1 files changed, 40 insertions, 69 deletions
diff --git a/src/plugins/vcsbase/vcsbaseeditorparameterwidget.cpp b/src/plugins/vcsbase/vcsbaseeditorparameterwidget.cpp
index 35e9ab1fb7..3acf13fedc 100644
--- a/src/plugins/vcsbase/vcsbaseeditorparameterwidget.cpp
+++ b/src/plugins/vcsbase/vcsbaseeditorparameterwidget.cpp
@@ -38,58 +38,6 @@
#include <QtCore/QDebug>
namespace VCSBase {
-namespace Internal {
-
-/*!
- \class VCSBase::Internal::VCSBaseEditorParameterToggleButton
-
- \brief ToggleButton to be inserted into VCSBase::VCSBaseEditorParameterWidget
-
- Inserts a single option into the argument list depending on whether it is checked.
-*/
-
-class VCSBaseEditorParameterToggleButton : public QToolButton
-{
- Q_OBJECT
-public:
- explicit VCSBaseEditorParameterToggleButton(QWidget *parent = 0);
-
- void applyToArguments(QStringList *w) const;
- void setFromArguments(const QStringList &a);
-
- void setOption(const QString &o) { m_option = o; }
- QString option() const { return m_option; }
-
-signals:
- void changed();
-
-private:
- QString m_option;
-};
-
-VCSBaseEditorParameterToggleButton::VCSBaseEditorParameterToggleButton(QWidget *parent) :
- QToolButton(parent)
-{
- setCheckable(true);
- connect(this, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
-}
-
-void VCSBaseEditorParameterToggleButton::applyToArguments(QStringList *a) const
-{
- if (isChecked()) {
- if (!a->contains(m_option))
- a->append(m_option);
- } else {
- a->removeAll(m_option);
- }
-}
-
-void VCSBaseEditorParameterToggleButton::setFromArguments(const QStringList &a)
-{
- setChecked(a.contains(m_option));
-}
-
-} // namespace Internal
class VCSBaseEditorParameterWidgetPrivate
{
@@ -98,7 +46,7 @@ public:
QStringList m_baseArguments;
QHBoxLayout *m_layout;
- QList<Internal::VCSBaseEditorParameterToggleButton *> m_toggles;
+ QList<VCSBaseEditorParameterWidget::OptionMapping> m_optionMappings;
};
/*!
@@ -138,33 +86,34 @@ void VCSBaseEditorParameterWidget::setBaseArguments(const QStringList &b)
QStringList VCSBaseEditorParameterWidget::arguments() const
{
// Compile effective arguments
- QStringList args = d->m_baseArguments;
- foreach (const Internal::VCSBaseEditorParameterToggleButton *tb, d->m_toggles)
- tb->applyToArguments(&args);
+ QStringList args = baseArguments();
+ foreach (const OptionMapping &mapping, optionMappings())
+ args += argumentsForOption(mapping);
return args;
}
-void VCSBaseEditorParameterWidget::addToggleButton(const QString &option,
- const QString &label,
- const QString &toolTip)
+QToolButton *VCSBaseEditorParameterWidget::addToggleButton(const QString &option,
+ const QString &label,
+ const QString &toolTip)
{
- Internal::VCSBaseEditorParameterToggleButton *tb = new Internal::VCSBaseEditorParameterToggleButton;
- tb->setOption(option);
+ QToolButton *tb = new QToolButton;
tb->setText(label);
tb->setToolTip(toolTip);
- connect(tb, SIGNAL(changed()), this, SIGNAL(argumentsChanged()));
+ tb->setCheckable(true);
+ connect(tb, SIGNAL(toggled(bool)), this, SIGNAL(argumentsChanged()));
d->m_layout->addWidget(tb);
- d->m_toggles.append(tb);
+ d->m_optionMappings.append(OptionMapping(option, tb));
+ return tb;
}
-void VCSBaseEditorParameterWidget::addIgnoreWhiteSpaceButton(const QString &option)
+QToolButton *VCSBaseEditorParameterWidget::addIgnoreWhiteSpaceButton(const QString &option)
{
- addToggleButton(option, msgIgnoreWhiteSpaceLabel(), msgIgnoreWhiteSpaceToolTip());
+ return addToggleButton(option, msgIgnoreWhiteSpaceLabel(), msgIgnoreWhiteSpaceToolTip());
}
-void VCSBaseEditorParameterWidget::addIgnoreBlankLinesButton(const QString &option)
+QToolButton *VCSBaseEditorParameterWidget::addIgnoreBlankLinesButton(const QString &option)
{
- addToggleButton(option, msgIgnoreBlankLinesLabel(), msgIgnoreBlankLinesToolTip());
+ return addToggleButton(option, msgIgnoreBlankLinesLabel(), msgIgnoreBlankLinesToolTip());
}
QString VCSBaseEditorParameterWidget::msgIgnoreWhiteSpaceLabel()
@@ -196,6 +145,28 @@ void VCSBaseEditorParameterWidget::handleArgumentsChanged()
executeCommand();
}
-} // namespace VCSBase
+VCSBaseEditorParameterWidget::OptionMapping::OptionMapping() :
+ widget(0)
+{
+}
+
+VCSBaseEditorParameterWidget::OptionMapping::OptionMapping(const QString &optName, QWidget *w) :
+ optionName(optName), widget(w)
+{
+}
-#include "vcsbaseeditorparameterwidget.moc"
+const QList<VCSBaseEditorParameterWidget::OptionMapping> &VCSBaseEditorParameterWidget::optionMappings() const
+{
+ return d->m_optionMappings;
+}
+
+QStringList VCSBaseEditorParameterWidget::argumentsForOption(const OptionMapping &mapping) const
+{
+ QStringList args;
+ const QToolButton *tb = qobject_cast<const QToolButton *>(mapping.widget);
+ if (tb != 0 && tb->isChecked())
+ args += mapping.optionName;
+ return args;
+}
+
+} // namespace VCSBase