aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/util/qquickvaluetypes.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@theqtcompany.com>2014-11-10 11:39:03 +0100
committerSimon Hausmann <simon.hausmann@digia.com>2014-12-22 21:48:11 +0100
commitfa3cf15e0577fe382ac577456422ad78325a3977 (patch)
tree3323ab526433f73fb644b1692c10629f01093d62 /src/quick/util/qquickvaluetypes.cpp
parentee771dda2e9e304edea88e6d5f6e6d540a0bab97 (diff)
Initial work on gadget support
Changed built-in QtQml value types to use gadgets. This is in preparation for supporting external gadgets. This replaces the mostly direct inheritance of the concrete value types with gadgets and "dynamic" inheritance through QQmlValueType being generic. Over time as some of the value types may become gadgets, we can remove the ones here. It's important that these "separate" gadgets have the same memory layout as the actual types (QPointF, etc.). Also while QQmlValueType remains practically a singleton, it's not required anymore to be one. Consequently the JS wrappers for value types keep their own instance of QQmlValueType. This allows eliminating the qobject_cast in various places that dealt with the singleton nature. This comes at a cost, making the JS wrappers slightly heavier. However that is meant to be a temporary situation and finally the value type wrapper should merely store the meta-object in addition to the data and the type. Change-Id: I15071ded0a1e54203f29ec1ecf7a9ab646d1168e Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/quick/util/qquickvaluetypes.cpp')
-rw-r--r--src/quick/util/qquickvaluetypes.cpp93
1 files changed, 2 insertions, 91 deletions
diff --git a/src/quick/util/qquickvaluetypes.cpp b/src/quick/util/qquickvaluetypes.cpp
index 37a5ba307f..2e4fec0599 100644
--- a/src/quick/util/qquickvaluetypes.cpp
+++ b/src/quick/util/qquickvaluetypes.cpp
@@ -48,11 +48,6 @@ namespace QQuickValueTypes {
}
}
-QQuickColorValueType::QQuickColorValueType(QObject *parent)
- : QQmlValueTypeBase<QColor>(QMetaType::QColor, parent)
-{
-}
-
QString QQuickColorValueType::toString() const
{
// to maintain behaviour with QtQuick 1.0, we just output normal toString() value.
@@ -99,26 +94,11 @@ void QQuickColorValueType::setA(qreal a)
v.setAlphaF(a);
}
-
-QQuickVector2DValueType::QQuickVector2DValueType(QObject *parent)
- : QQmlValueTypeBase<QVector2D>(QMetaType::QVector2D, parent)
-{
-}
-
QString QQuickVector2DValueType::toString() const
{
return QString(QLatin1String("QVector2D(%1, %2)")).arg(v.x()).arg(v.y());
}
-bool QQuickVector2DValueType::isEqual(const QVariant &other) const
-{
- if (other.userType() != QMetaType::QVector2D)
- return false;
-
- QVector2D otherVector = other.value<QVector2D>();
- return (v == otherVector);
-}
-
qreal QQuickVector2DValueType::x() const
{
return v.x();
@@ -199,26 +179,11 @@ bool QQuickVector2DValueType::fuzzyEquals(const QVector2D &vec) const
return qFuzzyCompare(v, vec);
}
-
-QQuickVector3DValueType::QQuickVector3DValueType(QObject *parent)
- : QQmlValueTypeBase<QVector3D>(QMetaType::QVector3D, parent)
-{
-}
-
QString QQuickVector3DValueType::toString() const
{
return QString(QLatin1String("QVector3D(%1, %2, %3)")).arg(v.x()).arg(v.y()).arg(v.z());
}
-bool QQuickVector3DValueType::isEqual(const QVariant &other) const
-{
- if (other.userType() != QMetaType::QVector3D)
- return false;
-
- QVector3D otherVector = other.value<QVector3D>();
- return (v == otherVector);
-}
-
qreal QQuickVector3DValueType::x() const
{
return v.x();
@@ -321,26 +286,11 @@ bool QQuickVector3DValueType::fuzzyEquals(const QVector3D &vec) const
return qFuzzyCompare(v, vec);
}
-
-QQuickVector4DValueType::QQuickVector4DValueType(QObject *parent)
- : QQmlValueTypeBase<QVector4D>(QMetaType::QVector4D, parent)
-{
-}
-
QString QQuickVector4DValueType::toString() const
{
return QString(QLatin1String("QVector4D(%1, %2, %3, %4)")).arg(v.x()).arg(v.y()).arg(v.z()).arg(v.w());
}
-bool QQuickVector4DValueType::isEqual(const QVariant &other) const
-{
- if (other.userType() != QMetaType::QVector4D)
- return false;
-
- QVector4D otherVector = other.value<QVector4D>();
- return (v == otherVector);
-}
-
qreal QQuickVector4DValueType::x() const
{
return v.x();
@@ -450,11 +400,6 @@ bool QQuickVector4DValueType::fuzzyEquals(const QVector4D &vec) const
return qFuzzyCompare(v, vec);
}
-QQuickQuaternionValueType::QQuickQuaternionValueType(QObject *parent)
- : QQmlValueTypeBase<QQuaternion>(QMetaType::QQuaternion, parent)
-{
-}
-
QString QQuickQuaternionValueType::toString() const
{
return QString(QLatin1String("QQuaternion(%1, %2, %3, %4)")).arg(v.scalar()).arg(v.x()).arg(v.y()).arg(v.z());
@@ -500,12 +445,6 @@ void QQuickQuaternionValueType::setZ(qreal z)
v.setZ(z);
}
-
-QQuickMatrix4x4ValueType::QQuickMatrix4x4ValueType(QObject *parent)
- : QQmlValueTypeBase<QMatrix4x4>(QMetaType::QMatrix4x4, parent)
-{
-}
-
QMatrix4x4 QQuickMatrix4x4ValueType::times(const QMatrix4x4 &m) const
{
return v * m;
@@ -579,30 +518,6 @@ bool QQuickMatrix4x4ValueType::fuzzyEquals(const QMatrix4x4 &m) const
return qFuzzyCompare(v, m);
}
-QString QQuickMatrix4x4ValueType::toString() const
-{
- return QString(QLatin1String("QMatrix4x4(%1, %2, %3, %4, %5, %6, %7, %8, %9, %10, %11, %12, %13, %14, %15, %16)"))
- .arg(v(0, 0)).arg(v(0, 1)).arg(v(0, 2)).arg(v(0, 3))
- .arg(v(1, 0)).arg(v(1, 1)).arg(v(1, 2)).arg(v(1, 3))
- .arg(v(2, 0)).arg(v(2, 1)).arg(v(2, 2)).arg(v(2, 3))
- .arg(v(3, 0)).arg(v(3, 1)).arg(v(3, 2)).arg(v(3, 3));
-}
-
-bool QQuickMatrix4x4ValueType::isEqual(const QVariant &other) const
-{
- if (other.userType() != qMetaTypeId<QMatrix4x4>())
- return false;
-
- QMatrix4x4 otherMatrix = other.value<QMatrix4x4>();
- return (v == otherMatrix);
-
-}
-
-QQuickFontValueType::QQuickFontValueType(QObject *parent)
- : QQmlValueTypeBase<QFont>(QMetaType::QFont, parent)
-{
-}
-
QString QQuickFontValueType::toString() const
{
return QString(QLatin1String("QFont(%1)")).arg(v.toString());
@@ -681,9 +596,7 @@ void QQuickFontValueType::setStrikeout(bool b)
qreal QQuickFontValueType::pointSize() const
{
if (v.pointSizeF() == -1) {
- if (dpi.isNull)
- dpi = qt_defaultDpi();
- return v.pixelSize() * qreal(72.) / qreal(dpi);
+ return v.pixelSize() * qreal(72.) / qreal(qt_defaultDpi());
}
return v.pointSizeF();
}
@@ -703,9 +616,7 @@ void QQuickFontValueType::setPointSize(qreal size)
int QQuickFontValueType::pixelSize() const
{
if (v.pixelSize() == -1) {
- if (dpi.isNull)
- dpi = qt_defaultDpi();
- return (v.pointSizeF() * dpi) / qreal(72.);
+ return (v.pointSizeF() * qt_defaultDpi()) / qreal(72.);
}
return v.pixelSize();
}