ClangFormatConfigWidget: Avoid using sender()

Use Utils::Guard instead of Utils::ExecuteOnDestruction.

Change-Id: I7f2be9c3864d9cac31423353d46dfa98660dd0af
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2022-08-15 10:09:46 +02:00
parent 70089a8701
commit 71f0597e49
2 changed files with 11 additions and 16 deletions

View File

@@ -54,7 +54,6 @@
#include <texteditor/textdocument.h>
#include <texteditor/texteditorsettings.h>
#include <utils/executeondestruction.h>
#include <utils/layoutbuilder.h>
#include <utils/qtcassert.h>
@@ -181,29 +180,26 @@ void ClangFormatConfigWidget::initOverrideCheckBox()
void ClangFormatConfigWidget::connectChecks()
{
auto doSaveChanges = [this](QObject *sender) {
if (!m_ignoreChanges.isLocked())
saveChanges(sender);
};
for (QObject *child : m_checksWidget->children()) {
auto comboBox = qobject_cast<QComboBox *>(child);
if (comboBox != nullptr) {
connect(comboBox, &QComboBox::currentIndexChanged,
this, &ClangFormatConfigWidget::onTableChanged);
this, std::bind(doSaveChanges, comboBox));
comboBox->installEventFilter(this);
continue;
}
const auto button = qobject_cast<QPushButton *>(child);
if (button != nullptr)
connect(button, &QPushButton::clicked, this, &ClangFormatConfigWidget::onTableChanged);
connect(button, &QPushButton::clicked, this, std::bind(doSaveChanges, button));
}
}
void ClangFormatConfigWidget::onTableChanged()
{
if (m_disableTableUpdate)
return;
saveChanges(sender());
}
static bool projectConfigExists()
{
return Core::ICore::userResourcePath()
@@ -332,8 +328,7 @@ static void fillComboBoxOrLineEdit(QObject *object, const std::string &text, siz
void ClangFormatConfigWidget::fillTable()
{
Utils::ExecuteOnDestruction executeOnDestruction([this] { m_disableTableUpdate = false; });
m_disableTableUpdate = true;
Utils::GuardLocker locker(m_ignoreChanges);
const std::string configText = readFile(m_config->filePath().path());