Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
itemstoragemodel.h
Go to the documentation of this file.
1/*
2 * Copyright 2020 Twilight
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15*/
16#pragma once
17#include <QObject>
18#include <QString>
19#include <QAbstractListModel>
20#include <QVector>
21
22class Item;
23class ItemStorageBox;
24class Router;
25
38class ItemStorageModel : public QAbstractListModel
39{
40 Q_OBJECT
41
42 // Checkmarks changed
43 Q_PROPERTY(bool hasChecked READ hasCheckedCached NOTIFY hasCheckedChangedCached STORED false)
44
45signals:
46 void hasCheckedChanged();
47 void hasCheckedChangedCached();
48
49public:
50 // Name of attached properties
51 static constexpr const char* isCheckedKey = "isChecked";
52
60
62
63 virtual int rowCount(const QModelIndex& parent) const override;
64 virtual QVariant data(const QModelIndex& index, int role) const override;
65 virtual QHash<int, QByteArray> roleNames() const override;
66 bool setData(const QModelIndex &index, const QVariant &value,
67 int role = Qt::EditRole) override;
68
69 QVariant getPlaceHolderData(int role) const;
70
71 // Signals from the box
72 void onMove(int from, int to);
73 void onRemove(int ind);
74 void onInsert();
75 void onReset();
76
77 // Attached property management
78 bool hasChecked();
79 bool hasCheckedCached();
80 QVector<Item*> getChecked();
81 void onBeforeRelocate(Item* item);
82 void checkStateDirty();
83
84 void pageClosing();
85
86 // ---- Drag & drop (Bag / Items screen) -----------------------------------
87 // Backing for the list's drag-to-reorder and drag-between-panes gestures, the
88 // direct analogue of PokemonStorageModel's. `toIndex` is the destination
89 // insertion slot (0..count): the moved item(s) land *before* the item at that
90 // slot (== append when toIndex is the count). When `group` is true the whole
91 // currently-checked set moves together (preserving order); otherwise just the
92 // single item at `fromIndex`. Same rules as the checked* bulk actions
93 // (destination never overflows). An item box can be empty, so -- unlike the
94 // Pokemon party -- there is no "never empties" guard.
95
97 Q_INVOKABLE void dragReorder(int fromIndex, int toIndex, bool group);
98
101 Q_INVOKABLE void dragTransfer(int fromIndex, int toIndex, bool group);
102
105 Q_INVOKABLE void deleteItem(int index, bool group);
106
107public slots:
108 // Attached property management
109 void clearCheckedState();
110 void clearCheckedStateGone();
111
112 void checkedMoveToTop();
113 void checkedMoveUp();
114 void checkedMoveDown();
115 void checkedMoveToBottom();
116 void checkedDelete();
117 void checkedTransfer();
118 void checkedToggleAll();
119
120public:
124 bool checkedStateDirty = false;
125};
A container of Items – either the trainer's bag or a PC item box.
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.
BagItemRoles
Columns (mapped in roleNames()).
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.
Definition item.h:36
Screen navigation for the UI – the QML StackView's controller.
Definition router.h:74