VirtualBox

Ignore:
Timestamp:
Oct 10, 2012 4:19:53 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
81300
Message:

FE/Qt: VM group feature UI: Moving some item searching stuff into corresponding place, reusing it.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItem.h

    r43597 r43604  
    2727#include "QIWithRetranslateUI.h"
    2828
     29/* Other VBox includes: */
     30#include <iprt/cdefs.h>
     31
    2932/* Forward declaration: */
    3033class UIGChooserModel;
     
    4346    UIGChooserItemType_Group   = QGraphicsItem::UserType + 1,
    4447    UIGChooserItemType_Machine = QGraphicsItem::UserType + 2
     48};
     49
     50/* Item search flags: */
     51enum UIGChooserItemSearchFlag
     52{
     53    UIGChooserItemSearchFlag_Machine   = RT_BIT(0),
     54    UIGChooserItemSearchFlag_Group     = RT_BIT(1),
     55    UIGChooserItemSearchFlag_ExactName = RT_BIT(2)
    4556};
    4657
     
    94105    virtual bool hasItems(UIGChooserItemType type = UIGChooserItemType_Any) const = 0;
    95106    virtual void clearItems(UIGChooserItemType type = UIGChooserItemType_Any) = 0;
     107    virtual UIGChooserItem* searchForItem(const QString &strSearchTag, int iItemSearchFlags) = 0;
    96108    virtual UIGChooserItemMachine* firstMachineItem() = 0;
    97109
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemGroup.cpp

    r43597 r43604  
    732732}
    733733
     734UIGChooserItem* UIGChooserItemGroup::searchForItem(const QString &strSearchTag, int iItemSearchFlags)
     735{
     736    /* Are we searching among group-items? */
     737    if (iItemSearchFlags & UIGChooserItemSearchFlag_Group)
     738    {
     739        /* Are we searching by the exact name? */
     740        if (iItemSearchFlags & UIGChooserItemSearchFlag_ExactName)
     741        {
     742            /* Exact name matches? */
     743            if (name() == strSearchTag)
     744                return this;
     745        }
     746        /* Are we searching by the few first symbols? */
     747        else
     748        {
     749            /* Name starts with passed symbols? */
     750            if (name().startsWith(strSearchTag, Qt::CaseInsensitive))
     751                return this;
     752        }
     753    }
     754
     755    /* Search among all the children, but machines first: */
     756    foreach (UIGChooserItem *pItem, items(UIGChooserItemType_Machine))
     757        if (UIGChooserItem *pFoundItem = pItem->searchForItem(strSearchTag, iItemSearchFlags))
     758            return pFoundItem;
     759    foreach (UIGChooserItem *pItem, items(UIGChooserItemType_Group))
     760        if (UIGChooserItem *pFoundItem = pItem->searchForItem(strSearchTag, iItemSearchFlags))
     761            return pFoundItem;
     762
     763    /* Nothing found? */
     764    return 0;
     765}
     766
    734767UIGChooserItemMachine* UIGChooserItemGroup::firstMachineItem()
    735768{
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemGroup.h

    r43597 r43604  
    148148    bool hasItems(UIGChooserItemType type = UIGChooserItemType_Any) const;
    149149    void clearItems(UIGChooserItemType type = UIGChooserItemType_Any);
     150    UIGChooserItem* searchForItem(const QString &strSearchTag, int iItemSearchFlags);
    150151    UIGChooserItemMachine* firstMachineItem();
    151152
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemMachine.cpp

    r43598 r43604  
    360360}
    361361
     362UIGChooserItem* UIGChooserItemMachine::searchForItem(const QString &strSearchTag, int iItemSearchFlags)
     363{
     364    /* Ignoring if we are not searching for the machine-item? */
     365    if (!(iItemSearchFlags & UIGChooserItemSearchFlag_Machine))
     366        return 0;
     367
     368    /* Are we searching by the exact name? */
     369    if (iItemSearchFlags & UIGChooserItemSearchFlag_ExactName)
     370    {
     371        /* Exact name doesn't match? */
     372        if (name() != strSearchTag)
     373            return 0;
     374    }
     375    /* Are we searching by the few first symbols? */
     376    else
     377    {
     378        /* Name doesn't start with passed symbols? */
     379        if (!name().startsWith(strSearchTag, Qt::CaseInsensitive))
     380            return 0;
     381    }
     382
     383    /* Returning this: */
     384    return this;
     385}
     386
    362387UIGChooserItemMachine* UIGChooserItemMachine::firstMachineItem()
    363388{
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemMachine.h

    r43597 r43604  
    2323#include "UIVMItem.h"
    2424#include "UIGChooserItem.h"
    25 
    26 /* Other VBox includes: */
    27 #include <iprt/cdefs.h>
    2825
    2926/* Forward declarations: */
     
    127124    bool hasItems(UIGChooserItemType type) const;
    128125    void clearItems(UIGChooserItemType type);
     126    UIGChooserItem* searchForItem(const QString &strSearchTag, int iItemSearchFlags);
    129127    UIGChooserItemMachine* firstMachineItem();
    130128
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserModel.cpp

    r43598 r43604  
    296296    {
    297297        /* Search for group-item with passed descriptor (name): */
    298         pItem = findGroupItem(strItemDescriptor, mainRoot());
     298        pItem = mainRoot()->searchForItem(strItemDescriptor,
     299                                          UIGChooserItemSearchFlag_Group |
     300                                          UIGChooserItemSearchFlag_ExactName);
    299301    }
    300302    /* Its a machine-item definition? */
     
    306308        {
    307309            /* Search for machine-item with required name: */
    308             pItem = findMachineItem(machine.GetName(), mainRoot());
     310            pItem = mainRoot()->searchForItem(machine.GetName(),
     311                                              UIGChooserItemSearchFlag_Machine |
     312                                              UIGChooserItemSearchFlag_ExactName);
    309313        }
    310314    }
     
    556560    m_pLookupTimer->start();
    557561    /* Look for item which is starting from the lookup-string: */
    558     UIGChooserItem *pItem = lookForItem(mainRoot(), m_strLookupString + strLookupSymbol);
     562    UIGChooserItem *pItem = mainRoot()->searchForItem(m_strLookupString + strLookupSymbol,
     563                                                      UIGChooserItemSearchFlag_Machine |
     564                                                      UIGChooserItemSearchFlag_Group);
    559565    /* If item found: */
    560566    if (pItem)
     
    611617            updateNavigation();
    612618            updateLayout();
    613             setCurrentItem(findMachineItem(machine.GetName(), mainRoot()));
     619            setCurrentItem(mainRoot()->searchForItem(machine.GetName(),
     620                                                     UIGChooserItemSearchFlag_Machine |
     621                                                     UIGChooserItemSearchFlag_ExactName));
    614622        }
    615623    }
     
    941949            /* Select first of reloaded items: */
    942950            if (!pSelectedItem)
    943                 pSelectedItem = findMachineItem(strMachineName, mainRoot());
     951                pSelectedItem = mainRoot()->searchForItem(strMachineName,
     952                                                          UIGChooserItemSearchFlag_Machine |
     953                                                          UIGChooserItemSearchFlag_ExactName);
    944954        }
    945955    }
     
    14041414}
    14051415
    1406 UIGChooserItem* UIGChooserModel::findGroupItem(const QString &strName, UIGChooserItem *pParent)
    1407 {
    1408     /* Search among all the group-items of passed parent: */
    1409     foreach (UIGChooserItem *pItem, pParent->items(UIGChooserItemType_Group))
    1410         if (pItem->name() == strName)
    1411             return pItem;
    1412     /* Recursively iterate into each the group-item of the passed parent: */
    1413     foreach (UIGChooserItem *pItem, pParent->items(UIGChooserItemType_Group))
    1414         if (UIGChooserItem *pGroupItem = findGroupItem(strName, pItem))
    1415             return pGroupItem;
    1416     /* Nothing found? */
    1417     return 0;
    1418 }
    1419 
    14201416void UIGChooserModel::cleanupGroupTree(UIGChooserItem *pParent)
    14211417{
     
    14331429            unindentRoot();
    14341430    }
    1435 }
    1436 
    1437 UIGChooserItem* UIGChooserModel::findMachineItem(const QString &strName, UIGChooserItem *pParent)
    1438 {
    1439     /* Search among all the machine-items of passed parent: */
    1440     foreach (UIGChooserItem *pItem, pParent->items(UIGChooserItemType_Machine))
    1441         if (pItem->name() == strName)
    1442             return pItem;
    1443     /* Recursively iterate into each the group-item of the passed parent: */
    1444     foreach (UIGChooserItem *pItem, pParent->items(UIGChooserItemType_Group))
    1445         if (UIGChooserItem *pMachineItem = findMachineItem(strName, pItem))
    1446             return pMachineItem;
    1447     /* Nothing found? */
    1448     return 0;
    14491431}
    14501432
     
    16941676}
    16951677
    1696 UIGChooserItem* UIGChooserModel::lookForItem(UIGChooserItem *pParent, const QString &strStartingFrom)
    1697 {
    1698     /* Search among the machines: */
    1699     foreach (UIGChooserItem *pItem, pParent->items(UIGChooserItemType_Machine))
    1700         if (pItem->name().startsWith(strStartingFrom, Qt::CaseInsensitive))
    1701             return pItem;
    1702     /* Search among the groups: */
    1703     foreach (UIGChooserItem *pItem, pParent->items(UIGChooserItemType_Group))
    1704     {
    1705         if (pItem->name().startsWith(strStartingFrom, Qt::CaseInsensitive))
    1706             return pItem;
    1707         if (UIGChooserItem *pResult = lookForItem(pItem, strStartingFrom))
    1708             return pResult;
    1709     }
    1710     /* Nothing found: */
    1711     return 0;
    1712 }
    1713 
    17141678void UIGChooserModel::loadGroupTree()
    17151679{
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserModel.h

    r43598 r43604  
    245245
    246246    /* Helper: Group-item stuff: */
    247     UIGChooserItem* findGroupItem(const QString &strName, UIGChooserItem *pParent);
    248247    void cleanupGroupTree(UIGChooserItem *pGroupItem);
    249248
    250249    /* Helpers: Machine-item stuff: */
    251     UIGChooserItem* findMachineItem(const QString &strName, UIGChooserItem *pParent);
    252250    void sortItems(UIGChooserItem *pParent);
    253251    void updateMachineItems(const QString &strId, UIGChooserItem *pParent);
     
    262260    /* Handler: Drag&drop event: */
    263261    bool processDragMoveEvent(QGraphicsSceneDragDropEvent *pEvent);
    264 
    265     /* Helper: Lookup stuff: */
    266     UIGChooserItem* lookForItem(UIGChooserItem *pParent, const QString &strStartingFrom);
    267262
    268263    /* Helpers: Loading stuff: */
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