PDA

View Full Version : How to convert a horizontal model to a vertical model?



The Lion
4th June 2013, 16:03
Hi,

I have a horizontal table model with [1 row x 7 columns].
I'd like to make a proxy model to it, which will be a vertical [7 rows x 1 column] model.
Someone suggests me to use QIdentityProxyModel, but I have no idea further.
Would somebody please give me advises?
Many thanks in advance.

Jong Hwang

pkj
4th June 2013, 16:46
Re implement columnCount, rowCount, and data functions of your inherited qidentityproxyModel...


int MyIdentityProxyModel::columnCount(...) const {
return sourceModel()->rowCount();
}
int MyIdentityProxyModel::rowCount(...) const {
return sourceModel()->columnCount();
}
QVariant MyIdentityProxyModel::data(const QModelIndex &idx, int role)
{
if (role != Qt::DisplayRole) return QIdentityProxyModel::data(idx, role);
QModelIndex srcIdx = sourceModel()->index(idx.column(), idx.role());
return srcIdx.data();
}

This is not tested code. But just to give you an idea.

The Lion
5th June 2013, 09:11
Thank you very much for your quick and helpful info.

Jong Hwang

ChrisW67
5th June 2013, 09:40
Example in the wiki: Transpose proxy model

The Lion
5th June 2013, 10:53
Thank you very much.
I was about to pull my hair out.
You saved my life. :)