1881
|
1 |
/*
|
|
2 |
* Hedgewars, a free turn based strategy game
|
|
3 |
* Copyright (c) 2009 Andrey Korotaev <unC0Rr@gmail.com>
|
|
4 |
*
|
|
5 |
* This program is free software; you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License as published by
|
|
7 |
* the Free Software Foundation; version 2 of the License
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
15 |
* along with this program; if not, write to the Free Software
|
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
17 |
*/
|
|
18 |
|
1885
|
19 |
#include <QDebug>
|
1881
|
20 |
#include <QModelIndex>
|
|
21 |
#include "ammoSchemeModel.h"
|
|
22 |
|
|
23 |
AmmoSchemeModel::AmmoSchemeModel(QObject* parent) :
|
|
24 |
QAbstractTableModel(parent)
|
|
25 |
{
|
1884
|
26 |
defaultScheme
|
1885
|
27 |
<< "Default" // name
|
1889
|
28 |
<< "false" // fortsmode
|
|
29 |
<< "false" // team divide
|
|
30 |
<< "false" // solid land
|
|
31 |
<< "false" // border
|
1885
|
32 |
<< "45" // turn time
|
1887
|
33 |
<< "101" // init health
|
1885
|
34 |
<< "15" // sudden death
|
|
35 |
<< "5" // case probability
|
1884
|
36 |
;
|
1881
|
37 |
|
1884
|
38 |
schemes.append(defaultScheme);
|
1881
|
39 |
}
|
|
40 |
|
|
41 |
QVariant AmmoSchemeModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
42 |
{
|
|
43 |
return QVariant();
|
|
44 |
}
|
|
45 |
|
|
46 |
int AmmoSchemeModel::rowCount(const QModelIndex &parent) const
|
|
47 |
{
|
|
48 |
if (parent.isValid())
|
|
49 |
return 0;
|
|
50 |
else
|
|
51 |
return schemes.size();
|
|
52 |
}
|
|
53 |
|
|
54 |
int AmmoSchemeModel::columnCount(const QModelIndex & parent) const
|
|
55 |
{
|
|
56 |
if (parent.isValid())
|
|
57 |
return 0;
|
|
58 |
else
|
1884
|
59 |
return defaultScheme.size();
|
1881
|
60 |
}
|
|
61 |
|
|
62 |
Qt::ItemFlags AmmoSchemeModel::flags(const QModelIndex & index) const
|
|
63 |
{
|
|
64 |
return
|
|
65 |
Qt::ItemIsEnabled
|
|
66 |
| Qt::ItemIsSelectable
|
|
67 |
| Qt::ItemIsEditable;
|
|
68 |
}
|
|
69 |
|
|
70 |
bool AmmoSchemeModel::setData(const QModelIndex & index, const QVariant & value, int role)
|
|
71 |
{
|
1884
|
72 |
if (!index.isValid() || index.row() < 0
|
|
73 |
|| index.row() >= schemes.size()
|
|
74 |
|| index.column() >= defaultScheme.size()
|
1885
|
75 |
|| role != Qt::EditRole)
|
1884
|
76 |
return false;
|
|
77 |
|
|
78 |
schemes[index.row()][index.column()] = value.toString();
|
1885
|
79 |
|
1881
|
80 |
emit dataChanged(index, index);
|
1884
|
81 |
return true;
|
1881
|
82 |
}
|
1884
|
83 |
|
|
84 |
bool AmmoSchemeModel::insertRows(int row, int count, const QModelIndex & parent)
|
|
85 |
{
|
|
86 |
beginInsertRows(parent, row, row);
|
|
87 |
|
1889
|
88 |
QStringList newScheme = defaultScheme;
|
|
89 |
newScheme[0] = tr("new");
|
|
90 |
|
|
91 |
schemes.insert(row, newScheme);
|
1884
|
92 |
|
|
93 |
endInsertRows();
|
|
94 |
}
|
|
95 |
|
|
96 |
bool AmmoSchemeModel::removeRows(int row, int count, const QModelIndex & parent)
|
|
97 |
{
|
|
98 |
beginRemoveRows(parent, row, row);
|
|
99 |
|
|
100 |
schemes.removeAt(row);
|
|
101 |
|
|
102 |
endRemoveRows();
|
|
103 |
}
|
|
104 |
|
|
105 |
QVariant AmmoSchemeModel::data(const QModelIndex &index, int role) const
|
|
106 |
{
|
|
107 |
if (!index.isValid() || index.row() < 0
|
|
108 |
|| index.row() >= schemes.size()
|
|
109 |
|| index.column() >= defaultScheme.size()
|
1889
|
110 |
|| (role != Qt::EditRole && role != Qt::DisplayRole)
|
|
111 |
)
|
1884
|
112 |
return QVariant();
|
|
113 |
|
1887
|
114 |
return QVariant::fromValue(schemes[index.row()][index.column()]);
|
1884
|
115 |
}
|