VirtualBox

Changeset 77638 in vbox


Ignore:
Timestamp:
Mar 10, 2019 7:21:30 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9241: VirtualBox Manager UI: Chooser pane: Rework chooser pane to populate invisible nodes tree first of all; visible item tree is now buildable on demand and can be built for any particular node and deeper.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserHandlerKeyboard.cpp

    r77430 r77638  
    323323void UIChooserHandlerKeyboard::shift(UIItemShiftDirection direction, UIItemShiftSize size) const
    324324{
     325    Q_UNUSED(direction);
     326    Q_UNUSED(size);
     327    /// @todo implement item shifting
     328
     329#if 0
    325330    /* Get focus-item and his parent: */
    326331    UIChooserItem *pFocusItem = model()->focusItem();
     
    372377    model()->updateNavigation();
    373378    model()->updateLayout();
    374 }
    375 
     379#endif
     380}
     381
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItem.cpp

    r77636 r77638  
    296296}
    297297
    298 UIChooserItem::~UIChooserItem()
    299 {
    300     delete node();
    301 }
    302 
    303298UIChooserItemGroup *UIChooserItem::toGroupItem()
    304299{
     
    369364    if (m_pParent)
    370365        m_pParent->toGroupItem()->updateFavorites();
     366}
     367
     368int UIChooserItem::position() const
     369{
     370    return node()->position();
    371371}
    372372
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItem.h

    r77636 r77638  
    8181    UIChooserItem(UIChooserItem *pParent, UIChooserNode *pNode,
    8282                  int iDefaultValue = 100, int iHoveredValue = 90);
    83     /** Destructs item. */
    84     virtual ~UIChooserItem() /* override */;
    8583
    8684    /** @name Item stuff.
     
    120118        virtual void setFavorite(bool fFavorite);
    121119
     120        /** Returns item position. */
     121        int position() const;
     122
    122123        /** Returns a level of item. */
    123124        int level() const;
     
    145146    /** @name Children stuff.
    146147      * @{ */
    147         /** Returns whether there are children items of certain @a enmType. */
    148         virtual bool hasItems(UIChooserItemType enmType = UIChooserItemType_Any) const = 0;
    149148        /** Returns children items of certain @a enmType. */
    150149        virtual QList<UIChooserItem*> items(UIChooserItemType enmType = UIChooserItemType_Any) const = 0;
    151 
    152         /** Replaces children @a items of certain @a enmType. */
    153         virtual void setItems(const QList<UIChooserItem*> &items, UIChooserItemType enmType) = 0;
    154         /** Clears children items of certain @a enmType. */
    155         virtual void clearItems(UIChooserItemType enmType = UIChooserItemType_Any) = 0;
    156150
    157151        /** Adds possible @a fFavorite child @a pItem to certain @a iPosition. */
     
    159153        /** Removes child @a pItem. */
    160154        virtual void removeItem(UIChooserItem *pItem) = 0;
    161 
    162         /** Updates all children items with specified @a uId. */
    163         virtual void updateAllItems(const QUuid &uId) = 0;
    164         /** Removes all children items with specified @a uId. */
    165         virtual void removeAllItems(const QUuid &uId) = 0;
    166155
    167156        /** Searches for a first child item answering to specified @a strSearchTag and @a iItemSearchFlags. */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGlobal.cpp

    r77636 r77638  
    3333
    3434
    35 UIChooserItemGlobal::UIChooserItemGlobal(UIChooserItem *pParent,
    36                                          bool fFavorite,
    37                                          int iPosition /* = -1 */)
    38     : UIChooserItem(pParent, new UIChooserNodeGlobal(pParent->node(), fFavorite, QString()), 0, 100)
    39     , m_iPosition(iPosition)
     35UIChooserItemGlobal::UIChooserItemGlobal(UIChooserItem *pParent, UIChooserNodeGlobal *pNode)
     36    : UIChooserItem(pParent, pNode, 0, 100)
    4037    , m_iDefaultLightnessMin(0)
    4138    , m_iDefaultLightnessMax(0)
     
    4744    , m_iMaximumNameWidth(0)
    4845    , m_iHeightHint(0)
    49 {
    50     prepare();
    51 }
    52 
    53 UIChooserItemGlobal::UIChooserItemGlobal(UIChooserItem *pParent,
    54                                          bool fFavorite,
    55                                          UIChooserItemGlobal *pCopiedItem,
    56                                          int iPosition /* = -1 */)
    57     : UIChooserItem(pParent, new UIChooserNodeGlobal(pParent->node(), fFavorite, QString()), 0, 100)
    58     , m_iPosition(iPosition)
    59     , m_iDefaultLightnessMin(0)
    60     , m_iDefaultLightnessMax(0)
    61     , m_iHoverLightnessMin(0)
    62     , m_iHoverLightnessMax(0)
    63     , m_iHighlightLightnessMin(0)
    64     , m_iHighlightLightnessMax(0)
    65     , m_iMinimumNameWidth(0)
    66     , m_iMaximumNameWidth(0)
    67     , m_iHeightHint(pCopiedItem->heightHint())
    6846{
    6947    prepare();
     
    212190}
    213191
    214 bool UIChooserItemGlobal::hasItems(UIChooserItemType) const
    215 {
    216     AssertMsgFailedReturn(("Global graphics item do NOT support children!"), false);
    217 }
    218 
    219192QList<UIChooserItem*> UIChooserItemGlobal::items(UIChooserItemType) const
    220193{
     
    222195}
    223196
    224 void UIChooserItemGlobal::setItems(const QList<UIChooserItem*> &, UIChooserItemType)
     197void UIChooserItemGlobal::addItem(UIChooserItem *, bool, int)
    225198{
    226199    AssertMsgFailed(("Global graphics item do NOT support children!"));
    227200}
    228201
    229 void UIChooserItemGlobal::clearItems(UIChooserItemType)
     202void UIChooserItemGlobal::removeItem(UIChooserItem *)
    230203{
    231204    AssertMsgFailed(("Global graphics item do NOT support children!"));
    232 }
    233 
    234 void UIChooserItemGlobal::addItem(UIChooserItem *, bool, int)
    235 {
    236     AssertMsgFailed(("Global graphics item do NOT support children!"));
    237 }
    238 
    239 void UIChooserItemGlobal::removeItem(UIChooserItem *)
    240 {
    241     AssertMsgFailed(("Global graphics item do NOT support children!"));
    242 }
    243 
    244 void UIChooserItemGlobal::updateAllItems(const QUuid &)
    245 {
    246     updateItem();
    247 }
    248 
    249 void UIChooserItemGlobal::removeAllItems(const QUuid &)
    250 {
    251     // Just do nothing ..
    252205}
    253206
     
    403356    /* Add item to the parent: */
    404357    AssertPtrReturnVoid(parentItem());
    405     parentItem()->addItem(this, isFavorite(), m_iPosition);
     358    parentItem()->addItem(this, isFavorite(), position());
    406359
    407360    /* Configure connections: */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGlobal.h

    r77636 r77638  
    2525#include "UIChooserItem.h"
    2626
     27/* Forward declarations: */
     28class UIChooserNodeGlobal;
     29
    2730
    2831/** UIChooserItem extension implementing global item. */
     
    3639    enum { Type = UIChooserItemType_Global };
    3740
    38     /** Constructs possible @a fFavorite item with specified @a iPosition, passing @a pParent to the base-class. */
    39     UIChooserItemGlobal(UIChooserItem *pParent, bool fFavorite, int iPosition = -1);
    40     /** Constructs possible @a fFavorite copy of @a pCopiedItem with specified @a iPosition, passing @a pParent to the base-class. */
    41     UIChooserItemGlobal(UIChooserItem *pParent, bool fFavorite, UIChooserItemGlobal *pCopiedItem, int iPosition = -1);
     41    /** Build item for certain @a pNode, passing @a pParent to the base-class. */
     42    UIChooserItemGlobal(UIChooserItem *pParent, UIChooserNodeGlobal *pNode);
    4243    /** Destructs global item. */
    4344    virtual ~UIChooserItemGlobal() /* override */;
     
    9899    /** @name Children stuff.
    99100      * @{ */
    100         /** Returns whether there are children items of certain @a enmType. */
    101         virtual bool hasItems(UIChooserItemType enmType = UIChooserItemType_Any) const /* override */;
    102101        /** Returns children items of certain @a enmType. */
    103102        virtual QList<UIChooserItem*> items(UIChooserItemType enmType = UIChooserItemType_Any) const /* override */;
    104 
    105         /** Replaces children @a items of certain @a enmType. */
    106         virtual void setItems(const QList<UIChooserItem*> &items, UIChooserItemType enmType) /* override */;
    107         /** Clears children items of certain @a enmType. */
    108         virtual void clearItems(UIChooserItemType enmType = UIChooserItemType_Any) /* override */;
    109103
    110104        /** Adds possible @a fFavorite child @a pItem to certain @a iPosition. */
     
    112106        /** Removes child @a pItem. */
    113107        virtual void removeItem(UIChooserItem *pItem) /* override */;
    114 
    115         /** Updates all children items with specified @a uId. */
    116         virtual void updateAllItems(const QUuid &uId) /* override */;
    117         /** Removes all children items with specified @a uId. */
    118         virtual void removeAllItems(const QUuid &uId) /* override */;
    119108
    120109        /** Searches for a first child item answering to specified @a strSearchTag and @a iItemSearchFlags. */
     
    228217    /** @name Item stuff.
    229218      * @{ */
    230         /** Holds initial item position. */
    231         const int  m_iPosition;
    232 
    233219        /** Holds item minimum default lightness. */
    234220        int  m_iDefaultLightnessMin;
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGroup.cpp

    r77636 r77638  
    3838#include "UIIconPool.h"
    3939#include "UIVirtualBoxManager.h"
    40 #include "UIVirtualMachineItem.h"
    4140
    4241
     
    4544*********************************************************************************************************************************/
    4645
    47 UIChooserItemGroup::UIChooserItemGroup(QGraphicsScene *pScene)
    48     : UIChooserItem(0, new UIChooserNodeGroup(0 /* parent */,
    49                                               false /* favorite? */,
    50                                               QString() /* name */,
    51                                               true /* opened? */))
     46UIChooserItemGroup::UIChooserItemGroup(QGraphicsScene *pScene, UIChooserNodeGroup *pNode)
     47    : UIChooserItem(0, pNode)
    5248    , m_pScene(pScene)
    53     , m_pItemToCopy(0)
    54     , m_iPosition(0)
    5549    , m_iAdditionalHeight(0)
    5650    , m_iHeaderDarkness(110)
     
    7165}
    7266
    73 UIChooserItemGroup::UIChooserItemGroup(UIChooserItem *pParent,
    74                                        const QString &strName,
    75                                        bool fOpened /* = false */,
    76                                        int iPosition /* = -1 */)
    77     : UIChooserItem(pParent, new UIChooserNodeGroup(pParent->node(),
    78                                                     pParent->isFavorite(),
    79                                                     strName,
    80                                                     fOpened))
     67UIChooserItemGroup::UIChooserItemGroup(UIChooserItem *pParent, UIChooserNodeGroup *pNode)
     68    : UIChooserItem(pParent, pNode)
    8169    , m_pScene(0)
    82     , m_pItemToCopy(0)
    83     , m_iPosition(iPosition)
    8470    , m_iAdditionalHeight(0)
    8571    , m_iHeaderDarkness(110)
     
    10086}
    10187
    102 UIChooserItemGroup::UIChooserItemGroup(UIChooserItem *pParent,
    103                                        UIChooserItemGroup *pCopiedItem,
    104                                        int iPosition /* = -1 */)
    105     : UIChooserItem(pParent, new UIChooserNodeGroup(pParent->node(),
    106                                                     pParent->isFavorite(),
    107                                                     pCopiedItem->name(),
    108                                                     pCopiedItem->isOpened()))
    109     , m_pScene(0)
    110     , m_pItemToCopy(pCopiedItem)
    111     , m_iPosition(iPosition)
    112     , m_iAdditionalHeight(0)
    113     , m_iHeaderDarkness(110)
    114     , m_pToggleButton(0)
    115     , m_pEnterButton(0)
    116     , m_pExitButton(0)
    117     , m_pNameEditorWidget(0)
    118     , m_pContainerFavorite(0)
    119     , m_pLayoutFavorite(0)
    120     , m_pScrollArea(0)
    121     , m_pContainer(0)
    122     , m_pLayout(0)
    123     , m_pLayoutGlobal(0)
    124     , m_pLayoutGroup(0)
    125     , m_pLayoutMachine(0)
    126 {
    127     prepare();
    128 }
    129 
    13088UIChooserItemGroup::~UIChooserItemGroup()
    13189{
     
    384342}
    385343
    386 bool UIChooserItemGroup::hasItems(UIChooserItemType type /* = UIChooserItemType_Any */) const
    387 {
    388     switch (type)
    389     {
    390         case UIChooserItemType_Any:
    391             return hasItems(UIChooserItemType_Global) || hasItems(UIChooserItemType_Group) || hasItems(UIChooserItemType_Machine);
    392         case UIChooserItemType_Global:
    393             return !m_globalItems.isEmpty();
    394         case UIChooserItemType_Group:
    395             return !m_groupItems.isEmpty();
    396         case UIChooserItemType_Machine:
    397             return !m_machineItems.isEmpty();
    398     }
    399     return false;
    400 }
    401 
    402344QList<UIChooserItem*> UIChooserItemGroup::items(UIChooserItemType type /* = UIChooserItemType_Any */) const
    403345{
     
    411353    }
    412354    return QList<UIChooserItem*>();
    413 }
    414 
    415 void UIChooserItemGroup::setItems(const QList<UIChooserItem*> &items, UIChooserItemType type)
    416 {
    417     /* Check item type: */
    418     switch (type)
    419     {
    420         case UIChooserItemType_Global: m_globalItems = items; break;
    421         case UIChooserItemType_Group: m_groupItems = items; break;
    422         case UIChooserItemType_Machine: m_machineItems = items; break;
    423         default: AssertMsgFailed(("Invalid item type!")); break;
    424     }
    425 
    426     /* Update linked values: */
    427     updateLayoutSpacings();
    428     updateItemCountInfo();
    429     updateToolTip();
    430     updateGeometry();
    431 }
    432 
    433 void UIChooserItemGroup::clearItems(UIChooserItemType type /* = UIChooserItemType_Any */)
    434 {
    435     switch (type)
    436     {
    437         case UIChooserItemType_Any:
    438         {
    439             clearItems(UIChooserItemType_Global);
    440             clearItems(UIChooserItemType_Group);
    441             clearItems(UIChooserItemType_Machine);
    442             break;
    443         }
    444         case UIChooserItemType_Global:
    445         {
    446             while (!m_globalItems.isEmpty()) { delete m_globalItems.last(); }
    447             AssertMsg(m_globalItems.isEmpty(), ("Global items cleanup failed!"));
    448             break;
    449         }
    450         case UIChooserItemType_Group:
    451         {
    452             while (!m_groupItems.isEmpty()) { delete m_groupItems.last(); }
    453             AssertMsg(m_groupItems.isEmpty(), ("Group items cleanup failed!"));
    454             break;
    455         }
    456         case UIChooserItemType_Machine:
    457         {
    458             while (!m_machineItems.isEmpty()) { delete m_machineItems.last(); }
    459             AssertMsg(m_machineItems.isEmpty(), ("Machine items cleanup failed!"));
    460             break;
    461         }
    462     }
    463 
    464     /* Update linked values: */
    465     updateLayoutSpacings();
    466     updateItemCountInfo();
    467     updateToolTip();
    468     updateGeometry();
    469355}
    470356
     
    576462}
    577463
    578 void UIChooserItemGroup::updateAllItems(const QUuid &uId)
    579 {
    580     /* Update all the required items recursively: */
    581     foreach (UIChooserItem *pItem, items())
    582         pItem->updateAllItems(uId);
    583 
    584     /* Update item finally: */
    585     updateItem();
    586 }
    587 
    588 void UIChooserItemGroup::removeAllItems(const QUuid &uId)
    589 {
    590     /* Remove all the required items recursively: */
    591     foreach (UIChooserItem *pItem, items())
    592         pItem->removeAllItems(uId);
    593 }
    594 
    595464UIChooserItem* UIChooserItemGroup::searchForItem(const QString &strSearchTag, int iItemSearchFlags)
    596465{
     
    632501{
    633502    /* If this group-item have at least one machine-item: */
    634     if (hasItems(UIChooserItemType_Machine))
     503    if (node()->hasNodes(UIChooserItemType_Machine))
    635504        /* Return the first machine-item: */
    636505        return items(UIChooserItemType_Machine).first()->firstMachineItem();
    637506    /* If this group-item have at least one group-item: */
    638     else if (hasItems(UIChooserItemType_Group))
     507    else if (node()->hasNodes(UIChooserItemType_Group))
    639508        /* Return the first machine-item of the first group-item: */
    640509        return items(UIChooserItemType_Group).first()->firstMachineItem();
     
    645514void UIChooserItemGroup::sortItems()
    646515{
     516    /// @todo implement manual sorting
     517
     518#if 0
    647519    /* Sort group-items: */
    648520    QMap<QString, UIChooserItem*> sorter;
     
    656528        sorter.insert(pItem->name().toLower(), pItem);
    657529    setItems(sorter.values(), UIChooserItemType_Machine);
     530#endif
    658531
    659532    /* Update model: */
     
    920793                const UIChooserItemMimeData *pCastedMime = qobject_cast<const UIChooserItemMimeData*>(pMime);
    921794                AssertMsg(pCastedMime, ("Can't cast passed mime-data to UIChooserItemMimeData!"));
    922                 UIChooserItem *pItem = pCastedMime->item();
     795                UIChooserNode *pNode = pCastedMime->item()->node();
    923796
    924797                /* Check if we have position information: */
     
    937810
    938811                /* Copy passed group-item into this group: */
    939                 UIChooserItem *pNewGroupItem = new UIChooserItemGroup(this, pItem->toGroupItem(), iPosition);
     812                UIChooserNodeGroup *pNewGroupNode = new UIChooserNodeGroup(node(), pNode->toGroupNode(), iPosition);
     813                UIChooserItemGroup *pNewGroupItem = new UIChooserItemGroup(this, pNewGroupNode);
    940814                if (isClosed())
    941815                    open(false);
     
    945819                {
    946820                    /* Delete passed item: */
    947                     delete pItem;
     821                    delete pNode;
    948822                }
    949823
     
    973847                const UIChooserItemMimeData *pCastedMime = qobject_cast<const UIChooserItemMimeData*>(pMime);
    974848                AssertMsg(pCastedMime, ("Can't cast passed mime-data to UIChooserItemMimeData!"));
    975                 UIChooserItem *pItem = pCastedMime->item();
     849                UIChooserNode *pNode = pCastedMime->item()->node();
    976850
    977851                /* Check if we have position information: */
     
    990864
    991865                /* Copy passed machine-item into this group: */
    992                 UIChooserItem *pNewMachineItem = new UIChooserItemMachine(this, pItem->toMachineItem(), iPosition);
     866                UIChooserNodeMachine *pNewMachineNode = new UIChooserNodeMachine(node(), pNode->toMachineNode(), iPosition);
     867                UIChooserItemMachine *pNewMachineItem = new UIChooserItemMachine(this, pNewMachineNode);
    993868                if (isClosed())
    994869                    open(false);
     
    998873                {
    999874                    /* Delete passed item: */
    1000                     delete pItem;
     875                    delete pNode;
    1001876                }
    1002877
     
    12651140     * it will be added to the scene indirectly: */
    12661141    else if (parentItem())
    1267         parentItem()->addItem(this, isFavorite(), m_iPosition);
     1142        parentItem()->addItem(this, isFavorite(), position());
    12681143    /* Otherwise sombody forgot to pass scene or parent. */
    12691144    else
    12701145        AssertFailedReturnVoid();
    12711146
    1272     /* Copy item contents if any: */
    1273     if (m_pItemToCopy)
    1274         copyContent(m_pItemToCopy, this);
     1147    /* Copy contents: */
     1148    copyContents(node()->toGroupNode());
    12751149
    12761150    /* Apply language settings: */
     
    13101184
    13111185    /* Delete all the items: */
    1312     clearItems();
     1186    while (!m_groupItems.isEmpty()) { delete m_groupItems.last(); }
     1187    while (!m_globalItems.isEmpty()) { delete m_globalItems.last(); }
     1188    while (!m_machineItems.isEmpty()) { delete m_machineItems.last(); }
    13131189
    13141190    /* If that item is focused: */
     
    13891265}
    13901266
    1391 /* static */
    1392 void UIChooserItemGroup::copyContent(UIChooserItemGroup *pFrom, UIChooserItemGroup *pTo)
    1393 {
    1394     /* Copy group-items: */
    1395     foreach (UIChooserItem *pGroupItem, pFrom->items(UIChooserItemType_Group))
    1396         new UIChooserItemGroup(pTo, pGroupItem->toGroupItem());
    1397     /* Copy global-items: */
    1398     foreach (UIChooserItem *pGlobalItem, pFrom->items(UIChooserItemType_Global))
    1399         new UIChooserItemGlobal(pTo, pGlobalItem->toGlobalItem());
    1400     /* Copy machine-items: */
    1401     foreach (UIChooserItem *pMachineItem, pFrom->items(UIChooserItemType_Machine))
    1402         new UIChooserItemMachine(pTo, pMachineItem->toMachineItem());
     1267void UIChooserItemGroup::copyContents(UIChooserNodeGroup *pCopyFrom)
     1268{
     1269    foreach (UIChooserNode *pNode, pCopyFrom->nodes(UIChooserItemType_Group))
     1270        new UIChooserItemGroup(this, pNode->toGroupNode());
     1271    foreach (UIChooserNode *pNode, pCopyFrom->nodes(UIChooserItemType_Global))
     1272        new UIChooserItemGlobal(this, pNode->toGlobalNode());
     1273    foreach (UIChooserNode *pNode, pCopyFrom->nodes(UIChooserItemType_Machine))
     1274        new UIChooserItemMachine(this, pNode->toMachineNode());
    14031275}
    14041276
     
    14781350    {
    14791351        /* Main root-item always takes body into account: */
    1480         if (hasItems())
     1352        if (node()->hasNodes())
    14811353        {
    14821354            /* We have to take maximum children width into account: */
     
    15201392    {
    15211393        /* Main root-item always takes body into account: */
    1522         if (hasItems())
     1394        if (node()->hasNodes())
    15231395        {
    15241396            /* We have to take maximum children height into account: */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGroup.h

    r77636 r77638  
    2828class QGraphicsLinearLayout;
    2929class QLineEdit;
     30class UIChooserNodeGroup;
    3031class UIEditorGroupRename;
    3132class UIGraphicsButton;
     
    5556    enum { Type = UIChooserItemType_Group };
    5657
    57     /** Constructs root item, passing pScene to the base-class. */
    58     UIChooserItemGroup(QGraphicsScene *pScene);
    59     /** Constructs non-root item with specified @a strName and @a iPosition, @a fOpened if requested, passing pParent to the base-class. */
    60     UIChooserItemGroup(UIChooserItem *pParent, const QString &strName, bool fOpened = false, int iPosition  = -1);
    61     /** Constructs a copy of non-root @a pCopiedItem with specified @a iPosition, passing pParent to the base-class. */
    62     UIChooserItemGroup(UIChooserItem *pParent, UIChooserItemGroup *pCopiedItem, int iPosition = -1);
     58    /** Build item for certain @a pNode, adding it directly to the @a pScene. */
     59    UIChooserItemGroup(QGraphicsScene *pScene, UIChooserNodeGroup *pNode);
     60    /** Build item for certain @a pNode, passing @a pParent to the base-class. */
     61    UIChooserItemGroup(UIChooserItem *pParent, UIChooserNodeGroup *pNode);
    6362    /** Destructs group item. */
    6463    virtual ~UIChooserItemGroup() /* override */;
     
    130129    /** @name Children stuff.
    131130      * @{ */
    132         /** Returns whether there are children items of certain @a enmType. */
    133         virtual bool hasItems(UIChooserItemType enmType = UIChooserItemType_Any) const /* override */;
    134131        /** Returns children items of certain @a enmType. */
    135132        virtual QList<UIChooserItem*> items(UIChooserItemType enmType = UIChooserItemType_Any) const /* override */;
    136 
    137         /** Replaces children @a items of certain @a enmType. */
    138         virtual void setItems(const QList<UIChooserItem*> &items, UIChooserItemType enmType) /* override */;
    139         /** Clears children items of certain @a enmType. */
    140         virtual void clearItems(UIChooserItemType enmType = UIChooserItemType_Any) /* override */;
    141133
    142134        /** Adds possible @a fFavorite child @a pItem to certain @a iPosition. */
     
    144136        /** Removes child @a pItem. */
    145137        virtual void removeItem(UIChooserItem *pItem) /* override */;
    146 
    147         /** Updates all children items with specified @a uId. */
    148         virtual void updateAllItems(const QUuid &uId) /* override */;
    149         /** Removes all children items with specified @a uId. */
    150         virtual void removeAllItems(const QUuid &uId) /* override */;
    151138
    152139        /** Searches for a first child item answering to specified @a strSearchTag and @a iItemSearchFlags. */
     
    266253    /** @name Children stuff.
    267254      * @{ */
    268         /** Copies group contents @a pFrom one item @a pTo another. */
    269         static void copyContent(UIChooserItemGroup *pFrom, UIChooserItemGroup *pTo);
     255        /** Copies group contents from @a pCopyFrom node recursively. */
     256        void copyContents(UIChooserNodeGroup *pCopyFrom);
    270257
    271258        /** Returns whether group contains machine with @a uId. */
     
    310297      * @{ */
    311298        /** Holds the graphics scene reference. */
    312         QGraphicsScene      *m_pScene;
    313         /** Holds the copied chooser item reference. */
    314         UIChooserItemGroup  *m_pItemToCopy;
    315         /** Holds the item position. */
    316         const int            m_iPosition;
     299        QGraphicsScene *m_pScene;
    317300
    318301        /** Holds the cached visible name. */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemMachine.cpp

    r77636 r77638  
    2727#include "UIChooserItemMachine.h"
    2828#include "UIChooserModel.h"
     29#include "UIChooserNodeGroup.h"
    2930#include "UIChooserNodeMachine.h"
    3031#include "UIIconPool.h"
     
    3536
    3637
    37 UIChooserItemMachine::UIChooserItemMachine(UIChooserItem *pParent,
    38                                            const CMachine &comMachine,
    39                                            int iPosition /* = -1 */)
    40     : UIChooserItem(pParent, new UIChooserNodeMachine(pParent->node(), false /* favorite? */, comMachine), 0, 100)
    41     , m_iPosition(iPosition)
     38UIChooserItemMachine::UIChooserItemMachine(UIChooserItem *pParent, UIChooserNodeMachine *pNode)
     39    : UIChooserItem(pParent, pNode, 0, 100)
    4240    , m_iDefaultLightnessMin(0)
    4341    , m_iDefaultLightnessMax(0)
     
    5553}
    5654
    57 UIChooserItemMachine::UIChooserItemMachine(UIChooserItem *pParent,
    58                                            UIChooserItemMachine *pCopiedItem,
    59                                            int iPosition /* = -1 */)
    60     : UIChooserItem(pParent, new UIChooserNodeMachine(pParent->node(), false /* favorite? */, pCopiedItem->machine()), 0, 100)
    61     , m_iPosition(iPosition)
    62     , m_iDefaultLightnessMin(0)
    63     , m_iDefaultLightnessMax(0)
    64     , m_iHoverLightnessMin(0)
    65     , m_iHoverLightnessMax(0)
    66     , m_iHighlightLightnessMin(0)
    67     , m_iHighlightLightnessMax(0)
    68     , m_iFirstRowMaximumWidth(0)
    69     , m_iMinimumNameWidth(0)
    70     , m_iMaximumNameWidth(0)
    71     , m_iMinimumSnapshotNameWidth(0)
    72     , m_iMaximumSnapshotNameWidth(0)
    73 {
    74     prepare();
    75 }
    76 
    7755UIChooserItemMachine::~UIChooserItemMachine()
    7856{
    7957    cleanup();
    80 }
    81 
    82 CMachine UIChooserItemMachine::machine() const
    83 {
    84     return node()->toMachineNode()->machine();
    8558}
    8659
     
    249222}
    250223
    251 bool UIChooserItemMachine::hasItems(UIChooserItemType) const
    252 {
    253     AssertMsgFailed(("Machine graphics item do NOT support children!"));
    254     return false;
    255 }
    256 
    257224QList<UIChooserItem*> UIChooserItemMachine::items(UIChooserItemType) const
    258225{
     
    261228}
    262229
    263 void UIChooserItemMachine::setItems(const QList<UIChooserItem*>&, UIChooserItemType)
     230void UIChooserItemMachine::addItem(UIChooserItem*, bool, int)
    264231{
    265232    AssertMsgFailed(("Machine graphics item do NOT support children!"));
    266233}
    267234
    268 void UIChooserItemMachine::clearItems(UIChooserItemType)
     235void UIChooserItemMachine::removeItem(UIChooserItem*)
    269236{
    270237    AssertMsgFailed(("Machine graphics item do NOT support children!"));
    271 }
    272 
    273 void UIChooserItemMachine::addItem(UIChooserItem*, bool, int)
    274 {
    275     AssertMsgFailed(("Machine graphics item do NOT support children!"));
    276 }
    277 
    278 void UIChooserItemMachine::removeItem(UIChooserItem*)
    279 {
    280     AssertMsgFailed(("Machine graphics item do NOT support children!"));
    281 }
    282 
    283 void UIChooserItemMachine::updateAllItems(const QUuid &uId)
    284 {
    285     /* Skip other ids: */
    286     if (id() != QUuid(uId))
    287         return;
    288 
    289     /* Update item: */
    290     updateItem();
    291 }
    292 
    293 void UIChooserItemMachine::removeAllItems(const QUuid &uId)
    294 {
    295     /* Skip wrong id: */
    296     if (id() != QUuid(uId))
    297         return;
    298 
    299     /* Exclude itself from the current items: */
    300     if (model()->currentItems().contains(this))
    301         model()->removeFromCurrentItems(this);
    302     /* Move the focus item to the first available current after that: */
    303     if (model()->focusItem() == this && !model()->currentItems().isEmpty())
    304         model()->setFocusItem(model()->currentItems().first());
    305 
    306     /* Remove item: */
    307     delete this;
    308238}
    309239
     
    488418                const UIChooserItemMimeData *pCastedMime = qobject_cast<const UIChooserItemMimeData*>(pMime);
    489419                AssertMsg(pCastedMime, ("Can't cast passed mime-data to UIChooserItemMimeData!"));
    490                 UIChooserItem *pItem = pCastedMime->item();
     420                UIChooserNode *pNode = pCastedMime->item()->node();
    491421
    492422                /* Group passed item with current item into the new group: */
    493                 UIChooserItemGroup *pNewGroupItem = new UIChooserItemGroup(parentItem(),
     423                UIChooserNodeGroup *pNewGroupNode = new UIChooserNodeGroup(parentItem()->node(),
     424                                                                           false /* favorite */,
     425                                                                           parentItem()->node()->nodes().size(),
    494426                                                                           UIChooserModel::uniqueGroupName(parentItem()),
    495                                                                            true);
    496                 new UIChooserItemMachine(pNewGroupItem, this);
    497                 new UIChooserItemMachine(pNewGroupItem, pItem->toMachineItem());
     427                                                                           true /* true */);
     428                UIChooserItemGroup *pNewGroupItem = new UIChooserItemGroup(parentItem(), pNewGroupNode);
     429                UIChooserNodeMachine *pNewMachineNode1 = new UIChooserNodeMachine(pNewGroupNode,
     430                                                                                  node()->toMachineNode(),
     431                                                                                  pNewGroupNode->nodes().size());
     432                new UIChooserItemMachine(pNewGroupItem, pNewMachineNode1);
     433                UIChooserNodeMachine *pNewMachineNode2 = new UIChooserNodeMachine(pNewGroupNode,
     434                                                                                  pNode->toMachineNode(),
     435                                                                                  pNewGroupNode->nodes().size());
     436                new UIChooserItemMachine(pNewGroupItem, pNewMachineNode2);
    498437
    499438                /* If proposed action is 'move': */
    500439                if (pEvent->proposedAction() == Qt::MoveAction)
    501440                {
    502                     /* Delete passed item: */
    503                     delete pItem;
     441                    /* Delete passed node: */
     442                    delete pNode;
    504443                }
    505                 /* Delete this item: */
    506                 delete this;
     444                /* Delete this node: */
     445                delete node();
    507446
    508447                /* Update model: */
     
    576515    /* Add item to the parent: */
    577516    AssertPtrReturnVoid(parentItem());
    578     parentItem()->addItem(this, isFavorite(), m_iPosition);
     517    parentItem()->addItem(this, isFavorite(), position());
    579518
    580519    /* Configure connections: */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemMachine.h

    r77636 r77638  
    2525#include "UIChooserItem.h"
    2626
    27 /* COM includes: */
    28 #include "COMEnums.h"
    29 #include "CMachine.h"
     27/* Forward declarations: */
     28class UIChooserNodeMachine;
    3029
    3130
     
    4039    enum { Type = UIChooserItemType_Machine };
    4140
    42     /** Constructs item with specified @a comMachine and @a iPosition, passing @a pParent to the base-class. */
    43     UIChooserItemMachine(UIChooserItem *pParent, const CMachine &comMachine, int iPosition = -1);
    44     /** Constructs a copy of @a pCopiedItem with specified @a iPosition, passing @a pParent to the base-class. */
    45     UIChooserItemMachine(UIChooserItem *pParent, UIChooserItemMachine *pCopiedItem, int iPosition = -1);
     41    /** Build item for certain @a pNode, passing @a pParent to the base-class. */
     42    UIChooserItemMachine(UIChooserItem *pParent, UIChooserNodeMachine *pNode);
    4643    /** Destructs machine item. */
    4744    virtual ~UIChooserItemMachine() /* override */;
     
    4946    /** @name Item stuff.
    5047      * @{ */
    51         /** Returns item machine. */
    52         CMachine machine() const;
    5348        /** Returns item machine id. */
    5449        QUuid id() const;
     
    112107    /** @name Children stuff.
    113108      * @{ */
    114         /** Returns whether there are children items of certain @a enmType. */
    115         virtual bool hasItems(UIChooserItemType enmType = UIChooserItemType_Any) const /* override */;
    116109        /** Returns children items of certain @a enmType. */
    117110        virtual QList<UIChooserItem*> items(UIChooserItemType enmType = UIChooserItemType_Any) const /* override */;
    118 
    119         /** Replaces children @a items of certain @a enmType. */
    120         virtual void setItems(const QList<UIChooserItem*> &items, UIChooserItemType enmType) /* override */;
    121         /** Clears children items of certain @a enmType. */
    122         virtual void clearItems(UIChooserItemType enmType = UIChooserItemType_Any) /* override */;
    123111
    124112        /** Adds possible @a fFavorite child @a pItem to certain @a iPosition. */
     
    126114        /** Removes child @a pItem. */
    127115        virtual void removeItem(UIChooserItem *pItem) /* override */;
    128 
    129         /** Updates all children items with specified @a uId. */
    130         virtual void updateAllItems(const QUuid &uId) /* override */;
    131         /** Removes all children items with specified @a uId. */
    132         virtual void removeAllItems(const QUuid &uId) /* override */;
    133116
    134117        /** Searches for a first child item answering to specified @a strSearchTag and @a iItemSearchFlags. */
     
    270253    /** @name Item stuff.
    271254      * @{ */
    272         /** Holds initial item position. */
    273         const int  m_iPosition;
    274 
    275255        /** Holds item minimum default lightness. */
    276256        int  m_iDefaultLightnessMin;
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.cpp

    r77636 r77638  
    3737#include "UIChooserNode.h"
    3838#include "UIChooserNodeGroup.h"
     39#include "UIChooserNodeGlobal.h"
    3940#include "UIChooserNodeMachine.h"
    4041#include "UIExtraDataManager.h"
     
    6667    , m_pContextMenuGroup(0)
    6768    , m_pContextMenuMachine(0)
     69    , m_pInvisibleRootNode(0)
    6870    , m_iScrollingTokenSize(30)
    6971    , m_fIsScrollingInProgress(false)
     
    8082void UIChooserModel::init()
    8183{
    82     /* Install root as event-filter for scene view,
    83      * we need QEvent::Scroll events from it: */
    84     root()->installEventFilterHelper(scene()->views()[0]);
    85 
    86     /* Load group tree: */
    87     loadGroupTree();
     84    /* Load tree: */
     85    loadTree();
     86
     87    /* Build tree for main root: */
     88    buildTreeForMainRoot();
    8889    updateNavigation();
    8990    updateLayout();
     
    107108    makeSureGroupDefinitionsSaveIsFinished();
    108109    makeSureGroupOrdersSaveIsFinished();
     110
     111    /* Unset current items: */
     112    unsetCurrentItems();
     113
     114    /* Delete tree: */
     115    delete m_pInvisibleRootNode;
     116    m_pInvisibleRootNode = 0;
    109117}
    110118
     
    288296    /* Return first machine-item of the current-item: */
    289297    return   currentItem() && currentItem()->firstMachineItem() && currentItem()->firstMachineItem()->node()
    290            ? currentItem()->firstMachineItem()->toMachineItem()->node()->toMachineNode()
     298           ? currentItem()->firstMachineItem()->node()->toMachineNode()
    291299           : 0;
    292300}
     
    443451}
    444452
     453UIChooserNode *UIChooserModel::invisibleRoot() const
     454{
     455    return m_pInvisibleRootNode;
     456}
     457
    445458UIChooserItem *UIChooserModel::root() const
    446459{
     
    455468void UIChooserModel::wipeOutEmptyGroups()
    456469{
    457     wipeOutEmptyGroups(root());
     470    wipeOutEmptyGroups(invisibleRoot());
    458471}
    459472
     
    663676void UIChooserModel::sltMachineStateChanged(const QUuid &uId, const KMachineState)
    664677{
    665     /* Update machine-items with passed id: */
    666     root()->updateAllItems(uId);
     678    /* Update machine-nodes with passed id: */
     679    invisibleRoot()->updateAllNodes(uId);
    667680}
    668681
    669682void UIChooserModel::sltMachineDataChanged(const QUuid &uId)
    670683{
    671     /* Update machine-items with passed id: */
    672     root()->updateAllItems(uId);
     684    /* Update machine-nodes with passed id: */
     685    invisibleRoot()->updateAllNodes(uId);
    673686}
    674687
     
    685698            addMachineIntoTheTree(comMachine, true /* make it visible */);
    686699
    687             /* And update model: */
     700            /* Rebuild tree for main root: */
     701            buildTreeForMainRoot();
    688702            updateNavigation();
    689703            updateLayout();
     
    699713    {
    700714        /* Remove machine-items with passed id: */
    701         root()->removeAllItems(uId.toString());
    702         /* Update model: */
     715        invisibleRoot()->removeAllNodes(uId.toString());
     716        /* Wipe out empty groups: */
    703717        wipeOutEmptyGroups();
    704718
    705         /* And update model: */
     719        /* Rebuild tree for main root: */
     720        buildTreeForMainRoot();
    706721        updateNavigation();
    707722        updateLayout();
     
    720735void UIChooserModel::sltSessionStateChanged(const QUuid &uId, const KSessionState)
    721736{
    722     /* Update machine-items with passed id: */
    723     root()->updateAllItems(uId);
     737    /* Update machine-nodes with passed id: */
     738    invisibleRoot()->updateAllNodes(uId);
    724739}
    725740
    726741void UIChooserModel::sltSnapshotChanged(const QUuid &uId, const QUuid &)
    727742{
    728     /* Update machine-items with passed id: */
    729     root()->updateAllItems(uId);
     743    /* Update machine-nodes with passed id: */
     744    invisibleRoot()->updateAllNodes(uId);
    730745}
    731746
     
    774789    /* Check if we have collisions with our siblings: */
    775790    UIChooserItem *pFocusItem = focusItem();
     791    UIChooserNode *pFocusNode = pFocusItem->node();
    776792    UIChooserItem *pParentItem = pFocusItem->parentItem();
    777     QList<UIChooserItem*> siblings = pParentItem->items();
    778     QList<UIChooserItem*> toBeRenamed;
    779     QList<UIChooserItem*> toBeRemoved;
    780     foreach (UIChooserItem *pItem, pFocusItem->items())
    781     {
    782         QString strItemName = pItem->name();
    783         UIChooserItem *pCollisionSibling = 0;
    784         foreach (UIChooserItem *pSibling, siblings)
    785             if (pSibling != pFocusItem && pSibling->name() == strItemName)
     793    UIChooserNode *pParentNode = pParentItem->node();
     794    QList<UIChooserNode*> siblings = pParentNode->nodes();
     795    QList<UIChooserNode*> toBeRenamed;
     796    QList<UIChooserNode*> toBeRemoved;
     797    foreach (UIChooserNode *pNode, pFocusNode->nodes())
     798    {
     799        QString strItemName = pNode->name();
     800        UIChooserNode *pCollisionSibling = 0;
     801        foreach (UIChooserNode *pSibling, siblings)
     802            if (pSibling != pFocusNode && pSibling->name() == strItemName)
    786803                pCollisionSibling = pSibling;
    787804        if (pCollisionSibling)
    788805        {
    789             if (pItem->type() == UIChooserItemType_Machine)
     806            if (pNode->type() == UIChooserItemType_Machine)
    790807            {
    791808                if (pCollisionSibling->type() == UIChooserItemType_Machine)
    792                     toBeRemoved << pItem;
     809                    toBeRemoved << pNode;
    793810                else if (pCollisionSibling->type() == UIChooserItemType_Group)
    794811                {
    795                     msgCenter().cannotResolveCollisionAutomatically(strItemName, pParentItem->name());
     812                    msgCenter().cannotResolveCollisionAutomatically(strItemName, pParentNode->name());
    796813                    return;
    797814                }
    798815            }
    799             else if (pItem->type() == UIChooserItemType_Group)
     816            else if (pNode->type() == UIChooserItemType_Group)
    800817            {
    801                 if (msgCenter().confirmAutomaticCollisionResolve(strItemName, pParentItem->name()))
    802                     toBeRenamed << pItem;
     818                if (msgCenter().confirmAutomaticCollisionResolve(strItemName, pParentNode->name()))
     819                    toBeRenamed << pNode;
    803820                else
    804821                    return;
     
    809826    /* Copy all the children into our parent: */
    810827    QList<UIChooserItem*> copiedItems;
    811     foreach (UIChooserItem *pItem, pFocusItem->items())
    812     {
    813         if (toBeRemoved.contains(pItem))
     828    foreach (UIChooserNode *pNode, pFocusNode->nodes())
     829    {
     830        if (toBeRemoved.contains(pNode))
    814831            continue;
    815         switch (pItem->type())
     832        switch (pNode->type())
    816833        {
    817834            case UIChooserItemType_Group:
    818835            {
    819                 UIChooserItemGroup *pGroupItem = new UIChooserItemGroup(pParentItem, pItem->toGroupItem());
    820                 if (toBeRenamed.contains(pItem))
    821                     pGroupItem->node()->toGroupNode() ->setName(uniqueGroupName(pParentItem));
     836                UIChooserNodeGroup *pGroupNode = new UIChooserNodeGroup(pParentNode,
     837                                                                        pNode->toGroupNode(),
     838                                                                        pParentNode->nodes().size());
     839                UIChooserItemGroup *pGroupItem = new UIChooserItemGroup(pParentItem, pGroupNode);
     840                if (toBeRenamed.contains(pNode))
     841                    pGroupNode->setName(uniqueGroupName(pParentItem));
    822842                copiedItems << pGroupItem;
    823843                break;
     
    825845            case UIChooserItemType_Machine:
    826846            {
    827                 UIChooserItemMachine *pMachineItem = new UIChooserItemMachine(pParentItem, pItem->toMachineItem());
     847                UIChooserNodeMachine *pMachineNode = new UIChooserNodeMachine(pParentNode,
     848                                                                              pNode->toMachineNode(),
     849                                                                              pParentNode->nodes().size());
     850                UIChooserItemMachine *pMachineItem = new UIChooserItemMachine(pParentItem, pMachineNode);
    828851                copiedItems << pMachineItem;
    829852                break;
     
    835858
    836859    /* Delete focus group: */
    837     delete focusItem();
     860    delete pFocusNode;
    838861
    839862    /* Notify about selection invalidated: */
     
    897920        return;
    898921
    899     /* Create new group item in the current root: */
    900     UIChooserItemGroup *pNewGroupItem = new UIChooserItemGroup(root(), uniqueGroupName(root()), true);
     922    /* Create new group node in the current root: */
     923    UIChooserNodeGroup *pNewGroupNode = new UIChooserNodeGroup(invisibleRoot(),
     924                                                               false /* favorite */,
     925                                                               invisibleRoot()->nodes().size() /* position */,
     926                                                               uniqueGroupName(root()),
     927                                                               true /* opened */);
     928    UIChooserItemGroup *pNewGroupItem = new UIChooserItemGroup(root(), pNewGroupNode);
    901929
    902930    /* Enumerate all the currently chosen items: */
     
    917945                busyGroupNames << pItem->name();
    918946                /* Copy or move group-item: */
    919                 new UIChooserItemGroup(pNewGroupItem, pItem->toGroupItem());
    920                 delete pItem;
     947                UIChooserNodeGroup *pNewGroupSubNode = new UIChooserNodeGroup(pNewGroupNode,
     948                                                                              pItem->node()->toGroupNode(),
     949                                                                              pNewGroupNode->nodes().size());
     950                new UIChooserItemGroup(pNewGroupItem, pNewGroupSubNode);
     951                delete pItem->node();
    921952                break;
    922953            }
     
    929960                busyMachineNames << pItem->name();
    930961                /* Copy or move machine-item: */
    931                 new UIChooserItemMachine(pNewGroupItem, pItem->toMachineItem());
    932                 delete pItem;
     962                UIChooserNodeMachine *pNewMachineSubNode = new UIChooserNodeMachine(pNewGroupNode,
     963                                                                                    pItem->node()->toMachineNode(),
     964                                                                                    pNewGroupNode->nodes().size());
     965                new UIChooserItemMachine(pNewGroupItem, pNewMachineSubNode);
     966                delete pItem->node();
    933967                break;
    934968            }
     
    946980void UIChooserModel::sltReloadMachine(const QUuid &uId)
    947981{
    948     /* Remove all the items first: */
    949     root()->removeAllItems(uId);
     982    /* Remove all the nodes first: */
     983    invisibleRoot()->removeAllNodes(uId);
    950984    /* Wipe out empty groups: */
    951985    wipeOutEmptyGroups();
     
    958992        addMachineIntoTheTree(comMachine);
    959993
    960         /* And update model: */
     994        /* Rebuild tree for main root: */
     995        buildTreeForMainRoot();
    961996        updateNavigation();
    962997        updateLayout();
     
    11741209    prepareScene();
    11751210
    1176     /* Prepare root: */
    1177     prepareRoot();
    1178 
    11791211    /* Prepare lookup: */
    11801212    prepareLookup();
     
    11951227    if (m_pScene)
    11961228        m_pScene->installEventFilter(this);
    1197 }
    1198 
    1199 void UIChooserModel::prepareRoot()
    1200 {
    1201     m_pRoot = new UIChooserItemGroup(scene());
    12021229}
    12031230
     
    14181445}
    14191446
    1420 void UIChooserModel::cleanupRoot()
    1421 {
    1422     delete root();
    1423     m_pRoot.clear();
    1424 }
    1425 
    14261447void UIChooserModel::cleanupScene()
    14271448{
     
    14401461    /* Cleanup lookup: */
    14411462    cleanupLookup();
    1442 
    1443     /* Cleanup root: */
    1444     cleanupRoot();
    14451463
    14461464    /* Cleanup scene: */
     
    15941612}
    15951613
    1596 void UIChooserModel::loadGroupTree()
    1597 {
    1598     /* Make sure root exists: */
    1599     if (root())
    1600     {
    1601         /* Create global item: */
    1602         new UIChooserItemGlobal(root(),
    1603                                 isGlobalItemFavorite(root()),
    1604                                 0);
    1605 
    1606         /* Add all the approved machine items into the tree: */
     1614void UIChooserModel::loadTree()
     1615{
     1616    /* Create invisible root group node: */
     1617    m_pInvisibleRootNode = new UIChooserNodeGroup(0 /* parent */,
     1618                                                  false /* favorite */,
     1619                                                  0 /* position */,
     1620                                                  QString() /* name */,
     1621                                                  true /* opened */);
     1622    if (invisibleRoot())
     1623    {
     1624        /* Create global node: */
     1625        new UIChooserNodeGlobal(m_pInvisibleRootNode,
     1626                                isGlobalNodeFavorite(m_pInvisibleRootNode),
     1627                                0 /* position */,
     1628                                QString() /* tip */);
     1629
     1630        /* Add all the approved machine nodes into the tree: */
    16071631        LogRelFlow(("UIChooserModel: Loading VMs...\n"));
    16081632        foreach (const CMachine &comMachine, vboxGlobal().virtualBox().GetMachines())
     
    16461670            LogRelFlow(("UIChooserModel:   Creating item for VM {%s} in group {%s}.\n", strName.toUtf8().constData(),
    16471671                                                                                        strGroup.toUtf8().constData()));
    1648             createMachineItem(getGroupItem(strGroup, root(), fMakeItVisible), comMachine);
     1672            createMachineNode(getGroupNode(strGroup, invisibleRoot(), fMakeItVisible), comMachine);
    16491673        }
    16501674        /* Update group definitions: */
     
    16571681        LogRelFlow(("UIChooserModel:  VM {%s} is inaccessible.\n", toOldStyleUuid(comMachine.GetId()).toUtf8().constData()));
    16581682        /* Create machine-item with main-root group-item as parent: */
    1659         createMachineItem(root(), comMachine);
    1660     }
    1661 }
    1662 
    1663 UIChooserItem *UIChooserModel::getGroupItem(const QString &strName, UIChooserItem *pParentItem, bool fAllGroupsOpened)
     1683        createMachineNode(invisibleRoot(), comMachine);
     1684    }
     1685}
     1686
     1687UIChooserNode *UIChooserModel::getGroupNode(const QString &strName, UIChooserNode *pParentNode, bool fAllGroupsOpened)
    16641688{
    16651689    /* Check passed stuff: */
    1666     if (pParentItem->name() == strName)
    1667         return pParentItem;
     1690    if (pParentNode->name() == strName)
     1691        return pParentNode;
    16681692
    16691693    /* Prepare variables: */
     
    16741698
    16751699    /* Passed group name equal to first sub-name: */
    1676     if (pParentItem->name() == strFirstSubName)
     1700    if (pParentNode->name() == strFirstSubName)
    16771701    {
    16781702        /* Make sure first-suffix is NOT empty: */
    16791703        AssertMsg(!strFirstSuffix.isEmpty(), ("Invalid group name!"));
    1680         /* Trying to get group-item among our children: */
    1681         foreach (UIChooserItem *pGroupItem, pParentItem->items(UIChooserItemType_Group))
    1682         {
    1683             if (pGroupItem->name() == strSecondSubName)
     1704        /* Trying to get group node among our children: */
     1705        foreach (UIChooserNode *pGroupNode, pParentNode->nodes(UIChooserItemType_Group))
     1706        {
     1707            if (pGroupNode->name() == strSecondSubName)
    16841708            {
    1685                 UIChooserItem *pFoundItem = getGroupItem(strFirstSuffix, pGroupItem, fAllGroupsOpened);
    1686                 if (UIChooserItemGroup *pFoundGroupItem = pFoundItem->toGroupItem())
    1687                     if (fAllGroupsOpened && pFoundGroupItem->isClosed())
    1688                         pFoundGroupItem->open(false);
    1689                 return pFoundItem;
     1709                UIChooserNode *pFoundNode = getGroupNode(strFirstSuffix, pGroupNode, fAllGroupsOpened);
     1710                if (UIChooserNodeGroup *pFoundGroupNode = pFoundNode->toGroupNode())
     1711                    if (fAllGroupsOpened && pFoundGroupNode->isClosed())
     1712                        pFoundGroupNode->open();
     1713                return pFoundNode;
    16901714            }
    16911715        }
     
    16931717
    16941718    /* Found nothing? Creating: */
    1695     UIChooserItemGroup *pNewGroupItem =
    1696         new UIChooserItemGroup(/* Parent item and desired group name: */
    1697                                pParentItem, strSecondSubName,
    1698                                /* Should be new group opened when created? */
    1699                                fAllGroupsOpened || shouldBeGroupOpened(pParentItem, strSecondSubName),
    1700                                /* Which position new group-item should be placed in? */
    1701                                getDesiredPosition(pParentItem, UIChooserItemType_Group, strSecondSubName));
    1702     return strSecondSuffix.isEmpty() ? pNewGroupItem : getGroupItem(strFirstSuffix, pNewGroupItem, fAllGroupsOpened);
    1703 }
    1704 
    1705 bool UIChooserModel::shouldBeGroupOpened(UIChooserItem *pParentItem, const QString &strName)
     1719    UIChooserNodeGroup *pNewGroupNode =
     1720        new UIChooserNodeGroup(pParentNode,
     1721                               false /* favorite */,
     1722                               getDesiredPosition(pParentNode, UIChooserItemType_Group, strSecondSubName),
     1723                               strSecondSubName,
     1724                               fAllGroupsOpened || shouldBeGroupOpened(pParentNode, strSecondSubName));
     1725    return strSecondSuffix.isEmpty() ? pNewGroupNode : getGroupNode(strFirstSuffix, pNewGroupNode, fAllGroupsOpened);
     1726}
     1727
     1728bool UIChooserModel::shouldBeGroupOpened(UIChooserNode *pParentNode, const QString &strName)
    17061729{
    17071730    /* Read group definitions: */
    1708     const QStringList definitions = gEDataManager->selectorWindowGroupsDefinitions(pParentItem->fullName());
     1731    const QStringList definitions = gEDataManager->selectorWindowGroupsDefinitions(pParentNode->fullName());
    17091732    /* Return 'false' if no definitions found: */
    17101733    if (definitions.isEmpty())
     
    17311754}
    17321755
    1733 void UIChooserModel::wipeOutEmptyGroups(UIChooserItem *pParent)
     1756void UIChooserModel::wipeOutEmptyGroups(UIChooserNode *pParent)
    17341757{
    17351758    /* Cleanup all the group-items recursively first: */
    1736     foreach (UIChooserItem *pItem, pParent->items(UIChooserItemType_Group))
    1737         wipeOutEmptyGroups(pItem);
    1738     /* If parent has no items: */
    1739     if (!pParent->hasItems())
     1759    foreach (UIChooserNode *pNode, pParent->nodes(UIChooserItemType_Group))
     1760        wipeOutEmptyGroups(pNode);
     1761    /* If parent has no nodes: */
     1762    if (!pParent->hasNodes())
    17401763    {
    17411764        /* If that is non-root item: */
     
    17481771}
    17491772
    1750 bool UIChooserModel::isGlobalItemFavorite(UIChooserItem *pParentItem) const
     1773void UIChooserModel::buildTreeForMainRoot()
     1774{
     1775    /* Cleanup previous tree if exists: */
     1776    delete m_pRoot;
     1777    m_pRoot = 0;
     1778
     1779    /* Build whole tree for invisible root item: */
     1780    m_pRoot = new UIChooserItemGroup(scene(), invisibleRoot()->toGroupNode());
     1781
     1782    /* Install root as event-filter for scene view,
     1783     * we need QEvent::Scroll events from it: */
     1784    root()->installEventFilterHelper(scene()->views()[0]);
     1785}
     1786
     1787bool UIChooserModel::isGlobalNodeFavorite(UIChooserNode *pParentNode) const
    17511788{
    17521789    /* Read group definitions: */
    1753     const QStringList definitions = gEDataManager->selectorWindowGroupsDefinitions(pParentItem->fullName());
     1790    const QStringList definitions = gEDataManager->selectorWindowGroupsDefinitions(pParentNode->fullName());
    17541791    /* Return 'false' if no definitions found: */
    17551792    if (definitions.isEmpty())
     
    17761813}
    17771814
    1778 int UIChooserModel::getDesiredPosition(UIChooserItem *pParentItem, UIChooserItemType enmType, const QString &strName)
     1815int UIChooserModel::getDesiredPosition(UIChooserNode *pParentNode, UIChooserItemType enmType, const QString &strName)
    17791816{
    17801817    /* End of list (by default)? */
    1781     int iNewItemDesiredPosition = -1;
    1782     /* Which position should be new item placed by definitions: */
    1783     int iNewItemDefinitionPosition = positionFromDefinitions(pParentItem, enmType, strName);
     1818    int iNewNodeDesiredPosition = -1;
     1819    /* Which position should be new node placed by definitions: */
     1820    int iNewNodeDefinitionPosition = positionFromDefinitions(pParentNode, enmType, strName);
    17841821    /* If some position wanted: */
    1785     if (iNewItemDefinitionPosition != -1)
     1822    if (iNewNodeDefinitionPosition != -1)
    17861823    {
    17871824        /* Start of list if some definition present: */
    1788         iNewItemDesiredPosition = 0;
    1789         /* We have to check all the existing item positions: */
    1790         QList<UIChooserItem*> items = pParentItem->items(enmType);
    1791         for (int i = items.size() - 1; i >= 0; --i)
    1792         {
    1793             /* Get current item: */
    1794             UIChooserItem *pItem = items[i];
    1795             /* Which position should be current item placed by definitions? */
    1796             QString strDefinitionName = pItem->type() == UIChooserItemType_Group ? pItem->name() :
    1797                                         pItem->type() == UIChooserItemType_Machine ? toOldStyleUuid(pItem->toMachineItem()->id()) :
     1825        iNewNodeDesiredPosition = 0;
     1826        /* We have to check all the existing node positions: */
     1827        QList<UIChooserNode*> nodes = pParentNode->nodes(enmType);
     1828        for (int i = nodes.size() - 1; i >= 0; --i)
     1829        {
     1830            /* Get current node: */
     1831            UIChooserNode *pNode = nodes[i];
     1832            /* Which position should be current node placed by definitions? */
     1833            QString strDefinitionName = pNode->type() == UIChooserItemType_Group ? pNode->name() :
     1834                                        pNode->type() == UIChooserItemType_Machine ? toOldStyleUuid(pNode->toMachineNode()->id()) :
    17981835                                        QString();
    17991836            AssertMsg(!strDefinitionName.isEmpty(), ("Wrong definition name!"));
    1800             int iItemDefinitionPosition = positionFromDefinitions(pParentItem, enmType, strDefinitionName);
     1837            int iNodeDefinitionPosition = positionFromDefinitions(pParentNode, enmType, strDefinitionName);
    18011838            /* If some position wanted: */
    1802             if (iItemDefinitionPosition != -1)
     1839            if (iNodeDefinitionPosition != -1)
    18031840            {
    1804                 AssertMsg(iItemDefinitionPosition != iNewItemDefinitionPosition, ("Incorrect definitions!"));
    1805                 if (iItemDefinitionPosition < iNewItemDefinitionPosition)
     1841                AssertMsg(iNodeDefinitionPosition != iNewNodeDefinitionPosition, ("Incorrect definitions!"));
     1842                if (iNodeDefinitionPosition < iNewNodeDefinitionPosition)
    18061843                {
    1807                     iNewItemDesiredPosition = i + 1;
     1844                    iNewNodeDesiredPosition = i + 1;
    18081845                    break;
    18091846                }
     
    18111848        }
    18121849    }
    1813     /* Return desired item position: */
    1814     return iNewItemDesiredPosition;
    1815 }
    1816 
    1817 int UIChooserModel::positionFromDefinitions(UIChooserItem *pParentItem, UIChooserItemType enmType, const QString &strName)
     1850    /* Return desired node position: */
     1851    return iNewNodeDesiredPosition;
     1852}
     1853
     1854int UIChooserModel::positionFromDefinitions(UIChooserNode *pParentNode, UIChooserItemType enmType, const QString &strName)
    18181855{
    18191856    /* Read group definitions: */
    1820     const QStringList definitions = gEDataManager->selectorWindowGroupsDefinitions(pParentItem->fullName());
     1857    const QStringList definitions = gEDataManager->selectorWindowGroupsDefinitions(pParentNode->fullName());
    18211858    /* Return 'false' if no definitions found: */
    18221859    if (definitions.isEmpty())
     
    18591896}
    18601897
    1861 void UIChooserModel::createMachineItem(UIChooserItem *pParentItem, const CMachine &comMachine)
    1862 {
    1863     /* Create machine item: */
    1864     new UIChooserItemMachine(pParentItem,
    1865                              comMachine,
    1866                              getDesiredPosition(pParentItem, UIChooserItemType_Machine, toOldStyleUuid(comMachine.GetId())));
     1898void UIChooserModel::createMachineNode(UIChooserNode *pParentNode, const CMachine &comMachine)
     1899{
     1900    /* Create machine node: */
     1901    new UIChooserNodeMachine(pParentNode,
     1902                             false /* favorite */,
     1903                             getDesiredPosition(pParentNode, UIChooserItemType_Machine, toOldStyleUuid(comMachine.GetId())),
     1904                             comMachine);
    18671905}
    18681906
    18691907void UIChooserModel::removeItems(const QList<UIChooserItem*> &itemsToRemove)
    18701908{
    1871 
    18721909    /* Confirm machine-items removal: */
    18731910    QStringList names;
     
    18771914        return;
    18781915
    1879     /* Remove all the passed items: */
     1916    /* Remove all the passed nodes: */
    18801917    foreach (UIChooserItem *pItem, itemsToRemove)
    1881         delete pItem;
     1918        delete pItem->node();
    18821919
    18831920    /* And update model: */
     
    20052042    /* Prepare full group map: */
    20062043    QMap<QString, QStringList> groups;
    2007     gatherGroupDefinitions(groups, root());
     2044    gatherGroupDefinitions(groups, invisibleRoot());
    20082045
    20092046    /* Save information in other thread: */
     
    20252062    /* Prepare full group map: */
    20262063    QMap<QString, QStringList> groups;
    2027     gatherGroupOrders(groups, root());
     2064    gatherGroupOrders(groups, invisibleRoot());
    20282065
    20292066    /* Save information in other thread: */
     
    20352072
    20362073void UIChooserModel::gatherGroupDefinitions(QMap<QString, QStringList> &definitions,
    2037                                             UIChooserItem *pParentGroup)
    2038 {
    2039     /* Iterate over all the machine-items: */
    2040     foreach (UIChooserItem *pItem, pParentGroup->items(UIChooserItemType_Machine))
    2041         if (UIChooserItemMachine *pMachineItem = pItem->toMachineItem())
    2042             if (pMachineItem->accessible())
    2043                 definitions[toOldStyleUuid(pMachineItem->id())] << pParentGroup->fullName();
    2044     /* Iterate over all the group-items: */
    2045     foreach (UIChooserItem *pItem, pParentGroup->items(UIChooserItemType_Group))
    2046         gatherGroupDefinitions(definitions, pItem);
     2074                                            UIChooserNode *pParentGroup)
     2075{
     2076    /* Iterate over all the machine-nodes: */
     2077    foreach (UIChooserNode *pNode, pParentGroup->nodes(UIChooserItemType_Machine))
     2078        if (UIChooserNodeMachine *pMachineNode = pNode->toMachineNode())
     2079            if (pMachineNode->accessible())
     2080                definitions[toOldStyleUuid(pMachineNode->id())] << pParentGroup->fullName();
     2081    /* Iterate over all the group-nodes: */
     2082    foreach (UIChooserNode *pNode, pParentGroup->nodes(UIChooserItemType_Group))
     2083        gatherGroupDefinitions(definitions, pNode);
    20472084}
    20482085
    20492086void UIChooserModel::gatherGroupOrders(QMap<QString, QStringList> &orders,
    2050                                        UIChooserItem *pParentItem)
     2087                                       UIChooserNode *pParentItem)
    20512088{
    20522089    /* Prepare extra-data key for current group: */
    20532090    const QString strExtraDataKey = pParentItem->fullName();
    2054     /* Iterate over all the global-items: */
    2055     foreach (UIChooserItem *pItem, pParentItem->items(UIChooserItemType_Global))
    2056     {
    2057         const QString strGlobalDescriptor(pItem->isFavorite() ? "nf" : "n");
     2091    /* Iterate over all the global-nodes: */
     2092    foreach (UIChooserNode *pNode, pParentItem->nodes(UIChooserItemType_Global))
     2093    {
     2094        const QString strGlobalDescriptor(pNode->isFavorite() ? "nf" : "n");
    20582095        orders[strExtraDataKey] << QString("%1=GLOBAL").arg(strGlobalDescriptor);
    20592096    }
    2060     /* Iterate over all the group-items: */
    2061     foreach (UIChooserItem *pItem, pParentItem->items(UIChooserItemType_Group))
    2062     {
    2063         const QString strGroupDescriptor(pItem->toGroupItem()->isOpened() ? "go" : "gc");
    2064         orders[strExtraDataKey] << QString("%1=%2").arg(strGroupDescriptor, pItem->name());
    2065         gatherGroupOrders(orders, pItem);
    2066     }
    2067     /* Iterate over all the machine-items: */
    2068     foreach (UIChooserItem *pItem, pParentItem->items(UIChooserItemType_Machine))
    2069         orders[strExtraDataKey] << QString("m=%1").arg(toOldStyleUuid(pItem->toMachineItem()->id()));
     2097    /* Iterate over all the group-nodes: */
     2098    foreach (UIChooserNode *pNode, pParentItem->nodes(UIChooserItemType_Group))
     2099    {
     2100        const QString strGroupDescriptor(pNode->toGroupNode()->isOpened() ? "go" : "gc");
     2101        orders[strExtraDataKey] << QString("%1=%2").arg(strGroupDescriptor, pNode->name());
     2102        gatherGroupOrders(orders, pNode);
     2103    }
     2104    /* Iterate over all the machine-nodes: */
     2105    foreach (UIChooserNode *pNode, pParentItem->nodes(UIChooserItemType_Machine))
     2106        orders[strExtraDataKey] << QString("m=%1").arg(toOldStyleUuid(pNode->toMachineNode()->id()));
    20702107}
    20712108
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.h

    r77605 r77638  
    4141class UIChooserHandlerKeyboard;
    4242class UIChooserItem;
     43class UIChooserNode;
    4344class UIVirtualMachineItem;
    4445class CMachine;
     
    188189    /** @name Children stuff.
    189190      * @{ */
     191        /** Returns invisible root node instance. */
     192        UIChooserNode *invisibleRoot() const;
     193
    190194        /** Returns the root instance. */
    191195        UIChooserItem *root() const;
     
    316320        /** Prepares scene. */
    317321        void prepareScene();
    318         /** Prepares root. */
    319         void prepareRoot();
    320322        /** Prepares lookup. */
    321323        void prepareLookup();
     
    337339        /** Cleanups lookup. */
    338340        void cleanupLookup();
    339         /** Cleanups root. */
    340         void cleanupRoot();
    341341        /** Cleanups scene. */
    342342        void cleanupScene();
     
    367367    /** @name Children stuff.
    368368      * @{ */
    369         /** Loads group tree. */
    370         void loadGroupTree();
     369        /** Loads tree. */
     370        void loadTree();
    371371        /** Adds machine item based on certain @a comMachine and optionally @a fMakeItVisible. */
    372372        void addMachineIntoTheTree(const CMachine &comMachine, bool fMakeItVisible = false);
    373         /** Acquires group item, creates one if necessary.
     373        /** Acquires group node, creates one if necessary.
    374374          * @param  strName           Brings the name of group we looking for.
    375           * @param  pParentItem       Brings the parent we starting to look for a group from.
     375          * @param  pParentNode       Brings the parent we starting to look for a group from.
    376376          * @param  fAllGroupsOpened  Brings whether we should open all the groups till the required one. */
    377         UIChooserItem *getGroupItem(const QString &strName, UIChooserItem *pParentItem, bool fAllGroupsOpened);
     377        UIChooserNode *getGroupNode(const QString &strName, UIChooserNode *pParentNode, bool fAllGroupsOpened);
    378378        /** Returns whether group with certain @a strName should be opened, searching starting from the passed @a pParentItem. */
    379         bool shouldBeGroupOpened(UIChooserItem *pParentItem, const QString &strName);
     379        bool shouldBeGroupOpened(UIChooserNode *pParentNode, const QString &strName);
    380380
    381381        /** Wipes out empty groups starting from @a pParentItem. */
    382         void wipeOutEmptyGroups(UIChooserItem *pParentItem);
    383 
    384         /** Returns whether global item within the @a pParentItem is favorite. */
    385         bool isGlobalItemFavorite(UIChooserItem *pParentItem) const;
    386 
    387         /** Acquires desired position for a child of @a pParentItem with specified @a enmType and @a strName. */
    388         int getDesiredPosition(UIChooserItem *pParentItem, UIChooserItemType enmType, const QString &strName);
    389         /** Acquires saved position for a child of @a pParentItem with specified @a enmType and @a strName. */
    390         int positionFromDefinitions(UIChooserItem *pParentItem, UIChooserItemType enmType, const QString &strName);
    391 
    392         /** Creates machine item based on certain @a comMachine as a child of specified @a pParentItem. */
    393         void createMachineItem(UIChooserItem *pParentItem, const CMachine &comMachine);
     382        void wipeOutEmptyGroups(UIChooserNode *pParentNode);
     383
     384        /** Returns whether global node within the @a pParentNode is favorite. */
     385        bool isGlobalNodeFavorite(UIChooserNode *pParentNode) const;
     386
     387        /** Acquires desired position for a child of @a pParentNode with specified @a enmType and @a strName. */
     388        int getDesiredPosition(UIChooserNode *pParentNode, UIChooserItemType enmType, const QString &strName);
     389        /** Acquires saved position for a child of @a pParentNode with specified @a enmType and @a strName. */
     390        int positionFromDefinitions(UIChooserNode *pParentNode, UIChooserItemType enmType, const QString &strName);
     391
     392        /** Creates machine node based on certain @a comMachine as a child of specified @a pParentNode. */
     393        void createMachineNode(UIChooserNode *pParentNode, const CMachine &comMachine);
     394
     395        /** Build tree for main root. */
     396        void buildTreeForMainRoot();
    394397
    395398        /** Removes machine @a items. */
     
    412415
    413416        /** Gathers group @a definitions of @a pParentGroup. */
    414         void gatherGroupDefinitions(QMap<QString, QStringList> &definitions, UIChooserItem *pParentGroup);
     417        void gatherGroupDefinitions(QMap<QString, QStringList> &definitions, UIChooserNode *pParentGroup);
    415418        /** Gathers group @a orders of @a pParentGroup. */
    416         void gatherGroupOrders(QMap<QString, QStringList> &orders, UIChooserItem *pParentItem);
     419        void gatherGroupOrders(QMap<QString, QStringList> &orders, UIChooserNode *pParentItem);
    417420
    418421        /** Makes sure group definitions saving is finished. */
     
    455458    /** @name Children stuff.
    456459      * @{ */
     460        /** Holds the invisible root node instance. */
     461        UIChooserNode  *m_pInvisibleRootNode;
     462
    457463        /** Holds the root instance. */
    458464        QPointer<UIChooserItem>  m_pRoot;
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNode.cpp

    r77636 r77638  
    3030}
    3131
     32UIChooserNode::~UIChooserNode()
     33{
     34    if (!m_pItem.isNull())
     35        delete m_pItem.data();
     36}
     37
    3238UIChooserNodeGroup *UIChooserNode::toGroupNode()
    3339{
     
    4450    return static_cast<UIChooserNodeMachine*>(this);
    4551}
     52
     53int UIChooserNode::position()
     54{
     55    return parentNode() ? parentNode()->positionOf(this) : 0;
     56}
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNode.h

    r77636 r77638  
    5050      * @param  fFavorite  Brings whether the node is favorite. */
    5151    UIChooserNode(UIChooserNode *pParent = 0, bool fFavorite = false);
     52    /** Destructs chooser node. */
     53    virtual ~UIChooserNode() /* override */;
    5254
    5355    /** Returns RTTI node type. */
     
    8082    virtual QString definition() const = 0;
    8183
     84    /** Returns whether there are children of certain @a enmType. */
     85    virtual bool hasNodes(UIChooserItemType enmType = UIChooserItemType_Any) const = 0;
     86    /** Returns a list of nodes of certain @a enmType. */
     87    virtual QList<UIChooserNode*> nodes(UIChooserItemType enmType = UIChooserItemType_Any) const = 0;
     88
     89    /** Adds passed @a pNode to specified @a iPosition. */
     90    virtual void addNode(UIChooserNode *pNode, int iPosition) = 0;
     91    /** Removes passed @a pNode. */
     92    virtual void removeNode(UIChooserNode *pNode) = 0;
     93
     94    /** Removes all children with specified @a uId recursively. */
     95    virtual void removeAllNodes(const QUuid &uId) = 0;
     96    /** Updates all children with specified @a uId recursively. */
     97    virtual void updateAllNodes(const QUuid &uId) = 0;
     98
     99    /** Returns node position. */
     100    int position();
     101    /** Returns position of specified node inside this one. */
     102    virtual int positionOf(UIChooserNode *pNode) = 0;
     103
    82104    /** Defines linked @a pItem. */
    83105    void setItem(UIChooserItem *pItem) { m_pItem = pItem; }
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNodeGlobal.cpp

    r77636 r77638  
    2525UIChooserNodeGlobal::UIChooserNodeGlobal(UIChooserNode *pParent,
    2626                                         bool fFavorite,
     27                                         int iPosition,
    2728                                         const QString &)
    2829    : UIChooserNode(pParent, fFavorite)
    2930{
     31    if (parentNode())
     32        parentNode()->addNode(this, iPosition);
    3033    retranslateUi();
     34}
     35
     36UIChooserNodeGlobal::UIChooserNodeGlobal(UIChooserNode *pParent,
     37                                         UIChooserNodeGlobal *pCopyFrom,
     38                                         int iPosition)
     39    : UIChooserNode(pParent, pCopyFrom->isFavorite())
     40{
     41    if (parentNode())
     42        parentNode()->addNode(this, iPosition);
     43    retranslateUi();
     44}
     45
     46UIChooserNodeGlobal::~UIChooserNodeGlobal()
     47{
     48    delete item();
     49    if (parentNode())
     50        parentNode()->removeNode(this);
    3151}
    3252
     
    5171}
    5272
     73bool UIChooserNodeGlobal::hasNodes(UIChooserItemType enmType) const
     74{
     75    Q_UNUSED(enmType);
     76    AssertFailedReturn(false);
     77}
     78
     79QList<UIChooserNode*> UIChooserNodeGlobal::nodes(UIChooserItemType enmType) const
     80{
     81    Q_UNUSED(enmType);
     82    AssertFailedReturn(QList<UIChooserNode*>());
     83}
     84
     85void UIChooserNodeGlobal::addNode(UIChooserNode *pNode, int iPosition)
     86{
     87    Q_UNUSED(pNode);
     88    Q_UNUSED(iPosition);
     89    AssertFailedReturnVoid();
     90}
     91
     92void UIChooserNodeGlobal::removeNode(UIChooserNode *pNode)
     93{
     94    Q_UNUSED(pNode);
     95    AssertFailedReturnVoid();
     96}
     97
     98void UIChooserNodeGlobal::removeAllNodes(const QUuid &)
     99{
     100    // Nothing to remove for global-node..
     101}
     102
     103void UIChooserNodeGlobal::updateAllNodes(const QUuid &)
     104{
     105    // Nothing to update for global-node..
     106
     107    /* Update global-item: */
     108    item()->updateItem();
     109}
     110
     111int UIChooserNodeGlobal::positionOf(UIChooserNode *pNode)
     112{
     113    Q_UNUSED(pNode);
     114    AssertFailedReturn(0);
     115}
     116
    53117void UIChooserNodeGlobal::retranslateUi()
    54118{
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNodeGlobal.h

    r77636 r77638  
    3535    /** Constructs chooser node passing @a pParent to the base-class.
    3636      * @param  fFavorite  Brings whether the node is favorite.
     37      * @param  iPosition  Brings the initial node position.
    3738      * @param  strTip     Brings the dummy tip. */
    3839    UIChooserNodeGlobal(UIChooserNode *pParent,
    3940                        bool fFavorite,
     41                        int iPosition,
    4042                        const QString &strTip);
     43    /** Constructs chooser node passing @a pParent to the base-class.
     44      * @param  pCopyFrom  Brings the node to copy data from.
     45      * @param  iPosition  Brings the initial node position. */
     46    UIChooserNodeGlobal(UIChooserNode *pParent,
     47                        UIChooserNodeGlobal *pCopyFrom,
     48                        int iPosition);
     49    /** Destructs chooser node. */
     50    virtual ~UIChooserNodeGlobal() /* override */;
    4151
    4252    /** Returns RTTI node type. */
     
    5161    /** Returns item definition. */
    5262    virtual QString definition() const /* override */;
     63
     64    /** Returns whether there are children of certain @a enmType. */
     65    virtual bool hasNodes(UIChooserItemType enmType) const /* override */;
     66    /** Returns a list of nodes of certain @a enmType. */
     67    virtual QList<UIChooserNode*> nodes(UIChooserItemType enmType) const /* override */;
     68
     69    /** Adds passed @a pNode to specified @a iPosition. */
     70    virtual void addNode(UIChooserNode *pNode, int iPosition) /* override */;
     71    /** Removes passed @a pNode. */
     72    virtual void removeNode(UIChooserNode *pNode) /* override */;
     73
     74    /** Removes all children with specified @a uId recursively. */
     75    virtual void removeAllNodes(const QUuid &uId) /* override */;
     76    /** Updates all children with specified @a uId recursively. */
     77    virtual void updateAllNodes(const QUuid &uId) /* override */;
     78
     79    /** Returns position of specified node inside this one. */
     80    virtual int positionOf(UIChooserNode *pNode) /* override */;
    5381
    5482protected:
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNodeGroup.cpp

    r77636 r77638  
    2424UIChooserNodeGroup::UIChooserNodeGroup(UIChooserNode *pParent,
    2525                                       bool fFavorite,
     26                                       int iPosition,
    2627                                       const QString &strName,
    2728                                       bool fOpened)
     
    3031    , m_fOpened(fOpened)
    3132{
     33    if (parentNode())
     34        parentNode()->addNode(this, iPosition);
    3235    retranslateUi();
     36}
     37
     38UIChooserNodeGroup::UIChooserNodeGroup(UIChooserNode *pParent,
     39                                       UIChooserNodeGroup *pCopyFrom,
     40                                       int iPosition)
     41    : UIChooserNode(pParent, pCopyFrom->isFavorite())
     42    , m_strName(pCopyFrom->name())
     43    , m_fOpened(pCopyFrom->isOpened())
     44{
     45    if (parentNode())
     46        parentNode()->addNode(this, iPosition);
     47    copyContents(pCopyFrom);
     48    retranslateUi();
     49}
     50
     51UIChooserNodeGroup::~UIChooserNodeGroup()
     52{
     53    /* Cleanup groups first, that
     54     * gives us proper recursion: */
     55    while (!m_nodesGroup.isEmpty())
     56        delete m_nodesGroup.last();
     57    while (!m_nodesGlobal.isEmpty())
     58        delete m_nodesGlobal.last();
     59    while (!m_nodesMachine.isEmpty())
     60        delete m_nodesMachine.last();
     61    delete item();
     62    if (parentNode())
     63        parentNode()->removeNode(this);
    3364}
    3465
     
    6192}
    6293
     94bool UIChooserNodeGroup::hasNodes(UIChooserItemType enmType) const
     95{
     96    switch (enmType)
     97    {
     98        case UIChooserItemType_Any:
     99            return hasNodes(UIChooserItemType_Group) || hasNodes(UIChooserItemType_Global) || hasNodes(UIChooserItemType_Machine);
     100        case UIChooserItemType_Group:
     101            return !m_nodesGroup.isEmpty();
     102        case UIChooserItemType_Global:
     103            return !m_nodesGlobal.isEmpty();
     104        case UIChooserItemType_Machine:
     105            return !m_nodesMachine.isEmpty();
     106    }
     107    return false;
     108}
     109
     110QList<UIChooserNode*> UIChooserNodeGroup::nodes(UIChooserItemType enmType) const
     111{
     112    switch (enmType)
     113    {
     114        case UIChooserItemType_Any:     return m_nodesGlobal + m_nodesGroup + m_nodesMachine;
     115        case UIChooserItemType_Group:   return m_nodesGroup;
     116        case UIChooserItemType_Global:  return m_nodesGlobal;
     117        case UIChooserItemType_Machine: return m_nodesMachine;
     118    }
     119    AssertFailedReturn(QList<UIChooserNode*>());
     120}
     121
     122void UIChooserNodeGroup::addNode(UIChooserNode *pNode, int iPosition)
     123{
     124    switch (pNode->type())
     125    {
     126        case UIChooserItemType_Group:   m_nodesGroup.insert(iPosition, pNode); return;
     127        case UIChooserItemType_Global:  m_nodesGlobal.insert(iPosition, pNode); return;
     128        case UIChooserItemType_Machine: m_nodesMachine.insert(iPosition, pNode); return;
     129        default: break;
     130    }
     131    AssertFailedReturnVoid();
     132}
     133
     134void UIChooserNodeGroup::removeNode(UIChooserNode *pNode)
     135{
     136    switch (pNode->type())
     137    {
     138        case UIChooserItemType_Group:   m_nodesGroup.removeAll(pNode); return;
     139        case UIChooserItemType_Global:  m_nodesGlobal.removeAll(pNode); return;
     140        case UIChooserItemType_Machine: m_nodesMachine.removeAll(pNode); return;
     141        default: break;
     142    }
     143    AssertFailedReturnVoid();
     144}
     145
     146void UIChooserNodeGroup::removeAllNodes(const QUuid &uId)
     147{
     148    foreach (UIChooserNode *pNode, nodes())
     149        pNode->removeAllNodes(uId);
     150}
     151
     152void UIChooserNodeGroup::updateAllNodes(const QUuid &uId)
     153{
     154    // Nothing to update for group-node..
     155
     156    /* Update group-item: */
     157    item()->updateItem();
     158
     159    /* Update all the children recursively: */
     160    foreach (UIChooserNode *pNode, nodes())
     161        pNode->updateAllNodes(uId);
     162}
     163
     164int UIChooserNodeGroup::positionOf(UIChooserNode *pNode)
     165{
     166    switch (pNode->type())
     167    {
     168        case UIChooserItemType_Group:   return m_nodesGroup.indexOf(pNode->toGroupNode());
     169        case UIChooserItemType_Global:  return m_nodesGlobal.indexOf(pNode->toGlobalNode());
     170        case UIChooserItemType_Machine: return m_nodesMachine.indexOf(pNode->toMachineNode());
     171        default: break;
     172    }
     173    AssertFailedReturn(0);
     174}
     175
    63176void UIChooserNodeGroup::setName(const QString &strName)
    64177{
     
    84197        item()->updateItem();
    85198}
     199
     200void UIChooserNodeGroup::copyContents(UIChooserNodeGroup *pCopyFrom)
     201{
     202    foreach (UIChooserNode *pNode, pCopyFrom->nodes(UIChooserItemType_Group))
     203        new UIChooserNodeGroup(this, pNode->toGroupNode(), m_nodesGroup.size());
     204    foreach (UIChooserNode *pNode, pCopyFrom->nodes(UIChooserItemType_Global))
     205        new UIChooserNodeGlobal(this, pNode->toGlobalNode(), m_nodesGlobal.size());
     206    foreach (UIChooserNode *pNode, pCopyFrom->nodes(UIChooserItemType_Machine))
     207        new UIChooserNodeMachine(this, pNode->toMachineNode(), m_nodesMachine.size());
     208}
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNodeGroup.h

    r77636 r77638  
    3535    /** Constructs chooser node passing @a pParent to the base-class.
    3636      * @param  fFavorite  Brings whether the node is favorite.
     37      * @param  iPosition  Brings the initial node position.
    3738      * @param  strName    Brings current node name.
    3839      * @param  fOpened    Brings whether this group node is opened. */
    3940    UIChooserNodeGroup(UIChooserNode *pParent,
    4041                       bool fFavorite,
     42                       int iPosition,
    4143                       const QString &strName,
    4244                       bool fOpened);
     45    /** Constructs chooser node passing @a pParent to the base-class.
     46      * @param  pCopyFrom  Brings the node to copy data from.
     47      * @param  iPosition  Brings the initial node position. */
     48    UIChooserNodeGroup(UIChooserNode *pParent,
     49                       UIChooserNodeGroup *pCopyFrom,
     50                       int iPosition);
     51    /** Destructs chooser node removing it's children. */
     52    virtual ~UIChooserNodeGroup() /* override */;
    4353
    4454    /** Returns RTTI node type. */
     
    5363    /** Returns item definition. */
    5464    virtual QString definition() const /* override */;
     65
     66    /** Returns whether there are children of certain @a enmType. */
     67    virtual bool hasNodes(UIChooserItemType enmType) const /* override */;
     68    /** Returns a list of nodes of certain @a enmType. */
     69    virtual QList<UIChooserNode*> nodes(UIChooserItemType enmType) const /* override */;
     70
     71    /** Adds passed @a pNode to specified @a iPosition. */
     72    virtual void addNode(UIChooserNode *pNode, int iPosition) /* override */;
     73    /** Removes passed @a pNode. */
     74    virtual void removeNode(UIChooserNode *pNode) /* override */;
     75
     76    /** Removes all children with specified @a uId recursively. */
     77    virtual void removeAllNodes(const QUuid &uId) /* override */;
     78    /** Updates all children with specified @a uId recursively. */
     79    virtual void updateAllNodes(const QUuid &uId) /* override */;
     80
     81    /** Returns position of specified node inside this one. */
     82    virtual int positionOf(UIChooserNode *pNode) /* override */;
    5583
    5684    /** Defines node @a strName. */
     
    74102private:
    75103
     104    /** Copies children contents from @a pCopyFrom item. */
     105    void copyContents(UIChooserNodeGroup *pCopyFrom);
     106
    76107    /** Holds the node name. */
    77108    QString  m_strName;
    78109    /** Holds whether node is opened. */
    79110    bool     m_fOpened;
     111
     112    /** Holds group children. */
     113    QList<UIChooserNode*>  m_nodesGroup;
     114    /** Holds global children. */
     115    QList<UIChooserNode*>  m_nodesGlobal;
     116    /** Holds machine children. */
     117    QList<UIChooserNode*>  m_nodesMachine;
    80118};
    81119
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNodeMachine.cpp

    r77636 r77638  
    1616 */
    1717
    18 /* Qt includes */
    19 //#include <QUuid>
    20 
    2118/* GUI includes: */
    2219#include "UIChooserNodeMachine.h"
     
    2522UIChooserNodeMachine::UIChooserNodeMachine(UIChooserNode *pParent,
    2623                                           bool fFavorite,
     24                                           int  iPosition,
    2725                                           const CMachine &comMachine)
    2826    : UIChooserNode(pParent, fFavorite)
    2927    , UIVirtualMachineItem(comMachine)
    3028{
     29    if (parentNode())
     30        parentNode()->addNode(this, iPosition);
    3131    retranslateUi();
     32}
     33
     34UIChooserNodeMachine::UIChooserNodeMachine(UIChooserNode *pParent,
     35                                           UIChooserNodeMachine *pCopyFrom,
     36                                           int iPosition)
     37    : UIChooserNode(pParent, pCopyFrom->isFavorite())
     38    , UIVirtualMachineItem(pCopyFrom->machine())
     39{
     40    if (parentNode())
     41        parentNode()->addNode(this, iPosition);
     42    retranslateUi();
     43}
     44
     45UIChooserNodeMachine::~UIChooserNodeMachine()
     46{
     47    delete item();
     48    if (parentNode())
     49        parentNode()->removeNode(this);
    3250}
    3351
     
    5876}
    5977
     78bool UIChooserNodeMachine::hasNodes(UIChooserItemType enmType) const
     79{
     80    Q_UNUSED(enmType);
     81    AssertFailedReturn(false);
     82}
     83
     84QList<UIChooserNode*> UIChooserNodeMachine::nodes(UIChooserItemType enmType) const
     85{
     86    Q_UNUSED(enmType);
     87    AssertFailedReturn(QList<UIChooserNode*>());
     88}
     89
     90void UIChooserNodeMachine::addNode(UIChooserNode *pNode, int iPosition)
     91{
     92    Q_UNUSED(pNode);
     93    Q_UNUSED(iPosition);
     94    AssertFailedReturnVoid();
     95}
     96
     97void UIChooserNodeMachine::removeNode(UIChooserNode *pNode)
     98{
     99    Q_UNUSED(pNode);
     100    AssertFailedReturnVoid();
     101}
     102
     103void UIChooserNodeMachine::removeAllNodes(const QUuid &uId)
     104{
     105    /* Skip other ids: */
     106    if (id() != uId)
     107        return;
     108
     109    /* Remove this node: */
     110    delete this;
     111}
     112
     113void UIChooserNodeMachine::updateAllNodes(const QUuid &uId)
     114{
     115    /* Skip other ids: */
     116    if (id() != uId)
     117        return;
     118
     119    /* Update machine-node: */
     120    recache();
     121
     122    /* Update machine-item: */
     123    if (item())
     124        item()->updateItem();
     125}
     126
     127int UIChooserNodeMachine::positionOf(UIChooserNode *pNode)
     128{
     129    Q_UNUSED(pNode);
     130    AssertFailedReturn(0);
     131}
     132
    60133void UIChooserNodeMachine::retranslateUi()
    61134{
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNodeMachine.h

    r77636 r77638  
    3636    /** Constructs chooser node passing @a pParent to the base-class.
    3737      * @param  fFavorite   Brings whether the node is favorite.
     38      * @param  iPosition   Brings the initial node position.
    3839      * @param  comMachine  Brings COM machine object. */
    3940    UIChooserNodeMachine(UIChooserNode *pParent,
    4041                         bool fFavorite,
     42                         int iPosition,
    4143                         const CMachine &comMachine);
     44    /** Constructs chooser node passing @a pParent to the base-class.
     45      * @param  pCopyFrom  Brings the node to copy data from.
     46      * @param  iPosition  Brings the initial node position. */
     47    UIChooserNodeMachine(UIChooserNode *pParent,
     48                         UIChooserNodeMachine *pCopyFrom,
     49                         int iPosition);
     50    /** Destructs chooser node. */
     51    virtual ~UIChooserNodeMachine() /* override */;
    4252
    4353    /** Returns RTTI node type. */
     
    5363    virtual QString definition() const /* override */;
    5464
     65    /** Returns whether there are children of certain @a enmType. */
     66    virtual bool hasNodes(UIChooserItemType enmType) const /* override */;
     67    /** Returns a list of nodes of certain @a enmType. */
     68    virtual QList<UIChooserNode*> nodes(UIChooserItemType enmType) const /* override */;
     69
     70    /** Adds passed @a pNode to specified @a iPosition. */
     71    virtual void addNode(UIChooserNode *pNode, int iPosition) /* override */;
     72    /** Removes passed @a pNode. */
     73    virtual void removeNode(UIChooserNode *pNode) /* override */;
     74
     75    /** Removes all children with specified @a uId recursively. */
     76    virtual void removeAllNodes(const QUuid &uId) /* override */;
     77    /** Updates all children with specified @a uId recursively. */
     78    virtual void updateAllNodes(const QUuid &uId) /* override */;
     79
     80    /** Returns position of specified node inside this one. */
     81    virtual int positionOf(UIChooserNode *pNode) /* override */;
     82
    5583protected:
    5684
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