From 405bd4299819e39397cea0090a9442fd4b6ce911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20De=20Canni=C3=A8re?= Date: Fri, 17 Mar 2023 15:42:47 +0100 Subject: Doc: Revamp "Extending QML" examples into a tutorial The examples in the "Extending QML" series were often redundant with the information of the "Writing QML Extensions with C++" tutorial, had outdated code and sometimes had no documentation. The examples that covered topics not mentioned in the first tutorial were revamped into a second "advanced" tutorial extending the first one. The others were removed. The remaining examples were largely based on the same example code of a birthday party. This code was slightly adapted and separated into 7 states, each building upon the previous, with the code change illustrating the associated feature. A tutorial page, in the style of the first one, was added documenting the different QML features and the required code changes in the example project. Links in the documentation from and to the affected pages were update as best as possible. Pick-to: 6.5 Fixes: QTBUG-111033 Change-Id: I9d97e8b32b128c1624d67525996fa14d493909d3 Reviewed-by: Qt CI Bot Reviewed-by: Fabian Kosmale Reviewed-by: Ulf Hermann --- .../advanced5-Attached-properties/person.cpp | 87 ++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.cpp (limited to 'examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.cpp') diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.cpp new file mode 100644 index 0000000000..fe3d19b58d --- /dev/null +++ b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.cpp @@ -0,0 +1,87 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include "person.h" + +Person::Person(QObject *parent) : QObject(parent) +{ + m_shoe = new ShoeDescription(this); +} + +int ShoeDescription::size() const +{ + return m_size; +} + +void ShoeDescription::setSize(int size) +{ + if (m_size != size) { + m_size = size; + emit shoeChanged(); + } +} + +QColor ShoeDescription::color() const +{ + return m_color; +} + +void ShoeDescription::setColor(const QColor &color) +{ + if (m_color != color) { + m_color = color; + emit shoeChanged(); + } +} + +QString ShoeDescription::brand() const +{ + return m_brand; +} + +void ShoeDescription::setBrand(const QString &brand) +{ + if (m_brand != brand) { + m_brand = brand; + emit shoeChanged(); + } +} + +qreal ShoeDescription::price() const +{ + return m_price; +} + +void ShoeDescription::setPrice(qreal price) +{ + if (m_price != price) { + m_price = price; + emit shoeChanged(); + } +} + +QString Person::name() const +{ + return m_name; +} + +void Person::setName(const QString &name) +{ + if (m_name != name) { + m_name = name; + emit nameChanged(); + } +} + +ShoeDescription *Person::shoe() const +{ + return m_shoe; +} + +void Person::setShoe(ShoeDescription *shoe) +{ + if (m_shoe != shoe) { + m_shoe = shoe; + emit shoeChanged(); + } +} -- cgit v1.2.1