Commit f3ad26b2 authored by hjk's avatar hjk
Browse files

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: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent dfa0d137
......@@ -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)
......
......@@ -75,11 +75,13 @@ public:
QString toString() const;
QString dialogText() const;
void setDialogText(const QString &dialogText);
signals:
void valueChanged(const QVariant &newValue);
private:
void uncheckableButtonClicked();
void checkableButtonClicked(bool);
void lineEditEditingFinished();
void pathChooserEditingFinished();
......@@ -92,6 +94,7 @@ private:
QVariant m_defaultValue;
QString m_settingsKey;
QString m_settingsGroup;
QString m_dialogText;
QWidget *m_widget;
ApplyMode m_applyMode;
};
......
......@@ -377,23 +377,9 @@ QWidget *LocalsAndExpressionsOptionsPage::widget()
+ QLatin1String("</p></body></html>"));
auto checkBoxUseCodeModel = new QCheckBox(debuggingHelperGroupBox);
checkBoxUseCodeModel->setText(tr("Use code model"));
checkBoxUseCodeModel->setToolTip(action(UseCodeModel)->toolTip());
checkBoxUseCodeModel->setToolTip(tr("Makes use of Qt Creator's code model "
"to find out if a variable has already been assigned a "
"value at the point the debugger interrupts."));
auto checkBoxShowThreadNames = new QCheckBox(debuggingHelperGroupBox);
checkBoxShowThreadNames->setToolTip(tr("Displays names of QThread based threads."));
checkBoxShowThreadNames->setText(tr("Display thread names"));
auto checkBoxShowStdNamespace = new QCheckBox(m_widget);
checkBoxShowStdNamespace->setToolTip(tr("Shows \"std::\" prefix for types from the standard library."));
checkBoxShowStdNamespace->setText(tr("Show \"std::\" namespace for types"));
auto checkBoxShowStdNamespace = new QCheckBox(m_widget);
auto checkBoxShowQtNamespace = new QCheckBox(m_widget);
checkBoxShowQtNamespace->setToolTip(tr("Shows Qt namespace prefix for Qt types. This is only relevant if Qt was configured with '-qtnamespace'."));
checkBoxShowQtNamespace->setText(tr("Qt's namespace for types"));
auto spinBoxMaximalStringLength = new QSpinBox(m_widget);
spinBoxMaximalStringLength->setSpecialValueText(tr("<unlimited>"));
......
......@@ -261,6 +261,8 @@ DebuggerSettings::DebuggerSettings()
item = new SavedAction(this);
item->setSettingsKey(debugModeGroup, QLatin1String("ShowStandardNamespace"));
item->setText(tr("Show \"std::\" Namespace in Types"));
item->setDialogText(tr("Show \"std::\" namespace in types"));
item->setToolTip(tr("Shows \"std::\" prefix for types from the standard library."));
item->setCheckable(true);
item->setDefaultValue(true);
item->setValue(true);
......@@ -269,6 +271,9 @@ DebuggerSettings::DebuggerSettings()
item = new SavedAction(this);
item->setSettingsKey(debugModeGroup, QLatin1String("ShowQtNamespace"));
item->setText(tr("Show Qt's Namespace in Types"));
item->setDialogText(tr("Show Qt's namespace in types"));
item->setToolTip(tr("Shows Qt namespace prefix for Qt types. This is only "
"relevant if Qt was configured with \"-qtnamespace\"."));
item->setCheckable(true);
item->setDefaultValue(true);
item->setValue(true);
......@@ -277,6 +282,7 @@ DebuggerSettings::DebuggerSettings()
item = new SavedAction(this);
item->setSettingsKey(debugModeGroup, QLatin1String("SortStructMembers"));
item->setText(tr("Sort Members of Classes and Structs Alphabetically"));
item->setDialogText(tr("Sort members of classes and structs alphabetically"));
item->setCheckable(true);
item->setDefaultValue(true);
item->setValue(true);
......@@ -295,7 +301,7 @@ DebuggerSettings::DebuggerSettings()
item = new SavedAction(this);
item->setSettingsKey(debugModeGroup, QLatin1String("UseCodeModel"));
item->setText(tr("Use Code Model"));
item->setDialogText(tr("Use code model"));
item->setToolTip(tr("Selecting this causes the C++ Code Model being asked "
"for variable scope information. This might result in slightly faster "
"debugger operation but may fail for optimized code."));
......@@ -306,6 +312,8 @@ DebuggerSettings::DebuggerSettings()
item = new SavedAction(this);
item->setSettingsKey(debugModeGroup, QLatin1String("ShowThreadNames"));
item->setToolTip(tr("Displays names of QThread based threads."));
item->setDialogText(tr("Display thread names"));
item->setCheckable(true);
item->setDefaultValue(false);
item->setValue(false);
......
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