ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientBadgeDefinitionModel.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_BADGE_DEFINITION_MODEL_HPP
21#define ORES_QT_CLIENT_BADGE_DEFINITION_MODEL_HPP
22
23#include <vector>
24#include <QFutureWatcher>
25#include <QAbstractTableModel>
26#include "ores.qt/ClientManager.hpp"
27#include "ores.qt/RecencyPulseManager.hpp"
28#include "ores.qt/RecencyTracker.hpp"
29#include "ores.logging/make_logger.hpp"
30#include "ores.dq/domain/badge_definition.hpp"
31
32namespace ores::qt {
33
40class ClientBadgeDefinitionModel final : public QAbstractTableModel {
41 Q_OBJECT
42
43private:
44 inline static std::string_view logger_name =
45 "ores.qt.client_badge_definition_model";
46
47 [[nodiscard]] static auto& lg() {
48 using namespace ores::logging;
49 static auto instance = make_logger(logger_name);
50 return instance;
51 }
52
53public:
57 enum Column {
58 Code,
59 Name,
60 Description,
61 BackgroundColour,
62 TextColour,
63 SeverityCode,
64 DisplayOrder,
65 Version,
66 ModifiedBy,
67 RecordedAt,
68 ColumnCount
69 };
70
71 explicit ClientBadgeDefinitionModel(ClientManager* clientManager,
72 QObject* parent = nullptr);
73 ~ClientBadgeDefinitionModel() override = default;
74
75 // QAbstractTableModel interface
76 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
77 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
78 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
79 QVariant headerData(int section, Qt::Orientation orientation,
80 int role = Qt::DisplayRole) const override;
81
85 void refresh();
86
93 const dq::domain::badge_definition* getDefinition(int row) const;
94
98 void load_page(std::uint32_t offset, std::uint32_t limit);
99
103 std::uint32_t page_size() const { return page_size_; }
104
108 void set_page_size(std::uint32_t size);
109
113 std::uint32_t total_available_count() const { return total_available_count_; }
114
115signals:
120
124 void loadError(const QString& error_message, const QString& details = {});
125
126private slots:
127 void onDefinitionsLoaded();
128 void onPulseStateChanged(bool isOn);
129 void onPulsingComplete();
130
131private:
132 QVariant recency_foreground_color(const std::string& code) const;
133
134 struct FetchResult {
135 bool success;
136 std::vector<dq::domain::badge_definition> definitions;
137 std::uint32_t total_available_count;
138 QString error_message;
139 QString error_details;
140 };
141
142 void fetch_definitions(std::uint32_t offset, std::uint32_t limit);
143
144 ClientManager* clientManager_;
145 std::vector<dq::domain::badge_definition> definitions_;
146 QFutureWatcher<FetchResult>* watcher_;
147 std::uint32_t page_size_{100};
148 std::uint32_t total_available_count_{0};
149 bool is_fetching_{false};
150
151 using BadgeDefinitionKeyExtractor = std::string(*)(const dq::domain::badge_definition&);
152 RecencyTracker<dq::domain::badge_definition, BadgeDefinitionKeyExtractor> recencyTracker_;
153 RecencyPulseManager* pulseManager_;
154};
155
156}
157
158#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
Visual definition for a badge, including colours, label, and severity.
Definition badge_definition.hpp:41
Model for displaying badge definitions fetched from the server.
Definition ClientBadgeDefinitionModel.hpp:40
void set_page_size(std::uint32_t size)
Set the page size for pagination.
Definition ClientBadgeDefinitionModel.cpp:275
void refresh()
Refresh badge definition data from server asynchronously.
Definition ClientBadgeDefinitionModel.cpp:143
std::uint32_t total_available_count() const
Get the total number of records available on the server.
Definition ClientBadgeDefinitionModel.hpp:113
const dq::domain::badge_definition * getDefinition(int row) const
Get badge definition at the specified row.
Definition ClientBadgeDefinitionModel.cpp:287
void dataLoaded()
Emitted when data has been successfully loaded.
void load_page(std::uint32_t offset, std::uint32_t limit)
Load a specific page of data.
Definition ClientBadgeDefinitionModel.cpp:169
void loadError(const QString &error_message, const QString &details={})
Emitted when an error occurs during data loading.
std::uint32_t page_size() const
Get the page size used for pagination.
Definition ClientBadgeDefinitionModel.hpp:103
Column
Enumeration of table columns for type-safe column access.
Definition ClientBadgeDefinitionModel.hpp:57
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:109