VirtualBox

Changeset 77916 in vbox for trunk


Ignore:
Timestamp:
Mar 27, 2019 12:43:21 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9241: VirtualBox Manager: Chooser pane: Initial cleanup for UIChooserModel class.

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

Legend:

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

    r77891 r77916  
    109109UIActionPool *UIChooserModel::actionPool() const
    110110{
    111     return chooser()->actionPool();
     111    return chooser() ? chooser()->actionPool() : 0;
    112112}
    113113
     
    117117}
    118118
    119 UIChooserView *UIChooserModel::view()
    120 {
    121     if (!scene())
    122         return 0;
    123     UIChooserView *pChooserView = qobject_cast<UIChooserView*>(scene()->views()[0]);
    124     return pChooserView;
     119UIChooserView *UIChooserModel::view() const
     120{
     121    return scene() && !scene()->views().isEmpty() ? qobject_cast<UIChooserView*>(scene()->views().first()) : 0;
    125122}
    126123
    127124QPaintDevice *UIChooserModel::paintDevice() const
    128125{
    129     if (scene() && !scene()->views().isEmpty())
    130         return scene()->views().first();
    131     return 0;
     126    return scene() && !scene()->views().isEmpty() ? scene()->views().first() : 0;
    132127}
    133128
    134129QGraphicsItem *UIChooserModel::itemAt(const QPointF &position, const QTransform &deviceTransform /* = QTransform() */) const
    135130{
    136     return scene()->itemAt(position, deviceTransform);
     131    return scene() ? scene()->itemAt(position, deviceTransform) : 0;
    137132}
    138133
     
    389384void UIChooserModel::makeSureSomeItemIsSelected()
    390385{
    391     /* Make sure selection item list is never empty
    392      * if at least one item (for example 'focus') present: */
     386    /* Make sure selection list is never empty if at
     387     * least one item (for example 'focus') present: */
    393388    if (!currentItem() && focusItem())
    394389        setCurrentItem(focusItem());
     
    447442void UIChooserModel::performSearch(const QString &strSearchTerm, int iItemSearchFlags)
    448443{
    449     if (!invisibleRoot())
    450         return;
    451 
    452     /* Currently we perform the search only for machines. when this to be changed make sure the disabled flags
    453        of the other item types are also managed correctly: */
    454 
    455     QList<UIChooserNode*> allNodes = resetSearch();
     444    /* Invisible root always exists: */
     445    AssertPtrReturnVoid(invisibleRoot());
     446
     447    /* Currently we perform the search only for machines, when this to be changed make
     448     * sure the disabled flags of the other item types are also managed correctly. */
     449
     450    /* Reset the search first to erase the disabled flag: */
     451    const QList<UIChooserNode*> nodes = resetSearch();
     452
     453    /* Stop here if no search conditions specified: */
    456454    if (strSearchTerm.isEmpty())
    457455        return;
    458456
     457    /* Search for all the nodes matching required condition: */
    459458    invisibleRoot()->searchForNodes(strSearchTerm, iItemSearchFlags, m_searchResults);
    460459
    461     foreach (UIChooserNode* pNode, allNodes)
     460    /* Assign/reset the disabled flag for required nodes: */
     461    foreach (UIChooserNode* pNode, nodes)
    462462    {
    463463        if (!pNode)
     
    466466    }
    467467
     468    /* Make sure 1st item visible: */
    468469    scrollToSearchResult(true);
    469470}
     
    471472QList<UIChooserNode*> UIChooserModel::resetSearch()
    472473{
    473     QList<UIChooserNode*> allNodes;
    474     /* Calling UIChooserNode::searchForNodes with an empty search string returns a list all nodes (of the whole treee) of the required type: */
    475     invisibleRoot()->searchForNodes(QString(), UIChooserItemSearchFlag_Machine, allNodes);
    476 
    477     /* Reset the disabled flag of the node items first. */
    478     foreach (UIChooserNode* pNode, allNodes)
     474    QList<UIChooserNode*> nodes;
     475
     476    /* Invisible root always exists: */
     477    AssertPtrReturn(invisibleRoot(), nodes);
     478
     479    /* Calling UIChooserNode::searchForNodes with an empty search string
     480     * returns a list all nodes (of the whole tree) of the required type: */
     481    invisibleRoot()->searchForNodes(QString(), UIChooserItemSearchFlag_Machine, nodes);
     482
     483    /* Reset the disabled flag of the nodes first: */
     484    foreach (UIChooserNode *pNode, nodes)
    479485    {
    480486        if (!pNode)
     
    482488        pNode->setDisabled(false);
    483489    }
    484     /* Reset the search result relate data: */
     490
     491    /* Reset the search result related data: */
    485492    m_searchResults.clear();
    486493    m_iCurrentScrolledIndex = -1;
    487     return allNodes;
     494    return nodes;
    488495}
    489496
    490497void UIChooserModel::scrollToSearchResult(bool fIsNext)
    491498{
     499    /* If nothing was found: */
    492500    if (m_searchResults.isEmpty())
    493501    {
     502        /* Clear the search widget's match count(s): */
    494503        m_iCurrentScrolledIndex = -1;
    495504        if (view())
     
    552561    /* Remember new drag-object: */
    553562    m_pCurrentDragObject = pDragObject;
    554     connect(m_pCurrentDragObject, SIGNAL(destroyed(QObject*)), this, SLOT(sltCurrentDragObjectDestroyed()));
     563    connect(m_pCurrentDragObject, &QDrag::destroyed,
     564            this, &UIChooserModel::sltCurrentDragObjectDestroyed);
    555565}
    556566
     
    660670    if (!fRegistered)
    661671    {
    662         /* Rebuild tree for main root: */
    663         buildTreeForMainRoot();
     672        /* Update tree for main root: */
    664673        updateNavigation();
    665674        updateLayout();
     
    734743    if (!actionPool()->action(UIActionIndexST_M_Group_S_Rename)->isEnabled())
    735744        return;
    736 
    737745    /* Only for single selected group: */
    738746    if (!isSingleGroupSelected())
     
    748756    if (!actionPool()->action(UIActionIndexST_M_Group_S_Sort)->isEnabled())
    749757        return;
    750 
    751758    /* Only for single selected group: */
    752759    if (!isSingleGroupSelected())
    753760        return;
    754761
    755     /* Sort group-node: */
    756     sortNodes(currentItem()->node());
    757 }
    758 
    759 void UIChooserModel::sltShowHideSearchWidget()
    760 {
    761     if (view())
    762         setSearchWidgetVisible(!view()->isSearchWidgetVisible());
     762    /* Sort nodes: */
     763    currentItem()->node()->sortNodes();
     764
     765    /* Rebuild tree for main root: */
     766    buildTreeForMainRoot();
     767    updateNavigation();
     768    updateLayout();
    763769}
    764770
     
    973979        return;
    974980
    975     /* Sort parent group-node: */
    976     sortNodes(currentItem()->parentItem()->node());
     981    /* Sort nodes: */
     982    currentItem()->parentItem()->node()->sortNodes();
     983
     984    /* Rebuild tree for main root: */
     985    buildTreeForMainRoot();
     986    updateNavigation();
     987    updateLayout();
    977988}
    978989
     
    11281139{
    11291140    root()->resetDragToken();
     1141}
     1142
     1143void UIChooserModel::sltShowHideSearchWidget()
     1144{
     1145    if (view())
     1146        setSearchWidgetVisible(!view()->isSearchWidgetVisible());
    11301147}
    11311148
     
    16481665    return false;
    16491666}
    1650 
    1651 void UIChooserModel::sortNodes(UIChooserNode *pNode)
    1652 {
    1653     /* Sort nodes: */
    1654     pNode->sortNodes();
    1655 
    1656     /* Rebuild tree for main root: */
    1657     buildTreeForMainRoot();
    1658     updateNavigation();
    1659     updateLayout();
    1660 }
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.h

    r77909 r77916  
    104104        /** Returns the scene reference. */
    105105        QGraphicsScene *scene() const;
     106        /** Returns the reference of the first view of the scene(). */
     107        UIChooserView *view() const;
    106108        /** Returns the paint device reference. */
    107109        QPaintDevice *paintDevice() const;
     
    180182        /** Performs a search starting from the m_pInvisibleRootNode. */
    181183        void performSearch(const QString &strSearchTerm, int iItemSearchFlags);
    182         /** Clean the search result data members and disables item's visual effects. Also returns a list of
    183           * all nodes which may be utilized by the calling code. */
     184        /** Cleans the search result data members and disables item's visual effects.
     185          * Also returns a list of all nodes which may be utilized by the calling code. */
    184186        QList<UIChooserNode*> resetSearch();
    185187        /** Scrolls to next/prev (wrt. @a fIsNext) search result. */
     
    262264        /** Handles group sort request. */
    263265        void sltSortGroup();
    264         /** Handles machine search widget show/hide request. */
    265         void sltShowHideSearchWidget();
    266266        /** Handles group destroy request. */
    267267        void sltUngroupSelectedGroup();
     
    283283        void sltCurrentDragObjectDestroyed();
    284284
     285        /** Handles machine search widget show/hide request. */
     286        void sltShowHideSearchWidget();
    285287        /** Handles request to erase lookup timer. */
    286288        void sltEraseLookupTimer();
     
    326328        /** Popups context-menu of certain @a enmType in specified @a point. */
    327329        void popupContextMenu(UIGraphicsSelectorContextMenuType enmType, QPoint point);
    328         /** Returns the reference of the first view of the scene(). */
    329         UIChooserView *view();
    330330    /** @} */
    331331
     
    356356        /** Processes drag leave @a pEvent. */
    357357        bool processDragLeaveEvent(QGraphicsSceneDragDropEvent *pEvent);
    358 
    359         /** Performs sorting for @a pNode. */
    360         void sortNodes(UIChooserNode *pNode);
    361358    /** @} */
    362359
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