CodeStyleSelectorWidget: Avoid using sender()

Change-Id: I4250a3e37e52c68ba61676e835ca55a358d60146
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Jarek Kobus
2022-07-21 11:41:06 +02:00
parent ac85001d24
commit 18a79179ff
2 changed files with 15 additions and 19 deletions

View File

@@ -109,7 +109,7 @@ CodeStyleDialog::CodeStyleDialog(ICodeStylePreferencesFactory *factory,
m_codeStyle->setId(codeStyle->id()); m_codeStyle->setId(codeStyle->id());
m_codeStyle->setDisplayName(m_originalDisplayName); m_codeStyle->setDisplayName(m_originalDisplayName);
m_codeStyle->setReadOnly(codeStyle->isReadOnly()); m_codeStyle->setReadOnly(codeStyle->isReadOnly());
TextEditor::CodeStyleEditorWidget *editor = factory->createEditor(m_codeStyle, project, this); CodeStyleEditorWidget *editor = factory->createEditor(m_codeStyle, project, this);
m_buttons = new QDialogButtonBox( m_buttons = new QDialogButtonBox(
QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
@@ -372,38 +372,34 @@ void CodeStyleSelectorWidget::slotCodeStyleAdded(ICodeStylePreferences *codeStyl
m_ui->delegateComboBox->addItem(name, data); m_ui->delegateComboBox->addItem(name, data);
m_ui->delegateComboBox->setItemData(m_ui->delegateComboBox->count() - 1, name, Qt::ToolTipRole); m_ui->delegateComboBox->setItemData(m_ui->delegateComboBox->count() - 1, name, Qt::ToolTipRole);
connect(codeStylePreferences, &ICodeStylePreferences::displayNameChanged, connect(codeStylePreferences, &ICodeStylePreferences::displayNameChanged,
this, &CodeStyleSelectorWidget::slotUpdateName); this, [this, codeStylePreferences] { slotUpdateName(codeStylePreferences); });
if (codeStylePreferences->delegatingPool()) { if (codeStylePreferences->delegatingPool()) {
connect(codeStylePreferences, &ICodeStylePreferences::currentPreferencesChanged, connect(codeStylePreferences, &ICodeStylePreferences::currentPreferencesChanged,
this, &CodeStyleSelectorWidget::slotUpdateName); this, [this, codeStylePreferences] { slotUpdateName(codeStylePreferences); });
} }
} }
void CodeStyleSelectorWidget::slotCodeStyleRemoved(ICodeStylePreferences *codeStylePreferences) void CodeStyleSelectorWidget::slotCodeStyleRemoved(ICodeStylePreferences *codeStylePreferences)
{ {
m_ignoreGuiSignals = true; m_ignoreGuiSignals = true;
m_ui->delegateComboBox->removeItem(m_ui->delegateComboBox->findData(QVariant::fromValue(codeStylePreferences))); m_ui->delegateComboBox->removeItem(m_ui->delegateComboBox->findData(
disconnect(codeStylePreferences, &ICodeStylePreferences::displayNameChanged, QVariant::fromValue(codeStylePreferences)));
this, &CodeStyleSelectorWidget::slotUpdateName); disconnect(codeStylePreferences, &ICodeStylePreferences::displayNameChanged, this, nullptr);
if (codeStylePreferences->delegatingPool()) { if (codeStylePreferences->delegatingPool()) {
disconnect(codeStylePreferences, &ICodeStylePreferences::currentPreferencesChanged, disconnect(codeStylePreferences, &ICodeStylePreferences::currentPreferencesChanged,
this, &CodeStyleSelectorWidget::slotUpdateName); this, nullptr);
} }
m_ignoreGuiSignals = false; m_ignoreGuiSignals = false;
} }
void CodeStyleSelectorWidget::slotUpdateName() void CodeStyleSelectorWidget::slotUpdateName(ICodeStylePreferences *codeStylePreferences)
{ {
auto changedCodeStyle = qobject_cast<ICodeStylePreferences *>(sender()); updateName(codeStylePreferences);
if (!changedCodeStyle)
return;
updateName(changedCodeStyle);
QList<ICodeStylePreferences *> codeStyles = m_codeStyle->delegatingPool()->codeStyles(); QList<ICodeStylePreferences *> codeStyles = m_codeStyle->delegatingPool()->codeStyles();
for (int i = 0; i < codeStyles.count(); i++) { for (int i = 0; i < codeStyles.count(); i++) {
ICodeStylePreferences *codeStyle = codeStyles.at(i); ICodeStylePreferences *codeStyle = codeStyles.at(i);
if (codeStyle->currentDelegate() == changedCodeStyle) if (codeStyle->currentDelegate() == codeStylePreferences)
updateName(codeStyle); updateName(codeStyle);
} }

View File

@@ -46,19 +46,19 @@ public:
QWidget *parent = nullptr); QWidget *parent = nullptr);
~CodeStyleSelectorWidget() override; ~CodeStyleSelectorWidget() override;
void setCodeStyle(TextEditor::ICodeStylePreferences *codeStyle); void setCodeStyle(ICodeStylePreferences *codeStyle);
private: private:
void slotComboBoxActivated(int index); void slotComboBoxActivated(int index);
void slotCurrentDelegateChanged(TextEditor::ICodeStylePreferences *delegate); void slotCurrentDelegateChanged(ICodeStylePreferences *delegate);
void slotCopyClicked(); void slotCopyClicked();
void slotEditClicked(); void slotEditClicked();
void slotRemoveClicked(); void slotRemoveClicked();
void slotImportClicked(); void slotImportClicked();
void slotExportClicked(); void slotExportClicked();
void slotCodeStyleAdded(ICodeStylePreferences*); void slotCodeStyleAdded(ICodeStylePreferences *codeStylePreferences);
void slotCodeStyleRemoved(ICodeStylePreferences*); void slotCodeStyleRemoved(ICodeStylePreferences *codeStylePreferences);
void slotUpdateName(); void slotUpdateName(ICodeStylePreferences *codeStylePreferences);
void updateName(ICodeStylePreferences *codeStyle); void updateName(ICodeStylePreferences *codeStyle);
ICodeStylePreferencesFactory *m_factory; ICodeStylePreferencesFactory *m_factory;