Changeset 39238 in vbox
- Timestamp:
- Nov 8, 2011 1:12:09 PM (13 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/selector
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/selector/UIVMListView.cpp
r39096 r39238 421 421 UIVMItem *UIVMListView::currentItem() const 422 422 { 423 return model()->data(currentIndex(), UIVMItemModel::UIVMItemPtrRole).value<UIVMItem*>(); 423 /* Get current selection: */ 424 QModelIndexList selectedIndexes = selectionModel()->selectedIndexes(); 425 /* Return 1st of selected items or NULL if nothing selected: */ 426 return selectedIndexes.isEmpty() ? 0 : 427 model()->data(selectedIndexes[0], UIVMItemModel::UIVMItemPtrRole).value<UIVMItem*>(); 424 428 } 425 429 426 430 QList<UIVMItem*> UIVMListView::currentItems() const 427 431 { 432 /* Prepare selected item list: */ 428 433 QList<UIVMItem*> currentItems; 429 for (int i = 0; i < selectionModel()->selectedIndexes().size(); ++i) 430 currentItems << model()->data(selectionModel()->selectedIndexes()[i], UIVMItemModel::UIVMItemPtrRole).value<UIVMItem*>(); 434 /* Get current selection: */ 435 QModelIndexList selectedIndexes = selectionModel()->selectedIndexes(); 436 /* For every item of the selection => add it into the selected item list: */ 437 for (int i = 0; i < selectedIndexes.size(); ++i) 438 currentItems << model()->data(selectedIndexes[i], UIVMItemModel::UIVMItemPtrRole).value<UIVMItem*>(); 439 /* Return selected item list: */ 431 440 return currentItems; 432 441 } … … 442 451 QListView::selectionChanged(aSelected, aDeselected); 443 452 444 /* If selection still contains previous 'current index' => 445 * make it the new 'current index': */ 446 if (selectionModel()->selection().contains(m_previousCurrentIndex)) 447 selectionModel()->setCurrentIndex(m_previousCurrentIndex, QItemSelectionModel::NoUpdate); 448 /* If selection do NOT contains previous 'current item' but contains at least something => 449 * set first of the selected items as the new 'current item': */ 450 else if (!selectionModel()->selectedIndexes().isEmpty()) 451 selectionModel()->setCurrentIndex(selectionModel()->selectedIndexes()[0], QItemSelectionModel::NoUpdate); 452 /* If selection do NOT contains anything at all (is empty) => 453 * select current index: */ 454 else 453 /* If selection is empty => select 'current item': */ 454 if (selectionModel()->selectedIndexes().isEmpty()) 455 455 selectionModel()->select(currentIndex(), QItemSelectionModel::SelectCurrent); 456 457 /* Remember the current item: */458 m_previousCurrentIndex = currentIndex();459 456 460 457 /* Ensure current index is visible: */ -
trunk/src/VBox/Frontends/VirtualBox/src/selector/UIVMListView.h
r39096 r39238 127 127 private: 128 128 bool m_fItemInMove; 129 QModelIndex m_previousCurrentIndex;130 129 }; 131 130
Note:
See TracChangeset
for help on using the changeset viewer.