forked from qt-creator/qt-creator
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:
@@ -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());
|
||||
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user