Aspect: Don't try to change value more than once

When our window loses focus the editingFinished signal is triggered.
This can happen multiple times (QTBUG-121983) if the result of the edit
is a modal dialog and the user clicks outside our application.

This would call editingFinished again, resulting in multiple message
boxes being opened. (Easiest to reproduce is changing the build
directory of a project which displays a message box confirming the
change)

This patch checks, via a recursion Guard, that the slot is not already
in the process of being called.

Change-Id: I5e61e1b57680f0b1f2483a81682e791bfb5c0867
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2024-02-06 11:27:54 +01:00
parent 898190bd21
commit 5ae401b923

View File

@@ -7,6 +7,7 @@
#include "checkablemessagebox.h" #include "checkablemessagebox.h"
#include "environment.h" #include "environment.h"
#include "fancylineedit.h" #include "fancylineedit.h"
#include "guard.h"
#include "iconbutton.h" #include "iconbutton.h"
#include "layoutbuilder.h" #include "layoutbuilder.h"
#include "passworddialog.h" #include "passworddialog.h"
@@ -1181,13 +1182,12 @@ void StringAspect::addToLayout(LayoutItem &parent)
connect(lineEditDisplay, &FancyLineEdit::validChanged, this, &StringAspect::validChanged); connect(lineEditDisplay, &FancyLineEdit::validChanged, this, &StringAspect::validChanged);
bufferToGui(); bufferToGui();
if (isAutoApply() && d->m_autoApplyOnEditingFinished) { if (isAutoApply() && d->m_autoApplyOnEditingFinished) {
connect(lineEditDisplay, connect(lineEditDisplay, &FancyLineEdit::editingFinished, this, [this, lineEditDisplay] {
&FancyLineEdit::editingFinished, if (lineEditDisplay->text() != d->undoable.get()) {
this, d->undoable.set(undoStack(), lineEditDisplay->text());
[this, lineEditDisplay] { handleGuiChanged();
d->undoable.set(undoStack(), lineEditDisplay->text()); }
handleGuiChanged(); });
});
} else { } else {
connect(lineEditDisplay, &QLineEdit::textChanged, this, [this, lineEditDisplay] { connect(lineEditDisplay, &QLineEdit::textChanged, this, [this, lineEditDisplay] {
d->undoable.set(undoStack(), lineEditDisplay->text()); d->undoable.set(undoStack(), lineEditDisplay->text());
@@ -1386,6 +1386,8 @@ public:
bool m_autoApplyOnEditingFinished = false; bool m_autoApplyOnEditingFinished = false;
bool m_allowPathFromDevice = true; bool m_allowPathFromDevice = true;
bool m_validatePlaceHolder = false; bool m_validatePlaceHolder = false;
Guard m_editFinishedGuard;
}; };
FilePathAspect::FilePathAspect(AspectContainer *container) FilePathAspect::FilePathAspect(AspectContainer *container)
@@ -1559,8 +1561,12 @@ void FilePathAspect::addToLayout(Layouting::LayoutItem &parent)
connect(d->m_pathChooserDisplay, &PathChooser::validChanged, this, &FilePathAspect::validChanged); connect(d->m_pathChooserDisplay, &PathChooser::validChanged, this, &FilePathAspect::validChanged);
bufferToGui(); bufferToGui();
if (isAutoApply() && d->m_autoApplyOnEditingFinished) { if (isAutoApply() && d->m_autoApplyOnEditingFinished) {
connect(d->m_pathChooserDisplay, &PathChooser::editingFinished, connect(d->m_pathChooserDisplay, &PathChooser::editingFinished, this, [this] {
this, &FilePathAspect::handleGuiChanged); if (d->m_editFinishedGuard.isLocked())
return;
GuardLocker lk(d->m_editFinishedGuard);
handleGuiChanged();
});
connect(d->m_pathChooserDisplay, &PathChooser::browsingFinished, connect(d->m_pathChooserDisplay, &PathChooser::browsingFinished,
this, &FilePathAspect::handleGuiChanged); this, &FilePathAspect::handleGuiChanged);
} else { } else {