ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientReportInstanceModel.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_INSTANCE_MODEL_HPP
21#define ORES_QT_CLIENT_REPORT_INSTANCE_MODEL_HPP
22
23#include <vector>
24#include <QFutureWatcher>
25#include <QAbstractTableModel>
26#include "ores.qt/AbstractClientModel.hpp"
27#include "ores.qt/ClientManager.hpp"
28#include "ores.qt/RecencyPulseManager.hpp"
29#include "ores.qt/RecencyTracker.hpp"
30#include "ores.logging/make_logger.hpp"
31#include "ores.reporting.api/domain/report_instance.hpp"
32
33namespace ores::qt {
34
42 Q_OBJECT
43
44private:
45 inline static std::string_view logger_name =
46 "ores.qt.client_report_instance_model";
47
48 [[nodiscard]] static auto& lg() {
49 using namespace ores::logging;
50 static auto instance = make_logger(logger_name);
51 return instance;
52 }
53
54public:
58 enum Column {
59 Name,
60 DefinitionId,
61 TriggerRunId,
62 OutputMessage,
63 StartedAt,
64 CompletedAt,
65 Version,
66 ModifiedBy,
67 ColumnCount
68 };
69
70 explicit ClientReportInstanceModel(ClientManager* clientManager,
71 QObject* parent = nullptr);
72 ~ClientReportInstanceModel() override = default;
73
74 // QAbstractTableModel interface
75 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
76 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
77 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
78 QVariant headerData(int section, Qt::Orientation orientation,
79 int role = Qt::DisplayRole) const override;
80
84 void refresh();
85
93
97 void load_page(std::uint32_t offset, std::uint32_t limit);
98
102 std::uint32_t page_size() const { return page_size_; }
103
107 void set_page_size(std::uint32_t size);
108
112 std::uint32_t total_available_count() const { return total_available_count_; }
113
114signals:
123private slots:
124 void onInstancesLoaded();
125 void onPulseStateChanged(bool isOn);
126 void onPulsingComplete();
127
128private:
129 QVariant recency_foreground_color(const std::string& code) const;
130
131 struct FetchResult {
132 bool success;
133 std::vector<reporting::domain::report_instance> instances;
134 std::uint32_t total_available_count;
135 QString error_message;
136 QString error_details;
137 };
138
139 void fetch_instances(std::uint32_t offset, std::uint32_t limit);
140
141 ClientManager* clientManager_;
142 std::vector<reporting::domain::report_instance> instances_;
143 QFutureWatcher<FetchResult>* watcher_;
144 std::uint32_t page_size_{100};
145 std::uint32_t total_available_count_{0};
146 bool is_fetching_{false};
147
148 using ReportInstanceKeyExtractor = std::string(*)(const reporting::domain::report_instance&);
149 RecencyTracker<reporting::domain::report_instance, ReportInstanceKeyExtractor> recencyTracker_;
150 RecencyPulseManager* pulseManager_;
151};
152
153}
154
155#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:109
Model for displaying report instances fetched from the server.
Definition ClientReportInstanceModel.hpp:41
const reporting::domain::report_instance * getInstance(int row) const
Get report instance at the specified row.
Definition ClientReportInstanceModel.cpp:280
void set_page_size(std::uint32_t size)
Set the page size for pagination.
Definition ClientReportInstanceModel.cpp:268
void refresh()
Refresh report instance data from server asynchronously.
Definition ClientReportInstanceModel.cpp:136
std::uint32_t total_available_count() const
Get the total number of records available on the server.
Definition ClientReportInstanceModel.hpp:112
void load_page(std::uint32_t offset, std::uint32_t limit)
Load a specific page of data.
Definition ClientReportInstanceModel.cpp:162
std::uint32_t page_size() const
Get the page size used for pagination.
Definition ClientReportInstanceModel.hpp:102
Column
Enumeration of table columns for type-safe column access.
Definition ClientReportInstanceModel.hpp:58
A single execution of a report definition.
Definition report_instance.hpp:44