VirtualBox

Changeset 70308 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Dec 22, 2017 11:44:17 AM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9072 Reapply search and highlighting after each filtering

Location:
trunk/src/VBox/Frontends/VirtualBox/src/logviewer
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerFilterPanel.cpp

    r70098 r70308  
    5656    AssertReturnVoid(pCurrentPage);
    5757    QString strInputText = m_pViewer->currentLog();
    58     if (!strInputText.isNull())
     58    if (strInputText.isNull())
     59        return;
     60
     61    /* Prepare filter-data: */
     62    QString strFilteredText;
     63    const QRegExp rxFilterExp(m_strFilterText, Qt::CaseInsensitive);
     64
     65    /* If filter regular-expression is not empty and valid, filter the log: */
     66    if (!rxFilterExp.isEmpty() && rxFilterExp.isValid())
    5967    {
    60         /* Prepare filter-data: */
    61         QString strFilteredText;
    62         const QRegExp rxFilterExp(m_strFilterText, Qt::CaseInsensitive);
    63 
    64         /* If filter regular-expression is not empty and valid, filter the log: */
    65         if (!rxFilterExp.isEmpty() && rxFilterExp.isValid())
    66         {
    67             while (!strInputText.isEmpty())
     68        while (!strInputText.isEmpty())
     69        {
     70            /* Read each line and check if it matches regular-expression: */
     71            const int index = strInputText.indexOf('\n');
     72            if (index > 0)
    6873            {
    69                 /* Read each line and check if it matches regular-expression: */
    70                 const int index = strInputText.indexOf('\n');
    71                 if (index > 0)
    72                 {
    73                     QString strLine = strInputText.left(index + 1);
    74                     if (strLine.contains(rxFilterExp))
    75                         strFilteredText.append(strLine);
    76                 }
    77                 strInputText.remove(0, index + 1);
     74                QString strLine = strInputText.left(index + 1);
     75                if (strLine.contains(rxFilterExp))
     76                    strFilteredText.append(strLine);
    7877            }
    79             pCurrentPage->setPlainText(strFilteredText);
    80         }
    81         /* Restore entire log when filter regular expression is empty or not valid: */
    82         else
    83             pCurrentPage->setPlainText(strInputText);
    84 
    85         /* Move the cursor position to end: */
    86         QTextCursor cursor = pCurrentPage->textCursor();
    87         cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
    88         pCurrentPage->setTextCursor(cursor);
     78            strInputText.remove(0, index + 1);
     79        }
     80        QTextDocument *document = pCurrentPage->document();
     81        if(document)
     82            document->setPlainText(strFilteredText);
    8983    }
     84    /* Restore entire log when filter regular expression is empty or not valid: */
     85    else
     86        pCurrentPage->setPlainText(strInputText);
     87
     88    /* Move the cursor position to end: */
     89    QTextCursor cursor = pCurrentPage->textCursor();
     90    cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
     91    pCurrentPage->setTextCursor(cursor);
     92
     93    emit sigFilterApplied();
    9094}
    9195
     
    161165{
    162166    /* Prepare connections: */
    163     connect(m_pCloseButton, SIGNAL(clicked()), this, SLOT(hide()));
    164     connect(m_pFilterComboBox, SIGNAL(editTextChanged(const QString &)),
    165             this, SLOT(filter(const QString &)));
     167    connect(m_pCloseButton, &UIMiniCancelButton::clicked, this, &UIVMLogViewerFilterPanel::hide);
     168    connect(m_pFilterComboBox, &QComboBox::editTextChanged, this, &UIVMLogViewerFilterPanel::filter);
    166169}
    167170
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerFilterPanel.h

    r70027 r70308  
    3838    Q_OBJECT;
    3939
     40signals:
     41
     42    /* Notifies listeners that the filter has been applied. */
     43    void sigFilterApplied();
     44
    4045public:
    4146
     
    4954      * @param  iCurrentIndex  Specifies index of current log-page, but it is actually not used in the method. */
    5055    void applyFilter(const int iCurrentIndex = 0);
     56
    5157private slots:
    5258
     
    7682    UIVMLogViewerWidget *m_pViewer;
    7783    /** Holds the instance of main-layout we create. */
    78     QHBoxLayout *m_pMainLayout;
     84    QHBoxLayout         *m_pMainLayout;
    7985    /** Holds the instance of close-button we create. */
    80     UIMiniCancelButton *m_pCloseButton;
     86    UIMiniCancelButton  *m_pCloseButton;
    8187    /** Holds the instance of filter-label we create. */
    82     QLabel *m_pFilterLabel;
     88    QLabel              *m_pFilterLabel;
    8389    /** Holds instance of filter combo-box we create. */
    84     QComboBox *m_pFilterComboBox;
     90    QComboBox           *m_pFilterComboBox;
    8591    /** Holds the filter text. */
    86     QString m_strFilterText;
     92    QString              m_strFilterText;
    8793};
    8894
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerSearchPanel.h

    r70272 r70308  
    4343
    4444signals:
     45
    4546    void sigHighlightingUpdated();
    4647
     
    7071
    7172private:
     73
    7274    enum SearchDirection { ForwardSearch, BackwardSearch };
    7375    /** Prepares search-panel. */
     
    141143
    142144#endif /* !___UIVMLogViewerSearchPanel_h___ */
    143 
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp

    r70281 r70308  
    174174{
    175175    /* Disconnect this connection to avoid initial signals during page creation/deletion: */
    176     disconnect(m_pViewerContainer, SIGNAL(currentChanged(int)), m_pFilterPanel, SLOT(applyFilter(int)));
     176    disconnect(m_pViewerContainer, &QITabWidget::currentChanged, m_pFilterPanel, &UIVMLogViewerFilterPanel::applyFilter);
    177177    disconnect(m_pViewerContainer, &QITabWidget::currentChanged, this, &UIVMLogViewerWidget::sltTabIndexChange);
    178178
     
    228228
    229229    /* Setup this connection after refresh to avoid initial signals during page creation: */
    230     connect(m_pViewerContainer, SIGNAL(currentChanged(int)), m_pFilterPanel, SLOT(applyFilter(int)));
     230    connect(m_pViewerContainer, &QITabWidget::currentChanged, m_pFilterPanel, &UIVMLogViewerFilterPanel::applyFilter);
    231231    connect(m_pViewerContainer, &QITabWidget::currentChanged, this, &UIVMLogViewerWidget::sltTabIndexChange);
    232232
     
    304304}
    305305
     306void UIVMLogViewerWidget::
     307sltFilterApplied()
     308{
     309    /* Reapply the search to get highlighting etc. correctly */
     310    if (m_pSearchPanel && m_pSearchPanel->isVisible())
     311        m_pSearchPanel->refresh();
     312}
     313
    306314void UIVMLogViewerWidget::setMachine(const CMachine &machine)
    307315{
     
    372380        /* Add VM Log-Viewer filter-panel to main-layout: */
    373381        m_pMainLayout->insertWidget(3, m_pFilterPanel);
     382        connect(m_pFilterPanel, &UIVMLogViewerFilterPanel::sigFilterApplied,
     383                this, &UIVMLogViewerWidget::sltFilterApplied);
    374384    }
    375385}
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.h

    r70281 r70308  
    9393    void sltTabIndexChange(int tabIndex);
    9494
     95    void sltFilterApplied();
     96
    9597private:
    9698
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