VirtualBox

Ignore:
Timestamp:
Jun 4, 2018 8:01:05 AM (7 years ago)
Author:
vboxsync
Message:

FE/Qt bugref:9183 Showing the differencing disks as children of the mard drives in medium selection widget

Location:
trunk/src/VBox/Frontends/VirtualBox/src/medium
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSelector.cpp

    r72411 r72423  
    198198        case UIMediumType_Floppy:
    199199            return new UIMediumItemFD(medium, pParent);
    200 
    201200            break;
    202201        case UIMediumType_HardDisk:
     
    204203        case UIMediumType_Invalid:
    205204        default:
    206             return new UIMediumItemHD(medium, pParent);
     205            return createHardDiskItem(medium);
    207206            break;
    208207    }
     208}
     209
     210UIMediumItem* UIMediumSelector::createHardDiskItem(const UIMedium &medium)
     211{
     212    if (medium.medium().isNull())
     213        return 0;
     214    if (!m_pTreeWidget)
     215        return 0;
     216    printf("%s\n", qPrintable(medium.id()));
     217    /* Search the tree to see if we already have the item: */
     218    UIMediumItem *pMediumItem = searchItem(0, medium.id());
     219    if (pMediumItem)
     220        return pMediumItem;
     221    /* Check if the corresponding medium has a parent */
     222    if (medium.parentID() != UIMedium::nullID())
     223    {
     224        UIMediumItem *pParentMediumItem = searchItem(0, medium.parentID());
     225        /* If parent medium-item was not found we create it: */
     226        if (!pParentMediumItem)
     227        {
     228            /* Make sure corresponding parent medium is already cached! */
     229            UIMedium parentMedium = vboxGlobal().medium(medium.parentID());
     230            if (parentMedium.isNull())
     231                AssertMsgFailed(("Parent medium with ID={%s} was not found!\n", medium.parentID().toUtf8().constData()));
     232            /* Try to create parent medium-item: */
     233            else
     234                pParentMediumItem = createHardDiskItem(parentMedium);
     235            /* If parent medium-item was found: */
     236            if (pParentMediumItem)
     237            {
     238                pMediumItem = new UIMediumItemHD(medium, pParentMediumItem);
     239                LogRel2(("UIMediumManager: Child hard-disk medium-item with ID={%s} created.\n", medium.id().toUtf8().constData()));
     240            }
     241            else
     242                AssertMsgFailed(("Parent medium with ID={%s} could not be created!\n", medium.parentID().toUtf8().constData()));
     243
     244        }
     245    }
     246    /* Else just create item as top-level one: */
     247    else
     248    {
     249        pMediumItem = new UIMediumItemHD(medium, m_pTreeWidget);
     250        LogRel2(("UIMediumManager: Root hard-disk medium-item with ID={%s} created.\n", medium.id().toUtf8().constData()));
     251    }
     252    return pMediumItem;
    209253}
    210254
     
    397441    m_pAttachedSubTreeRoot = 0;
    398442    m_pNotAttachedSubTreeRoot = 0;
    399     QVector<UIMediumItem*> menuItemList;
     443    QVector<UIMediumItem*> menuItemVector;
    400444
    401445    foreach (const QString &strMediumID, vboxGlobal().mediumIDs())
     
    428472                pParent = m_pNotAttachedSubTreeRoot;
    429473            }
    430             menuItemList.push_back(addTreeItem(medium, pParent));
     474            menuItemVector.push_back(addTreeItem(medium, pParent));
    431475        }
    432476    }
    433     restoreSelection(selectedMediums, menuItemList);
     477    restoreSelection(selectedMediums, menuItemVector);
    434478
    435479    updateOkButton();
     
    439483    if (m_pNotAttachedSubTreeRoot)
    440484        m_pTreeWidget->expandItem(m_pNotAttachedSubTreeRoot);
    441 
    442 }
     485}
     486
     487UIMediumItem* UIMediumSelector::searchItem(const QTreeWidgetItem *pParent, const QString &mediumId)
     488{
     489    if (!m_pTreeWidget)
     490        return 0;
     491    if (!pParent)
     492    {
     493        pParent = m_pTreeWidget->invisibleRootItem();
     494    }
     495    if (!pParent)
     496        return 0;
     497
     498    for (int i = 0; i < pParent->childCount(); ++i)
     499    {
     500        QTreeWidgetItem *pChild = pParent->child(i);
     501        if (!pChild)
     502            continue;
     503        UIMediumItem *mediumItem = dynamic_cast<UIMediumItem*>(pChild);
     504        if (mediumItem)
     505        {
     506            if (mediumItem->id() == mediumId)
     507                return mediumItem;
     508        }
     509        searchItem(pChild, mediumId);
     510    }
     511    return 0;
     512}
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSelector.h

    r72410 r72423  
    8888    UIMediumItem* addTreeItem(const UIMedium &medium, QITreeWidgetItem *pParent);
    8989    void restoreSelection(const QStringList &selectedMediums, QVector<UIMediumItem*> &mediumList);
     90    UIMediumItem* createHardDiskItem(const UIMedium &medium);
     91    UIMediumItem* searchItem(const QTreeWidgetItem *pParent, const QString &mediumId);
    9092
    9193    QVBoxLayout       *m_pMainLayout;
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