VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.cpp@ 82781

Last change on this file since 82781 was 80881, checked in by vboxsync, 5 years ago

FE/Qt: bugref:8938. Refactoring connections that include casted parameters.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.6 KB
Line 
1/* $Id: UIVMLogPage.cpp 80881 2019-09-18 11:13:38Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIVMLogViewer class implementation.
4 */
5
6/*
7 * Copyright (C) 2010-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18/* Qt includes: */
19#include <QDateTime>
20#include <QDir>
21#include <QVBoxLayout>
22#if defined(RT_OS_SOLARIS)
23# include <QFontDatabase>
24#endif
25#include <QPainter>
26#include <QScrollBar>
27#include <QTextBlock>
28
29/* GUI includes: */
30#include "UIVMLogPage.h"
31#include "UIVMLogViewerTextEdit.h"
32
33
34UIVMLogPage::UIVMLogPage(QWidget *pParent /* = 0 */, int tabIndex /*= -1 */)
35 : QIWithRetranslateUI<QWidget>(pParent)
36 , m_pMainLayout(0)
37 , m_pTextEdit(0)
38 , m_tabIndex(tabIndex)
39 , m_iSelectedBookmarkIndex(-1)
40 , m_bFiltered(false)
41 , m_iFilteredLineCount(-1)
42 , m_iUnfilteredLineCount(-1)
43{
44 prepare();
45}
46
47UIVMLogPage::~UIVMLogPage()
48{
49 cleanup();
50}
51
52int UIVMLogPage::defaultLogPageWidth() const
53{
54 if (!m_pTextEdit)
55 return 0;
56
57 /* Compute a width for 132 characters plus scrollbar and frame width: */
58 int iDefaultWidth = m_pTextEdit->fontMetrics().width(QChar('x')) * 132 +
59 m_pTextEdit->verticalScrollBar()->width() +
60 m_pTextEdit->frameWidth() * 2;
61
62 return iDefaultWidth;
63}
64
65
66void UIVMLogPage::prepare()
67{
68 prepareWidgets();
69 retranslateUi();
70}
71
72void UIVMLogPage::prepareWidgets()
73{
74 m_pMainLayout = new QHBoxLayout();
75 setLayout(m_pMainLayout);
76 m_pMainLayout->setSpacing(0);
77 m_pMainLayout->setContentsMargins(0, 0, 0, 0);
78
79 m_pTextEdit = new UIVMLogViewerTextEdit(this);
80 m_pMainLayout->addWidget(m_pTextEdit);
81
82 connect(m_pTextEdit, &UIVMLogViewerTextEdit::sigAddBookmark,
83 this, &UIVMLogPage::sltAddBookmark);
84 connect(m_pTextEdit, &UIVMLogViewerTextEdit::sigDeleteBookmark,
85 this, &UIVMLogPage::sltDeleteBookmark);
86}
87
88QPlainTextEdit *UIVMLogPage::textEdit()
89{
90 return m_pTextEdit;
91}
92
93QTextDocument* UIVMLogPage::document()
94{
95 if (!m_pTextEdit)
96 return 0;
97 return m_pTextEdit->document();
98}
99
100void UIVMLogPage::setTabIndex(int index)
101{
102 m_tabIndex = index;
103}
104
105int UIVMLogPage::tabIndex() const
106{
107 return m_tabIndex;
108}
109
110void UIVMLogPage::retranslateUi()
111{
112}
113
114void UIVMLogPage::cleanup()
115{
116}
117
118void UIVMLogPage::setLogString(const QString &strLog)
119{
120 m_strLog = strLog;
121}
122
123const QString& UIVMLogPage::logString() const
124{
125 return m_strLog;
126}
127
128void UIVMLogPage::setLogFileName(const QString &strLogFileName)
129{
130 m_strLogFileName = strLogFileName;
131}
132
133const QString& UIVMLogPage::logFileName() const
134{
135 return m_strLogFileName;
136}
137
138void UIVMLogPage::setTextEditText(const QString &strText)
139{
140 if (!m_pTextEdit)
141 return;
142
143 m_pTextEdit->setPlainText(strText);
144 /* Move the cursor position to end: */
145 QTextCursor cursor = m_pTextEdit->textCursor();
146 cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
147 m_pTextEdit->setTextCursor(cursor);
148 update();
149}
150
151void UIVMLogPage::setTextEditTextAsHtml(const QString &strText)
152{
153 if (!m_pTextEdit)
154 return;
155 m_pTextEdit->appendHtml(strText);
156 update();
157}
158
159void UIVMLogPage::markForError()
160{
161 if (!m_pTextEdit)
162 return;
163 m_pTextEdit->setWrapLines(true);
164}
165
166void UIVMLogPage::setScrollBarMarkingsVector(const QVector<float> &vector)
167{
168 if (!m_pTextEdit)
169 return;
170 m_pTextEdit->setScrollBarMarkingsVector(vector);
171 update();
172}
173
174void UIVMLogPage::clearScrollBarMarkingsVector()
175{
176 if (!m_pTextEdit)
177 return;
178 m_pTextEdit->clearScrollBarMarkingsVector();
179 update();
180}
181
182void UIVMLogPage::documentUndo()
183{
184 if (!m_pTextEdit)
185 return;
186 if (m_pTextEdit->document())
187 m_pTextEdit->document()->undo();
188}
189
190
191void UIVMLogPage::deleteBookmark(int index)
192{
193 if (m_bookmarkVector.size() <= index)
194 return;
195 m_bookmarkVector.remove(index, 1);
196 updateTextEditBookmarkLineSet();
197}
198
199void UIVMLogPage::deleteBookmark(LogBookmark bookmark)
200{
201 int index = -1;
202 for (int i = 0; i < m_bookmarkVector.size(); ++i)
203 {
204 if (m_bookmarkVector.at(i).first == bookmark.first)
205 {
206 index = i;
207 break;
208 }
209 }
210 if (index != -1)
211 deleteBookmark(index);
212}
213
214
215void UIVMLogPage::deleteAllBookmarks()
216{
217 m_bookmarkVector.clear();
218 updateTextEditBookmarkLineSet();
219}
220
221void UIVMLogPage::scrollToBookmark(int bookmarkIndex)
222{
223 if (!m_pTextEdit)
224 return;
225 if (bookmarkIndex >= m_bookmarkVector.size())
226 return;
227
228 int lineNumber = m_bookmarkVector.at(bookmarkIndex).first;
229 m_pTextEdit->scrollToLine(lineNumber);
230}
231
232const QVector<LogBookmark>& UIVMLogPage::bookmarkVector() const
233{
234 return m_bookmarkVector;
235}
236
237void UIVMLogPage::setBookmarkVector(const QVector<LogBookmark>& bookmarks)
238{
239 m_bookmarkVector = bookmarks;
240 updateTextEditBookmarkLineSet();
241}
242
243void UIVMLogPage::sltAddBookmark(LogBookmark bookmark)
244{
245 m_bookmarkVector.push_back(bookmark);
246 updateTextEditBookmarkLineSet();
247 emit sigBookmarksUpdated();
248}
249
250void UIVMLogPage::sltDeleteBookmark(LogBookmark bookmark)
251{
252 deleteBookmark(bookmark);
253 updateTextEditBookmarkLineSet();
254 emit sigBookmarksUpdated();
255}
256
257void UIVMLogPage::updateTextEditBookmarkLineSet()
258{
259 if (!m_pTextEdit)
260 return;
261 QSet<int> bookmarkLinesSet;
262 for (int i = 0; i < m_bookmarkVector.size(); ++i)
263 {
264 bookmarkLinesSet.insert(m_bookmarkVector.at(i).first);
265 }
266 m_pTextEdit->setBookmarkLineSet(bookmarkLinesSet);
267}
268
269bool UIVMLogPage::isFiltered() const
270{
271 return m_bFiltered;
272}
273
274void UIVMLogPage::setFiltered(bool filtered)
275{
276 if (m_bFiltered == filtered)
277 return;
278 m_bFiltered = filtered;
279 if (m_pTextEdit)
280 {
281 m_pTextEdit->setShownTextIsFiltered(m_bFiltered);
282 m_pTextEdit->update();
283 }
284 emit sigLogPageFilteredChanged(m_bFiltered);
285}
286
287void UIVMLogPage::setShowLineNumbers(bool bShowLineNumbers)
288{
289 if (!m_pTextEdit)
290 return;
291 m_pTextEdit->setShowLineNumbers(bShowLineNumbers);
292}
293
294void UIVMLogPage::setWrapLines(bool bWrapLines)
295{
296 if (!m_pTextEdit)
297 return;
298 m_pTextEdit->setWrapLines(bWrapLines);
299}
300
301void UIVMLogPage::setFilterParameters(const QSet<QString> &filterTermSet, int filterOperationType,
302 int iFilteredLineCount, int iUnfilteredLineCount)
303{
304 m_filterTermSet = filterTermSet;
305 m_filterOperationType = filterOperationType;
306 m_iFilteredLineCount = iFilteredLineCount;
307 m_iUnfilteredLineCount = iUnfilteredLineCount;
308}
309
310int UIVMLogPage::filteredLineCount() const
311{
312 return m_iFilteredLineCount;
313}
314
315int UIVMLogPage::unfilteredLineCount() const
316{
317 return m_iUnfilteredLineCount;
318}
319
320bool UIVMLogPage::shouldFilterBeApplied(const QSet<QString> &filterTermSet, int filterOperationType) const
321{
322 /* If filter terms set is different reapply the filter. */
323 if (filterTermSet != m_filterTermSet)
324 return true;
325
326 /* If filter operation type set is different reapply the filter. */
327 if (filterOperationType != m_filterOperationType)
328 return true;
329 return false;
330}
331
332QFont UIVMLogPage::currentFont() const
333{
334 if (!m_pTextEdit)
335 return QFont();
336 return m_pTextEdit->font();
337}
338
339void UIVMLogPage::setCurrentFont(QFont font)
340{
341 if (m_pTextEdit)
342 m_pTextEdit->setCurrentFont(font);
343}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use