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
qqmlscriptstring.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qqmlscriptstring.h"
6
8
39{
40 return script.d.constData();
41}
42
50
56{
57 d->script = script;
58 d->context = context;
59 d->scope = scope;
60}
61
69
76
81{
82 d = other.d;
83 return *this;
84}
85
92{
93 if (d == other.d)
94 return true;
95 if (!d || !other.d)
96 return false;
97
98 if (d->isNumberLiteral || other.d->isNumberLiteral)
99 return d->isNumberLiteral && other.d->isNumberLiteral && d->numberValue == other.d->numberValue;
100
101 if (d->isStringLiteral || other.d->isStringLiteral)
102 return d->isStringLiteral && other.d->isStringLiteral && d->script == other.d->script;
103
104 if (d->script == QLatin1String("true") ||
105 d->script == QLatin1String("false") ||
106 d->script == QLatin1String("undefined") ||
107 d->script == QLatin1String("null"))
108 return d->script == other.d->script;
109
110 return d->context == other.d->context &&
111 d->scope == other.d->scope &&
112 d->script == other.d->script &&
113 d->bindingId == other.d->bindingId;
114}
115
122{
123 return !operator==(other);
124}
125
130{
131 if (!d)
132 return true;
133 if (!d->script.isEmpty())
134 return false;
135 return d->bindingId == -1;
136}
137
142{
143 return d && d->script == QLatin1String("undefined");
144}
145
150{
151 return d && d->script == QLatin1String("null");
152}
153
159{
160 if (d && d->isStringLiteral)
161 return d->script.mid(1, d->script.size()-2);
162 return QString();
163}
164
170{
171 if (ok)
172 *ok = d && d->isNumberLiteral;
173 return (d && d->isNumberLiteral) ? d->numberValue : 0.;
174}
175
181{
182 bool isTrue = d && d->script == QLatin1String("true");
183 bool isFalse = !isTrue && d && d->script == QLatin1String("false");
184 if (ok)
185 *ok = isTrue || isFalse;
186 return isTrue ? true : false;
187}
188
190
191#include "moc_qqmlscriptstring.cpp"
192
\inmodule QtCore
Definition qobject.h:103
The QQmlContext class defines a context within a QML engine.
Definition qqmlcontext.h:25
static const QQmlScriptStringPrivate * get(const QQmlScriptString &script)
The QQmlScriptString class encapsulates a script and its context.
qreal numberLiteral(bool *ok) const
If the content of the QQmlScriptString is a number literal, returns that number and sets ok to true.
QQmlScriptString()
Constructs an empty instance.
QString stringLiteral() const
If the content of the QQmlScriptString is a string literal, returns that string.
bool isNullLiteral() const
Returns whether the content of the QQmlScriptString is the null literal.
bool operator!=(const QQmlScriptString &) const
Returns true if this and the other QQmlScriptString objects are different.
bool isUndefinedLiteral() const
Returns whether the content of the QQmlScriptString is the undefined literal.
bool operator==(const QQmlScriptString &) const
Returns true if this and the other QQmlScriptString objects are equal.
bool booleanLiteral(bool *ok) const
If the content of the QQmlScriptString is a boolean literal, returns the boolean value and sets ok to...
bool isEmpty() const
Returns whether the QQmlScriptString is empty.
QQmlScriptString & operator=(const QQmlScriptString &)
Assigns other to this.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QString mid(qsizetype position, qsizetype n=-1) const &
Definition qstring.cpp:5300
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
qsizetype size() const noexcept
Returns the number of characters in this string.
Definition qstring.h:186
Combined button and popup list for selecting options.
static void * context
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
double qreal
Definition qtypes.h:187
QSharedPointer< T > other(t)
[5]