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

Editable list model for an item box (the bag or a PC item box). More...

#include <itemstoragemodel.h>

Inheritance diagram for ItemStorageModel:
Collaboration diagram for ItemStorageModel:

Public Types

enum  BagItemRoles { IdRole = Qt::UserRole + 1 , CountRole , CheckedRole , PlaceholderRole }
 Columns (mapped in roleNames()). More...

Public Member Functions

 ItemStorageModel (ItemStorageBox *items, Router *router)
virtual int rowCount (const QModelIndex &parent) const override
 Row count.
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's data.
void onMove (int from, int to)
 React to a box move.
void onRemove (int ind)
 React to a box removal.
void onInsert ()
 React to a box insert.
void onReset ()
 React to a box reset.
bool hasChecked ()
 Are any rows checked (live)?
bool hasCheckedCached ()
 Cached form (backs the property).
QVector< Item * > getChecked ()
 The currently-checked items.
void onBeforeRelocate (Item *item)
 Cleanup hook before an item relocates away.
void checkStateDirty ()
 Mark the checked-state cache stale.
void pageClosing ()
 Hook for when the page closes.
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 box, inserting at toIndex there.
void deleteItem (int index, bool group)
 Delete the item at index, or – when group – the whole checked set (the per-row hover/checked delete button; replaces the old footer delete).
void clearCheckedState ()
 Uncheck everything.
void clearCheckedStateGone ()
 Clear checked state for removed rows.
void checkedMoveToTop ()
 Move checked rows to the top.
void checkedMoveUp ()
 Move checked rows up one.
void checkedMoveDown ()
 Move checked rows down one.
void checkedMoveToBottom ()
 Move checked rows to the bottom.
void checkedDelete ()
 Delete checked rows.
void checkedTransfer ()
 Transfer checked rows to the paired box.
void checkedToggleAll ()
 Toggle all checkboxes.

Public Attributes

ItemStorageBoxitems = nullptr
 The wrapped item box.
Routerrouter
 For page hooks.
