Use a RAII class to emit floatingChanging()

Otherwise during reparenting the signal can be emitted by mistake.
Now we only check at the end if we need to emit it.
This commit is contained in:
Sergio Martins
2022-05-26 09:29:37 +01:00
parent a85c56a25a
commit 042cabbe5d
3 changed files with 28 additions and 0 deletions

View File

@@ -680,6 +680,9 @@ void DockWidget::Private::updateToggleAction()
void DockWidget::Private::updateFloatAction()
{
if (m_willUpdateActions)
return;
QScopedValueRollback<bool> recursionGuard(m_updatingFloatAction, true); // Guard against recursiveness
if (q->isFloating()) {

View File

@@ -36,6 +36,27 @@ class SideBar;
class DOCKS_EXPORT_FOR_UNIT_TESTS DockWidget::Private : public QObject /// clazy:exclude=missing-qobject-macro
{
public:
/// RAII class to help updating actions exactly once, otherwise they can be triggered in the middle
/// of operations during reparenting
struct UpdateActions
{
explicit UpdateActions(Controllers::DockWidget *dw)
: dw(dw)
{
dw->d->m_willUpdateActions = true;
}
~UpdateActions()
{
dw->d->m_willUpdateActions = false;
dw->d->updateFloatAction();
}
private:
Q_DISABLE_COPY(UpdateActions)
Controllers::DockWidget *const dw;
};
Private(const QString &dockName, DockWidget::Options options_,
LayoutSaverOptions layoutSaverOptions_, DockWidget *qq);
@@ -175,7 +196,9 @@ public:
bool m_isMovingToSideBar = false;
QSize m_lastOverlayedSize = QSize(0, 0);
int m_userType = 0;
bool m_willUpdateActions = false;
};
}
}

View File

@@ -169,6 +169,8 @@ void DropArea::addDockWidget(Controllers::DockWidget *dw, Location location,
if (!validateAffinity(dw))
return;
Controllers::DockWidget::Private::UpdateActions actionsUpdater(dw);
Controllers::Frame *frame = nullptr;
Controllers::Frame *relativeToFrame = relativeTo ? relativeTo->d->frame() : nullptr;