Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
statusselectmodel.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
22#include "./statusselectmodel.h"
23
28
30{
31 // Populate list
32 statusListCache.append(new StatusSelectEntry("-----", 0));
33 statusListCache.append(new StatusSelectEntry("Sleep (1)", 1));
34 statusListCache.append(new StatusSelectEntry("Sleep (2)", 2));
35 statusListCache.append(new StatusSelectEntry("Sleep (3)", 3));
36 statusListCache.append(new StatusSelectEntry("Sleep (4)", 4));
37 statusListCache.append(new StatusSelectEntry("Sleep (5)", 5));
38 statusListCache.append(new StatusSelectEntry("Sleep (6)", 6));
39 statusListCache.append(new StatusSelectEntry("Sleep (7)", 7));
40 statusListCache.append(new StatusSelectEntry("Poisoned", 8));
41 statusListCache.append(new StatusSelectEntry("Burned", 16));
42 statusListCache.append(new StatusSelectEntry("Frozen", 32));
43 statusListCache.append(new StatusSelectEntry("Paralyzed", 64));
44}
45
46int StatusSelectModel::rowCount(const QModelIndex& parent) const
47{
48 // Not a tree, just a list, there's no parent
49 Q_UNUSED(parent)
50
51 // Return list count
52 return statusListCache.size();
53}
54
55QVariant StatusSelectModel::data(const QModelIndex& index, int role) const
56{
57 // If index is invalid in any way, return nothing
58 if (!index.isValid())
59 return QVariant();
60
61 if (index.row() >= statusListCache.size())
62 return QVariant();
63
64 // Get Item from Item List Cache
65 auto item = statusListCache.at(index.row());
66
67 if(item == nullptr)
68 return QVariant();
69
70 // Now return requested information
71 if (role == IndRole)
72 return item->ind;
73 else if (role == NameRole)
74 return item->name;
75
76 // All else fails, return nothing
77 return QVariant();
78}
79
80QHash<int, QByteArray> StatusSelectModel::roleNames() const
81{
82 QHash<int, QByteArray> roles;
83
84 roles[IndRole] = "statusInd";
85 roles[NameRole] = "statusName";
86
87 return roles;
88}
89
91{
92 int ret = -1;
93
94 for(int i = 0; i < statusListCache.size(); i++) {
95 if(ind != statusListCache.at(i)->ind)
96 continue;
97
98 ret = i;
99 break;
100 }
101
102 return ret;
103}
int statusToListIndex(int ind)
Row index for status ind.
virtual QVariant data(const QModelIndex &index, int role) const override
Row+role value.
QVector< StatusSelectEntry * > statusListCache
Cached picker rows.
virtual int rowCount(const QModelIndex &parent) const override
Row count.
virtual QHash< int, QByteArray > roleNames() const override
Role -> QML name.
One status-condition picker row: display name + status index.
QString name
Display name.
StatusSelectEntry(QString name, int ind)
int ind
Status index.