VirtualBox

Changeset 77604 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 7, 2019 3:50:55 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9241: VirtualBox Manager UI: Another large bunch of refactoring for Chooser pane, this time heavy UIChooserModel cleanup.

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  
    10541054
    10551055                /* Update model: */
    1056                 pModel->cleanupGroupTree();
     1056                pModel->wipeOutEmptyGroups();
    10571057                pModel->updateNavigation();
    10581058                pModel->updateLayout();
     
    11071107
    11081108                /* Update model: */
    1109                 pModel->cleanupGroupTree();
     1109                pModel->wipeOutEmptyGroups();
    11101110                pModel->updateNavigation();
    11111111                pModel->updateLayout();
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemMachine.cpp

    r77596 r77604  
    522522
    523523                /* Update model: */
    524                 pModel->cleanupGroupTree();
     524                pModel->wipeOutEmptyGroups();
    525525                pModel->updateNavigation();
    526526                pModel->updateLayout();
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.cpp

    r77601 r77604  
    2020#include <QGraphicsScene>
    2121#include <QGraphicsSceneContextMenuEvent>
    22 #include <QGraphicsSceneMouseEvent>
    2322#include <QGraphicsView>
    24 #include <QPropertyAnimation>
    2523#include <QScrollBar>
    26 #include <QRegExp>
    2724#include <QTimer>
    28 #include <QParallelAnimationGroup>
    2925
    3026/* GUI includes: */
     
    3935#include "UIChooserItemMachine.h"
    4036#include "UIChooserModel.h"
    41 #include "UIExtraDataDefs.h"
    4237#include "UIExtraDataManager.h"
    4338#include "UIMessageCenter.h"
     
    5045#include "CExtPack.h"
    5146#include "CExtPackManager.h"
    52 #include "CMachine.h"
    53 #include "CMedium.h"
    54 #include "CVirtualBox.h"
    55 
    5647
    5748/* Type defs: */
     
    7667    , m_pLookupTimer(0)
    7768{
    78     /* Prepare: */
    7969    prepare();
    8070}
     
    8272UIChooserModel::~UIChooserModel()
    8373{
    84     /* Cleanup: */
    8574    cleanup();
    8675}
     
    9483    /* Load group tree: */
    9584    loadGroupTree();
    96 
    97     /* Update navigation: */
    9885    updateNavigation();
    99 
    100     /* Update layout: */
    10186    updateLayout();
    10287
     
    155140            emit sigToolMenuRequested(UIToolClass_Global, pItem->mapToScene(QPointF(pItem->size().width(), 0)).toPoint());
    156141            break;
    157         case UIChooserItemType_Group:
    158142        case UIChooserItemType_Machine:
    159143            emit sigToolMenuRequested(UIToolClass_Machine, pItem->mapToScene(QPointF(pItem->size().width(), 0)).toPoint());
     
    466450}
    467451
    468 void UIChooserModel::cleanupGroupTree()
    469 {
    470     cleanupGroupTree(root());
     452void UIChooserModel::wipeOutEmptyGroups()
     453{
     454    wipeOutEmptyGroups(root());
    471455}
    472456
     
    691675    if (fRegistered)
    692676    {
    693         /* Search for corresponding machine: */
     677        /* Show machine if we should: */
    694678        CMachine comMachine = vboxGlobal().virtualBox().FindMachine(uId.toString());
    695         /* Should we show this machine? */
    696679        if (gEDataManager->showMachineInSelectorChooser(uId))
    697680        {
    698681            /* Add new machine-item: */
    699             addMachineIntoTheTree(comMachine, true);
     682            addMachineIntoTheTree(comMachine, true /* make it visible */);
     683
    700684            /* And update model: */
    701685            updateNavigation();
    702686            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: */
    704689            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        }
    711694    }
    712695    /* Existing VM unregistered? */
     
    716699        root()->removeAllItems(uId.toString());
    717700        /* Update model: */
    718         cleanupGroupTree();
     701        wipeOutEmptyGroups();
     702
     703        /* And update model: */
    719704        updateNavigation();
    720705        updateLayout();
     706
    721707        /* Make sure current-item present, if possible: */
    722708        if (!currentItem() && !navigationList().isEmpty())
     
    841827                break;
    842828            }
     829            default:
     830                break;
    843831        }
    844832    }
     
    894882    if (pWizard->exec() == QDialog::Accepted)
    895883        m_uLastCreatedMachineId = pWizard->createdMachineId();
    896 
    897884    if (pWizard)
    898885        delete pWizard;
     
    910897        return;
    911898
    912     /* Create new group in the current root: */
     899    /* Create new group item in the current root: */
    913900    UIChooserItemGroup *pNewGroupItem = new UIChooserItemGroup(root(), uniqueGroupName(root()), true);
     901
    914902    /* Enumerate all the currently chosen items: */
    915903    QStringList busyGroupNames;
     
    949937
    950938    /* Update model: */
    951     cleanupGroupTree();
     939    wipeOutEmptyGroups();
    952940    updateNavigation();
    953941    updateLayout();
     
    961949    root()->removeAllItems(uId);
    962950    /* Wipe out empty groups: */
    963     cleanupGroupTree();
     951    wipeOutEmptyGroups();
    964952
    965953    /* Show machine if we should: */
    966954    CMachine comMachine = vboxGlobal().virtualBox().FindMachine(uId.toString());
    967955    if (gEDataManager->showMachineInSelectorChooser(uId))
     956    {
     957        /* Add new machine-item: */
    968958        addMachineIntoTheTree(comMachine);
    969959
    970     /* And update model: */
     960        /* And update model: */
    971961        updateNavigation();
    972962        updateLayout();
    973963
     964        /* Choose newly added item: */
     965        setCurrentItem(root()->searchForItem(comMachine.GetName(),
     966                                             UIChooserItemSearchFlag_Machine |
     967                                             UIChooserItemSearchFlag_ExactName));
     968    }
     969    else
     970    {
    974971        /* Make sure at least one item selected after that: */
    975972        if (!currentItem() && !navigationList().isEmpty())
    976973            setCurrentItem(navigationList().first());
     974    }
    977975
    978976    /* Notify listeners about selection change: */
     
    10161014        {
    10171015            /* Machine name: */
    1018             QString strMachineName = ((UIChooserItem*)pItem)->name();
     1016            const QString strMachineName = ((UIChooserItem*)pItem)->name();
    10191017            /* We should reload this machine: */
    10201018            sltReloadMachine(pItem->id());
     
    13771375
    13781376    /* 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);
    13801380}
    13811381
     
    15961596void UIChooserModel::loadGroupTree()
    15971597{
    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: */
    16021607        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
    16061612            if (!uMachineID.isNull() && gEDataManager->showMachineInSelectorChooser(uMachineID))
    1607             addMachineIntoTheTree(machine);
     1613                addMachineIntoTheTree(comMachine);
    16081614        }
    16091615        LogRelFlow(("UIChooserModel: VMs loaded.\n"));
    16101616    }
    1611 
    1612 void UIChooserModel::addMachineIntoTheTree(const CMachine &machine, bool fMakeItVisible /* = false */)
     1617}
     1618
     1619void UIChooserModel::addMachineIntoTheTree(const CMachine &comMachine, bool fMakeItVisible /* = false */)
    16131620{
    16141621    /* Make sure passed VM is not NULL: */
    1615     if (machine.isNull())
     1622    if (comMachine.isNull())
    16161623        LogRelFlow(("UIChooserModel: ERROR: Passed VM is NULL!\n"));
    1617     AssertReturnVoid(!machine.isNull());
     1624    AssertReturnVoid(!comMachine.isNull());
    16181625
    16191626    /* 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()));
    16211628    /* Is that machine accessible? */
    1622     if (machine.GetAccessible())
     1629    if (comMachine.GetAccessible())
    16231630    {
    16241631        /* VM is accessible: */
    1625         const QString strName = machine.GetName();
     1632        const QString strName = comMachine.GetName();
    16261633        LogRelFlow(("UIChooserModel:  VM {%s} is accessible.\n", strName.toUtf8().constData()));
    16271634        /* Which groups passed machine attached to? */
    1628         const QVector<QString> groups = machine.GetGroups();
     1635        const QVector<QString> groups = comMachine.GetGroups();
    16291636        const QStringList groupList = groups.toList();
    16301637        const QString strGroups = groupList.join(", ");
     
    16391646            LogRelFlow(("UIChooserModel:   Creating item for VM {%s} in group {%s}.\n", strName.toUtf8().constData(),
    16401647                                                                                        strGroup.toUtf8().constData()));
    1641             createMachineItem(machine, getGroupItem(strGroup, root(), fMakeItVisible));
     1648            createMachineItem(getGroupItem(strGroup, root(), fMakeItVisible), comMachine);
    16421649        }
    16431650        /* Update group definitions: */
    1644         m_groups[toOldStyleUuid(machine.GetId())] = groupList;
     1651        m_groups[toOldStyleUuid(comMachine.GetId())] = groupList;
    16451652    }
    16461653    /* Inaccessible machine: */
     
    16481655    {
    16491656        /* 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()));
    16511658        /* Create machine-item with main-root group-item as parent: */
    1652         createMachineItem(machine, root());
     1659        createMachineItem(root(), comMachine);
    16531660    }
    16541661}
     
    16811688                        pFoundGroupItem->open(false);
    16821689                return pFoundItem;
    1683         }
    1684     }
    1685 }
     1690            }
     1691        }
     1692    }
    16861693
    16871694    /* Found nothing? Creating: */
    16881695    UIChooserItemGroup *pNewGroupItem =
    1689             new UIChooserItemGroup(/* Parent item and desired group name: */
    1690                                     pParentItem, strSecondSubName,
    1691                                     /* Should be new group opened when created? */
    1692                                     fAllGroupsOpened || shouldBeGroupOpened(pParentItem, strSecondSubName),
    1693                                     /* Which position new group-item should be placed in? */
    1694                                     getDesiredPosition(pParentItem, UIChooserItemType_Group, strSecondSubName));
     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));
    16951702    return strSecondSuffix.isEmpty() ? pNewGroupItem : getGroupItem(strFirstSuffix, pNewGroupItem, fAllGroupsOpened);
    16961703}
     
    17241731}
    17251732
    1726 void UIChooserModel::cleanupGroupTree(UIChooserItem *pParent)
     1733void UIChooserModel::wipeOutEmptyGroups(UIChooserItem *pParent)
    17271734{
    17281735    /* Cleanup all the group-items recursively first: */
    17291736    foreach (UIChooserItem *pItem, pParent->items(UIChooserItemType_Group))
    1730         cleanupGroupTree(pItem);
     1737        wipeOutEmptyGroups(pItem);
    17311738    /* If parent has no items: */
    17321739    if (!pParent->hasItems())
    17331740    {
    1734         /* Cleanup if that is non-root item: */
     1741        /* If that is non-root item: */
    17351742        if (!pParent->isRoot())
     1743        {
     1744            /* Delete parent node and item: */
    17361745            delete pParent;
    1737             }
    1738         }
     1746        }
     1747    }
     1748}
    17391749
    17401750bool UIChooserModel::isGlobalItemFavorite(UIChooserItem *pParentItem) const
     
    17481758    /* Prepare required group definition reg-exp: */
    17491759    const QString strDefinitionTemplate = QString("n(\\S)*=GLOBAL");
    1750     const QRegExp definitionRegExp(strDefinitionTemplate);
     1760    const QRegExp definitionRegExp = QRegExp(strDefinitionTemplate);
    17511761    /* For each the group definition: */
    17521762    foreach (const QString &strDefinition, definitions)
     
    17661776}
    17671777
    1768 int UIChooserModel::getDesiredPosition(UIChooserItem *pParentItem, UIChooserItemType type, const QString &strName)
     1778int UIChooserModel::getDesiredPosition(UIChooserItem *pParentItem, UIChooserItemType enmType, const QString &strName)
    17691779{
    17701780    /* End of list (by default)? */
    17711781    int iNewItemDesiredPosition = -1;
    17721782    /* Which position should be new item placed by definitions: */
    1773     int iNewItemDefinitionPosition = positionFromDefinitions(pParentItem, type, strName);
     1783    int iNewItemDefinitionPosition = positionFromDefinitions(pParentItem, enmType, strName);
    17741784    /* If some position wanted: */
    17751785    if (iNewItemDefinitionPosition != -1)
     
    17781788        iNewItemDesiredPosition = 0;
    17791789        /* We have to check all the existing item positions: */
    1780         QList<UIChooserItem*> items = pParentItem->items(type);
     1790        QList<UIChooserItem*> items = pParentItem->items(enmType);
    17811791        for (int i = items.size() - 1; i >= 0; --i)
    17821792        {
     
    17881798                                        QString();
    17891799            AssertMsg(!strDefinitionName.isEmpty(), ("Wrong definition name!"));
    1790             int iItemDefinitionPosition = positionFromDefinitions(pParentItem, type, strDefinitionName);
     1800            int iItemDefinitionPosition = positionFromDefinitions(pParentItem, enmType, strDefinitionName);
    17911801            /* If some position wanted: */
    17921802            if (iItemDefinitionPosition != -1)
     
    18051815}
    18061816
    1807 int UIChooserModel::positionFromDefinitions(UIChooserItem *pParentItem, UIChooserItemType type, const QString &strName)
     1817int UIChooserModel::positionFromDefinitions(UIChooserItem *pParentItem, UIChooserItemType enmType, const QString &strName)
    18081818{
    18091819    /* Read group definitions: */
     
    18161826    QString strDefinitionTemplateShort;
    18171827    QString strDefinitionTemplateFull;
    1818     switch (type)
     1828    switch (enmType)
    18191829    {
    18201830        case UIChooserItemType_Group:
     
    18491859}
    18501860
    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);
     1861void 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())));
    18611867}
    18621868
    18631869void UIChooserModel::removeItems(const QList<UIChooserItem*> &itemsToRemove)
    18641870{
     1871
    18651872    /* Confirm machine-items removal: */
    18661873    QStringList names;
     
    18751882
    18761883    /* And update model: */
    1877     cleanupGroupTree();
     1884    wipeOutEmptyGroups();
    18781885    updateNavigation();
    18791886    updateLayout();
     
    20612068    foreach (UIChooserItem *pItem, pParentItem->items(UIChooserItemType_Machine))
    20622069        orders[strExtraDataKey] << QString("m=%1").arg(toOldStyleUuid(pItem->toMachineItem()->id()));
    2063     }
     2070}
    20642071
    20652072void UIChooserModel::makeSureGroupDefinitionsSaveIsFinished()
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.h

    r77601 r77604  
    2323
    2424/* Qt includes: */
    25 #include <QMap>
    26 #include <QObject>
    2725#include <QPointer>
    2826#include <QThread>
    29 #include <QTransform>
    3027#include <QUuid>
    3128
    3229/* GUI includes: */
    33 #include "UIChooserItem.h"
     30#include "UIChooserDefs.h"
    3431#include "UIExtraDataDefs.h"
    3532
     
    3936/* Forward declaration: */
    4037class QDrag;
    41 class QGraphicsItem;
    42 class QGraphicsScene;
    43 class QGraphicsSceneContextMenuEvent;
    44 class QMenu;
    45 class QPaintDevice;
    46 class QTimer;
    4738class UIActionPool;
    4839class UIChooser;
    4940class UIChooserHandlerMouse;
    5041class UIChooserHandlerKeyboard;
     42class UIChooserItem;
    5143class UIVirtualMachineItem;
    5244class CMachine;
     
    202194        void startEditingGroupItemName();
    203195
    204         /** Cleanups group tree. */
    205         void cleanupGroupTree();
     196        /** Wipes out empty groups. */
     197        void wipeOutEmptyGroups();
    206198
    207199        /** Activates machine item. */
     
    387379        bool shouldBeGroupOpened(UIChooserItem *pParentItem, const QString &strName);
    388380
    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);
    391383
    392384        /** Returns whether global item within the @a pParentItem is favorite. */
    393385        bool isGlobalItemFavorite(UIChooserItem *pParentItem) const;
    394386
    395         /** Acquires desired position for an child 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. */
    396388        int getDesiredPosition(UIChooserItem *pParentItem, UIChooserItemType enmType, const QString &strName);
    397         /** Acquires saved position for an child 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. */
    398390        int positionFromDefinitions(UIChooserItem *pParentItem, UIChooserItemType enmType, const QString &strName);
    399391
    400392        /** 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);
    404394
    405395        /** Removes machine @a items. */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette