summaryrefslogtreecommitdiffstats
path: root/src/gui/math3d
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2009-08-21 04:43:15 (GMT)
committerRhys Weatherley <rhys.weatherley@nokia.com>2009-08-21 04:43:15 (GMT)
commitbc9ced591a81293a155800cb28771f3bac17a9d2 (patch)
treed616a685f1de2ccb045a6d275a07d6fd8b2fb732 /src/gui/math3d
parent303915f67c2e797d8c9697466266e1f5c1bf45c6 (diff)
downloadQt-bc9ced591a81293a155800cb28771f3bac17a9d2.zip
Qt-bc9ced591a81293a155800cb28771f3bac17a9d2.tar.gz
Qt-bc9ced591a81293a155800cb28771f3bac17a9d2.tar.bz2
Add implicit conversions from math3d classes to QVariant
Existing QVariant-capable classes in QtGui like QColor, QPixmap, etc have "operator QVariant()". This change adds the same operators for QVector2D, QVector3D, QVector4D, QQuaternion, and QMatrix4x4. Reviewed-by: Justin McPherson
Diffstat (limited to 'src/gui/math3d')
-rw-r--r--src/gui/math3d/qmatrix4x4.cpp9
-rw-r--r--src/gui/math3d/qmatrix4x4.h3
-rw-r--r--src/gui/math3d/qquaternion.cpp9
-rw-r--r--src/gui/math3d/qquaternion.h3
-rw-r--r--src/gui/math3d/qvector2d.cpp9
-rw-r--r--src/gui/math3d/qvector2d.h3
-rw-r--r--src/gui/math3d/qvector3d.cpp9
-rw-r--r--src/gui/math3d/qvector3d.h2
-rw-r--r--src/gui/math3d/qvector4d.cpp9
-rw-r--r--src/gui/math3d/qvector4d.h2
10 files changed, 58 insertions, 0 deletions
diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp
index ed0802b..36ffcbe 100644
--- a/src/gui/math3d/qmatrix4x4.cpp
+++ b/src/gui/math3d/qmatrix4x4.cpp
@@ -41,6 +41,7 @@
#include "qmatrix4x4.h"
#include <QtCore/qmath.h>
+#include <QtCore/qvariant.h>
#include <QtGui/qmatrix.h>
#include <QtGui/qtransform.h>
@@ -1817,6 +1818,14 @@ void QMatrix4x4::inferSpecialType()
flagBits = Scale;
}
+/*!
+ Returns the matrix as a QVariant.
+*/
+QMatrix4x4::operator QVariant() const
+{
+ return QVariant(QVariant::Matrix4x4, this);
+}
+
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QMatrix4x4 &m)
diff --git a/src/gui/math3d/qmatrix4x4.h b/src/gui/math3d/qmatrix4x4.h
index 04a4216..10e628b 100644
--- a/src/gui/math3d/qmatrix4x4.h
+++ b/src/gui/math3d/qmatrix4x4.h
@@ -58,6 +58,7 @@ QT_MODULE(Gui)
class QMatrix;
class QTransform;
+class QVariant;
class Q_GUI_EXPORT QMatrix4x4
{
@@ -182,6 +183,8 @@ public:
void inferSpecialType();
+ operator QVariant() const;
+
#ifndef QT_NO_DEBUG_STREAM
friend Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QMatrix4x4 &m);
#endif
diff --git a/src/gui/math3d/qquaternion.cpp b/src/gui/math3d/qquaternion.cpp
index b2c598f..f279388 100644
--- a/src/gui/math3d/qquaternion.cpp
+++ b/src/gui/math3d/qquaternion.cpp
@@ -41,6 +41,7 @@
#include "qquaternion.h"
#include <QtCore/qmath.h>
+#include <QtCore/qvariant.h>
#include <QtCore/qdebug.h>
QT_BEGIN_NAMESPACE
@@ -560,6 +561,14 @@ QQuaternion QQuaternion::nlerp
return (q1 * (1.0f - t) + q2b * t).normalized();
}
+/*!
+ Returns the quaternion as a QVariant.
+*/
+QQuaternion::operator QVariant() const
+{
+ return QVariant(QVariant::Quaternion, this);
+}
+
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QQuaternion &q)
diff --git a/src/gui/math3d/qquaternion.h b/src/gui/math3d/qquaternion.h
index a2fb29f..af60b61 100644
--- a/src/gui/math3d/qquaternion.h
+++ b/src/gui/math3d/qquaternion.h
@@ -54,6 +54,7 @@ QT_MODULE(Gui)
#ifndef QT_NO_QUATERNION
class QMatrix4x4;
+class QVariant;
class Q_GUI_EXPORT QQuaternion
{
@@ -118,6 +119,8 @@ public:
QVector4D toVector4D() const;
#endif
+ operator QVariant() const;
+
#ifndef QT_NO_VECTOR3D
static QQuaternion fromAxisAndAngle(const QVector3D& axis, qreal angle);
#endif
diff --git a/src/gui/math3d/qvector2d.cpp b/src/gui/math3d/qvector2d.cpp
index 1662020..35c86a1 100644
--- a/src/gui/math3d/qvector2d.cpp
+++ b/src/gui/math3d/qvector2d.cpp
@@ -43,6 +43,7 @@
#include "qvector3d.h"
#include "qvector4d.h"
#include <QtCore/qdebug.h>
+#include <QtCore/qvariant.h>
#include <QtCore/qmath.h>
QT_BEGIN_NAMESPACE
@@ -402,6 +403,14 @@ QVector4D QVector2D::toVector4D() const
\sa toPoint(), toVector3D()
*/
+/*!
+ Returns the 2D vector as a QVariant.
+*/
+QVector2D::operator QVariant() const
+{
+ return QVariant(QVariant::Vector2D, this);
+}
+
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QVector2D &vector)
diff --git a/src/gui/math3d/qvector2d.h b/src/gui/math3d/qvector2d.h
index 93052f6..d9727e2 100644
--- a/src/gui/math3d/qvector2d.h
+++ b/src/gui/math3d/qvector2d.h
@@ -53,6 +53,7 @@ QT_MODULE(Gui)
class QVector3D;
class QVector4D;
+class QVariant;
#ifndef QT_NO_VECTOR2D
@@ -114,6 +115,8 @@ public:
QPoint toPoint() const;
QPointF toPointF() const;
+ operator QVariant() const;
+
private:
float xp, yp;
diff --git a/src/gui/math3d/qvector3d.cpp b/src/gui/math3d/qvector3d.cpp
index 0e3f4e1..5c96979 100644
--- a/src/gui/math3d/qvector3d.cpp
+++ b/src/gui/math3d/qvector3d.cpp
@@ -43,6 +43,7 @@
#include "qvector2d.h"
#include "qvector4d.h"
#include <QtCore/qmath.h>
+#include <QtCore/qvariant.h>
#include <QtCore/qdebug.h>
QT_BEGIN_NAMESPACE
@@ -530,6 +531,14 @@ QVector4D QVector3D::toVector4D() const
*/
/*!
+ Returns the 3D vector as a QVariant.
+*/
+QVector3D::operator QVariant() const
+{
+ return QVariant(QVariant::Vector3D, this);
+}
+
+/*!
Returns the length of the vector from the origin.
\sa lengthSquared(), normalized()
diff --git a/src/gui/math3d/qvector3d.h b/src/gui/math3d/qvector3d.h
index 36292d2..d1370fb 100644
--- a/src/gui/math3d/qvector3d.h
+++ b/src/gui/math3d/qvector3d.h
@@ -127,6 +127,8 @@ public:
QPoint toPoint() const;
QPointF toPointF() const;
+ operator QVariant() const;
+
private:
float xp, yp, zp;
diff --git a/src/gui/math3d/qvector4d.cpp b/src/gui/math3d/qvector4d.cpp
index a2efff7..11eb4c4 100644
--- a/src/gui/math3d/qvector4d.cpp
+++ b/src/gui/math3d/qvector4d.cpp
@@ -43,6 +43,7 @@
#include "qvector3d.h"
#include "qvector2d.h"
#include <QtCore/qdebug.h>
+#include <QtCore/qvariant.h>
#include <QtCore/qmath.h>
QT_BEGIN_NAMESPACE
@@ -500,6 +501,14 @@ QVector3D QVector4D::toVector3DAffine() const
\sa toPoint(), toVector2D()
*/
+/*!
+ Returns the 4D vector as a QVariant.
+*/
+QVector4D::operator QVariant() const
+{
+ return QVariant(QVariant::Vector4D, this);
+}
+
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QVector4D &vector)
diff --git a/src/gui/math3d/qvector4d.h b/src/gui/math3d/qvector4d.h
index 42db45b..69ccd30 100644
--- a/src/gui/math3d/qvector4d.h
+++ b/src/gui/math3d/qvector4d.h
@@ -124,6 +124,8 @@ public:
QPoint toPoint() const;
QPointF toPointF() const;
+ operator QVariant() const;
+
private:
float xp, yp, zp, wp;