Changeset 102951 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Jan 18, 2024 1:20:03 PM (13 months ago)
- svn:sync-xref-src-repo-rev:
- 161179
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/settings/editors/UIStorageSettingsEditor.cpp
r102937 r102951 680 680 virtual ~StorageModel() RT_OVERRIDE; 681 681 682 /** Returns platform architecture. */683 KPlatformArchitecture arch() const;684 685 682 /** Returns row count for the passed @a parentIndex. */ 686 int rowCount(const QModelIndex &parentIndex = QModelIndex()) const;683 virtual int rowCount(const QModelIndex &parentIndex = QModelIndex()) const RT_OVERRIDE; 687 684 /** Returns column count for the passed @a parentIndex. */ 688 int columnCount(const QModelIndex &parentIndex = QModelIndex()) const;685 virtual int columnCount(const QModelIndex &parentIndex = QModelIndex()) const RT_OVERRIDE; 689 686 690 687 /** Returns root item. */ 691 688 QModelIndex root() const; 692 689 /** Returns item specified by @a iRow, @a iColum and @a parentIndex. */ 693 QModelIndex index(int iRow, int iColumn, const QModelIndex &parentIndex = QModelIndex()) const;690 virtual QModelIndex index(int iRow, int iColumn, const QModelIndex &parentIndex = QModelIndex()) const RT_OVERRIDE; 694 691 /** Returns parent item of @a specifiedIndex item. */ 695 QModelIndex parent(const QModelIndex &specifiedIndex) const;692 virtual QModelIndex parent(const QModelIndex &specifiedIndex) const RT_OVERRIDE; 696 693 697 694 /** Returns model data for @a specifiedIndex and @a iRole. */ 698 QVariant data(const QModelIndex &specifiedIndex, int iRole) const;695 virtual QVariant data(const QModelIndex &specifiedIndex, int iRole) const RT_OVERRIDE; 699 696 /** Defines model data for @a specifiedIndex and @a iRole as @a value. */ 700 bool setData(const QModelIndex &specifiedIndex, const QVariant &value, int iRole); 697 virtual bool setData(const QModelIndex &specifiedIndex, const QVariant &value, int iRole) RT_OVERRIDE; 698 699 /** Sorts the contents of model by @a iColumn and @a enmOrder. */ 700 virtual void sort(int iColumn = 0, Qt::SortOrder enmOrder = Qt::AscendingOrder) RT_OVERRIDE; 701 702 /** Clears model of all contents. */ 703 void clear(); 701 704 702 705 /** Adds controller with certain @a strCtrName, @a enmBus and @a enmType. */ … … 715 718 KDeviceType attachmentDeviceType(const QUuid &uCtrId, const QUuid &uAttId) const; 716 719 717 /** Sorts the contents of model by @a iColumn and @a enmOrder. */718 void sort(int iColumn = 0, Qt::SortOrder enmOrder = Qt::AscendingOrder);720 /** Returns platform architecture. */ 721 KPlatformArchitecture arch() const; 719 722 720 723 /** Returns chipset type. */ … … 725 728 /** Defines @a enmConfigurationAccessLevel. */ 726 729 void setConfigurationAccessLevel(ConfigurationAccessLevel enmConfigurationAccessLevel); 727 728 /** Clears model of all contents. */729 void clear();730 730 731 731 /** Returns current controller types. */ … … 1725 1725 } 1726 1726 1727 KPlatformArchitecture StorageModel::arch() const1728 {1729 return m_pParentEditor ? m_pParentEditor->arch() : KPlatformArchitecture_x86;1730 }1731 1732 1727 int StorageModel::rowCount(const QModelIndex &parentIndex) const 1733 1728 { … … 2456 2451 } 2457 2452 2458 QModelIndex StorageModel::addController(const QString &aCtrName, KStorageBus enmBus, KStorageControllerType enmType)2459 {2460 beginInsertRows(root(), m_pRootItem->childCount(), m_pRootItem->childCount());2461 new ControllerItem(this, m_pRootItem, aCtrName, enmBus, enmType);2462 endInsertRows();2463 return index(m_pRootItem->childCount() - 1, 0, root());2464 }2465 2466 void StorageModel::delController(const QUuid &uCtrId)2467 {2468 if (AbstractItem *pItem = m_pRootItem->childItemById(uCtrId))2469 {2470 int iItemPosition = m_pRootItem->posOfChild(pItem);2471 beginRemoveRows(root(), iItemPosition, iItemPosition);2472 delete pItem;2473 endRemoveRows();2474 }2475 }2476 2477 QModelIndex StorageModel::addAttachment(const QUuid &uCtrId, KDeviceType enmDeviceType, const QUuid &uMediumId)2478 {2479 if (AbstractItem *pParentItem = m_pRootItem->childItemById(uCtrId))2480 {2481 int iParentPosition = m_pRootItem->posOfChild(pParentItem);2482 QModelIndex parentIndex = index(iParentPosition, 0, root());2483 beginInsertRows(parentIndex, pParentItem->childCount(), pParentItem->childCount());2484 AttachmentItem *pItem = new AttachmentItem(pParentItem, enmDeviceType);2485 pItem->setHotPluggable(m_enmConfigurationAccessLevel != ConfigurationAccessLevel_Full);2486 pItem->setMediumId(uMediumId);2487 endInsertRows();2488 return index(pParentItem->childCount() - 1, 0, parentIndex);2489 }2490 return QModelIndex();2491 }2492 2493 void StorageModel::delAttachment(const QUuid &uCtrId, const QUuid &uAttId)2494 {2495 if (AbstractItem *pParentItem = m_pRootItem->childItemById(uCtrId))2496 {2497 int iParentPosition = m_pRootItem->posOfChild(pParentItem);2498 if (AbstractItem *pItem = pParentItem->childItemById(uAttId))2499 {2500 int iItemPosition = pParentItem->posOfChild(pItem);2501 beginRemoveRows(index(iParentPosition, 0, root()), iItemPosition, iItemPosition);2502 delete pItem;2503 endRemoveRows();2504 }2505 }2506 }2507 2508 void StorageModel::moveAttachment(const QUuid &uAttId, const QUuid &uCtrOldId, const QUuid &uCtrNewId)2509 {2510 /* No known info about attachment device type and medium ID: */2511 KDeviceType enmDeviceType = KDeviceType_Null;2512 QUuid uMediumId;2513 2514 /* First of all we are looking for old controller item: */2515 AbstractItem *pOldItem = m_pRootItem->childItemById(uCtrOldId);2516 if (pOldItem)2517 {2518 /* And acquire controller position: */2519 const int iOldCtrPosition = m_pRootItem->posOfChild(pOldItem);2520 2521 /* Then we are looking for an attachment item: */2522 if (AbstractItem *pSubItem = pOldItem->childItemById(uAttId))2523 {2524 /* And make sure this is really an attachment: */2525 AttachmentItem *pSubItemAttachment = qobject_cast<AttachmentItem*>(pSubItem);2526 if (pSubItemAttachment)2527 {2528 /* This way we can acquire actual attachment device type and medium ID: */2529 enmDeviceType = pSubItemAttachment->deviceType();2530 uMediumId = pSubItemAttachment->mediumId();2531 2532 /* And delete atachment item finally: */2533 const int iAttPosition = pOldItem->posOfChild(pSubItem);2534 beginRemoveRows(index(iOldCtrPosition, 0, root()), iAttPosition, iAttPosition);2535 delete pSubItem;2536 endRemoveRows();2537 }2538 }2539 }2540 2541 /* As the last step we are looking for new controller item: */2542 AbstractItem *pNewItem = m_pRootItem->childItemById(uCtrNewId);2543 if (pNewItem)2544 {2545 /* And acquire controller position: */2546 const int iNewCtrPosition = m_pRootItem->posOfChild(pNewItem);2547 2548 /* Then we have to make sure moved attachment is valid: */2549 if (enmDeviceType != KDeviceType_Null)2550 {2551 /* And create new attachment item finally: */2552 QModelIndex newCtrIndex = index(iNewCtrPosition, 0, root());2553 beginInsertRows(newCtrIndex, pNewItem->childCount(), pNewItem->childCount());2554 AttachmentItem *pItem = new AttachmentItem(pNewItem, enmDeviceType);2555 pItem->setHotPluggable(m_enmConfigurationAccessLevel != ConfigurationAccessLevel_Full);2556 pItem->setMediumId(uMediumId);2557 endInsertRows();2558 }2559 }2560 }2561 2562 KDeviceType StorageModel::attachmentDeviceType(const QUuid &uCtrId, const QUuid &uAttId) const2563 {2564 /* First of all we are looking for top-level (controller) item: */2565 AbstractItem *pTopLevelItem = m_pRootItem->childItemById(uCtrId);2566 if (pTopLevelItem)2567 {2568 /* Then we are looking for sub-level (attachment) item: */2569 AbstractItem *pSubLevelItem = pTopLevelItem->childItemById(uAttId);2570 if (pSubLevelItem)2571 {2572 /* And make sure this is really an attachment: */2573 AttachmentItem *pAttachmentItem = qobject_cast<AttachmentItem*>(pSubLevelItem);2574 if (pAttachmentItem)2575 {2576 /* This way we can acquire actual attachment device type: */2577 return pAttachmentItem->deviceType();2578 }2579 }2580 }2581 2582 /* Null by default: */2583 return KDeviceType_Null;2584 }2585 2586 2453 void StorageModel::sort(int /* iColumn */, Qt::SortOrder enmOrder) 2587 2454 { … … 2639 2506 } 2640 2507 2641 KChipsetType StorageModel::chipsetType() const2642 {2643 return m_enmChipsetType;2644 }2645 2646 void StorageModel::setChipsetType(KChipsetType enmChipsetType)2647 {2648 m_enmChipsetType = enmChipsetType;2649 }2650 2651 void StorageModel::setConfigurationAccessLevel(ConfigurationAccessLevel enmConfigurationAccessLevel)2652 {2653 m_enmConfigurationAccessLevel = enmConfigurationAccessLevel;2654 }2655 2656 2508 void StorageModel::clear() 2657 2509 { … … 2662 2514 endRemoveRows(); 2663 2515 } 2516 } 2517 2518 QModelIndex StorageModel::addController(const QString &aCtrName, KStorageBus enmBus, KStorageControllerType enmType) 2519 { 2520 beginInsertRows(root(), m_pRootItem->childCount(), m_pRootItem->childCount()); 2521 new ControllerItem(this, m_pRootItem, aCtrName, enmBus, enmType); 2522 endInsertRows(); 2523 return index(m_pRootItem->childCount() - 1, 0, root()); 2524 } 2525 2526 void StorageModel::delController(const QUuid &uCtrId) 2527 { 2528 if (AbstractItem *pItem = m_pRootItem->childItemById(uCtrId)) 2529 { 2530 int iItemPosition = m_pRootItem->posOfChild(pItem); 2531 beginRemoveRows(root(), iItemPosition, iItemPosition); 2532 delete pItem; 2533 endRemoveRows(); 2534 } 2535 } 2536 2537 QModelIndex StorageModel::addAttachment(const QUuid &uCtrId, KDeviceType enmDeviceType, const QUuid &uMediumId) 2538 { 2539 if (AbstractItem *pParentItem = m_pRootItem->childItemById(uCtrId)) 2540 { 2541 int iParentPosition = m_pRootItem->posOfChild(pParentItem); 2542 QModelIndex parentIndex = index(iParentPosition, 0, root()); 2543 beginInsertRows(parentIndex, pParentItem->childCount(), pParentItem->childCount()); 2544 AttachmentItem *pItem = new AttachmentItem(pParentItem, enmDeviceType); 2545 pItem->setHotPluggable(m_enmConfigurationAccessLevel != ConfigurationAccessLevel_Full); 2546 pItem->setMediumId(uMediumId); 2547 endInsertRows(); 2548 return index(pParentItem->childCount() - 1, 0, parentIndex); 2549 } 2550 return QModelIndex(); 2551 } 2552 2553 void StorageModel::delAttachment(const QUuid &uCtrId, const QUuid &uAttId) 2554 { 2555 if (AbstractItem *pParentItem = m_pRootItem->childItemById(uCtrId)) 2556 { 2557 int iParentPosition = m_pRootItem->posOfChild(pParentItem); 2558 if (AbstractItem *pItem = pParentItem->childItemById(uAttId)) 2559 { 2560 int iItemPosition = pParentItem->posOfChild(pItem); 2561 beginRemoveRows(index(iParentPosition, 0, root()), iItemPosition, iItemPosition); 2562 delete pItem; 2563 endRemoveRows(); 2564 } 2565 } 2566 } 2567 2568 void StorageModel::moveAttachment(const QUuid &uAttId, const QUuid &uCtrOldId, const QUuid &uCtrNewId) 2569 { 2570 /* No known info about attachment device type and medium ID: */ 2571 KDeviceType enmDeviceType = KDeviceType_Null; 2572 QUuid uMediumId; 2573 2574 /* First of all we are looking for old controller item: */ 2575 AbstractItem *pOldItem = m_pRootItem->childItemById(uCtrOldId); 2576 if (pOldItem) 2577 { 2578 /* And acquire controller position: */ 2579 const int iOldCtrPosition = m_pRootItem->posOfChild(pOldItem); 2580 2581 /* Then we are looking for an attachment item: */ 2582 if (AbstractItem *pSubItem = pOldItem->childItemById(uAttId)) 2583 { 2584 /* And make sure this is really an attachment: */ 2585 AttachmentItem *pSubItemAttachment = qobject_cast<AttachmentItem*>(pSubItem); 2586 if (pSubItemAttachment) 2587 { 2588 /* This way we can acquire actual attachment device type and medium ID: */ 2589 enmDeviceType = pSubItemAttachment->deviceType(); 2590 uMediumId = pSubItemAttachment->mediumId(); 2591 2592 /* And delete atachment item finally: */ 2593 const int iAttPosition = pOldItem->posOfChild(pSubItem); 2594 beginRemoveRows(index(iOldCtrPosition, 0, root()), iAttPosition, iAttPosition); 2595 delete pSubItem; 2596 endRemoveRows(); 2597 } 2598 } 2599 } 2600 2601 /* As the last step we are looking for new controller item: */ 2602 AbstractItem *pNewItem = m_pRootItem->childItemById(uCtrNewId); 2603 if (pNewItem) 2604 { 2605 /* And acquire controller position: */ 2606 const int iNewCtrPosition = m_pRootItem->posOfChild(pNewItem); 2607 2608 /* Then we have to make sure moved attachment is valid: */ 2609 if (enmDeviceType != KDeviceType_Null) 2610 { 2611 /* And create new attachment item finally: */ 2612 QModelIndex newCtrIndex = index(iNewCtrPosition, 0, root()); 2613 beginInsertRows(newCtrIndex, pNewItem->childCount(), pNewItem->childCount()); 2614 AttachmentItem *pItem = new AttachmentItem(pNewItem, enmDeviceType); 2615 pItem->setHotPluggable(m_enmConfigurationAccessLevel != ConfigurationAccessLevel_Full); 2616 pItem->setMediumId(uMediumId); 2617 endInsertRows(); 2618 } 2619 } 2620 } 2621 2622 KDeviceType StorageModel::attachmentDeviceType(const QUuid &uCtrId, const QUuid &uAttId) const 2623 { 2624 /* First of all we are looking for top-level (controller) item: */ 2625 AbstractItem *pTopLevelItem = m_pRootItem->childItemById(uCtrId); 2626 if (pTopLevelItem) 2627 { 2628 /* Then we are looking for sub-level (attachment) item: */ 2629 AbstractItem *pSubLevelItem = pTopLevelItem->childItemById(uAttId); 2630 if (pSubLevelItem) 2631 { 2632 /* And make sure this is really an attachment: */ 2633 AttachmentItem *pAttachmentItem = qobject_cast<AttachmentItem*>(pSubLevelItem); 2634 if (pAttachmentItem) 2635 { 2636 /* This way we can acquire actual attachment device type: */ 2637 return pAttachmentItem->deviceType(); 2638 } 2639 } 2640 } 2641 2642 /* Null by default: */ 2643 return KDeviceType_Null; 2644 } 2645 2646 KPlatformArchitecture StorageModel::arch() const 2647 { 2648 return m_pParentEditor ? m_pParentEditor->arch() : KPlatformArchitecture_x86; 2649 } 2650 2651 KChipsetType StorageModel::chipsetType() const 2652 { 2653 return m_enmChipsetType; 2654 } 2655 2656 void StorageModel::setChipsetType(KChipsetType enmChipsetType) 2657 { 2658 m_enmChipsetType = enmChipsetType; 2659 } 2660 2661 void StorageModel::setConfigurationAccessLevel(ConfigurationAccessLevel enmConfigurationAccessLevel) 2662 { 2663 m_enmConfigurationAccessLevel = enmConfigurationAccessLevel; 2664 2664 } 2665 2665
Note:
See TracChangeset
for help on using the changeset viewer.