From f3ad26b23df1e877955121d6e3d849209c6c13a7 Mon Sep 17 00:00:00 2001 From: hjk Date: Fri, 29 May 2015 11:06:10 +0200 Subject: [PATCH] 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 --- src/libs/utils/savedaction.cpp | 54 ++++++++++++++-------- src/libs/utils/savedaction.h | 5 +- src/plugins/debugger/commonoptionspage.cpp | 16 +------ src/plugins/debugger/debuggeractions.cpp | 10 +++- 4 files changed, 48 insertions(+), 37 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 #include -#include +#include #include #include #include @@ -234,15 +234,12 @@ void SavedAction::connectWidget(QWidget *widget, ApplyMode applyMode) m_widget = widget; m_applyMode = applyMode; - if (QAbstractButton *button = qobject_cast(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(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(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(m_widget)) + if (QCheckBox *button = qobject_cast(m_widget)) setValue(button->isChecked()); else if (QLineEdit *lineEdit = qobject_cast(m_widget)) setValue(lineEdit->text()); @@ -304,17 +305,9 @@ void SavedAction::apply(QSettings *s) writeSettings(s); } -void SavedAction::uncheckableButtonClicked() -{ - QAbstractButton *button = qobject_cast(sender()); - QTC_ASSERT(button, return); - //qDebug() << "UNCHECKABLE BUTTON: " << sender(); - QAction::trigger(); -} - void SavedAction::checkableButtonClicked(bool) { - QAbstractButton *button = qobject_cast(sender()); + QCheckBox *button = qobject_cast(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) diff --git a/src/libs/utils/savedaction.h b/src/libs/utils/savedaction.h index bfeaa7b344b..ed4450e99f5 100644 --- a/src/libs/utils/savedaction.h +++ b/src/libs/utils/savedaction.h @@ -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; }; diff --git a/src/plugins/debugger/commonoptionspage.cpp b/src/plugins/debugger/commonoptionspage.cpp index 31f7e5c161d..7b1c8275fc3 100644 --- a/src/plugins/debugger/commonoptionspage.cpp +++ b/src/plugins/debugger/commonoptionspage.cpp @@ -377,23 +377,9 @@ QWidget *LocalsAndExpressionsOptionsPage::widget() + QLatin1String("

")); 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("")); diff --git a/src/plugins/debugger/debuggeractions.cpp b/src/plugins/debugger/debuggeractions.cpp index c766b28da69..481b011fd51 100644 --- a/src/plugins/debugger/debuggeractions.cpp +++ b/src/plugins/debugger/debuggeractions.cpp @@ -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);