#include "insertProxyModel.h"
//--------------------------------------------------------------------------
{
m_insertPos = insertPos;
m_nbCol = nbCol;
connect(this, SIGNAL(sourceModelChanged()), this, SLOT(slotSourceModelChanged()));
}
//--------------------------------------------------------------------------
InsertProxyModel::~InsertProxyModel()
{
}
//--------------------------------------------------------------------------
{
if(!parent.isValid())
{
res = createIndex(row, column);
}
return res;
}
//--------------------------------------------------------------------------
{
}
//--------------------------------------------------------------------------
int InsertProxyModel
::rowCount(const QModelIndex & parent
) const {
int res = 0;
if(!parent.isValid())
{
}
return res;
}
//--------------------------------------------------------------------------
int InsertProxyModel
::columnCount(const QModelIndex & parent
) const {
int res = 0;
if(!parent.isValid())
{
res = sourceModel()->columnCount() + m_nbCol;
}
return res;
}
//--------------------------------------------------------------------------
{
if(proxyIndex.isValid())
{
if(proxyIndex.column() >= m_insertPos && proxyIndex.column() <= (m_insertPos+m_nbCol-1))
{
res = createIndex(proxyIndex.row(), -1, (quintptr)-1);
}
else if(proxyIndex.column() < m_insertPos)
{
res = sourceModel()->index(proxyIndex.row(), proxyIndex.column());
}
else
{
res = sourceModel()->index(proxyIndex.row(), proxyIndex.column()-m_nbCol);
}
}
return res;
}
//--------------------------------------------------------------------------
{
if(!sourceIndex.isValid())
{
if((sourceIndex.row() > -1) &&
(sourceIndex.column() >= m_insertPos && sourceIndex.column() <= (m_insertPos+m_nbCol-1)) &&
(sourceIndex.internalId() == (quintptr)(sourceIndex.column())))
{
res = index(sourceIndex.row(), sourceIndex.column());
}
}
else
{
res = index(sourceIndex.row(), sourceIndex.column());
}
return res;
}
//--------------------------------------------------------------------------
QVariant InsertProxyModel
::headerData(int section, Qt
::Orientation orientation,
int role
) const {
if(orientation == Qt::Horizontal)
{
if(section >= m_insertPos && section <= (m_insertPos+m_nbCol-1))
{
}
else if(section < m_insertPos)
{
res = sourceModel()->headerData(section, orientation, role);
}
else
{
res = sourceModel()->headerData(section-m_nbCol, orientation, role);
}
}
else
{
res = sourceModel()->headerData(section, orientation, role);
}
return res;
}
//--------------------------------------------------------------------------
{
if(index.column() >= m_insertPos && index.column() <= (m_insertPos+m_nbCol-1))
{
if((role == Qt::DisplayRole) || (role == Qt::EditRole))
{
if(index.row() < mData.size())
{
//res = mData.at(index.row());
//I try to put the same test text in all the added column here
res = "bleh";
}
}
}
else
{
res = sourceModel()->data(mapToSource(index), role);
}
return res;
}
//--------------------------------------------------------------------------
{
bool res = false;
if(index.column() >= m_insertPos && index.column() <= (m_insertPos+m_nbCol-1))
{
if((role == Qt::DisplayRole) || (role == Qt::EditRole))
{
while((index.row() + 1) > mData.size())
{
}
mData[index.row()] = value.toString();
return true;
}
}
else
{
res = sourceModel()->setData(mapToSource(index), value, role);
}
return res;
}
//--------------------------------------------------------------------------
Qt
::ItemFlags InsertProxyModel
::flags(const QModelIndex &index
) const{
Qt::ItemFlags res;
if(index.column() >= m_insertPos && index.column() <= (m_insertPos+m_nbCol-1))
{
res = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
}
else
{
res = sourceModel()->flags(mapToSource(index));
}
return res;
}
//--------------------------------------------------------------------------
void InsertProxyModel::slotSourceModelChanged(void)
{
}
//--------------------------------------------------------------------------
{
emit dataChanged(mapFromSource(first), mapFromSource(last));
}
//--------------------------------------------------------------------------