ScxmlEditor: Avoid using sender()

Do some cleanup of unneeded () after lambda capture.
Fit code into 100 char lines.

Change-Id: I2494765f6ba7aa1f13f4eadb7183bc88febd9638
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Jarek Kobus
2022-07-20 18:04:18 +02:00
parent bb0030e907
commit 74046fa1f5
3 changed files with 68 additions and 50 deletions

View File

@@ -227,7 +227,7 @@ void MainWidget::init()
if (provider) if (provider)
provider->init(m_errorPane->warningModel()); provider->init(m_errorPane->warningModel());
connect(m_errorPane, &ErrorWidget::mouseExited, this, [this]() { connect(m_errorPane, &ErrorWidget::mouseExited, this, [this] {
StateView *view = m_views.last(); StateView *view = m_views.last();
if (view) if (view)
view->scene()->unhighlightAll(); view->scene()->unhighlightAll();
@@ -264,12 +264,12 @@ void MainWidget::init()
m_actionHandler = new ActionHandler(this); m_actionHandler = new ActionHandler(this);
// Connect actions // Connect actions
connect(m_actionHandler->action(ActionZoomIn), &QAction::triggered, this, [this]() { connect(m_actionHandler->action(ActionZoomIn), &QAction::triggered, this, [this] {
StateView *view = m_views.last(); StateView *view = m_views.last();
if (view) if (view)
view->view()->zoomIn(); view->view()->zoomIn();
}); });
connect(m_actionHandler->action(ActionZoomOut), &QAction::triggered, this, [this]() { connect(m_actionHandler->action(ActionZoomOut), &QAction::triggered, this, [this] {
StateView *view = m_views.last(); StateView *view = m_views.last();
if (view) if (view)
view->view()->zoomOut(); view->view()->zoomOut();
@@ -282,49 +282,62 @@ void MainWidget::init()
}); });
connect(m_actionHandler->action(ActionMagnifier), &QAction::toggled, this, &MainWidget::setMagnifier); connect(m_actionHandler->action(ActionMagnifier), &QAction::toggled, this, &MainWidget::setMagnifier);
connect(m_navigator, &Navigator::hideFrame, this, [this]() { m_actionHandler->action(ActionNavigator)->setChecked(false); }); connect(m_navigator, &Navigator::hideFrame, this,
[this] { m_actionHandler->action(ActionNavigator)->setChecked(false); });
connect(m_actionHandler->action(ActionNavigator), &QAction::toggled, m_navigator, &Navigator::setVisible); connect(m_actionHandler->action(ActionNavigator), &QAction::toggled, m_navigator, &Navigator::setVisible);
connect(m_actionHandler->action(ActionCopy), &QAction::triggered, this, [this]() { connect(m_actionHandler->action(ActionCopy), &QAction::triggered, this, [this] {
StateView *view = m_views.last(); StateView *view = m_views.last();
if (view) if (view)
view->scene()->copy(); view->scene()->copy();
}); });
connect(m_actionHandler->action(ActionCut), &QAction::triggered, this, [this]() { connect(m_actionHandler->action(ActionCut), &QAction::triggered, this, [this] {
StateView *view = m_views.last(); StateView *view = m_views.last();
if (view) if (view)
view->scene()->cut(); view->scene()->cut();
}); });
connect(m_actionHandler->action(ActionPaste), &QAction::triggered, this, [this]() { connect(m_actionHandler->action(ActionPaste), &QAction::triggered, this, [this] {
StateView *view = m_views.last(); StateView *view = m_views.last();
if (view) if (view)
view->scene()->paste(view->view()->mapToScene(QPoint(30, 30))); view->scene()->paste(view->view()->mapToScene(QPoint(30, 30)));
}); });
connect(m_actionHandler->action(ActionExportToImage), &QAction::triggered, this, &MainWidget::exportToImage); connect(m_actionHandler->action(ActionExportToImage), &QAction::triggered,
connect(m_actionHandler->action(ActionScreenshot), &QAction::triggered, this, &MainWidget::saveScreenShot); this, &MainWidget::exportToImage);
connect(m_actionHandler->action(ActionScreenshot), &QAction::triggered,
this, &MainWidget::saveScreenShot);
connect(m_errorPane->warningModel(), &WarningModel::warningsChanged, this, [this]() { connect(m_errorPane->warningModel(), &WarningModel::warningsChanged, this, [this] {
m_actionHandler->action(ActionFullNamespace)->setEnabled(m_errorPane->warningModel()->count(Warning::ErrorType) <= 0); m_actionHandler->action(ActionFullNamespace)->setEnabled(
m_errorPane->warningModel()->count(Warning::ErrorType) <= 0);
}); });
connect(m_actionHandler->action(ActionFullNamespace), &QAction::triggered, this, [this](bool checked) { connect(m_actionHandler->action(ActionFullNamespace), &QAction::triggered, this, [this](bool checked) {
m_document->setUseFullNameSpace(checked); m_document->setUseFullNameSpace(checked);
}); });
connect(m_actionHandler->action(ActionAlignLeft), &QAction::triggered, this, [this]() { alignButtonClicked(ActionAlignLeft); }); connect(m_actionHandler->action(ActionAlignLeft), &QAction::triggered,
connect(m_actionHandler->action(ActionAlignRight), &QAction::triggered, this, [this]() { alignButtonClicked(ActionAlignRight); }); this, [this] { alignButtonClicked(ActionAlignLeft); });
connect(m_actionHandler->action(ActionAlignTop), &QAction::triggered, this, [this]() { alignButtonClicked(ActionAlignTop); }); connect(m_actionHandler->action(ActionAlignRight), &QAction::triggered,
connect(m_actionHandler->action(ActionAlignBottom), &QAction::triggered, this, [this]() { alignButtonClicked(ActionAlignBottom); }); this, [this] { alignButtonClicked(ActionAlignRight); });
connect(m_actionHandler->action(ActionAlignHorizontal), &QAction::triggered, this, [this]() { alignButtonClicked(ActionAlignHorizontal); }); connect(m_actionHandler->action(ActionAlignTop), &QAction::triggered,
connect(m_actionHandler->action(ActionAlignVertical), &QAction::triggered, this, [this]() { alignButtonClicked(ActionAlignVertical); }); this, [this] { alignButtonClicked(ActionAlignTop); });
connect(m_actionHandler->action(ActionAdjustWidth), &QAction::triggered, this, [this]() { adjustButtonClicked(ActionAdjustWidth); }); connect(m_actionHandler->action(ActionAlignBottom), &QAction::triggered,
connect(m_actionHandler->action(ActionAdjustHeight), &QAction::triggered, this, [this]() { adjustButtonClicked(ActionAdjustHeight); }); this, [this] { alignButtonClicked(ActionAlignBottom); });
connect(m_actionHandler->action(ActionAdjustSize), &QAction::triggered, this, [this]() { adjustButtonClicked(ActionAdjustSize); }); connect(m_actionHandler->action(ActionAlignHorizontal), &QAction::triggered,
this, [this] { alignButtonClicked(ActionAlignHorizontal); });
connect(m_actionHandler->action(ActionStatistics), &QAction::triggered, this, [this]() { connect(m_actionHandler->action(ActionAlignVertical), &QAction::triggered,
this, [this] { alignButtonClicked(ActionAlignVertical); });
connect(m_actionHandler->action(ActionAdjustWidth), &QAction::triggered,
this, [this] { adjustButtonClicked(ActionAdjustWidth); });
connect(m_actionHandler->action(ActionAdjustHeight), &QAction::triggered,
this, [this] { adjustButtonClicked(ActionAdjustHeight); });
connect(m_actionHandler->action(ActionAdjustSize), &QAction::triggered,
this, [this] { adjustButtonClicked(ActionAdjustSize); });
connect(m_actionHandler->action(ActionStatistics), &QAction::triggered,
this, [this] {
StatisticsDialog dialog; StatisticsDialog dialog;
dialog.setDocument(m_document); dialog.setDocument(m_document);
dialog.exec(); dialog.exec();
@@ -514,9 +527,10 @@ void MainWidget::addStateView(BaseItem *item)
connect(view->view(), &GraphicsView::panningChanged, m_actionHandler->action(ActionPan), &QAction::setChecked); connect(view->view(), &GraphicsView::panningChanged, m_actionHandler->action(ActionPan), &QAction::setChecked);
connect(view->view(), &GraphicsView::magnifierChanged, m_actionHandler->action(ActionMagnifier), &QAction::setChecked); connect(view->view(), &GraphicsView::magnifierChanged, m_actionHandler->action(ActionMagnifier), &QAction::setChecked);
connect(m_magnifier, &Magnifier::visibilityChanged, m_actionHandler->action(ActionMagnifier), &QAction::setChecked); connect(m_magnifier, &Magnifier::visibilityChanged, m_actionHandler->action(ActionMagnifier), &QAction::setChecked);
connect(view->scene(), &GraphicsScene::openStateView, this, &MainWidget::addStateView, Qt::QueuedConnection); GraphicsScene *scene = view->scene();
connect(view->scene(), &GraphicsScene::selectedStateCountChanged, this, [this](int count) { connect(scene, &GraphicsScene::openStateView, this, &MainWidget::addStateView, Qt::QueuedConnection);
bool currentView = sender() == m_views.last()->scene(); connect(scene, &GraphicsScene::selectedStateCountChanged, this, [this, scene](int count) {
bool currentView = scene == m_views.last()->scene();
// Enable/disable alignments // Enable/disable alignments
for (int i = ActionAlignLeft; i <= ActionAdjustSize; ++i) for (int i = ActionAlignLeft; i <= ActionAdjustSize; ++i)
@@ -526,13 +540,13 @@ void MainWidget::addStateView(BaseItem *item)
}); });
// Enable/disable color buttons // Enable/disable color buttons
connect(view->scene(), &GraphicsScene::selectedBaseItemCountChanged, this, [this](int count) { connect(scene, &GraphicsScene::selectedBaseItemCountChanged, this, [this](int count) {
m_toolButtons[ToolButtonStateColor]->setEnabled(count > 0); m_toolButtons[ToolButtonStateColor]->setEnabled(count > 0);
m_toolButtons[ToolButtonFontColor]->setEnabled(count > 0); m_toolButtons[ToolButtonFontColor]->setEnabled(count > 0);
}); });
connect(view->scene(), &GraphicsScene::pasteAvailable, this, [this](bool para) { connect(scene, &GraphicsScene::pasteAvailable, this, [this, scene](bool para) {
bool currentView = sender() == m_views.last()->scene(); bool currentView = scene == m_views.last()->scene();
m_actionHandler->action(ActionPaste)->setEnabled(currentView && para); m_actionHandler->action(ActionPaste)->setEnabled(currentView && para);
}); });

View File

@@ -54,7 +54,7 @@ PaneTitleButton::PaneTitleButton(OutputPane *pane, QWidget *parent)
stopAlert(); stopAlert();
}); });
connect(&animator, &QAbstractAnimation::finished, this, [this]() { connect(&animator, &QAbstractAnimation::finished, this, [this] {
m_animCounter++; m_animCounter++;
if (m_animCounter < 8) { if (m_animCounter < 8) {
if (m_animCounter % 2 == 1) if (m_animCounter % 2 == 1)
@@ -64,11 +64,11 @@ PaneTitleButton::PaneTitleButton(OutputPane *pane, QWidget *parent)
} }
}); });
connect(pane, &OutputPane::titleChanged, this, [=]() { connect(pane, &OutputPane::titleChanged, this, [=] {
setText(pane->title()); setText(pane->title());
}); });
connect(pane, &OutputPane::iconChanged, this, [=]() { connect(pane, &OutputPane::iconChanged, this, [=] {
setIcon(pane->icon()); setIcon(pane->icon());
}); });
} }
@@ -138,8 +138,10 @@ int OutputTabWidget::addPane(OutputPane *pane)
{ {
if (pane) { if (pane) {
auto button = new PaneTitleButton(pane, this); auto button = new PaneTitleButton(pane, this);
connect(button, &PaneTitleButton::clicked, this, &OutputTabWidget::buttonClicked); connect(button, &PaneTitleButton::clicked, this, [this, button](bool checked) {
connect(pane, &OutputPane::dataChanged, this, &OutputTabWidget::showAlert); buttonClicked(button, checked);
});
connect(pane, &OutputPane::dataChanged, this, [this, pane] { showAlert(pane); });
m_toolBar->addWidget(button); m_toolBar->addWidget(button);
m_stackedWidget->addWidget(pane); m_stackedWidget->addWidget(pane);
@@ -189,24 +191,26 @@ void OutputTabWidget::close()
emit visibilityChanged(false); emit visibilityChanged(false);
} }
void OutputTabWidget::showAlert() void OutputTabWidget::showAlert(OutputPane *pane)
{ {
int index = m_pages.indexOf(qobject_cast<OutputPane*>(sender())); const int index = m_pages.indexOf(pane);
if (index >= 0 && !m_buttons[index]->isChecked()) if (index >= 0 && !m_buttons[index]->isChecked())
m_buttons[index]->startAlert(m_pages[index]->alertColor()); m_buttons[index]->startAlert(m_pages[index]->alertColor());
} }
void OutputTabWidget::buttonClicked(bool para) void OutputTabWidget::buttonClicked(PaneTitleButton *button, bool checked)
{ {
int index = m_buttons.indexOf(qobject_cast<PaneTitleButton*>(sender())); const int index = m_buttons.indexOf(button);
if (index >= 0) { if (index < 0)
if (para) { return;
if (checked) {
for (int i = 0; i < m_buttons.count(); ++i) { for (int i = 0; i < m_buttons.count(); ++i) {
if (i != index) if (i != index)
m_buttons[i]->setChecked(false); m_buttons[i]->setChecked(false);
} }
showPane(index); showPane(index);
} else } else {
close(); close();
} }
} }

View File

@@ -87,8 +87,8 @@ signals:
private: private:
void createUi(); void createUi();
void close(); void close();
void buttonClicked(bool para); void buttonClicked(PaneTitleButton *button, bool checked);
void showAlert(); void showAlert(OutputPane *pane);
QVector<OutputPane *> m_pages; QVector<OutputPane *> m_pages;
QVector<PaneTitleButton *> m_buttons; QVector<PaneTitleButton *> m_buttons;