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

void QListWidget::dropEvent ( QDropEvent event  )  [virtual]

Reimplemented from QListView.

Definition at line 1725 of file qlistwidget.cpp.

References QList< T >::append(), QList< T >::at(), QList< T >::contains(), QList< T >::count(), QAbstractItemView::dragDropMode, QListView::dropEvent(), QAbstractItemModel::index(), insertItem(), QAbstractItemView::model(), QPersistentModelIndex::row(), QListView::selectedIndexes(), QDropEvent::source(), QList< T >::takeFirst(), and takeItem().

                                             {
    Q_D(QListWidget);
    if (event->source() == this && d->movement != Static) {
        QListView::dropEvent(event);
        return;
    }

    if (event->source() == this && (event->proposedAction() == Qt::MoveAction ||
                                    dragDropMode() == QAbstractItemView::InternalMove)) {
        QModelIndex topIndex;
        int col = -1;
        int row = -1;
        if (d->dropOn(event, &row, &col, &topIndex)) {
            QList<QModelIndex> selIndexes = selectedIndexes();
            QList<QPersistentModelIndex> persIndexes;
            for(int i = 0; i < selIndexes.count(); i++)
                persIndexes.append(selIndexes.at(i));

            if (persIndexes.contains(topIndex))
                return;

            QPersistentModelIndex dropRow = model()->index(row, col, topIndex);

            QList<QListWidgetItem *> taken;
            for (int i = 0; i < persIndexes.count(); ++i)
                taken.append(takeItem(persIndexes.at(i).row()));

            // insert them back in at their new positions
            for (int i = 0; i < persIndexes.count(); ++i) {
                // Either at a specific point or appended
                if (row == -1) {
                    insertItem(count(), taken.takeFirst());
                } else {
                    int r = dropRow.row() >= 0 ? dropRow.row() : row;
                    insertItem(qMin(r, count()), taken.takeFirst());
                }
            }

            event->accept();
            // Don't want QAbstractItemView to delete it because it was "moved" we already did it
            event->setDropAction(Qt::CopyAction);
        }
    }

    QListView::dropEvent(event);
}


Generated by  Doxygen 1.6.0   Back to index