ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientQueueModel.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2026 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_CLIENT_QUEUE_MODEL_HPP
21#define ORES_QT_CLIENT_QUEUE_MODEL_HPP
22
23#include <vector>
24#include <optional>
25#include <chrono>
26#include <cstdint>
27#include <string>
28#include <QSize>
29#include <QFutureWatcher>
30#include <QAbstractTableModel>
31#include "ores.qt/AbstractClientModel.hpp"
32#include "ores.qt/ClientManager.hpp"
33#include "ores.qt/ColumnMetadata.hpp"
34#include "ores.logging/make_logger.hpp"
35
36namespace ores::qt {
37
44struct queue_row {
45 std::string id; // stream name (used as identifier)
46 std::string name; // stream name
47 std::string subjects; // subjects joined with ", "
48 std::uint64_t message_count{0};
49 std::uint64_t byte_count{0};
50 std::uint64_t consumer_count{0};
51 std::chrono::system_clock::time_point created_at;
52 std::optional<std::chrono::system_clock::time_point> last_message_at;
53};
54
62 Q_OBJECT
63
64private:
65 inline static std::string_view logger_name = "ores.qt.client_queue_model";
66
67 [[nodiscard]] static auto& lg() {
68 using namespace ores::logging;
69 static auto instance = make_logger(logger_name);
70 return instance;
71 }
72
73public:
74 enum Column {
75 StreamName,
76 Subjects,
77 Messages,
78 Bytes,
79 Consumers,
80 CreatedAt,
81 LastMessageAt,
82 ColumnCount
83 };
84
85 static constexpr std::size_t kColumnCount = std::size_t(ColumnCount);
86 static constexpr std::array<ColumnMetadata, kColumnCount> kColumns = {{
87 { .column = StreamName, .header = "Stream", .style = column_style::text_left, .hidden_by_default = false, .default_width = kColumnWidthAuto },
88 { .column = Subjects, .header = "Subjects", .style = column_style::text_left, .hidden_by_default = false, .default_width = kColumnWidthAuto },
89 { .column = Messages, .header = "Messages", .style = column_style::mono_center, .hidden_by_default = false, .default_width = 90 },
90 { .column = Bytes, .header = "Bytes", .style = column_style::mono_center, .hidden_by_default = false, .default_width = 90 },
91 { .column = Consumers, .header = "Consumers", .style = column_style::mono_center, .hidden_by_default = false, .default_width = 80 },
92 { .column = CreatedAt, .header = "Created", .style = column_style::mono_left, .hidden_by_default = false, .default_width = kColumnWidthAuto },
93 { .column = LastMessageAt, .header = "Last Message", .style = column_style::mono_left, .hidden_by_default = false, .default_width = kColumnWidthAuto },
94 }};
95
96 inline static const QSize kDefaultWindowSize = {900, 400};
97 static constexpr std::string_view kSettingsGroup = "QueueMonitorListWindow";
98
99 static std::vector<column_style> const& columnStyles() {
100 static std::vector<column_style> const kStylesVector = []() {
101 std::vector<column_style> result;
102 result.reserve(kColumnCount);
103 for (std::size_t i = 0; i < kColumnCount; ++i)
104 result.push_back(kColumns[i].style);
105 return result;
106 }();
107 return kStylesVector;
108 }
109
110 static QVector<int> defaultHiddenColumns() {
111 static QVector<int> const result =
112 ::ores::qt::defaultHiddenColumns<kColumnCount>(kColumns);
113 return result;
114 }
115
116 explicit ClientQueueModel(ClientManager* clientManager,
117 QObject* parent = nullptr);
118 ~ClientQueueModel() override = default;
119
120 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
121 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
122 QVariant data(const QModelIndex& index,
123 int role = Qt::DisplayRole) const override;
124 QVariant headerData(int section, Qt::Orientation orientation,
125 int role = Qt::DisplayRole) const override;
126
127 void refresh();
128
129 const queue_row* getRow(int row) const;
130
131signals:
132
133private slots:
134 void onDataLoaded();
135
136private:
137 struct FetchResult {
138 bool success;
139 std::vector<queue_row> rows;
140 QString error_message;
141 QString error_details;
142 };
143
144 ClientManager* clientManager_;
145 std::vector<queue_row> rows_;
146 QFutureWatcher<FetchResult>* watcher_;
147 bool is_fetching_{false};
148};
149
150}
151
152#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
constexpr int kColumnWidthAuto
Sentinel value for column default width meaning "auto-size to contents".
Definition ColumnMetadata.hpp:37
@ mono_center
Monospace, centered.
@ text_left
Proportional font, left-aligned (default).
@ mono_left
Monospace, left-aligned.
Base class for all client-side entity models.
Definition AbstractClientModel.hpp:36
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:109
A row in the JetStream stream monitor table.
Definition ClientQueueModel.hpp:44
Table model that lists JetStream streams and their statistics.
Definition ClientQueueModel.hpp:61