diff options
author | Jarek Kobus <jaroslaw.kobus@qt.io> | 2022-08-15 10:09:46 +0200 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2022-08-22 10:11:01 +0000 |
commit | 71f0597e4916a0a852ac30952eb99dee79d7a51e (patch) | |
tree | 4edd7db73792d166dc8db4f9016ff5a2361fcd75 /src/plugins/clangformat | |
parent | 70089a870144377298b04fd13c8f0b76ddb9cb6b (diff) |
ClangFormatConfigWidget: Avoid using sender()
Use Utils::Guard instead of Utils::ExecuteOnDestruction.
Change-Id: I7f2be9c3864d9cac31423353d46dfa98660dd0af
Reviewed-by: hjk <hjk@qt.io>
Diffstat (limited to 'src/plugins/clangformat')
-rw-r--r-- | src/plugins/clangformat/clangformatconfigwidget.cpp | 21 | ||||
-rw-r--r-- | src/plugins/clangformat/clangformatconfigwidget.h | 6 |
2 files changed, 11 insertions, 16 deletions
diff --git a/src/plugins/clangformat/clangformatconfigwidget.cpp b/src/plugins/clangformat/clangformatconfigwidget.cpp index 71c42d504b..5d6037cdf4 100644 --- a/src/plugins/clangformat/clangformatconfigwidget.cpp +++ b/src/plugins/clangformat/clangformatconfigwidget.cpp @@ -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()); diff --git a/src/plugins/clangformat/clangformatconfigwidget.h b/src/plugins/clangformat/clangformatconfigwidget.h index 7d0372368e..391d347153 100644 --- a/src/plugins/clangformat/clangformatconfigwidget.h +++ b/src/plugins/clangformat/clangformatconfigwidget.h @@ -29,6 +29,8 @@ #include <clang/Format/Format.h> +#include <utils/guard.h> + #include <QScrollArea> #include <memory> @@ -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<Ui::ClangFormatChecksWidget> m_checks; clang::format::FormatStyle m_style; - bool m_disableTableUpdate = false; + Utils::Guard m_ignoreChanges; QLabel *m_projectHasClangFormat; QCheckBox *m_overrideDefault; |