LogViewer
A modern log viewer with AI-assisted analysis (Qt 6)
Loading...
Searching...
No Matches
SideBySidePanel.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "EventsContainer.hpp"
4#include "IDataParser.hpp"
5
6#include <QFutureWatcher>
7#include <QLabel>
8#include <QString>
9#include <QWidget>
10#include <filesystem>
11#include <memory>
12
13class QComboBox;
14class QPushButton;
15class QSplitter;
16
17namespace ui::qt
18{
19
20class EventsTableView;
21
36{
37 Q_OBJECT
38
39public:
40 explicit SideBySidePanel(QWidget* parent = nullptr);
41 ~SideBySidePanel() override;
42
43 void OpenLeft(const QString& path);
44 void OpenRight(const QString& path);
45
46signals:
48
49private slots:
50 void OnOpenLeftFile();
51 void OnOpenRightFile();
52 void OnSyncModeChanged(int index);
53 void OnSetLeftRef();
54 void OnSetRightRef();
55 void OnLeftSelectionChanged(int actualRow);
56 void OnRightSelectionChanged(int actualRow);
57 void OnLeftLoadFinished();
59
60private:
61 enum class SyncMode { Timestamp, Manual, None };
62
63 // ── UI helpers ─────────────────────────────────────────────────────────
64 void BuildUi();
65 QWidget* BuildSide(bool isLeft);
67 void UpdateSyncStatus();
68
69 // ── Loading ─────────────────────────────────────────────────────────────
70 void LoadFile(bool isLeft);
71 void LoadFileDirect(bool isLeft, const QString& path);
72 void StartAsyncLoad(bool isLeft, std::unique_ptr<parser::IDataParser> parser,
73 const std::filesystem::path& path);
74
75 // ── Sync helpers ────────────────────────────────────────────────────────
76 double GetTimestamp(db::EventsContainer& container, size_t actualRow) const;
77 void SyncFromLeft(int actualRow);
78 void SyncFromRight(int actualRow);
79
80public:
85 static int FindNearestByTimestamp(db::EventsContainer& container,
86 double target, int fallbackRow);
87
88private:
89
90 // ── Data ────────────────────────────────────────────────────────────────
93
96
97 QLabel* m_leftFileLabel {nullptr};
98 QLabel* m_rightFileLabel {nullptr};
99 QPushButton* m_leftOpenBtn {nullptr};
100 QPushButton* m_rightOpenBtn {nullptr};
101
102 // Sync toolbar
103 QComboBox* m_syncModeCombo {nullptr};
104 QPushButton* m_setLeftRefBtn {nullptr};
105 QPushButton* m_setRightRefBtn {nullptr};
106 QLabel* m_syncStatusLabel{nullptr};
107
108 // ── Sync state ──────────────────────────────────────────────────────────
110 bool m_leftRefSet {false};
111 bool m_rightRefSet{false};
112 double m_leftRefTs {0.0}; // timestamp of chosen left reference event
113 double m_rightRefTs {0.0}; // timestamp of chosen right reference event
114 int m_leftRefRow {-1}; // actual index in left container
115 int m_rightRefRow{-1}; // actual index in right container
116 double m_syncOffset {0.0}; // rightTs = leftTs + m_syncOffset
117 bool m_syncInProgress{false};
118
119 // ── Async loading ───────────────────────────────────────────────────────
120 // The observer and parser must outlive the background future; store them
121 // per-side until the QFutureWatcher signals completion.
122 struct LoadJob
123 {
124 std::unique_ptr<parser::IDataParser> parser;
125
127 {
129 std::exception_ptr exception;
131 void ProgressUpdated() override {}
132 void NewEventFound(db::LogEvent&& ev) override
133 { container.AddEvent(std::move(ev)); }
135 std::vector<std::pair<int,db::LogEvent::EventItems>>&& b) override
136 { container.AddEventBatch(std::move(b)); }
137 };
138 std::unique_ptr<Observer> observer;
139 };
140
143 QFutureWatcher<void>* m_leftWatcher {nullptr};
144 QFutureWatcher<void>* m_rightWatcher {nullptr};
145};
146
147} // namespace ui::qt
Container class for managing collections of LogEvent objects.
Interface definitions for data parsing components.
High-performance, thread-safe container for managing large collections of LogEvent objects.
Definition EventsContainer.hpp:129
void AddEvent(LogEvent &&event)
Adds a new event to the container.
Definition EventsContainer.cpp:28
void AddEventBatch(std::vector< std::pair< int, LogEvent::EventItems > > &&eventBatch)
Adds a batch of new events to the container.
Definition EventsContainer.cpp:47
Represents a single, structured log event with key-value data.
Definition LogEvent.hpp:97
Observer interface for receiving notifications from data parsers.
Definition IDataParser.hpp:52
Definition EventsTableView.hpp:29
Definition SideBySidePanel.hpp:36
void OnRightLoadFinished()
Definition SideBySidePanel.cpp:365
void OpenLeft(const QString &path)
Definition SideBySidePanel.cpp:241
void SyncFromRight(int actualRow)
Definition SideBySidePanel.cpp:441
void OnLeftLoadFinished()
Definition SideBySidePanel.cpp:339
QFutureWatcher< void > * m_leftWatcher
Definition SideBySidePanel.hpp:143
LoadJob m_leftJob
Definition SideBySidePanel.hpp:141
bool m_leftRefSet
Definition SideBySidePanel.hpp:110
void OnOpenRightFile()
Definition SideBySidePanel.cpp:239
double m_leftRefTs
Definition SideBySidePanel.hpp:112
void OnOpenLeftFile()
Definition SideBySidePanel.cpp:238
void OnSetRightRef()
Definition SideBySidePanel.cpp:215
LoadJob m_rightJob
Definition SideBySidePanel.hpp:142
db::EventsContainer m_leftEvents
Definition SideBySidePanel.hpp:91
QComboBox * m_syncModeCombo
Definition SideBySidePanel.hpp:103
void LoadFile(bool isLeft)
Definition SideBySidePanel.cpp:244
void OpenRight(const QString &path)
Definition SideBySidePanel.cpp:242
void OnSyncModeChanged(int index)
Definition SideBySidePanel.cpp:188
QPushButton * m_setLeftRefBtn
Definition SideBySidePanel.hpp:104
void LoadFileDirect(bool isLeft, const QString &path)
Definition SideBySidePanel.cpp:279
void StartAsyncLoad(bool isLeft, std::unique_ptr< parser::IDataParser > parser, const std::filesystem::path &path)
Definition SideBySidePanel.cpp:302
SyncMode m_syncMode
Definition SideBySidePanel.hpp:109
void OnLeftSelectionChanged(int actualRow)
Definition SideBySidePanel.cpp:395
void OnSetLeftRef()
Definition SideBySidePanel.cpp:196
bool m_rightRefSet
Definition SideBySidePanel.hpp:111
QLabel * m_syncStatusLabel
Definition SideBySidePanel.hpp:106
void OnRightSelectionChanged(int actualRow)
Definition SideBySidePanel.cpp:402
void SyncFromLeft(int actualRow)
Definition SideBySidePanel.cpp:409
int m_rightRefRow
Definition SideBySidePanel.hpp:115
double m_rightRefTs
Definition SideBySidePanel.hpp:113
QLabel * m_leftFileLabel
Definition SideBySidePanel.hpp:97
QPushButton * m_leftOpenBtn
Definition SideBySidePanel.hpp:99
double m_syncOffset
Definition SideBySidePanel.hpp:116
QFutureWatcher< void > * m_rightWatcher
Definition SideBySidePanel.hpp:144
QPushButton * m_setRightRefBtn
Definition SideBySidePanel.hpp:105
void UpdateSyncStatus()
Definition SideBySidePanel.cpp:159
QPushButton * m_rightOpenBtn
Definition SideBySidePanel.hpp:100
EventsTableView * m_rightView
Definition SideBySidePanel.hpp:95
db::EventsContainer m_rightEvents
Definition SideBySidePanel.hpp:92
void BuildUi()
Definition SideBySidePanel.cpp:48
static int FindNearestByTimestamp(db::EventsContainer &container, double target, int fallbackRow)
Definition SideBySidePanel.cpp:484
QWidget * BuildSide(bool isLeft)
Definition SideBySidePanel.cpp:110
EventsTableView * m_leftView
Definition SideBySidePanel.hpp:94
int m_leftRefRow
Definition SideBySidePanel.hpp:114
bool m_syncInProgress
Definition SideBySidePanel.hpp:117
double GetTimestamp(db::EventsContainer &container, size_t actualRow) const
Definition SideBySidePanel.cpp:474
SyncMode
Definition SideBySidePanel.hpp:61
QLabel * m_rightFileLabel
Definition SideBySidePanel.hpp:98
void UpdateManualControls()
Definition SideBySidePanel.cpp:152
Data parsing components and interfaces.
Definition IControler.hpp:22
Definition ConfigEditorDialog.cpp:19
Definition SideBySidePanel.hpp:127
Observer(db::EventsContainer &c)
Definition SideBySidePanel.hpp:130
db::EventsContainer & container
Definition SideBySidePanel.hpp:128
void NewEventBatchFound(std::vector< std::pair< int, db::LogEvent::EventItems > > &&b) override
Called when a batch of new events is discovered during parsing.
Definition SideBySidePanel.hpp:134
void NewEventFound(db::LogEvent &&ev) override
Called when a new event is discovered during parsing.
Definition SideBySidePanel.hpp:132
std::exception_ptr exception
Definition SideBySidePanel.hpp:129
void ProgressUpdated() override
Called when parsing progress is updated.
Definition SideBySidePanel.hpp:131
Definition SideBySidePanel.hpp:123
std::unique_ptr< Observer > observer
Definition SideBySidePanel.hpp:138
std::unique_ptr< parser::IDataParser > parser
Definition SideBySidePanel.hpp:124