Skip to content

Commit

Permalink
Explose number of needed items in models
Browse files Browse the repository at this point in the history
  • Loading branch information
Martchus committed Dec 17, 2024
1 parent 2dc2173 commit 778585c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion syncthingmodel/syncthingdevicemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ QHash<int, QByteArray> SyncthingDeviceModel::roleNames() const
{ DeviceId, "devId" },
{ DeviceDetail, "detail" },
{ DeviceDetailIcon, "detailIcon" },
{ DeviceNeededItemsCount, "neededItems" },
};
return roles;
}
Expand Down Expand Up @@ -319,6 +320,8 @@ QVariant SyncthingDeviceModel::data(const QModelIndex &index, int role) const
return devStatusColor(dev);
case DeviceId:
return dev.id;
case DeviceNeededItemsCount:
return dev.overallCompletion.needed.items;
default:;
}
return QVariant();
Expand Down Expand Up @@ -352,7 +355,7 @@ void SyncthingDeviceModel::devStatusChanged(const SyncthingDev &dev, int index)
// update top-level indices
const QModelIndex modelIndex1(this->index(index, 0, QModelIndex()));
static const QVector<int> modelRoles1({ Qt::DisplayRole, Qt::EditRole, Qt::DecorationRole, Qt::ForegroundRole, DevicePaused, DeviceStatus,
DeviceStatusString, DeviceStatusColor, DeviceId, IsThisDevice, IsPinned });
DeviceStatusString, DeviceStatusColor, DeviceId, IsThisDevice, IsPinned, DeviceNeededItemsCount });
emit dataChanged(modelIndex1, modelIndex1, modelRoles1);
const QModelIndex modelIndex2(this->index(index, 1, QModelIndex()));
static const QVector<int> modelRoles2({ Qt::DisplayRole, Qt::EditRole, Qt::ForegroundRole });
Expand Down
1 change: 1 addition & 0 deletions syncthingmodel/syncthingdevicemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class LIB_SYNCTHING_MODEL_EXPORT SyncthingDeviceModel : public SyncthingModel {
DeviceId,
DeviceDetail,
DeviceDetailIcon,
DeviceNeededItemsCount,
};

explicit SyncthingDeviceModel(SyncthingConnection &connection, QObject *parent = nullptr);
Expand Down
5 changes: 4 additions & 1 deletion syncthingmodel/syncthingdirectorymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ QHash<int, QByteArray> SyncthingDirectoryModel::roleNames() const
{ DirectoryPullErrorCount, "pullErrorCount" },
{ DirectoryDetail, "detail" },
{ DirectoryDetailIcon, "detailIcon" },
{ DirectoryNeededItemsCount, "neededItemsCount" },
};
return roles;
}
Expand Down Expand Up @@ -358,6 +359,8 @@ QVariant SyncthingDirectoryModel::data(const QModelIndex &index, int role) const
return dir.path;
case DirectoryPullErrorCount:
return dir.pullErrorCount;
case DirectoryNeededItemsCount:
return dir.neededStats.total;
default:;
}

Expand Down Expand Up @@ -392,7 +395,7 @@ void SyncthingDirectoryModel::dirStatusChanged(const SyncthingDir &dir, int inde
// update top-level indices
const QModelIndex modelIndex1(this->index(index, 0, QModelIndex()));
static const QVector<int> modelRoles1({ Qt::DisplayRole, Qt::EditRole, Qt::DecorationRole, DirectoryPaused, DirectoryStatus,
DirectoryStatusString, DirectoryStatusColor, DirectoryId, DirectoryPath, DirectoryPullErrorCount });
DirectoryStatusString, DirectoryStatusColor, DirectoryId, DirectoryPath, DirectoryPullErrorCount, DirectoryNeededItemsCount });
emit dataChanged(modelIndex1, modelIndex1, modelRoles1);
const QModelIndex modelIndex2(this->index(index, 1, QModelIndex()));
static const QVector<int> modelRoles2({ Qt::DisplayRole, Qt::EditRole, Qt::ForegroundRole });
Expand Down
1 change: 1 addition & 0 deletions syncthingmodel/syncthingdirectorymodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class LIB_SYNCTHING_MODEL_EXPORT SyncthingDirectoryModel : public SyncthingModel
DirectoryPullErrorCount,
DirectoryDetail,
DirectoryDetailIcon,
DirectoryNeededItemsCount,
};

explicit SyncthingDirectoryModel(SyncthingConnection &connection, QObject *parent = nullptr);
Expand Down

0 comments on commit 778585c

Please sign in to comment.