aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/doc/snippets/qml/textEditStatusSwitch.qml
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2024-01-22 18:52:47 -0700
committerShawn Rutledge <shawn.rutledge@qt.io>2024-01-23 12:34:26 -0700
commit5647b6900b2ecc291022143176b545b933eca3a8 (patch)
treec49bc648f00b63541a0a89a0141ff9b803f16147 /src/quick/doc/snippets/qml/textEditStatusSwitch.qml
parentba0816773308d3733cad0ac4a873d792a605f7ff (diff)
Replace TextEdit.textDocument.error signal with status property
If we make loading and saving asynchronous later, we'll need the same sort of status property as in Image, Loader etc. to let the user QML know when it's done, or when it has failed. Bindings are more flexible than signal handlers; so we might as well have better-prepared API now. To make use of the Status enum in QML, we need to de-anonymize TextDocument and make it merely uncreatable. Anyway, it was already referred to as the TextDocument type in the docs. Pick-to: 6.7 Change-Id: Ia4354feba77995759797030382891308b941f0af Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Diffstat (limited to 'src/quick/doc/snippets/qml/textEditStatusSwitch.qml')
-rw-r--r--src/quick/doc/snippets/qml/textEditStatusSwitch.qml34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/quick/doc/snippets/qml/textEditStatusSwitch.qml b/src/quick/doc/snippets/qml/textEditStatusSwitch.qml
new file mode 100644
index 0000000000..d87e68f6cd
--- /dev/null
+++ b/src/quick/doc/snippets/qml/textEditStatusSwitch.qml
@@ -0,0 +1,34 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+import QtQuick
+
+//! [0]
+TextEdit {
+ id: edit
+ width: 300
+ height: 200
+ textDocument.source: "example.md"
+ wrapMode: TextEdit.WordWrap
+
+ Text {
+ anchors {
+ bottom: parent.bottom
+ right: parent.right
+ }
+ color: edit.textDocument.status === TextDocument.Loaded ? "darkolivegreen" : "tomato"
+ text:
+ switch (edit.textDocument.status) {
+ case TextDocument.Loading:
+ return qsTr("Loading ") + edit.textDocument.source
+ case TextDocument.Loaded:
+ return qsTr("Loaded ") + edit.textDocument.source
+ case TextDocument.ReadError:
+ return qsTr("Failed to load ") + edit.textDocument.source
+ case TextDocument.NonLocalFileError:
+ return qsTr("Not a local file: ") + edit.textDocument.source
+ default:
+ return "Unexpected status " + edit.textDocument.status + ": " + edit.textDocument.source
+ }
+ }
+}
+//! [0]