Use immediately invoked lambda to implement roleNames()
Because I can
This commit is contained in:
parent
0acfdd7002
commit
5932c98b1d
|
@ -19,23 +19,20 @@ SyncthingDeviceModel::SyncthingDeviceModel(SyncthingConnection &connection, QObj
|
|||
connect(&m_connection, &SyncthingConnection::devStatusChanged, this, &SyncthingDeviceModel::devStatusChanged);
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> SyncthingDeviceModel::initRoleNames()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> SyncthingDeviceModel::roleNames() const
|
||||
{
|
||||
const static QHash<int, QByteArray> roles(initRoleNames());
|
||||
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;
|
||||
}());
|
||||
return roles;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,6 @@ private Q_SLOTS:
|
|||
void devStatusChanged(const SyncthingDev &, int index);
|
||||
|
||||
private:
|
||||
static QHash<int, QByteArray> initRoleNames();
|
||||
static QString devStatusString(const SyncthingDev &dev);
|
||||
QVariant devStatusColor(const SyncthingDev &dev) const;
|
||||
|
||||
|
|
|
@ -24,24 +24,21 @@ SyncthingDirectoryModel::SyncthingDirectoryModel(SyncthingConnection &connection
|
|||
connect(&m_connection, &SyncthingConnection::dirStatusChanged, this, &SyncthingDirectoryModel::dirStatusChanged);
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> SyncthingDirectoryModel::initRoleNames()
|
||||
{
|
||||
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[DirectoryDetail] = "detail";
|
||||
return roles;
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> SyncthingDirectoryModel::roleNames() const
|
||||
{
|
||||
const static QHash<int, QByteArray> roles(initRoleNames());
|
||||
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[DirectoryDetail] = "detail";
|
||||
return roles;
|
||||
}());
|
||||
return roles;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,6 @@ private Q_SLOTS:
|
|||
void dirStatusChanged(const SyncthingDir &, int index);
|
||||
|
||||
private:
|
||||
static QHash<int, QByteArray> initRoleNames();
|
||||
static QString dirStatusString(const SyncthingDir &dir);
|
||||
QVariant dirStatusColor(const SyncthingDir &dir) const;
|
||||
|
||||
|
|
|
@ -34,20 +34,17 @@ SyncthingDownloadModel::SyncthingDownloadModel(SyncthingConnection &connection,
|
|||
connect(&m_connection, &SyncthingConnection::downloadProgressChanged, this, &SyncthingDownloadModel::downloadProgressChanged);
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> SyncthingDownloadModel::initRoleNames()
|
||||
{
|
||||
QHash<int, QByteArray> roles;
|
||||
roles[Qt::DisplayRole] = "name";
|
||||
roles[Qt::DecorationRole] = "fileIcon";
|
||||
roles[ItemPercentage] = "percentage";
|
||||
roles[ItemProgressLabel] = "progressLabel";
|
||||
roles[ItemPath] = "path";
|
||||
return roles;
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> SyncthingDownloadModel::roleNames() const
|
||||
{
|
||||
const static QHash<int, QByteArray> roles(initRoleNames());
|
||||
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;
|
||||
}());
|
||||
return roles;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,8 +54,6 @@ private:
|
|||
bool operator==(const SyncthingDir *dir) const;
|
||||
};
|
||||
|
||||
static QHash<int, QByteArray> initRoleNames();
|
||||
|
||||
const std::vector<SyncthingDir> &m_dirs;
|
||||
const QIcon m_unknownIcon;
|
||||
const QFileIconProvider m_fileIconProvider;
|
||||
|
|
Loading…
Reference in New Issue