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
|
|
28 |
<< "0" // fortsmode
|
|
29 |
<< "0" // team divide
|
|
30 |
<< "0" // solid land
|
|
31 |
<< "0" // border
|
|
32 |
<< "45" // turn time
|
|
33 |
<< "100" // init health
|
|
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 |
|
|
88 |
schemes.insert(row, defaultScheme);
|
|
89 |
|
|
90 |
endInsertRows();
|
|
91 |
}
|
|
92 |
|
|
93 |
bool AmmoSchemeModel::removeRows(int row, int count, const QModelIndex & parent)
|
|
94 |
{
|
|
95 |
beginRemoveRows(parent, row, row);
|
|
96 |
|
|
97 |
schemes.removeAt(row);
|
|
98 |
|
|
99 |
endRemoveRows();
|
|
100 |
}
|
|
101 |
|
|
102 |
QVariant AmmoSchemeModel::data(const QModelIndex &index, int role) const
|
|
103 |
{
|
|
104 |
if (!index.isValid() || index.row() < 0
|
|
105 |
|| index.row() >= schemes.size()
|
|
106 |
|| index.column() >= defaultScheme.size()
|
|
107 |
|| role != Qt::DisplayRole)
|
|
108 |
return QVariant();
|
|
109 |
|
|
110 |
return schemes[index.row()][index.column()];
|
|
111 |
}
|