20 #include "ammoSchemeModel.h" |
20 #include "ammoSchemeModel.h" |
21 |
21 |
22 AmmoSchemeModel::AmmoSchemeModel(QObject* parent) : |
22 AmmoSchemeModel::AmmoSchemeModel(QObject* parent) : |
23 QAbstractTableModel(parent) |
23 QAbstractTableModel(parent) |
24 { |
24 { |
|
25 defaultScheme |
|
26 << "Default" |
|
27 << "45" |
|
28 << "0" |
|
29 << "0" |
|
30 << "0" |
|
31 << "0" |
|
32 ; |
25 |
33 |
|
34 schemes.append(defaultScheme); |
26 } |
35 } |
27 |
36 |
28 QVariant AmmoSchemeModel::headerData(int section, Qt::Orientation orientation, int role) const |
37 QVariant AmmoSchemeModel::headerData(int section, Qt::Orientation orientation, int role) const |
29 { |
38 { |
30 return QVariant(); |
39 return QVariant(); |
54 | Qt::ItemIsEditable; |
63 | Qt::ItemIsEditable; |
55 } |
64 } |
56 |
65 |
57 bool AmmoSchemeModel::setData(const QModelIndex & index, const QVariant & value, int role) |
66 bool AmmoSchemeModel::setData(const QModelIndex & index, const QVariant & value, int role) |
58 { |
67 { |
|
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(); |
59 emit dataChanged(index, index); |
75 emit dataChanged(index, index); |
|
76 return true; |
60 } |
77 } |
|
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 } |