VirtualBox

Changeset 86649 in vbox


Ignore:
Timestamp:
Oct 20, 2020 2:12:42 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9653: VirtualBox Manager: Chooser pane: Move search by definition functionality to separate function to make it reusable.

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

    r86630 r86649  
    203203void UIChooserModel::setSelectedItem(const QString &strDefinition)
    204204{
    205     /* Ignore if empty definition passed: */
    206     if (strDefinition.isEmpty())
    207         return;
    208 
    209     /* Parse definition: */
    210     UIChooserItem *pItem = 0;
    211     const QString strItemType = strDefinition.section('=', 0, 0);
    212     const QString strItemDescriptor = strDefinition.section('=', 1, -1);
    213     /* Its a local group-item definition? */
    214     if (strItemType == prefixToString(UIChooserNodeDataPrefixType_Local))
    215     {
    216         /* Search for group-item with passed descriptor (name): */
    217         pItem = root()->searchForItem(strItemDescriptor,
    218                                       UIChooserItemSearchFlag_LocalGroup |
    219                                       UIChooserItemSearchFlag_ExactId);
    220     }
    221     /* Its a provider group-item definition? */
    222     else if (strItemType == prefixToString(UIChooserNodeDataPrefixType_Provider))
    223     {
    224         /* Search for group-item with passed descriptor (name): */
    225         pItem = root()->searchForItem(strItemDescriptor,
    226                                       UIChooserItemSearchFlag_CloudProvider |
    227                                       UIChooserItemSearchFlag_ExactId);
    228     }
    229     /* Its a profile group-item definition? */
    230     else if (strItemType == prefixToString(UIChooserNodeDataPrefixType_Profile))
    231     {
    232         /* Search for group-item with passed descriptor (name): */
    233         pItem = root()->searchForItem(strItemDescriptor,
    234                                       UIChooserItemSearchFlag_CloudProfile |
    235                                       UIChooserItemSearchFlag_ExactId);
    236     }
    237     /* Its a global-item definition? */
    238     else if (strItemType == prefixToString(UIChooserNodeDataPrefixType_Global))
    239     {
    240         /* Search for global-item with required name: */
    241         pItem = root()->searchForItem(strItemDescriptor,
    242                                       UIChooserItemSearchFlag_Global |
    243                                       UIChooserItemSearchFlag_ExactName);
    244     }
    245     /* Its a machine-item definition? */
    246     else if (strItemType == prefixToString(UIChooserNodeDataPrefixType_Machine))
    247     {
    248         /* Search for machine-item with required ID: */
    249         pItem = root()->searchForItem(strItemDescriptor,
    250                                       UIChooserItemSearchFlag_Machine |
    251                                       UIChooserItemSearchFlag_ExactId);
    252     }
     205    /* Search an item by definition: */
     206    UIChooserItem *pItem = searchItemByDefinition(strDefinition);
    253207
    254208    /* Make sure found item is in navigation list: */
     
    508462    m_navigationItems.clear();
    509463    m_navigationItems = createNavigationItemList(root());
     464}
     465
     466UIChooserItem *UIChooserModel::searchItemByDefinition(const QString &strDefinition) const
     467{
     468    /* Null if empty definition passed: */
     469    if (strDefinition.isEmpty())
     470        return 0;
     471
     472    /* Parse definition: */
     473    UIChooserItem *pItem = 0;
     474    const QString strItemType = strDefinition.section('=', 0, 0);
     475    const QString strItemDescriptor = strDefinition.section('=', 1, -1);
     476    /* Its a local group-item definition? */
     477    if (strItemType == prefixToString(UIChooserNodeDataPrefixType_Local))
     478    {
     479        /* Search for group-item with passed descriptor (name): */
     480        pItem = root()->searchForItem(strItemDescriptor,
     481                                      UIChooserItemSearchFlag_LocalGroup |
     482                                      UIChooserItemSearchFlag_ExactId);
     483    }
     484    /* Its a provider group-item definition? */
     485    else if (strItemType == prefixToString(UIChooserNodeDataPrefixType_Provider))
     486    {
     487        /* Search for group-item with passed descriptor (name): */
     488        pItem = root()->searchForItem(strItemDescriptor,
     489                                      UIChooserItemSearchFlag_CloudProvider |
     490                                      UIChooserItemSearchFlag_ExactId);
     491    }
     492    /* Its a profile group-item definition? */
     493    else if (strItemType == prefixToString(UIChooserNodeDataPrefixType_Profile))
     494    {
     495        /* Search for group-item with passed descriptor (name): */
     496        pItem = root()->searchForItem(strItemDescriptor,
     497                                      UIChooserItemSearchFlag_CloudProfile |
     498                                      UIChooserItemSearchFlag_ExactId);
     499    }
     500    /* Its a global-item definition? */
     501    else if (strItemType == prefixToString(UIChooserNodeDataPrefixType_Global))
     502    {
     503        /* Search for global-item with required name: */
     504        pItem = root()->searchForItem(strItemDescriptor,
     505                                      UIChooserItemSearchFlag_Global |
     506                                      UIChooserItemSearchFlag_ExactName);
     507    }
     508    /* Its a machine-item definition? */
     509    else if (strItemType == prefixToString(UIChooserNodeDataPrefixType_Machine))
     510    {
     511        /* Search for machine-item with required ID: */
     512        pItem = root()->searchForItem(strItemDescriptor,
     513                                      UIChooserItemSearchFlag_Machine |
     514                                      UIChooserItemSearchFlag_ExactId);
     515    }
     516
     517    /* Return result: */
     518    return pItem;
    510519}
    511520
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.h

    r86629 r86649  
    188188    /** @name Search stuff.
    189189      * @{ */
     190        /** Performs a search for an item matching @a strDefinition. */
     191        UIChooserItem *searchItemByDefinition(const QString &strDefinition) const;
     192
    190193        /** Performs a search using @a strSearchTerm and @a iSearchFlags specified. */
    191194        virtual void performSearch(const QString &strSearchTerm, int iSearchFlags) /* override */;
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