ORE Studio 0.0.4
Loading...
Searching...
No Matches
EventViewerDialog.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2024-2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 * MA 02110-1301, USA.
19 *
20 */
21#ifndef ORES_QT_EVENT_VIEWER_WINDOW_HPP
22#define ORES_QT_EVENT_VIEWER_WINDOW_HPP
23
24#include <deque>
25#include <vector>
26#include <memory>
27#include <QWidget>
28#include <QDateTime>
29#include <QAbstractTableModel>
30#include "ores.eventing/service/event_bus.hpp"
31#include "ores.logging/make_logger.hpp"
32
33class QTableView;
34class QVBoxLayout;
35class QLabel;
36class QPushButton;
37
38namespace ores::qt {
39
40class ClientManager;
41
46 QDateTime timestamp;
47 QString eventType;
48 QString source; // "local" or "remote"
49 QString summary;
50 QString jsonPayload;
51};
52
56class EventTableModel final : public QAbstractTableModel {
57 Q_OBJECT
58
59public:
60 enum Column {
61 Timestamp = 0,
62 EventType,
63 Source,
64 Summary,
65 ColumnCount
66 };
67
68 explicit EventTableModel(QObject* parent = nullptr);
69
70 [[nodiscard]] int rowCount(const QModelIndex& parent = QModelIndex()) const override;
71 [[nodiscard]] int columnCount(const QModelIndex& parent = QModelIndex()) const override;
72 [[nodiscard]] QVariant data(const QModelIndex& index,
73 int role = Qt::DisplayRole) const override;
74 [[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation,
75 int role = Qt::DisplayRole) const override;
76
77 void addEvent(EventRecord event);
78 void clear();
79 [[nodiscard]] const EventRecord& eventAt(int row) const;
80 [[nodiscard]] int eventCount() const { return static_cast<int>(events_.size()); }
81
82private:
83 std::deque<EventRecord> events_;
84 static constexpr int max_events_ = 1000;
85};
86
100class EventViewerWindow final : public QWidget {
101 Q_OBJECT
102
103private:
104 inline static std::string_view logger_name = "ores.qt.event_viewer_window";
105
106 [[nodiscard]] static auto& lg() {
107 using namespace ores::logging;
108 static auto instance = make_logger(logger_name);
109 return instance;
110 }
111
112public:
120 explicit EventViewerWindow(
121 std::shared_ptr<eventing::service::event_bus> eventBus,
122 ClientManager* clientManager,
123 QWidget* parent = nullptr);
124
125 ~EventViewerWindow() override;
126
127protected:
128 void showEvent(QShowEvent* event) override;
129 void closeEvent(QCloseEvent* event) override;
130
131private slots:
132 void onEventDoubleClicked(const QModelIndex& index);
133 void onClearClicked();
134 void onNotificationReceived(const QString& eventType,
135 const QDateTime& timestamp,
136 const QStringList& entityIds);
137
138private:
139 void setupUi();
140 void subscribeToEvents();
141 void unsubscribeFromEvents();
142
146 void addEvent(EventRecord record);
147
148 std::shared_ptr<eventing::service::event_bus> eventBus_;
149 ClientManager* clientManager_;
150
151 // UI components
152 QTableView* tableView_;
153 EventTableModel* model_;
154 QLabel* statusLabel_;
155 QPushButton* clearButton_;
156
157 // Event subscriptions (cleared on close)
158 std::vector<eventing::service::subscription> subscriptions_;
159
160 // Track if we're connected to ClientManager signals
161 bool connectedToClientManager_{false};
162};
163
164// Backwards compatibility alias
166
167}
168
169#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:35
Manages the lifecycle of the network client and IO context.
Definition ClientManager.hpp:90
Record of a single event for display in the viewer.
Definition EventViewerDialog.hpp:45
Table model for displaying event records.
Definition EventViewerDialog.hpp:56
MDI window for viewing domain events in real-time.
Definition EventViewerDialog.hpp:100