diff options
author | Liang Qi <liang.qi@theqtcompany.com> | 2015-03-24 22:09:49 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@theqtcompany.com> | 2015-03-24 22:09:49 +0100 |
commit | c8427a542bc61d95e4f313f22a0118ccf1e963a4 (patch) | |
tree | cc9a9c6e31180c50a8d0a2f9b82ca84c9049c741 /src/qml/jsruntime/qv4sequenceobject.cpp | |
parent | 7b7297470cde5645b2ea1db4cec7ac4bec87c1a3 (diff) | |
parent | 3f2eabc8d90c4ee535cb0a2500e033171e203537 (diff) |
Merge remote-tracking branch 'origin/5.5' into dev
Conflicts:
tests/auto/qml/qqmlitemmodels/testtypes.h
Change-Id: I2f2f3f47fd873ddd4fd027414654a861b56357f4
Diffstat (limited to 'src/qml/jsruntime/qv4sequenceobject.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4sequenceobject.cpp | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/src/qml/jsruntime/qv4sequenceobject.cpp b/src/qml/jsruntime/qv4sequenceobject.cpp index a7e3b22cd2..f2cd5da302 100644 --- a/src/qml/jsruntime/qv4sequenceobject.cpp +++ b/src/qml/jsruntime/qv4sequenceobject.cpp @@ -41,6 +41,9 @@ #include <private/qv4scopedvalue_p.h> #include "qv4runtime_p.h" #include "qv4objectiterator_p.h" +#include <private/qqmlvaluetypewrapper_p.h> +#include <private/qqmlmodelindexvaluetype_p.h> +#include <QtCore/qabstractitemmodel.h> #include <algorithm> @@ -71,7 +74,9 @@ static void generateWarning(QV4::ExecutionEngine *v4, const QString& description F(bool, Bool, QList<bool>, false) \ F(QString, String, QList<QString>, QString()) \ F(QString, QString, QStringList, QString()) \ - F(QUrl, Url, QList<QUrl>, QUrl()) + F(QUrl, Url, QList<QUrl>, QUrl()) \ + F(QModelIndex, QModelIndex, QModelIndexList, QModelIndex()) \ + F(QItemSelectionRange, QItemSelectionRange, QItemSelection, QItemSelectionRange()) static QV4::ReturnedValue convertElementToValue(QV4::ExecutionEngine *engine, const QString &element) { @@ -88,6 +93,19 @@ static QV4::ReturnedValue convertElementToValue(QV4::ExecutionEngine *engine, co return engine->newString(element.toString())->asReturnedValue(); } +static QV4::ReturnedValue convertElementToValue(QV4::ExecutionEngine *engine, const QModelIndex &element) +{ + const QMetaObject *vtmo = QQmlValueTypeFactory::metaObjectForMetaType(QMetaType::QModelIndex); + return QV4::QQmlValueTypeWrapper::create(engine, QVariant(element), vtmo, QMetaType::QModelIndex); +} + +static QV4::ReturnedValue convertElementToValue(QV4::ExecutionEngine *engine, const QItemSelectionRange &element) +{ + int metaTypeId = qMetaTypeId<QItemSelectionRange>(); + const QMetaObject *vtmo = QQmlValueTypeFactory::metaObjectForMetaType(metaTypeId); + return QV4::QQmlValueTypeWrapper::create(engine, QVariant::fromValue(element), vtmo, metaTypeId); +} + static QV4::ReturnedValue convertElementToValue(QV4::ExecutionEngine *, qreal element) { return QV4::Encode(element); @@ -113,6 +131,16 @@ static QString convertElementToString(const QUrl &element) return element.toString(); } +static QString convertElementToString(const QModelIndex &element) +{ + return reinterpret_cast<const QQmlModelIndexValueType *>(&element)->toString(); +} + +static QString convertElementToString(const QItemSelectionRange &element) +{ + return reinterpret_cast<const QQmlItemSelectionRangeValueType *>(&element)->toString(); +} + static QString convertElementToString(qreal element) { QString qstr; @@ -145,6 +173,22 @@ template <> QUrl convertValueToElement(const Value &value) return QUrl(value.toQString()); } +template <> QModelIndex convertValueToElement(const Value &value) +{ + const QQmlValueTypeWrapper *v = value.as<QQmlValueTypeWrapper>(); + if (v) + return v->toVariant().toModelIndex(); + return QModelIndex(); +} + +template <> QItemSelectionRange convertValueToElement(const Value &value) +{ + const QQmlValueTypeWrapper *v = value.as<QQmlValueTypeWrapper>(); + if (v) + return v->toVariant().value<QItemSelectionRange>(); + return QItemSelectionRange(); +} + template <> qreal convertValueToElement(const Value &value) { return value.toNumber(); @@ -541,6 +585,12 @@ DEFINE_OBJECT_VTABLE(QQmlIntList); typedef QQmlSequence<QList<QUrl> > QQmlUrlList; template<> DEFINE_OBJECT_VTABLE(QQmlUrlList); +typedef QQmlSequence<QModelIndexList> QQmlQModelIndexList; +template<> +DEFINE_OBJECT_VTABLE(QQmlQModelIndexList); +typedef QQmlSequence<QItemSelection> QQmlQItemSelectionRangeList; +template<> +DEFINE_OBJECT_VTABLE(QQmlQItemSelectionRangeList); typedef QQmlSequence<QList<bool> > QQmlBoolList; template<> DEFINE_OBJECT_VTABLE(QQmlBoolList); |