- Timestamp:
- Mar 27, 2019 12:43:21 PM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.cpp
r77891 r77916 109 109 UIActionPool *UIChooserModel::actionPool() const 110 110 { 111 return chooser() ->actionPool();111 return chooser() ? chooser()->actionPool() : 0; 112 112 } 113 113 … … 117 117 } 118 118 119 UIChooserView *UIChooserModel::view() 120 { 121 if (!scene()) 122 return 0; 123 UIChooserView *pChooserView = qobject_cast<UIChooserView*>(scene()->views()[0]); 124 return pChooserView; 119 UIChooserView *UIChooserModel::view() const 120 { 121 return scene() && !scene()->views().isEmpty() ? qobject_cast<UIChooserView*>(scene()->views().first()) : 0; 125 122 } 126 123 127 124 QPaintDevice *UIChooserModel::paintDevice() const 128 125 { 129 if (scene() && !scene()->views().isEmpty()) 130 return scene()->views().first(); 131 return 0; 126 return scene() && !scene()->views().isEmpty() ? scene()->views().first() : 0; 132 127 } 133 128 134 129 QGraphicsItem *UIChooserModel::itemAt(const QPointF &position, const QTransform &deviceTransform /* = QTransform() */) const 135 130 { 136 return scene() ->itemAt(position, deviceTransform);131 return scene() ? scene()->itemAt(position, deviceTransform) : 0; 137 132 } 138 133 … … 389 384 void UIChooserModel::makeSureSomeItemIsSelected() 390 385 { 391 /* Make sure selection item list is never empty392 * if atleast one item (for example 'focus') present: */386 /* Make sure selection list is never empty if at 387 * least one item (for example 'focus') present: */ 393 388 if (!currentItem() && focusItem()) 394 389 setCurrentItem(focusItem()); … … 447 442 void UIChooserModel::performSearch(const QString &strSearchTerm, int iItemSearchFlags) 448 443 { 449 if (!invisibleRoot()) 450 return; 451 452 /* Currently we perform the search only for machines. when this to be changed make sure the disabled flags 453 of the other item types are also managed correctly: */ 454 455 QList<UIChooserNode*> allNodes = resetSearch(); 444 /* Invisible root always exists: */ 445 AssertPtrReturnVoid(invisibleRoot()); 446 447 /* Currently we perform the search only for machines, when this to be changed make 448 * sure the disabled flags of the other item types are also managed correctly. */ 449 450 /* Reset the search first to erase the disabled flag: */ 451 const QList<UIChooserNode*> nodes = resetSearch(); 452 453 /* Stop here if no search conditions specified: */ 456 454 if (strSearchTerm.isEmpty()) 457 455 return; 458 456 457 /* Search for all the nodes matching required condition: */ 459 458 invisibleRoot()->searchForNodes(strSearchTerm, iItemSearchFlags, m_searchResults); 460 459 461 foreach (UIChooserNode* pNode, allNodes) 460 /* Assign/reset the disabled flag for required nodes: */ 461 foreach (UIChooserNode* pNode, nodes) 462 462 { 463 463 if (!pNode) … … 466 466 } 467 467 468 /* Make sure 1st item visible: */ 468 469 scrollToSearchResult(true); 469 470 } … … 471 472 QList<UIChooserNode*> UIChooserModel::resetSearch() 472 473 { 473 QList<UIChooserNode*> allNodes; 474 /* Calling UIChooserNode::searchForNodes with an empty search string returns a list all nodes (of the whole treee) of the required type: */ 475 invisibleRoot()->searchForNodes(QString(), UIChooserItemSearchFlag_Machine, allNodes); 476 477 /* Reset the disabled flag of the node items first. */ 478 foreach (UIChooserNode* pNode, allNodes) 474 QList<UIChooserNode*> nodes; 475 476 /* Invisible root always exists: */ 477 AssertPtrReturn(invisibleRoot(), nodes); 478 479 /* Calling UIChooserNode::searchForNodes with an empty search string 480 * returns a list all nodes (of the whole tree) of the required type: */ 481 invisibleRoot()->searchForNodes(QString(), UIChooserItemSearchFlag_Machine, nodes); 482 483 /* Reset the disabled flag of the nodes first: */ 484 foreach (UIChooserNode *pNode, nodes) 479 485 { 480 486 if (!pNode) … … 482 488 pNode->setDisabled(false); 483 489 } 484 /* Reset the search result relate data: */ 490 491 /* Reset the search result related data: */ 485 492 m_searchResults.clear(); 486 493 m_iCurrentScrolledIndex = -1; 487 return allNodes;494 return nodes; 488 495 } 489 496 490 497 void UIChooserModel::scrollToSearchResult(bool fIsNext) 491 498 { 499 /* If nothing was found: */ 492 500 if (m_searchResults.isEmpty()) 493 501 { 502 /* Clear the search widget's match count(s): */ 494 503 m_iCurrentScrolledIndex = -1; 495 504 if (view()) … … 552 561 /* Remember new drag-object: */ 553 562 m_pCurrentDragObject = pDragObject; 554 connect(m_pCurrentDragObject, SIGNAL(destroyed(QObject*)), this, SLOT(sltCurrentDragObjectDestroyed())); 563 connect(m_pCurrentDragObject, &QDrag::destroyed, 564 this, &UIChooserModel::sltCurrentDragObjectDestroyed); 555 565 } 556 566 … … 660 670 if (!fRegistered) 661 671 { 662 /* Rebuild tree for main root: */ 663 buildTreeForMainRoot(); 672 /* Update tree for main root: */ 664 673 updateNavigation(); 665 674 updateLayout(); … … 734 743 if (!actionPool()->action(UIActionIndexST_M_Group_S_Rename)->isEnabled()) 735 744 return; 736 737 745 /* Only for single selected group: */ 738 746 if (!isSingleGroupSelected()) … … 748 756 if (!actionPool()->action(UIActionIndexST_M_Group_S_Sort)->isEnabled()) 749 757 return; 750 751 758 /* Only for single selected group: */ 752 759 if (!isSingleGroupSelected()) 753 760 return; 754 761 755 /* Sort group-node: */ 756 sortNodes(currentItem()->node()); 757 } 758 759 void UIChooserModel::sltShowHideSearchWidget() 760 { 761 if (view()) 762 setSearchWidgetVisible(!view()->isSearchWidgetVisible()); 762 /* Sort nodes: */ 763 currentItem()->node()->sortNodes(); 764 765 /* Rebuild tree for main root: */ 766 buildTreeForMainRoot(); 767 updateNavigation(); 768 updateLayout(); 763 769 } 764 770 … … 973 979 return; 974 980 975 /* Sort parent group-node: */ 976 sortNodes(currentItem()->parentItem()->node()); 981 /* Sort nodes: */ 982 currentItem()->parentItem()->node()->sortNodes(); 983 984 /* Rebuild tree for main root: */ 985 buildTreeForMainRoot(); 986 updateNavigation(); 987 updateLayout(); 977 988 } 978 989 … … 1128 1139 { 1129 1140 root()->resetDragToken(); 1141 } 1142 1143 void UIChooserModel::sltShowHideSearchWidget() 1144 { 1145 if (view()) 1146 setSearchWidgetVisible(!view()->isSearchWidgetVisible()); 1130 1147 } 1131 1148 … … 1648 1665 return false; 1649 1666 } 1650 1651 void UIChooserModel::sortNodes(UIChooserNode *pNode)1652 {1653 /* Sort nodes: */1654 pNode->sortNodes();1655 1656 /* Rebuild tree for main root: */1657 buildTreeForMainRoot();1658 updateNavigation();1659 updateLayout();1660 } -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.h
r77909 r77916 104 104 /** Returns the scene reference. */ 105 105 QGraphicsScene *scene() const; 106 /** Returns the reference of the first view of the scene(). */ 107 UIChooserView *view() const; 106 108 /** Returns the paint device reference. */ 107 109 QPaintDevice *paintDevice() const; … … 180 182 /** Performs a search starting from the m_pInvisibleRootNode. */ 181 183 void performSearch(const QString &strSearchTerm, int iItemSearchFlags); 182 /** Clean the search result data members and disables item's visual effects. Also returns a list of183 * all nodes which may be utilized by the calling code. */184 /** Cleans the search result data members and disables item's visual effects. 185 * Also returns a list of all nodes which may be utilized by the calling code. */ 184 186 QList<UIChooserNode*> resetSearch(); 185 187 /** Scrolls to next/prev (wrt. @a fIsNext) search result. */ … … 262 264 /** Handles group sort request. */ 263 265 void sltSortGroup(); 264 /** Handles machine search widget show/hide request. */265 void sltShowHideSearchWidget();266 266 /** Handles group destroy request. */ 267 267 void sltUngroupSelectedGroup(); … … 283 283 void sltCurrentDragObjectDestroyed(); 284 284 285 /** Handles machine search widget show/hide request. */ 286 void sltShowHideSearchWidget(); 285 287 /** Handles request to erase lookup timer. */ 286 288 void sltEraseLookupTimer(); … … 326 328 /** Popups context-menu of certain @a enmType in specified @a point. */ 327 329 void popupContextMenu(UIGraphicsSelectorContextMenuType enmType, QPoint point); 328 /** Returns the reference of the first view of the scene(). */329 UIChooserView *view();330 330 /** @} */ 331 331 … … 356 356 /** Processes drag leave @a pEvent. */ 357 357 bool processDragLeaveEvent(QGraphicsSceneDragDropEvent *pEvent); 358 359 /** Performs sorting for @a pNode. */360 void sortNodes(UIChooserNode *pNode);361 358 /** @} */ 362 359
Note:
See TracChangeset
for help on using the changeset viewer.