summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2009-11-13 05:46:04 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2009-11-13 05:46:04 (GMT)
commit9191ed87ba75db959cb6833ad694d168a0976ee6 (patch)
tree61167330a182df86fd78ec9aa82bf0c379ea21f9
parentb696712ecaad7a14754ad4bd271d241978d29646 (diff)
parent3585025a5e7551190e93179be430072709e75751 (diff)
downloadQt-9191ed87ba75db959cb6833ad694d168a0976ee6.zip
Qt-9191ed87ba75db959cb6833ad694d168a0976ee6.tar.gz
Qt-9191ed87ba75db959cb6833ad694d168a0976ee6.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
-rw-r--r--src/declarative/util/qmllistaccessor.cpp128
-rw-r--r--src/declarative/util/qmllistaccessor_p.h5
-rw-r--r--tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp36
3 files changed, 18 insertions, 151 deletions
diff --git a/src/declarative/util/qmllistaccessor.cpp b/src/declarative/util/qmllistaccessor.cpp
index 910f2a5..2c01081 100644
--- a/src/declarative/util/qmllistaccessor.cpp
+++ b/src/declarative/util/qmllistaccessor.cpp
@@ -149,134 +149,6 @@ 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<QStringList>(d).append(str);
- break;
- }
- case VariantList:
- {
- qvariant_cast<QVariantList>(d).append(value);
- break;
- }
- case QmlList:
- {
- QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData();
- li->append(const_cast<void *>(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<QStringList>(d).insert(index, str);
- break;
- }
- case VariantList:
- {
- qvariant_cast<QVariantList>(d).insert(index, value);
- break;
- }
- case QmlList:
- {
- QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData();
- li->insert(index, const_cast<void *>(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<QStringList>(d).removeAt(index);
- break;
- case VariantList:
- qvariant_cast<QVariantList>(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<QStringList>(d).clear();
- break;
- case VariantList:
- qvariant_cast<QVariantList>(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 2697606..7b34d75 100644
--- a/src/declarative/util/qmllistaccessor_p.h
+++ b/src/declarative/util/qmllistaccessor_p.h
@@ -65,11 +65,6 @@ 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; }
diff --git a/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp b/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp
index b2d42ff..4c8219a 100644
--- a/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp
+++ b/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp
@@ -41,6 +41,7 @@
#include <qtest.h>
#include <QtDeclarative/qml.h>
#include <private/qmllistaccessor_p.h>
+#include <QDebug>
class tst_QmlListAccessor : public QObject
{
@@ -51,7 +52,7 @@ public:
private slots:
void qmllist();
//void qlist();
- //void qstringlist();
+ void qstringlist();
};
void tst_QmlListAccessor::qmllist()
@@ -71,31 +72,30 @@ void tst_QmlListAccessor::qmllist()
QVariant v = accessor.at(0);
QCOMPARE(qvariant_cast<QObject*>(v), obj);
- accessor.removeAt(3);
- QVERIFY(accessor.count() == 1);
-
- accessor.removeAt(0);
- QVERIFY(accessor.count() == 0);
+ QVERIFY(accessor.isValid());
+}
- accessor.insert(4, qVariantFromValue(obj));
- QVERIFY(accessor.count() == 1);
+void tst_QmlListAccessor::qstringlist()
+{
+ QStringList list;
+ list.append(QLatin1String("Item1"));
+ list.append(QLatin1String("Item2"));
+ QVERIFY(list.count() == 2);
- v = accessor.at(0);
- QCOMPARE(qvariant_cast<QObject*>(v), obj);
+ QmlListAccessor accessor;
+ accessor.setList(list);
- QObject *obj2 = new QObject;
- accessor.append(qVariantFromValue(obj2));
+ QVERIFY(accessor.isValid());
QVERIFY(accessor.count() == 2);
- v = accessor.at(1);
- QCOMPARE(qvariant_cast<QObject*>(v), obj2);
-
- accessor.clear();
- QVERIFY(accessor.count() == 0);
+ QVariant v = accessor.at(0);
+ QCOMPARE(qvariant_cast<QString>(v), QLatin1String("Item1"));
- QVERIFY(accessor.isValid());
+ v = accessor.at(1);
+ QCOMPARE(qvariant_cast<QString>(v), QLatin1String("Item2"));
}
+
QTEST_MAIN(tst_QmlListAccessor)
#include "tst_qmllistaccessor.moc"