VirtualBox

Changeset 82917 in vbox for trunk


Ignore:
Timestamp:
Jan 29, 2020 6:28:06 PM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9653: VirtualBox Manager: Chooser pane: Rework UIChooserNodeMachine to use composition approach over inheritance from UIVirtualMachineItem; That allows us to sub-class UIVirtualMachineItem for cloud VM needs.

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

Legend:

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

    r80881 r82917  
    503503            /* Which position should be current node placed by definitions? */
    504504            QString strDefinitionName = pNode->type() == UIChooserItemType_Group ? pNode->name() :
    505                                         pNode->type() == UIChooserItemType_Machine ? toOldStyleUuid(pNode->toMachineNode()->id()) :
     505                                        pNode->type() == UIChooserItemType_Machine ? toOldStyleUuid(pNode->toMachineNode()->cache()->id()) :
    506506                                        QString();
    507507            AssertMsg(!strDefinitionName.isEmpty(), ("Wrong definition name!"));
     
    620620    foreach (UIChooserNode *pNode, pParentGroup->nodes(UIChooserItemType_Machine))
    621621        if (UIChooserNodeMachine *pMachineNode = pNode->toMachineNode())
    622             if (pMachineNode->accessible())
    623                 definitions[toOldStyleUuid(pMachineNode->id())] << pParentGroup->fullName();
     622            if (pMachineNode->cache()->accessible())
     623                definitions[toOldStyleUuid(pMachineNode->cache()->id())] << pParentGroup->fullName();
    624624    /* Iterate over all the group-nodes: */
    625625    foreach (UIChooserNode *pNode, pParentGroup->nodes(UIChooserItemType_Group))
     
    647647    /* Iterate over all the machine-nodes: */
    648648    foreach (UIChooserNode *pNode, pParentItem->nodes(UIChooserItemType_Machine))
    649         orders[strExtraDataKey] << QString("m=%1").arg(toOldStyleUuid(pNode->toMachineNode()->id()));
     649        orders[strExtraDataKey] << QString("m=%1").arg(toOldStyleUuid(pNode->toMachineNode()->cache()->id()));
    650650}
    651651
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGroup.cpp

    r79461 r82917  
    322322        int iCountOfStartedMachineItems = 0;
    323323        foreach (UIChooserItem *pItem, items(UIChooserItemType_Machine))
    324             if (UIVirtualMachineItem::isItemStarted(pItem->node()->toMachineNode()))
     324            if (UIVirtualMachineItem::isItemStarted(pItem->node()->toMachineNode()->cache()))
    325325                ++iCountOfStartedMachineItems;
    326326        /* Template: */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemMachine.cpp

    r79388 r82917  
    6060QUuid UIChooserItemMachine::id() const
    6161{
    62     return node()->toMachineNode()->id();
     62    return node()->toMachineNode()->cache()->id();
    6363}
    6464
    6565bool UIChooserItemMachine::accessible() const
    6666{
    67     return node()->toMachineNode()->accessible();
     67    return node()->toMachineNode()->cache()->accessible();
    6868}
    6969
    7070void UIChooserItemMachine::recache()
    7171{
    72     node()->toMachineNode()->recache();
     72    node()->toMachineNode()->cache()->recache();
    7373}
    7474
    7575bool UIChooserItemMachine::isLockedMachine() const
    7676{
    77     const KMachineState enmState = node()->toMachineNode()->machineState();
     77    const KMachineState enmState = node()->toMachineNode()->cache()->machineState();
    7878    return enmState != KMachineState_PoweredOff &&
    7979           enmState != KMachineState_Saved &&
     
    153153
    154154    /* Recache and update pixmaps: */
    155     node()->toMachineNode()->recachePixmap();
     155    node()->toMachineNode()->cache()->recachePixmap();
    156156    updatePixmaps();
    157157}
     
    219219void UIChooserItemMachine::updateToolTip()
    220220{
    221     setToolTip(node()->toMachineNode()->toolTipText());
     221    setToolTip(node()->toMachineNode()->cache()->toolTipText());
    222222}
    223223
     
    289289    /* And machine-item content to take into account: */
    290290    int iTopLineWidth = m_iMinimumNameWidth;
    291     if (!node()->toMachineNode()->snapshotName().isEmpty())
     291    if (!node()->toMachineNode()->cache()->snapshotName().isEmpty())
    292292        iTopLineWidth += (iMinorSpacing +
    293293                          m_iMinimumSnapshotNameWidth);
     
    472472{
    473473    /* Recache and update pixmaps: */
    474     node()->toMachineNode()->recachePixmap();
     474    node()->toMachineNode()->cache()->recachePixmap();
    475475    updatePixmaps();
    476476}
     
    589589    /* Get new pixmap and pixmap-size: */
    590590    QSize pixmapSize;
    591     QPixmap pixmap = node()->toMachineNode()->osPixmap(&pixmapSize);
     591    QPixmap pixmap = node()->toMachineNode()->cache()->osPixmap(&pixmapSize);
    592592    /* Update linked values: */
    593593    if (m_pixmapSize != pixmapSize)
     
    609609    const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
    610610    /* Get new state-pixmap and state-pixmap size: */
    611     const QIcon stateIcon = node()->toMachineNode()->machineStateIcon();
     611    const QIcon stateIcon = node()->toMachineNode()->cache()->machineStateIcon();
    612612    AssertReturnVoid(!stateIcon.isNull());
    613613    const QSize statePixmapSize = QSize(iIconMetric, iIconMetric);
     
    700700    int iMinimumSnapshotNameWidth = 0;
    701701    /* Is there any snapshot exists? */
    702     if (!node()->toMachineNode()->snapshotName().isEmpty())
     702    if (!node()->toMachineNode()->cache()->snapshotName().isEmpty())
    703703    {
    704704        QFontMetrics fm(m_snapshotNameFont, model()->paintDevice());
    705705        int iBracketWidth = fm.width("()"); /* bracket width */
    706         int iActualTextWidth = fm.width(node()->toMachineNode()->snapshotName()); /* snapshot-name width */
     706        int iActualTextWidth = fm.width(node()->toMachineNode()->cache()->snapshotName()); /* snapshot-name width */
    707707        int iMinimumTextWidth = fm.width("..."); /* ellipsis width */
    708708        iMinimumSnapshotNameWidth = iBracketWidth + qMin(iActualTextWidth, iMinimumTextWidth);
     
    789789    /* Calculate new visible snapshot-name: */
    790790    int iBracketWidth = QFontMetrics(m_snapshotNameFont, pPaintDevice).width("()");
    791     QString strVisibleSnapshotName = compressText(m_snapshotNameFont, pPaintDevice, node()->toMachineNode()->snapshotName(),
     791    QString strVisibleSnapshotName = compressText(m_snapshotNameFont, pPaintDevice, node()->toMachineNode()->cache()->snapshotName(),
    792792                                                  m_iMaximumSnapshotNameWidth - iBracketWidth);
    793793    strVisibleSnapshotName = QString("(%1)").arg(strVisibleSnapshotName);
     
    810810{
    811811    /* Get new state-text and state-text size: */
    812     const QSize stateTextSize = textSize(m_stateTextFont, model()->paintDevice(), node()->toMachineNode()->machineStateName());
     812    const QSize stateTextSize = textSize(m_stateTextFont, model()->paintDevice(), node()->toMachineNode()->cache()->machineStateName());
    813813
    814814    /* Update linked values: */
     
    10871087
    10881088            /* Paint middle element: */
    1089             if (!node()->toMachineNode()->snapshotName().isEmpty())
     1089            if (!node()->toMachineNode()->cache()->snapshotName().isEmpty())
    10901090            {
    10911091                /* Prepare variables: */
     
    11451145                          model()->paintDevice(),
    11461146                          /* Text to paint: */
    1147                           node()->toMachineNode()->machineStateName());
     1147                          node()->toMachineNode()->cache()->machineStateName());
    11481148            }
    11491149        }
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.cpp

    r80881 r82917  
    282282{
    283283    /* Return first machine-item of the selected-item: */
    284     return   firstSelectedItem() && firstSelectedItem()->firstMachineItem() && firstSelectedItem()->firstMachineItem()->node()
    285            ? firstSelectedItem()->firstMachineItem()->node()->toMachineNode()
     284    return      firstSelectedItem()
     285             && firstSelectedItem()->firstMachineItem()
     286             && firstSelectedItem()->firstMachineItem()->node()
     287             && firstSelectedItem()->firstMachineItem()->node()->toMachineNode()
     288           ? firstSelectedItem()->firstMachineItem()->node()->toMachineNode()->cache()
    286289           : 0;
    287290}
     
    297300    QList<UIVirtualMachineItem*> currentMachineList;
    298301    foreach (UIChooserItemMachine *pItem, currentMachineItemList)
    299         currentMachineList << pItem->node()->toMachineNode();
     302        currentMachineList << pItem->node()->toMachineNode()->cache();
    300303    return currentMachineList;
    301304}
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNodeMachine.cpp

    r77847 r82917  
    2525                                           const CMachine &comMachine)
    2626    : UIChooserNode(pParent, fFavorite)
    27     , UIVirtualMachineItem(comMachine)
     27    , m_pCache(new UIVirtualMachineItem(comMachine))
    2828{
    2929    if (parentNode())
     
    3636                                           int iPosition)
    3737    : UIChooserNode(pParent, pCopyFrom->isFavorite())
    38     , UIVirtualMachineItem(pCopyFrom->machine())
     38    , m_pCache(new UIVirtualMachineItem(pCopyFrom->cache()->machine()))
    3939{
    4040    if (parentNode())
     
    5252QString UIChooserNodeMachine::name() const
    5353{
    54     return UIVirtualMachineItem::name();
     54    return m_pCache->name();
    5555}
    5656
     
    104104{
    105105    /* Skip other ids: */
    106     if (id() != uId)
     106    if (m_pCache->id() != uId)
    107107        return;
    108108
     
    114114{
    115115    /* Skip other ids: */
    116     if (id() != uId)
     116    if (m_pCache->id() != uId)
    117117        return;
    118118
    119     /* Update machine-node: */
    120     recache();
     119    /* Update cache: */
     120    m_pCache->recache();
    121121
    122122    /* Update machine-item: */
     
    160160void UIChooserNodeMachine::retranslateUi()
    161161{
    162     /* Update description: */
     162    /* Update internal stuff: */
    163163    m_strDescription = tr("Virtual Machine");
    164164
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNodeMachine.h

    r77847 r82917  
    2828
    2929/** UIChooserNode subclass used as interface for invisible tree-view machine nodes. */
    30 class UIChooserNodeMachine : public UIChooserNode, public UIVirtualMachineItem
     30class UIChooserNodeMachine : public UIChooserNode
    3131{
    3232    Q_OBJECT;
     
    8787    virtual void sortNodes() /* override */;
    8888
     89    /** Returns virtual machine cache instance. */
     90    UIVirtualMachineItem *cache() const { return m_pCache; }
     91
    8992protected:
    9093
    9194    /** Handles translation event. */
    9295    virtual void retranslateUi() /* override */;
     96
     97private:
     98
     99    /** Holds virtual machine cache instance. */
     100    UIVirtualMachineItem *m_pCache;
    93101};
    94102
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