VirtualBox

Changeset 75529 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Nov 16, 2018 5:46:04 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9289: VirtualBox Manager / Details pane: A lot of refactoring, proper coding-style / doxygen.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/manager/details
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/details/UIDetailsModel.cpp

    r75526 r75529  
    55
    66/*
    7  * Copyright (C) 2012-2017 Oracle Corporation
     7 * Copyright (C) 2012-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2828
    2929/* GUI includes: */
     30# include "UIConverter.h"
    3031# include "UIDetails.h"
    3132# include "UIDetailsModel.h"
     
    3435# include "UIExtraDataManager.h"
    3536# include "VBoxGlobal.h"
    36 # include "UIConverter.h"
    3737
    3838#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    3939
     40
     41/*********************************************************************************************************************************
     42*   Class UIDetailsModel implementation.                                                                                         *
     43*********************************************************************************************************************************/
    4044
    4145UIDetailsModel::UIDetailsModel(UIDetails *pParent)
     
    5458}
    5559
    56 QGraphicsScene* UIDetailsModel::scene() const
     60QGraphicsScene *UIDetailsModel::scene() const
    5761{
    5862    return m_pScene;
    5963}
    6064
    61 QGraphicsView* UIDetailsModel::paintDevice() const
    62 {
    63     if (!m_pScene || m_pScene->views().isEmpty())
    64         return 0;
    65     return m_pScene->views().first();
    66 }
    67 
    68 QGraphicsItem* UIDetailsModel::itemAt(const QPointF &position) const
     65QGraphicsView *UIDetailsModel::paintDevice() const
     66{
     67    if (m_pScene && !m_pScene->views().isEmpty())
     68        return m_pScene->views().first();
     69    return 0;
     70}
     71
     72QGraphicsItem *UIDetailsModel::itemAt(const QPointF &position) const
    6973{
    7074    return scene()->itemAt(position, QTransform());
     
    97101void UIDetailsModel::sltHandleViewResize()
    98102{
    99     /* Relayout: */
    100103    updateLayout();
    101104}
     
    125128{
    126129    m_pRoot->rebuildGroup();
     130}
     131
     132bool UIDetailsModel::eventFilter(QObject *pObject, QEvent *pEvent)
     133{
     134    /* Handle allowed context-menu events: */
     135    if (pObject == scene() && pEvent->type() == QEvent::GraphicsSceneContextMenu)
     136        return processContextMenuEvent(static_cast<QGraphicsSceneContextMenuEvent*>(pEvent));
     137
     138    /* Call to base-class: */
     139    return QObject::eventFilter(pObject, pEvent);
    127140}
    128141
     
    165178}
    166179
    167 void UIDetailsModel::sltToggleAnimationFinished(DetailsElementType type, bool fToggled)
     180void UIDetailsModel::sltToggleAnimationFinished(DetailsElementType enmType, bool fToggled)
    168181{
    169182    /* Cleanup animation callback: */
     
    177190        {
    178191            UIDetailsElement *pElement = pElementItem->toElement();
    179             if (pElement->elementType() == type)
     192            if (pElement->elementType() == enmType)
    180193                pElement->markAnimationFinished();
    181194        }
     
    185198
    186199    /* Update element open/close status: */
    187     if (m_categories.contains(type))
    188         m_categories[type] = fToggled;
     200    if (m_categories.contains(enmType))
     201        m_categories[enmType] = fToggled;
    189202}
    190203
     
    193206    /* Which item was toggled? */
    194207    QAction *pAction = qobject_cast<QAction*>(sender());
    195     DetailsElementType type = pAction->data().value<DetailsElementType>();
     208    DetailsElementType enmType = pAction->data().value<DetailsElementType>();
    196209
    197210    /* Toggle element visibility status: */
    198     if (m_categories.contains(type))
    199         m_categories.remove(type);
     211    if (m_categories.contains(enmType))
     212        m_categories.remove(enmType);
    200213    else
    201         m_categories[type] = true;
     214        m_categories[enmType] = true;
    202215
    203216    /* Rebuild group: */
     
    256269    cleanupRoot();
    257270    cleanupScene();
    258 }
    259 
    260 bool UIDetailsModel::eventFilter(QObject *pObject, QEvent *pEvent)
    261 {
    262     /* Ignore if no scene object: */
    263     if (pObject != scene())
    264         return QObject::eventFilter(pObject, pEvent);
    265 
    266     /* Ignore if no context-menu event: */
    267     if (pEvent->type() != QEvent::GraphicsSceneContextMenu)
    268         return QObject::eventFilter(pObject, pEvent);
    269 
    270     /* Process context menu event: */
    271         return processContextMenuEvent(static_cast<QGraphicsSceneContextMenuEvent*>(pEvent));
    272271}
    273272
     
    284283    for (int iType = DetailsElementType_General; iType <= DetailsElementType_Description; ++iType)
    285284    {
    286         DetailsElementType currentElementType = (DetailsElementType)iType;
    287         QAction *pAction = contextMenu.addAction(gpConverter->toString(currentElementType), this, SLOT(sltElementTypeToggled()));
     285        const DetailsElementType enmCurrentElementType = (DetailsElementType)iType;
     286        QAction *pAction = contextMenu.addAction(gpConverter->toString(enmCurrentElementType), this, SLOT(sltElementTypeToggled()));
    288287        pAction->setCheckable(true);
    289         pAction->setChecked(m_categories.contains(currentElementType));
    290         pAction->setData(QVariant::fromValue(currentElementType));
     288        pAction->setChecked(m_categories.contains(enmCurrentElementType));
     289        pAction->setData(QVariant::fromValue(enmCurrentElementType));
    291290    }
    292291    /* Exec context-menu: */
     
    297296}
    298297
    299 UIDetailsElementAnimationCallback::UIDetailsElementAnimationCallback(QObject *pParent, DetailsElementType type, bool fToggled)
     298
     299/*********************************************************************************************************************************
     300*   Class UIDetailsElementAnimationCallback implementation.                                                                      *
     301*********************************************************************************************************************************/
     302
     303UIDetailsElementAnimationCallback::UIDetailsElementAnimationCallback(QObject *pParent, DetailsElementType enmType, bool fToggled)
    300304    : QObject(pParent)
    301     , m_type(type)
     305    , m_enmType(enmType)
    302306    , m_fToggled(fToggled)
    303307{
    304308}
    305309
    306 void UIDetailsElementAnimationCallback::addNotifier(UIDetailsItem *pItem)
     310void UIDetailsElementAnimationCallback::addNotifier(UIDetailsElement *pItem)
    307311{
    308312    /* Connect notifier: */
    309     connect(pItem, SIGNAL(sigToggleElementFinished()), this, SLOT(sltAnimationFinished()));
     313    connect(pItem, &UIDetailsElement::sigToggleElementFinished,
     314            this, &UIDetailsElementAnimationCallback::sltAnimationFinished);
    310315    /* Remember notifier: */
    311316    m_notifiers << pItem;
     
    315320{
    316321    /* Determine notifier: */
    317     UIDetailsItem *pItem = qobject_cast<UIDetailsItem*>(sender());
     322    UIDetailsElement *pItem = qobject_cast<UIDetailsElement*>(sender());
    318323    /* Disconnect notifier: */
    319     disconnect(pItem, SIGNAL(sigToggleElementFinished()), this, SLOT(sltAnimationFinished()));
     324    disconnect(pItem, &UIDetailsElement::sigToggleElementFinished,
     325               this, &UIDetailsElementAnimationCallback::sltAnimationFinished);
    320326    /* Remove notifier: */
    321327    m_notifiers.removeAll(pItem);
    322328    /* Check if we finished: */
    323329    if (m_notifiers.isEmpty())
    324         emit sigAllAnimationFinished(m_type, m_fToggled);
    325 }
    326 
     330        emit sigAllAnimationFinished(m_enmType, m_fToggled);
     331}
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/details/UIDetailsModel.h

    r75526 r75529  
    55
    66/*
    7  * Copyright (C) 2012-2017 Oracle Corporation
     7 * Copyright (C) 2012-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    18 #ifndef __UIDetailsModel_h__
    19 #define __UIDetailsModel_h__
     18#ifndef ___UIDetailsModel_h___
     19#define ___UIDetailsModel_h___
    2020
    2121/* Qt includes: */
     22#include <QMap>
    2223#include <QObject>
    2324#include <QPointer>
    24 #include <QMap>
    2525#include <QSet>
    2626
     
    3737class QGraphicsView;
    3838class UIVirtualMachineItem;
     39class UIDetails;
     40class UIDetailsElement;
    3941class UIDetailsElementAnimationCallback;
    4042class UIDetailsGroup;
    4143class UIDetailsItem;
    42 class UIDetails;
    43 
    44 /* Graphics details-model: */
     44
     45
     46/** QObject sub-class used as graphics details model. */
    4547class UIDetailsModel : public QObject
    4648{
     
    4951signals:
    5052
    51     /* Notifiers: Root-item stuff: */
    52     void sigRootItemMinimumWidthHintChanged(int iRootItemMinimumWidthHint);
    53     void sigRootItemMinimumHeightHintChanged(int iRootItemMinimumHeightHint);
    54 
    55     /* Notifier: Link processing stuff: */
     53    /** Notifies listeners about model root item @a iMinimumWidthHint changed. */
     54    void sigRootItemMinimumWidthHintChanged(int iMinimumWidthHint);
     55    /** Notifies listeners about model root item @a iMinimumHeightHint changed. */
     56    void sigRootItemMinimumHeightHintChanged(int iMinimumHeightHint);
     57
     58    /** Notifies listeners about element link clicked.
     59      * @param  strCategory  Brings details element category.
     60      * @param  strControl   Brings settings control to select.
     61      * @param  uId          Brings ID of the machine details referring. */
    5662    void sigLinkClicked(const QString &strCategory, const QString &strControl, const QUuid &uId);
    5763
    5864public:
    5965
    60     /** Constructs a details-model passing @a pParent to the base-class.
     66    /** Constructs a details model passing @a pParent to the base-class.
    6167      * @param  pParent  Brings the details container to embed into. */
    6268    UIDetailsModel(UIDetails *pParent);
    63     /** Destructs a details-model. */
    64     ~UIDetailsModel();
    65 
    66     /* API: Scene stuff: */
    67     QGraphicsScene* scene() const;
    68     QGraphicsView* paintDevice() const;
    69     QGraphicsItem* itemAt(const QPointF &position) const;
    70 
    71     /** Returns the details reference. */
     69    /** Destructs a details model. */
     70    virtual ~UIDetailsModel() /* override */;
     71
     72    /** Returns graphics scene this model belongs to. */
     73    QGraphicsScene *scene() const;
     74    /** Returns paint device this model belongs to. */
     75    QGraphicsView *paintDevice() const;
     76
     77    /** Returns graphics item as certain @a position. */
     78    QGraphicsItem *itemAt(const QPointF &position) const;
     79
     80    /** Returns the details pane reference. */
    7281    UIDetails *details() const { return m_pDetails; }
    7382
     
    7584    UIDetailsItem *root() const;
    7685
    77     /* API: Layout stuff: */
     86    /** Updates layout by positioning items manually. */
    7887    void updateLayout();
    7988
    80     /* API: Current-item(s) stuff: */
     89    /** Defines virtual machine @a items for this model to reflect. */
    8190    void setItems(const QList<UIVirtualMachineItem*> &items);
    8291
     
    8695public slots:
    8796
    88     /* Handler: Details-view stuff: */
     97    /** Handle details view resize. */
    8998    void sltHandleViewResize();
    9099
    91     /* Handlers: Chooser stuff: */
     100    /** Handles chooser pane signal about item sliding started. */
    92101    void sltHandleSlidingStarted();
     102    /** Handles chooser pane signal about group toggle started. */
    93103    void sltHandleToggleStarted();
     104    /** Handles chooser pane signal about group toggle finished. */
    94105    void sltHandleToggleFinished();
    95106
     
    99110    void sltHandleExtraDataOptionsChange(DetailsElementType enmType);
    100111
     112protected:
     113
     114    /** Preprocesses any Qt @a pEvent for passed @a pObject. */
     115    virtual bool eventFilter(QObject *pObject, QEvent *pEvent) /* override */;
     116
    101117private slots:
    102118
    103     /* Handlers: Element-items stuff: */
     119    /** Handles request to start toggle details element of certain @a enmType, making element @a fToggled. */
    104120    void sltToggleElements(DetailsElementType type, bool fToggled);
     121    /** Handles sigal about details element of certain @a enmType toggling finished, making element @a fToggled. */
    105122    void sltToggleAnimationFinished(DetailsElementType type, bool fToggled);
     123
     124    /** Handles request about toggling visibility. */
    106125    void sltElementTypeToggled();
    107126
     
    129148    /** @} */
    130149
    131     /* Handler: Event-filter: */
    132     bool eventFilter(QObject *pObject, QEvent *pEvent);
    133 
    134     /* Handler: Context-menu stuff: */
     150    /** Performs handling for allowed context menu @a pEvent. */
    135151    bool processContextMenuEvent(QGraphicsSceneContextMenuEvent *pEvent);
    136152
     
    138154    UIDetails *m_pDetails;
    139155
    140     /* Variables: */
    141     QGraphicsScene *m_pScene;
    142     UIDetailsGroup *m_pRoot;
     156    /** Holds the graphics scene reference. */
     157    QGraphicsScene                    *m_pScene;
     158    /** Holds the root element instance. */
     159    UIDetailsGroup                    *m_pRoot;
     160    /** Holds the element animation callback instance. */
    143161    UIDetailsElementAnimationCallback *m_pAnimationCallback;
    144162
     
    147165};
    148166
    149 /* Details-element animation callback: */
     167
     168/** QObject sub-class used as details element animation callback. */
    150169class UIDetailsElementAnimationCallback : public QObject
    151170{
     
    154173signals:
    155174
    156     /* Notifier: Complete stuff: */
    157     void sigAllAnimationFinished(DetailsElementType type, bool fToggled);
     175    /** Notifies listeners about all animations finished.
     176      * @param  enmType   Brings the type of element item which was animated.
     177      * @param  fToggled  Brigns whether elements being toggled to be closed or opened. */
     178    void sigAllAnimationFinished(DetailsElementType enmType, bool fToggled);
    158179
    159180public:
    160181
    161     /* Constructor: */
    162     UIDetailsElementAnimationCallback(QObject *pParent, DetailsElementType type, bool fToggled);
    163 
    164     /* API: Notifiers stuff: */
    165     void addNotifier(UIDetailsItem *pItem);
     182    /** Constructors details element animation callback passing @a pParent to the base-class.
     183      * @param  enmType   Brings the type of element item which was animated.
     184      * @param  fToggled  Brigns whether elements being toggled to be closed or opened. */
     185    UIDetailsElementAnimationCallback(QObject *pParent, DetailsElementType enmType, bool fToggled);
     186
     187    /** Adds notifier for a certain details @a pItem. */
     188    void addNotifier(UIDetailsElement *pItem);
    166189
    167190private slots:
    168191
    169     /* Handler: Progress stuff: */
     192    /** Handles a signal about animation finnished. */
    170193    void sltAnimationFinished();
    171194
    172195private:
    173196
    174     /* Variables: */
    175     QList<UIDetailsItem*> m_notifiers;
    176     DetailsElementType m_type;
    177     bool m_fToggled;
     197    /** Holds the list of elements which notifies this callback about completion. */
     198    QList<UIDetailsElement*>  m_notifiers;
     199    /** Holds the type of element item which was animated. */
     200    DetailsElementType        m_enmType;
     201    /** Holds whether elements being toggled to be closed or opened. */
     202    bool                      m_fToggled;
    178203};
    179204
    180 #endif /* __UIDetailsModel_h__ */
    181 
     205
     206#endif /* !___UIDetailsModel_h___ */
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