aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/utils/savedaction.cpp
diff options
context:
space:
mode:
authorhjk <hjk@theqtcompany.com>2015-05-29 11:06:10 +0200
committerhjk <hjk@theqtcompany.com>2015-06-04 10:32:27 +0000
commitf3ad26b23df1e877955121d6e3d849209c6c13a7 (patch)
tree6f1e6b05c6d96a225e66c74b742e18f194f71ff1 /src/libs/utils/savedaction.cpp
parentdfa0d1373448f7e5fb200b420752252c0d089716 (diff)
Utils: Add a text variant to SavedAction for use in dialogs
Usually the same as the text() for use in menus, but with different capitalization. Also, restrict the QAbstractButton case to QCheckBox. That's the only case where it is used. Change-Id: Iaf87265a214891b83fa5604eb69290e2160c57f0 Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
Diffstat (limited to 'src/libs/utils/savedaction.cpp')
-rw-r--r--src/libs/utils/savedaction.cpp54
1 files changed, 34 insertions, 20 deletions
diff --git a/src/libs/utils/savedaction.cpp b/src/libs/utils/savedaction.cpp
index 165c08fa383..94c83a0e9dd 100644
--- a/src/libs/utils/savedaction.cpp
+++ b/src/libs/utils/savedaction.cpp
@@ -37,7 +37,7 @@
#include <QDebug>
#include <QSettings>
-#include <QAbstractButton>
+#include <QCheckBox>
#include <QGroupBox>
#include <QLineEdit>
#include <QSpinBox>
@@ -234,15 +234,12 @@ void SavedAction::connectWidget(QWidget *widget, ApplyMode applyMode)
m_widget = widget;
m_applyMode = applyMode;
- if (QAbstractButton *button = qobject_cast<QAbstractButton *>(widget)) {
- if (button->isCheckable()) {
- button->setChecked(m_value.toBool());
- connect(button, &QAbstractButton::clicked,
- this, &SavedAction::checkableButtonClicked);
- } else {
- connect(button, &QAbstractButton::clicked,
- this, &SavedAction::uncheckableButtonClicked);
- }
+ if (QCheckBox *button = qobject_cast<QCheckBox *>(widget)) {
+ if (!m_dialogText.isEmpty())
+ button->setText(m_dialogText);
+ button->setChecked(m_value.toBool());
+ connect(button, &QCheckBox::clicked,
+ this, &SavedAction::checkableButtonClicked);
} else if (QSpinBox *spinBox = qobject_cast<QSpinBox *>(widget)) {
spinBox->setValue(m_value.toInt());
//qDebug() << "SETTING VALUE" << spinBox->value();
@@ -272,6 +269,10 @@ void SavedAction::connectWidget(QWidget *widget, ApplyMode applyMode)
} else {
qDebug() << "Cannot connect widget " << widget << toString();
}
+
+ // Copy tooltip, but only if there's nothing explcitly set on the widget yet.
+ if (widget->toolTip().isEmpty())
+ widget->setToolTip(toolTip());
}
/*
@@ -286,7 +287,7 @@ void SavedAction::disconnectWidget()
void SavedAction::apply(QSettings *s)
{
- if (QAbstractButton *button = qobject_cast<QAbstractButton *>(m_widget))
+ if (QCheckBox *button = qobject_cast<QCheckBox *>(m_widget))
setValue(button->isChecked());
else if (QLineEdit *lineEdit = qobject_cast<QLineEdit *>(m_widget))
setValue(lineEdit->text());
@@ -304,17 +305,9 @@ void SavedAction::apply(QSettings *s)
writeSettings(s);
}
-void SavedAction::uncheckableButtonClicked()
-{
- QAbstractButton *button = qobject_cast<QAbstractButton *>(sender());
- QTC_ASSERT(button, return);
- //qDebug() << "UNCHECKABLE BUTTON: " << sender();
- QAction::trigger();
-}
-
void SavedAction::checkableButtonClicked(bool)
{
- QAbstractButton *button = qobject_cast<QAbstractButton *>(sender());
+ QCheckBox *button = qobject_cast<QCheckBox *>(sender());
QTC_ASSERT(button, return);
//qDebug() << "CHECKABLE BUTTON: " << sender();
if (m_applyMode == ImmediateApply)
@@ -353,6 +346,27 @@ void SavedAction::textEditTextChanged()
setValue(textEdit->toPlainText());
}
+/*
+ Default text to be used in labels if this SavedAction is
+ used in a settings dialog.
+
+ This typically is similar to the text this SavedAction shows
+ when used in menus, but differs in capitalization.
+
+
+ \sa text()
+*/
+QString SavedAction::dialogText() const
+{
+ return m_dialogText;
+}
+
+void SavedAction::setDialogText(const QString &dialogText)
+{
+ m_dialogText = dialogText;
+}
+
+
void SavedAction::groupBoxToggled(bool checked)
{
if (m_applyMode == ImmediateApply)