Changeset 77638 in vbox
- Timestamp:
- Mar 10, 2019 7:21:30 PM (6 years ago)
- 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 323 323 void UIChooserHandlerKeyboard::shift(UIItemShiftDirection direction, UIItemShiftSize size) const 324 324 { 325 Q_UNUSED(direction); 326 Q_UNUSED(size); 327 /// @todo implement item shifting 328 329 #if 0 325 330 /* Get focus-item and his parent: */ 326 331 UIChooserItem *pFocusItem = model()->focusItem(); … … 372 377 model()->updateNavigation(); 373 378 model()->updateLayout(); 374 } 375 379 #endif 380 } 381 -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItem.cpp
r77636 r77638 296 296 } 297 297 298 UIChooserItem::~UIChooserItem()299 {300 delete node();301 }302 303 298 UIChooserItemGroup *UIChooserItem::toGroupItem() 304 299 { … … 369 364 if (m_pParent) 370 365 m_pParent->toGroupItem()->updateFavorites(); 366 } 367 368 int UIChooserItem::position() const 369 { 370 return node()->position(); 371 371 } 372 372 -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItem.h
r77636 r77638 81 81 UIChooserItem(UIChooserItem *pParent, UIChooserNode *pNode, 82 82 int iDefaultValue = 100, int iHoveredValue = 90); 83 /** Destructs item. */84 virtual ~UIChooserItem() /* override */;85 83 86 84 /** @name Item stuff. … … 120 118 virtual void setFavorite(bool fFavorite); 121 119 120 /** Returns item position. */ 121 int position() const; 122 122 123 /** Returns a level of item. */ 123 124 int level() const; … … 145 146 /** @name Children stuff. 146 147 * @{ */ 147 /** Returns whether there are children items of certain @a enmType. */148 virtual bool hasItems(UIChooserItemType enmType = UIChooserItemType_Any) const = 0;149 148 /** Returns children items of certain @a enmType. */ 150 149 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;156 150 157 151 /** Adds possible @a fFavorite child @a pItem to certain @a iPosition. */ … … 159 153 /** Removes child @a pItem. */ 160 154 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;166 155 167 156 /** 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 33 33 34 34 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) 35 UIChooserItemGlobal::UIChooserItemGlobal(UIChooserItem *pParent, UIChooserNodeGlobal *pNode) 36 : UIChooserItem(pParent, pNode, 0, 100) 40 37 , m_iDefaultLightnessMin(0) 41 38 , m_iDefaultLightnessMax(0) … … 47 44 , m_iMaximumNameWidth(0) 48 45 , 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())68 46 { 69 47 prepare(); … … 212 190 } 213 191 214 bool UIChooserItemGlobal::hasItems(UIChooserItemType) const215 {216 AssertMsgFailedReturn(("Global graphics item do NOT support children!"), false);217 }218 219 192 QList<UIChooserItem*> UIChooserItemGlobal::items(UIChooserItemType) const 220 193 { … … 222 195 } 223 196 224 void UIChooserItemGlobal:: setItems(const QList<UIChooserItem*> &, UIChooserItemType)197 void UIChooserItemGlobal::addItem(UIChooserItem *, bool, int) 225 198 { 226 199 AssertMsgFailed(("Global graphics item do NOT support children!")); 227 200 } 228 201 229 void UIChooserItemGlobal:: clearItems(UIChooserItemType)202 void UIChooserItemGlobal::removeItem(UIChooserItem *) 230 203 { 231 204 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 ..252 205 } 253 206 … … 403 356 /* Add item to the parent: */ 404 357 AssertPtrReturnVoid(parentItem()); 405 parentItem()->addItem(this, isFavorite(), m_iPosition);358 parentItem()->addItem(this, isFavorite(), position()); 406 359 407 360 /* Configure connections: */ -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGlobal.h
r77636 r77638 25 25 #include "UIChooserItem.h" 26 26 27 /* Forward declarations: */ 28 class UIChooserNodeGlobal; 29 27 30 28 31 /** UIChooserItem extension implementing global item. */ … … 36 39 enum { Type = UIChooserItemType_Global }; 37 40 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); 42 43 /** Destructs global item. */ 43 44 virtual ~UIChooserItemGlobal() /* override */; … … 98 99 /** @name Children stuff. 99 100 * @{ */ 100 /** Returns whether there are children items of certain @a enmType. */101 virtual bool hasItems(UIChooserItemType enmType = UIChooserItemType_Any) const /* override */;102 101 /** Returns children items of certain @a enmType. */ 103 102 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 */;109 103 110 104 /** Adds possible @a fFavorite child @a pItem to certain @a iPosition. */ … … 112 106 /** Removes child @a pItem. */ 113 107 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 */;119 108 120 109 /** Searches for a first child item answering to specified @a strSearchTag and @a iItemSearchFlags. */ … … 228 217 /** @name Item stuff. 229 218 * @{ */ 230 /** Holds initial item position. */231 const int m_iPosition;232 233 219 /** Holds item minimum default lightness. */ 234 220 int m_iDefaultLightnessMin; -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGroup.cpp
r77636 r77638 38 38 #include "UIIconPool.h" 39 39 #include "UIVirtualBoxManager.h" 40 #include "UIVirtualMachineItem.h"41 40 42 41 … … 45 44 *********************************************************************************************************************************/ 46 45 47 UIChooserItemGroup::UIChooserItemGroup(QGraphicsScene *pScene) 48 : UIChooserItem(0, new UIChooserNodeGroup(0 /* parent */, 49 false /* favorite? */, 50 QString() /* name */, 51 true /* opened? */)) 46 UIChooserItemGroup::UIChooserItemGroup(QGraphicsScene *pScene, UIChooserNodeGroup *pNode) 47 : UIChooserItem(0, pNode) 52 48 , m_pScene(pScene) 53 , m_pItemToCopy(0)54 , m_iPosition(0)55 49 , m_iAdditionalHeight(0) 56 50 , m_iHeaderDarkness(110) … … 71 65 } 72 66 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)) 67 UIChooserItemGroup::UIChooserItemGroup(UIChooserItem *pParent, UIChooserNodeGroup *pNode) 68 : UIChooserItem(pParent, pNode) 81 69 , m_pScene(0) 82 , m_pItemToCopy(0)83 , m_iPosition(iPosition)84 70 , m_iAdditionalHeight(0) 85 71 , m_iHeaderDarkness(110) … … 100 86 } 101 87 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 130 88 UIChooserItemGroup::~UIChooserItemGroup() 131 89 { … … 384 342 } 385 343 386 bool UIChooserItemGroup::hasItems(UIChooserItemType type /* = UIChooserItemType_Any */) const387 {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 402 344 QList<UIChooserItem*> UIChooserItemGroup::items(UIChooserItemType type /* = UIChooserItemType_Any */) const 403 345 { … … 411 353 } 412 354 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();469 355 } 470 356 … … 576 462 } 577 463 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 595 464 UIChooserItem* UIChooserItemGroup::searchForItem(const QString &strSearchTag, int iItemSearchFlags) 596 465 { … … 632 501 { 633 502 /* If this group-item have at least one machine-item: */ 634 if ( hasItems(UIChooserItemType_Machine))503 if (node()->hasNodes(UIChooserItemType_Machine)) 635 504 /* Return the first machine-item: */ 636 505 return items(UIChooserItemType_Machine).first()->firstMachineItem(); 637 506 /* If this group-item have at least one group-item: */ 638 else if ( hasItems(UIChooserItemType_Group))507 else if (node()->hasNodes(UIChooserItemType_Group)) 639 508 /* Return the first machine-item of the first group-item: */ 640 509 return items(UIChooserItemType_Group).first()->firstMachineItem(); … … 645 514 void UIChooserItemGroup::sortItems() 646 515 { 516 /// @todo implement manual sorting 517 518 #if 0 647 519 /* Sort group-items: */ 648 520 QMap<QString, UIChooserItem*> sorter; … … 656 528 sorter.insert(pItem->name().toLower(), pItem); 657 529 setItems(sorter.values(), UIChooserItemType_Machine); 530 #endif 658 531 659 532 /* Update model: */ … … 920 793 const UIChooserItemMimeData *pCastedMime = qobject_cast<const UIChooserItemMimeData*>(pMime); 921 794 AssertMsg(pCastedMime, ("Can't cast passed mime-data to UIChooserItemMimeData!")); 922 UIChooser Item *pItem = pCastedMime->item();795 UIChooserNode *pNode = pCastedMime->item()->node(); 923 796 924 797 /* Check if we have position information: */ … … 937 810 938 811 /* 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); 940 814 if (isClosed()) 941 815 open(false); … … 945 819 { 946 820 /* Delete passed item: */ 947 delete p Item;821 delete pNode; 948 822 } 949 823 … … 973 847 const UIChooserItemMimeData *pCastedMime = qobject_cast<const UIChooserItemMimeData*>(pMime); 974 848 AssertMsg(pCastedMime, ("Can't cast passed mime-data to UIChooserItemMimeData!")); 975 UIChooser Item *pItem = pCastedMime->item();849 UIChooserNode *pNode = pCastedMime->item()->node(); 976 850 977 851 /* Check if we have position information: */ … … 990 864 991 865 /* 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); 993 868 if (isClosed()) 994 869 open(false); … … 998 873 { 999 874 /* Delete passed item: */ 1000 delete p Item;875 delete pNode; 1001 876 } 1002 877 … … 1265 1140 * it will be added to the scene indirectly: */ 1266 1141 else if (parentItem()) 1267 parentItem()->addItem(this, isFavorite(), m_iPosition);1142 parentItem()->addItem(this, isFavorite(), position()); 1268 1143 /* Otherwise sombody forgot to pass scene or parent. */ 1269 1144 else 1270 1145 AssertFailedReturnVoid(); 1271 1146 1272 /* Copy item contents if any: */ 1273 if (m_pItemToCopy) 1274 copyContent(m_pItemToCopy, this); 1147 /* Copy contents: */ 1148 copyContents(node()->toGroupNode()); 1275 1149 1276 1150 /* Apply language settings: */ … … 1310 1184 1311 1185 /* 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(); } 1313 1189 1314 1190 /* If that item is focused: */ … … 1389 1265 } 1390 1266 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()); 1267 void 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()); 1403 1275 } 1404 1276 … … 1478 1350 { 1479 1351 /* Main root-item always takes body into account: */ 1480 if ( hasItems())1352 if (node()->hasNodes()) 1481 1353 { 1482 1354 /* We have to take maximum children width into account: */ … … 1520 1392 { 1521 1393 /* Main root-item always takes body into account: */ 1522 if ( hasItems())1394 if (node()->hasNodes()) 1523 1395 { 1524 1396 /* We have to take maximum children height into account: */ -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGroup.h
r77636 r77638 28 28 class QGraphicsLinearLayout; 29 29 class QLineEdit; 30 class UIChooserNodeGroup; 30 31 class UIEditorGroupRename; 31 32 class UIGraphicsButton; … … 55 56 enum { Type = UIChooserItemType_Group }; 56 57 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); 63 62 /** Destructs group item. */ 64 63 virtual ~UIChooserItemGroup() /* override */; … … 130 129 /** @name Children stuff. 131 130 * @{ */ 132 /** Returns whether there are children items of certain @a enmType. */133 virtual bool hasItems(UIChooserItemType enmType = UIChooserItemType_Any) const /* override */;134 131 /** Returns children items of certain @a enmType. */ 135 132 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 */;141 133 142 134 /** Adds possible @a fFavorite child @a pItem to certain @a iPosition. */ … … 144 136 /** Removes child @a pItem. */ 145 137 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 */;151 138 152 139 /** Searches for a first child item answering to specified @a strSearchTag and @a iItemSearchFlags. */ … … 266 253 /** @name Children stuff. 267 254 * @{ */ 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); 270 257 271 258 /** Returns whether group contains machine with @a uId. */ … … 310 297 * @{ */ 311 298 /** 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; 317 300 318 301 /** Holds the cached visible name. */ -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemMachine.cpp
r77636 r77638 27 27 #include "UIChooserItemMachine.h" 28 28 #include "UIChooserModel.h" 29 #include "UIChooserNodeGroup.h" 29 30 #include "UIChooserNodeMachine.h" 30 31 #include "UIIconPool.h" … … 35 36 36 37 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) 38 UIChooserItemMachine::UIChooserItemMachine(UIChooserItem *pParent, UIChooserNodeMachine *pNode) 39 : UIChooserItem(pParent, pNode, 0, 100) 42 40 , m_iDefaultLightnessMin(0) 43 41 , m_iDefaultLightnessMax(0) … … 55 53 } 56 54 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 77 55 UIChooserItemMachine::~UIChooserItemMachine() 78 56 { 79 57 cleanup(); 80 }81 82 CMachine UIChooserItemMachine::machine() const83 {84 return node()->toMachineNode()->machine();85 58 } 86 59 … … 249 222 } 250 223 251 bool UIChooserItemMachine::hasItems(UIChooserItemType) const252 {253 AssertMsgFailed(("Machine graphics item do NOT support children!"));254 return false;255 }256 257 224 QList<UIChooserItem*> UIChooserItemMachine::items(UIChooserItemType) const 258 225 { … … 261 228 } 262 229 263 void UIChooserItemMachine:: setItems(const QList<UIChooserItem*>&, UIChooserItemType)230 void UIChooserItemMachine::addItem(UIChooserItem*, bool, int) 264 231 { 265 232 AssertMsgFailed(("Machine graphics item do NOT support children!")); 266 233 } 267 234 268 void UIChooserItemMachine:: clearItems(UIChooserItemType)235 void UIChooserItemMachine::removeItem(UIChooserItem*) 269 236 { 270 237 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;308 238 } 309 239 … … 488 418 const UIChooserItemMimeData *pCastedMime = qobject_cast<const UIChooserItemMimeData*>(pMime); 489 419 AssertMsg(pCastedMime, ("Can't cast passed mime-data to UIChooserItemMimeData!")); 490 UIChooser Item *pItem = pCastedMime->item();420 UIChooserNode *pNode = pCastedMime->item()->node(); 491 421 492 422 /* 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(), 494 426 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); 498 437 499 438 /* If proposed action is 'move': */ 500 439 if (pEvent->proposedAction() == Qt::MoveAction) 501 440 { 502 /* Delete passed item: */503 delete p Item;441 /* Delete passed node: */ 442 delete pNode; 504 443 } 505 /* Delete this item: */506 delete this;444 /* Delete this node: */ 445 delete node(); 507 446 508 447 /* Update model: */ … … 576 515 /* Add item to the parent: */ 577 516 AssertPtrReturnVoid(parentItem()); 578 parentItem()->addItem(this, isFavorite(), m_iPosition);517 parentItem()->addItem(this, isFavorite(), position()); 579 518 580 519 /* Configure connections: */ -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemMachine.h
r77636 r77638 25 25 #include "UIChooserItem.h" 26 26 27 /* COM includes: */ 28 #include "COMEnums.h" 29 #include "CMachine.h" 27 /* Forward declarations: */ 28 class UIChooserNodeMachine; 30 29 31 30 … … 40 39 enum { Type = UIChooserItemType_Machine }; 41 40 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); 46 43 /** Destructs machine item. */ 47 44 virtual ~UIChooserItemMachine() /* override */; … … 49 46 /** @name Item stuff. 50 47 * @{ */ 51 /** Returns item machine. */52 CMachine machine() const;53 48 /** Returns item machine id. */ 54 49 QUuid id() const; … … 112 107 /** @name Children stuff. 113 108 * @{ */ 114 /** Returns whether there are children items of certain @a enmType. */115 virtual bool hasItems(UIChooserItemType enmType = UIChooserItemType_Any) const /* override */;116 109 /** Returns children items of certain @a enmType. */ 117 110 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 */;123 111 124 112 /** Adds possible @a fFavorite child @a pItem to certain @a iPosition. */ … … 126 114 /** Removes child @a pItem. */ 127 115 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 */;133 116 134 117 /** Searches for a first child item answering to specified @a strSearchTag and @a iItemSearchFlags. */ … … 270 253 /** @name Item stuff. 271 254 * @{ */ 272 /** Holds initial item position. */273 const int m_iPosition;274 275 255 /** Holds item minimum default lightness. */ 276 256 int m_iDefaultLightnessMin; -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.cpp
r77636 r77638 37 37 #include "UIChooserNode.h" 38 38 #include "UIChooserNodeGroup.h" 39 #include "UIChooserNodeGlobal.h" 39 40 #include "UIChooserNodeMachine.h" 40 41 #include "UIExtraDataManager.h" … … 66 67 , m_pContextMenuGroup(0) 67 68 , m_pContextMenuMachine(0) 69 , m_pInvisibleRootNode(0) 68 70 , m_iScrollingTokenSize(30) 69 71 , m_fIsScrollingInProgress(false) … … 80 82 void UIChooserModel::init() 81 83 { 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(); 88 89 updateNavigation(); 89 90 updateLayout(); … … 107 108 makeSureGroupDefinitionsSaveIsFinished(); 108 109 makeSureGroupOrdersSaveIsFinished(); 110 111 /* Unset current items: */ 112 unsetCurrentItems(); 113 114 /* Delete tree: */ 115 delete m_pInvisibleRootNode; 116 m_pInvisibleRootNode = 0; 109 117 } 110 118 … … 288 296 /* Return first machine-item of the current-item: */ 289 297 return currentItem() && currentItem()->firstMachineItem() && currentItem()->firstMachineItem()->node() 290 ? currentItem()->firstMachineItem()-> toMachineItem()->node()->toMachineNode()298 ? currentItem()->firstMachineItem()->node()->toMachineNode() 291 299 : 0; 292 300 } … … 443 451 } 444 452 453 UIChooserNode *UIChooserModel::invisibleRoot() const 454 { 455 return m_pInvisibleRootNode; 456 } 457 445 458 UIChooserItem *UIChooserModel::root() const 446 459 { … … 455 468 void UIChooserModel::wipeOutEmptyGroups() 456 469 { 457 wipeOutEmptyGroups( root());470 wipeOutEmptyGroups(invisibleRoot()); 458 471 } 459 472 … … 663 676 void UIChooserModel::sltMachineStateChanged(const QUuid &uId, const KMachineState) 664 677 { 665 /* Update machine- items with passed id: */666 root()->updateAllItems(uId);678 /* Update machine-nodes with passed id: */ 679 invisibleRoot()->updateAllNodes(uId); 667 680 } 668 681 669 682 void UIChooserModel::sltMachineDataChanged(const QUuid &uId) 670 683 { 671 /* Update machine- items with passed id: */672 root()->updateAllItems(uId);684 /* Update machine-nodes with passed id: */ 685 invisibleRoot()->updateAllNodes(uId); 673 686 } 674 687 … … 685 698 addMachineIntoTheTree(comMachine, true /* make it visible */); 686 699 687 /* And update model: */ 700 /* Rebuild tree for main root: */ 701 buildTreeForMainRoot(); 688 702 updateNavigation(); 689 703 updateLayout(); … … 699 713 { 700 714 /* Remove machine-items with passed id: */ 701 root()->removeAllItems(uId.toString());702 /* Update model: */715 invisibleRoot()->removeAllNodes(uId.toString()); 716 /* Wipe out empty groups: */ 703 717 wipeOutEmptyGroups(); 704 718 705 /* And update model: */ 719 /* Rebuild tree for main root: */ 720 buildTreeForMainRoot(); 706 721 updateNavigation(); 707 722 updateLayout(); … … 720 735 void UIChooserModel::sltSessionStateChanged(const QUuid &uId, const KSessionState) 721 736 { 722 /* Update machine- items with passed id: */723 root()->updateAllItems(uId);737 /* Update machine-nodes with passed id: */ 738 invisibleRoot()->updateAllNodes(uId); 724 739 } 725 740 726 741 void UIChooserModel::sltSnapshotChanged(const QUuid &uId, const QUuid &) 727 742 { 728 /* Update machine- items with passed id: */729 root()->updateAllItems(uId);743 /* Update machine-nodes with passed id: */ 744 invisibleRoot()->updateAllNodes(uId); 730 745 } 731 746 … … 774 789 /* Check if we have collisions with our siblings: */ 775 790 UIChooserItem *pFocusItem = focusItem(); 791 UIChooserNode *pFocusNode = pFocusItem->node(); 776 792 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) 786 803 pCollisionSibling = pSibling; 787 804 if (pCollisionSibling) 788 805 { 789 if (p Item->type() == UIChooserItemType_Machine)806 if (pNode->type() == UIChooserItemType_Machine) 790 807 { 791 808 if (pCollisionSibling->type() == UIChooserItemType_Machine) 792 toBeRemoved << p Item;809 toBeRemoved << pNode; 793 810 else if (pCollisionSibling->type() == UIChooserItemType_Group) 794 811 { 795 msgCenter().cannotResolveCollisionAutomatically(strItemName, pParent Item->name());812 msgCenter().cannotResolveCollisionAutomatically(strItemName, pParentNode->name()); 796 813 return; 797 814 } 798 815 } 799 else if (p Item->type() == UIChooserItemType_Group)816 else if (pNode->type() == UIChooserItemType_Group) 800 817 { 801 if (msgCenter().confirmAutomaticCollisionResolve(strItemName, pParent Item->name()))802 toBeRenamed << p Item;818 if (msgCenter().confirmAutomaticCollisionResolve(strItemName, pParentNode->name())) 819 toBeRenamed << pNode; 803 820 else 804 821 return; … … 809 826 /* Copy all the children into our parent: */ 810 827 QList<UIChooserItem*> copiedItems; 811 foreach (UIChooser Item *pItem, pFocusItem->items())812 { 813 if (toBeRemoved.contains(p Item))828 foreach (UIChooserNode *pNode, pFocusNode->nodes()) 829 { 830 if (toBeRemoved.contains(pNode)) 814 831 continue; 815 switch (p Item->type())832 switch (pNode->type()) 816 833 { 817 834 case UIChooserItemType_Group: 818 835 { 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)); 822 842 copiedItems << pGroupItem; 823 843 break; … … 825 845 case UIChooserItemType_Machine: 826 846 { 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); 828 851 copiedItems << pMachineItem; 829 852 break; … … 835 858 836 859 /* Delete focus group: */ 837 delete focusItem();860 delete pFocusNode; 838 861 839 862 /* Notify about selection invalidated: */ … … 897 920 return; 898 921 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); 901 929 902 930 /* Enumerate all the currently chosen items: */ … … 917 945 busyGroupNames << pItem->name(); 918 946 /* 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(); 921 952 break; 922 953 } … … 929 960 busyMachineNames << pItem->name(); 930 961 /* 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(); 933 967 break; 934 968 } … … 946 980 void UIChooserModel::sltReloadMachine(const QUuid &uId) 947 981 { 948 /* Remove all the items first: */949 root()->removeAllItems(uId);982 /* Remove all the nodes first: */ 983 invisibleRoot()->removeAllNodes(uId); 950 984 /* Wipe out empty groups: */ 951 985 wipeOutEmptyGroups(); … … 958 992 addMachineIntoTheTree(comMachine); 959 993 960 /* And update model: */ 994 /* Rebuild tree for main root: */ 995 buildTreeForMainRoot(); 961 996 updateNavigation(); 962 997 updateLayout(); … … 1174 1209 prepareScene(); 1175 1210 1176 /* Prepare root: */1177 prepareRoot();1178 1179 1211 /* Prepare lookup: */ 1180 1212 prepareLookup(); … … 1195 1227 if (m_pScene) 1196 1228 m_pScene->installEventFilter(this); 1197 }1198 1199 void UIChooserModel::prepareRoot()1200 {1201 m_pRoot = new UIChooserItemGroup(scene());1202 1229 } 1203 1230 … … 1418 1445 } 1419 1446 1420 void UIChooserModel::cleanupRoot()1421 {1422 delete root();1423 m_pRoot.clear();1424 }1425 1426 1447 void UIChooserModel::cleanupScene() 1427 1448 { … … 1440 1461 /* Cleanup lookup: */ 1441 1462 cleanupLookup(); 1442 1443 /* Cleanup root: */1444 cleanupRoot();1445 1463 1446 1464 /* Cleanup scene: */ … … 1594 1612 } 1595 1613 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: */ 1614 void 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: */ 1607 1631 LogRelFlow(("UIChooserModel: Loading VMs...\n")); 1608 1632 foreach (const CMachine &comMachine, vboxGlobal().virtualBox().GetMachines()) … … 1646 1670 LogRelFlow(("UIChooserModel: Creating item for VM {%s} in group {%s}.\n", strName.toUtf8().constData(), 1647 1671 strGroup.toUtf8().constData())); 1648 createMachine Item(getGroupItem(strGroup, root(), fMakeItVisible), comMachine);1672 createMachineNode(getGroupNode(strGroup, invisibleRoot(), fMakeItVisible), comMachine); 1649 1673 } 1650 1674 /* Update group definitions: */ … … 1657 1681 LogRelFlow(("UIChooserModel: VM {%s} is inaccessible.\n", toOldStyleUuid(comMachine.GetId()).toUtf8().constData())); 1658 1682 /* Create machine-item with main-root group-item as parent: */ 1659 createMachine Item(root(), comMachine);1660 } 1661 } 1662 1663 UIChooser Item *UIChooserModel::getGroupItem(const QString &strName, UIChooserItem *pParentItem, bool fAllGroupsOpened)1683 createMachineNode(invisibleRoot(), comMachine); 1684 } 1685 } 1686 1687 UIChooserNode *UIChooserModel::getGroupNode(const QString &strName, UIChooserNode *pParentNode, bool fAllGroupsOpened) 1664 1688 { 1665 1689 /* Check passed stuff: */ 1666 if (pParent Item->name() == strName)1667 return pParent Item;1690 if (pParentNode->name() == strName) 1691 return pParentNode; 1668 1692 1669 1693 /* Prepare variables: */ … … 1674 1698 1675 1699 /* Passed group name equal to first sub-name: */ 1676 if (pParent Item->name() == strFirstSubName)1700 if (pParentNode->name() == strFirstSubName) 1677 1701 { 1678 1702 /* Make sure first-suffix is NOT empty: */ 1679 1703 AssertMsg(!strFirstSuffix.isEmpty(), ("Invalid group name!")); 1680 /* Trying to get group -itemamong our children: */1681 foreach (UIChooser Item *pGroupItem, pParentItem->items(UIChooserItemType_Group))1682 { 1683 if (pGroup Item->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) 1684 1708 { 1685 UIChooser Item *pFoundItem = getGroupItem(strFirstSuffix, pGroupItem, fAllGroupsOpened);1686 if (UIChooser ItemGroup *pFoundGroupItem = pFoundItem->toGroupItem())1687 if (fAllGroupsOpened && pFoundGroup Item->isClosed())1688 pFoundGroup Item->open(false);1689 return pFound Item;1709 UIChooserNode *pFoundNode = getGroupNode(strFirstSuffix, pGroupNode, fAllGroupsOpened); 1710 if (UIChooserNodeGroup *pFoundGroupNode = pFoundNode->toGroupNode()) 1711 if (fAllGroupsOpened && pFoundGroupNode->isClosed()) 1712 pFoundGroupNode->open(); 1713 return pFoundNode; 1690 1714 } 1691 1715 } … … 1693 1717 1694 1718 /* 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 1728 bool UIChooserModel::shouldBeGroupOpened(UIChooserNode *pParentNode, const QString &strName) 1706 1729 { 1707 1730 /* Read group definitions: */ 1708 const QStringList definitions = gEDataManager->selectorWindowGroupsDefinitions(pParent Item->fullName());1731 const QStringList definitions = gEDataManager->selectorWindowGroupsDefinitions(pParentNode->fullName()); 1709 1732 /* Return 'false' if no definitions found: */ 1710 1733 if (definitions.isEmpty()) … … 1731 1754 } 1732 1755 1733 void UIChooserModel::wipeOutEmptyGroups(UIChooser Item*pParent)1756 void UIChooserModel::wipeOutEmptyGroups(UIChooserNode *pParent) 1734 1757 { 1735 1758 /* Cleanup all the group-items recursively first: */ 1736 foreach (UIChooser Item *pItem, pParent->items(UIChooserItemType_Group))1737 wipeOutEmptyGroups(p Item);1738 /* If parent has no items: */1739 if (!pParent->has Items())1759 foreach (UIChooserNode *pNode, pParent->nodes(UIChooserItemType_Group)) 1760 wipeOutEmptyGroups(pNode); 1761 /* If parent has no nodes: */ 1762 if (!pParent->hasNodes()) 1740 1763 { 1741 1764 /* If that is non-root item: */ … … 1748 1771 } 1749 1772 1750 bool UIChooserModel::isGlobalItemFavorite(UIChooserItem *pParentItem) const 1773 void 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 1787 bool UIChooserModel::isGlobalNodeFavorite(UIChooserNode *pParentNode) const 1751 1788 { 1752 1789 /* Read group definitions: */ 1753 const QStringList definitions = gEDataManager->selectorWindowGroupsDefinitions(pParent Item->fullName());1790 const QStringList definitions = gEDataManager->selectorWindowGroupsDefinitions(pParentNode->fullName()); 1754 1791 /* Return 'false' if no definitions found: */ 1755 1792 if (definitions.isEmpty()) … … 1776 1813 } 1777 1814 1778 int UIChooserModel::getDesiredPosition(UIChooser Item *pParentItem, UIChooserItemType enmType, const QString &strName)1815 int UIChooserModel::getDesiredPosition(UIChooserNode *pParentNode, UIChooserItemType enmType, const QString &strName) 1779 1816 { 1780 1817 /* End of list (by default)? */ 1781 int iNew ItemDesiredPosition = -1;1782 /* Which position should be new itemplaced by definitions: */1783 int iNew ItemDefinitionPosition = 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); 1784 1821 /* If some position wanted: */ 1785 if (iNew ItemDefinitionPosition != -1)1822 if (iNewNodeDefinitionPosition != -1) 1786 1823 { 1787 1824 /* Start of list if some definition present: */ 1788 iNew ItemDesiredPosition = 0;1789 /* We have to check all the existing itempositions: */1790 QList<UIChooser Item*> items = pParentItem->items(enmType);1791 for (int i = items.size() - 1; i >= 0; --i)1792 { 1793 /* Get current item: */1794 UIChooser Item *pItem = items[i];1795 /* Which position should be current itemplaced by definitions? */1796 QString strDefinitionName = p Item->type() == UIChooserItemType_Group ? pItem->name() :1797 p Item->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()) : 1798 1835 QString(); 1799 1836 AssertMsg(!strDefinitionName.isEmpty(), ("Wrong definition name!")); 1800 int i ItemDefinitionPosition = positionFromDefinitions(pParentItem, enmType, strDefinitionName);1837 int iNodeDefinitionPosition = positionFromDefinitions(pParentNode, enmType, strDefinitionName); 1801 1838 /* If some position wanted: */ 1802 if (i ItemDefinitionPosition != -1)1839 if (iNodeDefinitionPosition != -1) 1803 1840 { 1804 AssertMsg(i ItemDefinitionPosition != iNewItemDefinitionPosition, ("Incorrect definitions!"));1805 if (i ItemDefinitionPosition < iNewItemDefinitionPosition)1841 AssertMsg(iNodeDefinitionPosition != iNewNodeDefinitionPosition, ("Incorrect definitions!")); 1842 if (iNodeDefinitionPosition < iNewNodeDefinitionPosition) 1806 1843 { 1807 iNew ItemDesiredPosition = i + 1;1844 iNewNodeDesiredPosition = i + 1; 1808 1845 break; 1809 1846 } … … 1811 1848 } 1812 1849 } 1813 /* Return desired itemposition: */1814 return iNew ItemDesiredPosition;1815 } 1816 1817 int UIChooserModel::positionFromDefinitions(UIChooser Item *pParentItem, UIChooserItemType enmType, const QString &strName)1850 /* Return desired node position: */ 1851 return iNewNodeDesiredPosition; 1852 } 1853 1854 int UIChooserModel::positionFromDefinitions(UIChooserNode *pParentNode, UIChooserItemType enmType, const QString &strName) 1818 1855 { 1819 1856 /* Read group definitions: */ 1820 const QStringList definitions = gEDataManager->selectorWindowGroupsDefinitions(pParent Item->fullName());1857 const QStringList definitions = gEDataManager->selectorWindowGroupsDefinitions(pParentNode->fullName()); 1821 1858 /* Return 'false' if no definitions found: */ 1822 1859 if (definitions.isEmpty()) … … 1859 1896 } 1860 1897 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()))); 1898 void 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); 1867 1905 } 1868 1906 1869 1907 void UIChooserModel::removeItems(const QList<UIChooserItem*> &itemsToRemove) 1870 1908 { 1871 1872 1909 /* Confirm machine-items removal: */ 1873 1910 QStringList names; … … 1877 1914 return; 1878 1915 1879 /* Remove all the passed items: */1916 /* Remove all the passed nodes: */ 1880 1917 foreach (UIChooserItem *pItem, itemsToRemove) 1881 delete pItem ;1918 delete pItem->node(); 1882 1919 1883 1920 /* And update model: */ … … 2005 2042 /* Prepare full group map: */ 2006 2043 QMap<QString, QStringList> groups; 2007 gatherGroupDefinitions(groups, root());2044 gatherGroupDefinitions(groups, invisibleRoot()); 2008 2045 2009 2046 /* Save information in other thread: */ … … 2025 2062 /* Prepare full group map: */ 2026 2063 QMap<QString, QStringList> groups; 2027 gatherGroupOrders(groups, root());2064 gatherGroupOrders(groups, invisibleRoot()); 2028 2065 2029 2066 /* Save information in other thread: */ … … 2035 2072 2036 2073 void UIChooserModel::gatherGroupDefinitions(QMap<QString, QStringList> &definitions, 2037 UIChooser Item*pParentGroup)2038 { 2039 /* Iterate over all the machine- items: */2040 foreach (UIChooser Item *pItem, pParentGroup->items(UIChooserItemType_Machine))2041 if (UIChooser ItemMachine *pMachineItem = pItem->toMachineItem())2042 if (pMachine Item->accessible())2043 definitions[toOldStyleUuid(pMachine Item->id())] << pParentGroup->fullName();2044 /* Iterate over all the group- items: */2045 foreach (UIChooser Item *pItem, pParentGroup->items(UIChooserItemType_Group))2046 gatherGroupDefinitions(definitions, p Item);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); 2047 2084 } 2048 2085 2049 2086 void UIChooserModel::gatherGroupOrders(QMap<QString, QStringList> &orders, 2050 UIChooser Item*pParentItem)2087 UIChooserNode *pParentItem) 2051 2088 { 2052 2089 /* Prepare extra-data key for current group: */ 2053 2090 const QString strExtraDataKey = pParentItem->fullName(); 2054 /* Iterate over all the global- items: */2055 foreach (UIChooser Item *pItem, pParentItem->items(UIChooserItemType_Global))2056 { 2057 const QString strGlobalDescriptor(p Item->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"); 2058 2095 orders[strExtraDataKey] << QString("%1=GLOBAL").arg(strGlobalDescriptor); 2059 2096 } 2060 /* Iterate over all the group- items: */2061 foreach (UIChooser Item *pItem, pParentItem->items(UIChooserItemType_Group))2062 { 2063 const QString strGroupDescriptor(p Item->toGroupItem()->isOpened() ? "go" : "gc");2064 orders[strExtraDataKey] << QString("%1=%2").arg(strGroupDescriptor, p Item->name());2065 gatherGroupOrders(orders, p Item);2066 } 2067 /* Iterate over all the machine- items: */2068 foreach (UIChooser Item *pItem, pParentItem->items(UIChooserItemType_Machine))2069 orders[strExtraDataKey] << QString("m=%1").arg(toOldStyleUuid(p Item->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())); 2070 2107 } 2071 2108 -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.h
r77605 r77638 41 41 class UIChooserHandlerKeyboard; 42 42 class UIChooserItem; 43 class UIChooserNode; 43 44 class UIVirtualMachineItem; 44 45 class CMachine; … … 188 189 /** @name Children stuff. 189 190 * @{ */ 191 /** Returns invisible root node instance. */ 192 UIChooserNode *invisibleRoot() const; 193 190 194 /** Returns the root instance. */ 191 195 UIChooserItem *root() const; … … 316 320 /** Prepares scene. */ 317 321 void prepareScene(); 318 /** Prepares root. */319 void prepareRoot();320 322 /** Prepares lookup. */ 321 323 void prepareLookup(); … … 337 339 /** Cleanups lookup. */ 338 340 void cleanupLookup(); 339 /** Cleanups root. */340 void cleanupRoot();341 341 /** Cleanups scene. */ 342 342 void cleanupScene(); … … 367 367 /** @name Children stuff. 368 368 * @{ */ 369 /** Loads grouptree. */370 void load GroupTree();369 /** Loads tree. */ 370 void loadTree(); 371 371 /** Adds machine item based on certain @a comMachine and optionally @a fMakeItVisible. */ 372 372 void addMachineIntoTheTree(const CMachine &comMachine, bool fMakeItVisible = false); 373 /** Acquires group item, creates one if necessary.373 /** Acquires group node, creates one if necessary. 374 374 * @param strName Brings the name of group we looking for. 375 * @param pParent ItemBrings the parent we starting to look for a group from.375 * @param pParentNode Brings the parent we starting to look for a group from. 376 376 * @param fAllGroupsOpened Brings whether we should open all the groups till the required one. */ 377 UIChooser Item *getGroupItem(const QString &strName, UIChooserItem *pParentItem, bool fAllGroupsOpened);377 UIChooserNode *getGroupNode(const QString &strName, UIChooserNode *pParentNode, bool fAllGroupsOpened); 378 378 /** Returns whether group with certain @a strName should be opened, searching starting from the passed @a pParentItem. */ 379 bool shouldBeGroupOpened(UIChooser Item *pParentItem, const QString &strName);379 bool shouldBeGroupOpened(UIChooserNode *pParentNode, const QString &strName); 380 380 381 381 /** 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(); 394 397 395 398 /** Removes machine @a items. */ … … 412 415 413 416 /** Gathers group @a definitions of @a pParentGroup. */ 414 void gatherGroupDefinitions(QMap<QString, QStringList> &definitions, UIChooser Item*pParentGroup);417 void gatherGroupDefinitions(QMap<QString, QStringList> &definitions, UIChooserNode *pParentGroup); 415 418 /** Gathers group @a orders of @a pParentGroup. */ 416 void gatherGroupOrders(QMap<QString, QStringList> &orders, UIChooser Item*pParentItem);419 void gatherGroupOrders(QMap<QString, QStringList> &orders, UIChooserNode *pParentItem); 417 420 418 421 /** Makes sure group definitions saving is finished. */ … … 455 458 /** @name Children stuff. 456 459 * @{ */ 460 /** Holds the invisible root node instance. */ 461 UIChooserNode *m_pInvisibleRootNode; 462 457 463 /** Holds the root instance. */ 458 464 QPointer<UIChooserItem> m_pRoot; -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNode.cpp
r77636 r77638 30 30 } 31 31 32 UIChooserNode::~UIChooserNode() 33 { 34 if (!m_pItem.isNull()) 35 delete m_pItem.data(); 36 } 37 32 38 UIChooserNodeGroup *UIChooserNode::toGroupNode() 33 39 { … … 44 50 return static_cast<UIChooserNodeMachine*>(this); 45 51 } 52 53 int UIChooserNode::position() 54 { 55 return parentNode() ? parentNode()->positionOf(this) : 0; 56 } -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNode.h
r77636 r77638 50 50 * @param fFavorite Brings whether the node is favorite. */ 51 51 UIChooserNode(UIChooserNode *pParent = 0, bool fFavorite = false); 52 /** Destructs chooser node. */ 53 virtual ~UIChooserNode() /* override */; 52 54 53 55 /** Returns RTTI node type. */ … … 80 82 virtual QString definition() const = 0; 81 83 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 82 104 /** Defines linked @a pItem. */ 83 105 void setItem(UIChooserItem *pItem) { m_pItem = pItem; } -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNodeGlobal.cpp
r77636 r77638 25 25 UIChooserNodeGlobal::UIChooserNodeGlobal(UIChooserNode *pParent, 26 26 bool fFavorite, 27 int iPosition, 27 28 const QString &) 28 29 : UIChooserNode(pParent, fFavorite) 29 30 { 31 if (parentNode()) 32 parentNode()->addNode(this, iPosition); 30 33 retranslateUi(); 34 } 35 36 UIChooserNodeGlobal::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 46 UIChooserNodeGlobal::~UIChooserNodeGlobal() 47 { 48 delete item(); 49 if (parentNode()) 50 parentNode()->removeNode(this); 31 51 } 32 52 … … 51 71 } 52 72 73 bool UIChooserNodeGlobal::hasNodes(UIChooserItemType enmType) const 74 { 75 Q_UNUSED(enmType); 76 AssertFailedReturn(false); 77 } 78 79 QList<UIChooserNode*> UIChooserNodeGlobal::nodes(UIChooserItemType enmType) const 80 { 81 Q_UNUSED(enmType); 82 AssertFailedReturn(QList<UIChooserNode*>()); 83 } 84 85 void UIChooserNodeGlobal::addNode(UIChooserNode *pNode, int iPosition) 86 { 87 Q_UNUSED(pNode); 88 Q_UNUSED(iPosition); 89 AssertFailedReturnVoid(); 90 } 91 92 void UIChooserNodeGlobal::removeNode(UIChooserNode *pNode) 93 { 94 Q_UNUSED(pNode); 95 AssertFailedReturnVoid(); 96 } 97 98 void UIChooserNodeGlobal::removeAllNodes(const QUuid &) 99 { 100 // Nothing to remove for global-node.. 101 } 102 103 void UIChooserNodeGlobal::updateAllNodes(const QUuid &) 104 { 105 // Nothing to update for global-node.. 106 107 /* Update global-item: */ 108 item()->updateItem(); 109 } 110 111 int UIChooserNodeGlobal::positionOf(UIChooserNode *pNode) 112 { 113 Q_UNUSED(pNode); 114 AssertFailedReturn(0); 115 } 116 53 117 void UIChooserNodeGlobal::retranslateUi() 54 118 { -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNodeGlobal.h
r77636 r77638 35 35 /** Constructs chooser node passing @a pParent to the base-class. 36 36 * @param fFavorite Brings whether the node is favorite. 37 * @param iPosition Brings the initial node position. 37 38 * @param strTip Brings the dummy tip. */ 38 39 UIChooserNodeGlobal(UIChooserNode *pParent, 39 40 bool fFavorite, 41 int iPosition, 40 42 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 */; 41 51 42 52 /** Returns RTTI node type. */ … … 51 61 /** Returns item definition. */ 52 62 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 */; 53 81 54 82 protected: -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNodeGroup.cpp
r77636 r77638 24 24 UIChooserNodeGroup::UIChooserNodeGroup(UIChooserNode *pParent, 25 25 bool fFavorite, 26 int iPosition, 26 27 const QString &strName, 27 28 bool fOpened) … … 30 31 , m_fOpened(fOpened) 31 32 { 33 if (parentNode()) 34 parentNode()->addNode(this, iPosition); 32 35 retranslateUi(); 36 } 37 38 UIChooserNodeGroup::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 51 UIChooserNodeGroup::~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); 33 64 } 34 65 … … 61 92 } 62 93 94 bool 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 110 QList<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 122 void 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 134 void 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 146 void UIChooserNodeGroup::removeAllNodes(const QUuid &uId) 147 { 148 foreach (UIChooserNode *pNode, nodes()) 149 pNode->removeAllNodes(uId); 150 } 151 152 void 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 164 int 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 63 176 void UIChooserNodeGroup::setName(const QString &strName) 64 177 { … … 84 197 item()->updateItem(); 85 198 } 199 200 void 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 35 35 /** Constructs chooser node passing @a pParent to the base-class. 36 36 * @param fFavorite Brings whether the node is favorite. 37 * @param iPosition Brings the initial node position. 37 38 * @param strName Brings current node name. 38 39 * @param fOpened Brings whether this group node is opened. */ 39 40 UIChooserNodeGroup(UIChooserNode *pParent, 40 41 bool fFavorite, 42 int iPosition, 41 43 const QString &strName, 42 44 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 */; 43 53 44 54 /** Returns RTTI node type. */ … … 53 63 /** Returns item definition. */ 54 64 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 */; 55 83 56 84 /** Defines node @a strName. */ … … 74 102 private: 75 103 104 /** Copies children contents from @a pCopyFrom item. */ 105 void copyContents(UIChooserNodeGroup *pCopyFrom); 106 76 107 /** Holds the node name. */ 77 108 QString m_strName; 78 109 /** Holds whether node is opened. */ 79 110 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; 80 118 }; 81 119 -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNodeMachine.cpp
r77636 r77638 16 16 */ 17 17 18 /* Qt includes */19 //#include <QUuid>20 21 18 /* GUI includes: */ 22 19 #include "UIChooserNodeMachine.h" … … 25 22 UIChooserNodeMachine::UIChooserNodeMachine(UIChooserNode *pParent, 26 23 bool fFavorite, 24 int iPosition, 27 25 const CMachine &comMachine) 28 26 : UIChooserNode(pParent, fFavorite) 29 27 , UIVirtualMachineItem(comMachine) 30 28 { 29 if (parentNode()) 30 parentNode()->addNode(this, iPosition); 31 31 retranslateUi(); 32 } 33 34 UIChooserNodeMachine::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 45 UIChooserNodeMachine::~UIChooserNodeMachine() 46 { 47 delete item(); 48 if (parentNode()) 49 parentNode()->removeNode(this); 32 50 } 33 51 … … 58 76 } 59 77 78 bool UIChooserNodeMachine::hasNodes(UIChooserItemType enmType) const 79 { 80 Q_UNUSED(enmType); 81 AssertFailedReturn(false); 82 } 83 84 QList<UIChooserNode*> UIChooserNodeMachine::nodes(UIChooserItemType enmType) const 85 { 86 Q_UNUSED(enmType); 87 AssertFailedReturn(QList<UIChooserNode*>()); 88 } 89 90 void UIChooserNodeMachine::addNode(UIChooserNode *pNode, int iPosition) 91 { 92 Q_UNUSED(pNode); 93 Q_UNUSED(iPosition); 94 AssertFailedReturnVoid(); 95 } 96 97 void UIChooserNodeMachine::removeNode(UIChooserNode *pNode) 98 { 99 Q_UNUSED(pNode); 100 AssertFailedReturnVoid(); 101 } 102 103 void 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 113 void 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 127 int UIChooserNodeMachine::positionOf(UIChooserNode *pNode) 128 { 129 Q_UNUSED(pNode); 130 AssertFailedReturn(0); 131 } 132 60 133 void UIChooserNodeMachine::retranslateUi() 61 134 { -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNodeMachine.h
r77636 r77638 36 36 /** Constructs chooser node passing @a pParent to the base-class. 37 37 * @param fFavorite Brings whether the node is favorite. 38 * @param iPosition Brings the initial node position. 38 39 * @param comMachine Brings COM machine object. */ 39 40 UIChooserNodeMachine(UIChooserNode *pParent, 40 41 bool fFavorite, 42 int iPosition, 41 43 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 */; 42 52 43 53 /** Returns RTTI node type. */ … … 53 63 virtual QString definition() const /* override */; 54 64 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 55 83 protected: 56 84
Note:
See TracChangeset
for help on using the changeset viewer.