20#ifndef ORES_QT_CHANGE_REASON_CACHE_HPP
21#define ORES_QT_CHANGE_REASON_CACHE_HPP
24#include <unordered_map>
26#include <QFutureWatcher>
27#include "ores.qt/ClientManager.hpp"
28#include "ores.logging/make_logger.hpp"
29#include "ores.dq/domain/change_reason.hpp"
30#include "ores.dq/domain/change_reason_category.hpp"
51 inline static std::string_view logger_name =
"ores.qt.change_reason_cache";
53 [[nodiscard]]
static auto& lg() {
55 static auto instance = make_logger(logger_name);
61 QObject* parent =
nullptr);
85 const std::vector<dq::domain::change_reason>&
allReasons()
const {
96 const std::string& category_code)
const;
105 const std::string& category_code)
const;
114 const std::string& code)
const;
127 const std::vector<dq::domain::change_reason_category>&
allCategories()
const {
148 void onReasonsLoaded();
149 void onCategoriesLoaded();
150 void onNotificationReceived(
const QString& eventType,
151 const QDateTime& timestamp,
const QStringList& entityIds);
155 void loadCategories();
156 void subscribeToEvents();
158 struct ReasonsResult {
160 std::vector<dq::domain::change_reason> reasons;
163 struct CategoriesResult {
165 std::vector<dq::domain::change_reason_category> categories;
168 ClientManager* clientManager_;
171 std::vector<dq::domain::change_reason> reasons_;
172 std::vector<dq::domain::change_reason_category> categories_;
175 std::unordered_map<std::string, std::size_t> reason_index_;
178 bool is_loaded_{
false};
179 bool is_loading_{
false};
180 bool reasons_loaded_{
false};
181 bool categories_loaded_{
false};
183 QFutureWatcher<ReasonsResult>* reasons_watcher_;
184 QFutureWatcher<CategoriesResult>* categories_watcher_;
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:35
Defines a specific reason for record changes.
Definition change_reason.hpp:47
Shared cache for change reasons used across all entity dialogs.
Definition ChangeReasonCache.hpp:47
const std::vector< dq::domain::change_reason > & allReasons() const
Get all change reasons.
Definition ChangeReasonCache.hpp:85
void loaded()
Emitted when reasons and categories have been loaded.
const dq::domain::change_reason * getReasonByCode(const std::string &code) const
Get a reason by its code.
Definition ChangeReasonCache.cpp:325
std::vector< dq::domain::change_reason > getReasonsForAmend(const std::string &category_code) const
Get change reasons filtered for amend operations.
Definition ChangeReasonCache.cpp:287
void refreshed()
Emitted when the cache is refreshed due to server event.
bool isValidReasonCode(const std::string &code) const
Check if a reason code is valid.
Definition ChangeReasonCache.cpp:335
bool isLoading() const
Check if loading is in progress.
Definition ChangeReasonCache.hpp:80
const std::vector< dq::domain::change_reason_category > & allCategories() const
Get all change reason categories.
Definition ChangeReasonCache.hpp:127
std::vector< dq::domain::change_reason > getReasonsForDelete(const std::string &category_code) const
Get change reasons filtered for delete operations.
Definition ChangeReasonCache.cpp:306
void loadAll()
Load all change reasons and categories from the server.
Definition ChangeReasonCache.cpp:86
void loadError(const QString &error_message)
Emitted when an error occurs during loading.
bool isLoaded() const
Check if reasons have been loaded.
Definition ChangeReasonCache.hpp:75
Manages the lifecycle of the network client and IO context.
Definition ClientManager.hpp:90