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 | #include <QtQml/private/qqmlsignalnames_p.h> |
10 | |
11 | QT_BEGIN_NAMESPACE |
12 | |
13 | /*! |
14 | \internal |
15 | |
16 | Returns an underlying C++ type of \a p property. |
17 | */ |
18 | inline QString getUnderlyingType(const QQmlJSMetaProperty &p) |
19 | { |
20 | if (p.isList()) { |
21 | // We cannot just use p.type()->internalName() here because it may be |
22 | // a list property of something that only receives a C++ name from qmltc. |
23 | const QQmlJSScope::ConstPtr valueType = p.type()->valueType(); |
24 | return (valueType->isReferenceType() ? u"QQmlListProperty<": u "QList<") |
25 | + valueType->internalName() + u'>'; |
26 | } |
27 | |
28 | return p.type()->augmentedInternalName(); |
29 | } |
30 | |
31 | // simple class that, for a given property, creates information for the |
32 | // Q_PROPERTY macro (READ/WRITE function names, etc.) |
33 | struct QmltcPropertyData |
34 | { |
35 | QmltcPropertyData(const QQmlJSMetaProperty &p) : QmltcPropertyData(p.propertyName()) { } |
36 | |
37 | QmltcPropertyData(const QString &propertyName) |
38 | { |
39 | read = propertyName; |
40 | write = QQmlSignalNames::addPrefixToPropertyName(prefix: u"set", propertyName); |
41 | bindable = QQmlSignalNames::addPrefixToPropertyName(prefix: u"bindable", propertyName); |
42 | notify = QQmlSignalNames::propertyNameToChangedSignalName(property: propertyName); |
43 | reset = QQmlSignalNames::addPrefixToPropertyName(prefix: u"reset", propertyName); |
44 | } |
45 | |
46 | QString read; |
47 | QString write; |
48 | QString bindable; |
49 | QString notify; |
50 | QString reset; |
51 | }; |
52 | |
53 | QT_END_NAMESPACE |
54 | |
55 | #endif // QMLTCPROPERTYUTILS_H |
56 |