26#include <QVariantList>
39QString fixSpeciesMarkup(QString s)
41 s.replace(QStringLiteral(
"<f>"), QStringLiteral(
" ♀"));
42 s.replace(QStringLiteral(
"<F>"), QStringLiteral(
" ♀"));
43 s.replace(QStringLiteral(
"<m>"), QStringLiteral(
" ♂"));
44 s.replace(QStringLiteral(
"<M>"), QStringLiteral(
" ♂"));
45 s.replace(QStringLiteral(
"Mr.Mime"), QStringLiteral(
"Mr. Mime"));
59 if(this->party !=
nullptr)
62 if(this->storage !=
nullptr) {
63 for(
int i = 0; i < storage->boxCount(); ++i) {
64 auto box = storage->boxAt(i);
86 if(!index.isValid() || index.row() < 0 || index.row() >= rows.size())
89 const Row& r = rows.at(index.row());
96 out.reserve(r.cells.size());
97 for(
const Cell& c : r.cells)
104 out.reserve(r.cells.size());
105 for(
const Cell& c : r.cells)
106 out.append(c.tooltip);
115 QHash<int, QByteArray> roles;
122PokemonOverviewModel::Cell PokemonOverviewModel::buildCell(
PokemonStorageBox* box,
int speciesId)
const
131 QStringList nicknames;
137 if(mon ==
nullptr || mon->species != speciesId)
142 if(mon->hasTradeStatus(basics))
147 if(mon->hasNickname())
148 nicknames.append(fixSpeciesMarkup(mon->nickname));
161 if(!nicknames.isEmpty()) {
162 line1 = nicknames.join(QStringLiteral(
", "));
164 line1 += QStringLiteral(
", and ×%1 %2")
166 .arg(others == 1 ? QStringLiteral(
"other") : QStringLiteral(
"others"));
177 own.append(QStringLiteral(
"×%1 caught").arg(caught));
178 own.append(QStringLiteral(
"×%1 traded").arg(traded));
179 line2 = own.join(QStringLiteral(
", "));
185 cell.tooltip = line2;
186 else if(line2.isEmpty())
187 cell.tooltip = line1;
189 cell.tooltip = line1 + QStringLiteral(
"\n") + line2;
202 colBoxes.append(party);
203 colLabels.append(QStringLiteral(
"Party"));
205 if(storage !=
nullptr) {
206 for(
int i = 0; i < storage->boxCount(); ++i) {
207 auto box = storage->boxAt(i);
209 colBoxes.append(box);
210 colLabels.append(QStringLiteral(
"Box %1").arg(i + 1));
218 QSet<int> speciesIds;
219 QHash<int, QString> names;
220 QHash<int, int> dexes;
222 for(
auto box : colBoxes) {
228 int id = mon->species;
229 speciesIds.insert(
id);
230 if(!names.contains(
id)) {
231 names[id] = mon->speciesName();
232 dexes[id] = mon->dexNum();
238 for(
int id : speciesIds) {
240 row.name = names.value(
id, QStringLiteral(
"???"));
241 row.dex = dexes.value(
id, 0);
243 row.cells.reserve(colBoxes.size());
244 for(
auto box : colBoxes)
245 row.cells.append(buildCell(box,
id));
255void PokemonOverviewModel::applySort()
261 collator.setNumericMode(
true);
262 collator.setIgnorePunctuation(
true);
263 std::sort(rows.begin(), rows.end(), [&collator](
const Row& a,
const Row& b) {
264 int c = collator.compare(a.name, b.name);
265 return (c != 0) ? (c < 0) : (a.id < b.id);
269 std::sort(rows.begin(), rows.end(), [](
const Row& a,
const Row& b) {
274 std::sort(rows.begin(), rows.end(), [](
const Row& a,
const Row& b) {
275 return (a.dex != b.dex) ? (a.dex < b.dex) : (a.id < b.id);
298 case SortDex:
return QStringLiteral(
"Dex order");
299 case SortName:
return QStringLiteral(
"Alphabetical");
300 case SortInternal:
return QStringLiteral(
"Internal order");
301 default:
return QString();
308 case SortDex:
return QStringLiteral(
"qrc:/assets/icons/sort/pokedex.png");
309 case SortName:
return QStringLiteral(
"qrc:/assets/icons/sort/alphabetical.png");
310 case SortInternal:
return QStringLiteral(
"qrc:/assets/icons/sort/internal.png");
311 default:
return QString();
The trainer's headline values: name, ID, money, coins, badges, starter.
void sortCycle()
Advance to the next species sort order (re-sorts in place).
QString sortLabel() const
@ SortInternal
Internal / creation (raw species id) order.
@ SortName
Alphabetical by species name.
@ SortDex
Pokedex number order.
virtual QHash< int, QByteArray > roleNames() const override
Role -> QML name.
protected::void columnsChanged()
@ CountsRole
Per-column counts (QVariantList<int>, aligned to columns).
@ TooltipsRole
Per-column hover tooltips (QVariantList<QString>; empty when count 0).
@ NameRole
Species display name.
virtual int rowCount(const QModelIndex &parent) const override
Row count.
virtual QVariant data(const QModelIndex &index, int role) const override
Row+role value.
PokemonOverviewModel(PokemonStorageBox *party, Storage *storage, PlayerBasics *basics)
QStringList columns() const
void rebuild()
Re-aggregate the party + boxes (full model reset). Wired to pokemonChanged.
Holds contents of a single Pokemon storage box.
void pokemonChanged()
Box contents changed.
QVector< PokemonBox * > pokemon
The stored mons.
int pokemonCount()
Number of mons present.
The PC: the item storage box and all 12 Pokemon boxes.