VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.h@ 102493

Last change on this file since 102493 was 98844, checked in by vboxsync, 19 months ago

FE/Qt: Some small cleanup.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.5 KB
Line 
1/* $Id: UIVMLogPage.h 98844 2023-03-06 17:21:13Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIVMLogViewer class declaration.
4 */
5
6/*
7 * Copyright (C) 2010-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#ifndef FEQT_INCLUDED_SRC_logviewer_UIVMLogPage_h
29#define FEQT_INCLUDED_SRC_logviewer_UIVMLogPage_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34/* Qt includes: */
35#include <QWidget>
36#include <QUuid>
37
38/* GUI includes: */
39#include "QIWithRetranslateUI.h"
40#include "UIVMLogBookmark.h"
41
42/* Forward declarations: */
43class QHBoxLayout;
44class QPlainTextEdit;
45class UIVMLogViewerTextEdit;
46
47class UIVMLogBookmarkManager
48{
49public:
50 void addBookmark(const UIVMLogBookmark& newBookmark)
51 {
52 foreach (const UIVMLogBookmark& bookmark, m_bookmarks)
53 if (bookmark == newBookmark)
54 return;
55 m_bookmarks << newBookmark;
56 }
57
58 void addBookmark(int iCursorPosition, int iLineNumber, QString strBlockText)
59 {
60 foreach (const UIVMLogBookmark& bookmark, m_bookmarks)
61 if (bookmark.m_iLineNumber == iLineNumber)
62 return;
63 m_bookmarks << UIVMLogBookmark(iCursorPosition, iLineNumber, strBlockText);
64 }
65
66 void deleteBookmark(const UIVMLogBookmark& bookmark)
67 {
68 int index = -1;
69 for (int i = 0; i < m_bookmarks.size() && index == -1; ++i)
70 {
71 if (bookmark == m_bookmarks[i])
72 index = i;
73 }
74 deleteBookmarkByIndex(index);
75 }
76
77 void deleteBookmarkByIndex(int iIndex)
78 {
79 if (iIndex >= m_bookmarks.size() || iIndex < 0)
80 return;
81 m_bookmarks.removeAt(iIndex);
82 }
83
84 void deleteAllBookmarks()
85 {
86 m_bookmarks.clear();
87 }
88
89 int cursorPosition(int bookmarkIndex)
90 {
91 if (bookmarkIndex >= m_bookmarks.size())
92 return 0;
93 return m_bookmarks[bookmarkIndex].m_iCursorPosition;
94 }
95
96 QSet<int> lineSet() const
97 {
98 QSet<int> lines;
99 foreach (const UIVMLogBookmark& bookmark, m_bookmarks)
100 lines << bookmark.m_iLineNumber;
101 return lines;
102 }
103
104 const QVector<UIVMLogBookmark>& bookmarkList() const
105 {
106 return m_bookmarks;
107 }
108
109private:
110
111 QVector<UIVMLogBookmark> m_bookmarks;
112};
113
114
115class UIVMLogTab : public QIWithRetranslateUI<QWidget>
116{
117
118 Q_OBJECT;
119
120public:
121
122 UIVMLogTab(QWidget *pParent, const QUuid &uMachineId, const QString &strMachineName);
123 const QUuid &machineId() const;
124 const QString machineName() const;
125
126private:
127
128 QUuid m_uMachineId;
129 QString m_strMachineName;
130};
131
132/** UIVMLogPage defines data and functionalities of the each tab page of a UIVMLogViewerWidget.
133 * It stores the original log file content , a list of bookmarks, etc */
134class UIVMLogPage : public UIVMLogTab
135{
136 Q_OBJECT;
137
138signals:
139
140 void sigBookmarksUpdated();
141 void sigLogPageFilteredChanged(bool isFiltered);
142
143public:
144
145 UIVMLogPage(QWidget *pParent, const QUuid &uMachineId, const QString &strMachineName);
146 ~UIVMLogPage();
147
148 /** Returns the width of the current log page. return 0 if there is no current log page: */
149 int defaultLogPageWidth() const;
150
151 QPlainTextEdit *textEdit();
152 QTextDocument *document();
153
154 void setLogContent(const QString &strLogContent, bool fError);
155 const QString& logString() const;
156
157 void setLogFileName(const QString &strFileName);
158 const QString& logFileName() const;
159
160 /** Marks the plain text edit When we dont have a log content. */
161 void markForError();
162
163 void setScrollBarMarkingsVector(const QVector<float> &vector);
164 void clearScrollBarMarkingsVector();
165
166 /** Undos the changes done to textDocument */
167 void documentUndo();
168
169 const QVector<UIVMLogBookmark>& bookmarkList() const;
170
171 void deleteAllBookmarks();
172 /** Scrolls the plain text edit to the bookmark with index @a bookmarkIndex. */
173 void scrollToBookmark(int bookmarkIndex);
174
175 bool isFiltered() const;
176 void setFiltered(bool filtered);
177
178 void setShowLineNumbers(bool bShowLineNumbers);
179 void setWrapLines(bool bWrapLines);
180
181 QFont currentFont() const;
182 void setCurrentFont(QFont font);
183
184 void setLogFileId(int iLogFileId);
185 int logFileId() const;
186
187 void scrollToEnd();
188
189 void saveScrollBarPosition();
190 void restoreScrollBarPosition();
191
192 void deleteBookmarkByIndex(int iIndex);
193
194private slots:
195
196 void sltAddBookmark(const UIVMLogBookmark& bookmark);
197 void sltDeleteBookmark(const UIVMLogBookmark& bookmark);
198
199private:
200
201 void prepare();
202 void prepareWidgets();
203 void cleanup();
204 void retranslateUi();
205 void updateTextEditBookmarkLineSet();
206
207 /** Set plaintextEdit's text. Note that the text we
208 * show currently might be different than
209 * m_strLog. For example during filtering. */
210 void setTextEditText(const QString &strText);
211 void setTextEditTextAsHtml(const QString &strText);
212
213 QHBoxLayout *m_pMainLayout;
214 UIVMLogViewerTextEdit *m_pTextEdit;
215 /** Stores the log file (unmodified by filtering etc) content. */
216 QString m_strLog;
217 /** Stores full path and name of the log file. */
218 QString m_strLogFileName;
219 /** Stores the bookmarks of the logpage. All other bookmark related containers are updated wrt. this one. */
220 UIVMLogBookmarkManager m_bookmarkManager;
221
222 /** Keeps the index of the selected bookmark. Used especially when moving from one tab to another. */
223 int m_iSelectedBookmarkIndex;
224
225 /** @name Filtering related state variables
226 * @{ */
227 /** Designates whether currently displayed text is log text or a filtered version of it. That is
228 if m_bFiltered is false than (m_strLog == m_pTextEdit->text()). */
229 bool m_bFiltered;
230 /** @} */
231 /** The id we pass to CMachine::ReadLog. Used while refreshing and saving page content. */
232 int m_iLogFileId;
233};
234
235#endif /* !FEQT_INCLUDED_SRC_logviewer_UIVMLogPage_h */
Note: See TracBrowser for help on using the repository browser.

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