-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogViewerTab.cpp
More file actions
112 lines (94 loc) · 3.23 KB
/
LogViewerTab.cpp
File metadata and controls
112 lines (94 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* Copyright (C) 2023 GeorgH93
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "LogViewerTab.h"
#include "LogViewer.h"
#include "LogParser.h"
#include "LogProfile.h"
#include "AppConfig.h"
#include "Profiler.hpp"
#include <QFile>
#include <QFileInfo>
LogViewerTab::LogViewerTab(QFile* file, QWidget *parent)
: QSplitter(parent), tabToolTip(file->fileName()), fileName(file->fileName())
{
ui.setupUi(this);
const QFileInfo fileInfo(file->fileName());
tabTitle = fileInfo.fileName();
Load(file);
// Prevent collapsing the main log view
const auto mainView = ui.mainViewSplitter;
setCollapsible(this->indexOf(mainView), false);
mainView->setCollapsible(mainView->indexOf(ui.logViewer), false);
connect(ui.logViewer, &LogViewer::cursorPositionChanged, this, &LogViewerTab::OnSelectedLineChange);
}
LogViewerTab::~LogViewerTab()
{
ui.logViewer = nullptr;
}
void LogViewerTab::OnSelectedLineChange() const
{
const auto textCursor = ui.logViewer->textCursor();
const auto& entries = logHolder.GetFilteredEntries();
const auto lineNumber = entries[std::min(static_cast<size_t>(textCursor.blockNumber()), entries.size() - 1)]->lineNumber;
QTextCursor cursor = ui.fullLogView->textCursor();
cursor.movePosition(QTextCursor::Start);
if (lineNumber > 0)
{
cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, lineNumber - 1);
}
ui.fullLogView->setTextCursor(cursor);
ui.fullLogView->centerCursor();
if (true) //TODO check if highlighting is enabled
{
HighlightCurrentLineInFullView();
}
}
void LogViewerTab::HighlightCurrentLineInFullView() const
{
QList<QTextEdit::ExtraSelection> extraSelections;
QTextEdit::ExtraSelection selection;
selection.format.setBackground(AppConfig::GetInstance()->GetHighlightedLineBackgroundColor());
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
selection.cursor = ui.fullLogView->textCursor();
selection.cursor.clearSelection();
extraSelections.append(selection);
ui.fullLogView->setExtraSelections(extraSelections);
}
void LogViewerTab::Load(QFile* file)
{
if (!file->open(QIODevice::ReadOnly))
{
// TODO handle error
return;
}
QString log;
{
BlockProfiler profileLoadFile("Load log file to RAM");
log = QString(file->readAll());
}
file->close();
{
BlockProfiler profilerSetFullLog("Set full log view");
// Based on application_621.log: Below method call causes 94MB of memory usage
ui.fullLogView->setPlainText(log);
}
logHolder.Load(log);
logHolder.Filter([](auto) -> bool { return true; }); //TODO
systemInfo = logHolder.GetSystemInfo();
tabIcon = logHolder.GetLogProfile()->GetIcon();
ui.logViewer->SetLogHolder(&logHolder);
}