VirtualBox

Changeset 70549 in vbox


Ignore:
Timestamp:
Jan 12, 2018 7:46:15 AM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9072 Further cleaning after refactoring

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

Legend:

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

    r70539 r70549  
    168168
    169169private slots:
    170     /// remove
     170
    171171    void sltBookmark()
    172172    {
     
    212212{
    213213    prepareWidgets();
    214 //     prepareActions();
    215 
    216 //     prepareToolBar();
    217 //     prepareMenu();
    218 
    219 //     /* Reading log files: */
    220 //     sltRefresh();
    221 
    222 //     /* Loading language constants: */
    223214    retranslateUi();
    224215}
     
    250241    m_pPlainTextEdit->setWordWrapMode(QTextOption::NoWrap);
    251242    m_pPlainTextEdit->setReadOnly(true);
    252 
     243    connect(qobject_cast<UIVMLogViewerTextEdit*>(m_pPlainTextEdit), &UIVMLogViewerTextEdit::sigContextMenuBookmarkAction,
     244            this, &UIVMLogPage::sltAddBookmark);
    253245}
    254246
     
    348340}
    349341
     342
     343void UIVMLogPage::deleteBookmark(int index)
     344{
     345    if (m_bookmarkVector.size() <= index)
     346         return;
     347    m_bookmarkVector.remove(index, 1);
     348}
     349
     350void UIVMLogPage::deleteAllBookmarks()
     351{
     352    m_bookmarkVector.clear();
     353}
     354
     355void UIVMLogPage::scrollToBookmark(int bookmarkIndex)
     356{
     357    if(!m_pPlainTextEdit)
     358        return;
     359    if (bookmarkIndex >= m_bookmarkVector.size())
     360        return;
     361
     362    int lineNumber = m_bookmarkVector.at(bookmarkIndex).first;
     363    QTextDocument* document = m_pPlainTextEdit->document();
     364    if(!document)
     365        return;
     366
     367    QTextCursor cursor(document->findBlockByLineNumber(lineNumber));
     368    m_pPlainTextEdit->setTextCursor(cursor);
     369}
     370
     371const QVector<LogBookmark>& UIVMLogPage::bookmarkVector() const
     372{
     373    return m_bookmarkVector;
     374}
     375
     376void UIVMLogPage::sltAddBookmark(LogBookmark bookmark)
     377{
     378    m_bookmarkVector.push_back(bookmark);
     379    emit sigBookmarksUpdated();
     380}
     381// void UIVMLogViewerWidget::sltCreateBookmarkAtCurrent()
     382// {
     383    // if (!currentTextEdit())
     384    //     return;
     385    // QWidget* viewport = currentTextEdit()->viewport();
     386    // if (!viewport)
     387    //     return;
     388    // QPoint point(0.5 * viewport->width(), 0.5 * viewport->height());
     389    // QTextBlock block = currentTextEdit()->cursorForPosition(point).block();
     390    // LogBookmark bookmark;
     391    // bookmark.first = block.firstLineNumber();
     392    // bookmark.second = block.text();
     393    // sltCreateBookmarkAtLine(bookmark);
     394//}
     395
     396
    350397#include "UIVMLogPage.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.h

    r70539 r70549  
    5050    Q_OBJECT;
    5151
     52signals:
     53
     54    void sigBookmarksUpdated();
     55
    5256public:
    5357
     
    7680    void setTextEdit(const QString &strText);
    7781
    78     /* Marks the plain text edit When we dont have a log content. */
     82    /** Marks the plain text edit When we dont have a log content. */
    7983    void markForError();
    8084
     
    8286    void clearScrollBarMarkingsVector();
    8387
    84     /* Undos the changes done to textDocument */
     88    /** Undos the changes done to textDocument */
    8589    void documentUndo();
     90
     91    void deleteBookmark(int index);
     92
     93    const QVector<LogBookmark>& bookmarkVector() const;
     94    void deleteAllBookmarks();
     95    /** Scrolls the plain text edit to the bookmark with index @a bookmarkIndex. */
     96    void scrollToBookmark(int bookmarkIndex);
    8697
    8798protected:
     
    89100private slots:
    90101
     102    void sltAddBookmark(LogBookmark bookmark);
    91103
    92104private:
     
    105117    int             m_tabIndex;
    106118
    107     QVector<LogBookmark> m_bookmarkMap;
     119    QVector<LogBookmark> m_bookmarkVector;
    108120
    109121};
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerBookmarksPanel.cpp

    r70529 r70549  
    4848}
    4949
    50 void UIVMLogViewerBookmarksPanel::updateBookmarkList(const QVector<QPair<int, QString> > *bookmarkVector)
     50void UIVMLogViewerBookmarksPanel::updateBookmarkList(const QVector<QPair<int, QString> > &bookmarkVector)
    5151{
    5252    if (!m_pBookmarksComboBox || !viewer())
    53         return;
    54     if (!bookmarkVector)
    5553        return;
    5654
     
    5856    QStringList bList;
    5957    bList << "Bookmarks List";
    60     for(int i = 0; i < bookmarkVector->size(); ++i)
     58    for(int i = 0; i < bookmarkVector.size(); ++i)
    6159    {
    6260        QString strItem = QString("BookMark %1 at Line %2: %3").arg(QString::number(i)).
    63             arg(QString::number(bookmarkVector->at(i).first)).arg(bookmarkVector->at(i).second);
     61            arg(QString::number(bookmarkVector.at(i).first)).arg(bookmarkVector.at(i).second);
    6462
    6563        if (strItem.length() > m_iMaxBookmarkTextLength)
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerBookmarksPanel.h

    r70529 r70549  
    5050       user switches to another log page tab etc. */
    5151    void setBookmarksList(const QVector<QPair<int, QString> > &bookmarkList);
    52     void updateBookmarkList(const QVector<QPair<int, QString> > *bookmarkVector);
     52    void updateBookmarkList(const QVector<QPair<int, QString> > &bookmarkVector);
    5353
    5454public slots:
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp

    r70542 r70549  
    107107}
    108108
    109 void UIVMLogViewerWidget::sltDeleteBookmark(int /*index*/)
    110 {
    111     // QVector<LogBookmark>* bookmarkVector = currentBookmarkVector();
    112     // if (!bookmarkVector || bookmarkVector->size() <= index)
    113     //     return;
    114     // bookmarkVector->remove(index, 1);
    115     // if (m_pBookmarksPanel)
    116     //     m_pBookmarksPanel->updateBookmarkList(bookmarkVector);
     109void UIVMLogViewerWidget::sltDeleteBookmark(int index)
     110{
     111    UIVMLogPage* logPage = currentLogPage();
     112    if(!logPage)
     113        return;
     114    logPage->deleteBookmark(index);
     115    if (m_pBookmarksPanel)
     116        m_pBookmarksPanel->updateBookmarkList(logPage->bookmarkVector());
    117117}
    118118
    119119void UIVMLogViewerWidget::sltDeleteAllBookmarks()
    120120{
    121     // QVector<LogBookmark>* bookmarkVector = currentBookmarkVector();
    122     // if (!bookmarkVector)
    123     //     return;
    124     // bookmarkVector->clear();
    125     // if (m_pBookmarksPanel)
    126     //     m_pBookmarksPanel->updateBookmarkList(bookmarkVector);
    127 }
    128 
    129 void UIVMLogViewerWidget::sltBookmarkSelected(int /*index*/)
    130 {
    131     // QVector<LogBookmark>* bookmarkVector = currentBookmarkVector();
    132     // if (!bookmarkVector || index >= bookmarkVector->size())
    133     //     return;
    134     // if (!currentLogPage() || !currentLogPage()->document())
    135     //     return;
    136 
    137     // int lineNumber = bookmarkVector->at(index).first;
    138     // QTextCursor cursor(currentLogPage()->document()->findBlockByLineNumber(lineNumber));
    139     // currentLogPage()->setTextCursor(cursor);
    140 
     121    UIVMLogPage* logPage = currentLogPage();
     122    if(!logPage)
     123        return;
     124    logPage->deleteAllBookmarks();
     125
     126    if (m_pBookmarksPanel)
     127        m_pBookmarksPanel->updateBookmarkList(logPage->bookmarkVector());
     128}
     129
     130void UIVMLogViewerWidget::sltBoomarksUpdated()
     131{
     132    if(!currentLogPage() || !m_pBookmarksPanel)
     133        return;
     134    m_pBookmarksPanel->updateBookmarkList(currentLogPage()->bookmarkVector());
     135}
     136
     137void UIVMLogViewerWidget::gotoBookmark(int bookmarkIndex)
     138{
     139    if(!currentLogPage())
     140        return;
     141    currentLogPage()->scrollToBookmark(bookmarkIndex);
    141142}
    142143
     
    168169    disconnect(m_pTabWidget, &QITabWidget::currentChanged, this, &UIVMLogViewerWidget::sltTabIndexChange);
    169170
    170     // m_logMap.clear();
    171171    m_logPageList.clear();
    172172    m_pTabWidget->setEnabled(true);
     
    262262
    263263    resetHighlighthing();
    264     // if (m_pSearchPanel)
    265     //     m_pSearchPanel->reset();
     264    if (m_pSearchPanel)
     265        m_pSearchPanel->reset();
    266266    // m_iCurrentTabIndex = tabIndex;
     267
    267268    /* We keep a separate QVector<LogBookmark> for each log page: */
    268     // QVector<LogBookmark>* bookmarkVector = currentBookmarkVector();
    269     // if (bookmarkVector && m_pBookmarksPanel)
    270     //     m_pBookmarksPanel->updateBookmarkList(bookmarkVector);
     269    if (m_pBookmarksPanel && currentLogPage())
     270        m_pBookmarksPanel->updateBookmarkList(currentLogPage()->bookmarkVector());
    271271}
    272272
     
    276276    if (m_pSearchPanel && m_pSearchPanel->isVisible())
    277277        m_pSearchPanel->refresh();
    278 }
    279 
    280 void UIVMLogViewerWidget::sltCreateBookmarkAtCurrent()
    281 {
    282     // if (!currentTextEdit())
    283     //     return;
    284     // QWidget* viewport = currentTextEdit()->viewport();
    285     // if (!viewport)
    286     //     return;
    287     // QPoint point(0.5 * viewport->width(), 0.5 * viewport->height());
    288     // QTextBlock block = currentTextEdit()->cursorForPosition(point).block();
    289     // LogBookmark bookmark;
    290     // bookmark.first = block.firstLineNumber();
    291     // bookmark.second = block.text();
    292     // sltCreateBookmarkAtLine(bookmark);
    293 }
    294 
    295 void UIVMLogViewerWidget::sltCreateBookmarkAtLine(LogBookmark bookmark)
    296 {
    297     Q_UNUSED(bookmark);
    298     // QVector<LogBookmark> *pBookmarkVector = currentBookmarkVector();
    299     // if (!pBookmarkVector)
    300     //     return;
    301     // pBookmarkVector->push_back(bookmark);
    302     // if (m_pBookmarksPanel)
    303     //     m_pBookmarksPanel->updateBookmarkList(pBookmarkVector);
    304278}
    305279
     
    391365                this, &UIVMLogViewerWidget::sltDeleteAllBookmarks);
    392366        connect(m_pBookmarksPanel, &UIVMLogViewerBookmarksPanel::sigBookmarkSelected,
    393                 this, &UIVMLogViewerWidget::sltBookmarkSelected);
     367                this, &UIVMLogViewerWidget::gotoBookmark);
    394368    }
    395369}
     
    610584
    611585    /* Make sure the log view widget has the focus: */
    612     // QWidget *pCurrentLogPage = currentTextEdit();
    613     // if (pCurrentLogPage)
    614     //     pCurrentLogPage->setFocus();
     586    if(currentLogPage())
     587        currentLogPage()->setFocus();
    615588}
    616589
     
    666639}
    667640
    668 // const QVector<LogBookmark>* UIVMLogViewerWidget::currentBookmarkVector() const
    669 // {
    670 //     UIVMLogViewerTextEdit *logPage = qobject_cast<UIVMLogViewerTextEdit*>(currentLogPage());
    671 //     if (!logPage)
    672 //         return 0;
    673 //     QString logFileName = logPage->logFileName();
    674 //     if (logFileName.isEmpty())
    675 //         return 0;
    676 
    677 //     return &(m_bookmarkMap[logFileName]);
    678 // }
    679 
    680 // QVector<LogBookmark>* UIVMLogViewerWidget::currentBookmarkVector()
    681 // {
    682 //     UIVMLogViewerTextEdit *logPage = qobject_cast<UIVMLogViewerTextEdit*>(currentLogPage());
    683 //     if (!logPage)
    684 //         return 0;
    685 //     QString logFileName = logPage->logFileName();
    686 //     if (logFileName.isEmpty())
    687 //         return 0;
    688 
    689 //     return &(m_bookmarkMap[logFileName]);
    690 // }
    691 
    692641void UIVMLogViewerWidget::hidePanel(UIVMLogViewerPanel* panel)
    693642{
     
    790739    /* Create page-container: */
    791740    UIVMLogPage* pLogPage = new UIVMLogPage(this);
     741    connect(pLogPage, &UIVMLogPage::sigBookmarksUpdated, this, &UIVMLogViewerWidget::sltBoomarksUpdated);
    792742    AssertPtrReturnVoid(pLogPage);
    793743    /* Set the file name only if we really have log file to read. */
     
    818768    logPage->documentUndo();
    819769    logPage->clearScrollBarMarkingsVector();
    820     // QPlainTextEdit *pTextEdit = logPage(m_iCurrentTabIndex);
    821     // if (pTextEdit)
    822     // {
    823     //     QTextDocument *pDocument = pTextEdit->document();
    824     //     if (pDocument)
    825     //         pDocument->undo();
    826     // }
    827     // UIIndicatorScrollBar* scrollBar = qobject_cast<UIIndicatorScrollBar*>(pTextEdit->verticalScrollBar());
    828     // if (scrollBar)
    829     // {
    830     //     scrollBar->setMarkingsVector(QVector<float>());
    831     //     pTextEdit->repaint();
    832     // }
    833 }
     770}
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.h

    r70539 r70549  
    9595    /** Deletes the bookmark with @p index from the current logs bookmark list. */
    9696        void sltDeleteBookmark(int index);
     97        /** Receives delete all signal from the bookmark panel and notifies UIVMLogPage. */
    9798        void sltDeleteAllBookmarks();
    98         /** Scroll the plain text edit to the selected bookmark. */
    99         void sltBookmarkSelected(int index);
    100         /** Creates a bookmark out of line number and block text. */
    101         void sltCreateBookmarkAtLine(QPair<int, QString> bookmark);
    102         /** Determines the (middle) line number of the visible text and calls sltCreateBookmarkAtLine. */
    103         void sltCreateBookmarkAtCurrent();
     99        /** Manages bookmark panel update when bookmark vector is updated */
     100        void sltBoomarksUpdated();
     101        /* Makes the current UIVMLogPage to goto (scroll) its bookmark with index @a index. */
     102        void gotoBookmark(int bookmarkIndex);
    104103    /** @} */
    105104
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