20#ifndef ORES_QT_CLIENT_CURRENCY_MODEL_HPP
21#define ORES_QT_CLIENT_CURRENCY_MODEL_HPP
24#include <unordered_set>
25#include <QFutureWatcher>
26#include <QAbstractTableModel>
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.refdata/domain/currency.hpp"
47 inline static std::string_view logger_name =
48 "ores.qt.client_currency_model";
50 [[nodiscard]]
static auto& lg() {
52 static auto instance = make_logger(logger_name);
83 QObject* parent =
nullptr);
87 int rowCount(
const QModelIndex& parent = QModelIndex())
const override;
88 int columnCount(
const QModelIndex& parent = QModelIndex())
const override;
89 QVariant data(
const QModelIndex& index,
int role = Qt::DisplayRole)
const override;
90 QVariant headerData(
int section, Qt::Orientation orientation,
91 int role = Qt::DisplayRole)
const override;
103 void refresh(
bool replace =
true);
114 void load_page(std::uint32_t offset, std::uint32_t limit);
121 bool canFetchMore(
const QModelIndex& parent = QModelIndex())
const override;
129 void fetchMore(
const QModelIndex& parent = QModelIndex())
override;
144 std::vector<refdata::domain::currency>
getCurrencies()
const;
210 void loadError(
const QString& error_message,
const QString& details = {});
213 void onCurrenciesLoaded();
214 void onPulseStateChanged(
bool isOn);
215 void onPulsingComplete();
229 QVariant foreground_color(
const std::string& iso_code)
const;
233 std::vector<refdata::domain::currency> currencies;
234 std::uint32_t total_available_count;
235 QString error_message;
236 QString error_details;
239 using FutureWatcherResult = FetchResult;
241 ClientManager* clientManager_;
242 ImageCache* imageCache_;
243 std::vector<refdata::domain::currency> currencies_;
244 QFutureWatcher<FutureWatcherResult>* watcher_;
245 std::uint32_t page_size_{100};
246 std::uint32_t total_available_count_{0};
247 bool is_fetching_{
false};
251 RecencyTracker<refdata::domain::currency, CurrencyKeyExtractor> recencyTracker_;
252 RecencyPulseManager* pulseManager_;
257 void fetch_currencies(std::uint32_t offset, std::uint32_t limit);
260 std::unordered_set<std::string> synthetic_iso_codes_;
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:35
Model for displaying currencies fetched from the server via client.
Definition ClientCurrencyModel.hpp:43
bool canFetchMore(const QModelIndex &parent=QModelIndex()) const override
Check if more data can be fetched from the server.
Definition ClientCurrencyModel.cpp:348
void fetchMore(const QModelIndex &parent=QModelIndex()) override
Fetch the next page of data from the server.
Definition ClientCurrencyModel.cpp:364
void set_page_size(std::uint32_t size)
Set the page size for pagination.
Definition ClientCurrencyModel.cpp:372
void clear_synthetic_markers()
Clear all synthetic currency markers.
Definition ClientCurrencyModel.cpp:446
void add_synthetic_currencies(std::vector< refdata::domain::currency > currencies)
Add synthetic (generated) currencies to the model.
Definition ClientCurrencyModel.cpp:399
void mark_as_saved(const std::string &iso_code)
Mark a synthetic currency as saved (no longer synthetic).
Definition ClientCurrencyModel.cpp:426
std::uint32_t total_available_count() const
Get the total number of records available on the server.
Definition ClientCurrencyModel.hpp:165
const refdata::domain::currency * getCurrency(int row) const
Get currency at the specified row.
Definition ClientCurrencyModel.cpp:337
void dataLoaded()
Emitted when data has been successfully loaded.
std::vector< refdata::domain::currency > getCurrencies() const
Get all currencies.
Definition ClientCurrencyModel.cpp:344
void refresh(bool replace=true)
Refresh currency data from server asynchronously.
Definition ClientCurrencyModel.cpp:169
void load_page(std::uint32_t offset, std::uint32_t limit)
Load a specific page of currency data.
Definition ClientCurrencyModel.cpp:202
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 ClientCurrencyModel.hpp:151
Column
Enumeration of table columns for type-safe column access.
Definition ClientCurrencyModel.hpp:63
bool is_synthetic(const std::string &iso_code) const
Check if a currency is synthetic (generated but not saved).
Definition ClientCurrencyModel.cpp:422
Manages the lifecycle of the network client and IO context.
Definition ClientManager.hpp:90
Cache for dynamically loaded images (flags, icons) from the server.
Definition ImageCache.hpp:52
Represents a currency with its metadata and formatting rules.
Definition currency.hpp:33