Changeset 77604 in vbox for trunk/src/VBox
- Timestamp:
- Mar 7, 2019 3:50:55 PM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGroup.cpp
r77597 r77604 1054 1054 1055 1055 /* Update model: */ 1056 pModel-> cleanupGroupTree();1056 pModel->wipeOutEmptyGroups(); 1057 1057 pModel->updateNavigation(); 1058 1058 pModel->updateLayout(); … … 1107 1107 1108 1108 /* Update model: */ 1109 pModel-> cleanupGroupTree();1109 pModel->wipeOutEmptyGroups(); 1110 1110 pModel->updateNavigation(); 1111 1111 pModel->updateLayout(); -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemMachine.cpp
r77596 r77604 522 522 523 523 /* Update model: */ 524 pModel-> cleanupGroupTree();524 pModel->wipeOutEmptyGroups(); 525 525 pModel->updateNavigation(); 526 526 pModel->updateLayout(); -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.cpp
r77601 r77604 20 20 #include <QGraphicsScene> 21 21 #include <QGraphicsSceneContextMenuEvent> 22 #include <QGraphicsSceneMouseEvent>23 22 #include <QGraphicsView> 24 #include <QPropertyAnimation>25 23 #include <QScrollBar> 26 #include <QRegExp>27 24 #include <QTimer> 28 #include <QParallelAnimationGroup>29 25 30 26 /* GUI includes: */ … … 39 35 #include "UIChooserItemMachine.h" 40 36 #include "UIChooserModel.h" 41 #include "UIExtraDataDefs.h"42 37 #include "UIExtraDataManager.h" 43 38 #include "UIMessageCenter.h" … … 50 45 #include "CExtPack.h" 51 46 #include "CExtPackManager.h" 52 #include "CMachine.h"53 #include "CMedium.h"54 #include "CVirtualBox.h"55 56 47 57 48 /* Type defs: */ … … 76 67 , m_pLookupTimer(0) 77 68 { 78 /* Prepare: */79 69 prepare(); 80 70 } … … 82 72 UIChooserModel::~UIChooserModel() 83 73 { 84 /* Cleanup: */85 74 cleanup(); 86 75 } … … 94 83 /* Load group tree: */ 95 84 loadGroupTree(); 96 97 /* Update navigation: */98 85 updateNavigation(); 99 100 /* Update layout: */101 86 updateLayout(); 102 87 … … 155 140 emit sigToolMenuRequested(UIToolClass_Global, pItem->mapToScene(QPointF(pItem->size().width(), 0)).toPoint()); 156 141 break; 157 case UIChooserItemType_Group:158 142 case UIChooserItemType_Machine: 159 143 emit sigToolMenuRequested(UIToolClass_Machine, pItem->mapToScene(QPointF(pItem->size().width(), 0)).toPoint()); … … 466 450 } 467 451 468 void UIChooserModel:: cleanupGroupTree()469 { 470 cleanupGroupTree(root());452 void UIChooserModel::wipeOutEmptyGroups() 453 { 454 wipeOutEmptyGroups(root()); 471 455 } 472 456 … … 691 675 if (fRegistered) 692 676 { 693 /* S earch for corresponding machine: */677 /* Show machine if we should: */ 694 678 CMachine comMachine = vboxGlobal().virtualBox().FindMachine(uId.toString()); 695 /* Should we show this machine? */696 679 if (gEDataManager->showMachineInSelectorChooser(uId)) 697 680 { 698 681 /* Add new machine-item: */ 699 addMachineIntoTheTree(comMachine, true); 682 addMachineIntoTheTree(comMachine, true /* make it visible */); 683 700 684 /* And update model: */ 701 685 updateNavigation(); 702 686 updateLayout(); 703 /* Change current-item only if VM was created from the GUI side: */ 687 688 /* Choose newly added item only if VM was created from the GUI side: */ 704 689 if (uId == m_uLastCreatedMachineId) 705 { 706 setCurrentItem(root()->searchForItem(comMachine.GetName(), 707 UIChooserItemSearchFlag_Machine | 708 UIChooserItemSearchFlag_ExactName)); 709 } 710 } 690 setCurrentItem(root()->searchForItem(comMachine.GetName(), 691 UIChooserItemSearchFlag_Machine | 692 UIChooserItemSearchFlag_ExactName)); 693 } 711 694 } 712 695 /* Existing VM unregistered? */ … … 716 699 root()->removeAllItems(uId.toString()); 717 700 /* Update model: */ 718 cleanupGroupTree(); 701 wipeOutEmptyGroups(); 702 703 /* And update model: */ 719 704 updateNavigation(); 720 705 updateLayout(); 706 721 707 /* Make sure current-item present, if possible: */ 722 708 if (!currentItem() && !navigationList().isEmpty()) … … 841 827 break; 842 828 } 829 default: 830 break; 843 831 } 844 832 } … … 894 882 if (pWizard->exec() == QDialog::Accepted) 895 883 m_uLastCreatedMachineId = pWizard->createdMachineId(); 896 897 884 if (pWizard) 898 885 delete pWizard; … … 910 897 return; 911 898 912 /* Create new group i n the current root: */899 /* Create new group item in the current root: */ 913 900 UIChooserItemGroup *pNewGroupItem = new UIChooserItemGroup(root(), uniqueGroupName(root()), true); 901 914 902 /* Enumerate all the currently chosen items: */ 915 903 QStringList busyGroupNames; … … 949 937 950 938 /* Update model: */ 951 cleanupGroupTree();939 wipeOutEmptyGroups(); 952 940 updateNavigation(); 953 941 updateLayout(); … … 961 949 root()->removeAllItems(uId); 962 950 /* Wipe out empty groups: */ 963 cleanupGroupTree();951 wipeOutEmptyGroups(); 964 952 965 953 /* Show machine if we should: */ 966 954 CMachine comMachine = vboxGlobal().virtualBox().FindMachine(uId.toString()); 967 955 if (gEDataManager->showMachineInSelectorChooser(uId)) 956 { 957 /* Add new machine-item: */ 968 958 addMachineIntoTheTree(comMachine); 969 959 970 /* And update model: */960 /* And update model: */ 971 961 updateNavigation(); 972 962 updateLayout(); 973 963 964 /* Choose newly added item: */ 965 setCurrentItem(root()->searchForItem(comMachine.GetName(), 966 UIChooserItemSearchFlag_Machine | 967 UIChooserItemSearchFlag_ExactName)); 968 } 969 else 970 { 974 971 /* Make sure at least one item selected after that: */ 975 972 if (!currentItem() && !navigationList().isEmpty()) 976 973 setCurrentItem(navigationList().first()); 974 } 977 975 978 976 /* Notify listeners about selection change: */ … … 1016 1014 { 1017 1015 /* Machine name: */ 1018 QString strMachineName = ((UIChooserItem*)pItem)->name();1016 const QString strMachineName = ((UIChooserItem*)pItem)->name(); 1019 1017 /* We should reload this machine: */ 1020 1018 sltReloadMachine(pItem->id()); … … 1377 1375 1378 1376 /* Setup group saving connections: */ 1379 connect(this, SIGNAL(sigGroupSavingStarted()), this, SLOT(sltGroupSavingStart()), Qt::QueuedConnection); 1377 connect(this, &UIChooserModel::sigGroupSavingStarted, 1378 this, &UIChooserModel::sltGroupSavingStart, 1379 Qt::QueuedConnection); 1380 1380 } 1381 1381 … … 1596 1596 void UIChooserModel::loadGroupTree() 1597 1597 { 1598 /* Create Global item: */ 1599 createGlobalItem(root()); 1600 1601 /* Add all the approved machines we have into the group-tree: */ 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: */ 1602 1607 LogRelFlow(("UIChooserModel: Loading VMs...\n")); 1603 foreach (CMachine machine, vboxGlobal().virtualBox().GetMachines()) 1604 { 1605 const QUuid uMachineID = machine.GetId(); 1608 foreach (const CMachine &comMachine, vboxGlobal().virtualBox().GetMachines()) 1609 { 1610 const QUuid uMachineID = comMachine.GetId(); 1611 /// @todo rename showMachineInSelectorChooser to showMachineInVirtualBoxManager 1606 1612 if (!uMachineID.isNull() && gEDataManager->showMachineInSelectorChooser(uMachineID)) 1607 addMachineIntoTheTree(machine);1613 addMachineIntoTheTree(comMachine); 1608 1614 } 1609 1615 LogRelFlow(("UIChooserModel: VMs loaded.\n")); 1610 1616 } 1611 1612 void UIChooserModel::addMachineIntoTheTree(const CMachine &machine, bool fMakeItVisible /* = false */) 1617 } 1618 1619 void UIChooserModel::addMachineIntoTheTree(const CMachine &comMachine, bool fMakeItVisible /* = false */) 1613 1620 { 1614 1621 /* Make sure passed VM is not NULL: */ 1615 if ( machine.isNull())1622 if (comMachine.isNull()) 1616 1623 LogRelFlow(("UIChooserModel: ERROR: Passed VM is NULL!\n")); 1617 AssertReturnVoid(! machine.isNull());1624 AssertReturnVoid(!comMachine.isNull()); 1618 1625 1619 1626 /* Which VM we are loading: */ 1620 LogRelFlow(("UIChooserModel: Loading VM with ID={%s}...\n", toOldStyleUuid( machine.GetId()).toUtf8().constData()));1627 LogRelFlow(("UIChooserModel: Loading VM with ID={%s}...\n", toOldStyleUuid(comMachine.GetId()).toUtf8().constData())); 1621 1628 /* Is that machine accessible? */ 1622 if ( machine.GetAccessible())1629 if (comMachine.GetAccessible()) 1623 1630 { 1624 1631 /* VM is accessible: */ 1625 const QString strName = machine.GetName();1632 const QString strName = comMachine.GetName(); 1626 1633 LogRelFlow(("UIChooserModel: VM {%s} is accessible.\n", strName.toUtf8().constData())); 1627 1634 /* Which groups passed machine attached to? */ 1628 const QVector<QString> groups = machine.GetGroups();1635 const QVector<QString> groups = comMachine.GetGroups(); 1629 1636 const QStringList groupList = groups.toList(); 1630 1637 const QString strGroups = groupList.join(", "); … … 1639 1646 LogRelFlow(("UIChooserModel: Creating item for VM {%s} in group {%s}.\n", strName.toUtf8().constData(), 1640 1647 strGroup.toUtf8().constData())); 1641 createMachineItem( machine, getGroupItem(strGroup, root(), fMakeItVisible));1648 createMachineItem(getGroupItem(strGroup, root(), fMakeItVisible), comMachine); 1642 1649 } 1643 1650 /* Update group definitions: */ 1644 m_groups[toOldStyleUuid( machine.GetId())] = groupList;1651 m_groups[toOldStyleUuid(comMachine.GetId())] = groupList; 1645 1652 } 1646 1653 /* Inaccessible machine: */ … … 1648 1655 { 1649 1656 /* VM is accessible: */ 1650 LogRelFlow(("UIChooserModel: VM {%s} is inaccessible.\n", toOldStyleUuid( machine.GetId()).toUtf8().constData()));1657 LogRelFlow(("UIChooserModel: VM {%s} is inaccessible.\n", toOldStyleUuid(comMachine.GetId()).toUtf8().constData())); 1651 1658 /* Create machine-item with main-root group-item as parent: */ 1652 createMachineItem( machine, root());1659 createMachineItem(root(), comMachine); 1653 1660 } 1654 1661 } … … 1681 1688 pFoundGroupItem->open(false); 1682 1689 return pFoundItem; 1683 }1684 }1685 }1690 } 1691 } 1692 } 1686 1693 1687 1694 /* Found nothing? Creating: */ 1688 1695 UIChooserItemGroup *pNewGroupItem = 1689 1690 1691 1692 1693 1694 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)); 1695 1702 return strSecondSuffix.isEmpty() ? pNewGroupItem : getGroupItem(strFirstSuffix, pNewGroupItem, fAllGroupsOpened); 1696 1703 } … … 1724 1731 } 1725 1732 1726 void UIChooserModel:: cleanupGroupTree(UIChooserItem *pParent)1733 void UIChooserModel::wipeOutEmptyGroups(UIChooserItem *pParent) 1727 1734 { 1728 1735 /* Cleanup all the group-items recursively first: */ 1729 1736 foreach (UIChooserItem *pItem, pParent->items(UIChooserItemType_Group)) 1730 cleanupGroupTree(pItem);1737 wipeOutEmptyGroups(pItem); 1731 1738 /* If parent has no items: */ 1732 1739 if (!pParent->hasItems()) 1733 1740 { 1734 /* Cleanup if that is non-root item: */1741 /* If that is non-root item: */ 1735 1742 if (!pParent->isRoot()) 1743 { 1744 /* Delete parent node and item: */ 1736 1745 delete pParent; 1737 } 1738 } 1746 } 1747 } 1748 } 1739 1749 1740 1750 bool UIChooserModel::isGlobalItemFavorite(UIChooserItem *pParentItem) const … … 1748 1758 /* Prepare required group definition reg-exp: */ 1749 1759 const QString strDefinitionTemplate = QString("n(\\S)*=GLOBAL"); 1750 const QRegExp definitionRegExp (strDefinitionTemplate);1760 const QRegExp definitionRegExp = QRegExp(strDefinitionTemplate); 1751 1761 /* For each the group definition: */ 1752 1762 foreach (const QString &strDefinition, definitions) … … 1766 1776 } 1767 1777 1768 int UIChooserModel::getDesiredPosition(UIChooserItem *pParentItem, UIChooserItemType type, const QString &strName)1778 int UIChooserModel::getDesiredPosition(UIChooserItem *pParentItem, UIChooserItemType enmType, const QString &strName) 1769 1779 { 1770 1780 /* End of list (by default)? */ 1771 1781 int iNewItemDesiredPosition = -1; 1772 1782 /* Which position should be new item placed by definitions: */ 1773 int iNewItemDefinitionPosition = positionFromDefinitions(pParentItem, type, strName);1783 int iNewItemDefinitionPosition = positionFromDefinitions(pParentItem, enmType, strName); 1774 1784 /* If some position wanted: */ 1775 1785 if (iNewItemDefinitionPosition != -1) … … 1778 1788 iNewItemDesiredPosition = 0; 1779 1789 /* We have to check all the existing item positions: */ 1780 QList<UIChooserItem*> items = pParentItem->items( type);1790 QList<UIChooserItem*> items = pParentItem->items(enmType); 1781 1791 for (int i = items.size() - 1; i >= 0; --i) 1782 1792 { … … 1788 1798 QString(); 1789 1799 AssertMsg(!strDefinitionName.isEmpty(), ("Wrong definition name!")); 1790 int iItemDefinitionPosition = positionFromDefinitions(pParentItem, type, strDefinitionName);1800 int iItemDefinitionPosition = positionFromDefinitions(pParentItem, enmType, strDefinitionName); 1791 1801 /* If some position wanted: */ 1792 1802 if (iItemDefinitionPosition != -1) … … 1805 1815 } 1806 1816 1807 int UIChooserModel::positionFromDefinitions(UIChooserItem *pParentItem, UIChooserItemType type, const QString &strName)1817 int UIChooserModel::positionFromDefinitions(UIChooserItem *pParentItem, UIChooserItemType enmType, const QString &strName) 1808 1818 { 1809 1819 /* Read group definitions: */ … … 1816 1826 QString strDefinitionTemplateShort; 1817 1827 QString strDefinitionTemplateFull; 1818 switch ( type)1828 switch (enmType) 1819 1829 { 1820 1830 case UIChooserItemType_Group: … … 1849 1859 } 1850 1860 1851 void UIChooserModel::createMachineItem(const CMachine &machine, UIChooserItem *pParentItem) 1852 { 1853 /* Create machine-item: */ 1854 new UIChooserItemMachine(pParentItem, machine, getDesiredPosition(pParentItem, UIChooserItemType_Machine, toOldStyleUuid(machine.GetId()))); 1855 } 1856 1857 void UIChooserModel::createGlobalItem(UIChooserItem *pParentItem) 1858 { 1859 /* Create global-item: */ 1860 new UIChooserItemGlobal(pParentItem, isGlobalItemFavorite(pParentItem), 0); 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()))); 1861 1867 } 1862 1868 1863 1869 void UIChooserModel::removeItems(const QList<UIChooserItem*> &itemsToRemove) 1864 1870 { 1871 1865 1872 /* Confirm machine-items removal: */ 1866 1873 QStringList names; … … 1875 1882 1876 1883 /* And update model: */ 1877 cleanupGroupTree();1884 wipeOutEmptyGroups(); 1878 1885 updateNavigation(); 1879 1886 updateLayout(); … … 2061 2068 foreach (UIChooserItem *pItem, pParentItem->items(UIChooserItemType_Machine)) 2062 2069 orders[strExtraDataKey] << QString("m=%1").arg(toOldStyleUuid(pItem->toMachineItem()->id())); 2063 2070 } 2064 2071 2065 2072 void UIChooserModel::makeSureGroupDefinitionsSaveIsFinished() -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.h
r77601 r77604 23 23 24 24 /* Qt includes: */ 25 #include <QMap>26 #include <QObject>27 25 #include <QPointer> 28 26 #include <QThread> 29 #include <QTransform>30 27 #include <QUuid> 31 28 32 29 /* GUI includes: */ 33 #include "UIChooser Item.h"30 #include "UIChooserDefs.h" 34 31 #include "UIExtraDataDefs.h" 35 32 … … 39 36 /* Forward declaration: */ 40 37 class QDrag; 41 class QGraphicsItem;42 class QGraphicsScene;43 class QGraphicsSceneContextMenuEvent;44 class QMenu;45 class QPaintDevice;46 class QTimer;47 38 class UIActionPool; 48 39 class UIChooser; 49 40 class UIChooserHandlerMouse; 50 41 class UIChooserHandlerKeyboard; 42 class UIChooserItem; 51 43 class UIVirtualMachineItem; 52 44 class CMachine; … … 202 194 void startEditingGroupItemName(); 203 195 204 /** Cleanups group tree. */205 void cleanupGroupTree();196 /** Wipes out empty groups. */ 197 void wipeOutEmptyGroups(); 206 198 207 199 /** Activates machine item. */ … … 387 379 bool shouldBeGroupOpened(UIChooserItem *pParentItem, const QString &strName); 388 380 389 /** Cleanups group tree starting from the passed@a pParentItem. */390 void cleanupGroupTree(UIChooserItem *pParentItem);381 /** Wipes out empty groups starting from @a pParentItem. */ 382 void wipeOutEmptyGroups(UIChooserItem *pParentItem); 391 383 392 384 /** Returns whether global item within the @a pParentItem is favorite. */ 393 385 bool isGlobalItemFavorite(UIChooserItem *pParentItem) const; 394 386 395 /** Acquires desired position for a nchild of @a pParentItem with specified @a enmType and @a strName. */387 /** Acquires desired position for a child of @a pParentItem with specified @a enmType and @a strName. */ 396 388 int getDesiredPosition(UIChooserItem *pParentItem, UIChooserItemType enmType, const QString &strName); 397 /** Acquires saved position for a nchild of @a pParentItem with specified @a enmType and @a strName. */389 /** Acquires saved position for a child of @a pParentItem with specified @a enmType and @a strName. */ 398 390 int positionFromDefinitions(UIChooserItem *pParentItem, UIChooserItemType enmType, const QString &strName); 399 391 400 392 /** Creates machine item based on certain @a comMachine as a child of specified @a pParentItem. */ 401 void createMachineItem(const CMachine &comMachine, UIChooserItem *pParentItem); 402 /** Creates global item as a child of specified @a pParentItem. */ 403 void createGlobalItem(UIChooserItem *pParentItem); 393 void createMachineItem(UIChooserItem *pParentItem, const CMachine &comMachine); 404 394 405 395 /** Removes machine @a items. */
Note:
See TracChangeset
for help on using the changeset viewer.