VirtualBox

Changeset 77683 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 13, 2019 4:22:23 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9378. Implementing a recursive search function.

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

Legend:

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

    r77677 r77683  
    452452}
    453453
     454void UIChooserModel::performSearch(const QString &strSearchTerm, int iItemSearchFlags)
     455{
     456    if (!m_pInvisibleRootNode || strSearchTerm.isEmpty())
     457        return;
     458
     459    QList<UIChooserNode*> matchedItems;
     460    m_pInvisibleRootNode->searchForNodes(strSearchTerm,  iItemSearchFlags, matchedItems);
     461}
     462
    454463UIChooserNode *UIChooserModel::invisibleRoot() const
    455464{
     
    779788}
    780789
    781 void UIChooserModel::sltMachineSearch()
     790void UIChooserModel::sltShowHideSearchWidget()
    782791{
    783792    UIChooserView *pChooserView = qobject_cast<UIChooserView*>(scene()->views()[0]);
     
    14111420            this, SLOT(sltSortGroup()));
    14121421    connect(actionPool()->action(UIActionIndexST_M_Machine_S_Search), SIGNAL(triggered()),
    1413             this, SLOT(sltMachineSearch()));
     1422            this, SLOT(sltShowHideSearchWidget()));
    14141423
    14151424    /* Setup group saving connections: */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.h

    r77677 r77683  
    187187    /** @} */
    188188
     189    /** @name Virtual Machine/Group search stuff.
     190      * @{ */
     191        /** Performs a search starting from the m_pInvisibleRootNode. */
     192        void performSearch(const QString &strSearchTerm, int iItemSearchFlags);
     193    /** @} */
     194
    189195    /** @name Children stuff.
    190196      * @{ */
     
    277283        /** Handles group sort request. */
    278284        void sltSortGroup();
    279         /** Handles machine search request. */
    280         void sltMachineSearch();
     285        /** Handles machine search widget show/hide request. */
     286        void sltShowHideSearchWidget();
    281287        /** Handles group destroy request. */
    282288        void sltUngroupSelectedGroup();
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNode.h

    r77638 r77683  
    107107    UIChooserItem *item() const { return m_pItem.data(); }
    108108
     109    /** Performs search wrt.  @a strSearchTerm and @a iItemSearchFlags and updates @a matchedItems. */
     110    virtual void searchForNodes(const QString &strSearchTerm, int iItemSearchFlags, QList<UIChooserNode*> &matchedItems) = 0;
     111
    109112protected:
    110113
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNodeGlobal.cpp

    r77639 r77683  
    115115}
    116116
     117void UIChooserNodeGlobal::searchForNodes(const QString &strSearchTerm, int iItemSearchFlags, QList<UIChooserNode*> &matchedItems)
     118{
     119    if (!(iItemSearchFlags & UIChooserItemSearchFlag_Global))
     120        return;
     121    if (iItemSearchFlags & UIChooserItemSearchFlag_ExactName)
     122    {
     123        if (name() == strSearchTerm)
     124            matchedItems << this;
     125    }
     126    else
     127    {
     128        if (name().contains(strSearchTerm, Qt::CaseInsensitive))
     129            matchedItems << this;
     130    }
     131}
     132
    117133void UIChooserNodeGlobal::retranslateUi()
    118134{
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNodeGlobal.h

    r77639 r77683  
    8080    virtual int positionOf(UIChooserNode *pNode) /* override */;
    8181
     82    /** Updates the @a matchedItems wrt. @strSearchTerm and @a iItemSearchFlags. */
     83    virtual void searchForNodes(const QString &strSearchTerm, int iItemSearchFlags, QList<UIChooserNode*> &matchedItems) /* override */;
     84
    8285protected:
    8386
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNodeGroup.cpp

    r77639 r77683  
    188188}
    189189
     190
     191void UIChooserNodeGroup::searchForNodes(const QString &strSearchTerm, int iItemSearchFlags, QList<UIChooserNode*> &matchedItems)
     192{
     193
     194    if (iItemSearchFlags & UIChooserItemSearchFlag_Group)
     195    {
     196        if (iItemSearchFlags & UIChooserItemSearchFlag_ExactName)
     197        {
     198            if (name() == strSearchTerm)
     199                matchedItems << this;
     200        }
     201        else
     202        {
     203            if (name().contains(strSearchTerm, Qt::CaseInsensitive))
     204                matchedItems << this;
     205        }
     206    }
     207
     208    foreach (UIChooserNode* pNode, m_nodesGroup)
     209        pNode->searchForNodes(strSearchTerm, iItemSearchFlags, matchedItems);
     210
     211    foreach (UIChooserNode* pNode, m_nodesGlobal)
     212        pNode->searchForNodes(strSearchTerm, iItemSearchFlags, matchedItems);
     213
     214    foreach (UIChooserNode* pNode, m_nodesMachine)
     215        pNode->searchForNodes(strSearchTerm, iItemSearchFlags, matchedItems);
     216
     217}
     218
     219
    190220void UIChooserNodeGroup::retranslateUi()
    191221{
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNodeGroup.h

    r77639 r77683  
    9595    void close() { m_fOpened = false; }
    9696
     97
     98    /** Recursively searches for a children wrt.  @a strSearchTerm and @a iItemSearchFlags and updates the @a matchedItems. */
     99    virtual void searchForNodes(const QString &strSearchTerm, int iItemSearchFlags, QList<UIChooserNode*> &matchedItems) /* override */;
     100
    97101protected:
    98102
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNodeMachine.cpp

    r77639 r77683  
    131131}
    132132
     133void UIChooserNodeMachine::searchForNodes(const QString &strSearchTerm, int iItemSearchFlags,
     134                                          QList<UIChooserNode*> &matchedItems)
     135{
     136    if (!(iItemSearchFlags & UIChooserItemSearchFlag_Machine))
     137        return;
     138    if (iItemSearchFlags & UIChooserItemSearchFlag_ExactName)
     139    {
     140        if (name() == strSearchTerm)
     141            matchedItems << this;
     142        return;
     143    }
     144    if (name().contains(strSearchTerm, Qt::CaseInsensitive))
     145        matchedItems << this;
     146}
     147
    133148void UIChooserNodeMachine::retranslateUi()
    134149{
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNodeMachine.h

    r77639 r77683  
    8181    virtual int positionOf(UIChooserNode *pNode) /* override */;
    8282
     83    virtual void searchForNodes(const QString &strSearchTerm, int iItemSearchFlags, QList<UIChooserNode*> &matchedItems) /* override */;
     84
    8385protected:
    8486
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserSearchWidget.cpp

    r77677 r77683  
    2121/* GUI includes: */
    2222#include "QILineEdit.h"
     23#include "UIChooserDefs.h"
    2324#include "UIChooserSearchWidget.h"
    2425
     
    5455    {
    5556        connect(m_pLineEdit, &QILineEdit::textEdited,
    56                 this, &UIChooserSearchWidget::sigSearchTermChanged);
     57                this, &UIChooserSearchWidget::sltHandleSearchTermChange);
    5758    }
    5859}
     
    6869{
    6970}
     71
     72void UIChooserSearchWidget::sltHandleSearchTermChange(const QString &strSearchTerm)
     73{
     74    emit sigRedoSearch(strSearchTerm, UIChooserItemSearchFlag_Machine);
     75}
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserSearchWidget.h

    r77677 r77683  
    3939signals:
    4040
    41     void sigSearchTermChanged(const QString &strSearchTerm);
     41    void sigRedoSearch(const QString &strSearchTerm, int iItemSearchFlags);
    4242
    4343public:
     
    5454private slots:
    5555
     56    void sltHandleSearchTermChange(const QString &strSearchTerm);
     57
    5658private:
    5759
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserView.cpp

    r77677 r77683  
    127127}
    128128
     129void UIChooserView::sltRedoSearch(const QString &strSearchTerm, int iItemSearchFlags)
     130{
     131    if (!m_pChooser)
     132        return;
     133
     134    UIChooserModel *pModel =  m_pChooser->model();
     135    if (!pModel)
     136        return;
     137
     138    pModel->performSearch(strSearchTerm, iItemSearchFlags);
     139
     140}
     141
    129142void UIChooserView::retranslateUi()
    130143{
     
    138151{
    139152    /* Install Chooser-view accessibility interface factory: */
    140     QAccessible::installFactory(UIAccessibilityInterfaceForUIChooserView::pFactory);
     153     QAccessible::installFactory(UIAccessibilityInterfaceForUIChooserView::pFactory);
    141154
    142155    /* Prepare palette: */
     
    155168    m_pSearchWidget = new UIChooserSearchWidget(this);
    156169    m_pSearchWidget->hide();
     170    connect(m_pSearchWidget, &UIChooserSearchWidget::sigRedoSearch,
     171                this, &UIChooserView::sltRedoSearch);
    157172
    158173    /* Update scene-rect: */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserView.h

    r77677 r77683  
    7373    /** @} */
    7474
     75private slots:
     76
     77    void sltRedoSearch(const QString &strSearchTerm, int iItemSearchFlags);
     78
    7579private:
    7680
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