Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
pokemonboxselectmodel.cpp
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
21
29
32{
33 storage = pairedModel->storage;
34 party = pairedModel->party;
35
36 // The box list has to know all the up-to-date information on all the pokemon
37 // boxes because the list that is displayed contains more information than
38 // just a box number
39
40 // Subscribe to all changes in all PokemonStorageBox's
41 for(int i = 0; i < 12; i++) {
43 }
44
45 // Subscribe to all changes in the players party
47
48 // Subscribe to certain changes in storage
52}
53
54int PokemonBoxSelectModel::rowCount(const QModelIndex& parent) const
55{
56 // Not a tree, just a list, there's no parent
57 Q_UNUSED(parent)
58
59 // Return list count
60 return 13;
61}
62
63QVariant PokemonBoxSelectModel::data(const QModelIndex& index, int role) const
64{
65 // If index is invalid in any way, return nothing
66 if (!index.isValid())
67 return QVariant();
68
69 if (index.row() >= 13)
70 return QVariant();
71
72 // Now return requested information
73
74 // Return the display name decorated accordingly
75 if (role == NameRole)
76 return getDecoratedName(index.row());
77
78 // Return the value, just the row number
79 else if (role == ValueRole)
80 return index.row();
81
82 // Return the value, just the row number
83 else if (role == IndRole)
84 return pairedModel->curBox;
85
86 // Return whether it's disabled or not
87 // It's disabled
88 // 1) It's the same box as the other side half
89 // 2) The boxes are not formatted and the non-party box row is not the
90 // current non-party box.
91 else if (role == DisabledRole) {
92 bool ret = false;
93
94 if((index.row() - 1) == pairedModel->otherModel->curBox)
95 ret = true;
96 else if(!storage->boxesFormatted && (index.row() - 1) != storage->curBox && index.row() != 0)
97 ret = true;
98
99 return ret;
100 }
101
102 // All else fails, return nothing
103 return QVariant();
104}
105
106QHash<int, QByteArray> PokemonBoxSelectModel::roleNames() const
107{
108 QHash<int, QByteArray> roles;
109
110 roles[IndRole] = "boxInd";
111 roles[NameRole] = "boxName";
112 roles[ValueRole] = "boxValue";
113 roles[DisabledRole] = "boxDisabled";
114
115 return roles;
116}
117
118bool PokemonBoxSelectModel::setData(const QModelIndex& index, const QVariant& value, int role)
119{
120 if(!index.isValid())
121 return false;
122
123 if(index.row() >= 13)
124 return false;
125
126 // Now set requested information
127 if(role == IndRole) {
128 pairedModel->switchBox(value.toInt() - 1);
129 return true;
130 }
131
132 return false;
133}
134
136{
137 // Ask all the data to re-update
138 dataChanged(index(0), index(12));
139}
140
142{
143 // First get box in question
144 PokemonStorageBox* selBox = (box == 0)
145 ? party
146 : storage->boxAt(box - 1);
147
148 // Get name of box
149 QString name = boxSelect[box];
150
151 // Prepend the current-box marker (points at the label), where the old fill
152 // circle used to sit; otherwise pad with equal-width blank so every row stays
153 // left-aligned. The fill circle is gone -- the (N/Max) count below already
154 // conveys how full a box is, and more precisely than empty/partly/full did.
155 if(box > 0 && storage->curBox == (box - 1))
156 name = curBoxSym + " " + name;
157 else
158 name = " " + name;
159
160 // Next append box count
161 name += " (" +
162 QString::number(selBox->pokemonCount()) +
163 "/" +
164 QString::number(selBox->pokemonMax()) +
165 ")";
166
167 // Return
168 return name;
169}
void onBoxChange()
React to this selector changing.
PlayerPokemon * party
The party (box 0).
QString boxSelect[13]
Row labels: Party plus the 12 boxes.
QString getDecoratedName(int box) const
Row label with its fill-status symbol.
virtual bool setData(const QModelIndex &index, const QVariant &value, int role) override
Selection write-back.
virtual QHash< int, QByteArray > roleNames() const override
Role -> QML name.
PokemonStorageModel * pairedModel
The storage model this selector drives (see note).
Storage * storage
The PC storage (for fill status).
virtual int rowCount(const QModelIndex &parent) const override
Row count (13).
PokemonBoxSelectModel(PokemonStorageModel *pairedModel)
QString curBoxSym
Decoration: current-box marker (points at the label). Fill status is conveyed by the (N/Max) count.
virtual QVariant data(const QModelIndex &index, int role) const override
Row+role value.
Holds contents of a single Pokemon storage box.
void pokemonChanged()
Box contents changed.
int pokemonMax()
Capacity (maxSize).
int pokemonCount()
Number of mons present.
Editable list model for a PC box (or the party), with checkbox selection.
void pokemonChanged()
void curBoxChanged()
void boxesFormattedChanged()