-----------------------------------------------------------------------------
| 442 | |
| 443 | //----------------------------------------------------------------------------- |
| 444 | int ctkVTKObjectEventsObserver::removeConnection(vtkObject* vtk_obj, unsigned long vtk_event, |
| 445 | const QObject* qt_obj, const char* qt_slot) |
| 446 | { |
| 447 | Q_D(ctkVTKObjectEventsObserver); |
| 448 | |
| 449 | QList<ctkVTKConnection*> connections = |
| 450 | d->findConnections(vtk_obj, vtk_event, qt_obj, qt_slot); |
| 451 | |
| 452 | foreach (ctkVTKConnection* connection, connections) |
| 453 | { |
| 454 | delete connection; |
| 455 | } |
| 456 | |
| 457 | // Only remove shadow connections (connections in the index without a corresponding actual connection) |
| 458 | // from the index if the index size grew too big (shadow elements ratio >50% and minimum 100) |
| 459 | if (static_cast<int>(d->ConnectionIndex.size())>100+children().count()*2) |
| 460 | { |
| 461 | for (ctkVTKObjectEventsObserverPrivate::ConnectionIndexType::iterator connectionIt=d->ConnectionIndex.begin(); |
| 462 | connectionIt!=d->ConnectionIndex.end(); |
| 463 | /*upon deletion the increment is done already, so don't increment here*/) |
| 464 | { |
| 465 | ctkVTKConnection* connection=connectionIt.value(); |
| 466 | if (!children().contains(connection)) |
| 467 | { |
| 468 | // connection has been deleted, so remove it from the index |
| 469 | connectionIt=d->ConnectionIndex.erase(connectionIt); |
| 470 | continue; |
| 471 | } |
| 472 | ++connectionIt; |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | return connections.count(); |
| 477 | } |
| 478 | |
| 479 | //----------------------------------------------------------------------------- |
| 480 | int ctkVTKObjectEventsObserver::removeAllConnections() |