1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
42 #include <private/qqmlglobal_p.h>
44 #include <QtCore/qvariant.h>
45 #include <QtCore/qstringlist.h>
46 #include <QtCore/qdebug.h>
50 QQmlValueTypeProvider::QQmlValueTypeProvider()
55 QQmlValueTypeProvider::~QQmlValueTypeProvider()
59 QQmlValueType *QQmlValueTypeProvider::createValueType(int type)
61 QQmlValueType *value = 0;
63 QQmlValueTypeProvider *p = this;
65 if (p->create(type, value))
67 } while ((p = p->next));
72 bool QQmlValueTypeProvider::initValueType(int type, void *data, size_t n)
76 QQmlValueTypeProvider *p = this;
78 if (p->init(type, data, n))
80 } while ((p = p->next));
85 bool QQmlValueTypeProvider::destroyValueType(int type, void *data, size_t n)
89 QQmlValueTypeProvider *p = this;
91 if (p->destroy(type, data, n))
93 } while ((p = p->next));
98 bool QQmlValueTypeProvider::copyValueType(int type, const void *src, void *dst, size_t n)
103 QQmlValueTypeProvider *p = this;
105 if (p->copy(type, src, dst, n))
107 } while ((p = p->next));
112 QVariant QQmlValueTypeProvider::createValueType(int type, int argc, const void *argv[])
116 QQmlValueTypeProvider *p = this;
118 if (p->create(type, argc, argv, &v))
120 } while ((p = p->next));
125 bool QQmlValueTypeProvider::createValueFromString(int type, const QString &s, void *data, size_t n)
129 QQmlValueTypeProvider *p = this;
131 if (p->createFromString(type, s, data, n))
133 } while ((p = p->next));
138 bool QQmlValueTypeProvider::createStringFromValue(int type, const void *data, QString *s)
143 QQmlValueTypeProvider *p = this;
145 if (p->createStringFrom(type, data, s))
147 } while ((p = p->next));
152 QVariant QQmlValueTypeProvider::createVariantFromString(const QString &s)
156 QQmlValueTypeProvider *p = this;
158 if (p->variantFromString(s, &v))
160 } while ((p = p->next));
162 // Return a variant containing the string itself
166 QVariant QQmlValueTypeProvider::createVariantFromString(int type, const QString &s, bool *ok)
170 QQmlValueTypeProvider *p = this;
172 if (p->variantFromString(type, s, &v)) {
176 } while ((p = p->next));
182 QVariant QQmlValueTypeProvider::createVariantFromJsObject(int type, QQmlV8Handle obj, QV8Engine *e, bool *ok)
186 QQmlValueTypeProvider *p = this;
188 if (p->variantFromJsObject(type, obj, e, &v)) {
192 } while ((p = p->next));
198 bool QQmlValueTypeProvider::equalValueType(int type, const void *lhs, const void *rhs, size_t rhsSize)
203 QQmlValueTypeProvider *p = this;
205 if (p->equal(type, lhs, rhs, rhsSize))
207 } while ((p = p->next));
212 bool QQmlValueTypeProvider::storeValueType(int type, const void *src, void *dst, size_t dstSize)
217 QQmlValueTypeProvider *p = this;
219 if (p->store(type, src, dst, dstSize))
221 } while ((p = p->next));
226 bool QQmlValueTypeProvider::readValueType(int srcType, const void *src, size_t srcSize, int dstType, void *dst)
231 QQmlValueTypeProvider *p = this;
233 if (p->read(srcType, src, srcSize, dstType, dst))
235 } while ((p = p->next));
240 bool QQmlValueTypeProvider::writeValueType(int type, const void *src, void *dst, size_t n)
245 QQmlValueTypeProvider *p = this;
247 if (p->write(type, src, dst, n))
249 } while ((p = p->next));
254 bool QQmlValueTypeProvider::create(int, QQmlValueType *&) { return false; }
255 bool QQmlValueTypeProvider::init(int, void *, size_t) { return false; }
256 bool QQmlValueTypeProvider::destroy(int, void *, size_t) { return false; }
257 bool QQmlValueTypeProvider::copy(int, const void *, void *, size_t) { return false; }
258 bool QQmlValueTypeProvider::create(int, int, const void *[], QVariant *) { return false; }
259 bool QQmlValueTypeProvider::createFromString(int, const QString &, void *, size_t) { return false; }
260 bool QQmlValueTypeProvider::createStringFrom(int, const void *, QString *) { return false; }
261 bool QQmlValueTypeProvider::variantFromString(const QString &, QVariant *) { return false; }
262 bool QQmlValueTypeProvider::variantFromString(int, const QString &, QVariant *) { return false; }
263 bool QQmlValueTypeProvider::variantFromJsObject(int, QQmlV8Handle, QV8Engine *, QVariant *) { return false; }
264 bool QQmlValueTypeProvider::equal(int, const void *, const void *, size_t) { return false; }
265 bool QQmlValueTypeProvider::store(int, const void *, void *, size_t) { return false; }
266 bool QQmlValueTypeProvider::read(int, const void *, size_t, int, void *) { return false; }
267 bool QQmlValueTypeProvider::write(int, const void *, void *, size_t) { return false; }
269 static QQmlValueTypeProvider *valueTypeProvider = 0;
271 static QQmlValueTypeProvider **getValueTypeProvider(void)
273 if (valueTypeProvider == 0) {
274 static QQmlValueTypeProvider nullValueTypeProvider;
275 valueTypeProvider = &nullValueTypeProvider;
278 return &valueTypeProvider;
281 Q_QML_PRIVATE_EXPORT void QQml_addValueTypeProvider(QQmlValueTypeProvider *newProvider)
283 static QQmlValueTypeProvider **providerPtr = getValueTypeProvider();
284 newProvider->next = *providerPtr;
285 *providerPtr = newProvider;
288 Q_AUTOTEST_EXPORT QQmlValueTypeProvider *QQml_valueTypeProvider(void)
290 static QQmlValueTypeProvider **providerPtr = getValueTypeProvider();
294 QQmlColorProvider::~QQmlColorProvider() {}
295 QVariant QQmlColorProvider::colorFromString(const QString &, bool *ok) { if (ok) *ok = false; return QVariant(); }
296 unsigned QQmlColorProvider::rgbaFromString(const QString &, bool *ok) { if (ok) *ok = false; return 0; }
297 QVariant QQmlColorProvider::fromRgbF(double, double, double, double) { return QVariant(); }
298 QVariant QQmlColorProvider::fromHslF(double, double, double, double) { return QVariant(); }
299 QVariant QQmlColorProvider::lighter(const QVariant &, qreal) { return QVariant(); }
300 QVariant QQmlColorProvider::darker(const QVariant &, qreal) { return QVariant(); }
301 QVariant QQmlColorProvider::tint(const QVariant &, const QVariant &) { return QVariant(); }
303 static QQmlColorProvider *colorProvider = 0;
305 Q_QML_PRIVATE_EXPORT QQmlColorProvider *QQml_setColorProvider(QQmlColorProvider *newProvider)
307 QQmlColorProvider *old = colorProvider;
308 colorProvider = newProvider;
312 static QQmlColorProvider **getColorProvider(void)
314 if (colorProvider == 0) {
315 qWarning() << "Warning: QQml_colorProvider: no color provider has been set!";
316 static QQmlColorProvider nullColorProvider;
317 colorProvider = &nullColorProvider;
320 return &colorProvider;
323 Q_AUTOTEST_EXPORT QQmlColorProvider *QQml_colorProvider(void)
325 static QQmlColorProvider **providerPtr = getColorProvider();
330 QQmlGuiProvider::~QQmlGuiProvider() {}
331 QObject *QQmlGuiProvider::application(QObject *) { return 0; }
332 QStringList QQmlGuiProvider::fontFamilies() { return QStringList(); }
333 bool QQmlGuiProvider::openUrlExternally(QUrl &) { return false; }
335 QObject *QQmlGuiProvider::inputMethod()
337 // We don't have any input method code by default
338 QObject *o = new QObject();
339 o->setObjectName(QString::fromLatin1("No inputMethod available"));
343 static QQmlGuiProvider *guiProvider = 0;
345 Q_QML_PRIVATE_EXPORT QQmlGuiProvider *QQml_setGuiProvider(QQmlGuiProvider *newProvider)
347 QQmlGuiProvider *old = guiProvider;
348 guiProvider = newProvider;
352 static QQmlGuiProvider **getGuiProvider(void)
354 if (guiProvider == 0) {
355 qWarning() << "Warning: QQml_guiProvider: no GUI provider has been set!";
356 static QQmlGuiProvider nullGuiProvider;
357 guiProvider = &nullGuiProvider;
363 Q_AUTOTEST_EXPORT QQmlGuiProvider *QQml_guiProvider(void)
365 static QQmlGuiProvider **providerPtr = getGuiProvider();