VirtualBox

Changeset 39238 in vbox


Ignore:
Timestamp:
Nov 8, 2011 1:12:09 PM (13 years ago)
Author:
vboxsync
Message:

FE/Qt: 5804: Allow one operation on several VMs: Using '1st item of selection' instead of 'current item' for VM selector action handling purposes (because Qt handles 'current item' in very specific way).

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  
    421421UIVMItem *UIVMListView::currentItem() const
    422422{
    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*>();
    424428}
    425429
    426430QList<UIVMItem*> UIVMListView::currentItems() const
    427431{
     432    /* Prepare selected item list: */
    428433    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: */
    431440    return currentItems;
    432441}
     
    442451    QListView::selectionChanged(aSelected, aDeselected);
    443452
    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())
    455455        selectionModel()->select(currentIndex(), QItemSelectionModel::SelectCurrent);
    456 
    457     /* Remember the current item: */
    458     m_previousCurrentIndex = currentIndex();
    459456
    460457    /* Ensure current index is visible: */
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UIVMListView.h

    r39096 r39238  
    127127private:
    128128    bool m_fItemInMove;
    129     QModelIndex m_previousCurrentIndex;
    130129};
    131130
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette