aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quick/quickwidgets/qmlpreviewer
diff options
context:
space:
mode:
authorMohammadHossein Qanbari <mohammad.qanbari@qt.io>2024-09-25 12:39:57 +0200
committerMohammadHossein Qanbari <mohammad.qanbari@qt.io>2024-10-09 16:23:15 +0200
commitbd3ad6c71b2b8a6ae4aa8b23f82a06a652894622 (patch)
tree8d4656036ae6398f8c0cea2f78188874640ac6a2 /examples/quick/quickwidgets/qmlpreviewer
parentf6b89932a1d597fc561178396e92abfadbb3517e (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. Pick-to: 6.8 Change-Id: Ic623d320fe1736e11fd538a6735632b19c507394 Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io> Reviewed-by: Doris Verria <doris.verria@qt.io>
Diffstat (limited to 'examples/quick/quickwidgets/qmlpreviewer')
-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);