summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/qmlstringconverters.cpp
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 /src/declarative/qml/qmlstringconverters.cpp
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
Diffstat (limited to 'src/declarative/qml/qmlstringconverters.cpp')
-rw-r--r--src/declarative/qml/qmlstringconverters.cpp29
1 files changed, 29 insertions, 0 deletions
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