MCPcopy Create free account
hub / github.com/Martchus/syncthingtray / insertLocalItems

Method insertLocalItems

syncthingmodel/syncthingfilemodel.cpp:1250–1324  ·  view source on GitHub ↗

! * \brief Inserts items from local lookup that are not already present via the database query (usually ignored files). */

Source from the content-addressed store, hash-verified

1248 * \brief Inserts items from local lookup that are not already present via the database query (usually ignored files).
1249 */
1250void SyncthingFileModel::insertLocalItems(const QModelIndex &refreshedIndex, SyncthingFileModel::LocalItemMap &localItems)
1251{
1252 // get refreshed index/item
1253 auto *const refreshedItem = reinterpret_cast<SyncthingItem *>(refreshedIndex.internalPointer());
1254 auto &items = refreshedItem->children;
1255 const auto hasDbItems = !items.empty() && items.front()->type != SyncthingItemType::Error;
1256 const auto previouslyPopulated = refreshedItem->childrenPopulated;
1257 const auto previousChildCount = items.size();
1258 if (!refreshedItem->existsInDb.value_or(false)) {
1259 refreshedItem->childrenPopulated = true;
1260 }
1261
1262 // clear loading item
1263 if (!refreshedItem->existsInDb.value_or(false) && !items.empty()) {
1264 const auto last = items.size() - 1;
1265 beginRemoveRows(refreshedIndex, 0, last < std::numeric_limits<int>::max() ? static_cast<int>(last) : std::numeric_limits<int>::max());
1266 items.clear();
1267 endRemoveRows();
1268 }
1269
1270 // insert items from local lookup that are not already present via the database query (probably ignored files)
1271 auto index = items.size();
1272 auto row = index < std::numeric_limits<int>::max() ? static_cast<int>(index) : std::numeric_limits<int>::max();
1273 auto firstRow = row;
1274 for (auto &[localItemName, localItem] : localItems) {
1275 if (localItem.existsInDb.value_or(false)) {
1276 continue;
1277 }
1278 beginInsertRows(refreshedIndex, row, row);
1279 auto &item = items.emplace_back(std::make_unique<SyncthingItem>(std::move(localItem)));
1280 item->parent = refreshedItem;
1281 item->index = localItem.index = index++;
1282 if (hasDbItems) {
1283 item->existsInDb = false;
1284 }
1285 switch (refreshedItem->checked) {
1286 case Qt::Checked:
1287 if (m_recursiveSelectionEnabled) {
1288 setChildrenChecked(item.get(), item->checked = Qt::Checked);
1289 }
1290 break;
1291 case Qt::PartiallyChecked:
1292 setCheckState(refreshedIndex, Qt::Unchecked, false);
1293 break;
1294 default:;
1295 }
1296 populatePath(item->path = refreshedItem->path.isEmpty() ? item->name : QString(refreshedItem->path % m_pathSeparator % item->name),
1297 m_pathSeparator, item->children);
1298 endInsertRows();
1299 ++row;
1300 }
1301 if (!previouslyPopulated || items.size() != previousChildCount) {
1302 const auto sizeIndex = refreshedIndex.sibling(refreshedIndex.row(), 1);
1303 emit dataChanged(sizeIndex, sizeIndex, QVector<int>{ Qt::DisplayRole });
1304 emit dataChanged(refreshedIndex, refreshedIndex, QVector<int>{ SizeRole });
1305 }
1306
1307 // insert local child items recursively

Callers

nothing calls this directly

Calls 6

indexMethod · 0.95
setChildrenCheckedFunction · 0.85
populatePathFunction · 0.85
clearMethod · 0.80
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected