----------------------------------------------------------------------------- ! ImageViewerWindow::sortTabs */
| 367 | ImageViewerWindow::sortTabs |
| 368 | */ |
| 369 | void ImageViewerWindow::sortTabs() |
| 370 | { |
| 371 | qDebug() << "ImageViewerWindow::sortTabs"; |
| 372 | |
| 373 | // sort tabs according to their depth |
| 374 | int moveTo = 0; |
| 375 | int currentDepth = 0; |
| 376 | bool found = false; |
| 377 | bool sorted = false; |
| 378 | bool anyMoved = false; |
| 379 | |
| 380 | // get the tab bar that we can use to move tabs |
| 381 | QList< QTabBar* > tabBars = ui->tabWidget->findChildren<QTabBar*>(); |
| 382 | if ( tabBars.empty() ) return; |
| 383 | QTabBar* tabBar = tabBars.at(0); |
| 384 | |
| 385 | // disable gui updates so we don't make tabs go crazy |
| 386 | ui->tabWidget->setUpdatesEnabled(false); |
| 387 | |
| 388 | do{ |
| 389 | found = false; |
| 390 | |
| 391 | // shift move to forward to minimize moving tabs around |
| 392 | for ( int i=moveTo; i < ui->tabWidget->count();i++){ |
| 393 | IPImageViewer* tab = dynamic_cast<IPImageViewer*>( ui->tabWidget->widget(i) ); |
| 394 | if ( !tab ) continue; |
| 395 | if ( tab->processStep()->treeDepth() == currentDepth ){ |
| 396 | moveTo++; |
| 397 | found = true; |
| 398 | }else{ |
| 399 | break; |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | // scan from back to front to see if any other items at this depth and need to be shifted up |
| 404 | sorted = true; |
| 405 | int lastDepth = -1; |
| 406 | for ( int i=ui->tabWidget->count()-1; i >= moveTo; i--){ |
| 407 | IPImageViewer* tab = dynamic_cast<IPImageViewer*>( ui->tabWidget->widget(i) ); |
| 408 | if ( !tab ) continue; |
| 409 | // if the depth behind this one is less than this depth, we're not sorted |
| 410 | // otherwise, if this stays true we can break out of the process early |
| 411 | if ( sorted && lastDepth != -1 && lastDepth < tab->processStep()->treeDepth() ) |
| 412 | sorted = false; |
| 413 | lastDepth = tab->processStep()->treeDepth(); |
| 414 | // just checking moveTo spot to see if it's in order |
| 415 | if ( i== moveTo) break; |
| 416 | if ( tab->processStep()->treeDepth() == currentDepth ){ |
| 417 | anyMoved = true; |
| 418 | tabBar->moveTab(i,moveTo); |
| 419 | moveTo++; |
| 420 | found = true; |
| 421 | // moving the tab pushed back a different tab into this spot, shift |
| 422 | // i so we check it in the next loop |
| 423 | i++; |
| 424 | } |
| 425 | } |
| 426 | currentDepth++; |
no test coverage detected