42 #include "private/qdeclarativelistmodel_p_p.h" 43 #include "private/qdeclarativelistmodelworkeragent_p.h" 44 #include "private/qdeclarativeopenmetaobject_p.h" 52 #include <QtCore/qdebug.h> 53 #include <QtCore/qstack.h> 54 #include <QXmlStreamReader> 55 #include <QtScript/qscriptvalueiterator.h> 65 items->move(from, to);
69 typename T::ConstIterator
it=items->begin(); it += from+n;
70 for (; i<to-from; ++i,++
it)
73 it=items->begin(); it += from;
76 typename T::ConstIterator f=replaced.begin();
77 typename T::Iterator t=items->begin(); t += from;
78 for (; f != replaced.end(); ++f, ++t)
261 bool hasNested =
false;
271 for (
int i=0; i<roles.
count(); i++) {
298 qmlInfo(
this) <<
"List contains list-type data and cannot be used from a worker script";
318 if (index >=
count() || index < 0)
348 int cleared =
count();
365 modelCache->m_nested->_root =
this;
367 for (
int i=0; i<
values.count(); ++i) {
370 subNode->
m_model = modelCache->m_nested;
380 const_cast<NestedListModel*>(model),
386 objectCache->setNodeUpdatesEnabled(
true);
403 if (index < 0 || index >=
count()) {
404 qmlInfo(
this) <<
tr(
"remove: index %1 out of range").
arg(index);
440 qmlInfo(
this) <<
tr(
"insert: value is not an object");
444 if (index < 0 || index >
count()) {
445 qmlInfo(
this) <<
tr(
"insert: index %1 out of range").
arg(index);
475 if (n==0 || from==to)
478 qmlInfo(
this) <<
tr(
"move: out of range");
521 qmlInfo(
this) <<
tr(
"append: value is not an object");
598 qmlInfo(
this) <<
tr(
"set: value is not an object");
601 if (index >
count() || index < 0) {
602 qmlInfo(
this) <<
tr(
"set: index %1 out of range").
arg(index);
606 if (index ==
count()) {
642 if (
count() == 0 || index >=
count() || index < 0) {
643 qmlInfo(
this) <<
tr(
"set: index %1 out of range").
arg(index);
667 qmlInfo(
this) <<
"List sync() can only be called from a WorkerScript";
673 for(
int ii = 0; ii < values.
count(); ++ii) {
676 if(value.
userType() == qMetaTypeId<QDeclarativeCustomParserNode>()) {
680 if (node.
name() != listElementTypeName) {
686 listElementTypeName = node.
name();
691 li.
type = ListInstruction::Push;
697 for(
int jj = 0; jj < props.
count(); ++jj) {
703 if (nodeProp.
name() ==
"id") {
709 int ref = data.
count();
712 li.
type = ListInstruction::Set;
716 if(!compileProperty(nodeProp, instr, data))
719 li.
type = ListInstruction::Pop;
726 li.
type = ListInstruction::Pop;
736 int ref = data.
count();
739 d += char(variant.
type());
744 d +=
QByteArray( reinterpret_cast<const char*>(&temp),
sizeof(
double));
748 if (definesEmptyList(variant.
asScript())) {
752 int v = evaluateEnum(script);
764 d +=
QByteArray( reinterpret_cast<const char*>(&temp),
sizeof(
double));
772 li.
type = ListInstruction::Value;
787 for(
int ii = 0; ii < customProps.
count(); ++ii) {
794 if(!compileProperty(prop, instr, data)) {
810 for (
int ii = 0; ii < instr.
count(); ++ii)
826 bool processingSet =
false;
831 for (
int ii = 0; ii < lmd->
instrCount; ++ii) {
835 case ListInstruction::Push:
846 case ListInstruction::Pop:
850 case ListInstruction::Value:
862 ::memcpy(&temp, data + 1 + instr.
dataIdx,
sizeof(
double));
869 Q_ASSERT(
"Format error in ListInstruction");
872 processingSet =
false;
876 case ListInstruction::Set:
882 processingSet =
true;
899 for (
int i=1; i<s.
length()-1; i++) {
955 : m_scriptEngine(0), m_listModel(base), m_scriptClass(0), m_parentAgent(0)
1060 role = iter.value();
1063 if (
m_values[index][role] != value) {
1071 qdeclarativelistmodel_move<QList<QHash<int, QVariant> > >(from, to, n, &
m_values);
1082 qmlInfo(
m_listModel) <<
"Cannot add list-type data when modifying or after modification from a worker script";
1097 int role = iter.
value();
1135 qdeclarativelistmodel_move<QList<FlatNodeData *> >(from, to, n, &
m_nodeData);
1137 for (
int i=from; i<from + (to-from); i++) {
1155 objects.insert(data);
1160 objects.remove(data);
1180 if (role >= 0 && index >=0 ) {
1204 if (role >= 0 && index >= 0) {
1240 : _root(0), m_ownsRoot(false), m_listModel(base), _rolesOk(false)
1258 rv = node->
model(
this);
1274 rv = valueNode->
object(
this);
1276 rv = valueNode->
model(
this);
1300 for (
int ii = 0; ii < roles.
count(); ++ii) {
1338 if (!
_root)
return 0;
1376 qdeclarativelistmodel_move<QVariantList>(from, to, n, &
_root->
values);
1385 if (index < 0 || index >=
count()) {
1405 if (!emitItemsChanged)
1425 bool emitItemsChanged = node->
setProperty(property, value);
1426 if (!emitItemsChanged)
1475 : modelCache(0), objectCache(0), isArray(false), m_model(model), listIndex(-1)
1491 if (node) {
delete node; node = 0; }
1501 bool emitItemsChanged =
false;
1515 emitItemsChanged =
true;
1520 if (!emitItemsChanged && prev && prev->
values.
count() == 1
1522 emitItemsChanged =
true;
1529 return emitItemsChanged;
1535 for (
int i=0; i<size; i++) {
1554 bool emitItemsChanged =
false;
1556 if (val != (*it)->values[0])
1557 emitItemsChanged =
true;
1558 (*it)->values[0] = val;
1566 return emitItemsChanged;
1606 const char *indent = indentBa.
constData();
1608 for (
int ii = 0; ii < node->
values.
count(); ++ii) {
1611 qWarning().nospace() << indent <<
"Sub-node " << ii;
1612 dump(subNode, ind + 1);
1619 qWarning().nospace() << indent <<
"Property " << iter.key() <<
':';
1620 dump(iter.value(), ind + 1);
The QVariant class acts like a union for the most common Qt data types.
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
void setProperty(int index, const QString &property, const QVariant &value, QList< int > *roles)
QHash< int, QVariant > data(int index, const QList< int > &roles, bool *hasNested=0) const
QScriptClass::QueryFlags queryProperty(Object *, const Identifier &, QScriptClass::QueryFlags flags)
bool inWorkerThread() const
QList< QDeclarativeCustomParserProperty > properties() const
void move(int from, int to, int count)
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
bool insert(int index, const QScriptValue &)
QScriptValue property(const QString &name, const ResolveFlags &mode=ResolvePrototype) const
Returns the value of this QScriptValue's property with the given name, using the given mode to resolv...
void setCustomData(QObject *, const QByteArray &)
#define QT_END_NAMESPACE
This macro expands to.
void moveNodes(int from, int to, int n)
ModelObject(ModelNode *node, NestedListModel *model, QScriptEngine *seng)
void clear()
Removes all items from the hash.
char * data()
Returns a pointer to the data stored in the byte array.
static void setContextForObject(QObject *, QDeclarativeContext *)
Sets the QDeclarativeContext for the object to context.
QHash< QString, ModelNode * > properties
#define it(className, varName)
ModelNodeMetaObject * m_meta
QByteArray & append(char c)
Appends the character ch to this byte array.
virtual QVariant data(int index, int role) const
Returns the data at the given index for the specified roles.
static QScriptValue newObject(QScriptEngine *, QScriptDeclarativeClass *, Object *)
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
QByteArray compile(const QList< QDeclarativeCustomParserProperty > &)
qint32 toInt32() const
Returns the signed 32-bit integer value of this QScriptValue, using the conversion rules described in...
The QByteArray class provides an array of bytes.
QScriptValue toScriptValue(const T &value)
Creates a QScriptValue with the given value.
int length() const
Returns the number of characters in this string.
Value property(Object *, const Identifier &)
friend class FlatListModel
QList< int > roles() const
void changedData(int index, int count, const QList< int > &roles)
QDeclarativeListModel(QObject *parent=0)
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
QList< QVariant > assignedValues() const
QString name() const
Returns the name of the last property that was jumped over using next() or previous().
QVariant data(int index, int role) const
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
void set(int index, const QScriptValue &, QList< int > *roles)
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
void insert(int i, const T &t)
Inserts value at index position i in the list.
friend class FlatListScriptClass
bool insert(int index, const QScriptValue &)
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QStack class is a template class that provides a stack.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Q_INVOKABLE void move(int from, int to, int count)
bool setObjectValue(const QScriptValue &valuemap, bool writeToCache=true)
The QString class provides a Unicode character string.
The QHash class is a template class that provides a hash-table-based dictionary.
void setProperty(int index, const QString &property, const QVariant &value, QList< int > *roles)
void changedProperty(const QString &name) const
QString toString(int role) const
The QObject class is the base class of all Qt objects.
bool startsWith(const QByteArray &a) const
Returns true if this byte array starts with byte array ba; otherwise returns false.
void itemsRemoved(int index, int count)
Emit this signal when count items are removed at index.
virtual QString toString(int role) const
Returns a string description of the specified role.
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
const T value(const Key &key) const
Returns the value associated with the key.
The QScriptDeclarativeClass::Value class acts as a container for JavaScript data types.
void insertedNode(int index)
QDeclarativeListModel * m_listModel
Q_INVOKABLE void setProperty(int index, const QString &property, const QVariant &value)
Q_INVOKABLE void set(int index, const QScriptValue &)
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
T pop()
Removes the top item from the stack and returns it.
void append(const T &t)
Inserts value at the end of the list.
FlatListScriptClass * m_scriptClass
The QScriptEngine class provides an environment for evaluating Qt Script code.
QList< FlatNodeData * > m_nodeData
int indexOf(const QRegExp &rx, int from=0) const
Returns the index position of the first exact match of rx in the list, searching forward from index p...
#define QT_BEGIN_NAMESPACE
This macro expands to.
void addData(FlatNodeObjectData *data)
bool definesEmptyList(const QString &)
Q_INVOKABLE void append(const QScriptValue &)
QDeclarativeListModel * m_listModel
QScriptEngine * engine() const
Q_INVOKABLE QScriptValue get(int index) const
const T & at(int i) const
Returns the item at index position i in the list.
QVariant toVariant() const
Returns the QVariant value of this QScriptValue, if it can be converted to a QVariant; otherwise retu...
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
bool isEmpty() const
Returns true if the hash contains no items; otherwise returns false.
static QScriptValue qmlScriptObject(QObject *, QDeclarativeEngine *)
Creates a QScriptValue allowing you to use object in QML script.
Q_CORE_EXPORT void qWarning(const char *,...)
QList< QHash< int, QVariant > > m_values
QDeclarativeListModelWorkerAgent * agent()
QScriptValue newObject()
Creates a QtScript object of class Object.
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
QVariant valueForNode(ModelNode *, bool *hasNested=0) const
The QListModelInterface class can be subclassed to provide C++ models to QDeclarativeGraphics Views...
void removedNode(int index)
T value(int i) const
Returns the value at index position i in the list.
QHash< int, QString > m_roles
FlatListScriptClass(FlatListModel *model, QScriptEngine *seng)
void clear()
Removes all items from the list.
const Key & key() const
Returns the current item's key as a const reference.
bool isVariant() const
Returns true if this QScriptValue is a variant value; otherwise returns false.
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
void replace(int i, const T &t)
Replaces the item at index position i with value.
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
QDeclarativeListModel * model(const NestedListModel *model)
void push(const T &t)
Adds element t to the top of the stack.
NestedListModel * m_nested
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
ModelObject * object(const NestedListModel *model)
void itemsChanged(int index, int count, const QList< int > &roles)
Emit this signal when count items at index have had their roles changed.
int length() const
Same as size().
NestedListModel(QDeclarativeListModel *base)
QHash< QString, int > m_strings
const char * constData() const
Returns a pointer to the data stored in the byte array.
virtual QList< int > roles() const
Returns the list of roles for which the list model interface provides data.
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
Sets the value of this QScriptValue's property with the given name to the given value.
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
int userType() const
Returns the storage type of the value stored in the variant.
FlatListModel(QDeclarativeListModel *base)
The QScriptValueIterator class provides a Java-style iterator for QScriptValue.
bool compileProperty(const QDeclarativeCustomParserProperty &prop, QList< ListInstruction > &instr, QByteArray &data)
Q_DECLARATIVE_EXPORT QDeclarativeEngine * qmlEngine(const QObject *)
int count(char c) const
Returns the number of occurrences of character ch in the byte array.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
QDeclarativeListModel * modelCache
virtual int count() const
Returns the number of data entries in the model.
The QDeclarativeEngine class provides an environment for instantiating QML components.
QDeclarativeListModelWorkerAgent * m_parentAgent
static void dump(ModelNode *node, int ind)
bool isRegExp() const
Returns true if this QScriptValue is an object of the RegExp class; otherwise returns false...
bool compare(Object *, Object *)
enum QDeclarativeListModelParser::ListInstruction::@152 type
Q_INVOKABLE void insert(int index, const QScriptValue &)
QList< T > values() const
Returns a list containing all the values in the hash, in an arbitrary order.
QObject * parent() const
Returns a pointer to the parent object.
QScriptValue value() const
Returns the value of the last property that was jumped over using next() or previous().
void itemsInserted(int index, int count)
Emit this signal when count items are inserted at index.
T & last()
Returns a reference to the last item in the list.
QDeclarativeListModelWorkerAgent * m_agent
void resize(int size)
Sets the size of the byte array to size bytes.
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
QScriptValue get(int index) const
T qvariant_cast(const QVariant &)
QList< int > roles() const
T takeAt(int i)
Removes the item at index position i and returns it.
static const QCssKnownValue properties[NumProperties - 1]
void qdeclarativelistmodel_move(int from, int to, int n, T *items)
QVariant property(const char *name) const
Returns the value of the object's name property.
bool isDate() const
Returns true if this QScriptValue is an object of the Date class; otherwise returns false...
void itemsMoved(int from, int to, int count)
Emit this signal when count items are moved from index from to index to.
void setListValue(const QScriptValue &valuelist)
int count(const Key &key) const
Returns the number of items associated with the key.
void setValue(const QByteArray &name, const QVariant &val)
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
QScriptEngine * m_scriptEngine
QString toString(int role) const
QScriptValue undefinedValue()
Returns a QScriptValue of the primitive type Undefined.
static QDeclarativeContext * contextForObject(const QObject *)
Returns the QDeclarativeContext for the object, or 0 if no context has been set.
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
ModelObject * objectCache
NestedListModel * m_model
bool canMove(int from, int to, int n) const
friend class FlatNodeData
bool isArray() const
Returns true if this QScriptValue is an object of the Array class; otherwise returns false...
QDeclarativeInfo qmlInfo(const QObject *me)
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
void set(int index, const QScriptValue &, QList< int > *roles)
void setProperty(Object *, const Identifier &name, const QScriptValue &)
void removeData(FlatNodeObjectData *data)
ModelNode(NestedListModel *model)
bool addValue(const QScriptValue &value, QHash< int, QVariant > *row, QList< int > *roles)
The QScriptValue class acts as a container for the Qt Script data types.
friend class QDeclarativeListModelWorkerAgent
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
QString toString(const Identifier &)
QList< Key > keys() const
Returns a list containing all the keys in the hash, in an arbitrary order.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
bool setProperty(const QString &prop, const QVariant &val)
void next()
Advances the iterator by one position.
void move(int from, int to, int count)
QScriptValue newVariant(const QVariant &value)
Creates a QtScript object holding the given variant value.
bool isObject() const
Returns true if this QScriptValue is of the Object type; otherwise returns false. ...
void setNodeUpdatesEnabled(bool enable)
QScriptValue get(int index) const
void reserve(int size)
Reserve space for alloc elements.
bool hasNext() const
Returns true if there is at least one item ahead of the iterator (i.e.
bool endsWith(const QByteArray &a) const
Returns true if this byte array ends with byte array ba; otherwise returns false. ...
Q_INVOKABLE void remove(int index)
T & top()
Returns a reference to the stack's top item.
ListInstruction * instructions() const
void removeAt(int i)
Removes the item at index position i.