Changeset View
Changeset View
Standalone View
Standalone View
src/core/itemsmodel.cpp
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | |||||
61 | { | 61 | { | ||
62 | for (const KNSCore::EntryInternal &entry : entries) { | 62 | for (const KNSCore::EntryInternal &entry : entries) { | ||
63 | addEntry(entry); | 63 | addEntry(entry); | ||
64 | } | 64 | } | ||
65 | } | 65 | } | ||
66 | 66 | | |||
67 | void ItemsModel::addEntry(const EntryInternal &entry) | 67 | void ItemsModel::addEntry(const EntryInternal &entry) | ||
68 | { | 68 | { | ||
69 | // This might be expensive, but it avoids duplicates, which is not awesome for the user | ||||
70 | if (!m_entries.contains(entry)) { | ||||
69 | QString preview = entry.previewUrl(EntryInternal::PreviewSmall1); | 71 | QString preview = entry.previewUrl(EntryInternal::PreviewSmall1); | ||
alex: Use qAsConst(m_entries) and space before & not after :-) | |||||
leinir: Quite, thank you :) | |||||
alex: On second thought why not just use:
`bool duplicate = m_entries.contains(entry);` | |||||
Hmm... i do wonder slight of the cost of that, but also... much simpler code, so... basically can just go if (!m_entries.contains(entry)) { below, rather than this more elaborate version. leinir: Hmm... i do wonder slight of the cost of that, but also... much simpler code, so... basically… | |||||
70 | if (!m_hasPreviewImages && !preview.isEmpty()) { | 72 | if (!m_hasPreviewImages && !preview.isEmpty()) { | ||
71 | m_hasPreviewImages = true; | 73 | m_hasPreviewImages = true; | ||
72 | if (rowCount() > 0) { | 74 | if (rowCount() > 0) { | ||
73 | emit dataChanged(index(0, 0), index(rowCount() - 1, 0)); | 75 | emit dataChanged(index(0, 0), index(rowCount() - 1, 0)); | ||
74 | } | 76 | } | ||
75 | } | 77 | } | ||
76 | 78 | | |||
77 | qCDebug(KNEWSTUFFCORE) << "adding entry " << entry.name() << " to the model"; | 79 | qCDebug(KNEWSTUFFCORE) << "adding entry " << entry.name() << " to the model"; | ||
78 | beginInsertRows(QModelIndex(), m_entries.count(), m_entries.count()); | 80 | beginInsertRows(QModelIndex(), m_entries.count(), m_entries.count()); | ||
79 | m_entries.append(entry); | 81 | m_entries.append(entry); | ||
80 | endInsertRows(); | 82 | endInsertRows(); | ||
81 | 83 | | |||
82 | if (!preview.isEmpty() && entry.previewImage(EntryInternal::PreviewSmall1).isNull()) { | 84 | if (!preview.isEmpty() && entry.previewImage(EntryInternal::PreviewSmall1).isNull()) { | ||
83 | m_engine->loadPreview(entry, EntryInternal::PreviewSmall1); | 85 | m_engine->loadPreview(entry, EntryInternal::PreviewSmall1); | ||
84 | } | 86 | } | ||
85 | } | 87 | } | ||
88 | } | ||||
86 | 89 | | |||
87 | void ItemsModel::removeEntry(const EntryInternal &entry) | 90 | void ItemsModel::removeEntry(const EntryInternal &entry) | ||
88 | { | 91 | { | ||
89 | qCDebug(KNEWSTUFFCORE) << "removing entry " << entry.name() << " from the model"; | 92 | qCDebug(KNEWSTUFFCORE) << "removing entry " << entry.name() << " from the model"; | ||
90 | int index = m_entries.indexOf(entry); | 93 | int index = m_entries.indexOf(entry); | ||
91 | if (index > -1) { | 94 | if (index > -1) { | ||
92 | beginRemoveRows(QModelIndex(), index, index); | 95 | beginRemoveRows(QModelIndex(), index, index); | ||
93 | m_entries.removeAt(index); | 96 | m_entries.removeAt(index); | ||
▲ Show 20 Lines • Show All 61 Lines • Show Last 20 Lines |
Use qAsConst(m_entries) and space before & not after :-)