QTfrontend/ammoSchemeModel.cpp
author unc0rr
Sun, 15 Mar 2009 17:47:06 +0000
changeset 1895 7ba647a88b2f
parent 1890 de5cfe3beb22
child 1897 e9dcb47013c7
permissions -rw-r--r--
More game options by nemo + some tweaks by me
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
1895
7ba647a88b2f More game options by nemo
unc0rr
parents: 1890
diff changeset
    27
		<< QVariant(tr("Default")) // name           0
7ba647a88b2f More game options by nemo
unc0rr
parents: 1890
diff changeset
    28
		<< QVariant(false)         // fortsmode      1
7ba647a88b2f More game options by nemo
unc0rr
parents: 1890
diff changeset
    29
		<< QVariant(false)         // team divide    2
7ba647a88b2f More game options by nemo
unc0rr
parents: 1890
diff changeset
    30
		<< QVariant(false)         // solid land     3
7ba647a88b2f More game options by nemo
unc0rr
parents: 1890
diff changeset
    31
		<< QVariant(false)         // border         4
7ba647a88b2f More game options by nemo
unc0rr
parents: 1890
diff changeset
    32
		<< QVariant(false)         // low gravity    5
7ba647a88b2f More game options by nemo
unc0rr
parents: 1890
diff changeset
    33
		<< QVariant(false)         // laser sight    6
7ba647a88b2f More game options by nemo
unc0rr
parents: 1890
diff changeset
    34
		<< QVariant(false)         // invulnerable   7
7ba647a88b2f More game options by nemo
unc0rr
parents: 1890
diff changeset
    35
		<< QVariant(true)          // add mines      8
7ba647a88b2f More game options by nemo
unc0rr
parents: 1890
diff changeset
    36
		<< QVariant(100)           // damage modfier 9
7ba647a88b2f More game options by nemo
unc0rr
parents: 1890
diff changeset
    37
		<< QVariant(45)            // turn time      10
7ba647a88b2f More game options by nemo
unc0rr
parents: 1890
diff changeset
    38
		<< QVariant(100)           // init health    11
7ba647a88b2f More game options by nemo
unc0rr
parents: 1890
diff changeset
    39
		<< QVariant(15)            // sudden death   12
7ba647a88b2f More game options by nemo
unc0rr
parents: 1890
diff changeset
    40
		<< QVariant(5)             // case prob      13
1884
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
    41
		;
1881
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    42
1884
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
    43
	schemes.append(defaultScheme);
1881
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
QVariant AmmoSchemeModel::headerData(int section, Qt::Orientation orientation, int role) const
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    47
{
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    48
	return QVariant();
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    49
}
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    50
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    51
int AmmoSchemeModel::rowCount(const QModelIndex &parent) const
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    52
{
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    53
	if (parent.isValid())
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    54
		return 0;
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    55
	else
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    56
		return schemes.size();
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    57
}
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    58
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    59
int AmmoSchemeModel::columnCount(const QModelIndex & parent) const
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    60
{
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    61
	if (parent.isValid())
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    62
		return 0;
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    63
	else
1884
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
    64
		return defaultScheme.size();
1881
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    65
}
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    66
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    67
Qt::ItemFlags AmmoSchemeModel::flags(const QModelIndex & index) const
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    68
{
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    69
	return
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    70
		Qt::ItemIsEnabled
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    71
		| Qt::ItemIsSelectable
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    72
		| Qt::ItemIsEditable;
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    73
}
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    74
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    75
bool AmmoSchemeModel::setData(const QModelIndex & index, const QVariant & value, int role)
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    76
{
1884
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
    77
	if (!index.isValid() || index.row() < 0
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
    78
		|| index.row() >= schemes.size()
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
    79
		|| index.column() >= defaultScheme.size()
1885
75489216b5b0 Continue work on new schemes
unc0rr
parents: 1884
diff changeset
    80
		|| role != Qt::EditRole)
1884
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
    81
		return false;
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
    82
1890
de5cfe3beb22 Scheme options work now
unc0rr
parents: 1889
diff changeset
    83
	schemes[index.row()][index.column()] = value;
1885
75489216b5b0 Continue work on new schemes
unc0rr
parents: 1884
diff changeset
    84
1881
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    85
	emit dataChanged(index, index);
1884
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
    86
	return true;
1881
9b62d68c7b92 Stub for ammo schemes model
unc0rr
parents:
diff changeset
    87
}
1884
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
    88
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
    89
bool AmmoSchemeModel::insertRows(int row, int count, const QModelIndex & parent)
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
    90
{
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
    91
	beginInsertRows(parent, row, row);
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
    92
1890
de5cfe3beb22 Scheme options work now
unc0rr
parents: 1889
diff changeset
    93
	QList<QVariant> newScheme = defaultScheme;
de5cfe3beb22 Scheme options work now
unc0rr
parents: 1889
diff changeset
    94
	newScheme[0] = QVariant(tr("new"));
1889
b8590b604fdd Editing schemes, creating new one works now
unc0rr
parents: 1887
diff changeset
    95
	
b8590b604fdd Editing schemes, creating new one works now
unc0rr
parents: 1887
diff changeset
    96
	schemes.insert(row, newScheme);
1884
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
    97
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
    98
	endInsertRows();
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
    99
}
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
bool AmmoSchemeModel::removeRows(int row, int count, const QModelIndex & parent)
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
   102
{
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
   103
	beginRemoveRows(parent, row, row);
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
   104
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
   105
	schemes.removeAt(row);
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
   106
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
   107
	endRemoveRows();
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
   108
}
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
QVariant AmmoSchemeModel::data(const QModelIndex &index, int role) const
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
   111
{
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
   112
	if (!index.isValid() || index.row() < 0
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
   113
		|| index.row() >= schemes.size()
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
   114
		|| index.column() >= defaultScheme.size()
1889
b8590b604fdd Editing schemes, creating new one works now
unc0rr
parents: 1887
diff changeset
   115
		|| (role != Qt::EditRole && role != Qt::DisplayRole)
b8590b604fdd Editing schemes, creating new one works now
unc0rr
parents: 1887
diff changeset
   116
		)
1884
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
   117
		return QVariant();
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
   118
1890
de5cfe3beb22 Scheme options work now
unc0rr
parents: 1889
diff changeset
   119
	return schemes[index.row()][index.column()];
1884
40e59e9f82ce Continue work on new schemes implementation
unc0rr
parents: 1881
diff changeset
   120
}