Changeset View
Changeset View
Standalone View
Standalone View
src/declarativeimports/core/datamodel.cpp
Show First 20 Lines • Show All 262 Lines • ▼ Show 20 Line(s) | 262 | if (!m_sourceFilter.isEmpty() && m_sourceFilterRE.isValid() && !m_sourceFilterRE.exactMatch(sourceName)) { | |||
---|---|---|---|---|---|
263 | return; | 263 | return; | ||
264 | } | 264 | } | ||
265 | 265 | | |||
266 | if (m_keyRoleFilter.isEmpty()) { | 266 | if (m_keyRoleFilter.isEmpty()) { | ||
267 | //an item is represented by a source: keys are roles m_roleLevel == FirstLevel | 267 | //an item is represented by a source: keys are roles m_roleLevel == FirstLevel | ||
268 | QVariantList list; | 268 | QVariantList list; | ||
269 | 269 | | |||
270 | if (!m_dataSource->data()->isEmpty()) { | 270 | if (!m_dataSource->data()->isEmpty()) { | ||
271 | foreach (const QString &key, m_dataSource->data()->keys()) { | 271 | const auto lst = m_dataSource->data()->keys(); | ||
272 | for (const QString &key : lst) { | ||||
272 | if (!m_sourceFilter.isEmpty() && m_sourceFilterRE.isValid() && !m_sourceFilterRE.exactMatch(key)) { | 273 | if (!m_sourceFilter.isEmpty() && m_sourceFilterRE.isValid() && !m_sourceFilterRE.exactMatch(key)) { | ||
273 | continue; | 274 | continue; | ||
274 | } | 275 | } | ||
275 | QVariant value = m_dataSource->data()->value(key); | 276 | QVariant value = m_dataSource->data()->value(key); | ||
276 | if (value.isValid() && value.canConvert<Plasma::DataEngine::Data>()) { | 277 | if (value.isValid() && value.canConvert<Plasma::DataEngine::Data>()) { | ||
277 | Plasma::DataEngine::Data data = value.value<Plasma::DataEngine::Data>(); | 278 | Plasma::DataEngine::Data data = value.value<Plasma::DataEngine::Data>(); | ||
278 | data[QStringLiteral("DataEngineSource")] = key; | 279 | data[QStringLiteral("DataEngineSource")] = key; | ||
279 | list.append(data); | 280 | list.append(data); | ||
Show All 32 Lines | 305 | { | |||
312 | } | 313 | } | ||
313 | 314 | | |||
314 | if (m_dataSource) { | 315 | if (m_dataSource) { | ||
315 | disconnect(m_dataSource, nullptr, this, nullptr); | 316 | disconnect(m_dataSource, nullptr, this, nullptr); | ||
316 | } | 317 | } | ||
317 | 318 | | |||
318 | m_dataSource = source; | 319 | m_dataSource = source; | ||
319 | 320 | | |||
320 | foreach (const QString &key, m_dataSource->data()->keys()) { | 321 | const auto keys = m_dataSource->data()->keys(); | ||
322 | for (const QString &key : keys) { | ||||
apol: same?
Also this should clearly be using iterators, no? | |||||
broulik: Yes, please change it to iterators | |||||
321 | dataUpdated(key, m_dataSource->data()->value(key).value<Plasma::DataEngine::Data>()); | 323 | dataUpdated(key, m_dataSource->data()->value(key).value<Plasma::DataEngine::Data>()); | ||
322 | } | 324 | } | ||
323 | 325 | | |||
324 | connect(m_dataSource, &DataSource::newData, | 326 | connect(m_dataSource, &DataSource::newData, | ||
325 | this, &DataModel::dataUpdated); | 327 | this, &DataModel::dataUpdated); | ||
326 | connect(m_dataSource, &DataSource::sourceRemoved, | 328 | connect(m_dataSource, &DataSource::sourceRemoved, | ||
327 | this, &DataModel::removeSource); | 329 | this, &DataModel::removeSource); | ||
328 | connect(m_dataSource, &DataSource::sourceDisconnected, | 330 | connect(m_dataSource, &DataSource::sourceDisconnected, | ||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Line(s) | 384 | { | |||
403 | } else if (delta < 0) { | 405 | } else if (delta < 0) { | ||
404 | beginRemoveRows(QModelIndex(), sourceIndex + list.length(), sourceIndex + oldLength - 1); | 406 | beginRemoveRows(QModelIndex(), sourceIndex + list.length(), sourceIndex + oldLength - 1); | ||
405 | } | 407 | } | ||
406 | //convert to vector, so data() will be O(1) | 408 | //convert to vector, so data() will be O(1) | ||
407 | m_items[sourceName] = list.toVector(); | 409 | m_items[sourceName] = list.toVector(); | ||
408 | 410 | | |||
409 | if (!list.isEmpty()) { | 411 | if (!list.isEmpty()) { | ||
410 | if (list.first().canConvert<QVariantMap>()) { | 412 | if (list.first().canConvert<QVariantMap>()) { | ||
411 | foreach (const QVariant &item, list) { | 413 | for (const QVariant &item : list) { | ||
apol: It already is const. | |||||
412 | const QVariantMap &vh = item.value<QVariantMap>(); | 414 | const QVariantMap &vh = item.value<QVariantMap>(); | ||
413 | QMapIterator<QString, QVariant> it(vh); | 415 | QMapIterator<QString, QVariant> it(vh); | ||
414 | while (it.hasNext()) { | 416 | while (it.hasNext()) { | ||
415 | it.next(); | 417 | it.next(); | ||
416 | const QString &roleName = it.key(); | 418 | const QString &roleName = it.key(); | ||
417 | if (!m_roleIds.contains(roleName)) { | 419 | if (!m_roleIds.contains(roleName)) { | ||
418 | ++m_maxRoleId; | 420 | ++m_maxRoleId; | ||
419 | m_roleNames[m_maxRoleId] = roleName.toLatin1(); | 421 | m_roleNames[m_maxRoleId] = roleName.toLatin1(); | ||
420 | m_roleIds[roleName] = m_maxRoleId; | 422 | m_roleIds[roleName] = m_maxRoleId; | ||
421 | } | 423 | } | ||
422 | } | 424 | } | ||
423 | } | 425 | } | ||
424 | } else { | 426 | } else { | ||
425 | foreach (const QVariant &item, list) { | 427 | for (const QVariant &item : list) { | ||
426 | const QVariantMap &vh = item.value<QVariantMap>(); | 428 | const QVariantMap &vh = item.value<QVariantMap>(); | ||
427 | QMapIterator<QString, QVariant> it(vh); | 429 | QMapIterator<QString, QVariant> it(vh); | ||
428 | while (it.hasNext()) { | 430 | while (it.hasNext()) { | ||
429 | it.next(); | 431 | it.next(); | ||
430 | const QString &roleName = it.key(); | 432 | const QString &roleName = it.key(); | ||
431 | if (!m_roleIds.contains(roleName)) { | 433 | if (!m_roleIds.contains(roleName)) { | ||
432 | ++m_maxRoleId; | 434 | ++m_maxRoleId; | ||
433 | m_roleNames[m_maxRoleId] = roleName.toLatin1(); | 435 | m_roleNames[m_maxRoleId] = roleName.toLatin1(); | ||
▲ Show 20 Lines • Show All 153 Lines • Show Last 20 Lines |
same?
Also this should clearly be using iterators, no?