Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
PokemonStorageModel Class Reference

Editable list model for a PC box (or the party), with checkbox selection. More...

#include <pokemonstoragemodel.h>

Inheritance diagram for PokemonStorageModel:
Collaboration diagram for PokemonStorageModel:

Public Types

enum  BagItemRoles {
  IndRole = Qt::UserRole + 1 , DexRole , NameRole , CheckedRole ,
  PlaceholderRole , NicknameRole , LevelRole , IsShinyRole ,
  IsPartyRole , HpRole , HpMaxRole , StatusRole
}
 Columns (mapped in roleNames()). More...
enum  BoxSelect { PartyBox = -1 }
 Sentinel box index for the party. More...

Public Member Functions

 PokemonStorageModel (Router *router, Storage *storage, PlayerPokemon *party)
virtual int rowCount (const QModelIndex &parent) const override
 Row count of the current box.
virtual QVariant data (const QModelIndex &index, int role) const override
 Row+role value.
virtual QHash< int, QByteArray > roleNames () const override
 Role -> QML name.
bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
 Edit a row (e.g. checkbox).
QVariant getPlaceHolderData (int role) const
 The empty-slot placeholder row data.
void onMove (int from, int to)
 React to a move.
void onRemove (int ind)
 React to a removal.
void onInsert ()
 React to an insert.
bool hasChecked ()
 Are any rows checked (live)?
bool hasCheckedCached ()
 Cached form (backs the property).
QVector< PokemonBox * > getChecked ()
 The currently-checked mons.
void onBeforeRelocate (PokemonBox *item)
 Cleanup hook before a mon relocates away.
void checkStateDirty ()
 Mark the checked-state cache stale.
void pageClosing ()
 Hook for when the page closes.
PokemonBoxgetBoxMon (int index)
 Typed box mon at index (for the details screen).
PokemonPartygetPartyMon (int index)
 Typed party mon at index (for the details screen).
void dragReorder (int fromIndex, int toIndex, bool group)
 Reorder within this box: move fromIndex (or the checked set) to toIndex.
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 there.
void deleteMon (int index, bool group)
 Delete the mon at index, or – when group – the whole checked set (the per-cell hover/checked delete button; replaces the old footer release).
void clearCheckedState ()
 Uncheck everything.
void clearCheckedStateGone ()
 Clear checked state for removed rows.
void onReset ()
 React to a reset.
void checkedMoveToTop ()
 Move checked mons to the top.
void checkedMoveUp ()
 Move checked mons up one.
void checkedMoveDown ()
 Move checked mons down one.
void checkedMoveToBottom ()
 Move checked mons to the bottom.
void checkedDelete ()
 Delete checked mons.
void checkedTransfer ()
 Transfer checked mons to the paired box.
void checkedToggleAll ()
 Toggle all checkboxes.
void switchBox (int newBox, bool force=false)
 Show box newBox.
PokemonStorageBoxgetCurBox () const
 The currently-shown box object.
PokemonStorageBoxgetBox (int box) const
 The box object for index box.

Public Attributes

int curBox = PartyBox
Routerrouter = nullptr
 For page hooks.
Storagestorage = nullptr
 The PC storage.
PlayerPokemonparty = nullptr
 The party.
PokemonStorageModelotherModel = nullptr
 The paired sibling model (for transfers).
bool checkedStateDirty = false
 Whether the checked-state cache needs refresh.

Static Public Attributes

static constexpr const char * isCheckedKey = "isChecked"
 QML attached-property name for the per-row checkbox.

Detailed Description

Editable list model for a PC box (or the party), with checkbox selection.

The Pokemon analogue of ItemStorageModel: shows the mons in the curBox box (or the party when curBox == PartyBox), with per-row checkbox state and the same bulk checked* operations (move/delete/transfer/toggle). switchBox() changes which box is shown; getBoxMon()/getPartyMon() hand a typed mon to the details screen. Pairs with a sibling model (otherModel) and a box selector. Exposed as brg.pokemonStorageModel1/2.

See also
Storage, PlayerPokemon, PokemonBoxSelectModel.

Definition at line 48 of file pokemonstoragemodel.h.

Member Enumeration Documentation

◆ BagItemRoles

Columns (mapped in roleNames()).

Enumerator
IndRole 
DexRole 
NameRole 
CheckedRole 
PlaceholderRole 
NicknameRole 
LevelRole 
IsShinyRole 
IsPartyRole 
HpRole 

Current HP (for the storage-grid health bar).

HpMaxRole 

Computed max HP (hpStat).

StatusRole 

Raw status byte (0 none; 1-7 sleep; 8 poison; 16 burn; 32 freeze; 64 paralyze).

