Changeset 49582 in vbox
- Timestamp:
- Nov 20, 2013 12:33:17 PM (11 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/medium
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.cpp
r49581 r49582 146 146 147 147 148 /* Medium-item iterator:*/149 class UIMediumItemIterator : public QTreeWidgetItemIterator148 /** Functor allowing to check if passed UIMediumItem is suitable by ID. */ 149 class CheckIfSuitableByID : public CheckIfSuitableBy 150 150 { 151 151 public: 152 153 UIMediumItemIterator(QTreeWidget *pTree) 154 : QTreeWidgetItemIterator(pTree) {} 155 156 UIMediumItem* operator*() 157 { 158 QTreeWidgetItem *pItem = QTreeWidgetItemIterator::operator*(); 159 return pItem && pItem->type() == UIMediumItem::Type ? 160 static_cast<UIMediumItem*>(pItem) : 0; 161 } 162 163 UIMediumItemIterator& operator++() 164 { 165 return static_cast<UIMediumItemIterator&>(QTreeWidgetItemIterator::operator++()); 166 } 152 /** Constructor. */ 153 CheckIfSuitableByID(const QString &strID) : m_strID(strID) {} 154 155 private: 156 /** Determines whether passed UIMediumItem is suitable by ID. */ 157 bool isItSuitable(UIMediumItem *pItem) const { return pItem->id() == m_strID; } 158 /** Holds the ID to compare to. */ 159 QString m_strID; 160 }; 161 162 /** Functor allowing to check if passed UIMediumItem is suitable by @a state. */ 163 class CheckIfSuitableByState : public CheckIfSuitableBy 164 { 165 public: 166 /** Constructor. */ 167 CheckIfSuitableByState(KMediumState state) : m_state(state) {} 168 169 private: 170 /** Determines whether passed UIMediumItem is suitable by @a state. */ 171 bool isItSuitable(UIMediumItem *pItem) const { return pItem->state() == m_state; } 172 /** Holds the @a state to compare to. */ 173 KMediumState m_state; 167 174 }; 168 175 … … 345 352 { 346 353 pTree = treeWidget(type); 347 pMediumItem = searchItem(pTree, strMediumID);354 pMediumItem = searchItem(pTree, CheckIfSuitableByID(strMediumID)); 348 355 if (pMediumItem) 349 356 break; … … 437 444 switch (medium.type()) 438 445 { 439 case UIMediumType_HardDisk: pMediumItem = searchItem(mTwHD, medium.id()); break;440 case UIMediumType_DVD: pMediumItem = searchItem(mTwCD, medium.id()); break;441 case UIMediumType_Floppy: pMediumItem = searchItem(mTwFD, medium.id()); break;446 case UIMediumType_HardDisk: pMediumItem = searchItem(mTwHD, CheckIfSuitableByID(medium.id())); break; 447 case UIMediumType_DVD: pMediumItem = searchItem(mTwCD, CheckIfSuitableByID(medium.id())); break; 448 case UIMediumType_Floppy: pMediumItem = searchItem(mTwFD, CheckIfSuitableByID(medium.id())); break; 442 449 default: AssertFailed(); 443 450 } … … 1468 1475 } 1469 1476 1470 UIMediumItem* UIMediumManager::searchItem(QTreeWidget *pTree, const QString &strId) const1471 { 1472 /* Make sure passed IDis valid: */1473 if ( strId.isNull())1477 UIMediumItem* UIMediumManager::searchItem(QTreeWidget *pTree, const CheckIfSuitableBy &functor) const 1478 { 1479 /* Make sure argument is valid: */ 1480 if (!pTree) 1474 1481 return 0; 1475 1482 1476 /* Iterate other all the mediums of passed tree: */ 1477 UIMediumItemIterator iterator(pTree); 1478 while (*iterator) 1479 { 1480 if ((*iterator)->id() == strId) 1481 return *iterator; 1482 ++iterator; 1483 } 1483 /* Return wrapper: */ 1484 return searchItem(pTree->invisibleRootItem(), functor); 1485 } 1486 1487 UIMediumItem* UIMediumManager::searchItem(QTreeWidgetItem *pParentItem, const CheckIfSuitableBy &functor) const 1488 { 1489 /* Make sure argument is valid: */ 1490 if (!pParentItem) 1491 return 0; 1492 1493 /* Verify passed item if it is of 'medium' type too: */ 1494 if (UIMediumItem *pMediumParentItem = toMediumItem(pParentItem)) 1495 if (functor.isItSuitable(pMediumParentItem)) 1496 return pMediumParentItem; 1497 1498 /* Iterate other all the children: */ 1499 for (int iChildIndex = 0; iChildIndex < pParentItem->childCount(); ++iChildIndex) 1500 if (UIMediumItem *pMediumChildItem = toMediumItem(pParentItem->child(iChildIndex))) 1501 if (UIMediumItem *pRequiredMediumChildItem = searchItem(pMediumChildItem, functor)) 1502 return pRequiredMediumChildItem; 1484 1503 1485 1504 /* Null by default: */ … … 1497 1516 /* First try to create item under corresponding parent: */ 1498 1517 if (medium.parentID() != UIMedium::nullID()) 1499 if (UIMediumItem *pRoot = searchItem(pTree, medium.parentID()))1518 if (UIMediumItem *pRoot = searchItem(pTree, CheckIfSuitableByID(medium.parentID()))) 1500 1519 pMediumItem = new UIMediumItem(medium, pRoot); 1501 1520 /* Else just create item as top-level one: */ … … 1575 1594 if (fCheckRest) 1576 1595 { 1577 *pfInaccessible = false; 1578 1579 QTreeWidget *pTree = pMediumItem->treeWidget(); 1580 1581 /* Find the first pfInaccessible item to be in charge: */ 1582 UIMediumItemIterator it(pTree); 1583 for (; *it; ++ it) 1584 { 1585 if (*it != pMediumItem && (*it)->state() == KMediumState_Inaccessible) 1586 { 1587 *pfInaccessible = true; 1588 break; 1589 } 1590 } 1596 /* Find the first KMediumState_Inaccessible item to be in charge: */ 1597 UIMediumItem *pInaccessibleMediumItem = 1598 searchItem(pMediumItem->treeWidget(), CheckIfSuitableByState(KMediumState_Inaccessible)); 1599 *pfInaccessible = !!pInaccessibleMediumItem; 1591 1600 } 1592 1601 -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.h
r49581 r49582 36 36 class UIEnumerationProgressBar; 37 37 class UIMedium; 38 39 /** Functor interface allowing to check if passed UIMediumItem is suitable. */ 40 class CheckIfSuitableBy 41 { 42 public: 43 /** Determines whether passed UIMediumItem is suitable. */ 44 virtual bool isItSuitable(UIMediumItem *pItem) const = 0; 45 }; 38 46 39 47 /* Medium Manager Dialog: */ … … 134 142 void setCurrentItem(QTreeWidget *pTree, QTreeWidgetItem *pItem); 135 143 UIMediumItem* toMediumItem(QTreeWidgetItem *pItem) const; 136 UIMediumItem* searchItem(QTreeWidget *pTree, const QString &strId) const; 144 UIMediumItem* searchItem(QTreeWidget *pTree, const CheckIfSuitableBy &functor) const; 145 UIMediumItem* searchItem(QTreeWidgetItem *pParentItem, const CheckIfSuitableBy &functor) const; 137 146 UIMediumItem* createHardDiskItem(QTreeWidget *pTree, const UIMedium &medium) const; 138 147
Note:
See TracChangeset
for help on using the changeset viewer.