forked from qt-creator/qt-creator
Utils: Modernize SavedActions
Smaller visible interface. Change-Id: I5b4a875b208e1202b46780dbe7f91e881a17becb Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
@@ -43,7 +43,7 @@
|
|||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
|
|
||||||
using namespace Utils;
|
namespace Utils {
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
@@ -229,37 +229,50 @@ void SavedAction::connectWidget(QWidget *widget, ApplyMode applyMode)
|
|||||||
QTC_ASSERT(!m_widget,
|
QTC_ASSERT(!m_widget,
|
||||||
qDebug() << "ALREADY CONNECTED: " << widget << m_widget << toString(); return);
|
qDebug() << "ALREADY CONNECTED: " << widget << m_widget << toString(); return);
|
||||||
m_widget = widget;
|
m_widget = widget;
|
||||||
m_applyMode = applyMode;
|
|
||||||
|
|
||||||
if (QCheckBox *button = qobject_cast<QCheckBox *>(widget)) {
|
if (auto button = qobject_cast<QCheckBox *>(widget)) {
|
||||||
if (!m_dialogText.isEmpty())
|
if (!m_dialogText.isEmpty())
|
||||||
button->setText(m_dialogText);
|
button->setText(m_dialogText);
|
||||||
button->setChecked(m_value.toBool());
|
button->setChecked(m_value.toBool());
|
||||||
connect(button, &QCheckBox::clicked,
|
if (applyMode == ImmediateApply) {
|
||||||
this, &SavedAction::checkableButtonClicked);
|
connect(button, &QCheckBox::clicked,
|
||||||
} else if (QSpinBox *spinBox = qobject_cast<QSpinBox *>(widget)) {
|
this, [this, button] { setValue(button->isChecked()); });
|
||||||
|
}
|
||||||
|
} else if (auto spinBox = qobject_cast<QSpinBox *>(widget)) {
|
||||||
spinBox->setValue(m_value.toInt());
|
spinBox->setValue(m_value.toInt());
|
||||||
connect(spinBox, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged),
|
if (applyMode == ImmediateApply) {
|
||||||
this, &SavedAction::spinBoxValueChanged);
|
connect(spinBox, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged),
|
||||||
} else if (QLineEdit *lineEdit = qobject_cast<QLineEdit *>(widget)) {
|
this, [this, spinBox]() { setValue(spinBox->value()); });
|
||||||
|
}
|
||||||
|
} else if (auto lineEdit = qobject_cast<QLineEdit *>(widget)) {
|
||||||
lineEdit->setText(m_value.toString());
|
lineEdit->setText(m_value.toString());
|
||||||
connect(lineEdit, &QLineEdit::editingFinished,
|
if (applyMode == ImmediateApply) {
|
||||||
this, &SavedAction::lineEditEditingFinished);
|
connect(lineEdit, &QLineEdit::editingFinished,
|
||||||
} else if (PathChooser *pathChooser = qobject_cast<PathChooser *>(widget)) {
|
this, [this, lineEdit] { setValue(lineEdit->text()); });
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (auto pathChooser = qobject_cast<PathChooser *>(widget)) {
|
||||||
pathChooser->setPath(m_value.toString());
|
pathChooser->setPath(m_value.toString());
|
||||||
connect(pathChooser, &PathChooser::editingFinished,
|
if (applyMode == ImmediateApply) {
|
||||||
this, &SavedAction::pathChooserEditingFinished);
|
auto finished = [this, pathChooser] { setValue(pathChooser->path()); };
|
||||||
connect(pathChooser, &PathChooser::browsingFinished,
|
connect(pathChooser, &PathChooser::editingFinished, this, finished);
|
||||||
this, &SavedAction::pathChooserEditingFinished);
|
connect(pathChooser, &PathChooser::browsingFinished, this, finished);
|
||||||
} else if (QGroupBox *groupBox = qobject_cast<QGroupBox *>(widget)) {
|
}
|
||||||
|
} else if (auto groupBox = qobject_cast<QGroupBox *>(widget)) {
|
||||||
if (!groupBox->isCheckable())
|
if (!groupBox->isCheckable())
|
||||||
qDebug() << "connectWidget to non-checkable group box" << widget << toString();
|
qDebug() << "connectWidget to non-checkable group box" << widget << toString();
|
||||||
groupBox->setChecked(m_value.toBool());
|
groupBox->setChecked(m_value.toBool());
|
||||||
connect(groupBox, &QGroupBox::toggled, this, &SavedAction::groupBoxToggled);
|
if (applyMode == ImmediateApply) {
|
||||||
} else if (QTextEdit *textEdit = qobject_cast<QTextEdit *>(widget)) {
|
connect(groupBox, &QGroupBox::toggled,
|
||||||
|
this, [this, groupBox] { setValue(QVariant(groupBox->isChecked())); });
|
||||||
|
}
|
||||||
|
} else if (auto textEdit = qobject_cast<QTextEdit *>(widget)) {
|
||||||
textEdit->setPlainText(m_value.toString());
|
textEdit->setPlainText(m_value.toString());
|
||||||
connect(textEdit, &QTextEdit::textChanged, this, &SavedAction::textEditTextChanged);
|
if (applyMode == ImmediateApply) {
|
||||||
} else if (PathListEditor *editor = qobject_cast<PathListEditor *>(widget)) {
|
connect(textEdit, &QTextEdit::textChanged,
|
||||||
|
this, [this, textEdit] { setValue(textEdit->toPlainText()); });
|
||||||
|
}
|
||||||
|
} else if (auto editor = qobject_cast<PathListEditor *>(widget)) {
|
||||||
editor->setPathList(m_value.toStringList());
|
editor->setPathList(m_value.toStringList());
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Cannot connect widget " << widget << toString();
|
qDebug() << "Cannot connect widget " << widget << toString();
|
||||||
@@ -282,64 +295,24 @@ void SavedAction::disconnectWidget()
|
|||||||
|
|
||||||
void SavedAction::apply(QSettings *s)
|
void SavedAction::apply(QSettings *s)
|
||||||
{
|
{
|
||||||
if (QCheckBox *button = qobject_cast<QCheckBox *>(m_widget))
|
if (auto button = qobject_cast<QCheckBox *>(m_widget))
|
||||||
setValue(button->isChecked());
|
setValue(button->isChecked());
|
||||||
else if (QLineEdit *lineEdit = qobject_cast<QLineEdit *>(m_widget))
|
else if (auto lineEdit = qobject_cast<QLineEdit *>(m_widget))
|
||||||
setValue(lineEdit->text());
|
setValue(lineEdit->text());
|
||||||
else if (QSpinBox *spinBox = qobject_cast<QSpinBox *>(m_widget))
|
else if (auto spinBox = qobject_cast<QSpinBox *>(m_widget))
|
||||||
setValue(spinBox->value());
|
setValue(spinBox->value());
|
||||||
else if (PathChooser *pathChooser = qobject_cast<PathChooser *>(m_widget))
|
else if (auto pathChooser = qobject_cast<PathChooser *>(m_widget))
|
||||||
setValue(pathChooser->path());
|
setValue(pathChooser->path());
|
||||||
else if (const QGroupBox *groupBox = qobject_cast<QGroupBox *>(m_widget))
|
else if (auto groupBox = qobject_cast<QGroupBox *>(m_widget))
|
||||||
setValue(groupBox->isChecked());
|
setValue(groupBox->isChecked());
|
||||||
else if (const QTextEdit *textEdit = qobject_cast<QTextEdit *>(m_widget))
|
else if (auto textEdit = qobject_cast<QTextEdit *>(m_widget))
|
||||||
setValue(textEdit->toPlainText());
|
setValue(textEdit->toPlainText());
|
||||||
else if (const PathListEditor *editor = qobject_cast<PathListEditor *>(m_widget))
|
else if (auto editor = qobject_cast<PathListEditor *>(m_widget))
|
||||||
setValue(editor->pathList());
|
setValue(editor->pathList());
|
||||||
if (s)
|
if (s)
|
||||||
writeSettings(s);
|
writeSettings(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SavedAction::checkableButtonClicked(bool)
|
|
||||||
{
|
|
||||||
QCheckBox *button = qobject_cast<QCheckBox *>(sender());
|
|
||||||
QTC_ASSERT(button, return);
|
|
||||||
if (m_applyMode == ImmediateApply)
|
|
||||||
setValue(button->isChecked());
|
|
||||||
}
|
|
||||||
|
|
||||||
void SavedAction::lineEditEditingFinished()
|
|
||||||
{
|
|
||||||
QLineEdit *lineEdit = qobject_cast<QLineEdit *>(sender());
|
|
||||||
QTC_ASSERT(lineEdit, return);
|
|
||||||
if (m_applyMode == ImmediateApply)
|
|
||||||
setValue(lineEdit->text());
|
|
||||||
}
|
|
||||||
|
|
||||||
void SavedAction::spinBoxValueChanged(int value)
|
|
||||||
{
|
|
||||||
QSpinBox *spinBox = qobject_cast<QSpinBox *>(sender());
|
|
||||||
QTC_ASSERT(spinBox, return);
|
|
||||||
if (m_applyMode == ImmediateApply)
|
|
||||||
setValue(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SavedAction::pathChooserEditingFinished()
|
|
||||||
{
|
|
||||||
PathChooser *pathChooser = qobject_cast<PathChooser *>(sender());
|
|
||||||
QTC_ASSERT(pathChooser, return);
|
|
||||||
if (m_applyMode == ImmediateApply)
|
|
||||||
setValue(pathChooser->path());
|
|
||||||
}
|
|
||||||
|
|
||||||
void SavedAction::textEditTextChanged()
|
|
||||||
{
|
|
||||||
QTextEdit *textEdit = qobject_cast<QTextEdit *>(sender());
|
|
||||||
QTC_ASSERT(textEdit, return);
|
|
||||||
if (m_applyMode == ImmediateApply)
|
|
||||||
setValue(textEdit->toPlainText());
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Default text to be used in labels if this SavedAction is
|
Default text to be used in labels if this SavedAction is
|
||||||
used in a settings dialog.
|
used in a settings dialog.
|
||||||
@@ -360,13 +333,6 @@ void SavedAction::setDialogText(const QString &dialogText)
|
|||||||
m_dialogText = dialogText;
|
m_dialogText = dialogText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SavedAction::groupBoxToggled(bool checked)
|
|
||||||
{
|
|
||||||
if (m_applyMode == ImmediateApply)
|
|
||||||
setValue(QVariant(checked));
|
|
||||||
}
|
|
||||||
|
|
||||||
void SavedAction::actionTriggered(bool)
|
void SavedAction::actionTriggered(bool)
|
||||||
{
|
{
|
||||||
if (isCheckable())
|
if (isCheckable())
|
||||||
@@ -410,3 +376,4 @@ void SavedActionSet::finish()
|
|||||||
action->disconnectWidget();
|
action->disconnectWidget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Utils
|
||||||
|
@@ -82,13 +82,7 @@ signals:
|
|||||||
void valueChanged(const QVariant &newValue);
|
void valueChanged(const QVariant &newValue);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void checkableButtonClicked(bool);
|
|
||||||
void lineEditEditingFinished();
|
|
||||||
void pathChooserEditingFinished();
|
|
||||||
void actionTriggered(bool);
|
void actionTriggered(bool);
|
||||||
void spinBoxValueChanged(int);
|
|
||||||
void groupBoxToggled(bool checked);
|
|
||||||
void textEditTextChanged();
|
|
||||||
|
|
||||||
QVariant m_value;
|
QVariant m_value;
|
||||||
QVariant m_defaultValue;
|
QVariant m_defaultValue;
|
||||||
@@ -96,7 +90,6 @@ private:
|
|||||||
QString m_settingsGroup;
|
QString m_settingsGroup;
|
||||||
QString m_dialogText;
|
QString m_dialogText;
|
||||||
QWidget *m_widget;
|
QWidget *m_widget;
|
||||||
ApplyMode m_applyMode;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT SavedActionSet
|
class QTCREATOR_UTILS_EXPORT SavedActionSet
|
||||||
|
Reference in New Issue
Block a user