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

Method devStatusChanged

syncthingmodel/syncthingdevicemodel.cpp:393–429  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

391}
392
393void SyncthingDeviceModel::devStatusChanged(const SyncthingDev &dev, int index)
394{
395 if (index < 0 || static_cast<std::size_t>(index) >= m_rowCount.size()) {
396 return;
397 }
398
399 // update top-level indices
400 const QModelIndex modelIndex1(this->index(index, 0, QModelIndex()));
401 static const QVector<int> modelRoles1({ Qt::DisplayRole, Qt::EditRole, Qt::DecorationRole, Qt::ForegroundRole, DevicePaused, DeviceStatus,
402 DeviceStatusString, DeviceStatusColor, DeviceId, IsThisDevice, IsPinned, DeviceNeededItemsCount, Group });
403 emit dataChanged(modelIndex1, modelIndex1, modelRoles1);
404 const QModelIndex modelIndex2(this->index(index, 1, QModelIndex()));
405 static const QVector<int> modelRoles2({ Qt::DisplayRole, Qt::EditRole, Qt::ForegroundRole });
406 emit dataChanged(modelIndex2, modelIndex2, modelRoles2);
407
408 // remove/insert detail rows
409 const auto oldRowCount = m_rowCount[static_cast<std::size_t>(index)];
410 const auto newRowCount = computeDeviceRowCount(dev);
411 const auto newLastRow = newRowCount - 1;
412 if (newRowCount < oldRowCount) {
413 // remove surplus rows
414 beginRemoveRows(modelIndex1, newRowCount, oldRowCount - 1);
415 m_rowCount[static_cast<std::size_t>(index)] = newRowCount;
416 endRemoveRows();
417 } else if (oldRowCount < newRowCount) {
418 // insert additional rows
419 beginInsertRows(modelIndex1, oldRowCount, newLastRow);
420 m_rowCount[static_cast<std::size_t>(index)] = newRowCount;
421 endInsertRows();
422 }
423
424 // update detail rows
425 static const QVector<int> modelRoles3({ Qt::DisplayRole, Qt::EditRole, Qt::ToolTipRole, DeviceDetailTooltip });
426 emit dataChanged(this->index(0, 1, modelIndex1), this->index(newLastRow, 1, modelIndex1), modelRoles3);
427 static const QVector<int> modelRoles4({ Qt::DisplayRole, Qt::EditRole, DeviceDetail, DeviceDetailIcon });
428 emit dataChanged(this->index(0, 0, modelIndex1), this->index(newLastRow, 0, modelIndex1), modelRoles4);
429}
430
431void SyncthingDeviceModel::handleConfigInvalidated()
432{

Callers

nothing calls this directly

Calls 3

indexMethod · 0.95
computeDeviceRowCountFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected