#include "ModeleTable.h"
#include <QDragEnterEvent>
#include <QDropEvent>

ModeleTable::ModeleTable(QObject *parent)
	: QAbstractTableModel(parent)
{
	for (int colonne = 0; colonne < 4; colonne++)
	{
		QList<QString> sousListe;
		
		for (int ligne = 0; ligne < 5; ligne++)
		{
			sousListe.append("");
		}
		
		liste.append(sousListe);
	}
}

int ModeleTable::rowCount(const QModelIndex &parent) const
{
	return liste.first().count();
}

int ModeleTable::columnCount(const QModelIndex &parent) const
{
	return liste.count();
}

QVariant ModeleTable::data(const QModelIndex &index, int role) const
{
	if (false == index.isValid() )
	{
		return QVariant();
	}
	
	if (Qt::DisplayRole != role)
	{
		return QVariant();
	}
	
	if (index.column() >= liste.count() )
	{
		return QVariant();
	}
	else if(index.row() >= liste.first().count() )
	{
		return QVariant();
	}
	
	return liste.at(index.column() ).at(index.row() );
}

bool ModeleTable::setData(const QModelIndex &index, const QVariant &value, int role)
{
	//if (true == index.isValid() && Qt::EditRole == role)
	if (true == index.isValid() )
	{
		liste[index.column()].replace(index.row(), value.toString() );
		
		emit dataChanged(index, index);
	}
	
	return true;
}

Qt::ItemFlags ModeleTable::flags(const QModelIndex &index) const
{
	return QAbstractItemModel::flags(index) | Qt::ItemIsDropEnabled;
}