Definition at line 67 of file pokemonstoragemodel.h.

◆ BoxSelect

Sentinel box index for the party.

Enumerator
PartyBox 

Definition at line 83 of file pokemonstoragemodel.h.

Constructor & Destructor Documentation

◆ PokemonStorageModel()

PokemonStorageModel::PokemonStorageModel ( Router * router,
Storage * storage,
PlayerPokemon * party )

Member Function Documentation

◆ checkedDelete()

void PokemonStorageModel::checkedDelete ( )

◆ checkedMoveDown()

void PokemonStorageModel::checkedMoveDown ( )

Move checked mons down one.

Definition at line 340 of file pokemonstoragemodel.cpp.

References getChecked(), getCurBox(), PokemonStorageBox::pokemon, and PokemonStorageBox::pokemonMove().

◆ checkedMoveToBottom()

void PokemonStorageModel::checkedMoveToBottom ( )

Move checked mons to the bottom.

Definition at line 353 of file pokemonstoragemodel.cpp.

References getChecked(), getCurBox(), PokemonStorageBox::pokemon, and PokemonStorageBox::pokemonMove().

◆ checkedMoveToTop()

void PokemonStorageModel::checkedMoveToTop ( )

Move checked mons to the top.

Definition at line 324 of file pokemonstoragemodel.cpp.

References getChecked(), getCurBox(), PokemonStorageBox::pokemon, and PokemonStorageBox::pokemonMove().

◆ checkedMoveUp()

void PokemonStorageModel::checkedMoveUp ( )

Move checked mons up one.

Definition at line 332 of file pokemonstoragemodel.cpp.

References getChecked(), getCurBox(), PokemonStorageBox::pokemon, and PokemonStorageBox::pokemonMove().

◆ checkedToggleAll()

void PokemonStorageModel::checkedToggleAll ( )

Toggle all checkboxes.

Definition at line 433 of file pokemonstoragemodel.cpp.

References getCurBox(), isCheckedKey, and PokemonStorageBox::pokemon.

◆ checkedTransfer()

void PokemonStorageModel::checkedTransfer ( )

◆ checkStateDirty()

void PokemonStorageModel::checkStateDirty ( )

Mark the checked-state cache stale.

Definition at line 468 of file pokemonstoragemodel.cpp.

References checkedStateDirty, and hasChecked().

Referenced by PokemonStorageModel().

◆ clearCheckedState()

void PokemonStorageModel::clearCheckedState ( )

Uncheck everything.

Definition at line 304 of file pokemonstoragemodel.cpp.

References getCurBox(), and isCheckedKey.

Referenced by switchBox().

◆ clearCheckedStateGone()

void PokemonStorageModel::clearCheckedStateGone ( )

Clear checked state for removed rows.

Definition at line 313 of file pokemonstoragemodel.cpp.

References getCurBox(), isCheckedKey, and PokemonStorageBox::pokemon.

◆ data()

QVariant PokemonStorageModel::data ( const QModelIndex & index,
int role ) const
overridevirtual

◆ deleteMon()

void PokemonStorageModel::deleteMon ( int index,
bool group )

Delete the mon at index, or – when group – the whole checked set (the per-cell hover/checked delete button; replaces the old footer release).

Definition at line 627 of file pokemonstoragemodel.cpp.

References checkedDelete(), getCurBox(), and party.

◆ dragReorder()

void PokemonStorageModel::dragReorder ( int fromIndex,
int toIndex,
bool group )

Reorder within this box: move fromIndex (or the checked set) to toIndex.

Definition at line 511 of file pokemonstoragemodel.cpp.

References getChecked(), getCurBox(), onReset(), and PokemonStorageBox::pokemon.

◆ dragTransfer()

void PokemonStorageModel::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 there.

Definition at line 553 of file pokemonstoragemodel.cpp.

References PokemonParty::convertToParty(), getChecked(), getCurBox(), otherModel, and party.

◆ getBox()

PokemonStorageBox * PokemonStorageModel::getBox ( int box) const

The box object for index box.

Definition at line 98 of file pokemonstoragemodel.cpp.

References party, PartyBox, and storage.

Referenced by getCurBox().

◆ getBoxMon()

PokemonBox * PokemonStorageModel::getBoxMon ( int index)

Typed box mon at index (for the details screen).

Definition at line 490 of file pokemonstoragemodel.cpp.

References getCurBox(), and qmlCppOwned().

◆ getChecked()

QVector< PokemonBox * > PokemonStorageModel::getChecked ( )

◆ getCurBox()

◆ getPartyMon()

PokemonParty * PokemonStorageModel::getPartyMon ( int index)

