65 return items->items.size() + 1;
74 if (index.row() >
items->items.size())
77 if(index.row() == (
items->items.size()))
81 auto item =
items->items.at(index.row());
102 QHash<int, QByteArray> roles;
117 if(index.row() >=
items->items.size())
120 auto item =
items->items.at(index.row());
127 item->ind = value.toInt();
128 dataChanged(index, index);
132 item->amount = value.toInt();
133 dataChanged(index, index);
139 dataChanged(index, index);
183 beginMoveRows(QModelIndex(), from, from, QModelIndex(), to);
189 beginRemoveRows(QModelIndex(), ind, ind);
197 beginInsertRows(QModelIndex(),
items->items.size()+1,
items->items.size()+1);
212 for(
auto el :
items->items) {
229 for(
auto el :
items->items) {
239 for(
auto el :
items->items) {
248 for(
int i = 0; i <
items->items.size(); i++) {
249 auto el =
items->items.at(i);
251 dataChanged(index(i), index(i));
260 int ind =
items->items.indexOf(el);
261 items->itemMove(ind, 0);
268 int ind =
items->items.indexOf(el);
269 items->itemMove(ind, ind - 1);
279 for(
int i = checkedItems.size() - 1; i >= 0; i--) {
280 auto el = checkedItems.at(i);
281 int ind =
items->items.indexOf(el);
282 items->itemMove(ind, ind + 1);
292 for(
int i = checkedItems.size() - 1; i >= 0; i--) {
293 auto el = checkedItems.at(i);
294 int ind =
items->items.indexOf(el);
295 items->itemMove(ind,
items->items.size() - 1);
302 int ind =
items->items.indexOf(el);
303 items->itemRemove(ind);
310 int ind =
items->items.indexOf(el);
311 items->relocateOne(ind);
319 if(
items->items.size() == 0)
324 for(
int i = 0; i <
items->items.size(); i++) {
325 auto el =
items->items.at(i);
360 hasCheckedChangedCached();
371 auto& vec =
items->items;
378 else if(fromIndex >= 0 && fromIndex < vec.size())
379 set.append(vec.at(fromIndex));
387 Item* anchor =
nullptr;
388 for(
int i = qBound(0, toIndex, vec.size()); i < vec.size(); i++) {
389 if(!set.contains(vec.at(i))) {
400 int insertAt = (anchor !=
nullptr) ? vec.indexOf(anchor) : vec.size();
401 for(
int i = 0; i < set.size(); i++)
402 vec.insert(insertAt + i, set.at(i));
418 auto dst =
items->destBox();
424 else if(fromIndex >= 0 && fromIndex < src->
items.size())
425 set.append(src->items.at(fromIndex));
431 bool dstStacked =
false;
435 int ind = src->items.indexOf(el);
444 Item* stackTarget =
nullptr;
445 for(
int i = dst->items.size() - 1; i >= 0; i--) {
446 if(dst->items.at(i)->ind == el->ind) {
447 stackTarget = dst->items.at(i);
457 if(stackTarget !=
nullptr && stackTarget->
amount + el->amount <= 99) {
459 src->itemRemove(ind);
469 if(dst->items.size() >= dst->itemsMax())
475 src->relocateOne(ind);
484 int firstAppended = dst->items.size() - inserted;
485 int target = qBound(0, toIndex, firstAppended);
487 if(target != firstAppended) {
488 QVector<Item*> moved = dst->items.mid(firstAppended, inserted);
489 dst->items.remove(firstAppended, inserted);
490 for(
int i = 0; i < moved.size(); i++)
491 dst->items.insert(target + i, moved.at(i));
499 if(inserted > 0 || dstStacked)
517 if(index < 0 || index >=
items->items.size())
520 items->itemRemove(index);
A container of Items – either the trainer's bag or a PC item box.
void itemsResetChange()
The box was reset.
void itemInsertChange()
An item was inserted.
void itemMoveChange(int from, int to)
An item moved slot.
void itemRemoveChange(int ind)
An item was removed.
static constexpr const char * isCheckedKey
QML attached-property name for the per-row checkbox.
void onReset()
React to a box reset.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Edit a row (e.g. checkbox).
void clearCheckedStateGone()
Clear checked state for removed rows.
bool checkedStateDirty
Whether the checked-state cache needs refresh.
void onMove(int from, int to)
React to a box move.
QVector< Item * > getChecked()
The currently-checked items.
virtual int rowCount(const QModelIndex &parent) const override
Row count.
void checkedMoveToBottom()
Move checked rows to the bottom.
virtual QVariant data(const QModelIndex &index, int role) const override
Row+role value.
void clearCheckedState()
Uncheck everything.
void checkedTransfer()
Transfer checked rows to the paired box.
ItemStorageBox * items
The wrapped item box.
void onBeforeRelocate(Item *item)
Cleanup hook before an item relocates away.
ItemStorageModel(ItemStorageBox *items, Router *router)
bool hasChecked()
Are any rows checked (live)?
void checkedMoveToTop()
Move checked rows to the top.
void pageClosing()
Hook for when the page closes.
QVariant getPlaceHolderData(int role) const
The "empty slot" placeholder row's data.
void deleteItem(int index, bool group)
Delete the item at index, or – when group – the whole checked set (the per-row hover/checked delete b...
void onRemove(int ind)
React to a box removal.
void dragReorder(int fromIndex, int toIndex, bool group)
Reorder within this box: move fromIndex (or the checked set) to toIndex.
void checkedToggleAll()
Toggle all checkboxes.
bool hasCheckedCached()
Cached form (backs the property).
void checkedMoveUp()
Move checked rows up one.
virtual QHash< int, QByteArray > roleNames() const override
Role -> QML name.
void onInsert()
React to a box insert.
void checkedDelete()
Delete checked rows.
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.
Router * router
For page hooks.
ItemStorageModel * otherModel
The paired sibling model (for cross-pane transfers).
void checkedMoveDown()
Move checked rows down one.
void checkStateDirty()
Mark the checked-state cache stale.
One inventory slot: an item index and an amount, with live pricing.
int amount
Item amount (max 99 in Gen 1; backs property).
void setAmount(int val)
Set amount (backs property WRITE; clamped to the Gen 1 max).
Screen navigation for the UI – the QML StackView's controller.