Changeset View
Changeset View
Standalone View
Standalone View
src/declarativeimports/core/datamodel.cpp
Show First 20 Lines • Show All 250 Lines • ▼ Show 20 Line(s) | 250 | if (!m_sourceFilter.isEmpty() && m_sourceFilterRE.isValid() && !m_sourceFilterRE.exactMatch(sourceName)) { | |||
---|---|---|---|---|---|
251 | return; | 251 | return; | ||
252 | } | 252 | } | ||
253 | 253 | | |||
254 | if (m_keyRoleFilter.isEmpty()) { | 254 | if (m_keyRoleFilter.isEmpty()) { | ||
255 | //an item is represented by a source: keys are roles m_roleLevel == FirstLevel | 255 | //an item is represented by a source: keys are roles m_roleLevel == FirstLevel | ||
256 | QVariantList list; | 256 | QVariantList list; | ||
257 | 257 | | |||
258 | if (!m_dataSource->data()->isEmpty()) { | 258 | if (!m_dataSource->data()->isEmpty()) { | ||
259 | foreach (const QString &key, m_dataSource->data()->keys()) { | 259 | const auto lst = m_dataSource->data()->keys(); | ||
260 | for (const QString &key : lst) { | ||||
260 | if (!m_sourceFilter.isEmpty() && m_sourceFilterRE.isValid() && !m_sourceFilterRE.exactMatch(key)) { | 261 | if (!m_sourceFilter.isEmpty() && m_sourceFilterRE.isValid() && !m_sourceFilterRE.exactMatch(key)) { | ||
261 | continue; | 262 | continue; | ||
262 | } | 263 | } | ||
263 | QVariant value = m_dataSource->data()->value(key); | 264 | QVariant value = m_dataSource->data()->value(key); | ||
264 | if (value.isValid() && value.canConvert<Plasma::DataEngine::Data>()) { | 265 | if (value.isValid() && value.canConvert<Plasma::DataEngine::Data>()) { | ||
265 | Plasma::DataEngine::Data data = value.value<Plasma::DataEngine::Data>(); | 266 | Plasma::DataEngine::Data data = value.value<Plasma::DataEngine::Data>(); | ||
266 | data[QStringLiteral("DataEngineSource")] = key; | 267 | data[QStringLiteral("DataEngineSource")] = key; | ||
267 | list.append(data); | 268 | list.append(data); | ||
Show All 32 Lines | 293 | { | |||
300 | } | 301 | } | ||
301 | 302 | | |||
302 | if (m_dataSource) { | 303 | if (m_dataSource) { | ||
303 | disconnect(m_dataSource, nullptr, this, nullptr); | 304 | disconnect(m_dataSource, nullptr, this, nullptr); | ||
304 | } | 305 | } | ||
305 | 306 | | |||
306 | m_dataSource = source; | 307 | m_dataSource = source; | ||
307 | 308 | | |||
308 | foreach (const QString &key, m_dataSource->data()->keys()) { | 309 | const auto keys = m_dataSource->data()->keys(); | ||
310 | for (const QString &key : keys) { | ||||
apol: same?
Also this should clearly be using iterators, no? | |||||
broulik: Yes, please change it to iterators | |||||
309 | dataUpdated(key, m_dataSource->data()->value(key).value<Plasma::DataEngine::Data>()); | 311 | dataUpdated(key, m_dataSource->data()->value(key).value<Plasma::DataEngine::Data>()); | ||
310 | } | 312 | } | ||
311 | 313 | | |||
312 | connect(m_dataSource, &DataSource::newData, | 314 | connect(m_dataSource, &DataSource::newData, | ||
313 | this, &DataModel::dataUpdated); | 315 | this, &DataModel::dataUpdated); | ||
314 | connect(m_dataSource, &DataSource::sourceRemoved, | 316 | connect(m_dataSource, &DataSource::sourceRemoved, | ||
315 | this, &DataModel::removeSource); | 317 | this, &DataModel::removeSource); | ||
316 | connect(m_dataSource, &DataSource::sourceDisconnected, | 318 | connect(m_dataSource, &DataSource::sourceDisconnected, | ||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Line(s) | 372 | { | |||
391 | } else if (delta < 0) { | 393 | } else if (delta < 0) { | ||
392 | beginRemoveRows(QModelIndex(), sourceIndex + list.length(), sourceIndex + oldLength - 1); | 394 | beginRemoveRows(QModelIndex(), sourceIndex + list.length(), sourceIndex + oldLength - 1); | ||
393 | } | 395 | } | ||
394 | //convert to vector, so data() will be O(1) | 396 | //convert to vector, so data() will be O(1) | ||
395 | m_items[sourceName] = list.toVector(); | 397 | m_items[sourceName] = list.toVector(); | ||
396 | 398 | | |||
397 | if (!list.isEmpty()) { | 399 | if (!list.isEmpty()) { | ||
398 | if (list.first().canConvert<QVariantMap>()) { | 400 | if (list.first().canConvert<QVariantMap>()) { | ||
399 | foreach (const QVariant &item, list) { | 401 | for (const QVariant &item : list) { | ||
apol: It already is const. | |||||
400 | const QVariantMap &vh = item.value<QVariantMap>(); | 402 | const QVariantMap &vh = item.value<QVariantMap>(); | ||
401 | QMapIterator<QString, QVariant> it(vh); | 403 | QMapIterator<QString, QVariant> it(vh); | ||
402 | while (it.hasNext()) { | 404 | while (it.hasNext()) { | ||
403 | it.next(); | 405 | it.next(); | ||
404 | const QString &roleName = it.key(); | 406 | const QString &roleName = it.key(); | ||
405 | if (!m_roleIds.contains(roleName)) { | 407 | if (!m_roleIds.contains(roleName)) { | ||
406 | ++m_maxRoleId; | 408 | ++m_maxRoleId; | ||
407 | m_roleNames[m_maxRoleId] = roleName.toLatin1(); | 409 | m_roleNames[m_maxRoleId] = roleName.toLatin1(); | ||
408 | m_roleIds[roleName] = m_maxRoleId; | 410 | m_roleIds[roleName] = m_maxRoleId; | ||
409 | } | 411 | } | ||
410 | } | 412 | } | ||
411 | } | 413 | } | ||
412 | } else { | 414 | } else { | ||
413 | foreach (const QVariant &item, list) { | 415 | for (const QVariant &item : list) { | ||
414 | const QVariantMap &vh = item.value<QVariantMap>(); | 416 | const QVariantMap &vh = item.value<QVariantMap>(); | ||
415 | QMapIterator<QString, QVariant> it(vh); | 417 | QMapIterator<QString, QVariant> it(vh); | ||
416 | while (it.hasNext()) { | 418 | while (it.hasNext()) { | ||
417 | it.next(); | 419 | it.next(); | ||
418 | const QString &roleName = it.key(); | 420 | const QString &roleName = it.key(); | ||
419 | if (!m_roleIds.contains(roleName)) { | 421 | if (!m_roleIds.contains(roleName)) { | ||
420 | ++m_maxRoleId; | 422 | ++m_maxRoleId; | ||
421 | m_roleNames[m_maxRoleId] = roleName.toLatin1(); | 423 | 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?