VirtualBox

Changeset 53265 in vbox for trunk/src


Ignore:
Timestamp:
Nov 7, 2014 3:15:49 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
96833
Message:

FE/Qt: Selector UI: Chooser pane: Lookup mechanism optimization.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserModel.cpp

    r52733 r53265  
    560560    /* Restart timer to reset lookup-string: */
    561561    m_pLookupTimer->start();
    562     /* Look for item which is starting from the lookup-string: */
    563     UIGChooserItem *pItem = mainRoot()->searchForItem(m_strLookupString + strLookupSymbol,
    564                                                       UIGChooserItemSearchFlag_Machine |
    565                                                       UIGChooserItemSearchFlag_Group);
    566     /* If item found: */
     562
     563    /* Prepare item: */
     564    UIGChooserItem *pItem = 0;
     565
     566    /* We are starting to look from the current position: */
     567    int iCurrentIndex = navigationList().indexOf(currentItem());
     568
     569    /* Are we looking for the 1. same symbol or for the 2. composed word? */
     570    const QString strLookupString = m_strLookupString.isEmpty() || m_strLookupString == strLookupSymbol ?
     571                                    strLookupSymbol : m_strLookupString + strLookupSymbol;
     572    /* Are we looking from the 1. subsequent position or from the 2. same one? */
     573    const int     iFirstIndex     = m_strLookupString.isEmpty() || m_strLookupString == strLookupSymbol ?
     574                                    iCurrentIndex + 1 : iCurrentIndex;
     575
     576    /* If first position feats the bounds: */
     577    if (iFirstIndex < navigationList().size())
     578    {
     579        /* We have to look starting from the first position: */
     580        for (int iIndex = iFirstIndex; iIndex < navigationList().size(); ++iIndex)
     581        {
     582            UIGChooserItem *pIteratedItem = navigationList().at(iIndex);
     583            if (pIteratedItem->name().startsWith(strLookupString, Qt::CaseInsensitive))
     584            {
     585                pItem = pIteratedItem;
     586                break;
     587            }
     588        }
     589    }
     590
     591    /* If the item was not found: */
     592    if (!pItem && iFirstIndex > 0)
     593    {
     594        /* We have to try to look from the beginning of the list: */
     595        for (int iIndex = 0; iIndex < iFirstIndex; ++iIndex)
     596        {
     597            UIGChooserItem *pIteratedItem = navigationList().at(iIndex);
     598            if (pIteratedItem->name().startsWith(strLookupString, Qt::CaseInsensitive))
     599            {
     600                pItem = pIteratedItem;
     601                break;
     602            }
     603        }
     604    }
     605
     606    /* If that item was found: */
    567607    if (pItem)
    568608    {
     
    571611        setCurrentItem(pItem);
    572612        /* Append lookup symbol: */
    573         m_strLookupString += strLookupSymbol;
     613        if (m_strLookupString != strLookupSymbol)
     614            m_strLookupString += strLookupSymbol;
    574615    }
    575616}
Note: See TracChangeset for help on using the changeset viewer.

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