VirtualBox

Changeset 101604 in vbox for trunk


Ignore:
Timestamp:
Oct 26, 2023 12:56:21 PM (15 months ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10513: Machine settings / Serial page: Reworking prepare/cleanup cascade a bit.

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

Legend:

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

    r101497 r101604  
    125125    /** Constructs tab passing @a pParent to the base-class.
    126126      * @param  pParentPage  Holds the parent page reference allowing to access some of API there. */
    127     UIMachineSettingsSerial(QITabWidget *pParent, UIMachineSettingsSerialPage *pParentPage);
     127    UIMachineSettingsSerial(UIEditor *pParent, UIMachineSettingsSerialPage *pParentPage);
    128128
    129129    /** Loads port data from @a portCache. */
     
    181181*********************************************************************************************************************************/
    182182
    183 UIMachineSettingsSerial::UIMachineSettingsSerial(QITabWidget *pParent, UIMachineSettingsSerialPage *pParentPage)
     183UIMachineSettingsSerial::UIMachineSettingsSerial(UIEditor *pParent, UIMachineSettingsSerialPage *pParentPage)
    184184    : UIEditor(pParent)
    185185    , m_pParentPage(pParentPage)
     
    379379    if (pLayout)
    380380    {
    381 #ifdef VBOX_WS_MAC
    382             /* On Mac OS X we can do a bit of smoothness: */
    383             int iLeft, iTop, iRight, iBottom;
    384             pLayout->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom);
    385             pLayout->setContentsMargins(iLeft / 2, iTop / 2, iRight / 2, iBottom / 2);
    386 #endif
     381        pLayout->setContentsMargins(0, 0, 0, 0);
    387382
    388383        /* Prepare settings editor: */
     
    508503    {
    509504        /* Get port page: */
    510         UIMachineSettingsSerial *pTab = qobject_cast<UIMachineSettingsSerial*>(m_pTabWidget->widget(iSlot));
    511         AssertPtrReturnVoid(pTab);
     505        UIMachineSettingsSerial *pTabEditor = m_tabEditors.at(iSlot);
     506        AssertPtrReturnVoid(pTabEditor);
    512507
    513508        /* Load old data from cache: */
    514         pTab->getPortDataFromCache(m_pCache->child(iSlot));
     509        pTabEditor->getPortDataFromCache(m_pCache->child(iSlot));
    515510
    516511        /* Setup tab order: */
    517         pLastFocusWidget = pTab->setOrderAfter(pLastFocusWidget);
     512        pLastFocusWidget = pTabEditor->setOrderAfter(pLastFocusWidget);
    518513    }
    519514
     
    542537    {
    543538        /* Getting port page: */
    544         UIMachineSettingsSerial *pTab = qobject_cast<UIMachineSettingsSerial*>(m_pTabWidget->widget(iSlot));
    545         AssertPtrReturnVoid(pTab);
     539        UIMachineSettingsSerial *pTabEditor = m_tabEditors.at(iSlot);
     540        AssertPtrReturnVoid(pTabEditor);
    546541
    547542        /* Gather new data: */
    548         pTab->putPortDataToCache(m_pCache->child(iSlot));
     543        pTabEditor->putPortDataToCache(m_pCache->child(iSlot));
    549544    }
    550545
     
    575570
    576571    /* Delegate validation to adapter tabs: */
    577     for (int iIndex = 0; iIndex < m_pTabWidget->count(); ++iIndex)
    578     {
    579         UIMachineSettingsSerial *pTab = qobject_cast<UIMachineSettingsSerial*>(m_pTabWidget->widget(iIndex));
    580         AssertPtrReturn(pTab, false);
    581         if (!pTab->validate(messages))
     572    for (int iSlot = 0; iSlot < m_pTabWidget->count(); ++iSlot)
     573    {
     574        UIMachineSettingsSerial *pTabEditor = m_tabEditors.at(iSlot);
     575        AssertPtrReturn(pTabEditor, false);
     576        if (!pTabEditor->validate(messages))
    582577            fValid = false;
    583578    }
     
    595590    for (int iSlot = 0; iSlot < m_pTabWidget->count(); ++iSlot)
    596591    {
    597         UIMachineSettingsSerial *pTab = qobject_cast<UIMachineSettingsSerial*>(m_pTabWidget->widget(iSlot));
    598         AssertPtrReturnVoid(pTab);
    599         m_pTabWidget->setTabText(iSlot, pTab->tabTitle());
     592        UIMachineSettingsSerial *pTabEditor = m_tabEditors.at(iSlot);
     593        AssertPtrReturnVoid(pTabEditor);
     594        m_pTabWidget->setTabText(iSlot, pTabEditor->tabTitle());
    600595    }
    601596}
     
    615610                                     m_pCache->childCount() > iSlot &&
    616611                                     m_pCache->child(iSlot).base().m_fPortEnabled));
    617         UIMachineSettingsSerial *pTab = qobject_cast<UIMachineSettingsSerial*>(m_pTabWidget->widget(iSlot));
    618         AssertPtrReturnVoid(pTab);
    619         pTab->polishTab();
     612        UIMachineSettingsSerial *pTabEditor = m_tabEditors.at(iSlot);
     613        AssertPtrReturnVoid(pTabEditor);
     614        pTabEditor->polishTab();
    620615    }
    621616}
     
    639634    AssertPtrReturnVoid(m_pCache);
    640635
    641     /* Create main layout: */
     636    /* Prepare everything: */
     637    prepareWidgets();
     638
     639    /* Apply language settings: */
     640    retranslateUi();
     641}
     642
     643void UIMachineSettingsSerialPage::prepareWidgets()
     644{
     645    /* Prepare main layout: */
    642646    QVBoxLayout *pLayoutMain = new QVBoxLayout(this);
    643647    if (pLayoutMain)
    644648    {
    645         /* Creating tab-widget: */
    646         m_pTabWidget = new QITabWidget;
     649        /* Prepare tab-widget: */
     650        m_pTabWidget = new QITabWidget(this);
    647651        if (m_pTabWidget)
    648652        {
     
    652656            /* Create corresponding port tabs: */
    653657            for (ulong uSlot = 0; uSlot < uCount; ++uSlot)
    654             {
    655                 /* Create port tab: */
    656                 UIMachineSettingsSerial *pTab = new UIMachineSettingsSerial(m_pTabWidget, this);
    657                 if (pTab)
    658                 {
    659                     /* Tab connections: */
    660                     connect(pTab, &UIMachineSettingsSerial::sigPortChanged,
    661                             this, &UIMachineSettingsSerialPage::sltHandlePortChange);
    662                     connect(pTab, &UIMachineSettingsSerial::sigPathChanged,
    663                             this, &UIMachineSettingsSerialPage::sltHandlePathChange);
    664                     connect(pTab, &UIMachineSettingsSerial::sigValidityChanged,
    665                             this, &UIMachineSettingsSerialPage::revalidate);
    666 
    667                     /* Add tab into tab-widget: */
    668                     addEditor(pTab);
    669                     m_pTabWidget->addTab(pTab, pTab->tabTitle());
    670                 }
    671             }
    672 
    673             /* Add tab-widget into layout: */
     658                prepareTab();
     659
    674660            pLayoutMain->addWidget(m_pTabWidget);
    675661        }
    676662    }
     663}
     664
     665void UIMachineSettingsSerialPage::prepareTab()
     666{
     667    /* Prepare tab: */
     668    UIEditor *pTab = new UIEditor(m_pTabWidget);
     669    if (pTab)
     670    {
     671        /* Prepare tab layout: */
     672        QVBoxLayout *pLayout = new QVBoxLayout(pTab);
     673        if (pLayout)
     674        {
     675#ifdef VBOX_WS_MAC
     676            /* On Mac OS X we can do a bit of smoothness: */
     677            int iLeft, iTop, iRight, iBottom;
     678            pLayout->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom);
     679            pLayout->setContentsMargins(iLeft / 2, iTop / 2, iRight / 2, iBottom / 2);
     680#endif
     681
     682            /* Create port tab-editor: */
     683            UIMachineSettingsSerial *pEditor = new UIMachineSettingsSerial(pTab, this);
     684            if (pEditor)
     685            {
     686                m_tabEditors << pEditor;
     687                prepareConnections(pEditor);
     688                pTab->addEditor(pEditor);
     689                pLayout->addWidget(pEditor);
     690            }
     691
     692            pLayout->addStretch();
     693        }
     694
     695        addEditor(pTab);
     696        m_pTabWidget->addTab(pTab, QString());
     697    }
     698}
     699
     700void UIMachineSettingsSerialPage::prepareConnections(UIMachineSettingsSerial *pTabEditor)
     701{
     702    /* Tab connections: */
     703    connect(pTabEditor, &UIMachineSettingsSerial::sigPortChanged,
     704            this, &UIMachineSettingsSerialPage::sltHandlePortChange);
     705    connect(pTabEditor, &UIMachineSettingsSerial::sigPathChanged,
     706            this, &UIMachineSettingsSerialPage::sltHandlePathChange);
     707    connect(pTabEditor, &UIMachineSettingsSerial::sigValidityChanged,
     708            this, &UIMachineSettingsSerialPage::revalidate);
    677709}
    678710
     
    696728    for (int iSlot = 0; iSlot < m_pTabWidget->count(); ++iSlot)
    697729    {
    698         UIMachineSettingsSerial *pTab = qobject_cast<UIMachineSettingsSerial*>(m_pTabWidget->widget(iSlot));
    699         AssertPtrReturnVoid(pTab);
    700         m_ports[iSlot] = pTab->isPortEnabled() ? qMakePair(pTab->irq(), pTab->ioAddress()) : qMakePair(QString(), QString());
     730        UIMachineSettingsSerial *pTabEditor = m_tabEditors.at(iSlot);
     731        AssertPtrReturnVoid(pTabEditor);
     732        m_ports[iSlot] = pTabEditor->isPortEnabled() ? qMakePair(pTabEditor->irq(), pTabEditor->ioAddress()) : qMakePair(QString(), QString());
    701733    }
    702734}
     
    714746    for (int iSlot = 0; iSlot < m_pTabWidget->count(); ++iSlot)
    715747    {
    716         UIMachineSettingsSerial *pTab = qobject_cast<UIMachineSettingsSerial*>(m_pTabWidget->widget(iSlot));
    717         AssertPtrReturnVoid(pTab);
    718         m_paths[iSlot] = pTab->isPortEnabled() ? pTab->path() : QString();
     748        UIMachineSettingsSerial *pTabEditor = m_tabEditors.at(iSlot);
     749        AssertPtrReturnVoid(pTabEditor);
     750        m_paths[iSlot] = pTabEditor->isPortEnabled() ? pTabEditor->path() : QString();
    719751    }
    720752}
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSerial.h

    r98103 r101604  
    3737/* Forward declarations: */
    3838class QITabWidget;
    39 class UIMachineSettingsSerialPage;
     39class UIMachineSettingsSerial;
    4040struct UIDataSettingsMachineSerial;
    4141struct UIDataSettingsMachineSerialPort;
     
    9999    /** Prepares all. */
    100100    void prepare();
     101    /** Prepares widgets. */
     102    void prepareWidgets();
     103    /** Prepare tab. */
     104    void prepareTab();
     105    /** Prepares connections. */
     106    void prepareConnections(UIMachineSettingsSerial *pTabEditor);
    101107    /** Cleanups all. */
    102108    void cleanup();
     
    122128    /** Holds the tab-widget instance. */
    123129    QITabWidget *m_pTabWidget;
     130
     131    /** Holds the list of tab-editors. */
     132    QList<UIMachineSettingsSerial*>  m_tabEditors;
    124133};
    125134
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