59 if(!force &&
curBox == newBox)
120 if (!index.isValid())
123 if (index.row() >
getCurBox()->pokemon.size())
126 if(index.row() == (
getCurBox()->pokemon.size()))
131 auto monData = mon->toData();
134 if(mon ==
nullptr || monData ==
nullptr)
141 return (monData->pokedex) ? *monData->pokedex : -1;
143 return monData->readable;
149 return mon->nickname;
153 return mon->isShiny();
155 return !mon->isBoxMon();
159 return mon->hpStat();
169 QHash<int, QByteArray> roles;
192 if(index.row() >=
getCurBox()->pokemon.size())
204 dataChanged(index, index);
250 beginMoveRows(QModelIndex(), from, from, QModelIndex(), to);
256 beginRemoveRows(QModelIndex(), ind, ind);
264 beginInsertRows(QModelIndex(),
getCurBox()->pokemon.size()+1,
getCurBox()->pokemon.size()+1);
294 QVector<PokemonBox*> ret;
318 dataChanged(index(i), index(i));
346 for(
int i = checkedItems.size() - 1; i >= 0; i--) {
347 auto el = checkedItems.at(i);
359 for(
int i = checkedItems.size() - 1; i >= 0; i--) {
360 auto el = checkedItems.at(i);
382 beginInsertRows(QModelIndex(),
getCurBox()->pokemonCount(),
getCurBox()->pokemonCount());
421 el = partyEl->toBoxData();
422 partyEl->deleteLater();
476 hasCheckedChangedCached();
517 QVector<PokemonBox*> set;
520 else if(fromIndex >= 0 && fromIndex < vec.size())
521 set.append(vec.at(fromIndex));
530 for(
int i = qBound(0, toIndex, vec.size()); i < vec.size(); i++) {
531 if(!set.contains(vec.at(i))) {
542 int insertAt = (anchor !=
nullptr) ? vec.indexOf(anchor) : vec.size();
543 for(
int i = 0; i < set.size(); i++)
544 vec.insert(insertAt + i, set.at(i));
563 QVector<PokemonBox*> set;
566 else if(fromIndex >= 0 && fromIndex < src->pokemon.size())
567 set.append(src->pokemon.at(fromIndex));
578 if(src ==
party &&
party->pokemonCount() <= 1)
584 int ind = src->pokemon.indexOf(el);
592 src->pokemon.replace(ind, el);
594 else if(!dst->isParty && src->isParty) {
596 el = partyEl->toBoxData();
597 partyEl->deleteLater();
598 src->pokemon.replace(ind, el);
603 src->relocateOne(dst, ind);
611 int firstAppended = dst->pokemon.size() - inserted;
612 int target = qBound(0, toIndex, firstAppended);
614 if(target != firstAppended) {
615 QVector<PokemonBox*> moved = dst->pokemon.mid(firstAppended, inserted);
616 dst->pokemon.remove(firstAppended, inserted);
617 for(
int i = 0; i < moved.size(); i++)
618 dst->pokemon.insert(target + i, moved.at(i));
639 if(index < 0 || index >= box->pokemon.size())
643 if(box ==
party &&
party->pokemonCount() <= 1)
648 bool annPlaceholder = box->pokemonCount() == box->pokemonMax();
650 box->pokemonRemove(index);
653 beginInsertRows(QModelIndex(), box->pokemonCount(), box->pokemonCount());
The player's active party – a specialized PokemonStorageBox.
A single Pokemon record – the most property-rich object in the tree.
A party Pokemon: a PokemonBox plus the five pre-generated battle stats.
static PokemonParty * convertToParty(PokemonBox *data)
New party mon from a box record (regenerates stats).
Holds contents of a single Pokemon storage box.
int pokemonMax()
Capacity (maxSize).
void pokemonInsertChange()
A mon was inserted.
virtual bool relocateOne(PokemonStorageBox *dst, int ind)
Move one mon into dst.
QVector< PokemonBox * > pokemon
The stored mons.
void pokemonResetChange()
The box was reset.
void pokemonMoveChange(int from, int to)
A mon moved slot.
bool pokemonMove(int from, int to)
Reorder a mon within the box.
int pokemonCount()
Number of mons present.
void pokemonRemove(int ind)
Remove the mon at ind.
void pokemonRemoveChange(int ind)
A mon was removed.
PokemonParty * getPartyMon(int index)
Typed party mon at index (for the details screen).
void checkStateDirty()
Mark the checked-state cache stale.
QVariant getPlaceHolderData(int role) const
The empty-slot placeholder row data.
virtual QVariant data(const QModelIndex &index, int role) const override
Row+role value.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Edit a row (e.g. checkbox).
Storage * storage
The PC storage.
void dragReorder(int fromIndex, int toIndex, bool group)
Reorder within this box: move fromIndex (or the checked set) to toIndex.
@ HpMaxRole
Computed max HP (hpStat).
@ HpRole
Current HP (for the storage-grid health bar).
@ StatusRole
Raw status byte (0 none; 1-7 sleep; 8 poison; 16 burn; 32 freeze; 64 paralyze).
PokemonStorageBox * getBox(int box) const
The box object for index box.
void checkedDelete()
Delete checked mons.
void onMove(int from, int to)
React to a move.
PokemonStorageModel(Router *router, Storage *storage, PlayerPokemon *party)
Router * router
For page hooks.
static constexpr const char * isCheckedKey
QML attached-property name for the per-row checkbox.
virtual int rowCount(const QModelIndex &parent) const override
Row count of the current box.
void deleteMon(int index, bool group)
Delete the mon at index, or – when group – the whole checked set (the per-cell hover/checked delete b...
void checkedMoveToBottom()
Move checked mons to the bottom.
PokemonStorageModel * otherModel
The paired sibling model (for transfers).
void onInsert()
React to an insert.
virtual QHash< int, QByteArray > roleNames() const override
Role -> QML name.
bool hasCheckedCached()
Cached form (backs the property).
QVector< PokemonBox * > getChecked()
The currently-checked mons.
void onReset()
React to a reset.
void checkedMoveDown()
Move checked mons down one.
void clearCheckedState()
Uncheck everything.
bool checkedStateDirty
Whether the checked-state cache needs refresh.
PokemonBox * getBoxMon(int index)
Typed box mon at index (for the details screen).
void checkedTransfer()
Transfer checked mons to the paired box.
void pageClosing()
Hook for when the page closes.
void onRemove(int ind)
React to a removal.
void clearCheckedStateGone()
Clear checked state for removed rows.
void checkedToggleAll()
Toggle all checkboxes.
void switchBox(int newBox, bool force=false)
Show box newBox.
void checkedMoveUp()
Move checked mons up one.
bool hasChecked()
Are any rows checked (live)?
void onBeforeRelocate(PokemonBox *item)
Cleanup hook before a mon relocates away.
PlayerPokemon * party
The party.
PokemonStorageBox * getCurBox() const
The currently-shown box object.
void checkedMoveToTop()
Move checked mons to the top.
void dragTransfer(int fromIndex, int toIndex, bool group)
Move fromIndex (or the checked set) from this box into the paired pane's box, inserting at toIndex th...
Screen navigation for the UI – the QML StackView's controller.
The PC: the item storage box and all 12 Pokemon boxes.
qmlCppOwned() – protect Q_INVOKABLE QObject returns from QML's GC.
static T * qmlCppOwned(T *obj)
Hand QML CppOwnership of a C++-owned QObject returned from a Q_INVOKABLE.