aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMohammadHossein Qanbari <mohammad.qanbari@qt.io>2024-09-25 12:39:57 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2024-10-09 17:27:59 +0000
commitc043d6133e8a8a0227247acb613ad03741109415 (patch)
tree5dbb81e39283c86db99ad589dc8af642e8174219
parentbd2b935f59a2018988784b024f55c8460526a097 (diff)
QML Previewer Example: Prevent unnecessary state changes
Previously, when setting a new file address and pressing the close button, the focus would move to the quick widget due to QLineEdit::editingFinished() being called. This triggered an attempt to close the old file and open the new one, causing unintended state transitions. To resolve this, we now reload the file content and update the quick widget's source without transitioning to CloseState and OpenState. This is achieved by updating the file path and emitting stateChanged() from OpenState to OpenState in the StateController, notifying other widgets to reload their content. Change-Id: Ic623d320fe1736e11fd538a6735632b19c507394 Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io> Reviewed-by: Doris Verria <doris.verria@qt.io> (cherry picked from commit bd3ad6c71b2b8a6ae4aa8b23f82a06a652894622) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--examples/quick/quickwidgets/qmlpreviewer/states/statecontroller.cpp5
-rw-r--r--examples/quick/quickwidgets/qmlpreviewer/states/statecontroller.h10
-rw-r--r--examples/quick/quickwidgets/qmlpreviewer/widgets/editorwidget.cpp3
-rw-r--r--examples/quick/quickwidgets/qmlpreviewer/widgets/patheditwidget.cpp2
4 files changed, 12 insertions, 8 deletions
diff --git a/examples/quick/quickwidgets/qmlpreviewer/states/statecontroller.cpp b/examples/quick/quickwidgets/qmlpreviewer/states/statecontroller.cpp
index fdcaa56445..11e0ca4b94 100644
--- a/examples/quick/quickwidgets/qmlpreviewer/states/statecontroller.cpp
+++ b/examples/quick/quickwidgets/qmlpreviewer/states/statecontroller.cpp
@@ -66,6 +66,11 @@ void StateController::fileLoaded(const QString &filePath)
setCurrentState(OpenState);
break;
+ case OpenState:
+ setFilePath(filePath);
+ emit stateChanged(OpenState, OpenState);
+ break;
+
default:
break;
}
diff --git a/examples/quick/quickwidgets/qmlpreviewer/states/statecontroller.h b/examples/quick/quickwidgets/qmlpreviewer/states/statecontroller.h
index 7f5ef7e2e9..6001b3eba3 100644
--- a/examples/quick/quickwidgets/qmlpreviewer/states/statecontroller.h
+++ b/examples/quick/quickwidgets/qmlpreviewer/states/statecontroller.h
@@ -19,11 +19,11 @@ public:
// setDirty(true) *->|NewState *--* |
// | |_________*---* |
// | __________ | changesSaved() |
- // | | |<-* | fileClosed()
- // fileLoaded() *->| |-------------------*
- // |OpenState |<------------------*
- // | *-* |
- // |__________* | |
+ // fileLoaded() *->| |<-* | fileClosed()
+ // | |-------------------*
+ // *--*OpenState |<------------------*
+ // | | *-* |
+ // fileLoaded() *->|__________* | |
// | |
// | ___________ | changesSaved()
// | | | | or
diff --git a/examples/quick/quickwidgets/qmlpreviewer/widgets/editorwidget.cpp b/examples/quick/quickwidgets/qmlpreviewer/widgets/editorwidget.cpp
index 7ad9df7165..fe49b7dd81 100644
--- a/examples/quick/quickwidgets/qmlpreviewer/widgets/editorwidget.cpp
+++ b/examples/quick/quickwidgets/qmlpreviewer/widgets/editorwidget.cpp
@@ -224,9 +224,6 @@ void EditorWidget::onFileSelected(const QString &filePath)
case StateController::NewState:
stateController->changesSaved(filePath);
break;
- case StateController::OpenState:
- closeFile();
- break;
case StateController::DirtyState:
stateController->changesSaved(filePath);
closeFile();
diff --git a/examples/quick/quickwidgets/qmlpreviewer/widgets/patheditwidget.cpp b/examples/quick/quickwidgets/qmlpreviewer/widgets/patheditwidget.cpp
index 378e22acce..fac32c4b91 100644
--- a/examples/quick/quickwidgets/qmlpreviewer/widgets/patheditwidget.cpp
+++ b/examples/quick/quickwidgets/qmlpreviewer/widgets/patheditwidget.cpp
@@ -99,6 +99,8 @@ void PathEditWidget::onAppStateChanged(int oldState, int newState)
void PathEditWidget::validatePath()
{
const auto filePath = m_lineEdit->text();
+ if (filePath == StateController::instance()->filePath())
+ return;
QUrl url = QUrl::fromUserInput(filePath);
if (url.isValid())
emit fileSelected(filePath);