ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientReportDefinitionModel.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_REPORT_DEFINITION_MODEL_HPP
21#define ORES_QT_CLIENT_REPORT_DEFINITION_MODEL_HPP
22
23#include <vector>
24#include <QHash>
25#include <QString>
26#include <QFutureWatcher>
27#include <QAbstractTableModel>
28#include "ores.qt/AbstractClientModel.hpp"
29#include "ores.qt/ClientManager.hpp"
30#include "ores.qt/RecencyPulseManager.hpp"
31#include "ores.qt/RecencyTracker.hpp"
32#include "ores.logging/make_logger.hpp"
33#include "ores.reporting.api/domain/report_definition.hpp"
34
35namespace ores::qt {
36
44 Q_OBJECT
45
46private:
47 inline static std::string_view logger_name =
48 "ores.qt.client_report_definition_model";
49
50 [[nodiscard]] static auto& lg() {
51 using namespace ores::logging;
52 static auto instance = make_logger(logger_name);
53 return instance;
54 }
55
56public:
60 enum Column {
61 Name,
62 ReportType,
63 ScheduleExpression,
64 ConcurrencyPolicy,
65 Status,
66 NextFire,
67 Version,
68 ModifiedBy,
69 RecordedAt,
70 ColumnCount
71 };
72
73 explicit ClientReportDefinitionModel(ClientManager* clientManager,
74 QObject* parent = nullptr);
75 ~ClientReportDefinitionModel() override = default;
76
77 // QAbstractTableModel interface
78 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
79 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
80 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
81 QVariant headerData(int section, Qt::Orientation orientation,
82 int role = Qt::DisplayRole) const override;
83
87 void refresh();
88
95 void load_fsm_states();
96
104
108 void load_page(std::uint32_t offset, std::uint32_t limit);
109
113 std::uint32_t page_size() const { return page_size_; }
114
118 void set_page_size(std::uint32_t size);
119
123 std::uint32_t total_available_count() const { return total_available_count_; }
124
125signals:
134private slots:
135 void onDefinitionsLoaded();
136 void onFsmStatesLoaded();
137 void onPulseStateChanged(bool isOn);
138 void onPulsingComplete();
139
140private:
141 QVariant recency_foreground_color(const std::string& code) const;
142 QString resolve_fsm_state_name(
143 const std::optional<boost::uuids::uuid>& state_id) const;
144
145 struct FetchResult {
146 bool success;
147 std::vector<reporting::domain::report_definition> definitions;
148 std::uint32_t total_available_count;
149 QString error_message;
150 QString error_details;
151 };
152
153 struct FsmStateFetchResult {
154 bool success;
155 // Maps UUID string → state name (e.g. "draft", "active")
156 QHash<QString, QString> state_map;
157 };
158
159 void fetch_definitions(std::uint32_t offset, std::uint32_t limit);
160
161 ClientManager* clientManager_;
162 std::vector<reporting::domain::report_definition> definitions_;
163 QFutureWatcher<FetchResult>* watcher_;
164 QFutureWatcher<FsmStateFetchResult>* fsm_watcher_;
165 std::uint32_t page_size_{100};
166 std::uint32_t total_available_count_{0};
167 bool is_fetching_{false};
168
169 // UUID string → state name, populated once from the DQ service
170 QHash<QString, QString> fsm_state_map_;
171
172 using ReportDefinitionKeyExtractor = std::string(*)(const reporting::domain::report_definition&);
173 RecencyTracker<reporting::domain::report_definition, ReportDefinitionKeyExtractor> recencyTracker_;
174 RecencyPulseManager* pulseManager_;
175};
176
177}
178
179#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
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:112
Model for displaying report definitions fetched from the server.
Definition ClientReportDefinitionModel.hpp:43
void set_page_size(std::uint32_t size)
Set the page size for pagination.
Definition ClientReportDefinitionModel.cpp:287
void load_fsm_states()
Load FSM states for the report_definition_lifecycle machine.
Definition ClientReportDefinitionModel.cpp:326
void refresh()
Refresh report definition data from server asynchronously.
Definition ClientReportDefinitionModel.cpp:155
std::uint32_t total_available_count() const
Get the total number of records available on the server.
Definition ClientReportDefinitionModel.hpp:123
const reporting::domain::report_definition * getDefinition(int row) const
Get report definition at the specified row.
Definition ClientReportDefinitionModel.cpp:299
void load_page(std::uint32_t offset, std::uint32_t limit)
Load a specific page of data.
Definition ClientReportDefinitionModel.cpp:181
std::uint32_t page_size() const
Get the page size used for pagination.
Definition ClientReportDefinitionModel.hpp:113
Column
Enumeration of table columns for type-safe column access.
Definition ClientReportDefinitionModel.hpp:60
Persistent template for a scheduled report.
Definition report_definition.hpp:44