shell: use `std::find_if` in `ShellCorona::setContainmentTypeForScreen`

Consider using std::find_if algorithm instead of a raw loop. (CWE-398)
in shell/shellcorona.cpp:1614
wilder-5.26
Fushan Wen 4 years ago
parent 470dcc511b
commit c6b01d7f9e
No known key found for this signature in database
GPG Key ID: 2E48D1487C91DCAA
  1. 16
      shell/shellcorona.cpp

@ -1573,16 +1573,12 @@ Plasma::Containment *ShellCorona::setContainmentTypeForScreen(int screen, const
return oldContainment; return oldContainment;
} }
DesktopView *view = nullptr; auto viewIt = std::find_if(m_desktopViewForScreen.cbegin(), m_desktopViewForScreen.cend(), [oldContainment](const DesktopView *v) {
for (DesktopView *v : qAsConst(m_desktopViewForScreen)) { return v->containment() == oldContainment;
if (v->containment() == oldContainment) { });
view = v;
break;
}
}
// no view? give up // no view? give up
if (!view) { if (viewIt == m_desktopViewForScreen.cend()) {
return oldContainment; return oldContainment;
} }
@ -1641,14 +1637,14 @@ Plasma::Containment *ShellCorona::setContainmentTypeForScreen(int screen, const
if (removeAction) { if (removeAction) {
removeAction->deleteLater(); removeAction->deleteLater();
} }
view->setContainment(newContainment); (*viewIt)->setContainment(newContainment);
newContainment->setActivity(oldContainment->activity()); newContainment->setActivity(oldContainment->activity());
insertContainment(oldContainment->activity(), screen, newContainment); insertContainment(oldContainment->activity(), screen, newContainment);
// removing the focus from the item that is going to be destroyed // removing the focus from the item that is going to be destroyed
// fixes a crash // fixes a crash
// delayout the destruction of the old containment fixes another crash // delayout the destruction of the old containment fixes another crash
view->rootObject()->setFocus(true, Qt::MouseFocusReason); (*viewIt)->rootObject()->setFocus(true, Qt::MouseFocusReason);
QTimer::singleShot(2500, oldContainment, &Plasma::Applet::destroy); QTimer::singleShot(2500, oldContainment, &Plasma::Applet::destroy);
// Save now as we now have a screen, so lastScreen will not be -1 // Save now as we now have a screen, so lastScreen will not be -1

Loading…
Cancel
Save