| 43 | } |
| 44 | |
| 45 | auto ListModel::data(const QModelIndex& index, int role) const -> QVariant |
| 46 | { |
| 47 | int pos = index.row(); |
| 48 | if (pos >= modpacks.size() || pos < 0 || !index.isValid()) { |
| 49 | return QString("INVALID INDEX %1").arg(pos); |
| 50 | } |
| 51 | |
| 52 | ModPlatform::IndexedPack pack = modpacks.at(pos); |
| 53 | switch (role) { |
| 54 | case Qt::ToolTipRole: { |
| 55 | if (pack.description.length() > 100) { |
| 56 | // some magic to prevent to long tooltips and replace html linebreaks |
| 57 | QString edit = pack.description.left(97); |
| 58 | edit = edit.left(edit.lastIndexOf("<br>")).left(edit.lastIndexOf(" ")).append("..."); |
| 59 | return edit; |
| 60 | } |
| 61 | return pack.description; |
| 62 | } |
| 63 | case Qt::DecorationRole: { |
| 64 | if (m_logoMap.contains(pack.logoName)) { |
| 65 | return m_logoMap.value(pack.logoName); |
| 66 | } |
| 67 | QIcon icon = APPLICATION->getThemedIcon("screenshot-placeholder"); |
| 68 | // un-const-ify this |
| 69 | ((ListModel*)this)->requestLogo(pack.logoName, pack.logoUrl); |
| 70 | return icon; |
| 71 | } |
| 72 | case Qt::SizeHintRole: |
| 73 | return QSize(0, 58); |
| 74 | case Qt::UserRole: { |
| 75 | QVariant v; |
| 76 | v.setValue(pack); |
| 77 | return v; |
| 78 | } |
| 79 | // Custom data |
| 80 | case UserDataTypes::TITLE: |
| 81 | return pack.name; |
| 82 | case UserDataTypes::DESCRIPTION: |
| 83 | return pack.description; |
| 84 | case UserDataTypes::SELECTED: |
| 85 | return m_parent->getDialog()->isModSelected(pack.name); |
| 86 | default: |
| 87 | break; |
| 88 | } |
| 89 | |
| 90 | return {}; |
| 91 | } |
| 92 | |
| 93 | bool ListModel::setData(const QModelIndex &index, const QVariant &value, int role) |
| 94 | { |
no test coverage detected