Typed party mon at index (for the details screen).

Definition at line 501 of file pokemonstoragemodel.cpp.

References getCurBox(), PokemonStorageBox::pokemon, and qmlCppOwned().

◆ getPlaceHolderData()

QVariant PokemonStorageModel::getPlaceHolderData ( int role) const

The empty-slot placeholder row data.

Definition at line 211 of file pokemonstoragemodel.cpp.

References CheckedRole, DexRole, IndRole, NameRole, and PlaceholderRole.

Referenced by data().

◆ hasChecked()

bool PokemonStorageModel::hasChecked ( )

Are any rows checked (live)?

Definition at line 275 of file pokemonstoragemodel.cpp.

References getCurBox(), and isCheckedKey.

Referenced by checkStateDirty().

◆ hasCheckedCached()

bool PokemonStorageModel::hasCheckedCached ( )

Cached form (backs the property).

Definition at line 287 of file pokemonstoragemodel.cpp.

References checkedStateDirty.

◆ onBeforeRelocate()

void PokemonStorageModel::onBeforeRelocate ( PokemonBox * item)

Cleanup hook before a mon relocates away.

Definition at line 462 of file pokemonstoragemodel.cpp.

References isCheckedKey.

Referenced by switchBox().

◆ onInsert()

void PokemonStorageModel::onInsert ( )

React to an insert.

Definition at line 261 of file pokemonstoragemodel.cpp.

References getCurBox().

◆ onMove()

void PokemonStorageModel::onMove ( int from,
int to )

React to a move.

Definition at line 235 of file pokemonstoragemodel.cpp.

Referenced by switchBox().

◆ onRemove()

void PokemonStorageModel::onRemove ( int ind)

React to a removal.

Definition at line 254 of file pokemonstoragemodel.cpp.

Referenced by switchBox().

◆ onReset()

void PokemonStorageModel::onReset ( )

React to a reset.

Definition at line 268 of file pokemonstoragemodel.cpp.

Referenced by dragReorder(), PokemonStorageModel(), and switchBox().

◆ pageClosing()

void PokemonStorageModel::pageClosing ( )

Hook for when the page closes.

Definition at line 479 of file pokemonstoragemodel.cpp.

Referenced by PokemonStorageModel().

◆ roleNames()

QHash< int, QByteArray > PokemonStorageModel::roleNames ( ) const
overridevirtual

◆ rowCount()

int PokemonStorageModel::rowCount ( const QModelIndex & parent) const
overridevirtual

Row count of the current box.

Definition at line 106 of file pokemonstoragemodel.cpp.

References getCurBox(), and PokemonStorageBox::pokemon.

◆ setData()

bool PokemonStorageModel::setData ( const QModelIndex & index,
const QVariant & value,
int role = Qt::EditRole )
override

Edit a row (e.g. checkbox).

Definition at line 187 of file pokemonstoragemodel.cpp.

References CheckedRole, getCurBox(), isCheckedKey, and PokemonStorageBox::pokemon.

◆ switchBox()

Member Data Documentation

◆ checkedStateDirty

bool PokemonStorageModel::checkedStateDirty = false

Whether the checked-state cache needs refresh.

Definition at line 162 of file pokemonstoragemodel.h.

Referenced by checkStateDirty(), hasCheckedCached(), and switchBox().

◆ curBox

int PokemonStorageModel::curBox = PartyBox
See also
curBox property.

Definition at line 157 of file pokemonstoragemodel.h.

Referenced by getCurBox(), PokemonStorageModel(), and switchBox().

◆ isCheckedKey

const char* PokemonStorageModel::isCheckedKey = "isChecked"
staticconstexpr

QML attached-property name for the per-row checkbox.

Definition at line 64 of file pokemonstoragemodel.h.

Referenced by checkedToggleAll(), clearCheckedState(), clearCheckedStateGone(), data(), getChecked(), hasChecked(), onBeforeRelocate(), and setData().

◆ otherModel

PokemonStorageModel* PokemonStorageModel::otherModel = nullptr

The paired sibling model (for transfers).

Definition at line 161 of file pokemonstoragemodel.h.

Referenced by checkedTransfer(), and dragTransfer().

◆ party

PlayerPokemon* PokemonStorageModel::party = nullptr

◆ router

Router* PokemonStorageModel::router = nullptr

For page hooks.

Definition at line 158 of file pokemonstoragemodel.h.

Referenced by PokemonStorageModel().

◆ storage

Storage* PokemonStorageModel::storage = nullptr

The PC storage.

Definition at line 159 of file pokemonstoragemodel.h.

Referenced by getBox(), and PokemonStorageModel().


The documentation for this class was generated from the following files: