Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
pokemonstoragemodel.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
22// getBoxMon()/getPartyMon() are Q_INVOKABLE and return these to QML (the Pokémon
23// details screen binds them to typed PokemonBox/PokemonParty properties). Full
24// includes so QML receives real QObjects, not opaque values.
25// See notes/reference/qt6-patterns.md.
28
29class PokemonBox;
30class PokemonParty;
32class PlayerPokemon;
33class Storage;
34class Router;
35
48class PokemonStorageModel : public QAbstractListModel
49{
50 Q_OBJECT
51
52 // Checkmarks changed
53 Q_PROPERTY(bool hasChecked READ hasCheckedCached NOTIFY hasCheckedChangedCached STORED false)
54
55 Q_PROPERTY(int curBox MEMBER curBox NOTIFY curBoxChanged)
56
57signals:
58 void hasCheckedChanged();
59 void hasCheckedChangedCached();
60 void curBoxChanged();
61
62public:
63 // Name of attached properties
64 static constexpr const char* isCheckedKey = "isChecked";
65
81
83 enum BoxSelect {
85 };
86
91 );
92
93 virtual int rowCount(const QModelIndex& parent) const override;
94 virtual QVariant data(const QModelIndex& index, int role) const override;
95 virtual QHash<int, QByteArray> roleNames() const override;
96 bool setData(const QModelIndex &index, const QVariant &value,
97 int role = Qt::EditRole) override;
98
99 QVariant getPlaceHolderData(int role) const;
100
101 // Signals from the box
102 void onMove(int from, int to);
103 void onRemove(int ind);
104 void onInsert();
105
106 // Attached property management
107 bool hasChecked();
108 bool hasCheckedCached();
109 QVector<PokemonBox*> getChecked();
110 void onBeforeRelocate(PokemonBox* item);
111 void checkStateDirty();
112
113 void pageClosing();
114
115 Q_INVOKABLE PokemonBox* getBoxMon(int index);
116 Q_INVOKABLE PokemonParty* getPartyMon(int index);
117
118 // ---- Drag & drop (Pokemon storage screen) -------------------------------
119 // Backing for the grid's drag-to-reorder and drag-between-panes gestures.
120 // `toIndex` is the destination insertion slot (0..count): the moved mon(s)
121 // land *before* the mon currently at that slot (== append when toIndex is the
122 // count). When `group` is true the whole currently-checked set moves together
123 // (preserving order); otherwise just the single mon at `fromIndex`. These are
124 // the drag analogue of the checked* bulk actions and obey the same rules
125 // (party never empties, destination never overflows, party<->box conversion).
126
128 Q_INVOKABLE void dragReorder(int fromIndex, int toIndex, bool group);
129
132 Q_INVOKABLE void dragTransfer(int fromIndex, int toIndex, bool group);
133
136 Q_INVOKABLE void deleteMon(int index, bool group);
137
138public slots:
139 // Attached property management
140 void clearCheckedState();
141 void clearCheckedStateGone();
142 void onReset();
143
144 void checkedMoveToTop();
145 void checkedMoveUp();
146 void checkedMoveDown();
147 void checkedMoveToBottom();
148 void checkedDelete();
149 void checkedTransfer();
150 void checkedToggleAll();
151
152 void switchBox(int newBox, bool force = false);
154 PokemonStorageBox* getBox(int box) const;
155
156public:
158 Router* router = nullptr;
159 Storage* storage = nullptr;
160 PlayerPokemon* party = nullptr;
162 bool checkedStateDirty = false;
163};
The player's active party – a specialized PokemonStorageBox.
A single Pokemon record – the most property-rich object in the tree.
Definition pokemonbox.h:213
A party Pokemon: a PokemonBox plus the five pre-generated battle stats.
Holds contents of a single Pokemon storage box.
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.
BagItemRoles
Columns (mapped in roleNames()).
@ 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.
BoxSelect
Sentinel box index for the party.
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.
Definition router.h:74
The PC: the item storage box and all 12 Pokemon boxes.
Definition storage.h:49