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
qqmlbuiltinfunctions.cpp File Reference

(3f6036de68313e03adcde5fdb28bfb23063554eb)

#include "qqmlbuiltinfunctions_p.h"
#include <QtQml/qqmlcomponent.h>
#include <QtQml/qqmlfile.h>
#include <private/qqmlengine_p.h>
#include <private/qqmlcomponent_p.h>
#include <private/qqmlloggingcategory_p.h>
#include <private/qqmlstringconverters_p.h>
#include <private/qqmldelayedcallqueue_p.h>
#include <QFileInfo>
#include <private/qqmldebugconnector_p.h>
#include <private/qqmldebugserviceinterfaces_p.h>
#include <private/qqmlglobal_p.h>
#include <private/qqmlplatform_p.h>
#include <private/qv4engine_p.h>
#include <private/qv4functionobject_p.h>
#include <private/qv4include_p.h>
#include <private/qv4context_p.h>
#include <private/qv4stringobject_p.h>
#include <private/qv4dateobject_p.h>
#include <private/qv4mm_p.h>
#include <private/qv4jsonobject_p.h>
#include <private/qv4objectproto_p.h>
#include <private/qv4qobjectwrapper_p.h>
#include <private/qv4stackframe_p.h>
#include <QtCore/qstring.h>
#include <QtCore/qdatetime.h>
#include <QtCore/qcryptographichash.h>
#include <QtCore/qrect.h>
#include <QtCore/qsize.h>
#include <QtCore/qpoint.h>
#include <QtCore/qurl.h>
#include <QtCore/qfile.h>
#include <QtCore/qcoreapplication.h>
#include <QtCore/qloggingcategory.h>
#include <QDebug>
#include "moc_qqmlbuiltinfunctions_p.cpp"
+ Include dependency graph for qqmlbuiltinfunctions.cpp:

Go to the source code of this file.

Macros

#define THROW_TYPE_ERROR_WITH_MESSAGE(msg)
 

Enumerations

enum  ConsoleLogTypes { Log , Info , Warn , Error }
 

Functions

QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY (lcRootProperties, "qt.qml.rootObjectProperties")
 
 Q_LOGGING_CATEGORY (lcQml, "qml")
 
 Q_LOGGING_CATEGORY (lcJs, "js")
 
template<typename T >
void addParameters (QJSEngine *e, QJSValue &result, int i, T parameter)
 
template<>
void addParameters< double > (QJSEngine *, QJSValue &result, int i, double parameter)
 
template<typename T , typename ... Others>
void addParameters (QJSEngine *e, QJSValue &result, int i, T parameter, Others... others)
 
template<typename ... T>
static QVariant constructFromJSValue (QJSEngine *e, QMetaType type, T... parameters)
 
static QVariant colorVariantFromJSValue (const QJSValue &color, bool *ok)
 
static QTime dateTimeToTime (const QDateTime &dateTime)
 
static std::optional< QDatedateFromString (const QString &string, QV4::ExecutionEngine *engine)
 \qmlmethod string Qt::formatDate(datetime date, variant format, variant localeFormatOption)
 
static std::optional< QTimetimeFromString (const QString &string, QV4::ExecutionEngine *engine)
 \qmlmethod string Qt::formatTime(datetime time, variant format, variant localeFormatOption)
 
static std::optional< QDateTimedateTimeFromString (const QString &string, QV4::ExecutionEngine *engine)
 \qmlmethod string Qt::formatDateTime(datetime dateTime, variant format, variant localeFormatOption)
 
 DEFINE_OBJECT_VTABLE (QQmlBindingFunction)
 
static QString jsStack (QV4::ExecutionEngine *engine)
 
static QString serializeArray (Object *array, ExecutionEngine *v4, QSet< QV4::Heap::Object * > &alreadySeen)
 
static ReturnedValue writeToConsole (const FunctionObject *b, const Value *argv, int argc, ConsoleLogTypes logType, bool printStack=false)
 
 DEFINE_OBJECT_VTABLE (ConsoleObject)
 

Macro Definition Documentation

◆ THROW_TYPE_ERROR_WITH_MESSAGE

#define THROW_TYPE_ERROR_WITH_MESSAGE ( msg)
Value:
do { \
return scope.engine->throwTypeError(QString::fromUtf8(msg)); \
} while (false)
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:6018

Definition at line 57 of file qqmlbuiltinfunctions.cpp.

Enumeration Type Documentation

◆ ConsoleLogTypes

Enumerator
Log 
Info 
Warn 
Error 

Definition at line 1757 of file qqmlbuiltinfunctions.cpp.

Function Documentation

◆ addParameters() [1/2]

template<typename T >
void addParameters ( QJSEngine * e,
QJSValue & result,
int i,
T parameter )

Definition at line 492 of file qqmlbuiltinfunctions.cpp.

References i, and QJSEngine::toScriptValue().

Referenced by addParameters(), and constructFromJSValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addParameters() [2/2]

template<typename T , typename ... Others>
void addParameters ( QJSEngine * e,
QJSValue & result,
int i,
T parameter,
Others... others )

