Logo Search packages:      
Sourcecode: qt4-x11 version File versions  Download package

int QTreeView::indexRowSizeHint ( const QModelIndex index  )  const [protected, inherited]

Returns the size hint for the row indicated by index.

See also:
sizeHintForColumn()

Definition at line 1558 of file qtreeview.cpp.

References QAbstractItemModel::columnCount(), QWidget::height(), QSize::height(), QWidget::isRightToLeft(), QModelIndex::isValid(), QAbstractItemView::itemDelegate(), QAbstractItemView::model(), QModelIndex::parent(), QStyleOption::rect, QModelIndex::row(), QRect::setWidth(), QModelIndex::sibling(), QAbstractItemDelegate::sizeHint(), QAbstractItemView::viewOptions(), QAbstractScrollArea::viewport(), and QWidget::width().

Referenced by QTreeView::doItemsLayout().

{
    Q_D(const QTreeView);
    if (!index.isValid() || !model())
        return -1;

    int start = -1;
    int end = -1;
    int count = d->header->count();
    if (count) {
        // If the sections have moved, we end up checking too many or too few
        start = d->header->logicalIndexAt(0);
        end = d->header->logicalIndexAt(viewport()->width());
    } else {
        // If the header has not been layed out yet, we use the model directly
        count = model()->columnCount(index.parent());
    }

    if (isRightToLeft()) {
        start = (start == -1 ? count - 1 : start);
        end = (end == -1 ? 0 : end);
    } else {
        start = (start == -1 ? 0 : start);
        end = (end == -1 ? count - 1 : end);
    }

    int tmp = start;
    start = qMin(start, end);
    end = qMax(tmp, end);

    int height = -1;
    QStyleOptionViewItem option = viewOptions();
    // This is temporary hack to speed up the function and will go away in 4.2
    option.rect.setWidth(-1);
    QAbstractItemDelegate *delegate = itemDelegate();
    for (int column = start; column <= end; ++column) {
        QModelIndex idx = index.sibling(index.row(), column);
        if (idx.isValid()) {
            if (QWidget *editor = d->editors.value(idx, 0))
                height = qMax(height, editor->size().height());
            height = qMax(height, delegate->sizeHint(option, idx).height());
        }
    }

    return height;
}


Generated by  Doxygen 1.6.0   Back to index