1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#ifndef QMLTCPROPERTYUTILS_H
5#define QMLTCPROPERTYUTILS_H
6
7#include <private/qqmljsmetatypes_p.h>
8#include <private/qqmljsscope_p.h>
9
10QT_BEGIN_NAMESPACE
11
12/*!
13 \internal
14
15 Returns an underlying C++ type of \a p property.
16*/
17inline QString getUnderlyingType(const QQmlJSMetaProperty &p)
18{
19 if (p.isList()) {
20 // We cannot just use p.type()->internalName() here because it may be
21 // a list property of something that only receives a C++ name from qmltc.
22 const QQmlJSScope::ConstPtr valueType = p.type()->valueType();
23 return (valueType->isReferenceType() ? u"QQmlListProperty<" : u"QList<")
24 + valueType->internalName() + u'>';
25 }
26
27 return p.type()->augmentedInternalName();
28}
29
30// simple class that, for a given property, creates information for the
31// Q_PROPERTY macro (READ/WRITE function names, etc.)
32struct QmltcPropertyData
33{
34 QmltcPropertyData(const QQmlJSMetaProperty &p) : QmltcPropertyData(p.propertyName()) { }
35
36 QmltcPropertyData(const QString &propertyName)
37 {
38 const QString nameWithUppercase = propertyName[0].toUpper() + propertyName.sliced(pos: 1);
39
40 read = propertyName;
41 write = u"set" + nameWithUppercase;
42 bindable = u"bindable" + nameWithUppercase;
43 notify = propertyName + u"Changed";
44 reset = u"reset" + nameWithUppercase;
45 }
46
47 QString read;
48 QString write;
49 QString bindable;
50 QString notify;
51 QString reset;
52};
53
54QT_END_NAMESPACE
55
56#endif // QMLTCPROPERTYUTILS_H
57

source code of qtdeclarative/tools/qmltc/qmltcpropertyutils.h