VirtualBox

Changeset 66455 in vbox for trunk


Ignore:
Timestamp:
Apr 6, 2017 10:02:40 AM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: Machine settings: USB page: Reworking USB filter tree-widget item to handle own data itself as done for shared folder tree-widget item.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsUSB.cpp

    r66410 r66455  
    255255
    256256
    257 /** QITreeWidgetItem extension representing USB filter item. */
     257/** Machine settings: USB Filter tree-widget item. */
    258258class UIUSBFilterItem : public QITreeWidgetItem, public UIDataSettingsMachineUSBFilter
    259259{
    260260public:
    261261
    262     /** Constructs USB filter item. */
    263     UIUSBFilterItem() {}
    264 
    265     /** Loads USB filter @a data. */
    266     void loadUSBFilterData(const UIDataSettingsMachineUSBFilter &data)
    267     {
    268         m_fActive = data.m_fActive;
    269         m_strName = data.m_strName;
    270         m_strVendorId = data.m_strVendorId;
    271         m_strProductId = data.m_strProductId;
    272         m_strRevision = data.m_strRevision;
    273         m_strManufacturer = data.m_strManufacturer;
    274         m_strProduct = data.m_strProduct;
    275         m_strSerialNumber = data.m_strSerialNumber;
    276         m_strPort = data.m_strPort;
    277         m_strRemote = data.m_strRemote;
    278         m_enmAction = data.m_enmAction;
    279         m_fHostUSBDevice = data.m_fHostUSBDevice;
    280         m_enmHostUSBDeviceState = data.m_enmHostUSBDeviceState;
     262    /** Constructs USB filter (root) item.
     263      * @param  pParent  Brings the item parent. */
     264    UIUSBFilterItem(QITreeWidget *pParent)
     265        : QITreeWidgetItem(pParent)
     266    {
     267    }
     268
     269    /** Updates item fields. */
     270    void updateFields()
     271    {
     272        setText(0, m_strName);
     273        setToolTip(0, toolTipFor());
    281274    }
    282275
     
    289282               tr("%1, Active", "col.1 text, col.1 state").arg(text(0)) :
    290283               tr("%1",         "col.1 text")             .arg(text(0));
     284    }
     285
     286private:
     287
     288    /** Returns tool-tip generated from item data. */
     289    QString toolTipFor()
     290    {
     291        /* Prepare tool-tip: */
     292        QString strToolTip;
     293
     294        const QString strVendorId = m_strVendorId;
     295        if (!strVendorId.isEmpty())
     296            strToolTip += UIMachineSettingsUSB::tr("<nobr>Vendor ID: %1</nobr>", "USB filter tooltip").arg(strVendorId);
     297
     298        const QString strProductId = m_strProductId;
     299        if (!strProductId.isEmpty())
     300            strToolTip += strToolTip.isEmpty() ? "":"<br/>" + UIMachineSettingsUSB::tr("<nobr>Product ID: %2</nobr>", "USB filter tooltip").arg(strProductId);
     301
     302        const QString strRevision = m_strRevision;
     303        if (!strRevision.isEmpty())
     304            strToolTip += strToolTip.isEmpty() ? "":"<br/>" + UIMachineSettingsUSB::tr("<nobr>Revision: %3</nobr>", "USB filter tooltip").arg(strRevision);
     305
     306        const QString strProduct = m_strProduct;
     307        if (!strProduct.isEmpty())
     308            strToolTip += strToolTip.isEmpty() ? "":"<br/>" + UIMachineSettingsUSB::tr("<nobr>Product: %4</nobr>", "USB filter tooltip").arg(strProduct);
     309
     310        const QString strManufacturer = m_strManufacturer;
     311        if (!strManufacturer.isEmpty())
     312            strToolTip += strToolTip.isEmpty() ? "":"<br/>" + UIMachineSettingsUSB::tr("<nobr>Manufacturer: %5</nobr>", "USB filter tooltip").arg(strManufacturer);
     313
     314        const QString strSerial = m_strSerialNumber;
     315        if (!strSerial.isEmpty())
     316            strToolTip += strToolTip.isEmpty() ? "":"<br/>" + UIMachineSettingsUSB::tr("<nobr>Serial No.: %1</nobr>", "USB filter tooltip").arg(strSerial);
     317
     318        const QString strPort = m_strPort;
     319        if (!strPort.isEmpty())
     320            strToolTip += strToolTip.isEmpty() ? "":"<br/>" + UIMachineSettingsUSB::tr("<nobr>Port: %1</nobr>", "USB filter tooltip").arg(strPort);
     321
     322        /* Add the state field if it's a host USB device: */
     323        if (m_fHostUSBDevice)
     324        {
     325            strToolTip += strToolTip.isEmpty() ? "":"<br/>" + UIMachineSettingsUSB::tr("<nobr>State: %1</nobr>", "USB filter tooltip")
     326                                                              .arg(gpConverter->toString(m_enmHostUSBDeviceState));
     327        }
     328
     329        /* Return tool-tip: */
     330        return strToolTip;
    291331    }
    292332};
     
    398438    /* For each USB filter => load it to the page: */
    399439    for (int iFilterIndex = 0; iFilterIndex < m_pCache->childCount(); ++iFilterIndex)
    400         addUSBFilter(m_pCache->child(iFilterIndex).base(), false /* its new? */);
     440        addUSBFilterItem(m_pCache->child(iFilterIndex).base(), false /* its new? */);
    401441
    402442    /* Choose first filter as current: */
     
    747787    usbFilterData.m_fHostUSBDevice = false;
    748788
    749     /* Add new USB filter data: */
    750     addUSBFilter(usbFilterData, true /* its new? */);
     789    /* Add new USB filter item: */
     790    addUSBFilterItem(usbFilterData, true /* its new? */);
    751791
    752792    /* Revalidate: */
     
    786826    usbFilterData.m_strRemote = QString::number(usb.GetRemote());
    787827
    788     /* Add new USB filter data: */
    789     addUSBFilter(usbFilterData, true /* its new? */);
     828    /* Add new USB filter item: */
     829    addUSBFilterItem(usbFilterData, true /* its new? */);
    790830
    791831    /* Revalidate: */
     
    835875            default: AssertMsgFailed(("Invalid combo box index"));
    836876        }
    837         pItem->setText(0, pItem->m_strName);
    838         pItem->setToolTip(0, toolTipFor(*pItem));
     877        pItem->updateFields();
    839878    }
    840879}
     
    10331072}
    10341073
    1035 void UIMachineSettingsUSB::addUSBFilter(const UIDataSettingsMachineUSBFilter &usbFilterData, bool fChoose)
     1074void UIMachineSettingsUSB::addUSBFilterItem(const UIDataSettingsMachineUSBFilter &filterData, bool fChoose)
    10361075{
    10371076    /* Create USB filter item: */
    1038     UIUSBFilterItem *pItem = new UIUSBFilterItem;
     1077    UIUSBFilterItem *pItem = new UIUSBFilterItem(mTwFilters);
    10391078    AssertPtrReturnVoid(pItem);
    10401079    {
    10411080        /* Configure item: */
    1042         pItem->setCheckState(0, usbFilterData.m_fActive ? Qt::Checked : Qt::Unchecked);
    1043         pItem->setText(0, usbFilterData.m_strName);
    1044         pItem->setToolTip(0, toolTipFor(usbFilterData));
    1045         pItem->loadUSBFilterData(usbFilterData);
    1046 
    1047         /* Append tree-widget with item: */
    1048         mTwFilters->addTopLevelItem(pItem);
     1081        pItem->setCheckState(0, filterData.m_fActive ? Qt::Checked : Qt::Unchecked);
     1082        pItem->m_strName = filterData.m_strName;
     1083        pItem->m_strVendorId = filterData.m_strVendorId;
     1084        pItem->m_strProductId = filterData.m_strProductId;
     1085        pItem->m_strRevision = filterData.m_strRevision;
     1086        pItem->m_strManufacturer = filterData.m_strManufacturer;
     1087        pItem->m_strProduct = filterData.m_strProduct;
     1088        pItem->m_strSerialNumber = filterData.m_strSerialNumber;
     1089        pItem->m_strPort = filterData.m_strPort;
     1090        pItem->m_strRemote = filterData.m_strRemote;
     1091        pItem->m_enmAction = filterData.m_enmAction;
     1092        pItem->m_fHostUSBDevice = filterData.m_fHostUSBDevice;
     1093        pItem->m_enmHostUSBDeviceState = filterData.m_enmHostUSBDeviceState;
     1094        pItem->updateFields();
    10491095
    10501096        /* Select this item if it's new: */
    10511097        if (fChoose)
     1098        {
     1099            mTwFilters->scrollToItem(pItem);
    10521100            mTwFilters->setCurrentItem(pItem);
    1053     }
    1054 }
    1055 
    1056 /* static */
    1057 QString UIMachineSettingsUSB::toolTipFor(const UIDataSettingsMachineUSBFilter &usbFilterData)
    1058 {
    1059     /* Prepare tool-tip: */
    1060     QString strToolTip;
    1061 
    1062     const QString strVendorId = usbFilterData.m_strVendorId;
    1063     if (!strVendorId.isEmpty())
    1064         strToolTip += tr("<nobr>Vendor ID: %1</nobr>", "USB filter tooltip").arg(strVendorId);
    1065 
    1066     const QString strProductId = usbFilterData.m_strProductId;
    1067     if (!strProductId.isEmpty())
    1068         strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Product ID: %2</nobr>", "USB filter tooltip").arg(strProductId);
    1069 
    1070     const QString strRevision = usbFilterData.m_strRevision;
    1071     if (!strRevision.isEmpty())
    1072         strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Revision: %3</nobr>", "USB filter tooltip").arg(strRevision);
    1073 
    1074     const QString strProduct = usbFilterData.m_strProduct;
    1075     if (!strProduct.isEmpty())
    1076         strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Product: %4</nobr>", "USB filter tooltip").arg(strProduct);
    1077 
    1078     const QString strManufacturer = usbFilterData.m_strManufacturer;
    1079     if (!strManufacturer.isEmpty())
    1080         strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Manufacturer: %5</nobr>", "USB filter tooltip").arg(strManufacturer);
    1081 
    1082     const QString strSerial = usbFilterData.m_strSerialNumber;
    1083     if (!strSerial.isEmpty())
    1084         strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Serial No.: %1</nobr>", "USB filter tooltip").arg(strSerial);
    1085 
    1086     const QString strPort = usbFilterData.m_strPort;
    1087     if (!strPort.isEmpty())
    1088         strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Port: %1</nobr>", "USB filter tooltip").arg(strPort);
    1089 
    1090     /* Add the state field if it's a host USB device: */
    1091     if (usbFilterData.m_fHostUSBDevice)
    1092     {
    1093         strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>State: %1</nobr>", "USB filter tooltip")
    1094                                                           .arg(gpConverter->toString(usbFilterData.m_enmHostUSBDeviceState));
    1095     }
    1096 
    1097     return strToolTip;
     1101            sltHandleCurrentItemChange(pItem);
     1102        }
     1103    }
    10981104}
    10991105
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsUSB.h

    r66410 r66455  
    9494    void sltHandleActivityStateChange(QTreeWidgetItem *pChangedItem);
    9595
    96     /** Handles command to add new filter. */
     96    /** Handles command to add new USB filter. */
    9797    void sltNewFilter();
    98     /** Handles command to add existing filter. */
     98    /** Handles command to add existing USB filter. */
    9999    void sltAddFilter();
    100     /** Handles command to edit filter. */
     100    /** Handles command to edit USB filter. */
    101101    void sltEditFilter();
    102     /** Handles command to confirm add of existing filter defined by @a pAction. */
     102    /** Handles command to confirm add of existing USB filter defined by @a pAction. */
    103103    void sltAddFilterConfirmed(QAction *pAction);
    104     /** Handles command to remove chosen filter. */
     104    /** Handles command to remove chosen USB filter. */
    105105    void sltRemoveFilter();
    106     /** Handles command to move chosen filter up. */
     106    /** Handles command to move chosen USB filter up. */
    107107    void sltMoveFilterUp();
    108     /** Handles command to move chosen filter down. */
     108    /** Handles command to move chosen USB filter down. */
    109109    void sltMoveFilterDown();
    110110
     
    122122    void cleanup();
    123123
    124     /** Adds USB filter item based on a given @a usbFilterData, fChoose if requested. */
    125     void addUSBFilter(const UIDataSettingsMachineUSBFilter &usbFilterData, bool fChoose);
     124    /** Adds USB filter item based on a given @a filterData, fChoose if requested. */
     125    void addUSBFilterItem(const UIDataSettingsMachineUSBFilter &filterData, bool fChoose);
    126126
    127127    /** Returns the multi-line description of the given USB filter. */
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