summaryrefslogtreecommitdiffstats
path: root/examples/script
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2010-03-26 08:04:10 (GMT)
committerAlan Alpert <alan.alpert@nokia.com>2010-03-26 08:04:10 (GMT)
commit43381162eac93f0fbe10e06944c59158dccb3d8c (patch)
tree6eb3ad70f0074aaf662c83dce56281613c9219bc /examples/script
parenta0548f2fc01a47c1b5de4d967d0bc920bd1867f6 (diff)
parentd432123cec9ac927ec9162fa8b3d16684483f994 (diff)
downloadQt-43381162eac93f0fbe10e06944c59158dccb3d8c.zip
Qt-43381162eac93f0fbe10e06944c59158dccb3d8c.tar.gz
Qt-43381162eac93f0fbe10e06944c59158dccb3d8c.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7
Diffstat (limited to 'examples/script')
-rw-r--r--examples/script/customclass/bytearrayclass.cpp17
-rw-r--r--examples/script/customclass/bytearrayclass.h2
2 files changed, 17 insertions, 2 deletions
diff --git a/examples/script/customclass/bytearrayclass.cpp b/examples/script/customclass/bytearrayclass.cpp
index 1dbf2d4..239b4b4 100644
--- a/examples/script/customclass/bytearrayclass.cpp
+++ b/examples/script/customclass/bytearrayclass.cpp
@@ -148,13 +148,13 @@ void ByteArrayClass::setProperty(QScriptValue &object,
if (!ba)
return;
if (name == length) {
- ba->resize(value.toInt32());
+ resize(*ba, value.toInt32());
} else {
qint32 pos = id;
if (pos < 0)
return;
if (ba->size() <= pos)
- ba->resize(pos + 1);
+ resize(*ba, pos + 1);
(*ba)[pos] = char(value.toInt32());
}
}
@@ -194,10 +194,13 @@ QScriptValue ByteArrayClass::constructor()
return ctor;
}
+//! [10]
QScriptValue ByteArrayClass::newInstance(int size)
{
+ engine()->reportAdditionalMemoryCost(size);
return newInstance(QByteArray(size, /*ch=*/0));
}
+//! [10]
//! [1]
QScriptValue ByteArrayClass::newInstance(const QByteArray &ba)
@@ -235,6 +238,16 @@ void ByteArrayClass::fromScriptValue(const QScriptValue &obj, QByteArray &ba)
ba = qvariant_cast<QByteArray>(obj.data().toVariant());
}
+//! [9]
+void ByteArrayClass::resize(QByteArray &ba, int newSize)
+{
+ int oldSize = ba.size();
+ ba.resize(newSize);
+ if (newSize > oldSize)
+ engine()->reportAdditionalMemoryCost(newSize - oldSize);
+}
+//! [9]
+
ByteArrayClassPropertyIterator::ByteArrayClassPropertyIterator(const QScriptValue &object)
diff --git a/examples/script/customclass/bytearrayclass.h b/examples/script/customclass/bytearrayclass.h
index f185754..3f7ce22 100644
--- a/examples/script/customclass/bytearrayclass.h
+++ b/examples/script/customclass/bytearrayclass.h
@@ -82,6 +82,8 @@ private:
static QScriptValue toScriptValue(QScriptEngine *eng, const QByteArray &ba);
static void fromScriptValue(const QScriptValue &obj, QByteArray &ba);
+ void resize(QByteArray &ba, int newSize);
+
QScriptString length;
QScriptValue proto;
QScriptValue ctor;