From 9600df5fa3661addb8aaa817e64a2bc6c3abbcc3 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 17 Nov 2009 15:02:00 +1000 Subject: Restore methods removed by f01e6e8993856cdcddc51868e91ef25b35695546 --- src/declarative/util/qmllistaccessor.cpp | 128 +++++++++++++++++++++++++++++++ src/declarative/util/qmllistaccessor_p.h | 5 ++ 2 files changed, 133 insertions(+) diff --git a/src/declarative/util/qmllistaccessor.cpp b/src/declarative/util/qmllistaccessor.cpp index 2c01081..910f2a5 100644 --- a/src/declarative/util/qmllistaccessor.cpp +++ b/src/declarative/util/qmllistaccessor.cpp @@ -149,6 +149,134 @@ QVariant QmlListAccessor::at(int idx) const return QVariant(); } +void QmlListAccessor::append(const QVariant &value) +{ + switch(m_type) { + case Invalid: + break; + case StringList: + { + const QString &str = value.toString(); + qvariant_cast(d).append(str); + break; + } + case VariantList: + { + qvariant_cast(d).append(value); + break; + } + case QmlList: + { + QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); + li->append(const_cast(value.constData())); //XXX + break; + } + case QList: + QmlMetaType::append(d, value); + break; + case Instance: + case Integer: + //do nothing + break; + } +} + +void QmlListAccessor::insert(int index, const QVariant &value) +{ + switch(m_type) { + case Invalid: + break; + case StringList: + { + const QString &str = value.toString(); + qvariant_cast(d).insert(index, str); + break; + } + case VariantList: + { + qvariant_cast(d).insert(index, value); + break; + } + case QmlList: + { + QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); + li->insert(index, const_cast(value.constData())); //XXX + break; + } + case QList: + //XXX needs implementation + qWarning() << "insert function not yet implemented for QLists"; + break; + case Instance: + //XXX do nothing? + if (index == 0) + setList(value); + break; + case Integer: + break; + } +} + +void QmlListAccessor::removeAt(int index) +{ + switch(m_type) { + case Invalid: + break; + case StringList: + qvariant_cast(d).removeAt(index); + break; + case VariantList: + qvariant_cast(d).removeAt(index); + break; + case QmlList: + { + QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); + li->removeAt(index); + break; + } + case QList: + //XXX needs implementation + qWarning() << "removeAt function not yet implemented for QLists"; + break; + case Instance: + //XXX do nothing? + if (index == 0) + setList(QVariant()); + break; + case Integer: + break; + } +} + +void QmlListAccessor::clear() +{ + switch(m_type) { + case Invalid: + break; + case StringList: + qvariant_cast(d).clear(); + break; + case VariantList: + qvariant_cast(d).clear(); + break; + case QmlList: + { + QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); + li->clear(); + break; + } + case QList: + QmlMetaType::clear(d); + break; + case Instance: + //XXX what should we do here? + setList(QVariant()); + break; + case Integer: + d = 0; + } +} + bool QmlListAccessor::isValid() const { return m_type != Invalid; diff --git a/src/declarative/util/qmllistaccessor_p.h b/src/declarative/util/qmllistaccessor_p.h index 7b34d75..2697606 100644 --- a/src/declarative/util/qmllistaccessor_p.h +++ b/src/declarative/util/qmllistaccessor_p.h @@ -65,6 +65,11 @@ public: int count() const; QVariant at(int) const; + virtual void append(const QVariant &); + virtual void insert(int, const QVariant &); + virtual void removeAt(int); + virtual void clear(); + enum Type { Invalid, StringList, VariantList, QmlList, QList, Instance, Integer }; Type type() const { return m_type; } -- cgit v0.12