diff options
Diffstat (limited to 'src/qml/types/qqmllistmodel.cpp')
-rw-r--r-- | src/qml/types/qqmllistmodel.cpp | 111 |
1 files changed, 46 insertions, 65 deletions
diff --git a/src/qml/types/qqmllistmodel.cpp b/src/qml/types/qqmllistmodel.cpp index 8574a4784c..cc4ccbaeb1 100644 --- a/src/qml/types/qqmllistmodel.cpp +++ b/src/qml/types/qqmllistmodel.cpp @@ -99,7 +99,7 @@ const ListLayout::Role &ListLayout::getRoleOrCreate(const QString &key, Role::Da if (node) { const Role &r = *node->value; if (type != r.type) - qmlInfo(0) << QStringLiteral("Can't assign to existing role '%1' of different type [%2 -> %3]").arg(r.name).arg(roleTypeName(type)).arg(roleTypeName(r.type)); + qmlWarning(0) << QStringLiteral("Can't assign to existing role '%1' of different type [%2 -> %3]").arg(r.name).arg(roleTypeName(type)).arg(roleTypeName(r.type)); return r; } @@ -112,7 +112,7 @@ const ListLayout::Role &ListLayout::getRoleOrCreate(QV4::String *key, Role::Data if (node) { const Role &r = *node->value; if (type != r.type) - qmlInfo(0) << QStringLiteral("Can't assign to existing role '%1' of different type [%2 -> %3]").arg(r.name).arg(roleTypeName(type)).arg(roleTypeName(r.type)); + qmlWarning(0) << QStringLiteral("Can't assign to existing role '%1' of different type [%2 -> %3]").arg(r.name).arg(roleTypeName(type)).arg(roleTypeName(r.type)); return r; } @@ -226,14 +226,14 @@ const ListLayout::Role *ListLayout::getRoleOrCreate(const QString &key, const QV } if (type == Role::Invalid) { - qmlInfo(0) << "Can't create role for unsupported data type"; + qmlWarning(0) << "Can't create role for unsupported data type"; return 0; } return &getRoleOrCreate(key, type); } -const ListLayout::Role *ListLayout::getExistingRole(const QString &key) +const ListLayout::Role *ListLayout::getExistingRole(const QString &key) const { Role *r = 0; QStringHash<Role *>::Node *node = roleHash.findNode(key); @@ -242,7 +242,7 @@ const ListLayout::Role *ListLayout::getExistingRole(const QString &key) return r; } -const ListLayout::Role *ListLayout::getExistingRole(QV4::String *key) +const ListLayout::Role *ListLayout::getExistingRole(QV4::String *key) const { Role *r = 0; QStringHash<Role *>::Node *node = roleHash.findNode(key); @@ -603,11 +603,8 @@ int ListModel::setOrCreateProperty(int elementIndex, const QString &key, const Q ModelNodeMetaObject *cache = e->objectCache(); - if (roleIndex != -1 && cache) { - QVector<int> roles; - roles << roleIndex; - cache->updateValues(roles); - } + if (roleIndex != -1 && cache) + cache->updateValues(QVector<int>(1, roleIndex)); } } @@ -1204,7 +1201,7 @@ int ListElement::setJsProperty(const ListLayout::Role &role, const QV4::Value &d } roleIndex = setListProperty(role, subModel); } else { - qmlInfo(0) << QStringLiteral("Can't assign to existing role '%1' of different type [%2 -> %3]").arg(role.name).arg(roleTypeName(role.type)).arg(roleTypeName(ListLayout::Role::List)); + qmlWarning(0) << QStringLiteral("Can't assign to existing role '%1' of different type [%2 -> %3]").arg(role.name).arg(roleTypeName(role.type)).arg(roleTypeName(ListLayout::Role::List)); } } else if (d.isBoolean()) { roleIndex = setBoolProperty(role, d.booleanValue()); @@ -1270,10 +1267,12 @@ void ModelNodeMetaObject::updateValues() { const int roleCount = m_model->m_listModel->roleCount(); if (!m_initialized) { - int *changedRoles = reinterpret_cast<int *>(alloca(roleCount * sizeof(int))); - for (int i = 0; i < roleCount; ++i) - changedRoles[i] = i; - emitDirectNotifies(changedRoles, roleCount); + if (roleCount) { + int *changedRoles = reinterpret_cast<int *>(alloca(roleCount * sizeof(int))); + for (int i = 0; i < roleCount; ++i) + changedRoles[i] = i; + emitDirectNotifies(changedRoles, roleCount); + } return; } for (int i=0 ; i < roleCount ; ++i) { @@ -1312,11 +1311,8 @@ void ModelNodeMetaObject::propertyWritten(int index) QV4::ScopedValue v(scope, scope.engine->fromVariant(value)); int roleIndex = m_model->m_listModel->setExistingProperty(m_elementIndex, propName, v, scope.engine); - if (roleIndex != -1) { - QVector<int> roles; - roles << roleIndex; - m_model->emitItemsChanged(m_elementIndex, 1, roles); - } + if (roleIndex != -1) + m_model->emitItemsChanged(m_elementIndex, 1, QVector<int>(1, roleIndex)); } // Does the emission of the notifiers when we haven't created the meta-object yet @@ -1345,11 +1341,8 @@ void ModelObject::put(Managed *m, String *name, const Value &value) const int elementIndex = that->d()->m_elementIndex; const QString propName = name->toQString(); int roleIndex = that->d()->m_model->m_listModel->setExistingProperty(elementIndex, propName, value, eng); - if (roleIndex != -1) { - QVector<int> roles; - roles << roleIndex; - that->d()->m_model->emitItemsChanged(elementIndex, 1, roles); - } + if (roleIndex != -1) + that->d()->m_model->emitItemsChanged(elementIndex, 1, QVector<int>(1, roleIndex)); ModelNodeMetaObject *mo = ModelNodeMetaObject::get(that->object()); if (mo->initialized()) @@ -1543,14 +1536,10 @@ void DynamicRoleModelNodeMetaObject::propertyWritten(int index) } int elementIndex = parentModel->m_modelObjects.indexOf(m_owner); - int roleIndex = parentModel->m_roles.indexOf(QString::fromLatin1(name(index).constData())); - - if (elementIndex != -1 && roleIndex != -1) { - - QVector<int> roles; - roles << roleIndex; - - parentModel->emitItemsChanged(elementIndex, 1, roles); + if (elementIndex != -1) { + int roleIndex = parentModel->m_roles.indexOf(QString::fromLatin1(name(index).constData())); + if (roleIndex != -1) + parentModel->emitItemsChanged(elementIndex, 1, QVector<int>(1, roleIndex)); } } @@ -1919,14 +1908,14 @@ bool QQmlListModel::setData(const QModelIndex &index, const QVariant &value, int if (m_dynamicRoles) { const QByteArray property = m_roles.at(role).toUtf8(); if (m_modelObjects[row]->setValue(property, value)) { - emitItemsChanged(row, 1, QVector<int>() << role); + emitItemsChanged(row, 1, QVector<int>(1, role)); return true; } } else { const ListLayout::Role &r = m_listModel->getExistingRole(role); const int roleIndex = m_listModel->setOrCreateProperty(row, r.name, value); if (roleIndex != -1) { - emitItemsChanged(row, 1, QVector<int>() << role); + emitItemsChanged(row, 1, QVector<int>(1, role)); return true; } } @@ -1997,18 +1986,18 @@ void QQmlListModel::setDynamicRoles(bool enableDynamicRoles) if (m_mainThread && m_agent == 0) { if (enableDynamicRoles) { if (m_layout->roleCount()) - qmlInfo(this) << tr("unable to enable dynamic roles as this model is not empty!"); + qmlWarning(this) << tr("unable to enable dynamic roles as this model is not empty!"); else m_dynamicRoles = true; } else { if (m_roles.count()) { - qmlInfo(this) << tr("unable to enable static roles as this model is not empty!"); + qmlWarning(this) << tr("unable to enable static roles as this model is not empty!"); } else { m_dynamicRoles = false; } } } else { - qmlInfo(this) << tr("dynamic role setting must be made from the main thread, before any worker scripts are created"); + qmlWarning(this) << tr("dynamic role setting must be made from the main thread, before any worker scripts are created"); } } @@ -2061,7 +2050,7 @@ void QQmlListModel::remove(QQmlV4Function *args) int removeCount = (argLength == 2 ? QV4::ScopedValue(scope, (*args)[1])->toInt32() : 1); if (index < 0 || index+removeCount > count() || removeCount <= 0) { - qmlInfo(this) << tr("remove: indices [%1 - %2] out of range [0 - %3]").arg(index).arg(index+removeCount).arg(count()); + qmlWarning(this) << tr("remove: indices [%1 - %2] out of range [0 - %3]").arg(index).arg(index+removeCount).arg(count()); return; } @@ -2077,7 +2066,7 @@ void QQmlListModel::remove(QQmlV4Function *args) emitItemsRemoved(index, removeCount); } else { - qmlInfo(this) << tr("remove: incorrect number of arguments"); + qmlWarning(this) << tr("remove: incorrect number of arguments"); } } @@ -2105,7 +2094,7 @@ void QQmlListModel::insert(QQmlV4Function *args) int index = arg0->toInt32(); if (index < 0 || index > count()) { - qmlInfo(this) << tr("insert: index %1 out of range").arg(index); + qmlWarning(this) << tr("insert: index %1 out of range").arg(index); return; } @@ -2137,10 +2126,10 @@ void QQmlListModel::insert(QQmlV4Function *args) emitItemsInserted(index, 1); } else { - qmlInfo(this) << tr("insert: value is not an object"); + qmlWarning(this) << tr("insert: value is not an object"); } } else { - qmlInfo(this) << tr("insert: value is not an object"); + qmlWarning(this) << tr("insert: value is not an object"); } } @@ -2163,7 +2152,7 @@ void QQmlListModel::move(int from, int to, int n) if (n==0 || from==to) return; if (!canMove(from, to, n)) { - qmlInfo(this) << tr("move: out of range"); + qmlWarning(this) << tr("move: out of range"); return; } @@ -2252,10 +2241,10 @@ void QQmlListModel::append(QQmlV4Function *args) emitItemsInserted(index, 1); } else { - qmlInfo(this) << tr("append: value is not an object"); + qmlWarning(this) << tr("append: value is not an object"); } } else { - qmlInfo(this) << tr("append: value is not an object"); + qmlWarning(this) << tr("append: value is not an object"); } } @@ -2334,11 +2323,11 @@ void QQmlListModel::set(int index, const QQmlV4Handle &handle) QV4::ScopedObject object(scope, handle); if (!object) { - qmlInfo(this) << tr("set: value is not an object"); + qmlWarning(this) << tr("set: value is not an object"); return; } if (index > count() || index < 0) { - qmlInfo(this) << tr("set: index %1 out of range").arg(index); + qmlWarning(this) << tr("set: index %1 out of range").arg(index); return; } @@ -2384,7 +2373,7 @@ void QQmlListModel::set(int index, const QQmlV4Handle &handle) void QQmlListModel::setProperty(int index, const QString& property, const QVariant& value) { if (count() == 0 || index >= count() || index < 0) { - qmlInfo(this) << tr("set: index %1 out of range").arg(index); + qmlWarning(this) << tr("set: index %1 out of range").arg(index); return; } @@ -2394,20 +2383,12 @@ void QQmlListModel::setProperty(int index, const QString& property, const QVaria roleIndex = m_roles.count(); m_roles.append(property); } - if (m_modelObjects[index]->setValue(property.toUtf8(), value)) { - QVector<int> roles; - roles << roleIndex; - emitItemsChanged(index, 1, roles); - } + if (m_modelObjects[index]->setValue(property.toUtf8(), value)) + emitItemsChanged(index, 1, QVector<int>(1, roleIndex)); } else { int roleIndex = m_listModel->setOrCreateProperty(index, property, value); - if (roleIndex != -1) { - - QVector<int> roles; - roles << roleIndex; - - emitItemsChanged(index, 1, roles); - } + if (roleIndex != -1) + emitItemsChanged(index, 1, QVector<int>(1, roleIndex)); } } @@ -2422,7 +2403,7 @@ void QQmlListModel::sync() // This is just a dummy method to make it look like sync() exists in // ListModel (and not just QQmlListModelWorkerAgent) and to let // us document sync(). - qmlInfo(this) << "List sync() can only be called from a WorkerScript"; + qmlWarning(this) << "List sync() can only be called from a WorkerScript"; } bool QQmlListModelParser::verifyProperty(const QV4::CompiledData::Unit *qmlUnit, const QV4::CompiledData::Binding *binding) @@ -2536,7 +2517,7 @@ void QQmlListModelParser::verifyBindings(const QV4::CompiledData::Unit *qmlUnit, { listElementTypeName = QString(); // unknown - foreach (const QV4::CompiledData::Binding *binding, bindings) { + for (const QV4::CompiledData::Binding *binding : bindings) { QString propName = qmlUnit->stringAt(binding->propertyNameIndex); if (!propName.isEmpty()) { // isn't default property error(binding, QQmlListModel::tr("ListModel: undefined property '%1'").arg(propName)); @@ -2557,14 +2538,14 @@ void QQmlListModelParser::applyBindings(QObject *obj, QV4::CompiledData::Compila bool setRoles = false; - foreach (const QV4::CompiledData::Binding *binding, bindings) { + for (const QV4::CompiledData::Binding *binding : bindings) { if (binding->type != QV4::CompiledData::Binding::Type_Object) continue; setRoles |= applyProperty(qmlUnit, binding, rv->m_listModel, /*outter element index*/-1); } if (setRoles == false) - qmlInfo(obj) << "All ListElement declarations are empty, no roles can be created unless dynamicRoles is set."; + qmlWarning(obj) << "All ListElement declarations are empty, no roles can be created unless dynamicRoles is set."; } bool QQmlListModelParser::definesEmptyList(const QString &s) |