Definition at line 504 of file qqmlbuiltinfunctions.cpp.

References addParameters(), and i.

+ Here is the call graph for this function:

◆ addParameters< double >()

template<>
void addParameters< double > ( QJSEngine * ,
QJSValue & result,
int i,
double parameter )

Definition at line 498 of file qqmlbuiltinfunctions.cpp.

References i.

◆ colorVariantFromJSValue()

static QVariant colorVariantFromJSValue ( const QJSValue & color,
bool * ok )
static

Definition at line 626 of file qqmlbuiltinfunctions.cpp.

References QQmlStringConverters::colorFromString(), QVariant::fromValue(), and ok.

Referenced by QtObject::alpha(), QtObject::darker(), QtObject::lighter(), and QtObject::tint().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ constructFromJSValue()

template<typename ... T>
static QVariant constructFromJSValue ( QJSEngine * e,
QMetaType type,
T... parameters )
static

Definition at line 511 of file qqmlbuiltinfunctions.cpp.

References addParameters(), QQmlValueTypeProvider::createValueType(), QVariant::isValid(), QJSEngine::newArray(), and variant.

Referenced by QtObject::matrix4x4(), QtObject::quaternion(), QtObject::vector2d(), QtObject::vector3d(), and QtObject::vector4d().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dateFromString()

static std::optional< QDate > dateFromString ( const QString & string,
QV4::ExecutionEngine * engine )
static

\qmlmethod string Qt::formatDate(datetime date, variant format, variant localeFormatOption)

Returns a string representation of date, optionally formatted using format.

The date parameter may be a JavaScript Date object, a \l{date}{date} property, a QDate, or QDateTime value. The format and localeFormatOption parameter may be any of the possible format values as described for \l{QtQml::Qt::formatDateTime()}{Qt.formatDateTime()}.

If format is not specified, date is formatted using \l {QLocale::FormatType}{Locale.ShortFormat} using the default locale.

See also
Locale

Definition at line 783 of file qqmlbuiltinfunctions.cpp.

References arg, date, QDateTime::date(), dateTime, QV4::DateObject::dateTimeToDate(), engine, Qt::ISODate, QDate::isValid(), QDateTime::isValid(), qCWarning, QStringLiteral, QV4::DateObject::stringToDateTime(), and QJSEngine::throwError().

Referenced by QtObject::formatDate(), QtObject::formatDate(), and QQmlStringConverters::variantFromString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dateTimeFromString()

static std::optional< QDateTime > dateTimeFromString ( const QString & string,
QV4::ExecutionEngine * engine )
static

\qmlmethod string Qt::formatDateTime(datetime dateTime, variant format, variant localeFormatOption)

Returns a string representation of dateTime, optionally formatted using format and localeFormatOption.

The dateTime parameter may be a JavaScript Date object, a \l{date}{date} property, a QDate, QTime, or QDateTime value.

If format is not provided, dateTime is formatted using \l {QLocale::FormatType}{Locale.ShortFormat} using the default locale. Otherwise, format should be either:

\list

If format specifies a locale object, \dateTime is formatted with \l{QLocale::toString}. In this case, localeFormatOption can hold a value of type \l {QLocale::FormatType} to further tune the formatting. If none is provided, \l {QLocale::FormatType}{Locale.ShortFormat} is used.

If format specifies a format string, it should use the following expressions to specify the date:

\table
\header \li Expression \li Output
\row \li d \li the day as number without a leading zero (1 to 31)
\row \li dd \li the day as number with a leading zero (01 to 31)
\row \li ddd
        \li the abbreviated localized day name (e.g. 'Mon' to 'Sun').
        Uses QDate::shortDayName().
\row \li dddd
        \li the long localized day name (e.g. 'Monday' to 'Qt::Sunday').
        Uses QDate::longDayName().
\row \li M \li the month as number without a leading zero (1-12)
\row \li MM \li the month as number with a leading zero (01-12)
\row \li MMM
        \li the abbreviated localized month name (e.g. 'Jan' to 'Dec').
        Uses QDate::shortMonthName().
\row \li MMMM
        \li the long localized month name (e.g. 'January' to 'December').
        Uses QDate::longMonthName().
\row \li yy \li the year as two digit number (00-99)
\row \li yyyy \li the year as four digit number
\endtable

In addition the following expressions can be used to specify the time:

\table
\header \li Expression \li Output
\row \li h
     \li the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
\row \li hh
     \li the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
\row \li m \li the minute without a leading zero (0 to 59)
\row \li mm \li the minute with a leading zero (00 to 59)
\row \li s \li the second without a leading zero (0 to 59)
\row \li ss \li the second with a leading zero (00 to 59)
\row \li z \li the milliseconds without leading zeroes (0 to 999)
\row \li zzz \li the milliseconds with leading zeroes (000 to 999)
\row \li AP
        \li use AM/PM display. \e AP will be replaced by either "AM" or "PM".
\row \li ap
        \li use am/pm display. \e ap will be replaced by either "am" or "pm".
