VirtualBox

Changeset 29010 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
May 4, 2010 12:17:43 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
61049
Message:

FE/Qt: 4396: Storage Settings UI will now sort listed attachments by storage slot.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h

    r28800 r29010  
    263263    bool operator== (const StorageSlot &aOther) const { return bus == aOther.bus && port == aOther.port && device == aOther.device; }
    264264    bool operator!= (const StorageSlot &aOther) const { return bus != aOther.bus || port != aOther.port || device != aOther.device; }
     265    bool operator< (const StorageSlot &aOther) const { return (bus < aOther.bus) ||
     266                                                              (bus == aOther.bus && port < aOther.port) ||
     267                                                              (bus == aOther.bus && port == aOther.port && device < aOther.device); }
     268    bool operator> (const StorageSlot &aOther) const { return (bus > aOther.bus) ||
     269                                                              (bus == aOther.bus && port > aOther.port) ||
     270                                                              (bus == aOther.bus && port == aOther.port && device > aOther.device); }
    265271    bool isNull() { return bus == KStorageBus_Null; }
    266272    KStorageBus bus; LONG port; LONG device;
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsHD.cpp

    r28885 r29010  
    13221322                    static_cast <AttachmentItem*> (item)->setAttSlot (aValue.value <StorageSlot>());
    13231323                    emit dataChanged (aIndex, aIndex);
     1324                    sort();
    13241325                    return true;
    13251326                }
     
    14281429{
    14291430    mRootItem->setMachineId (aMachineId);
     1431}
     1432
     1433void StorageModel::sort(int /* iColumn */, Qt::SortOrder order)
     1434{
     1435    /* Count of controller items: */
     1436    int iItemLevel1Count = mRootItem->childCount();
     1437    /* For each of controller items: */
     1438    for (int iItemLevel1Pos = 0; iItemLevel1Pos < iItemLevel1Count; ++iItemLevel1Pos)
     1439    {
     1440        /* Get iterated controller item: */
     1441        AbstractItem *pItemLevel1 = mRootItem->childByPos(iItemLevel1Pos);
     1442        ControllerItem *pControllerItem = static_cast<ControllerItem*>(pItemLevel1);
     1443        /* Count of attachment items: */
     1444        int iItemLevel2Count = pItemLevel1->childCount();
     1445        /* Prepare empty list for sorted attachments: */
     1446        QList<AbstractItem*> newAttachments;
     1447        /* For each of attachment items: */
     1448        for (int iItemLevel2Pos = 0; iItemLevel2Pos < iItemLevel2Count; ++iItemLevel2Pos)
     1449        {
     1450            /* Get iterated attachment item: */
     1451            AbstractItem *pItemLevel2 = pItemLevel1->childByPos(iItemLevel2Pos);
     1452            AttachmentItem *pAttachmentItem = static_cast<AttachmentItem*>(pItemLevel2);
     1453            /* Get iterated attachment storage slot: */
     1454            StorageSlot attachmentSlot = pAttachmentItem->attSlot();
     1455            int iInsertPosition = 0;
     1456            for (; iInsertPosition < newAttachments.size(); ++iInsertPosition)
     1457            {
     1458                /* Get sorted attachment item: */
     1459                AbstractItem *pNewItemLevel2 = newAttachments[iInsertPosition];
     1460                AttachmentItem *pNewAttachmentItem = static_cast<AttachmentItem*>(pNewItemLevel2);
     1461                /* Get sorted attachment storage slot: */
     1462                StorageSlot newAttachmentSlot = pNewAttachmentItem->attSlot();
     1463                /* Apply sorting rule: */
     1464                if (((order == Qt::AscendingOrder) && (attachmentSlot < newAttachmentSlot)) ||
     1465                    ((order == Qt::DescendingOrder) && (attachmentSlot > newAttachmentSlot)))
     1466                    break;
     1467            }
     1468            /* Insert iterated attachment into sorted position: */
     1469            newAttachments.insert(iInsertPosition, pItemLevel2);
     1470        }
     1471
     1472        /* If that controller has attachments: */
     1473        if (iItemLevel2Count)
     1474        {
     1475            /* We should update corresponding model-indexes: */
     1476            QModelIndex controllerIndex = index(iItemLevel1Pos, 0, root());
     1477            pControllerItem->setAttachments(newAttachments);
     1478            /* That is actually beginMoveRows() + endMoveRows() which
     1479             * unfortunately become available only in Qt 4.6 version. */
     1480            beginRemoveRows(controllerIndex, 0, iItemLevel2Count - 1);
     1481            endRemoveRows();
     1482            beginInsertRows(controllerIndex, 0, iItemLevel2Count - 1);
     1483            endInsertRows();
     1484        }
     1485    }
     1486}
     1487
     1488QModelIndex StorageModel::attachmentBySlot(QModelIndex controllerIndex, StorageSlot attachmentStorageSlot)
     1489{
     1490    /* Check what parent model index is valid, set and of 'controller' type: */
     1491    AssertMsg(controllerIndex.isValid(), ("Controller index should be valid!\n"));
     1492    AbstractItem *pParentItem = static_cast<AbstractItem*>(controllerIndex.internalPointer());
     1493    AssertMsg(pParentItem, ("Parent item should be set!\n"));
     1494    AssertMsg(pParentItem->rtti() == AbstractItem::Type_ControllerItem, ("Parent item should be of 'controller' type!\n"));
     1495    NOREF(pParentItem);
     1496
     1497    /* Search for suitable attachment one by one: */
     1498    for (int i = 0; i < rowCount(controllerIndex); ++i)
     1499    {
     1500        QModelIndex curAttachmentIndex = index(i, 0, controllerIndex);
     1501        StorageSlot curAttachmentStorageSlot = data(curAttachmentIndex, R_AttSlot).value<StorageSlot>();
     1502        if (curAttachmentStorageSlot ==  attachmentStorageSlot)
     1503            return curAttachmentIndex;
     1504    }
     1505    return QModelIndex();
    14301506}
    14311507
     
    21952271            /* Setting Attachment Slot */
    21962272            if (sdr == mCbSlot)
    2197                 mStorageModel->setData (index, QVariant::fromValue (vboxGlobal().toStorageSlot (mCbSlot->currentText())),
    2198                                         StorageModel::R_AttSlot);
     2273            {
     2274                QModelIndex controllerIndex = mStorageModel->parent(index);
     2275                StorageSlot attachmentStorageSlot = vboxGlobal().toStorageSlot(mCbSlot->currentText());
     2276                mStorageModel->setData(index, QVariant::fromValue(attachmentStorageSlot), StorageModel::R_AttSlot);
     2277                QModelIndex theSameIndexAtNewPosition = mStorageModel->attachmentBySlot(controllerIndex, attachmentStorageSlot);
     2278                AssertMsg(theSameIndexAtNewPosition.isValid(), ("Current attachment disappears!\n"));
     2279                mTwStorageTree->setCurrentIndex(theSameIndexAtNewPosition);
     2280            }
    21992281            /* Setting Attachment Medium */
    22002282            else if (sdr == mCbVdi)
     
    25562638
    25572639    mStorageModel->addAttachment (QUuid (mStorageModel->data (index, StorageModel::R_ItemId).toString()), aDevice);
     2640    mStorageModel->sort();
    25582641    emit storageChanged();
    25592642    if (mValidator) mValidator->revalidate();
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsHD.h

    r28885 r29010  
    309309    QStringList ctrUsedMediumIds() const;
    310310
     311    void setAttachments(const QList<AbstractItem*> &attachments) { mAttachments = attachments; }
     312
    311313private:
    312314
     
    486488    void setMachineId (const QString &aMachineId);
    487489
     490    void sort(int iColumn = 0, Qt::SortOrder order = Qt::AscendingOrder);
     491    QModelIndex attachmentBySlot(QModelIndex controllerIndex, StorageSlot attachmentStorageSlot);
     492
    488493private:
    489494
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette