aboutsummaryrefslogtreecommitdiffstats
path: root/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/person.cpp
blob: 53cec6b19267f5e812286ce330f0c64673407398 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// 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();
    }
}

bool ShoeDescription::operatorEqualsImpl(const ShoeDescription &lhs, const ShoeDescription &rhs)
{
    return lhs.m_size == rhs.m_size && lhs.m_color == rhs.m_color && lhs.m_brand == rhs.m_brand
            && lhs.m_price == rhs.m_price;
}

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 (!shoe)
        return;

    if (*m_shoe != *shoe) {
        m_shoe = shoe;
        emit shoeChanged();
    }
}