VirtualBox

Changeset 77948 in vbox


Ignore:
Timestamp:
Mar 29, 2019 10:46:10 AM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9241: VirtualBox Manager: Chooser pane: A bit of cleanup for search functionality, split it and move abstract part from UIChooserModel to UIChooserAbstractModel.

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  
    108108        strResult += " " + QString::number(iMinimumPossibleNumber);
    109109    return strResult;
     110}
     111
     112void 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
     140QList<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
     167QList<UIChooserNode*> UIChooserAbstractModel::searchResult() const
     168{
     169    return m_searchResults;
    110170}
    111171
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserAbstractModel.h

    r77909 r77948  
    8080    /** @} */
    8181
     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
    8293    /** @name Group saving stuff.
    8394      * @{ */
     
    195206    /** @} */
    196207
     208    /** @name Search stuff.
     209      * @{ */
     210        /** Stores the results of the current search. */
     211        QList<UIChooserNode*>  m_searchResults;
     212    /** @} */
     213
    197214    /** @name Group saving stuff.
    198215      * @{ */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.cpp

    r77934 r77948  
    6363    , m_pContextMenuGroup(0)
    6464    , m_pContextMenuMachine(0)
    65     , m_iCurrentScrolledIndex(-1)
     65    , m_iCurrentSearchResultIndex(-1)
    6666    , m_iScrollingTokenSize(30)
    6767    , m_fIsScrollingInProgress(false)
     
    441441void UIChooserModel::performSearch(const QString &strSearchTerm, int iItemSearchFlags)
    442442{
    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);
    469448}
    470449
    471450QList<UIChooserNode*> UIChooserModel::resetSearch()
    472451{
    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
     459void UIChooserModel::selectSearchResult(bool fIsNext)
    497460{
    498461    /* 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: */
    513468    else
    514469    {
    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            }
    526493        }
    527494    }
     
    529496    /* Update the search widget's match count(s): */
    530497    if (view())
    531         view()->setSearchResultsCount(m_searchResults.size(), m_iCurrentScrolledIndex);
     498        view()->setSearchResultsCount(searchResult().size(), m_iCurrentSearchResultIndex);
    532499}
    533500
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.h

    r77934 r77948  
    178178    /** @} */
    179179
    180     /** @name Virtual Machine/Group search stuff.
     180    /** @name Search stuff.
    181181      * @{ */
    182182        /** Performs a search starting from the m_pInvisibleRootNode. */
    183         void performSearch(const QString &strSearchTerm, int iItemSearchFlags);
     183        virtual void performSearch(const QString &strSearchTerm, int iItemSearchFlags) /* override */;
    184184        /** Cleans the search result data members and disables item's visual effects.
    185185          * 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);
    189190        /** Shows/hides machine search widget. */
    190191        void setSearchWidgetVisible(bool fVisible);
     
    377378    /** @} */
    378379
    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;
    385384    /** @} */
    386385
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserView.cpp

    r77813 r77948  
    177177    if (!pModel)
    178178        return;
    179     pModel->scrollToSearchResult(fIsNext);
     179    pModel->selectSearchResult(fIsNext);
    180180}
    181181
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