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/textdocument.h>
|
||||||
#include <texteditor/texteditorsettings.h>
|
#include <texteditor/texteditorsettings.h>
|
||||||
|
|
||||||
#include <utils/executeondestruction.h>
|
|
||||||
#include <utils/layoutbuilder.h>
|
#include <utils/layoutbuilder.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
@@ -181,29 +180,26 @@ void ClangFormatConfigWidget::initOverrideCheckBox()
|
|||||||
|
|
||||||
void ClangFormatConfigWidget::connectChecks()
|
void ClangFormatConfigWidget::connectChecks()
|
||||||
{
|
{
|
||||||
|
auto doSaveChanges = [this](QObject *sender) {
|
||||||
|
if (!m_ignoreChanges.isLocked())
|
||||||
|
saveChanges(sender);
|
||||||
|
};
|
||||||
|
|
||||||
for (QObject *child : m_checksWidget->children()) {
|
for (QObject *child : m_checksWidget->children()) {
|
||||||
auto comboBox = qobject_cast<QComboBox *>(child);
|
auto comboBox = qobject_cast<QComboBox *>(child);
|
||||||
if (comboBox != nullptr) {
|
if (comboBox != nullptr) {
|
||||||
connect(comboBox, &QComboBox::currentIndexChanged,
|
connect(comboBox, &QComboBox::currentIndexChanged,
|
||||||
this, &ClangFormatConfigWidget::onTableChanged);
|
this, std::bind(doSaveChanges, comboBox));
|
||||||
comboBox->installEventFilter(this);
|
comboBox->installEventFilter(this);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto button = qobject_cast<QPushButton *>(child);
|
const auto button = qobject_cast<QPushButton *>(child);
|
||||||
if (button != nullptr)
|
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()
|
static bool projectConfigExists()
|
||||||
{
|
{
|
||||||
return Core::ICore::userResourcePath()
|
return Core::ICore::userResourcePath()
|
||||||
@@ -332,8 +328,7 @@ static void fillComboBoxOrLineEdit(QObject *object, const std::string &text, siz
|
|||||||
|
|
||||||
void ClangFormatConfigWidget::fillTable()
|
void ClangFormatConfigWidget::fillTable()
|
||||||
{
|
{
|
||||||
Utils::ExecuteOnDestruction executeOnDestruction([this] { m_disableTableUpdate = false; });
|
Utils::GuardLocker locker(m_ignoreChanges);
|
||||||
m_disableTableUpdate = true;
|
|
||||||
|
|
||||||
const std::string configText = readFile(m_config->filePath().path());
|
const std::string configText = readFile(m_config->filePath().path());
|
||||||
|
|
||||||
|
@@ -29,6 +29,8 @@
|
|||||||
|
|
||||||
#include <clang/Format/Format.h>
|
#include <clang/Format/Format.h>
|
||||||
|
|
||||||
|
#include <utils/guard.h>
|
||||||
|
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@@ -65,8 +67,6 @@ public:
|
|||||||
void synchronize() override;
|
void synchronize() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onTableChanged();
|
|
||||||
|
|
||||||
bool eventFilter(QObject *object, QEvent *event) override;
|
bool eventFilter(QObject *object, QEvent *event) override;
|
||||||
|
|
||||||
void showOrHideWidgets();
|
void showOrHideWidgets();
|
||||||
@@ -88,7 +88,7 @@ private:
|
|||||||
std::unique_ptr<Ui::ClangFormatChecksWidget> m_checks;
|
std::unique_ptr<Ui::ClangFormatChecksWidget> m_checks;
|
||||||
clang::format::FormatStyle m_style;
|
clang::format::FormatStyle m_style;
|
||||||
|
|
||||||
bool m_disableTableUpdate = false;
|
Utils::Guard m_ignoreChanges;
|
||||||
|
|
||||||
QLabel *m_projectHasClangFormat;
|
QLabel *m_projectHasClangFormat;
|
||||||
QCheckBox *m_overrideDefault;
|
QCheckBox *m_overrideDefault;
|
||||||
|
Reference in New Issue
Block a user