Skip to content

Commit

Permalink
Improve initialization of roleNames()
Browse files Browse the repository at this point in the history
  • Loading branch information
Martchus committed Nov 3, 2018
1 parent d803f83 commit 1d75ee2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 35 deletions.
22 changes: 10 additions & 12 deletions model/syncthingdevicemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,16 @@ SyncthingDeviceModel::SyncthingDeviceModel(SyncthingConnection &connection, QObj

QHash<int, QByteArray> SyncthingDeviceModel::roleNames() const
{
const static auto roles([] {
QHash<int, QByteArray> roles;
roles[Qt::DisplayRole] = "name";
roles[DeviceStatus] = "status";
roles[Qt::DecorationRole] = "statusIcon";
roles[DevicePaused] = "paused";
roles[DeviceStatusString] = "statusString";
roles[DeviceStatusColor] = "statusColor";
roles[DeviceId] = "devId";
roles[DeviceDetail] = "detail";
return roles;
}());
const static QHash<int, QByteArray> roles{
{ Qt::DisplayRole, "name" },
{ DeviceStatus, "status" },
{ Qt::DecorationRole, "statusIcon" },
{ DevicePaused, "paused" },
{ DeviceStatusString, "statusString" },
{ DeviceStatusColor, "statusColor" },
{ DeviceId, "devId" },
{ DeviceDetail, "detail" },
};
return roles;
}

Expand Down
26 changes: 12 additions & 14 deletions model/syncthingdirectorymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,18 @@ SyncthingDirectoryModel::SyncthingDirectoryModel(SyncthingConnection &connection

QHash<int, QByteArray> SyncthingDirectoryModel::roleNames() const
{
const static auto roles([] {
QHash<int, QByteArray> roles;
roles[Qt::DisplayRole] = "name";
roles[DirectoryStatus] = "status";
roles[Qt::DecorationRole] = "statusIcon";
roles[DirectoryStatusString] = "statusString";
roles[DirectoryStatusColor] = "statusColor";
roles[DirectoryPaused] = "paused";
roles[DirectoryId] = "dirId";
roles[DirectoryPath] = "path";
roles[DirectoryPullErrorCount] = "pullErrorCount";
roles[DirectoryDetail] = "detail";
return roles;
}());
const static QHash<int, QByteArray> roles{
{ Qt::DisplayRole, "name" },
{ DirectoryStatus, "status" },
{ Qt::DecorationRole, "statusIcon" },
{ DirectoryStatusString, "statusString" },
{ DirectoryStatusColor, "statusColor" },
{ DirectoryPaused, "paused" },
{ DirectoryId, "dirId" },
{ DirectoryPath, "path" },
{ DirectoryPullErrorCount, "pullErrorCount" },
{ DirectoryDetail, "detail" },
};
return roles;
}

Expand Down
16 changes: 7 additions & 9 deletions model/syncthingdownloadmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@ SyncthingDownloadModel::SyncthingDownloadModel(SyncthingConnection &connection,

QHash<int, QByteArray> SyncthingDownloadModel::roleNames() const
{
const static auto roles([] {
QHash<int, QByteArray> roles;
roles[Qt::DisplayRole] = "name";
roles[Qt::DecorationRole] = "fileIcon";
roles[ItemPercentage] = "percentage";
roles[ItemProgressLabel] = "progressLabel";
roles[ItemPath] = "path";
return roles;
}());
const static QHash<int, QByteArray> roles{
{ Qt::DisplayRole, "name" },
{ Qt::DecorationRole, "fileIcon" },
{ ItemPercentage, "percentage" },
{ ItemProgressLabel, "progressLabel" },
{ ItemPath, "path" },
};
return roles;
}

Expand Down

0 comments on commit 1d75ee2

Please sign in to comment.