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
qquickglobal.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2016 BasysKom GmbH.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#include <QtQuick/private/qquickvaluetypes_p.h>
6#include <QtQuick/private/qquickapplication_p.h>
7#include <QtQuick/private/qquickstate_p.h>
8#include <QtQuick/private/qquickpropertychanges_p.h>
9#include <QtQuick/private/qquickitemsmodule_p.h>
10#if QT_CONFIG(accessibility)
11# include <QtQuick/private/qquickaccessiblefactory_p.h>
12#endif
13#include <QtGui/QGuiApplication>
14#include <QtGui/qdesktopservices.h>
15#include <QtGui/qfontdatabase.h>
16#include <QtGui/qstylehints.h>
17
18#include <QtQml/private/qqmlbinding_p.h>
19#include <QtQml/private/qqmldebugserviceinterfaces_p.h>
20#include <QtQml/private/qqmldebugstatesdelegate_p.h>
21#include <QtQml/private/qqmlglobal_p.h>
22#include <QtQml/private/qv4engine_p.h>
23#include <QtQml/private/qv4object_p.h>
24#include <QtQml/private/qqmlanybinding_p.h>
25
26#include <QtCore/qiterable.h>
27#include <QtCore/qpointer.h>
28
29#ifdef Q_CC_MSVC
30// MSVC2010 warns about 'unused variable t', even if it's used in t->~T()
31# pragma warning( disable : 4189 )
32#endif
33
35
36#if QT_CONFIG(qml_debug)
37
38class QQmlQtQuick2DebugStatesDelegate : public QQmlDebugStatesDelegate
39{
40public:
41 QQmlQtQuick2DebugStatesDelegate();
42 ~QQmlQtQuick2DebugStatesDelegate();
43 void buildStatesList(bool cleanList, const QList<QPointer<QObject> > &instances) override;
44 void updateBinding(QQmlContext *context,
46 const QVariant &expression, bool isLiteralValue,
47 const QString &fileName, int line, int column,
48 bool *isBaseState) override;
49 bool setBindingForInvalidProperty(QObject *object,
50 const QString &propertyName,
51 const QVariant &expression,
52 bool isLiteralValue) override;
53 void resetBindingForInvalidProperty(QObject *object,
54 const QString &propertyName) override;
55
56private:
57 void buildStatesList(QObject *obj);
58
59 QList<QPointer<QQuickState> > m_allStates;
60};
61
62QQmlQtQuick2DebugStatesDelegate::QQmlQtQuick2DebugStatesDelegate()
63{
64}
65
66QQmlQtQuick2DebugStatesDelegate::~QQmlQtQuick2DebugStatesDelegate()
67{
68}
69
70void QQmlQtQuick2DebugStatesDelegate::buildStatesList(bool cleanList,
71 const QList<QPointer<QObject> > &instances)
72{
73 if (cleanList)
74 m_allStates.clear();
75
76 //only root context has all instances
77 for (int ii = 0; ii < instances.size(); ++ii) {
78 buildStatesList(instances.at(ii));
79 }
80}
81
82void QQmlQtQuick2DebugStatesDelegate::buildStatesList(QObject *obj)
83{
84 if (QQuickState *state = qobject_cast<QQuickState *>(obj)) {
85 m_allStates.append(state);
86 }
87
88 QObjectList children = obj->children();
89 for (int ii = 0; ii < children.size(); ++ii) {
90 buildStatesList(children.at(ii));
91 }
92}
93
94void QQmlQtQuick2DebugStatesDelegate::updateBinding(QQmlContext *context,
96 const QVariant &expression, bool isLiteralValue,
97 const QString &fileName, int line, int column,
98 bool *inBaseState)
99{
101 typedef QPointer<QQuickState> QuickStatePointer;
102 QObject *object = property.object();
103 QString propertyName = property.name();
104 for (const QuickStatePointer& statePointer : std::as_const(m_allStates)) {
105 if (QQuickState *state = statePointer.data()) {
106 // here we assume that the revert list on itself defines the base state
107 if (state->isStateActive() && state->containsPropertyInRevertList(object, propertyName)) {
108 *inBaseState = false;
109
110 QQmlAnyBinding newBinding;
111 if (!isLiteralValue) {
113 expression.toString(), object,
115 line);
116 }
117 state->changeBindingInRevertList(object, propertyName, newBinding);
118
119 if (isLiteralValue)
120 state->changeValueInRevertList(object, propertyName, expression);
121 }
122 }
123 }
124}
125
126bool QQmlQtQuick2DebugStatesDelegate::setBindingForInvalidProperty(QObject *object,
127 const QString &propertyName,
128 const QVariant &expression,
129 bool isLiteralValue)
130{
131 if (QQuickPropertyChanges *propertyChanges = qobject_cast<QQuickPropertyChanges *>(object)) {
132 if (isLiteralValue)
133 propertyChanges->changeValue(propertyName, expression);
134 else
135 propertyChanges->changeExpression(propertyName, expression.toString());
136 return true;
137 } else {
138 return false;
139 }
140}
141
142void QQmlQtQuick2DebugStatesDelegate::resetBindingForInvalidProperty(QObject *object, const QString &propertyName)
143{
144 if (QQuickPropertyChanges *propertyChanges = qobject_cast<QQuickPropertyChanges *>(object)) {
145 propertyChanges->removeProperty(propertyName);
146 }
147}
148
150{
151 return new QQmlQtQuick2DebugStatesDelegate;
152}
153
154#endif // QT_CONFIG(qml_debug)
155
157{
158public:
159 QVariant colorFromString(const QString &s, bool *ok) override
160 {
162 if (c.isValid()) {
163 if (ok) *ok = true;
164 return QVariant(c);
165 }
166
167 if (ok) *ok = false;
168 return QVariant();
169 }
170
171 unsigned rgbaFromString(const QString &s, bool *ok) override
172 {
174 if (c.isValid()) {
175 if (ok) *ok = true;
176 return c.rgba();
177 }
178
179 if (ok) *ok = false;
180 return 0;
181 }
182
183 QString stringFromRgba(unsigned rgba)
184 {
186 if (c.isValid()) {
187 return QVariant(c).toString();
188 }
189
190 return QString();
191 }
192
193 QVariant fromRgbF(double r, double g, double b, double a) override
194 {
195 return QVariant(QColor::fromRgbF(r, g, b, a));
196 }
197
198 QVariant fromHslF(double h, double s, double l, double a) override
199 {
200 return QVariant(QColor::fromHslF(h, s, l, a));
201 }
202
203 QVariant fromHsvF(double h, double s, double v, double a) override
204 {
205 return QVariant(QColor::fromHsvF(h, s, v, a));
206 }
207
208 QVariant lighter(const QVariant &var, qreal factor) override
209 {
211 color = color.lighter(int(qRound(factor*100.)));
213 }
214
215 QVariant darker(const QVariant &var, qreal factor) override
216 {
218 color = color.darker(int(qRound(factor*100.)));
220 }
221
223 {
227 }
228
229 QVariant tint(const QVariant &baseVar, const QVariant &tintVar) override
230 {
231 QColor tintColor = tintVar.value<QColor>().toRgb();
232
233 int tintAlpha = tintColor.alpha();
234 if (tintAlpha == 0xFF) {
235 return tintVar;
236 } else if (tintAlpha == 0x00) {
237 return baseVar;
238 }
239
240 // tint the base color and return the final color
241 QColor baseColor = baseVar.value<QColor>().toRgb();
242 qreal a = tintColor.alphaF();
243 qreal inv_a = 1.0 - a;
244
245 qreal r = tintColor.redF() * a + baseColor.redF() * inv_a;
246 qreal g = tintColor.greenF() * a + baseColor.greenF() * inv_a;
247 qreal b = tintColor.blueF() * a + baseColor.blueF() * inv_a;
248
249 return QVariant::fromValue(QColor::fromRgbF(r, g, b, a + inv_a * baseColor.alphaF()));
250 }
251};
252
254{
255public:
257 {
258 return new QQuickApplication(parent);
259 }
260
261#if QT_CONFIG(im)
262 QInputMethod *inputMethod() override
263 {
264 QInputMethod *im = qGuiApp->inputMethod();
266 return im;
267 }
268#endif
269
271 {
272 QStyleHints *sh = qGuiApp->styleHints();
274 return sh;
275 }
276
278 {
280 }
281
282 bool openUrlExternally(const QUrl &url) override
283 {
284#ifndef QT_NO_DESKTOPSERVICES
286#else
287 Q_UNUSED(url);
288 return false;
289#endif
290 }
291
292 QString pluginName() const override
293 {
295 }
296};
297
303
305{
307 return &guiProvider;
308}
309
311{
312 // This is used by QQuickPath, and on macOS it fails to automatically register.
313 qRegisterMetaType<QVector<QVector<QPointF>>>();
314
317
319
320#if QT_CONFIG(accessibility)
321 QAccessible::installFactory(&qQuickAccessibleFactory);
322#endif
323
324#if QT_CONFIG(qml_debug)
326#endif
327}
328
330
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
void setAlphaF(float alpha)
Sets the alpha of this color to alpha.
Definition qcolor.cpp:1511
static QColor fromHslF(float h, float s, float l, float a=1.0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qcolor.cpp:2594
QColor darker(int f=200) const noexcept
Definition qcolor.cpp:2857
float greenF() const noexcept
Returns the green color component of this color.
Definition qcolor.cpp:1643
static QColor fromRgba(QRgb rgba) noexcept
Static convenience function that returns a QColor constructed from the given QRgb value rgba.
Definition qcolor.cpp:2385
static QColor fromString(QAnyStringView name) noexcept
Definition qcolor.cpp:980
float redF() const noexcept
Returns the red color component of this color.
Definition qcolor.cpp:1611
int value() const noexcept
Returns the value color component of this color.
Definition qcolor.cpp:1756
static QColor fromHsvF(float h, float s, float v, float a=1.0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qcolor.cpp:2530
QColor lighter(int f=150) const noexcept
Definition qcolor.cpp:2812
float alphaF() const noexcept
Returns the alpha color component of this color.
Definition qcolor.cpp:1497
float blueF() const noexcept
Returns the blue color component of this color.
Definition qcolor.cpp:1675
static QColor fromRgbF(float r, float g, float b, float a=1.0)
Static convenience function that returns a QColor constructed from the RGB color values,...
Definition qcolor.cpp:2427
static bool openUrl(const QUrl &url)
Opens the given url in the appropriate Web browser for the user's desktop environment,...
static QStringList families(WritingSystem writingSystem=Any)
Returns a sorted list of the available font families which support the writingSystem.
QString platformName
The name of the underlying platform plugin.
The QInputMethod class provides access to the active text input method.
static void setObjectOwnership(QObject *, ObjectOwnership)
Sets the ownership of object.
Definition qlist.h:75
qsizetype size() const noexcept
Definition qlist.h:397
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
\inmodule QtCore
Definition qobject.h:103
QQmlAnyBinding is an abstraction over the various bindings in QML.
static QQmlAnyBinding createFromCodeString(const QQmlProperty &prop, const QString &code, QObject *obj, const QQmlRefPointer< QQmlContextData > &ctxt, const QString &url, quint16 lineNumber)
static QQmlRefPointer< QQmlContextData > get(QQmlContext *context)
The QQmlContext class defines a context within a QML engine.
Definition qqmlcontext.h:25
static void setStatesDelegateFactory(QQmlDebugStatesDelegate *(*)())
The QQmlProperty class abstracts accessing properties on objects created from QML.
QVariant lighter(const QVariant &var, qreal factor) override
QVariant fromRgbF(double r, double g, double b, double a) override
QString stringFromRgba(unsigned rgba)
QVariant tint(const QVariant &baseVar, const QVariant &tintVar) override
QVariant fromHsvF(double h, double s, double v, double a) override
unsigned rgbaFromString(const QString &s, bool *ok) override
QVariant darker(const QVariant &var, qreal factor) override
QVariant fromHslF(double h, double s, double l, double a) override
QVariant colorFromString(const QString &s, bool *ok) override
QVariant alpha(const QVariant &var, qreal value) override
QQuickApplication * application(QObject *parent) override
bool openUrlExternally(const QUrl &url) override
QString pluginName() const override
QStyleHints * styleHints() override
QStringList fontFamilies() override
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QStyleHints class contains platform specific hints and settings. \inmodule QtGui.
Definition qstylehints.h:17
\inmodule QtCore
Definition qurl.h:94
\inmodule QtCore
Definition qvariant.h:65
T value() const &
Definition qvariant.h:516
QString toString() const
Returns the variant as a QString if the variant has a userType() including, but not limited to:
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
Definition qvariant.h:536
else opt state
[0]
Combined button and popup list for selecting options.
static void * context
Q_CONSTRUCTOR_FUNCTION(qt_apple_check_os_version)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
int qRound(qfloat16 d) noexcept
Definition qfloat16.h:327
#define qGuiApp
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLboolean r
[2]
GLuint color
[2]
GLboolean GLboolean g
GLfloat GLfloat GLfloat GLfloat h
GLenum GLenum GLsizei void GLsizei void * column
GLhandleARB obj
[2]
GLdouble s
[6]
Definition qopenglext.h:235
const GLubyte * c
static QQmlDebugStatesDelegate *(* statesDelegateFactory)()
static QQmlGuiProvider ** getGuiProvider(void)
static QQmlGuiProvider * guiProvider
Q_QML_EXPORT QQmlGuiProvider * QQml_setGuiProvider(QQmlGuiProvider *newProvider)
Q_QML_EXPORT QQmlColorProvider * QQml_setColorProvider(QQmlColorProvider *newProvider)
static QQmlColorProvider * colorProvider
static QQmlColorProvider ** getColorProvider(void)
#define Q_UNUSED(x)
void Q_QUICK_EXPORT QQuick_initializeModule()
double qreal
Definition qtypes.h:187
const char property[13]
Definition qwizard.cpp:101
QUrl url("example.com")
[constructor-url-reference]