VirtualBox

Changeset 91256 in vbox


Ignore:
Timestamp:
Sep 15, 2021 3:50:45 PM (3 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9996. Refactoring UIDiskFormatsGroupBox. part 3.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/wizards
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/clonevd/UIWizardCloneVDExpertPage.cpp

    r91222 r91256  
    9393    QString strMediumPath =
    9494        UIDiskEditorGroupBox::appendExtension(strSelectedPath,
    95                                               UIDiskFormatsGroupBox::defaultExtension(pWizard->mediumFormat(), pWizard->deviceType()));
     95                                              UIDiskEditorGroupBox::defaultExtension(pWizard->mediumFormat(), pWizard->deviceType()));
    9696    QFileInfo mediumPath(strMediumPath);
    9797    m_pMediumSizePathGroupBox->setMediumPath(QDir::toNativeSeparators(mediumPath.absoluteFilePath()));
     
    118118    QString strMediumPath =
    119119        UIDiskEditorGroupBox::appendExtension(strPath,
    120                                               UIDiskFormatsGroupBox::defaultExtension(pWizard->mediumFormat(), pWizard->deviceType()));
     120                                              UIDiskEditorGroupBox::defaultExtension(pWizard->mediumFormat(), pWizard->deviceType()));
    121121    pWizard->setMediumPath(strMediumPath);
    122122    emit completeChanged();
     
    141141    m_pMediumSizePathGroupBox->setMediumSize(pWizard->sourceDiskLogicalSize());
    142142    pWizard->setMediumSize(m_pMediumSizePathGroupBox->mediumSize());
    143     QString strExtension = UIDiskFormatsGroupBox::defaultExtension(pWizard->mediumFormat(), pWizard->deviceType());
     143    QString strExtension = UIDiskEditorGroupBox::defaultExtension(pWizard->mediumFormat(), pWizard->deviceType());
    144144    QString strSourceDiskPath = QDir::toNativeSeparators(QFileInfo(pWizard->sourceDiskFilePath()).absolutePath());
    145145    /* Disk name without the format extension: */
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/clonevd/UIWizardCloneVDPathSizePage.cpp

    r91222 r91256  
    7373    if (!m_userModifiedParameters.contains("MediumPath"))
    7474    {
    75         QString strExtension = UIDiskFormatsGroupBox::defaultExtension(pWizard->mediumFormat(), pWizard->deviceType());
     75        QString strExtension = UIDiskEditorGroupBox::defaultExtension(pWizard->mediumFormat(), pWizard->deviceType());
    7676        QString strSourceDiskPath = QDir::toNativeSeparators(QFileInfo(pWizard->sourceDiskFilePath()).absolutePath());
    7777        /* Disk name without the format extension: */
     
    119119    QString strMediumPath =
    120120        UIDiskEditorGroupBox::appendExtension(strSelectedPath,
    121                                               UIDiskFormatsGroupBox::defaultExtension(pWizard->mediumFormat(), pWizard->deviceType()));
     121                                              UIDiskEditorGroupBox::defaultExtension(pWizard->mediumFormat(), pWizard->deviceType()));
    122122    QFileInfo mediumPath(strMediumPath);
    123123    m_pMediumSizePathGroupBox->setMediumPath(QDir::toNativeSeparators(mediumPath.absoluteFilePath()));
     
    131131    QString strMediumPath =
    132132        UIDiskEditorGroupBox::appendExtension(strPath,
    133                                               UIDiskFormatsGroupBox::defaultExtension(pWizard->mediumFormat(), pWizard->deviceType()));
     133                                              UIDiskEditorGroupBox::defaultExtension(pWizard->mediumFormat(), pWizard->deviceType()));
    134134    pWizard->setMediumPath(strMediumPath);
    135135    emit completeChanged();
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/editors/UIWizardDiskEditors.cpp

    r91254 r91256  
    168168
    169169/*********************************************************************************************************************************
    170 *   UIDiskFormatsGroupBox implementation.                                                                                   *
     170*   UIDiskFormatBase implementation.                                                                                   *
    171171*********************************************************************************************************************************/
    172172
    173 UIDiskFormatsGroupBox::UIDiskFormatsGroupBox(bool fExpertMode, KDeviceType enmDeviceType, QWidget *pParent /* = 0 */)
    174     : UIDiskEditorGroupBox(fExpertMode, pParent)
    175     , UIDiskFormatBase(enmDeviceType)
    176     , m_pFormatButtonGroup(0)
    177     , m_pMainLayout(0)
    178 {
    179     prepare();
    180 
    181 }
    182 
    183 CMediumFormat UIDiskFormatsGroupBox::mediumFormat() const
    184 {
    185     return m_pFormatButtonGroup &&
    186            m_pFormatButtonGroup->checkedButton() ? m_formatList[m_pFormatButtonGroup->checkedId()].m_comFormat : CMediumFormat();
    187 }
    188 
    189 void UIDiskFormatsGroupBox::setMediumFormat(const CMediumFormat &mediumFormat)
    190 {
    191     int iPosition = -1;
    192     for (int i = 0; i < m_formatList.size(); ++i)
    193     {
    194         if (mediumFormat == m_formatList[i].m_comFormat)
    195             iPosition = i;
    196     }
    197     if (iPosition >= 0)
    198     {
    199         m_pFormatButtonGroup->button(iPosition)->click();
    200         m_pFormatButtonGroup->button(iPosition)->setFocus();
    201     }
    202 }
    203 
    204 const CMediumFormat &UIDiskFormatsGroupBox::VDIMediumFormat() const
     173UIDiskFormatBase::UIDiskFormatBase(KDeviceType enmDeviceType, bool fExpertMode)
     174    : m_enmDeviceType(enmDeviceType)
     175    , m_fExpertMode(fExpertMode)
     176{
     177}
     178
     179const CMediumFormat &UIDiskFormatBase::VDIMediumFormat() const
    205180{
    206181    return m_comVDIMediumFormat;
    207182}
    208183
    209 void UIDiskFormatsGroupBox::prepare()
    210 {
    211     m_pMainLayout = new QVBoxLayout(this);
    212     populateFormats();
    213     createFormatWidgets();
    214     retranslateUi();
    215 }
    216 
    217 void UIDiskFormatsGroupBox::populateFormats(){
     184void UIDiskFormatBase::populateFormats(){
    218185    /* Enumerate medium formats in special order: */
    219186    CSystemProperties properties = uiCommon().virtualBox().GetSystemProperties();
     
    250217}
    251218
    252 void UIDiskFormatsGroupBox::retranslateUi()
    253 {
    254     if (m_fExpertMode)
    255         setTitle(tr("Hard Disk File &Type"));
    256 
    257     QList<QAbstractButton*> buttons = m_pFormatButtonGroup ? m_pFormatButtonGroup->buttons() : QList<QAbstractButton*>();
    258     for (int i = 0; i < buttons.size(); ++i)
    259     {
    260         QAbstractButton *pButton = buttons[i];
    261         UIMediumFormat enmFormat = gpConverter->fromInternalString<UIMediumFormat>(m_formatList[m_pFormatButtonGroup->id(pButton)].m_strName);
    262         pButton->setText(gpConverter->toString(enmFormat));
    263     }
    264 }
    265 
    266 void UIDiskFormatsGroupBox::addFormat(CMediumFormat medFormat, bool fPreferred /* = false */)
     219void UIDiskFormatBase::addFormat(CMediumFormat medFormat, bool fPreferred /* = false */)
    267220{
    268221    /* Check that medium format supports creation: */
     
    283236    if (!deviceTypes.contains(m_enmDeviceType))
    284237        return;
    285     m_formatList << Format(medFormat, medFormat.GetName(), defaultExtension(medFormat, m_enmDeviceType), fPreferred);
    286 }
    287 
    288 const QStringList UIDiskFormatsGroupBox::formatExtensions() const
     238    m_formatList << Format(medFormat, UIDiskEditorGroupBox::defaultExtension(medFormat, m_enmDeviceType), fPreferred);
     239}
     240
     241QStringList UIDiskFormatBase::formatExtensions() const
    289242{
    290243    QStringList extensionList;
     
    294247}
    295248
     249bool UIDiskFormatBase::isExpertMode() const
     250{
     251    return m_fExpertMode;
     252}
     253
     254/*********************************************************************************************************************************
     255*   UIDiskFormatsGroupBox implementation.                                                                                   *
     256*********************************************************************************************************************************/
     257
     258UIDiskFormatsGroupBox::UIDiskFormatsGroupBox(bool fExpertMode, KDeviceType enmDeviceType, QWidget *pParent /* = 0 */)
     259    : QIWithRetranslateUI<QWidget>(pParent)
     260    , UIDiskFormatBase(enmDeviceType, fExpertMode)
     261    , m_pFormatButtonGroup(0)
     262    , m_pMainLayout(0)
     263{
     264    prepare();
     265}
     266
     267CMediumFormat UIDiskFormatsGroupBox::mediumFormat() const
     268{
     269    return m_pFormatButtonGroup &&
     270           m_pFormatButtonGroup->checkedButton() ? m_formatList[m_pFormatButtonGroup->checkedId()].m_comFormat : CMediumFormat();
     271}
     272
     273void UIDiskFormatsGroupBox::setMediumFormat(const CMediumFormat &mediumFormat)
     274{
     275    int iPosition = -1;
     276    for (int i = 0; i < m_formatList.size(); ++i)
     277    {
     278        if (mediumFormat == m_formatList[i].m_comFormat)
     279            iPosition = i;
     280    }
     281    if (iPosition >= 0)
     282    {
     283        m_pFormatButtonGroup->button(iPosition)->click();
     284        m_pFormatButtonGroup->button(iPosition)->setFocus();
     285    }
     286}
     287
     288void UIDiskFormatsGroupBox::prepare()
     289{
     290    m_pMainLayout = new QVBoxLayout(this);
     291    populateFormats();
     292    createFormatWidgets();
     293    retranslateUi();
     294}
     295
     296void UIDiskFormatsGroupBox::retranslateUi()
     297{
     298    QList<QAbstractButton*> buttons = m_pFormatButtonGroup ? m_pFormatButtonGroup->buttons() : QList<QAbstractButton*>();
     299    for (int i = 0; i < buttons.size(); ++i)
     300    {
     301        QAbstractButton *pButton = buttons[i];
     302        const CMediumFormat &format = m_formatList[m_pFormatButtonGroup->id(pButton)].m_comFormat;
     303        if (format.isNull())
     304            continue;
     305        UIMediumFormat enmFormat = gpConverter->fromInternalString<UIMediumFormat>(format.GetName());
     306        pButton->setText(gpConverter->toString(enmFormat));
     307    }
     308}
     309
    296310void UIDiskFormatsGroupBox::createFormatWidgets()
    297311{
     
    308322
    309323        /* Make the preferred button font bold: */
    310         if (m_formatList[i].m_fPreferred && m_fExpertMode)
     324        if (m_formatList[i].m_fPreferred && isExpertMode())
    311325        {
    312326            QFont font = pFormatButton->font();
     
    561575{
    562576    /* Compose virtual-disk extension: */
    563     QString strDefaultExtension = UIDiskFormatsGroupBox::defaultExtension(mediumFormat, enmDeviceType);
     577    QString strDefaultExtension = UIDiskEditorGroupBox::defaultExtension(mediumFormat, enmDeviceType);
    564578    /* Update m_pLocationEditor's text if necessary: */
    565579    if (!m_pLocationEditor->text().isEmpty() && !strDefaultExtension.isEmpty())
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/editors/UIWizardDiskEditors.h

    r91254 r91256  
    7474};
    7575
    76 class UIDiskFormatBase
    77 {
    78 
    79 public:
    80 
    81     UIDiskFormatBase(KDeviceType enmDeviceType)
    82         : m_enmDeviceType(enmDeviceType)
    83     {}
    84 
    85 protected:
    86 
    87     struct Format
    88     {
    89         CMediumFormat m_comFormat;
    90         QString       m_strName;
    91         QString       m_strExtension;
    92         bool          m_fPreferred;
    93         Format(const CMediumFormat &comFormat, const QString &strName,
    94                const QString &strExtension, bool fPreferred)
    95                : m_comFormat(comFormat)
    96                , m_strName(strName)
    97                , m_strExtension(strExtension)
    98                , m_fPreferred(fPreferred){}
    99         Format(){}
    100     };
    101 
    102     QVector<Format> m_formatList;
    103     CMediumFormat m_comVDIMediumFormat;
    104     KDeviceType m_enmDeviceType;
    105 
    106 };
    107 
    108 class SHARED_LIBRARY_STUFF UIDiskFormatsGroupBox : public UIDiskEditorGroupBox, public UIDiskFormatBase
    109 {
    110     Q_OBJECT;
    111 
    112 signals:
    113 
    114     void sigMediumFormatChanged();
    115 
    116 public:
    117 
    118     UIDiskFormatsGroupBox(bool fExpertMode, KDeviceType enmDeviceType, QWidget *pParent = 0);
    119     CMediumFormat mediumFormat() const;
    120     void setMediumFormat(const CMediumFormat &mediumFormat);
    121     const CMediumFormat &VDIMediumFormat() const;
    122     const QStringList formatExtensions() const;
    123 
    124 private:
    125 
    126     void prepare();
    127     void populateFormats();
    128     void addFormat(CMediumFormat medFormat, bool fPreferred = false);
    129     void createFormatWidgets();
    130     virtual void retranslateUi() /* override final */;
    131 
    132 
    133     QButtonGroup *m_pFormatButtonGroup;
    134     QVBoxLayout *m_pMainLayout;
    135 };
    13676
    13777class SHARED_LIBRARY_STUFF UIDiskVariantGroupBox : public UIDiskEditorGroupBox
     
    209149};
    210150
     151/** Base class for the widgets used to select virtual medium format. It implements mutual functioanlity
     152  * like finding name, extension etc for a CMediumFormat and device type. */
     153class SHARED_LIBRARY_STUFF UIDiskFormatBase
     154{
     155public:
     156
     157    UIDiskFormatBase(KDeviceType enmDeviceType, bool fExpertMode);
     158    const CMediumFormat &VDIMediumFormat() const;
     159    QStringList formatExtensions() const;
     160
     161protected:
     162
     163    struct Format
     164    {
     165        CMediumFormat m_comFormat;
     166        QString       m_strExtension;
     167        bool          m_fPreferred;
     168        Format(const CMediumFormat &comFormat,
     169               const QString &strExtension, bool fPreferred)
     170               : m_comFormat(comFormat)
     171               , m_strExtension(strExtension)
     172               , m_fPreferred(fPreferred){}
     173        Format(){}
     174    };
     175
     176    void addFormat(CMediumFormat medFormat, bool fPreferred = false);
     177    void populateFormats();
     178    bool isExpertMode() const;
     179    QVector<Format> m_formatList;
     180
     181private:
     182
     183    CMediumFormat m_comVDIMediumFormat;
     184    KDeviceType m_enmDeviceType;
     185    bool m_fExpertMode;
     186};
     187
     188class SHARED_LIBRARY_STUFF UIDiskFormatsGroupBox : public QIWithRetranslateUI<QWidget>, public UIDiskFormatBase
     189{
     190    Q_OBJECT;
     191
     192signals:
     193
     194    void sigMediumFormatChanged();
     195
     196public:
     197
     198    UIDiskFormatsGroupBox(bool fExpertMode, KDeviceType enmDeviceType, QWidget *pParent = 0);
     199    CMediumFormat mediumFormat() const;
     200    void setMediumFormat(const CMediumFormat &mediumFormat);
     201
     202private:
     203
     204    void prepare();
     205    void createFormatWidgets();
     206    virtual void retranslateUi() /* override final */;
     207
     208    QButtonGroup *m_pFormatButtonGroup;
     209    QVBoxLayout *m_pMainLayout;
     210};
     211
    211212#endif /* !FEQT_INCLUDED_SRC_wizards_editors_UIWizardDiskEditors_h */
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd/UIWizardNewVDExpertPage.cpp

    r91061 r91256  
    8282    QString strMediumPath =
    8383        UIDiskEditorGroupBox::appendExtension(strPath,
    84                                               UIDiskFormatsGroupBox::defaultExtension(pWizard->mediumFormat(), KDeviceType_HardDisk));
     84                                              UIDiskEditorGroupBox::defaultExtension(pWizard->mediumFormat(), KDeviceType_HardDisk));
    8585    pWizard->setMediumPath(strMediumPath);
    8686    emit completeChanged();
     
    115115    QString strMediumPath =
    116116        UIDiskEditorGroupBox::appendExtension(strSelectedPath,
    117                                               UIDiskFormatsGroupBox::defaultExtension(pWizard->mediumFormat(), KDeviceType_HardDisk));
     117                                              UIDiskEditorGroupBox::defaultExtension(pWizard->mediumFormat(), KDeviceType_HardDisk));
    118118    QFileInfo mediumPath(strMediumPath);
    119119    m_pSizeAndPathGroup->setMediumPath(QDir::toNativeSeparators(mediumPath.absoluteFilePath()));
     
    135135    pWizard->setMediumFormat(comMediumFormat);
    136136
    137     QString strExtension = UIDiskFormatsGroupBox::defaultExtension(comMediumFormat, KDeviceType_HardDisk);
     137    QString strExtension = UIDiskEditorGroupBox::defaultExtension(comMediumFormat, KDeviceType_HardDisk);
    138138    QString strMediumFilePath =
    139139        UIDiskEditorGroupBox::constructMediumFilePath(UIDiskVariantGroupBox::appendExtension(m_strDefaultName,
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd/UIWizardNewVDSizeLocationPage.cpp

    r91061 r91256  
    7070    QString strMediumPath =
    7171        UIDiskEditorGroupBox::appendExtension(strSelectedPath,
    72                                               UIDiskFormatsGroupBox::defaultExtension(pWizard->mediumFormat(), KDeviceType_HardDisk));
     72                                              UIDiskEditorGroupBox::defaultExtension(pWizard->mediumFormat(), KDeviceType_HardDisk));
    7373    QFileInfo mediumPath(strMediumPath);
    7474    m_pMediumSizePathGroup->setMediumPath(QDir::toNativeSeparators(mediumPath.absoluteFilePath()));
     
    9090    QString strMediumPath =
    9191        UIDiskEditorGroupBox::appendExtension(strPath,
    92                                               UIDiskFormatsGroupBox::defaultExtension(pWizard->mediumFormat(), KDeviceType_HardDisk));
     92                                              UIDiskEditorGroupBox::defaultExtension(pWizard->mediumFormat(), KDeviceType_HardDisk));
    9393    pWizard->setMediumPath(strMediumPath);
    9494    emit completeChanged();
     
    107107    if (!m_userModifiedParameters.contains("MediumPath"))
    108108    {
    109         QString strExtension = UIDiskFormatsGroupBox::defaultExtension(pWizard->mediumFormat(), KDeviceType_HardDisk);
     109        QString strExtension = UIDiskEditorGroupBox::defaultExtension(pWizard->mediumFormat(), KDeviceType_HardDisk);
    110110        QString strMediumFilePath =
    111111            UIDiskEditorGroupBox::constructMediumFilePath(UIDiskVariantGroupBox::appendExtension(m_strDefaultName,
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMDiskPage.cpp

    r91220 r91256  
    296296        setWidgetVisibility(pWizard->mediumFormat());
    297297    }
    298     QString strDefaultExtension =  UIDiskFormatsGroupBox::defaultExtension(pWizard->mediumFormat(), KDeviceType_HardDisk);
     298    QString strDefaultExtension =  UIDiskEditorGroupBox::defaultExtension(pWizard->mediumFormat(), KDeviceType_HardDisk);
    299299
    300300    /* We set the medium name and path according to machine name/path and do not allow user change these in the guided mode: */
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMExpertPage.cpp

    r91220 r91256  
    688688    QString strMediumPath =
    689689        UIDiskEditorGroupBox::appendExtension(strSelectedPath,
    690                                               UIDiskFormatsGroupBox::defaultExtension(pWizard->mediumFormat(), KDeviceType_HardDisk));
     690                                              UIDiskEditorGroupBox::defaultExtension(pWizard->mediumFormat(), KDeviceType_HardDisk));
    691691    QFileInfo mediumPath(strMediumPath);
    692692    m_pSizeAndLocationGroup->setMediumPath(QDir::toNativeSeparators(mediumPath.absoluteFilePath()));
     
    806806            strMediumPath = uiCommon().virtualBox().GetSystemProperties().GetDefaultMachineFolder();
    807807    }
    808     QString strExtension = UIDiskFormatsGroupBox::defaultExtension(pWizard->mediumFormat(), KDeviceType_HardDisk);
     808    QString strExtension = UIDiskEditorGroupBox::defaultExtension(pWizard->mediumFormat(), KDeviceType_HardDisk);
    809809    if (m_pSizeAndLocationGroup)
    810810    {
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