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