Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
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
24
StatusSelectEntry::StatusSelectEntry
(QString
name
,
int
ind
)
25
:
name
(
name
),
26
ind
(
ind
)
27
{}
28
29
StatusSelectModel::StatusSelectModel
()
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
46
int
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
55
QVariant
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
80
QHash<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
90
int
StatusSelectModel::statusToListIndex
(
int
ind)
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
}
StatusSelectModel::statusToListIndex
int statusToListIndex(int ind)
Row index for status ind.
Definition
statusselectmodel.cpp:90
StatusSelectModel::data
virtual QVariant data(const QModelIndex &index, int role) const override
Row+role value.
Definition
statusselectmodel.cpp:55
StatusSelectModel::StatusSelectModel
StatusSelectModel()
Definition
statusselectmodel.cpp:29
StatusSelectModel::statusListCache
QVector< StatusSelectEntry * > statusListCache
Cached picker rows.
Definition
statusselectmodel.h:53
StatusSelectModel::rowCount
virtual int rowCount(const QModelIndex &parent) const override
Row count.
Definition
statusselectmodel.cpp:46
StatusSelectModel::roleNames
virtual QHash< int, QByteArray > roleNames() const override
Role -> QML name.
Definition
statusselectmodel.cpp:80
StatusSelectModel::IndRole
@ IndRole
Definition
statusselectmodel.h:43
StatusSelectModel::NameRole
@ NameRole
Definition
statusselectmodel.h:44
statusselectmodel.h
StatusSelectEntry
One status-condition picker row: display name + status index.
Definition
statusselectmodel.h:23
StatusSelectEntry::name
QString name
Display name.
Definition
statusselectmodel.h:26
StatusSelectEntry::StatusSelectEntry
StatusSelectEntry(QString name, int ind)
Definition
statusselectmodel.cpp:24
StatusSelectEntry::ind
int ind
Status index.
Definition
statusselectmodel.h:27
projects
app
src
mvc
statusselectmodel.cpp
Generated by
1.17.0