ItemStorageModelotherModel = nullptr
 The paired sibling model (for cross-pane 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 an item box (the bag or a PC item box).

Wraps an ItemStorageBox (see CreditsModel for the base convention) as an editable model: rows can be reordered/removed/inserted, and each row carries a checkbox state (a QML attached property, isCheckedKey). The checked* slots act on the checked rows in bulk – move up/down/top/bottom, delete, transfer (to the paired box), toggle-all. hasChecked drives "any selected" UI. Exposed as brg.bagItemsModel / brg.pcItemsModel.

See also
ItemStorageBox, Item.

Definition at line 38 of file itemstoragemodel.h.

Member Enumeration Documentation

◆ BagItemRoles

Columns (mapped in roleNames()).

Enumerator
IdRole 
CountRole 
CheckedRole 
PlaceholderRole 

Definition at line 54 of file itemstoragemodel.h.

Constructor & Destructor Documentation

◆ ItemStorageModel()

ItemStorageModel::ItemStorageModel ( ItemStorageBox * items,
Router * router )

Member Function Documentation

◆ checkedDelete()

void ItemStorageModel::checkedDelete ( )

Delete checked rows.

Definition at line 299 of file itemstoragemodel.cpp.

References getChecked(), and items.

Referenced by deleteItem().

◆ checkedMoveDown()

void ItemStorageModel::checkedMoveDown ( )

Move checked rows down one.

Definition at line 273 of file itemstoragemodel.cpp.

References getChecked(), and items.

◆ checkedMoveToBottom()

void ItemStorageModel::checkedMoveToBottom ( )

Move checked rows to the bottom.

Definition at line 286 of file itemstoragemodel.cpp.

References getChecked(), and items.

◆ checkedMoveToTop()

void ItemStorageModel::checkedMoveToTop ( )

Move checked rows to the top.

Definition at line 257 of file itemstoragemodel.cpp.

References getChecked(), and items.

◆ checkedMoveUp()

void ItemStorageModel::checkedMoveUp ( )

Move checked rows up one.

Definition at line 265 of file itemstoragemodel.cpp.

References getChecked(), and items.

◆ checkedToggleAll()

void ItemStorageModel::checkedToggleAll ( )

Toggle all checkboxes.

Definition at line 317 of file itemstoragemodel.cpp.

References isCheckedKey, and items.

◆ checkedTransfer()

void ItemStorageModel::checkedTransfer ( )

Transfer checked rows to the paired box.

Definition at line 307 of file itemstoragemodel.cpp.

References getChecked(), and items.

◆ checkStateDirty()

void ItemStorageModel::checkStateDirty ( )

Mark the checked-state cache stale.

Definition at line 352 of file itemstoragemodel.cpp.

References checkedStateDirty, and hasChecked().

Referenced by ItemStorageModel().

◆ clearCheckedState()

void ItemStorageModel::clearCheckedState ( )

Uncheck everything.

Definition at line 237 of file itemstoragemodel.cpp.

References isCheckedKey, and items.

Referenced by pageClosing().

◆ clearCheckedStateGone()

void ItemStorageModel::clearCheckedStateGone ( )

Clear checked state for removed rows.

Definition at line 246 of file itemstoragemodel.cpp.

References isCheckedKey, and items.

◆ data()

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

Row+role value.

Definition at line 68 of file itemstoragemodel.cpp.

References CheckedRole, CountRole, getPlaceHolderData(), IdRole, isCheckedKey, items, and PlaceholderRole.

◆ deleteItem()

void ItemStorageModel::deleteItem ( int index,
bool group )

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

Definition at line 505 of file itemstoragemodel.cpp.

References checkedDelete(), and items.

◆ dragReorder()

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

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

Definition at line 369 of file itemstoragemodel.cpp.

References getChecked(), items, and onReset().

◆ dragTransfer()

void ItemStorageModel::dragTransfer ( int fromIndex,
int toIndex,
bool group )

Move fromIndex (or the checked set) from this box into the paired box, inserting at toIndex there.

Definition at line 410 of file itemstoragemodel.cpp.

References Item::amount, getChecked(), items, otherModel, and Item::setAmount().

◆ getChecked()

QVector< Item * > ItemStorageModel::getChecked ( )

◆ getPlaceHolderData()

QVariant ItemStorageModel::getPlaceHolderData ( int role) const

The "empty slot" placeholder row's data.

Definition at line 146 of file itemstoragemodel.cpp.

References CheckedRole, CountRole, IdRole, and PlaceholderRole.

Referenced by data().

◆ hasChecked()

bool ItemStorageModel::hasChecked ( )

Are any rows checked (live)?

Definition at line 208 of file itemstoragemodel.cpp.

References isCheckedKey, and items.

Referenced by checkStateDirty().

◆ hasCheckedCached()

bool ItemStorageModel::hasCheckedCached ( )

Cached form (backs the property).

Definition at line 220 of file itemstoragemodel.cpp.

References checkedStateDirty.

◆ onBeforeRelocate()

void ItemStorageModel::onBeforeRelocate ( Item * item)

Cleanup hook before an item relocates away.

Definition at line 346 of file itemstoragemodel.cpp.

References isCheckedKey.

Referenced by ItemStorageModel().

◆ onInsert()

void ItemStorageModel::onInsert ( )

React to a box insert.

Definition at line 194 of file itemstoragemodel.cpp.

References items.

◆ onMove()

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

React to a box move.

Definition at line 168 of file itemstoragemodel.cpp.

Referenced by ItemStorageModel().

◆ onRemove()

void ItemStorageModel::onRemove ( int ind)

React to a box removal.

Definition at line 187 of file itemstoragemodel.cpp.

Referenced by ItemStorageModel().

◆ onReset()

void ItemStorageModel::onReset ( )

React to a box reset.

Definition at line 201 of file itemstoragemodel.cpp.

Referenced by dragReorder(), and ItemStorageModel().

◆ pageClosing()

void ItemStorageModel::pageClosing ( )

Hook for when the page closes.

Definition at line 363 of file itemstoragemodel.cpp.

References checkedStateDirty, and clearCheckedState().

Referenced by ItemStorageModel().

◆ roleNames()

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

Role -> QML name.

Definition at line 100 of file itemstoragemodel.cpp.

References CheckedRole, CountRole, IdRole, and PlaceholderRole.

◆ rowCount()

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

Row count.

Definition at line 59 of file itemstoragemodel.cpp.

References items.

◆ setData()

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

Edit a row (e.g. checkbox).

Definition at line 112 of file itemstoragemodel.cpp.

References CheckedRole, CountRole, IdRole, isCheckedKey, and items.

Member Data Documentation

◆ checkedStateDirty

bool ItemStorageModel::checkedStateDirty = false

Whether the checked-state cache needs refresh.

Definition at line 124 of file itemstoragemodel.h.

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

◆ isCheckedKey

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

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

Definition at line 51 of file itemstoragemodel.h.

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

◆ items

◆ otherModel

ItemStorageModel* ItemStorageModel::otherModel = nullptr

The paired sibling model (for cross-pane transfers).

Definition at line 123 of file itemstoragemodel.h.

Referenced by dragTransfer().

◆ router

Router* ItemStorageModel::router

For page hooks.

Definition at line 122 of file itemstoragemodel.h.

Referenced by ItemStorageModel().


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