Changeset 72423 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Jun 4, 2018 8:01:05 AM (7 years ago)
- 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 198 198 case UIMediumType_Floppy: 199 199 return new UIMediumItemFD(medium, pParent); 200 201 200 break; 202 201 case UIMediumType_HardDisk: … … 204 203 case UIMediumType_Invalid: 205 204 default: 206 return new UIMediumItemHD(medium, pParent);205 return createHardDiskItem(medium); 207 206 break; 208 207 } 208 } 209 210 UIMediumItem* 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; 209 253 } 210 254 … … 397 441 m_pAttachedSubTreeRoot = 0; 398 442 m_pNotAttachedSubTreeRoot = 0; 399 QVector<UIMediumItem*> menuItem List;443 QVector<UIMediumItem*> menuItemVector; 400 444 401 445 foreach (const QString &strMediumID, vboxGlobal().mediumIDs()) … … 428 472 pParent = m_pNotAttachedSubTreeRoot; 429 473 } 430 menuItem List.push_back(addTreeItem(medium, pParent));474 menuItemVector.push_back(addTreeItem(medium, pParent)); 431 475 } 432 476 } 433 restoreSelection(selectedMediums, menuItem List);477 restoreSelection(selectedMediums, menuItemVector); 434 478 435 479 updateOkButton(); … … 439 483 if (m_pNotAttachedSubTreeRoot) 440 484 m_pTreeWidget->expandItem(m_pNotAttachedSubTreeRoot); 441 442 } 485 } 486 487 UIMediumItem* 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 88 88 UIMediumItem* addTreeItem(const UIMedium &medium, QITreeWidgetItem *pParent); 89 89 void restoreSelection(const QStringList &selectedMediums, QVector<UIMediumItem*> &mediumList); 90 UIMediumItem* createHardDiskItem(const UIMedium &medium); 91 UIMediumItem* searchItem(const QTreeWidgetItem *pParent, const QString &mediumId); 90 92 91 93 QVBoxLayout *m_pMainLayout;
Note:
See TracChangeset
for help on using the changeset viewer.