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 |
|
|
19 |
#include <QModelIndex>
|
|
20 |
#include "ammoSchemeModel.h"
|
|
21 |
|
|
22 |
AmmoSchemeModel::AmmoSchemeModel(QObject* parent) :
|
|
23 |
QAbstractTableModel(parent)
|
|
24 |
{
|
1884
|
25 |
defaultScheme
|
|
26 |
<< "Default"
|
|
27 |
<< "45"
|
|
28 |
<< "0"
|
|
29 |
<< "0"
|
|
30 |
<< "0"
|
|
31 |
<< "0"
|
|
32 |
;
|
1881
|
33 |
|
1884
|
34 |
schemes.append(defaultScheme);
|
1881
|
35 |
}
|
|
36 |
|
|
37 |
QVariant AmmoSchemeModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
38 |
{
|
|
39 |
return QVariant();
|
|
40 |
}
|
|
41 |
|
|
42 |
int AmmoSchemeModel::rowCount(const QModelIndex &parent) const
|
|
43 |
{
|
|
44 |
if (parent.isValid())
|
|
45 |
return 0;
|
|
46 |
else
|
|
47 |
return schemes.size();
|
|
48 |
}
|
|
49 |
|
|
50 |
int AmmoSchemeModel::columnCount(const QModelIndex & parent) const
|
|
51 |
{
|
|
52 |
if (parent.isValid())
|
|
53 |
return 0;
|
|
54 |
else
|
1884
|
55 |
return defaultScheme.size();
|
1881
|
56 |
}
|
|
57 |
|
|
58 |
Qt::ItemFlags AmmoSchemeModel::flags(const QModelIndex & index) const
|
|
59 |
{
|
|
60 |
return
|
|
61 |
Qt::ItemIsEnabled
|
|
62 |
| Qt::ItemIsSelectable
|
|
63 |
| Qt::ItemIsEditable;
|
|
64 |
}
|
|
65 |
|
|
66 |
bool AmmoSchemeModel::setData(const QModelIndex & index, const QVariant & value, int role)
|
|
67 |
{
|
1884
|
68 |
if (!index.isValid() || index.row() < 0
|
|
69 |
|| index.row() >= schemes.size()
|
|
70 |
|| index.column() >= defaultScheme.size()
|
|
71 |
|| role != Qt::DisplayRole)
|
|
72 |
return false;
|
|
73 |
|
|
74 |
schemes[index.row()][index.column()] = value.toString();
|
1881
|
75 |
emit dataChanged(index, index);
|
1884
|
76 |
return true;
|
1881
|
77 |
}
|
1884
|
78 |
|
|
79 |
bool AmmoSchemeModel::insertRows(int row, int count, const QModelIndex & parent)
|
|
80 |
{
|
|
81 |
beginInsertRows(parent, row, row);
|
|
82 |
|
|
83 |
schemes.insert(row, defaultScheme);
|
|
84 |
|
|
85 |
endInsertRows();
|
|
86 |
}
|
|
87 |
|
|
88 |
bool AmmoSchemeModel::removeRows(int row, int count, const QModelIndex & parent)
|
|
89 |
{
|
|
90 |
beginRemoveRows(parent, row, row);
|
|
91 |
|
|
92 |
schemes.removeAt(row);
|
|
93 |
|
|
94 |
endRemoveRows();
|
|
95 |
}
|
|
96 |
|
|
97 |
QVariant AmmoSchemeModel::data(const QModelIndex &index, int role) const
|
|
98 |
{
|
|
99 |
if (!index.isValid() || index.row() < 0
|
|
100 |
|| index.row() >= schemes.size()
|
|
101 |
|| index.column() >= defaultScheme.size()
|
|
102 |
|| role != Qt::DisplayRole)
|
|
103 |
return QVariant();
|
|
104 |
|
|
105 |
return schemes[index.row()][index.column()];
|
|
106 |
}
|