summaryrefslogtreecommitdiffstats
path: root/src/declarative/util/qmllistmodel.cpp
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2009-11-17 03:11:53 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2009-11-17 03:11:53 (GMT)
commitd9d764056e69619f09171de554526cbddadefea8 (patch)
treeed2c74d4c9599d605703998a85aa504addd918b6 /src/declarative/util/qmllistmodel.cpp
parentf31522c3b01bb832d8ef3fa0eea7ec01f13424b2 (diff)
downloadQt-d9d764056e69619f09171de554526cbddadefea8.zip
Qt-d9d764056e69619f09171de554526cbddadefea8.tar.gz
Qt-d9d764056e69619f09171de554526cbddadefea8.tar.bz2
Error checking and tests for them in ListModel
Diffstat (limited to 'src/declarative/util/qmllistmodel.cpp')
-rw-r--r--src/declarative/util/qmllistmodel.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/declarative/util/qmllistmodel.cpp b/src/declarative/util/qmllistmodel.cpp
index 9e91147..a3c5c59 100644
--- a/src/declarative/util/qmllistmodel.cpp
+++ b/src/declarative/util/qmllistmodel.cpp
@@ -483,6 +483,10 @@ void QmlListModel::remove(int index)
*/
void QmlListModel::insert(int index, const QScriptValue& valuemap)
{
+ if (!valuemap.isObject() || valuemap.isArray()) {
+ qmlInfo(this) << tr("insert: value is not an object");
+ return;
+ }
if (!_root)
_root = new ModelNode;
if (index >= _root->values.count() || index<0) {
@@ -517,8 +521,10 @@ void QmlListModel::move(int from, int to, int n)
{
if (n==0 || from==to)
return;
- if (from+n > count() || to+n > count() || from < 0 || to < 0)
+ if (from+n > count() || to+n > count() || from < 0 || to < 0 || n < 0) {
qmlInfo(this) << tr("move: out of range");
+ return;
+ }
int origfrom=from; // preserve actual move, so any animations are correct
int origto=to;
int orign=n;
@@ -564,7 +570,7 @@ void QmlListModel::move(int from, int to, int n)
*/
void QmlListModel::append(const QScriptValue& valuemap)
{
- if (!valuemap.isObject()) {
+ if (!valuemap.isObject() || valuemap.isArray()) {
qmlInfo(this) << tr("append: value is not an object");
return;
}
@@ -636,9 +642,11 @@ QScriptValue QmlListModel::get(int index) const
*/
void QmlListModel::set(int index, const QScriptValue& valuemap)
{
- if (!_root)
- _root = new ModelNode;
- if ( index > _root->values.count()) {
+ if (!valuemap.isObject() || valuemap.isArray()) {
+ qmlInfo(this) << tr("set: value is not an object");
+ return;
+ }
+ if ( !_root || index > _root->values.count()) {
qmlInfo(this) << tr("set: index %1 out of range").arg(index);
return;
}
@@ -677,9 +685,7 @@ void QmlListModel::set(int index, const QScriptValue& valuemap)
*/
void QmlListModel::set(int index, const QString& property, const QVariant& value)
{
- if (!_root)
- _root = new ModelNode;
- if ( index >= _root->values.count()) {
+ if ( !_root || index >= _root->values.count()) {
qmlInfo(this) << tr("set: index %1 out of range").arg(index);
return;
}