QPlace

25th June 2009, 20:16

It is my first attempt to get a tree model going and I am stuck - don't quite understand how to implement method:

QModelIndex QAbstractItemModel::parent ( const QModelIndex& index ) const

My model displays QList<Apartments> as root items, where each apartment has one or more occupants. When I construct an index, reimplementing method

QModelIndex QAbstractItemModel::index(int row, int column, const QModelIndex &parent) const

I construct the index with createIndex(row, column, Pointer), where Pointer is a pointer to either Apartment or Occupant. I know what to use, Apartment or Occupant, depending on parent.isValid() call.

My question is: when I have to construct parent for a given index in the QAbstractItemModel::parent - how do I know if I am getting a root item (Apartment) to which I have to return QModelIndex() or a child Item (Occupant) to which I have to construct a parent?

Any help is greatly appreciated

QModelIndex QAbstractItemModel::parent ( const QModelIndex& index ) const

My model displays QList<Apartments> as root items, where each apartment has one or more occupants. When I construct an index, reimplementing method

QModelIndex QAbstractItemModel::index(int row, int column, const QModelIndex &parent) const

I construct the index with createIndex(row, column, Pointer), where Pointer is a pointer to either Apartment or Occupant. I know what to use, Apartment or Occupant, depending on parent.isValid() call.

My question is: when I have to construct parent for a given index in the QAbstractItemModel::parent - how do I know if I am getting a root item (Apartment) to which I have to return QModelIndex() or a child Item (Occupant) to which I have to construct a parent?

Any help is greatly appreciated