| 74 | } |
| 75 | |
| 76 | QVariant DisplayedFilesModel::data(const QModelIndex& index, int role) const |
| 77 | { |
| 78 | QMutexLocker locker(&_mutex); |
| 79 | const int row = index.row(); |
| 80 | if (row < 0 || row >= static_cast<int>(_fileInfoCache.size())) { |
| 81 | return {}; |
| 82 | } |
| 83 | const auto mapEntry = _fileInfoCache.at(row); |
| 84 | switch (const auto roleAsType = static_cast<DisplayedFilesModelRoles>(role)) { |
| 85 | case DisplayedFilesModelRoles::author: // NOLINT(bugprone-branch-clone) |
| 86 | [[fallthrough]]; |
| 87 | case DisplayedFilesModelRoles::baseName: |
| 88 | [[fallthrough]]; |
| 89 | case DisplayedFilesModelRoles::company: |
| 90 | [[fallthrough]]; |
| 91 | case DisplayedFilesModelRoles::creationTime: |
| 92 | [[fallthrough]]; |
| 93 | case DisplayedFilesModelRoles::description: |
| 94 | [[fallthrough]]; |
| 95 | case DisplayedFilesModelRoles::license: |
| 96 | [[fallthrough]]; |
| 97 | case DisplayedFilesModelRoles::modifiedTime: |
| 98 | [[fallthrough]]; |
| 99 | case DisplayedFilesModelRoles::path: |
| 100 | [[fallthrough]]; |
| 101 | case DisplayedFilesModelRoles::size: |
| 102 | if (mapEntry.contains(roleAsType)) { |
| 103 | return QString::fromStdString(mapEntry.at(roleAsType)); |
| 104 | } |
| 105 | break; |
| 106 | case DisplayedFilesModelRoles::image: { |
| 107 | if (const auto path = QString::fromStdString(mapEntry.at(DisplayedFilesModelRoles::path)); |
| 108 | _imageCache.contains(path)) { |
| 109 | return _imageCache[path]; |
| 110 | } |
| 111 | break; |
| 112 | } |
| 113 | default: |
| 114 | break; |
| 115 | } |
| 116 | switch (role) { |
| 117 | case Qt::ItemDataRole::ToolTipRole: { |
| 118 | auto toolTip = QString::fromStdString(mapEntry.at(DisplayedFilesModelRoles::path)); |
| 119 | auto addInfo = [&toolTip, &mapEntry](const QString& text, DisplayedFilesModelRoles role) { |
| 120 | auto it = mapEntry.find(role); |
| 121 | if (it != mapEntry.end()) { |
| 122 | auto str = QString::fromStdString(it->second); |
| 123 | QDateTime dt = QDateTime::fromString(str, Qt::DateFormat::ISODate); |
| 124 | toolTip.append(QLatin1Char('\n')); |
| 125 | toolTip.append(text); |
| 126 | QLocale loc = QLocale::system(); |
| 127 | toolTip.append(QString::fromLatin1(" %1").arg(loc.toString(dt))); |
| 128 | } |
| 129 | }; |
| 130 | |
| 131 | addInfo(tr("Created at:"), DisplayedFilesModelRoles::creationTime); |
| 132 | addInfo(tr("Modified at:"), DisplayedFilesModelRoles::modifiedTime); |
| 133 |
no test coverage detected