MCPcopy Create free account
hub / github.com/FreesmTeam/FreesmLauncher / data

Method data

launcher/ui/pages/modplatform/ResourceModel.cpp:44–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44auto ResourceModel::data(const QModelIndex& index, int role) const -> QVariant
45{
46 int pos = index.row();
47 if (pos >= m_packs.size() || pos < 0 || !index.isValid()) {
48 return QString("INVALID INDEX %1").arg(pos);
49 }
50
51 auto pack = m_packs.at(pos);
52 switch (role) {
53 case Qt::ToolTipRole: {
54 if (pack->description.length() > 100) {
55 // some magic to prevent to long tooltips and replace html linebreaks
56 QString edit = pack->description.left(97);
57 edit = edit.left(edit.lastIndexOf("<br>")).left(edit.lastIndexOf(" ")).append("...");
58 return edit;
59 }
60 return pack->description;
61 }
62 case Qt::DecorationRole: {
63 if (APPLICATION_DYN) {
64 if (auto icon_or_none = const_cast<ResourceModel*>(this)->getIcon(const_cast<QModelIndex&>(index), pack->logoUrl);
65 icon_or_none.has_value())
66 return icon_or_none.value();
67
68 return APPLICATION->getThemedIcon("screenshot-placeholder");
69 } else {
70 return {};
71 }
72 }
73 case Qt::SizeHintRole:
74 return QSize(0, 58);
75 case Qt::UserRole: {
76 QVariant v;
77 v.setValue(pack);
78 return v;
79 }
80 // Custom data
81 case UserDataTypes::TITLE:
82 return pack->name;
83 case UserDataTypes::DESCRIPTION:
84 return pack->description;
85 case UserDataTypes::SELECTED:
86 return pack->isAnyVersionSelected();
87 case UserDataTypes::INSTALLED:
88 return this->isPackInstalled(pack);
89 default:
90 break;
91 }
92
93 return {};
94}
95
96QHash<int, QByteArray> ResourceModel::roleNames() const
97{

Callers 7

getResultMethod · 0.45
getCurrentPackMethod · 0.45
openUrlMethod · 0.45
updateButtonStatesMethod · 0.45

Calls 11

isPackInstalledMethod · 0.95
QStringClass · 0.85
appendMethod · 0.80
valueMethod · 0.80
getThemedIconMethod · 0.80
setValueMethod · 0.80
isAnyVersionSelectedMethod · 0.80
sizeMethod · 0.45
isValidMethod · 0.45
atMethod · 0.45
getIconMethod · 0.45

Tested by

no test coverage detected