VirtualBox

Changeset 87088 in vbox for trunk/src


Ignore:
Timestamp:
Dec 14, 2020 5:54:10 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9871: Network Manager: A bit of cleanup here and there, mostly paranoia to make dialog suitable for debugging.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/networkmanager
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/networkmanager/UINetworkManager.cpp

    r87001 r87088  
    199199    , m_pDetailsWidget(0)
    200200{
    201     /* Prepare: */
    202201    prepare();
    203     uiCommon().setHelpKeyword(this, "networkingdetails");
    204202}
    205203
    206204QMenu *UINetworkManagerWidget::menu() const
    207205{
     206    AssertPtrReturn(m_pActionPool, 0);
    208207    return m_pActionPool->action(UIActionIndexMN_M_NetworkWindow)->menu();
    209208}
     
    223222
    224223    /* Translate tree-widget: */
    225     const QStringList fields = QStringList()
    226                                << UINetworkManager::tr("Name")
    227                                << UINetworkManager::tr("IPv4 Address/Mask")
    228                                << UINetworkManager::tr("IPv6 Address/Mask")
    229                                << UINetworkManager::tr("DHCP Server");
    230     m_pTreeWidget->setHeaderLabels(fields);
     224    if (m_pTreeWidget)
     225    {
     226        const QStringList fields = QStringList()
     227                                   << UINetworkManager::tr("Name")
     228                                   << UINetworkManager::tr("IPv4 Address/Mask")
     229                                   << UINetworkManager::tr("IPv6 Address/Mask")
     230                                   << UINetworkManager::tr("DHCP Server");
     231        m_pTreeWidget->setHeaderLabels(fields);
     232    }
    231233}
    232234
     
    251253void UINetworkManagerWidget::sltResetHostNetworkDetailsChanges()
    252254{
    253     /* Just push the current item data there again: */
     255    /* Just push current item data to details-widget again: */
    254256    sltHandleCurrentItemChange();
    255257}
     
    257259void UINetworkManagerWidget::sltApplyHostNetworkDetailsChanges()
    258260{
     261    /* Check tree-widget: */
     262    AssertMsgReturnVoid(m_pTreeWidget, ("Tree-widget isn't created!\n"));
     263
    259264    /* Get network item: */
    260265    UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidget->currentItem());
    261266    AssertMsgReturnVoid(pItem, ("Current item must not be null!\n"));
     267
     268    /* Check details-widget: */
     269    AssertMsgReturnVoid(m_pDetailsWidget, ("Details-widget isn't created!\n"));
    262270
    263271    /* Get item data: */
     
    431439void UINetworkManagerWidget::sltRemoveHostNetwork()
    432440{
     441    /* Check tree-widget: */
     442    AssertMsgReturnVoid(m_pTreeWidget, ("Tree-widget isn't created!\n"));
     443
    433444    /* Get network item: */
    434445    UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidget->currentItem());
     
    514525    gEDataManager->setHostNetworkManagerDetailsExpanded(fVisible);
    515526    /* Show/hide details area and Apply button: */
    516     m_pDetailsWidget->setVisible(fVisible);
    517     /* Notify external lsiteners: */
     527    if (m_pDetailsWidget)
     528        m_pDetailsWidget->setVisible(fVisible);
     529    /* Notify external listeners: */
    518530    emit sigHostNetworkDetailsVisibilityChanged(fVisible);
    519531}
     
    527539void UINetworkManagerWidget::sltAdjustTreeWidget()
    528540{
    529     /* Get the tree-widget abstract interface: */
    530     QAbstractItemView *pItemView = m_pTreeWidget;
    531     /* Get the tree-widget header-view: */
    532     QHeaderView *pItemHeader = m_pTreeWidget->header();
    533 
    534     /* Calculate the total tree-widget width: */
    535     const int iTotal = m_pTreeWidget->viewport()->width();
    536     /* Look for a minimum width hints for non-important columns: */
    537     const int iMinWidth1 = qMax(pItemView->sizeHintForColumn(Column_IPv4), pItemHeader->sectionSizeHint(Column_IPv4));
    538     const int iMinWidth2 = qMax(pItemView->sizeHintForColumn(Column_IPv6), pItemHeader->sectionSizeHint(Column_IPv6));
    539     const int iMinWidth3 = qMax(pItemView->sizeHintForColumn(Column_DHCP), pItemHeader->sectionSizeHint(Column_DHCP));
    540     /* Propose suitable width hints for non-important columns: */
    541     const int iWidth1 = iMinWidth1 < iTotal / Column_Max ? iMinWidth1 : iTotal / Column_Max;
    542     const int iWidth2 = iMinWidth2 < iTotal / Column_Max ? iMinWidth2 : iTotal / Column_Max;
    543     const int iWidth3 = iMinWidth3 < iTotal / Column_Max ? iMinWidth3 : iTotal / Column_Max;
    544     /* Apply the proposal: */
    545     m_pTreeWidget->setColumnWidth(Column_IPv4, iWidth1);
    546     m_pTreeWidget->setColumnWidth(Column_IPv6, iWidth2);
    547     m_pTreeWidget->setColumnWidth(Column_DHCP, iWidth3);
    548     m_pTreeWidget->setColumnWidth(Column_Name, iTotal - iWidth1 - iWidth2 - iWidth3);
     541    /* Check tree-widget: */
     542    if (m_pTreeWidget)
     543    {
     544        /* Get the tree-widget abstract interface: */
     545        QAbstractItemView *pItemView = m_pTreeWidget;
     546        /* Get the tree-widget header-view: */
     547        QHeaderView *pItemHeader = m_pTreeWidget->header();
     548
     549        /* Calculate the total tree-widget width: */
     550        const int iTotal = m_pTreeWidget->viewport()->width();
     551        /* Look for a minimum width hints for non-important columns: */
     552        const int iMinWidth1 = qMax(pItemView->sizeHintForColumn(Column_IPv4), pItemHeader->sectionSizeHint(Column_IPv4));
     553        const int iMinWidth2 = qMax(pItemView->sizeHintForColumn(Column_IPv6), pItemHeader->sectionSizeHint(Column_IPv6));
     554        const int iMinWidth3 = qMax(pItemView->sizeHintForColumn(Column_DHCP), pItemHeader->sectionSizeHint(Column_DHCP));
     555        /* Propose suitable width hints for non-important columns: */
     556        const int iWidth1 = iMinWidth1 < iTotal / Column_Max ? iMinWidth1 : iTotal / Column_Max;
     557        const int iWidth2 = iMinWidth2 < iTotal / Column_Max ? iMinWidth2 : iTotal / Column_Max;
     558        const int iWidth3 = iMinWidth3 < iTotal / Column_Max ? iMinWidth3 : iTotal / Column_Max;
     559        /* Apply the proposal: */
     560        m_pTreeWidget->setColumnWidth(Column_IPv4, iWidth1);
     561        m_pTreeWidget->setColumnWidth(Column_IPv6, iWidth2);
     562        m_pTreeWidget->setColumnWidth(Column_DHCP, iWidth3);
     563        m_pTreeWidget->setColumnWidth(Column_Name, iTotal - iWidth1 - iWidth2 - iWidth3);
     564    }
    549565}
    550566
     
    635651void UINetworkManagerWidget::sltHandleCurrentItemChange()
    636652{
     653    /* Check tree-widget: */
     654    AssertMsgReturnVoid(m_pTreeWidget, ("Tree-widget isn't created!\n"));
     655
    637656    /* Get network item: */
    638657    UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidget->currentItem());
     
    641660    m_pActionPool->action(UIActionIndexMN_M_Network_S_Remove)->setEnabled(pItem);
    642661    m_pActionPool->action(UIActionIndexMN_M_Network_T_Details)->setEnabled(pItem);
     662
     663    /* Check details-widget: */
     664    AssertMsgReturnVoid(m_pDetailsWidget, ("Details-widget isn't created!\n"));
    643665
    644666    /* If there is an item => update details data: */
     
    655677void UINetworkManagerWidget::sltHandleContextMenuRequest(const QPoint &position)
    656678{
     679    /* Check tree-widget: */
     680    AssertMsgReturnVoid(m_pTreeWidget, ("Tree-widget isn't created!\n"));
     681
    657682    /* Compose temporary context-menu: */
    658683    QMenu menu;
     
    673698void UINetworkManagerWidget::prepare()
    674699{
    675     /* Prepare actions: */
     700    /* Prepare self: */
     701    uiCommon().setHelpKeyword(this, "networkingdetails");
     702
     703    /* Prepare stuff: */
    676704    prepareActions();
    677     /* Prepare widgets: */
    678705    prepareWidgets();
    679706
     
    711738    /* Create main-layout: */
    712739    new QVBoxLayout(this);
    713     AssertPtrReturnVoid(layout());
     740    if (layout())
    714741    {
    715742        /* Configure layout: */
     
    735762    /* Create toolbar: */
    736763    m_pToolBar = new QIToolBar(parentWidget());
    737     AssertPtrReturnVoid(m_pToolBar);
     764    if (m_pToolBar)
    738765    {
    739766        /* Configure toolbar: */
     
    766793void UINetworkManagerWidget::prepareTreeWidget()
    767794{
    768     /* Create tree-widget: */
    769     m_pTreeWidget = new QITreeWidget;
    770     AssertPtrReturnVoid(m_pTreeWidget);
    771     {
    772         /* Configure tree-widget: */
     795    /* Prepare tree-widget: */
     796    m_pTreeWidget = new QITreeWidget(this);
     797    if (m_pTreeWidget)
     798    {
    773799        m_pTreeWidget->setRootIsDecorated(false);
    774800        m_pTreeWidget->setAlternatingRowColors(true);
     
    795821void UINetworkManagerWidget::prepareDetailsWidget()
    796822{
    797     /* Create details-widget: */
    798     m_pDetailsWidget = new UINetworkDetailsWidget(m_enmEmbedding);
    799     AssertPtrReturnVoid(m_pDetailsWidget);
    800     {
    801         /* Configure details-widget: */
     823    /* Prepare details-widget: */
     824    m_pDetailsWidget = new UINetworkDetailsWidget(m_enmEmbedding, this);
     825    if (m_pDetailsWidget)
     826    {
    802827        m_pDetailsWidget->setVisible(false);
    803828        m_pDetailsWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
     
    817842{
    818843    /* Details action/widget: */
    819     m_pActionPool->action(UIActionIndexMN_M_Network_T_Details)->setChecked(gEDataManager->hostNetworkManagerDetailsExpanded());
    820     sltToggleHostNetworkDetailsVisibility(m_pActionPool->action(UIActionIndexMN_M_Network_T_Details)->isChecked());
     844    if (m_pActionPool)
     845    {
     846        m_pActionPool->action(UIActionIndexMN_M_Network_T_Details)->setChecked(gEDataManager->hostNetworkManagerDetailsExpanded());
     847        sltToggleHostNetworkDetailsVisibility(m_pActionPool->action(UIActionIndexMN_M_Network_T_Details)->isChecked());
     848    }
    821849}
    822850
    823851void UINetworkManagerWidget::loadHostNetworks()
    824852{
     853    /* Check tree-widget: */
     854    if (!m_pTreeWidget)
     855        return;
     856
    825857    /* Clear tree first of all: */
    826858    m_pTreeWidget->clear();
     
    917949    /* Create new item: */
    918950    UIItemHostNetwork *pItem = new UIItemHostNetwork;
    919     AssertPtrReturnVoid(pItem);
     951    if (pItem)
    920952    {
    921953        /* Configure item: */
     
    933965{
    934966    /* Update passed item: */
    935     AssertPtrReturnVoid(pItem);
     967    if (pItem)
    936968    {
    937969        /* Configure item: */
     
    10161048void UINetworkManager::configureCentralWidget()
    10171049{
    1018     /* Create widget: */
     1050    /* Prepare widget: */
    10191051    UINetworkManagerWidget *pWidget = new UINetworkManagerWidget(EmbedTo_Dialog, m_pActionPool, true, this);
    1020     AssertPtrReturnVoid(pWidget);
    1021     {
    1022         /* Configure widget: */
     1052    if (pWidget)
     1053    {
    10231054        setWidget(pWidget);
    10241055        setWidgetMenu(pWidget->menu());
  • trunk/src/VBox/Frontends/VirtualBox/src/networkmanager/UINetworkManager.h

    r86997 r87088  
    6161      * @param  fShowToolbar  Brings whether we should create/show toolbar. */
    6262    UINetworkManagerWidget(EmbedTo enmEmbedding, UIActionPool *pActionPool,
    63                                bool fShowToolbar = true, QWidget *pParent = 0);
     63                           bool fShowToolbar = true, QWidget *pParent = 0);
    6464
    6565    /** Returns the menu. */
     
    161161      * @{ */
    162162        /** Holds the widget embedding type. */
    163         const EmbedTo m_enmEmbedding;
     163        const EmbedTo  m_enmEmbedding;
    164164        /** Holds the action-pool reference. */
    165         UIActionPool *m_pActionPool;
     165        UIActionPool  *m_pActionPool;
    166166        /** Holds whether we should create/show toolbar. */
    167         const bool    m_fShowToolbar;
     167        const bool     m_fShowToolbar;
    168168    /** @} */
    169169
     
    177177      * @{ */
    178178        /** Holds the tree-widget instance. */
    179         QITreeWidget *m_pTreeWidget;
     179        QITreeWidget           *m_pTreeWidget;
    180180        /** Holds the details-widget instance. */
    181181        UINetworkDetailsWidget *m_pDetailsWidget;
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