/*! Clears the current selection. For each item QGraphicsItem::setSelected(false) is called. Items can adjust selection state by responding to QGraphicsItem::ItemSelectedChange notification in custom implementations of QGraphicsItem::itemChange(). Items that adjust selection state from unselected to selected are not removed from selection. \sa setSelectionArea(), selectedItems(), QGraphicsItem::itemChange() */ void QGraphicsScene::clearSelection() { Q_D(QGraphicsScene); // Disable emitting selectionChanged ++d->selectionChanging; // Try to deselect selected items. // Note that deselection can be overridden in itemChange(). foreach (QGraphicsItem *item, d->selectedItems) { item->setSelected(false); } // Count deselected items. int changedCount = 0; foreach (QGraphicsItem *item, d->selectedItems) { if (!item->isSelected()) { changedCount++; } } // Remove deselected items from selection list. Removing is decoupled from // deselecting to support complicated deselection schemes. if (changedCount == d->selectedItems.count()) { d->selectedItems.clear(); } else if (changedCount > 0) { QMutableSetIterator it(d->selectedItems); while (it.hasNext()) { QGraphicsItem *item = it.next(); if (!item->isSelected()) { it.remove(); } } } // Reenable emitting selectionChanged() for individual items. --d->selectionChanging; if (!d->selectionChanging && changedCount > 0) emit selectionChanged(); }