Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qqmljsmetatypes.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#include "qqmljsmetatypes_p.h"
6
7#include "QtQml/private/qqmltranslation_p.h"
8
10
17{
18 return !m_propertyName.isEmpty() && bindingType() != QQmlSA::BindingType::Invalid;
19}
20
22{
23 if (auto boolLit = std::get_if<Content::BoolLiteral>(&m_bindingContent))
24 return boolLit->value;
25 // warn
26 return false;
27}
28
30{
31 if (auto numberLit = std::get_if<Content::NumberLiteral>(&m_bindingContent))
32 return numberLit->value;
33 // warn
34 return 0;
35}
36
38{
39 if (auto stringLiteral = std::get_if<Content::StringLiteral>(&m_bindingContent))
40 return stringLiteral->value;
41 // warn
42 return {};
43}
44
46{
47 if (auto regexpLiteral = std::get_if<Content::RegexpLiteral>(&m_bindingContent))
48 return regexpLiteral->value;
49 // warn
50 return {};
51}
52
61{
63 if (auto translation = std::get_if<Content::TranslationById>(&m_bindingContent)) {
64 data = QQmlTranslation::QsTrIdData(translation->id, translation->number);
65 } else if (auto translation = std::get_if<Content::TranslationString>(&m_bindingContent)) {
66 const QString context = translation->context.isEmpty()
67 ? QQmlTranslation::contextFromQmlFilename(qmlFileNameForContext)
68 : translation->context;
69 data = QQmlTranslation::QsTrData(context, translation->text, translation->comment,
70 translation->number);
71 }
72 return QQmlTranslation(data);
73}
74
80QSharedPointer<const QQmlJSScope> QQmlJSMetaPropertyBinding::literalType(const QQmlJSTypeResolver *resolver) const
81{
82 Q_ASSERT(resolver);
83 switch (bindingType()) {
84 case BindingType::BoolLiteral:
85 return resolver->boolType();
86 case BindingType::NumberLiteral:
87 return resolver->typeForName(QLatin1String("double"));
88 case BindingType::Translation: // translations are strings
89 case BindingType::TranslationById:
90 case BindingType::StringLiteral:
91 return resolver->stringType();
92 case BindingType::RegExpLiteral:
93 return resolver->typeForName(QLatin1String("regexp"));
94 case BindingType::Null:
95 return resolver->nullType();
96 case BindingType::Invalid:
97 case BindingType::Script:
98 case BindingType::Object:
99 case BindingType::Interceptor:
100 case BindingType::ValueSource:
101 case BindingType::AttachedProperty:
102 case BindingType::GroupProperty:
103 return {};
104 }
105 Q_UNREACHABLE_RETURN({});
106}
107
109
QSharedPointer< const QQmlJSScope > literalType(const QQmlJSTypeResolver *resolver) const
BindingType bindingType() const
QQmlTranslation translationDataValue(QString qmlFileNameForContext=QStringLiteral("")) const
Extracts the information about translations from a binding.
QQmlJSScope::ConstPtr stringType() const
QQmlJSScope::ConstPtr nullType() const
QQmlJSScope::ConstPtr boolType() const
QQmlJSScope::ConstPtr typeForName(const QString &name) const
static QString contextFromQmlFilename(const QString &qmlFilename)
std::variant< std::nullptr_t, QsTrData, QsTrIdData > Data
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
Combined button and popup list for selecting options.
static void * context
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QLatin1StringView QLatin1String
Definition qstringfwd.h:31