aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/doc/snippets
diff options
context:
space:
mode:
authorTopi Reinio <topi.reinio@qt.io>2020-12-07 16:56:05 +0100
committerTopi Reinio <topi.reinio@qt.io>2020-12-08 11:35:06 +0100
commited6f55ca126c80514e886b3b400a22ba5d443589 (patch)
tree22c2b46f4fa33ed2be61435280ca85779aaa931a /src/qml/doc/snippets
parentc3860cd04bbc089ef95bc441a1f8f1e46f9606f8 (diff)
Doc: Fix occurrences of \Q_OBJECT in code snippets
'Q_OBJECT', even in a comment, interferes with automoc. Prefixing it with a backslash solves the automoc issue, but documentation looks wrong as content inside \code is taken verbatim. Move code snippets to doc/snippets and refer to them with \snippet commands. Pick-to: 6.0 Change-Id: Ied7fdf87ef5edd2b237498b91b162c19bf7bc636 Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Diffstat (limited to 'src/qml/doc/snippets')
-rw-r--r--src/qml/doc/snippets/code/src_qml_qqmlengine.cpp91
-rw-r--r--src/qml/doc/snippets/code/src_qml_qqmllist.cpp94
-rw-r--r--src/qml/doc/snippets/code/src_qml_qqmlparserstatus.cpp63
3 files changed, 248 insertions, 0 deletions
diff --git a/src/qml/doc/snippets/code/src_qml_qqmlengine.cpp b/src/qml/doc/snippets/code/src_qml_qqmlengine.cpp
new file mode 100644
index 0000000000..228275e120
--- /dev/null
+++ b/src/qml/doc/snippets/code/src_qml_qqmlengine.cpp
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+class MySingleton : public QObject {
+ Q_OBJECT
+
+ // Register as default constructed singleton.
+ QML_ELEMENT
+ QML_SINGLETON
+
+ static int typeId;
+ // ...
+};
+//! [0]
+
+/*
+//! [1]
+ MySingleton::typeId = qmlTypeId(...);
+//! [1]
+*/
+
+void wrapper2() {
+//! [2]
+ // Retrieve as QObject*
+ QQmlEngine engine;
+ MySingleton* instance = engine.singletonInstance<MySingleton*>(MySingleton::typeId);
+//! [2]
+}
+
+/*
+//! [3]
+ // Register with QJSValue callback
+ int typeId = qmlRegisterSingletonType(...);
+//! [3]
+*/
+
+void wrapper4(int typeId) {
+//! [4]
+ // Retrieve as QJSValue
+ QQmlEngine engine;
+ QJSValue instance = engine.singletonInstance<QJSValue>(typeId);
+//! [4]
+}
diff --git a/src/qml/doc/snippets/code/src_qml_qqmllist.cpp b/src/qml/doc/snippets/code/src_qml_qqmllist.cpp
new file mode 100644
index 0000000000..7fd6664dd7
--- /dev/null
+++ b/src/qml/doc/snippets/code/src_qml_qqmllist.cpp
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+namespace DocWrapper0 {
+//! [0]
+class FruitBasket : QObject {
+ Q_OBJECT
+ QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_APPEND
+ Q_PROPERTY(QQmlListProperty<Fruit> fruit READ fruit)
+
+ public:
+ // ...
+ QQmlListProperty<Fruit> fruit();
+ // ...
+};
+//! [0]
+}
+
+namespace DocWrapper1 {
+//! [1]
+class FruitBasket : QObject {
+ Q_OBJECT
+ QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_REPLACE_IF_NOT_DEFAULT
+ Q_PROPERTY(QQmlListProperty<Fruit> fruit READ fruit)
+
+ public:
+ // ...
+ QQmlListProperty<Fruit> fruit();
+ // ...
+};
+//! [1]
+}
+
+namespace DocWrapper2 {
+//! [2]
+class FruitBasket : QObject {
+ Q_OBJECT
+ QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_REPLACE
+ Q_PROPERTY(QQmlListProperty<Fruit> fruit READ fruit)
+
+ public:
+ // ...
+ QQmlListProperty<Fruit> fruit();
+ // ...
+};
+//! [2]
+}
diff --git a/src/qml/doc/snippets/code/src_qml_qqmlparserstatus.cpp b/src/qml/doc/snippets/code/src_qml_qqmlparserstatus.cpp
new file mode 100644
index 0000000000..259ea15b3f
--- /dev/null
+++ b/src/qml/doc/snippets/code/src_qml_qqmlparserstatus.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+class MyObject : public QObject, public QQmlParserStatus
+{
+ Q_OBJECT
+ Q_INTERFACES(QQmlParserStatus)
+
+public:
+ MyObject(QObject *parent = 0);
+ // ...
+ void classBegin();
+ void componentComplete();
+};
+//! [0]