[go: up one dir, main page]

Menu

[4fe084]: / armormodel.cpp  Maximize  Restore  History

Download this file

192 lines (172 with data), 5.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/**********************************************************************************
* Copyright 2020-2022 Michael McBride
*
* This file is part of PF2 Character Manager
*
* PF2 Character Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
**********************************************************************************/
#include "string"
#include "armormodel.h"
#include "armor.h"
/*
* Armor Model for Armor.qml file
*
*/
ArmorModel::ArmorModel(QObject *parent)
: QAbstractListModel(parent),
mList(nullptr)
{
selected = 0;
}
int ArmorModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid() || !mList)
return 0;
return mList->items().size();
}
QVariant ArmorModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || !mList)
return QVariant();
const ArmorItem item = mList->items().at(index.row());
switch (role) {
case DescRole:
return QVariant(item.Description);
case IDRole:
return QVariant(item.id);
case NameRole:
if (item.Level == 0)
return QVariant(item.Name);
else
{
QVariant txt = item.Name;
txt = txt.toString() + " (level " + item.Level.toString() +")";
return txt;
}
case LevelRole:
return QVariant(item.Level);
case CategoryRole:
return QVariant(item.Category);
case PriceRole:
{
QVariant txt = "";
if (item.Price.toInt() < 100)
{
txt = (item.Price.toInt() /10);
txt = txt.toString() + " sp";
}
else
{
txt = (item.Price.toInt() / 100);
txt = txt.toString() + " gp";
}
return QVariant(txt);
}
case ACBonusRole:
return QVariant("+" + item.ACBonus.toString());
case DexCapRole:
if(item.DEXCap.toInt()<0) return "";
return QVariant("+" + item.DEXCap.toString());
case CheckPenaltyRole:
if(item.CheckPenality.toInt()>=0) return "";
return QVariant(item.CheckPenality);
case SpeedPenaltyRole:
return QVariant(item.SpeedPenality);
case StrengthRole:
return QVariant(item.Strength);
case BulkRole:
{
QVariant txt="";
if(item.Bulk.toInt()>0) {
if(item.Bulk.toInt()!=1) {
txt=int(item.Bulk.toInt()/10);
} else {
txt="Light";
}
} else txt="-";
return QVariant(txt);
}
case GroupRole:
return Armor::groupToTxt(item.Group);
case TraitsRole:
return Armor::traitToTxt(item.Traits);
case HardnessRole:
return QVariant(item.Hardness);
case HPRole:
return QVariant(item.HP);
case BTRole:
return QVariant(item.BT);
case SourceRole:
return QVariant(item.Source);
case PageRole:
return QVariant(item.Page);
case AONRole:
return QVariant(item.AON);
case CatTypeRole:
return QVariant(item.CatType);
}
return QVariant();
}
void ArmorModel::setList(Armor *list)
{
beginResetModel();
if (mList)
mList->disconnect(this);
mList = list;
if (mList) {
connect(mList, &Armor::preArmorAppended, this, [=]() {
const int index = mList->items().size();
beginInsertRows(QModelIndex(), index, index);
});
connect(mList, &Armor::postArmorAppended, this, [=]() {
endInsertRows();
});
connect(mList, &Armor::listChanged, this, [=]() {
beginResetModel();
this->dataChanged(index(0), index(rowCount()));
endResetModel();
});
}
endResetModel();
}
QHash<int, QByteArray> ArmorModel::roleNames() const
{
QHash<int, QByteArray> names;
names[DescRole] = "Description";
names[IDRole] = "id";
names[NameRole] = "Name";
names[LevelRole] = "Level";
names[CategoryRole] = "Category";
names[PriceRole] = "Price";
names[ACBonusRole] = "ACBonus";
names[DexCapRole] = "DexCap";
names[CheckPenaltyRole] = "CheckPenalty";
names[SpeedPenaltyRole] = "SpeedPenalty";
names[StrengthRole] = "Strength";
names[BulkRole] = "Bulk";
names[GroupRole] = "Group";
names[TraitsRole] = "Traits";
names[HardnessRole] = "Hardness";
names[HPRole] = "HP";
names[BTRole] = "BT";
names[SourceRole] = "Source";
names[PageRole] = "Page";
names[AONRole] = "AON";
names[CatTypeRole] = "CatType";
return names;
}
Armor *ArmorModel::list() const
{
return mList;
}