Changeset 77948 in vbox
- Timestamp:
- Mar 29, 2019 10:46:10 AM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserAbstractModel.cpp
r77909 r77948 108 108 strResult += " " + QString::number(iMinimumPossibleNumber); 109 109 return strResult; 110 } 111 112 void UIChooserAbstractModel::performSearch(const QString &strSearchTerm, int iItemSearchFlags) 113 { 114 /* Make sure invisible root exists: */ 115 AssertPtrReturnVoid(invisibleRoot()); 116 117 /* Currently we perform the search only for machines, when this to be changed make 118 * sure the disabled flags of the other item types are also managed correctly. */ 119 120 /* Reset the search first to erase the disabled flag, 121 * this also returns a full list of all machine nodes: */ 122 const QList<UIChooserNode*> nodes = resetSearch(); 123 124 /* Stop here if no search conditions specified: */ 125 if (strSearchTerm.isEmpty()) 126 return; 127 128 /* Search for all the nodes matching required condition: */ 129 invisibleRoot()->searchForNodes(strSearchTerm, iItemSearchFlags, m_searchResults); 130 131 /* Assign/reset the disabled flag for required nodes: */ 132 foreach (UIChooserNode *pNode, nodes) 133 { 134 if (!pNode) 135 continue; 136 pNode->setDisabled(!m_searchResults.contains(pNode)); 137 } 138 } 139 140 QList<UIChooserNode*> UIChooserAbstractModel::resetSearch() 141 { 142 /* Prepare resulting nodes: */ 143 QList<UIChooserNode*> nodes; 144 145 /* Make sure invisible root exists: */ 146 AssertPtrReturn(invisibleRoot(), nodes); 147 148 /* Calling UIChooserNode::searchForNodes with an empty search string 149 * returns a list all nodes (of the whole tree) of the required type: */ 150 invisibleRoot()->searchForNodes(QString(), UIChooserItemSearchFlag_Machine, nodes); 151 152 /* Reset the disabled flag of the nodes first: */ 153 foreach (UIChooserNode *pNode, nodes) 154 { 155 if (!pNode) 156 continue; 157 pNode->setDisabled(false); 158 } 159 160 /* Reset the search result related data: */ 161 m_searchResults.clear(); 162 163 /* Return nodes: */ 164 return nodes; 165 } 166 167 QList<UIChooserNode*> UIChooserAbstractModel::searchResult() const 168 { 169 return m_searchResults; 110 170 } 111 171 -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserAbstractModel.h
r77909 r77948 80 80 /** @} */ 81 81 82 /** @name Search stuff. 83 * @{ */ 84 /** Performs a search starting from the m_pInvisibleRootNode. */ 85 virtual void performSearch(const QString &strSearchTerm, int iItemSearchFlags); 86 /** Cleans the search result data members and disables item's visual effects. 87 * Also returns a list of all nodes which may be utilized by the calling code. */ 88 virtual QList<UIChooserNode*> resetSearch(); 89 /** Returns search result. */ 90 QList<UIChooserNode*> searchResult() const; 91 /** @} */ 92 82 93 /** @name Group saving stuff. 83 94 * @{ */ … … 195 206 /** @} */ 196 207 208 /** @name Search stuff. 209 * @{ */ 210 /** Stores the results of the current search. */ 211 QList<UIChooserNode*> m_searchResults; 212 /** @} */ 213 197 214 /** @name Group saving stuff. 198 215 * @{ */ -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.cpp
r77934 r77948 63 63 , m_pContextMenuGroup(0) 64 64 , m_pContextMenuMachine(0) 65 , m_iCurrentS crolledIndex(-1)65 , m_iCurrentSearchResultIndex(-1) 66 66 , m_iScrollingTokenSize(30) 67 67 , m_fIsScrollingInProgress(false) … … 441 441 void UIChooserModel::performSearch(const QString &strSearchTerm, int iItemSearchFlags) 442 442 { 443 /* Invisible root always exists: */ 444 AssertPtrReturnVoid(invisibleRoot()); 445 446 /* Currently we perform the search only for machines, when this to be changed make 447 * sure the disabled flags of the other item types are also managed correctly. */ 448 449 /* Reset the search first to erase the disabled flag: */ 450 const QList<UIChooserNode*> nodes = resetSearch(); 451 452 /* Stop here if no search conditions specified: */ 453 if (strSearchTerm.isEmpty()) 454 return; 455 456 /* Search for all the nodes matching required condition: */ 457 invisibleRoot()->searchForNodes(strSearchTerm, iItemSearchFlags, m_searchResults); 458 459 /* Assign/reset the disabled flag for required nodes: */ 460 foreach (UIChooserNode* pNode, nodes) 461 { 462 if (!pNode) 463 continue; 464 pNode->setDisabled(!m_searchResults.contains(pNode)); 465 } 466 467 /* Make sure 1st item visible: */ 468 scrollToSearchResult(true); 443 /* Call to base-class: */ 444 UIChooserAbstractModel::performSearch(strSearchTerm, iItemSearchFlags); 445 446 /* Select 1st found item: */ 447 selectSearchResult(true); 469 448 } 470 449 471 450 QList<UIChooserNode*> UIChooserModel::resetSearch() 472 451 { 473 QList<UIChooserNode*> nodes; 474 475 /* Invisible root always exists: */ 476 AssertPtrReturn(invisibleRoot(), nodes); 477 478 /* Calling UIChooserNode::searchForNodes with an empty search string 479 * returns a list all nodes (of the whole tree) of the required type: */ 480 invisibleRoot()->searchForNodes(QString(), UIChooserItemSearchFlag_Machine, nodes); 481 482 /* Reset the disabled flag of the nodes first: */ 483 foreach (UIChooserNode *pNode, nodes) 484 { 485 if (!pNode) 486 continue; 487 pNode->setDisabled(false); 488 } 489 490 /* Reset the search result related data: */ 491 m_searchResults.clear(); 492 m_iCurrentScrolledIndex = -1; 493 return nodes; 494 } 495 496 void UIChooserModel::scrollToSearchResult(bool fIsNext) 452 /* Reset search result index: */ 453 m_iCurrentSearchResultIndex = -1; 454 455 /* Call to base-class: */ 456 return UIChooserAbstractModel::resetSearch(); 457 } 458 459 void UIChooserModel::selectSearchResult(bool fIsNext) 497 460 { 498 461 /* If nothing was found: */ 499 if (m_searchResults.isEmpty()) 500 { 501 /* Clear the search widget's match count(s): */ 502 m_iCurrentScrolledIndex = -1; 503 if (view()) 504 view()->setSearchResultsCount(m_searchResults.size(), m_iCurrentScrolledIndex); 505 return; 506 } 507 508 if (fIsNext) 509 { 510 if (++m_iCurrentScrolledIndex >= m_searchResults.size()) 511 m_iCurrentScrolledIndex = 0; 512 } 462 if (searchResult().isEmpty()) 463 { 464 /* Reset search result index: */ 465 m_iCurrentSearchResultIndex = -1; 466 } 467 /* If something was found: */ 513 468 else 514 469 { 515 if (--m_iCurrentScrolledIndex < 0) 516 m_iCurrentScrolledIndex = m_searchResults.size() - 1; 517 } 518 519 if (m_searchResults.at(m_iCurrentScrolledIndex)) 520 { 521 UIChooserItem *pItem = m_searchResults.at(m_iCurrentScrolledIndex)->item(); 522 if (pItem) 523 { 524 pItem->makeSureItsVisible(); 525 setSelectedItem(pItem); 470 /* Advance index forward: */ 471 if (fIsNext) 472 { 473 if (++m_iCurrentSearchResultIndex >= searchResult().size()) 474 m_iCurrentSearchResultIndex = 0; 475 } 476 /* Advance index backward: */ 477 else 478 { 479 if (--m_iCurrentSearchResultIndex < 0) 480 m_iCurrentSearchResultIndex = searchResult().size() - 1; 481 } 482 483 /* If found item exists: */ 484 if (searchResult().at(m_iCurrentSearchResultIndex)) 485 { 486 /* Select curresponding found item, make sure it's visible, scroll if necessary: */ 487 UIChooserItem *pItem = searchResult().at(m_iCurrentSearchResultIndex)->item(); 488 if (pItem) 489 { 490 pItem->makeSureItsVisible(); 491 setSelectedItem(pItem); 492 } 526 493 } 527 494 } … … 529 496 /* Update the search widget's match count(s): */ 530 497 if (view()) 531 view()->setSearchResultsCount( m_searchResults.size(), m_iCurrentScrolledIndex);498 view()->setSearchResultsCount(searchResult().size(), m_iCurrentSearchResultIndex); 532 499 } 533 500 -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.h
r77934 r77948 178 178 /** @} */ 179 179 180 /** @name Virtual Machine/Group search stuff.180 /** @name Search stuff. 181 181 * @{ */ 182 182 /** Performs a search starting from the m_pInvisibleRootNode. */ 183 v oid performSearch(const QString &strSearchTerm, int iItemSearchFlags);183 virtual void performSearch(const QString &strSearchTerm, int iItemSearchFlags) /* override */; 184 184 /** Cleans the search result data members and disables item's visual effects. 185 185 * Also returns a list of all nodes which may be utilized by the calling code. */ 186 QList<UIChooserNode*> resetSearch(); 187 /** Scrolls to next/prev (wrt. @a fIsNext) search result. */ 188 void scrollToSearchResult(bool fIsNext); 186 virtual QList<UIChooserNode*> resetSearch() /* override */; 187 188 /** Selects next/prev (wrt. @a fIsNext) search result. */ 189 void selectSearchResult(bool fIsNext); 189 190 /** Shows/hides machine search widget. */ 190 191 void setSearchWidgetVisible(bool fVisible); … … 377 378 /** @} */ 378 379 379 /** @name Virtual Machine/Group search stuff. 380 * @{ */ 381 /** Stores the results of the current search. */ 382 QList<UIChooserNode*> m_searchResults; 383 /** Stores the index (within the m_searchResults) of the currently scrolled item. */ 384 int m_iCurrentScrolledIndex; 380 /** @name Search stuff. 381 * @{ */ 382 /** Stores the index (within the m_searchResults) of the currently selected found item. */ 383 int m_iCurrentSearchResultIndex; 385 384 /** @} */ 386 385 -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserView.cpp
r77813 r77948 177 177 if (!pModel) 178 178 return; 179 pModel->s crollToSearchResult(fIsNext);179 pModel->selectSearchResult(fIsNext); 180 180 } 181 181
Note:
See TracChangeset
for help on using the changeset viewer.