| 43 | } |
| 44 | |
| 45 | QVariant ListModel::data(const QModelIndex &index, int role) const |
| 46 | { |
| 47 | int pos = index.row(); |
| 48 | if(pos >= modpacks.size() || pos < 0 || !index.isValid()) |
| 49 | { |
| 50 | return QString("INVALID INDEX %1").arg(pos); |
| 51 | } |
| 52 | |
| 53 | ModpacksCH::Modpack pack = modpacks.at(pos); |
| 54 | if(role == Qt::DisplayRole) |
| 55 | { |
| 56 | return pack.name; |
| 57 | } |
| 58 | else if (role == Qt::ToolTipRole) |
| 59 | { |
| 60 | return pack.synopsis; |
| 61 | } |
| 62 | else if(role == Qt::DecorationRole) |
| 63 | { |
| 64 | QIcon placeholder = APPLICATION->getThemedIcon("screenshot-placeholder"); |
| 65 | |
| 66 | auto iter = m_logoMap.find(pack.name); |
| 67 | if (iter != m_logoMap.end()) { |
| 68 | auto & logo = *iter; |
| 69 | if(!logo.result.isNull()) { |
| 70 | return logo.result; |
| 71 | } |
| 72 | return placeholder; |
| 73 | } |
| 74 | |
| 75 | for(auto art : pack.art) { |
| 76 | if(art.type == "square") { |
| 77 | ((ListModel *)this)->requestLogo(pack.name, art.url); |
| 78 | } |
| 79 | } |
| 80 | return placeholder; |
| 81 | } |
| 82 | else if(role == Qt::UserRole) |
| 83 | { |
| 84 | QVariant v; |
| 85 | v.setValue(pack); |
| 86 | return v; |
| 87 | } |
| 88 | |
| 89 | return QVariant(); |
| 90 | } |
| 91 | |
| 92 | void ListModel::getLogo(const QString &logo, const QString &logoUrl, LogoCallback callback) |
| 93 | { |
no test coverage detected