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

void QListView::setSelection ( const QRect rect,
QItemSelectionModel::SelectionFlags  command 
) [protected, virtual, inherited]

Implements QAbstractItemView.

Definition at line 1365 of file qlistview.cpp.

References QVector< T >::begin(), QVector< T >::end(), QRect::height(), QListView::horizontalOffset(), QModelIndex::isValid(), QModelIndex::row(), QItemSelection::select(), QAbstractItemView::state(), QRect::translated(), QListView::verticalOffset(), and QRect::width().

{
    Q_D(QListView);
    if (!d->selectionModel)
        return;

    d->intersectingSet(rect.translated(horizontalOffset(), verticalOffset()));

    QItemSelection selection;
    QModelIndex tl;
    QModelIndex br;

    if (rect.width() == 1 && rect.height() == 1 && !d->intersectVector.isEmpty()) {
        tl = br = d->intersectVector.last(); // special case for mouse press; only select the top item
    } else {
        if (state() == DragSelectingState) { // visual selection mode (rubberband selection)
            QVector<QModelIndex>::iterator it = d->intersectVector.begin();
            for (; it != d->intersectVector.end(); ++it) {
                if (!tl.isValid() && !br.isValid()) {
                    tl = br = *it;
                } else if ((*it).row() == (tl.row() - 1)) {
                    tl = *it; // expand current range
                } else if ((*it).row() == (br.row() + 1)) {
                    br = (*it); // expand current range
                } else {
                    selection.select(tl, br); // select current range
                    tl = br = *it; // start new range
                }
            }
        } else { // logical selection mode (key and mouse click selection)
            QVector<QModelIndex>::iterator it = d->intersectVector.begin();
            for (; it != d->intersectVector.end(); ++it) {
                if (!tl.isValid() && !br.isValid())
                    tl = br = *it;
                else if ((*it).row() < tl.row())
                    tl = (*it);
                else if ((*it).row() > br.row())
                    br = (*it);
            }
        }
    }

    if (tl.isValid() && br.isValid())
        selection.select(tl, br);
    d->selectionModel->select(selection, command);
}


Generated by  Doxygen 1.6.0   Back to index