VirtualBox

Changeset 85998 in vbox for trunk/src


Ignore:
Timestamp:
Sep 2, 2020 1:12:28 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9812: Global preferences: Prepare cascade cleanup for Network page.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsNetwork.cpp

    r85808 r85998  
    217217
    218218UIGlobalSettingsNetwork::UIGlobalSettingsNetwork()
    219     : m_pActionAddNATNetwork(0), m_pActionRemoveNATNetwork(0), m_pActionEditNATNetwork(0)
    220     , m_pCache(0)
    221     , m_pTreeNetworkNAT(0)
    222     , m_pNetworkLabel(0)
    223     , m_pLayoutNAT(0)
     219    : m_pCache(0)
     220    , m_pLabelSeparator(0)
     221    , m_pLayoutNATNetwork(0)
     222    , m_pTreeWidgetNATNetwork(0)
    224223    , m_pToolbarNetworkNAT(0)
     224    , m_pActionAddNATNetwork(0)
     225    , m_pActionRemoveNATNetwork(0)
     226    , m_pActionEditNATNetwork(0)
    225227{
    226228    /* Prepare: */
     
    261263    for (int i = 0; i < m_pCache->childCount(); ++i)
    262264        createTreeWidgetItemForNATNetwork(m_pCache->child(i));
    263     m_pTreeNetworkNAT->sortByColumn(1, Qt::AscendingOrder);
    264     m_pTreeNetworkNAT->setCurrentItem(m_pTreeNetworkNAT->topLevelItem(0));
     265    m_pTreeWidgetNATNetwork->sortByColumn(1, Qt::AscendingOrder);
     266    m_pTreeWidgetNATNetwork->setCurrentItem(m_pTreeWidgetNATNetwork->topLevelItem(0));
    265267    sltHandleCurrentItemChangeNATNetwork();
    266268
     
    275277
    276278    /* Gather new network data: */
    277     for (int i = 0; i < m_pTreeNetworkNAT->topLevelItemCount(); ++i)
    278     {
    279         const UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeNetworkNAT->topLevelItem(i));
     279    for (int i = 0; i < m_pTreeWidgetNATNetwork->topLevelItemCount(); ++i)
     280    {
     281        const UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeWidgetNATNetwork->topLevelItem(i));
    280282        m_pCache->child(pItem->m_strName).cacheCurrentData(*pItem);
    281283        foreach (const UIDataPortForwardingRule &rule, pItem->ipv4rules())
     
    312314
    313315        /* Validate items first: */
    314         for (int i = 0; i < m_pTreeNetworkNAT->topLevelItemCount(); ++i)
     316        for (int i = 0; i < m_pTreeWidgetNATNetwork->topLevelItemCount(); ++i)
    315317        {
    316             UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeNetworkNAT->topLevelItem(i));
     318            UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeWidgetNATNetwork->topLevelItem(i));
    317319            if (!pItem->validate(message))
    318320                fPass = false;
     
    321323        /* And make sure item names are unique: */
    322324        QList<QString> names;
    323         for (int iItemIndex = 0; iItemIndex < m_pTreeNetworkNAT->topLevelItemCount(); ++iItemIndex)
     325        for (int iItemIndex = 0; iItemIndex < m_pTreeWidgetNATNetwork->topLevelItemCount(); ++iItemIndex)
    324326        {
    325             UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeNetworkNAT->topLevelItem(iItemIndex));
     327            UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeWidgetNATNetwork->topLevelItem(iItemIndex));
    326328            const QString strItemName(pItem->newName());
    327329            if (strItemName.isEmpty())
     
    348350void UIGlobalSettingsNetwork::retranslateUi()
    349351{
    350     m_pNetworkLabel->setText(tr("&NAT Networks"));
    351     m_pTreeNetworkNAT->setWhatsThis(tr("Lists all available NAT networks."));
     352    m_pLabelSeparator->setText(tr("&NAT Networks"));
     353    m_pTreeWidgetNATNetwork->setWhatsThis(tr("Lists all available NAT networks."));
    352354
    353355    /* Translate tree-widget columns: */
    354     m_pTreeNetworkNAT->setHeaderLabels(QStringList()
     356    m_pTreeWidgetNATNetwork->setHeaderLabels(QStringList()
    355357                                       << tr("Active", "NAT network")
    356358                                       << tr("Name"));
     
    374376    /* Compose a set of busy names: */
    375377    QSet<QString> names;
    376     for (int i = 0; i < m_pTreeNetworkNAT->topLevelItemCount(); ++i)
    377         names << static_cast<UIItemNetworkNAT*>(m_pTreeNetworkNAT->topLevelItem(i))->name();
     378    for (int i = 0; i < m_pTreeWidgetNATNetwork->topLevelItemCount(); ++i)
     379        names << static_cast<UIItemNetworkNAT*>(m_pTreeWidgetNATNetwork->topLevelItem(i))->name();
    378380    /* Compose a map of busy indexes: */
    379381    QMap<int, bool> presence;
     
    406408    /* Create tree-widget item: */
    407409    createTreeWidgetItemForNATNetwork(data, UIPortForwardingDataList(), UIPortForwardingDataList(), true);
    408     m_pTreeNetworkNAT->sortByColumn(1, Qt::AscendingOrder);
     410    m_pTreeWidgetNATNetwork->sortByColumn(1, Qt::AscendingOrder);
    409411}
    410412
     
    412414{
    413415    /* Get network item: */
    414     UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeNetworkNAT->currentItem());
     416    UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeWidgetNATNetwork->currentItem());
    415417    AssertPtrReturnVoid(pItem);
    416418
     
    426428{
    427429    /* Get network item: */
    428     UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeNetworkNAT->currentItem());
     430    UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeWidgetNATNetwork->currentItem());
    429431    AssertPtrReturnVoid(pItem);
    430432
     
    460462{
    461463    /* Get current item: */
    462     UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeNetworkNAT->currentItem());
     464    UIItemNetworkNAT *pItem = static_cast<UIItemNetworkNAT*>(m_pTreeWidgetNATNetwork->currentItem());
    463465
    464466    /* Update availability: */
     
    471473    /* Compose temporary context-menu: */
    472474    QMenu menu;
    473     if (m_pTreeNetworkNAT->itemAt(position))
     475    if (m_pTreeWidgetNATNetwork->itemAt(position))
    474476    {
    475477        menu.addAction(m_pActionEditNATNetwork);
     
    481483    }
    482484    /* And show it: */
    483     menu.exec(m_pTreeNetworkNAT->mapToGlobal(position));
     485    menu.exec(m_pTreeWidgetNATNetwork->mapToGlobal(position));
    484486}
    485487
    486488void UIGlobalSettingsNetwork::prepare()
    487489{
    488     prepareWidgets();
    489 
    490490    /* Prepare cache: */
    491491    m_pCache = new UISettingsCacheGlobalNetwork;
    492492    AssertPtrReturnVoid(m_pCache);
    493493
    494     /* NAT Network layout created in the .ui file. */
    495     AssertPtrReturnVoid(m_pLayoutNAT);
    496     {
    497         /* Prepare network tree: */
    498         prepareNATNetworkTree();
    499         /* Prepare network toolbar: */
    500         prepareNATNetworkToolbar();
    501         /* Prepare connections: */
    502         prepareConnections();
    503     }
     494    /* Prepare everything: */
     495    prepareWidgets();
     496    prepareConnections();
    504497
    505498    /* Apply language settings: */
     
    509502void UIGlobalSettingsNetwork::prepareWidgets()
    510503{
    511     if (objectName().isEmpty())
    512         setObjectName(QStringLiteral("UIGlobalSettingsNetwork"));
    513     QVBoxLayout *pMainLayout = new QVBoxLayout(this);
    514     pMainLayout->setContentsMargins(0, 0, 0, 0);
    515     pMainLayout->setObjectName(QStringLiteral("pMainLayout"));
    516     m_pNetworkLabel = new QILabelSeparator();
    517     m_pNetworkLabel->setObjectName(QStringLiteral("m_pNetworkLabel"));
    518     pMainLayout->addWidget(m_pNetworkLabel);
    519 
    520     m_pLayoutNAT = new QHBoxLayout();
    521     m_pLayoutNAT->setSpacing(3);
    522     m_pLayoutNAT->setObjectName(QStringLiteral("m_pLayoutNAT"));
    523     m_pTreeNetworkNAT = new QITreeWidget();
    524     m_pTreeNetworkNAT->setObjectName(QStringLiteral("m_pTreeNetworkNAT"));
    525     QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
    526     sizePolicy.setHorizontalStretch(0);
    527     sizePolicy.setVerticalStretch(0);
    528     sizePolicy.setHeightForWidth(m_pTreeNetworkNAT->sizePolicy().hasHeightForWidth());
    529     m_pTreeNetworkNAT->setSizePolicy(sizePolicy);
    530     m_pTreeNetworkNAT->setMinimumSize(QSize(0, 150));
    531     m_pTreeNetworkNAT->setRootIsDecorated(false);
    532     m_pLayoutNAT->addWidget(m_pTreeNetworkNAT);
    533 
    534     m_pToolbarNetworkNAT = new UIToolBar();
    535     m_pToolbarNetworkNAT->setObjectName(QStringLiteral("m_pToolbarNetworkNAT"));
    536     m_pLayoutNAT->addWidget(m_pToolbarNetworkNAT);
    537 
    538     pMainLayout->addLayout(m_pLayoutNAT);
    539     m_pNetworkLabel->setBuddy(m_pTreeNetworkNAT);
    540 }
    541 
    542 void UIGlobalSettingsNetwork::prepareNATNetworkTree()
    543 {
    544     /* NAT Network tree-widget created in the .ui file. */
    545     AssertPtrReturnVoid(m_pTreeNetworkNAT);
    546     {
    547         /* Configure tree-widget: */
    548         m_pTreeNetworkNAT->setColumnCount(2);
    549         m_pTreeNetworkNAT->header()->setStretchLastSection(false);
    550         m_pTreeNetworkNAT->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
    551         m_pTreeNetworkNAT->header()->setSectionResizeMode(1, QHeaderView::Stretch);
    552         m_pTreeNetworkNAT->setContextMenuPolicy(Qt::CustomContextMenu);
     504    /* Prepare main layout: */
     505    QVBoxLayout *pLayoutMain = new QVBoxLayout(this);
     506    if (pLayoutMain)
     507    {
     508        pLayoutMain->setContentsMargins(0, 0, 0, 0);
     509
     510        /* Prepare separator: */
     511        m_pLabelSeparator = new QILabelSeparator(this);
     512        if (m_pLabelSeparator)
     513            pLayoutMain->addWidget(m_pLabelSeparator);
     514
     515        /* Prepare NAT network layout: */
     516        m_pLayoutNATNetwork = new QHBoxLayout(this);
     517        if (m_pLayoutNATNetwork)
     518        {
     519            m_pLayoutNATNetwork->setSpacing(3);
     520
     521            /* Prepare NAT network tree-widget: */
     522            prepareNATNetworkTreeWidget();
     523            /* Prepare NAT network toolbar: */
     524            prepareNATNetworkToolbar();
     525
     526            pLayoutMain->addLayout(m_pLayoutNATNetwork);
     527        }
     528    }
     529}
     530
     531void UIGlobalSettingsNetwork::prepareNATNetworkTreeWidget()
     532{
     533    /* Prepare NAT network tree-widget: */
     534    m_pTreeWidgetNATNetwork = new QITreeWidget(this);
     535    if (m_pTreeWidgetNATNetwork)
     536    {
     537        if (m_pLabelSeparator)
     538            m_pLabelSeparator->setBuddy(m_pTreeWidgetNATNetwork);
     539        m_pTreeWidgetNATNetwork->setColumnCount(2);
     540        m_pTreeWidgetNATNetwork->setRootIsDecorated(false);
     541        m_pTreeWidgetNATNetwork->header()->setStretchLastSection(false);
     542        m_pTreeWidgetNATNetwork->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
     543        m_pTreeWidgetNATNetwork->header()->setSectionResizeMode(1, QHeaderView::Stretch);
     544        m_pTreeWidgetNATNetwork->setContextMenuPolicy(Qt::CustomContextMenu);
     545
     546        m_pLayoutNATNetwork->addWidget(m_pTreeWidgetNATNetwork);
    553547    }
    554548}
     
    556550void UIGlobalSettingsNetwork::prepareNATNetworkToolbar()
    557551{
    558     /* NAT Network toolbar created in the .ui file. */
    559     AssertPtrReturnVoid(m_pToolbarNetworkNAT);
    560     {
    561         /* Configure toolbar: */
     552    /* Prepare NAT network toolbar: */
     553    m_pToolbarNetworkNAT = new UIToolBar(this);
     554    if (m_pToolbarNetworkNAT)
     555    {
    562556        const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
    563557        m_pToolbarNetworkNAT->setIconSize(QSize(iIconMetric, iIconMetric));
    564558        m_pToolbarNetworkNAT->setOrientation(Qt::Vertical);
    565559
    566         /* Create' Add NAT Network' action: */
     560        /* Prepare 'Add NAT Network' action: */
    567561        m_pActionAddNATNetwork = m_pToolbarNetworkNAT->addAction(UIIconPool::iconSet(":/host_iface_add_16px.png",
    568562                                                                                     ":/host_iface_add_disabled_16px.png"),
    569563                                                                 QString(), this, SLOT(sltAddNATNetwork()));
    570         AssertPtrReturnVoid(m_pActionAddNATNetwork);
    571         {
    572             /* Configure action: */
     564        if (m_pActionAddNATNetwork)
    573565            m_pActionAddNATNetwork->setShortcuts(QList<QKeySequence>() << QKeySequence("Ins") << QKeySequence("Ctrl+N"));
    574         }
    575 
    576         /* Create 'Remove NAT Network' action: */
     566
     567        /* Prepare 'Remove NAT Network' action: */
    577568        m_pActionRemoveNATNetwork = m_pToolbarNetworkNAT->addAction(UIIconPool::iconSet(":/host_iface_remove_16px.png",
    578569                                                                                        ":/host_iface_remove_disabled_16px.png"),
    579570                                                                    QString(), this, SLOT(sltRemoveNATNetwork()));
    580         AssertPtrReturnVoid(m_pActionRemoveNATNetwork);
    581         {
    582             /* Configure action: */
     571        if (m_pActionRemoveNATNetwork)
    583572            m_pActionRemoveNATNetwork->setShortcuts(QList<QKeySequence>() << QKeySequence("Del") << QKeySequence("Ctrl+R"));
    584         }
    585 
    586         /* Create 'Edit NAT Network' action: */
     573
     574        /* Prepare 'Edit NAT Network' action: */
    587575        m_pActionEditNATNetwork = m_pToolbarNetworkNAT->addAction(UIIconPool::iconSet(":/host_iface_edit_16px.png",
    588576                                                                                      ":/host_iface_edit_disabled_16px.png"),
    589577                                                                  QString(), this, SLOT(sltEditNATNetwork()));
    590         AssertPtrReturnVoid(m_pActionEditNATNetwork);
    591         {
    592             /* Configure action: */
     578        if (m_pActionEditNATNetwork)
    593579            m_pActionEditNATNetwork->setShortcuts(QList<QKeySequence>() << QKeySequence("Space") << QKeySequence("F2"));
    594         }
     580
     581        m_pLayoutNATNetwork->addWidget(m_pToolbarNetworkNAT);
    595582    }
    596583}
     
    598585void UIGlobalSettingsNetwork::prepareConnections()
    599586{
    600     /* Configure 'NAT Network' connections: */
    601     connect(m_pTreeNetworkNAT, &QITreeWidget::currentItemChanged,
     587    /* Configure NAT network connections: */
     588    connect(m_pTreeWidgetNATNetwork, &QITreeWidget::currentItemChanged,
    602589            this, &UIGlobalSettingsNetwork::sltHandleCurrentItemChangeNATNetwork);
    603     connect(m_pTreeNetworkNAT, &QITreeWidget::customContextMenuRequested,
     590    connect(m_pTreeWidgetNATNetwork, &QITreeWidget::customContextMenuRequested,
    604591            this, &UIGlobalSettingsNetwork::sltHandleContextMenuRequestNATNetwork);
    605     connect(m_pTreeNetworkNAT, &QITreeWidget::itemDoubleClicked,
     592    connect(m_pTreeWidgetNATNetwork, &QITreeWidget::itemDoubleClicked,
    606593            this, &UIGlobalSettingsNetwork::sltEditNATNetwork);
    607     connect(m_pTreeNetworkNAT, &QITreeWidget::itemChanged,
     594    connect(m_pTreeWidgetNATNetwork, &QITreeWidget::itemChanged,
    608595            this, &UIGlobalSettingsNetwork::sltHandleItemChangeNATNetwork);
    609596}
     
    10181005
    10191006        /* Add item to the tree-widget: */
    1020         m_pTreeNetworkNAT->addTopLevelItem(pItem);
     1007        m_pTreeWidgetNATNetwork->addTopLevelItem(pItem);
    10211008    }
    10221009
    10231010    /* And choose it as current if necessary: */
    10241011    if (fChooseItem)
    1025         m_pTreeNetworkNAT->setCurrentItem(pItem);
     1012        m_pTreeWidgetNATNetwork->setCurrentItem(pItem);
    10261013}
    10271014
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsNetwork.h

    r85808 r85998  
    9494    /** Prepares widgets. */
    9595    void prepareWidgets();
    96     /** Prepares NAT network tree. */
    97     void prepareNATNetworkTree();
     96    /** Prepares NAT network tree-widget. */
     97    void prepareNATNetworkTreeWidget();
    9898    /** Prepares NAT network toolbar. */
    9999    void prepareNATNetworkToolbar();
     
    127127    bool isNetworkCouldBeUpdated(const UISettingsCacheGlobalNetworkNAT &cache) const;
    128128
    129     /** Holds the Add NAT network action instance. */
    130     QAction *m_pActionAddNATNetwork;
    131     /** Holds the Remove NAT network action instance. */
    132     QAction *m_pActionRemoveNATNetwork;
    133     /** Holds the Edit NAT network action instance. */
    134     QAction *m_pActionEditNATNetwork;
    135 
    136129    /** Holds the page data cache instance. */
    137130    UISettingsCacheGlobalNetwork *m_pCache;
     
    139132    /** @name Widgets
    140133     * @{ */
    141        QITreeWidget *m_pTreeNetworkNAT;
    142        QILabelSeparator *m_pNetworkLabel;
    143        QHBoxLayout *m_pLayoutNAT;
    144        UIToolBar *m_pToolbarNetworkNAT;
     134        /** Holds the separator label instance. */
     135        QILabelSeparator *m_pLabelSeparator;
     136        /** Holds the NAT networt layout instance. */
     137        QHBoxLayout      *m_pLayoutNATNetwork;
     138        /** Holds the NAT networt tree-widget instance. */
     139        QITreeWidget     *m_pTreeWidgetNATNetwork;
     140        /** Holds the NAT networt toolbar instance. */
     141        UIToolBar        *m_pToolbarNetworkNAT;
     142        /** Holds the Add NAT network action instance. */
     143        QAction          *m_pActionAddNATNetwork;
     144        /** Holds the Remove NAT network action instance. */
     145        QAction          *m_pActionRemoveNATNetwork;
     146        /** Holds the Edit NAT network action instance. */
     147        QAction          *m_pActionEditNATNetwork;
    145148    /** @} */
    146149};
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