Ejemplo n.º 1
0
QModelIndex Model::parent( const QModelIndex & child ) const {
  /*
  parent()
    Provides a model index corresponding to the parent of any given child item.
    If the model index specified corresponds to a top-level item in the model,
    or if there is no valid parent item in the model, the function must return
    an invalid model index, created with the empty QModelIndex() constructor.
  */
  // fall 1: parentitem fuer invalid
//       qDebug() << "parent ";
//  << QString("%1").arg((unsigned int) child);

  if ( !child.isValid() ) {
    return QModelIndex();
  }
//     qDebug() << "parent2or3";

  AbstractTreeItem *childItem =
    static_cast<AbstractTreeItem*>( child.internalPointer() );
  AbstractTreeItem *parentItem = childItem->parent();

// fall 2: parentitem fuer rootItem
//   if ( parentItem == NULL )
//     return QModelIndex();

  if ( parentItem == rootItem )
    return QModelIndex();

// fall 3: parentitem fuer alle anderen
//     return index(r,c,parent model index);
  return createIndex( parentItem->row(), 0, parentItem );
}
Ejemplo n.º 2
0
void AbstractTreeItem::dumpChildList() {
  qDebug() << "==== Childlist for Item:" << this << "====";
  if(childCount() > 0) {
    AbstractTreeItem *child;
    QList<AbstractTreeItem *>::const_iterator childIter = _childItems.constBegin();
    while(childIter != _childItems.constEnd()) {
      child = *childIter;
      qDebug() << "Row:" << child->row() << child << child->data(0, Qt::DisplayRole);
      childIter++;
    }
  }
  qDebug() << "==== End Of Childlist ====";
}