VirtualBox

Changeset 70645 in vbox


Ignore:
Timestamp:
Jan 19, 2018 12:27:22 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
120375
Message:

FE/Qt: bugref:9072 Don't blindly apply filter at every tab switch.

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

Legend:

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

    r70617 r70645  
    4545    , m_iSelectedBookmarkIndex(-1)
    4646    , m_bFiltered(false)
     47    , m_iFilteredLineCount(-1)
     48    , m_iUnfilteredLineCount(-1)
    4749    , m_bShowLineNumbers(true)
    4850    , m_bWrapLines(false)
     
    142144}
    143145
    144 void UIVMLogPage::setTextEdit(const QString &strText)
     146void UIVMLogPage::setTextEditText(const QString &strText)
    145147{
    146148    if (!m_pTextEdit)
     
    155157}
    156158
    157 void UIVMLogPage::setTextEditAsHtml(const QString &strText)
     159void UIVMLogPage::setTextEditTextAsHtml(const QString &strText)
    158160{
    159161    if (!m_pTextEdit)
     
    245247    if (m_pTextEdit)
    246248        m_pTextEdit->setFocus();
     249
    247250    QWidget::showEvent(pEvent);
    248251}
     
    311314    update();
    312315}
     316
     317void UIVMLogPage::setFilterParameters(const QSet<QString> &filterTermSet, int filterOperationType,
     318                                      int iFilteredLineCount, int iUnfilteredLineCount)
     319{
     320    m_filterTermSet = filterTermSet;
     321    m_filterOperationType = filterOperationType;
     322    m_iFilteredLineCount = iFilteredLineCount;
     323    m_iUnfilteredLineCount = iUnfilteredLineCount;
     324}
     325
     326int  UIVMLogPage::filteredLineCount() const
     327{
     328    return m_iFilteredLineCount;
     329}
     330
     331int  UIVMLogPage::unfilteredLineCount() const
     332{
     333    return m_iUnfilteredLineCount;
     334}
     335
     336bool UIVMLogPage::shouldFilterBeApplied(const QSet<QString> &filterTermSet, int filterOperationType) const
     337{
     338    /* If filter terms set is different reapply the filter. */
     339    if(filterTermSet != m_filterTermSet)
     340        return true;
     341
     342    /* If filter operation type set is different reapply the filter. */
     343    if(filterOperationType != m_filterOperationType)
     344        return true;
     345    return false;
     346}
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.h

    r70618 r70645  
    3838typedef QPair<int, QString> LogBookmark;
    3939
     40/** UIVMLogPage defines data and functionalities of the each tab page of a UIVMLogViewerWidget.
     41    It stores the original log file content , a list of bookmarks, etc */
    4042class UIVMLogPage  : public QIWithRetranslateUI<QWidget>
    4143{
     
    7173        show currently might be different than
    7274        m_strLog. For example during filtering. */
    73     void setTextEdit(const QString &strText);
    74     void setTextEditAsHtml(const QString &strText);
     75    void setTextEditText(const QString &strText);
     76    void setTextEditTextAsHtml(const QString &strText);
    7577
    7678    /** Marks the plain text edit When we dont have a log content. */
     
    9597    void setShowLineNumbers(bool bShowLineNumbers);
    9698    void setWrapLines(bool bWrapLines);
     99
     100    /** setFilterParameters is called at the end of filtering operation to store the parameter etc.
     101        these parameters are used to decide whether we have to reapply the filter, and if not to
     102        update filter panel with correct line counts etc.*/
     103    void setFilterParameters(const QSet<QString> &filterTermSet, int filterOperationType,
     104                             int iFilteredLineCount, int iUnfilteredLineCount);
     105    int  filteredLineCount() const;
     106    int  unfilteredLineCount() const;
     107    /** Compares filter parameters with previous filter operation's parameters to decide if the
     108        filter should be applied again. */
     109    bool shouldFilterBeApplied(const QSet<QString> &filterTermSet, int filterOperationType) const;
    97110
    98111protected:
     
    127140    /** Keeps the index of the selected bookmark. Used especially when moving from one tab to another. */
    128141    int                  m_iSelectedBookmarkIndex;
    129     /** Keeps the scrolled line number. Used when switching between tabs. */
    130     int                  m_iScrolledLineNumber;
     142
     143    /** @name Filtering related state variables
     144     * @{ */
    131145    /** Designates whether currently displayed text is log text or a filtered version of it. That is
    132146        if m_bFiltered is false than (m_strLog == m_pTextEdit->text()). */
    133     bool m_bFiltered;
     147        bool           m_bFiltered;
     148        /** The set of filter terms used in the last filtering.
     149            Used when deciding whether we have to reapply the filter or not. see shouldFilterBeApplied function. */
     150        QSet<QString>  m_filterTermSet;
     151        /** The type of the boolean last filtering operation. Used in deciding whether we have to reapply the
     152            filter. see shouldFilterBeApplied function. This is int cast of enum FilterOperatorButton
     153            of UIVMLogViewerFilterPanel. */
     154        int            m_filterOperationType;
     155        /** These counts are saveds and restored during filtering operation. If filter is not reapplied these counts
     156            are shown in the filter panel. */
     157        int            m_iFilteredLineCount;
     158        int            m_iUnfilteredLineCount;
     159    /** @} */
     160
    134161    bool m_bShowLineNumbers;
    135162    bool m_bWrapLines;
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerFilterPanel.cpp

    r70610 r70645  
    4040# include "UIIconPool.h"
    4141# include "UISpecialControls.h"
     42# include "UIVMLogPage.h"
    4243# include "UIVMLogViewerFilterPanel.h"
    4344# include "UIVMLogViewerWidget.h"
     
    204205    if (!pCurrentTextEdit)
    205206        return;
     207
     208    UIVMLogPage *logPage = viewer()->currentLogPage();
     209    if(!logPage)
     210        return;
     211    /* Check if we have to reapply the filter. If not
     212       restore line counts etc. and return */
     213    if(!logPage->shouldFilterBeApplied(m_filterTermSet, (int)m_eFilterOperatorButton))
     214    {
     215        m_iFilteredLineCount = logPage->filteredLineCount();
     216        m_iUnfilteredLineCount = logPage->unfilteredLineCount();
     217        emit sigFilterApplied(!logPage->isFiltered() /* isOriginalLog */);
     218        return;
     219    }
     220
     221
    206222    const QString* originalLogString = logString();
    207223    m_iUnfilteredLineCount = 0;
     
    214230    QStringList stringLines = originalLogString->split("\n");
    215231    m_iUnfilteredLineCount = stringLines.size();
    216     if (m_filterTermList.empty())
     232
     233    if (m_filterTermSet.empty())
    217234    {
    218235        document->setPlainText(*originalLogString);
    219236        emit sigFilterApplied(true /* isOriginalLog */);
    220237        m_iFilteredLineCount = document->lineCount();
     238        logPage->setFilterParameters(m_filterTermSet, (int)m_eFilterOperatorButton,
     239                                     m_iFilteredLineCount, m_iUnfilteredLineCount);
    221240        return;
    222241    }
     
    246265
    247266    emit sigFilterApplied(false /* isOriginalLog */);
     267    logPage->setFilterParameters(m_filterTermSet, (int)m_eFilterOperatorButton,
     268                                 m_iFilteredLineCount, m_iUnfilteredLineCount);
    248269}
    249270
     
    253274    /* Number of the filter terms contained with the @p string: */
    254275    int hitCount = 0;
    255     for (int i = 0; i < m_filterTermList.size(); ++i)
    256     {
    257         const QRegExp rxFilterExp(m_filterTermList.at(i), Qt::CaseInsensitive);
     276
     277    for(QSet<QString>::const_iterator iterator = m_filterTermSet.begin();
     278        iterator != m_filterTermSet.end(); ++iterator)
     279    {
     280        const QString& filterTerm = *iterator;
     281        const QRegExp rxFilterExp(filterTerm, Qt::CaseInsensitive);
    258282        /* Disregard empty and invalid filter terms: */
    259283        if (rxFilterExp.isEmpty() || !rxFilterExp.isValid())
     
    273297    }
    274298    /* All the terms are found within the @p string. To catch AND case: */
    275     if (hitCount == m_filterTermList.size())
     299    if (hitCount == m_filterTermSet.size())
    276300        return true;
    277301    return false;
     
    287311
    288312    /* Continue only if the term is new. */
    289     if (m_filterTermList.contains(m_pFilterComboBox->currentText()))
    290         return;
    291     m_filterTermList.push_back(m_pFilterComboBox->currentText());
     313    if (m_filterTermSet.contains(m_pFilterComboBox->currentText()))
     314        return;
     315    m_filterTermSet.insert(m_pFilterComboBox->currentText());
    292316
    293317    /* Add the new filter term to line edit: */
     
    302326void UIVMLogViewerFilterPanel::sltClearFilterTerms()
    303327{
    304     if (m_filterTermList.empty())
    305         return;
    306     m_filterTermList.clear();
     328    if (m_filterTermSet.empty())
     329        return;
     330    m_filterTermSet.clear();
    307331    applyFilter();
    308332    if (m_pFilterTermsLineEdit)
     
    320344void UIVMLogViewerFilterPanel::sltRemoveFilterTerm(const QString &termString)
    321345{
    322     QStringList newList;
    323     for (QStringList::iterator iterator = m_filterTermList.begin();
    324         iterator != m_filterTermList.end(); ++iterator)
    325     {
    326         if ((*iterator) != termString)
    327             newList.push_back(*iterator);
    328     }
    329     m_filterTermList = newList;
     346    m_filterTermSet.remove(termString);
    330347    applyFilter();
    331348}
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerFilterPanel.h

    r70610 r70645  
    1919#define ___UIVMLogViewerFilterPanel_h___
    2020
     21/* Qt includes: */
     22# include <QSet>
    2123
    2224/* GUI includes: */
     
    8486
    8587    enum FilterOperatorButton{
    86         AndButton = 0,
     88        AndButton = 0,/* Don't change this value */
    8789        OrButton,
    8890        ButtonEnd
     
    101103    QFrame              *m_pRadioButtonContainer;
    102104    QIToolButton        *m_pAddFilterTermButton;
    103     QStringList          m_filterTermList;
     105    QSet<QString>        m_filterTermSet;
    104106    FilterOperatorButton m_eFilterOperatorButton;
    105107    UIVMFilterLineEdit  *m_pFilterTermsLineEdit;
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerPanel.h

    r70539 r70645  
    4242    UIVMLogViewerPanel(QWidget *pParent, UIVMLogViewerWidget *pViewer);
    4343
    44 
    45 public slots:
    46 
    4744protected:
    4845
     
    7067    /* Return the unmodified log. */
    7168    const QString* logString() const;
    72 private slots:
    73 
    7469
    7570private:
    76 
    7771
    7872    /** Holds the reference to VM Log-Viewer this panel belongs to. */
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerSearchPanel.cpp

    r70591 r70645  
    7474    m_matchLocationVector.clear();
    7575    m_iMatchCount = -1;
    76     if (m_pHighlightAllCheckBox)
    77     {
    78         if (m_pHighlightAllCheckBox->checkState() == Qt::Checked)
    79             m_pHighlightAllCheckBox->setCheckState(Qt::Unchecked);
    80     }
    8176    configureInfoLabels();
    8277}
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.cpp

    r70617 r70645  
    162162    //setStyleSheet("background-color: rgba(240, 240, 240, 75%) ");
    163163    prepare();
     164
     165
    164166}
    165167
     
    186188    setWordWrapMode(QTextOption::NoWrap);
    187189    setWordWrapMode(QTextOption::NoWrap);
     190
    188191    setReadOnly(true);
     192
    189193    /* Set colors to have a selection with bluebackground and white foreground: */
    190194    QPalette mPalette = palette();
    191195    mPalette.setColor(QPalette::Highlight, QColor(48, 140, 198, 255));
    192196    mPalette.setColor(QPalette::HighlightedText, QColor(255, 255, 255, 255));
     197    mPalette.setColor(QPalette::Text, QColor(0, 0, 0, 255));
    193198    setPalette(mPalette);
    194199
     
    311316{
    312317    QPlainTextEdit::resizeEvent(pEvent);
    313 
    314     QRect cr = contentsRect();
    315     m_pLineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
     318    if(m_pLineNumberArea)
     319    {
     320        QRect cr = contentsRect();
     321        m_pLineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
     322    }
    316323}
    317324
     
    319326{
    320327    setMouseCursorLine(lineNumberForPos(pEvent->pos()));
    321     m_pLineNumberArea->repaint();
     328    if(m_pLineNumberArea)
     329        m_pLineNumberArea->repaint();
     330    QPlainTextEdit::mouseMoveEvent(pEvent);
    322331}
    323332
     
    326335    QPlainTextEdit::leaveEvent(pEvent);
    327336    /* Force a redraw as mouse leaves this to remove the mouse
    328        cursor track rectangle (the red rectangle we draw on the line number area. */
     337       cursor track rectangle (the red rectangle we draw on the line number area). */
    329338    update();
    330339}
     
    371380        return;
    372381
     382    moveCursor(QTextCursor::End);
    373383    int halfPageLineCount = 0.5 * visibleLineCount() ;
    374384    QTextCursor cursor(pDocument->findBlockByLineNumber(qMax(lineNumber - halfPageLineCount, 0)));
    375     moveCursor(QTextCursor::End);
    376385    setTextCursor(cursor);
    377386}
     
    403412}
    404413
     414
    405415QPair<int, QString> UIVMLogViewerTextEdit::bookmarkForPos(const QPoint &position)
    406416{
     
    461471}
    462472
     473int  UIVMLogViewerTextEdit::currentVerticalScrollBarValue() const
     474{
     475    if(!verticalScrollBar())
     476        return -1;
     477    return verticalScrollBar()->value();
     478}
     479void UIVMLogViewerTextEdit::setCurrentVerticalScrollBarValue(int value)
     480{
     481    if(!verticalScrollBar())
     482        return;
     483
     484    setCenterOnScroll(true);
     485
     486    verticalScrollBar()->setValue(value);
     487    verticalScrollBar()->setSliderPosition(value);
     488    printf("value %d\n", value);
     489    viewport()->update();
     490    update();
     491}
     492
    463493
    464494#include "UIVMLogViewerTextEdit.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.h

    r70598 r70645  
    5353    void setWrapLines(bool bWrapLines);
    5454
     55    /** currentVerticalScrollBarValue is used by UIVMLogPage to store and restore scrolled
     56        plain text position as we switch from a tab to another */
     57    int  currentVerticalScrollBarValue() const;
     58    void setCurrentVerticalScrollBarValue(int value);
     59
    5560protected:
    5661
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp

    r70617 r70645  
    263263    Q_UNUSED(tabIndex);
    264264
    265     // if (m_iCurrentTabIndex == tabIndex)
    266     //     return;
    267 
    268265    resetHighlighthing();
    269266    if (m_pSearchPanel)
    270267        m_pSearchPanel->reset();
    271     // m_iCurrentTabIndex = tabIndex;
    272268
    273269    /* We keep a separate QVector<LogBookmark> for each log page: */
     
    850846    /* Set text edit since we want to display this text: */
    851847    if (!noLogsToShow)
    852         pLogPage->setTextEdit(strLogContent);
     848        pLogPage->setTextEditText(strLogContent);
    853849    /* In case there are some errors append the error text as html: */
    854850    else
    855851    {
    856         pLogPage->setTextEditAsHtml(strLogContent);
     852        pLogPage->setTextEditTextAsHtml(strLogContent);
    857853        pLogPage->markForError();
    858854    }
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette