QTfrontend/ammoSchemeModel.cpp
changeset 1884 40e59e9f82ce
parent 1881 9b62d68c7b92
child 1885 75489216b5b0
equal deleted inserted replaced
1883:7c7476f56114 1884:40e59e9f82ce
    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();
    41 int AmmoSchemeModel::columnCount(const QModelIndex & parent) const
    50 int AmmoSchemeModel::columnCount(const QModelIndex & parent) const
    42 {
    51 {
    43 	if (parent.isValid())
    52 	if (parent.isValid())
    44 		return 0;
    53 		return 0;
    45 	else
    54 	else
    46 		return 3;
    55 		return defaultScheme.size();
    47 }
    56 }
    48 
    57 
    49 Qt::ItemFlags AmmoSchemeModel::flags(const QModelIndex & index) const
    58 Qt::ItemFlags AmmoSchemeModel::flags(const QModelIndex & index) const
    50 {
    59 {
    51 	return
    60 	return
    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 }