\row \li t
        \li include a time-zone indicator.
\endtable

All other input characters will be ignored. Any sequence of characters that
are enclosed in single quotes will be treated as text and not be used as an
expression. Two consecutive single quotes ("''") are replaced by a single quote
in the output.

For example, if the following date/time value was specified:

\code
// 21 May 2001 14:13:09
var dateTime = new Date(2001, 5, 21, 14, 13, 09)
\endcode

This dateTime value could be passed to Qt.formatDateTime(), \l {QtQml::Qt::formatDate()}{Qt.formatDate()} or \l {QtQml::Qt::formatTime()}{Qt.formatTime()} with the format values below to produce the following results:

\table
\header \li Format \li Result
\row \li "dd.MM.yyyy"      \li 21.05.2001
\row \li "ddd MMMM d yy"   \li Tue May 21 01
\row \li "hh:mm:ss.zzz"    \li 14:13:09.042
\row \li "h:m:s ap"        \li 2:13:9 pm
\endtable

\sa Locale

Definition at line 1076 of file qqmlbuiltinfunctions.cpp.

References arg, dateTime, engine, Qt::ISODate, QDateTime::isValid(), QStringLiteral, QV4::DateObject::stringToDateTime(), and QJSEngine::throwError().

Referenced by QtObject::formatDateTime(), QtObject::formatDateTime(), and QQmlStringConverters::variantFromString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dateTimeToTime()

static QTime dateTimeToTime ( const QDateTime & dateTime)
static

Definition at line 762 of file qqmlbuiltinfunctions.cpp.

References dateTime, QDateTime::time(), and QDateTime::toLocalTime().

Referenced by QtObject::formatTime(), QtObject::formatTime(), and timeFromString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DEFINE_OBJECT_VTABLE() [1/2]

DEFINE_OBJECT_VTABLE ( ConsoleObject )

◆ DEFINE_OBJECT_VTABLE() [2/2]

DEFINE_OBJECT_VTABLE ( QQmlBindingFunction )

◆ jsStack()

static QString jsStack ( QV4::ExecutionEngine * engine)
static

Definition at line 1764 of file qqmlbuiltinfunctions.cpp.

References engine, i, line, QString::number(), qAbs(), and QStringLiteral.

Referenced by QV4::ConsoleObject::method_assert(), QV4::ConsoleObject::method_trace(), and writeToConsole().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Q_LOGGING_CATEGORY() [1/3]

Q_LOGGING_CATEGORY ( lcJs ,
"js"  )

◆ Q_LOGGING_CATEGORY() [2/3]

Q_LOGGING_CATEGORY ( lcQml ,
"qml"  )

◆ Q_LOGGING_CATEGORY() [3/3]

QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY ( lcRootProperties ,
"qt.qml.rootObjectProperties"  )

◆ serializeArray()

static QString serializeArray ( Object * array,
ExecutionEngine * v4,
QSet< QV4::Heap::Object * > & alreadySeen )
static

Definition at line 1791 of file qqmlbuiltinfunctions.cpp.

References i, and serializeArray().

Referenced by serializeArray(), and writeToConsole().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ timeFromString()

static std::optional< QTime > timeFromString ( const QString & string,
QV4::ExecutionEngine * engine )
static

\qmlmethod string Qt::formatTime(datetime time, variant format, variant localeFormatOption)

Returns a string representation of time, optionally formatted using format, and, if provided, localeFormatOption.

The time parameter may be a JavaScript Date object, a QTime, or QDateTime value. The format and localeFormatOption parameter may be any of the possible format values as described for \l{QtQml::Qt::formatDateTime()}{Qt.formatDateTime()}.

If format is not specified, time is formatted using \l {QLocale::FormatType}{Locale.ShortFormat} using the default locale.

See also
Locale

Definition at line 888 of file qqmlbuiltinfunctions.cpp.

References arg, dateTime, dateTimeToTime(), engine, Qt::ISODate, QTime::isValid(), QDateTime::isValid(), qCWarning, QStringLiteral, QV4::DateObject::stringToDateTime(), QJSEngine::throwError(), time, and QDateTime::time().

Referenced by QtObject::formatTime(), QtObject::formatTime(), and QQmlStringConverters::variantFromString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeToConsole()

static ReturnedValue writeToConsole ( const FunctionObject * b,
const Value * argv,
int argc,
ConsoleLogTypes logType,
bool printStack = false )
static

Definition at line 1816 of file qqmlbuiltinfunctions.cpp.

References category(), QV4::EngineBase::currentStackFrame, QMessageLogger::debug(), QV4::Scope::engine, Error, frame, i, Info, jsStack(), Log, managed(), QByteArray(), QV4::ExecutionEngine::qmlEngine(), serializeArray(), THROW_GENERIC_ERROR, QV4::Encode::undefined(), Warn, and wrapper().

Referenced by QV4::ConsoleObject::method_error(), QV4::ConsoleObject::method_exception(), QV4::ConsoleObject::method_info(), QV4::ConsoleObject::method_log(), and QV4::ConsoleObject::method_warn().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: