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>
This commit is contained in:
hjk
2015-05-29 11:06:10 +02:00
parent dfa0d13734
commit f3ad26b23d
4 changed files with 48 additions and 37 deletions

View File

@@ -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)