summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2009-08-21 03:16:51 (GMT)
committerRhys Weatherley <rhys.weatherley@nokia.com>2009-08-21 03:16:51 (GMT)
commit7eb52559f44de7666c31ea28ce557eaca9177e9d (patch)
tree757b9927465409fc6a005a50bfe57322ec0824b9
parent0fd79d739bf102e406a8042eb20add5b1e8ebb10 (diff)
downloadQt-7eb52559f44de7666c31ea28ce557eaca9177e9d.zip
Qt-7eb52559f44de7666c31ea28ce557eaca9177e9d.tar.gz
Qt-7eb52559f44de7666c31ea28ce557eaca9177e9d.tar.bz2
Make QVector3D a first-class builtin type within QML
Reviewed-by: Martin Jones
-rw-r--r--src/declarative/qml/qmlbinding.cpp6
-rw-r--r--src/declarative/qml/qmlcompiler.cpp19
-rw-r--r--src/declarative/qml/qmlinstruction.cpp3
-rw-r--r--src/declarative/qml/qmlinstruction_p.h5
-rw-r--r--src/declarative/qml/qmlmetatype.cpp7
-rw-r--r--src/declarative/qml/qmlstringconverters.cpp29
-rw-r--r--src/declarative/qml/qmlstringconverters_p.h2
-rw-r--r--src/declarative/qml/qmlvme.cpp13
-rw-r--r--src/declarative/util/qmlanimation.cpp4
9 files changed, 88 insertions, 0 deletions
diff --git a/src/declarative/qml/qmlbinding.cpp b/src/declarative/qml/qmlbinding.cpp
index 45d20f4..39851ff 100644
--- a/src/declarative/qml/qmlbinding.cpp
+++ b/src/declarative/qml/qmlbinding.cpp
@@ -49,6 +49,7 @@
#include <QtCore/qdebug.h>
#include <private/qmlcontext_p.h>
#include <private/qmldeclarativedata_p.h>
+#include <private/qmlstringconverters_p.h>
Q_DECLARE_METATYPE(QList<QObject *>);
@@ -129,6 +130,11 @@ void QmlBinding::update()
(value.type() == QVariant::String || value.type() == QVariant::ByteArray) && !value.isNull())
value.setValue(context()->resolvedUrl(QUrl(value.toString())));
+ if (d->property.propertyType() == QVariant::Vector3D &&
+ value.type() == QVariant::String) {
+ value = qVariantFromValue(QmlStringConverters::vector3DFromString(value.toString()));
+ }
+
d->property.write(value);
}
diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp
index afc8698..1fb4b46 100644
--- a/src/declarative/qml/qmlcompiler.cpp
+++ b/src/declarative/qml/qmlcompiler.cpp
@@ -297,6 +297,13 @@ bool QmlCompiler::testLiteralAssignment(const QMetaProperty &prop,
if (!v->value.isBoolean()) COMPILE_EXCEPTION(v, "Invalid property assignment: boolean expected");
}
break;
+ case QVariant::Vector3D:
+ {
+ bool ok;
+ QVector3D point = QmlStringConverters::vector3DFromString(string, &ok);
+ if (!ok) COMPILE_EXCEPTION(v, "Invalid property assignment: 3D vector expected");
+ }
+ break;
default:
{
int t = prop.type();
@@ -487,6 +494,18 @@ void QmlCompiler::genLiteralAssignment(const QMetaProperty &prop,
instr.storeBool.value = b;
}
break;
+ case QVariant::Vector3D:
+ {
+ bool ok;
+ QVector3D vector =
+ QmlStringConverters::vector3DFromString(string, &ok);
+ float data[] = { vector.x(), vector.y(), vector.z() };
+ int index = output->indexForFloat(data, 3);
+ instr.type = QmlInstruction::StoreVector3D;
+ instr.storeRealPair.propertyIndex = prop.propertyIndex();
+ instr.storeRealPair.valueIndex = index;
+ }
+ break;
default:
{
int t = prop.type();
diff --git a/src/declarative/qml/qmlinstruction.cpp b/src/declarative/qml/qmlinstruction.cpp
index fd912ac..02e4883 100644
--- a/src/declarative/qml/qmlinstruction.cpp
+++ b/src/declarative/qml/qmlinstruction.cpp
@@ -119,6 +119,9 @@ void QmlCompiledData::dump(QmlInstruction *instr, int idx)
case QmlInstruction::StoreRectF:
qWarning() << idx << "\t" << line << "\t" << "STORE_RECTF\t\t" << instr->storeRect.propertyIndex << "\t" << instr->storeRect.valueIndex;
break;
+ case QmlInstruction::StoreVector3D:
+ qWarning() << idx << "\t" << line << "\t" << "STORE_VECTOR3D\t\t" << instr->storeVector3D.propertyIndex << "\t" << instr->storeVector3D.valueIndex;
+ break;
case QmlInstruction::StoreVariant:
qWarning() << idx << "\t" << line << "\t" << "STORE_VARIANT\t\t" << instr->storeString.propertyIndex << "\t" << instr->storeString.value << "\t\t" << primitives.at(instr->storeString.value);
break;
diff --git a/src/declarative/qml/qmlinstruction_p.h b/src/declarative/qml/qmlinstruction_p.h
index 7f3498f..0f2995a 100644
--- a/src/declarative/qml/qmlinstruction_p.h
+++ b/src/declarative/qml/qmlinstruction_p.h
@@ -111,6 +111,7 @@ public:
StoreSizeF, /* storeRealPair */
StoreRect, /* storeRect */
StoreRectF, /* storeRect */
+ StoreVector3D, /* storeVector3D */
StoreVariant, /* storeString */
StoreObject, /* storeObject */
StoreVariantObject, /* storeObject */
@@ -263,6 +264,10 @@ public:
} storeRect;
struct {
int propertyIndex;
+ int valueIndex;
+ } storeVector3D;
+ struct {
+ int propertyIndex;
} storeObject;
struct {
int propertyIndex;
diff --git a/src/declarative/qml/qmlmetatype.cpp b/src/declarative/qml/qmlmetatype.cpp
index 091bd1b..ab64079 100644
--- a/src/declarative/qml/qmlmetatype.cpp
+++ b/src/declarative/qml/qmlmetatype.cpp
@@ -75,6 +75,7 @@
# include <qpoint.h>
# include <qrect.h>
# include <qline.h>
+# include <qvector3d.h>
#endif
#define NS(x) QT_PREPEND_NAMESPACE(x)
@@ -1028,6 +1029,9 @@ bool QmlMetaType::copy(int type, void *data, const void *copy)
case QMetaType::QPointF:
*static_cast<NS(QPointF) *>(data) = *static_cast<const NS(QPointF)*>(copy);
return true;
+ case QMetaType::QVector3D:
+ *static_cast<NS(QVector3D) *>(data) = *static_cast<const NS(QVector3D)*>(copy);
+ return true;
#endif
#ifndef QT_NO_REGEXP
case QMetaType::QRegExp:
@@ -1155,6 +1159,9 @@ bool QmlMetaType::copy(int type, void *data, const void *copy)
case QMetaType::QPointF:
*static_cast<NS(QPointF) *>(data) = NS(QPointF)();
return true;
+ case QMetaType::QVector3D:
+ *static_cast<NS(QVector3D) *>(data) = NS(QVector3D)();
+ return true;
#endif
#ifndef QT_NO_REGEXP
case QMetaType::QRegExp:
diff --git a/src/declarative/qml/qmlstringconverters.cpp b/src/declarative/qml/qmlstringconverters.cpp
index c1f4b8c..34025c5 100644
--- a/src/declarative/qml/qmlstringconverters.cpp
+++ b/src/declarative/qml/qmlstringconverters.cpp
@@ -40,6 +40,7 @@
****************************************************************************/
#include <QtGui/qcolor.h>
+#include <QtGui/qvector3d.h>
#include <QtCore/qpoint.h>
#include <QtCore/qrect.h>
#include <QtCore/qsize.h>
@@ -94,6 +95,8 @@ QVariant QmlStringConverters::variantFromString(const QString &s)
if (ok) return QVariant(sz);
bool b = boolFromString(s, &ok);
if (ok) return QVariant(b);
+ QVector3D v = vector3DFromString(s, &ok);
+ if (ok) return qVariantFromValue(v);
return QVariant(s);
}
@@ -209,4 +212,30 @@ bool QmlStringConverters::boolFromString(const QString &str, bool *ok)
return true;
}
+//expects input of "x,y,z"
+QVector3D QmlStringConverters::vector3DFromString(const QString &s, bool *ok)
+{
+ if (s.count(QLatin1Char(',')) != 2) {
+ if (ok)
+ *ok = false;
+ return QVector3D();
+ }
+
+ bool xGood, yGood, zGood;
+ int index = s.indexOf(QLatin1Char(','));
+ int index2 = s.indexOf(QLatin1Char(','), index+1);
+ qreal xCoord = s.left(index).toDouble(&xGood);
+ qreal yCoord = s.mid(index+1, index2-index-1).toDouble(&yGood);
+ qreal zCoord = s.mid(index2+1).toDouble(&zGood);
+ if (!xGood || !yGood || !zGood) {
+ if (ok)
+ *ok = false;
+ return QVector3D();
+ }
+
+ if (ok)
+ *ok = true;
+ return QVector3D(xCoord, yCoord, zCoord);
+}
+
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qmlstringconverters_p.h b/src/declarative/qml/qmlstringconverters_p.h
index 52426a7..ab7448c 100644
--- a/src/declarative/qml/qmlstringconverters_p.h
+++ b/src/declarative/qml/qmlstringconverters_p.h
@@ -60,6 +60,7 @@ class QSizeF;
class QRectF;
class QString;
class QByteArray;
+class QVector3D;
QT_BEGIN_NAMESPACE
@@ -72,6 +73,7 @@ namespace QmlStringConverters
QSizeF Q_DECLARATIVE_EXPORT sizeFFromString(const QString &, bool *ok = 0);
QRectF Q_DECLARATIVE_EXPORT rectFFromString(const QString &, bool *ok = 0);
bool Q_DECLARATIVE_EXPORT boolFromString(const QString &, bool *ok = 0);
+ QVector3D Q_DECLARATIVE_EXPORT vector3DFromString(const QString &, bool *ok = 0);
};
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp
index 79b1d89..7455eb4 100644
--- a/src/declarative/qml/qmlvme.cpp
+++ b/src/declarative/qml/qmlvme.cpp
@@ -439,6 +439,19 @@ QObject *QmlVME::run(QStack<QObject *> &stack, QmlContext *ctxt, QmlCompiledData
}
break;
+ case QmlInstruction::StoreVector3D:
+ {
+ QObject *target = stack.top();
+ void *a[1];
+ QVector3D p(floatData.at(instr.storeVector3D.valueIndex),
+ floatData.at(instr.storeVector3D.valueIndex+1),
+ floatData.at(instr.storeVector3D.valueIndex+2));
+ a[0] = (void *)&p;
+ QMetaObject::metacall(target, QMetaObject::WriteProperty,
+ instr.storeVector3D.propertyIndex, a);
+ }
+ break;
+
case QmlInstruction::StoreObject:
{
QObject *assignObj = stack.pop();
diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp
index 7faddee..7b558b9 100644
--- a/src/declarative/util/qmlanimation.cpp
+++ b/src/declarative/util/qmlanimation.cpp
@@ -1462,6 +1462,10 @@ void QmlPropertyAnimationPrivate::convertVariant(QVariant &variant, int type)
variant.setValue(QmlStringConverters::colorFromString(variant.toString()));
break;
}
+ case QVariant::Vector3D: {
+ variant.setValue(QmlStringConverters::vector3DFromString(variant.toString()));
+ break;
+ }
default:
if ((uint)type >= QVariant::UserType) {
QmlMetaType::StringConverter converter = QmlMetaType::customStringConverter(type);