ORE Studio 0.0.4
Loading...
Searching...
No Matches
TelemetryMdiWindow.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_QT_TELEMETRY_MDI_WINDOW_HPP
21#define ORES_QT_TELEMETRY_MDI_WINDOW_HPP
22
23#include <QWidget>
24#include <QTreeWidget>
25#include <QTableView>
26#include <QTableWidget>
27#include <QSplitter>
28#include <QVBoxLayout>
29#include <QHBoxLayout>
30#include <QToolBar>
31#include <QLabel>
32#include <QTextEdit>
33#include <QGroupBox>
34#include <QTimer>
35#include <QPushButton>
36#include <QSortFilterProxyModel>
37#include <QCloseEvent>
38#include <memory>
39#include <unordered_map>
40#include "ores.qt/ClientManager.hpp"
41#include "ores.logging/make_logger.hpp"
42#include "ores.qt/ClientTelemetryLogModel.hpp"
43#include "ores.qt/PaginationWidget.hpp"
44#include "ores.iam/domain/session.hpp"
45
46namespace ores::qt {
47
54class TelemetryMdiWindow : public QWidget {
55 Q_OBJECT
56
57private:
58 inline static std::string_view logger_name =
59 "ores.qt.telemetry_mdi_window";
60
61 [[nodiscard]] static auto& lg() {
62 using namespace ores::logging;
63 static auto instance = make_logger(logger_name);
64 return instance;
65 }
66
67public:
68 explicit TelemetryMdiWindow(ClientManager* clientManager,
69 const QString& username,
70 QWidget* parent = nullptr);
71 ~TelemetryMdiWindow() override;
72
73 ClientTelemetryLogModel* logModel() const { return logModel_.get(); }
74
75 QSize sizeHint() const override;
76
77signals:
78 void statusChanged(const QString& message);
79 void errorOccurred(const QString& error_message);
80
81public slots:
82 void reload();
83 void reloadSessions();
84 void markAsStale();
85 void clearStaleIndicator();
86
87private slots:
88 void onSessionsLoaded();
89 void onSessionSelected(QTreeWidgetItem* item, int column);
90 void onLogSelected(const QModelIndex& current, const QModelIndex& previous);
91 void onLogsLoaded();
92 void onLoadError(const QString& error_message, const QString& details = {});
93 void onConnectionStateChanged();
94
95private:
96 void setupUi();
97 void setupToolbar();
98 void setupLevelFilters();
99 void setupSessionTree();
100 void setupLogTable();
101 void setupDetailPanels();
102 void setupReloadAction();
103 void startPulseAnimation();
104 void stopPulseAnimation();
105 void loadSessions();
106 void populateSessionTree(const std::vector<iam::domain::session>& sessions);
107 void updateSessionInfoPanel(const iam::domain::session& session);
108 void updateLogDetailPanel(const telemetry::domain::telemetry_log_entry& entry);
109 void clearDetailPanels();
110 void applyLevelFilter();
111 void updateFilterButtonStyle(QPushButton* btn, bool enabled, const QColor& color);
112
113protected:
114 void closeEvent(QCloseEvent* event) override;
115
116private:
117 // Main layout
118 QSplitter* mainSplitter_;
119 QWidget* leftPanel_;
120 QWidget* rightPanel_;
121
122 // Left panel: session tree + session details
123 QSplitter* leftSplitter_;
124 QTreeWidget* sessionTree_;
125 QGroupBox* sessionDetailsGroup_;
126 QTableWidget* sessionDetailsTable_;
127
128 // Right panel: toolbar + table + details
129 QVBoxLayout* rightLayout_;
130 QToolBar* toolBar_;
131 QTableView* logTableView_;
132 PaginationWidget* paginationWidget_;
133
134 // Log detail panel (message only)
135 QGroupBox* logDetailGroup_;
136 QTextEdit* logMessageEdit_;
137
138 // Level filter buttons
139 QPushButton* filterTraceBtn_;
140 QPushButton* filterDebugBtn_;
141 QPushButton* filterInfoBtn_;
142 QPushButton* filterWarnBtn_;
143 QPushButton* filterErrorBtn_;
144
145 // Toolbar actions
146 QAction* reloadAction_;
147 QIcon normalReloadIcon_;
148 QIcon staleReloadIcon_;
149 QTimer* pulseTimer_;
150 bool pulseState_{false};
151 int pulseCount_{0};
152
153 // Model and data
154 std::unique_ptr<ClientTelemetryLogModel> logModel_;
155 QSortFilterProxyModel* proxyModel_;
156 ClientManager* clientManager_;
157 QString username_;
158 bool isStale_{false};
159
160 // Session data cache
161 std::unordered_map<std::string, iam::domain::session> sessionCache_;
162 std::optional<boost::uuids::uuid> selectedSessionId_;
163
164 // Level filter state (true = show this level)
165 bool showTrace_{true};
166 bool showDebug_{true};
167 bool showInfo_{true};
168 bool showWarn_{true};
169 bool showError_{true};
170};
171
172}
173
174#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:35
Represents a user session in the system.
Definition session.hpp:78
Manages the lifecycle of the network client and IO context.
Definition ClientManager.hpp:90
Model for displaying telemetry log entries from the server.
Definition ClientTelemetryLogModel.hpp:40
Widget providing pagination controls for data tables.
Definition PaginationWidget.hpp:39
MDI window for viewing telemetry logs.
Definition TelemetryMdiWindow.hpp:54
A persisted telemetry log entry.
Definition telemetry_log_entry.hpp:41