diff --git a/src/plugins/clangformat/clangformatconfigwidget.cpp b/src/plugins/clangformat/clangformatconfigwidget.cpp index 71c42d504b1..5d6037cdf40 100644 --- a/src/plugins/clangformat/clangformatconfigwidget.cpp +++ b/src/plugins/clangformat/clangformatconfigwidget.cpp @@ -54,7 +54,6 @@ #include #include -#include #include #include @@ -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(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(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()); diff --git a/src/plugins/clangformat/clangformatconfigwidget.h b/src/plugins/clangformat/clangformatconfigwidget.h index 7d0372368ea..391d347153d 100644 --- a/src/plugins/clangformat/clangformatconfigwidget.h +++ b/src/plugins/clangformat/clangformatconfigwidget.h @@ -29,6 +29,8 @@ #include +#include + #include #include @@ -65,8 +67,6 @@ public: void synchronize() override; private: - void onTableChanged(); - bool eventFilter(QObject *object, QEvent *event) override; void showOrHideWidgets(); @@ -88,7 +88,7 @@ private: std::unique_ptr m_checks; clang::format::FormatStyle m_style; - bool m_disableTableUpdate = false; + Utils::Guard m_ignoreChanges; QLabel *m_projectHasClangFormat; QCheckBox *m_overrideDefault;