diff options
author | Topi Reinio <topi.reinio@qt.io> | 2020-12-07 16:56:05 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2020-12-08 12:44:11 +0000 |
commit | ba8051b7e716c34db96db6c68f03ef928760e1fb (patch) | |
tree | cba78329e88f4827cc0a237854c7b6a99ae2a2da /src | |
parent | a83f8065be447674f1af3b69d0293c5db87ac79c (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.
Change-Id: Ied7fdf87ef5edd2b237498b91b162c19bf7bc636
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
(cherry picked from commit ed6f55ca126c80514e886b3b400a22ba5d443589)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/doc/snippets/code/src_qml_qqmlengine.cpp | 91 | ||||
-rw-r--r-- | src/qml/doc/snippets/code/src_qml_qqmllist.cpp | 94 | ||||
-rw-r--r-- | src/qml/doc/snippets/code/src_qml_qqmlparserstatus.cpp | 63 | ||||
-rw-r--r-- | src/qml/qml/qqmlengine.cpp | 32 | ||||
-rw-r--r-- | src/qml/qml/qqmllist.cpp | 39 | ||||
-rw-r--r-- | src/qml/qml/qqmlparserstatus.cpp | 14 |
6 files changed, 260 insertions, 73 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] diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index 0b6b456473..0208b99621 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -1368,34 +1368,18 @@ void QQmlEngine::captureProperty(QObject *object, const QMetaProperty &property) type, either a default constructed QJSValue or a \c nullptr is returned. QObject* example: - \code - class MySingleton : public QObject { - \Q_OBJECT - - // Register as default constructed singleton. - QML_ELEMENT - QML_SINGLETON - - static int typeId; - // ... - }; - MySingleton::typeId = qmlTypeId(...); - - // Retrieve as QObject* - QQmlEngine engine; - MySingleton* instance = engine.singletonInstance<MySingleton*>(MySingleton::typeId); - \endcode + \snippet code/src_qml_qqmlengine.cpp 0 + \codeline + \snippet code/src_qml_qqmlengine.cpp 1 + \codeline + \snippet code/src_qml_qqmlengine.cpp 2 QJSValue example: - \code - // Register with QJSValue callback - int typeId = qmlRegisterSingletonType(...); - // Retrieve as QJSValue - QQmlEngine engine; - QJSValue instance = engine.singletonInstance<QJSValue>(typeId); - \endcode + \snippet code/src_qml_qqmlengine.cpp 3 + \codeline + \snippet code/src_qml_qqmlengine.cpp 4 It is recommended to store the QML type id, e.g. as a static member in the singleton class. The lookup via qmlTypeId() is costly. diff --git a/src/qml/qml/qqmllist.cpp b/src/qml/qml/qqmllist.cpp index 51499f816d..a3380a6c22 100644 --- a/src/qml/qml/qqmllist.cpp +++ b/src/qml/qml/qqmllist.cpp @@ -436,18 +436,7 @@ QML list properties are type-safe - in this case \c {Fruit} is a QObject type th When assigning the property in a derived type, the values are appended to those of the base class. This is the default behavior. - \code - class FruitBasket : QObject { - \Q_OBJECT - QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_APPEND - Q_PROPERTY(QQmlListProperty<Fruit> fruit READ fruit) - - public: - // ... - QQmlListProperty<Fruit> fruit(); - // ... - }; - \endcode + \snippet code/src_qml_qqmllist.cpp 0 \sa QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_REPLACE_IF_NOT_DEFAULT \sa QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_REPLACE @@ -463,18 +452,7 @@ QML list properties are type-safe - in this case \c {Fruit} is a QObject type th the base class unless it's the default property. In the case of the default property, values are appended to those of the base class. - \code - 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(); - // ... - }; - \endcode + \snippet code/src_qml_qqmllist.cpp 1 \sa QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_APPEND \sa QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_REPLACE @@ -488,18 +466,7 @@ QML list properties are type-safe - in this case \c {Fruit} is a QObject type th When assigning the property in a derived type, the values replace those of the base class. - \code - class FruitBasket : QObject { - \Q_OBJECT - QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_REPLACE - Q_PROPERTY(QQmlListProperty<Fruit> fruit READ fruit) - - public: - // ... - QQmlListProperty<Fruit> fruit(); - // ... - }; - \endcode + \snippet code/src_qml_qqmllist.cpp 2 \sa QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_APPEND \sa QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_REPLACE_IF_NOT_DEFAULT diff --git a/src/qml/qml/qqmlparserstatus.cpp b/src/qml/qml/qqmlparserstatus.cpp index cd45e6668b..d2aa679a95 100644 --- a/src/qml/qml/qqmlparserstatus.cpp +++ b/src/qml/qml/qqmlparserstatus.cpp @@ -68,19 +68,7 @@ QT_BEGIN_NAMESPACE To use QQmlParserStatus, you must inherit both a QObject-derived class and QQmlParserStatus, and use the Q_INTERFACES() macro. - \code - class MyObject : public QObject, public QQmlParserStatus - { - \Q_OBJECT - Q_INTERFACES(QQmlParserStatus) - - public: - MyObject(QObject *parent = 0); - ... - void classBegin(); - void componentComplete(); - } - \endcode + \snippet code/src_qml_qqmlparserstatus.cpp 0 */ /*! \internal */ |