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

bool QItemSelectionModel::isSelected ( const QModelIndex index  )  const

Returns true if the given model item index is selected.

Definition at line 1109 of file qitemselectionmodel.cpp.

References QModelIndex::isValid(), and QModelIndex::model().

Referenced by QTreeWidget::isItemSelected(), QTableWidget::isItemSelected(), QListWidget::isItemSelected(), and QListView::paintEvent().

{
    Q_D(const QItemSelectionModel);
    if (d->model != index.model() || !index.isValid())
        return false;

    bool selected = false;
    //  search model ranges
    QList<QItemSelectionRange>::const_iterator it = d->ranges.begin();
    for (; it != d->ranges.end(); ++it) {
        if ((*it).contains(index)) {
            selected = true;
            break;
        }
    }

    // check  currentSelection
    if (d->currentSelection.count()) {
        if ((d->currentCommand & Deselect) && selected)
            selected = !d->currentSelection.contains(index);
        else if (d->currentCommand & Toggle)
            selected ^= d->currentSelection.contains(index);
        else if ((d->currentCommand & Select) && !selected)
            selected = d->currentSelection.contains(index);
    }

    if (selected && (d->model->flags(index) & Qt::ItemIsSelectable))
        return true;

    return false;
}


Generated by  Doxygen 1.6.0   Back to index