diff options
author | Olivier De Cannière <olivier.decanniere@qt.io> | 2023-03-17 15:42:47 +0100 |
---|---|---|
committer | Olivier De Cannière <olivier.decanniere@qt.io> | 2023-03-30 18:02:16 +0200 |
commit | 405bd4299819e39397cea0090a9442fd4b6ce911 (patch) | |
tree | c1254e18a8ab47cc6bde048eb52ad0d89c2492c8 /examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.cpp | |
parent | 03ff348b4942ae29dd5bc2bd563998d7ba82ecd7 (diff) | |
download | qtdeclarative-405bd4299819e39397cea0090a9442fd4b6ce911.tar.gz |
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 <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.cpp')
-rw-r--r-- | examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
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(); + } +} |