VirtualBox

Ignore:
Timestamp:
Apr 30, 2020 1:23:42 PM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9653: VirtualBox Manager: Cleanup for Chooser pane widget.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooser.cpp

    r83674 r84103  
    2020
    2121/* GUI includes: */
     22#include "UICommon.h"
    2223#include "UIChooser.h"
    2324#include "UIChooserModel.h"
    2425#include "UIChooserView.h"
    2526#include "UIVirtualBoxManagerWidget.h"
    26 #include "UICommon.h"
    2727
    2828
     
    3030    : QWidget(pParent)
    3131    , m_pManagerWidget(pParent)
    32     , m_pMainLayout(0)
    3332    , m_pChooserModel(0)
    3433    , m_pChooserView(0)
    3534{
    36     /* Prepare: */
    3735    prepare();
    3836}
     
    4038UIChooser::~UIChooser()
    4139{
    42     /* Cleanup: */
    4340    cleanup();
    4441}
     
    4643UIActionPool *UIChooser::actionPool() const
    4744{
     45    AssertPtrReturn(managerWidget(), 0);
    4846    return managerWidget()->actionPool();
    4947}
     
    5149UIVirtualMachineItem *UIChooser::currentItem() const
    5250{
    53     return m_pChooserModel->firstSelectedMachineItem();
     51    AssertPtrReturn(model(), 0);
     52    return model()->firstSelectedMachineItem();
    5453}
    5554
    5655QList<UIVirtualMachineItem*> UIChooser::currentItems() const
    5756{
    58     return m_pChooserModel->selectedMachineItems();
     57    AssertPtrReturn(model(), QList<UIVirtualMachineItem*>());
     58    return model()->selectedMachineItems();
    5959}
    6060
    6161bool UIChooser::isGroupItemSelected() const
    6262{
    63     return m_pChooserModel->isGroupItemSelected();
     63    AssertPtrReturn(model(), false);
     64    return model()->isGroupItemSelected();
    6465}
    6566
    6667bool UIChooser::isGlobalItemSelected() const
    6768{
    68     return m_pChooserModel->isGlobalItemSelected();
     69    AssertPtrReturn(model(), false);
     70    return model()->isGlobalItemSelected();
    6971}
    7072
    7173bool UIChooser::isMachineItemSelected() const
    7274{
    73     return m_pChooserModel->isMachineItemSelected();
     75    AssertPtrReturn(model(), false);
     76    return model()->isMachineItemSelected();
    7477}
    7578
    7679bool UIChooser::isSingleGroupSelected() const
    7780{
    78     return m_pChooserModel->isSingleGroupSelected();
     81    AssertPtrReturn(model(), false);
     82    return model()->isSingleGroupSelected();
    7983}
    8084
    8185bool UIChooser::isSingleLocalGroupSelected() const
    8286{
    83     return m_pChooserModel->isSingleLocalGroupSelected();
     87    AssertPtrReturn(model(), false);
     88    return model()->isSingleLocalGroupSelected();
    8489}
    8590
    8691bool UIChooser::isSingleCloudProfileGroupSelected() const
    8792{
    88     return m_pChooserModel->isSingleCloudProfileGroupSelected();
     93    AssertPtrReturn(model(), false);
     94    return model()->isSingleCloudProfileGroupSelected();
    8995}
    9096
    9197bool UIChooser::isAllItemsOfOneGroupSelected() const
    9298{
    93     return m_pChooserModel->isAllItemsOfOneGroupSelected();
     99    AssertPtrReturn(model(), false);
     100    return model()->isAllItemsOfOneGroupSelected();
    94101}
    95102
    96103bool UIChooser::isGroupSavingInProgress() const
    97104{
    98     return m_pChooserModel->isGroupSavingInProgress();
     105    AssertPtrReturn(model(), false);
     106    return model()->isGroupSavingInProgress();
    99107}
    100108
     
    102110{
    103111    /* Pass height to a model: */
     112    AssertPtrReturnVoid(model());
    104113    model()->setGlobalItemHeightHint(newSize.height());
    105114}
     
    108117{
    109118    /* Translate scene coordinates to global one: */
     119    AssertPtrReturnVoid(view());
    110120    emit sigToolMenuRequested(enmClass, mapToGlobal(view()->mapFromScene(position)));
    111121}
     
    113123void UIChooser::prepare()
    114124{
    115     /* Prepare palette: */
     125    /* Prepare everything: */
    116126    preparePalette();
    117     /* Prepare layout: */
    118     prepareLayout();
    119     /* Prepare model: */
    120127    prepareModel();
    121     /* Prepare view: */
    122     prepareView();
    123     /* Prepare connections: */
     128    prepareWidgets();
    124129    prepareConnections();
    125130
    126     /* Load settings: */
    127     loadSettings();
     131    /* Init model: */
     132    initModel();
    128133}
    129134
     
    138143}
    139144
    140 void UIChooser::prepareLayout()
    141 {
    142     /* Create main-layout: */
    143     m_pMainLayout = new QVBoxLayout(this);
    144     if (m_pMainLayout)
     145void UIChooser::prepareModel()
     146{
     147    m_pChooserModel = new UIChooserModel(this);
     148}
     149
     150void UIChooser::prepareWidgets()
     151{
     152    /* Prepare main-layout: */
     153    QVBoxLayout *pMainLayout = new QVBoxLayout(this);
     154    if (pMainLayout)
    145155    {
    146         /* Configure main-layout: */
    147         m_pMainLayout->setContentsMargins(0, 0, 0, 0);
    148         m_pMainLayout->setSpacing(0);
     156        pMainLayout->setContentsMargins(0, 0, 0, 0);
     157        pMainLayout->setSpacing(0);
     158
     159        /* Prepare chooser-view: */
     160        m_pChooserView = new UIChooserView(this);
     161        if (m_pChooserView)
     162        {
     163            AssertPtrReturnVoid(model());
     164            m_pChooserView->setScene(model()->scene());
     165            m_pChooserView->show();
     166            setFocusProxy(m_pChooserView);
     167
     168            /* Add into layout: */
     169            pMainLayout->addWidget(m_pChooserView);
     170        }
    149171    }
    150172}
    151173
    152 void UIChooser::prepareModel()
    153 {
    154     /* Create chooser-model: */
    155     m_pChooserModel = new UIChooserModel(this);
    156 }
    157 
    158 void UIChooser::prepareView()
    159 {
    160     /* Setup chooser-view: */
    161     m_pChooserView = new UIChooserView(this);
    162     if (m_pChooserView)
    163     {
    164         /* Configure chooser-view. */
    165         m_pChooserView->setScene(m_pChooserModel->scene());
    166         m_pChooserView->show();
    167         setFocusProxy(m_pChooserView);
    168 
    169         /* Add into layout: */
    170         m_pMainLayout->addWidget(m_pChooserView);
    171     }
    172 }
    173 
    174174void UIChooser::prepareConnections()
    175175{
     176    AssertPtrReturnVoid(model());
     177    AssertPtrReturnVoid(view());
     178
    176179    /* Setup chooser-model connections: */
    177     connect(m_pChooserModel, &UIChooserModel::sigRootItemMinimumWidthHintChanged,
    178             m_pChooserView, &UIChooserView::sltMinimumWidthHintChanged);
    179     connect(m_pChooserModel, &UIChooserModel::sigToolMenuRequested,
     180    connect(model(), &UIChooserModel::sigRootItemMinimumWidthHintChanged,
     181            view(), &UIChooserView::sltMinimumWidthHintChanged);
     182    connect(model(), &UIChooserModel::sigToolMenuRequested,
    180183            this, &UIChooser::sltToolMenuRequested);
    181     connect(m_pChooserModel, &UIChooserModel::sigCloudMachineStateChange,
     184    connect(model(), &UIChooserModel::sigCloudMachineStateChange,
    182185            this, &UIChooser::sigCloudMachineStateChange);
    183186
    184187    /* Setup chooser-view connections: */
    185     connect(m_pChooserView, &UIChooserView::sigResized,
    186             m_pChooserModel, &UIChooserModel::sltHandleViewResized);
    187 }
    188 
    189 void UIChooser::loadSettings()
    190 {
    191     /* Init model: */
    192     m_pChooserModel->init();
    193 }
    194 
    195 void UIChooser::saveSettings()
     188    connect(view(), &UIChooserView::sigResized,
     189            model(), &UIChooserModel::sltHandleViewResized);
     190}
     191
     192void UIChooser::initModel()
     193{
     194    AssertPtrReturnVoid(model());
     195    model()->init();
     196}
     197
     198void UIChooser::deinitModel()
     199{
     200    AssertPtrReturnVoid(model());
     201    model()->deinit();
     202}
     203
     204void UIChooser::cleanup()
    196205{
    197206    /* Deinit model: */
    198     m_pChooserModel->deinit();
    199 }
    200 
    201 void UIChooser::cleanup()
    202 {
    203     /* Save settings: */
    204     saveSettings();
    205 }
     207    deinitModel();
     208}
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