20#ifndef ORES_QT_CLIENT_COUNTRY_MODEL_HPP
21#define ORES_QT_CLIENT_COUNTRY_MODEL_HPP
25#include <QFutureWatcher>
26#include <QAbstractTableModel>
27#include "ores.qt/AbstractClientModel.hpp"
28#include "ores.qt/ClientManager.hpp"
29#include "ores.qt/RecencyPulseManager.hpp"
30#include "ores.qt/RecencyTracker.hpp"
31#include "ores.qt/ColumnMetadata.hpp"
32#include "ores.logging/make_logger.hpp"
33#include "ores.refdata.api/domain/country.hpp"
49 inline static std::string_view logger_name =
50 "ores.qt.client_country_model";
52 [[nodiscard]]
static auto& lg() {
54 static auto instance = make_logger(logger_name);
79 static constexpr std::size_t
kColumnCount = std::size_t(ColumnCount);
80 static constexpr std::array<ColumnMetadata, kColumnCount> kColumns = {{
83 .header = std::string_view(
"Alpha-2"),
85 .hidden_by_default =
false,
90 .header = std::string_view(
"Alpha-3"),
92 .hidden_by_default =
true,
97 .header = std::string_view(
"Name"),
99 .hidden_by_default =
false,
103 .column = NumericCode,
104 .header = std::string_view(
"Numeric"),
106 .hidden_by_default =
true,
110 .column = OfficialName,
111 .header = std::string_view(
"Official Name"),
113 .hidden_by_default =
true,
118 .header = std::string_view(
"Version"),
120 .hidden_by_default =
false,
124 .column = ModifiedBy,
125 .header = std::string_view(
"Modified By"),
127 .hidden_by_default =
false,
131 .column = RecordedAt,
132 .header = std::string_view(
"Recorded At"),
134 .hidden_by_default =
false,
153 static std::vector<column_style>
const kStylesVector = []() {
154 std::vector<column_style> result;
157 result.push_back(kColumns[i].style);
160 return kStylesVector;
167 static QVector<int>
const result =
168 ::ores::qt::defaultHiddenColumns<kColumnCount>(kColumns);
174 QObject* parent =
nullptr);
178 int rowCount(
const QModelIndex& parent = QModelIndex())
const override;
179 int columnCount(
const QModelIndex& parent = QModelIndex())
const override;
180 QVariant data(
const QModelIndex& index,
int role = Qt::DisplayRole)
const override;
181 QVariant headerData(
int section, Qt::Orientation orientation,
182 int role = Qt::DisplayRole)
const override;
189 void refresh(
bool replace =
true);
197 void load_page(std::uint32_t offset, std::uint32_t limit);
212 std::vector<refdata::domain::country>
getCountries()
const;
241 void onCountriesLoaded();
242 void onPulseStateChanged(
bool isOn);
243 void onPulsingComplete();
246 QVariant recency_foreground_color(
const std::string& alpha2_code)
const;
250 std::vector<refdata::domain::country> countries;
251 std::uint32_t total_available_count;
252 QString error_message;
253 QString error_details;
256 void fetch_countries(std::uint32_t offset, std::uint32_t limit);
258 ClientManager* clientManager_;
259 ImageCache* imageCache_;
260 std::vector<refdata::domain::country> countries_;
261 QFutureWatcher<FetchResult>* watcher_;
262 std::uint32_t page_size_{100};
263 std::uint32_t total_available_count_{0};
264 bool is_fetching_{
false};
268 RecencyTracker<refdata::domain::country, CountryKeyExtractor> recencyTracker_;
269 RecencyPulseManager* pulseManager_;
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
constexpr int kColumnWidthAuto
Sentinel value for column default width meaning "auto-size to contents".
Definition ColumnMetadata.hpp:37
@ mono_center
Monospace, centered.
@ text_left
Proportional font, left-aligned (default).
@ mono_bold_left
Monospace bold, left-aligned.
@ mono_bold_center
Monospace bold, centered.
@ mono_left
Monospace, left-aligned.
Base class for all client-side entity models.
Definition AbstractClientModel.hpp:36
Model for displaying countries fetched from the server.
Definition ClientCountryModel.hpp:45
static constexpr std::string_view kSettingsGroup
Settings group name for persisting window and column state.
Definition ClientCountryModel.hpp:147
void set_page_size(std::uint32_t size)
Set the page size for pagination.
Definition ClientCountryModel.cpp:297
static constexpr std::size_t kColumnCount
Column metadata: header text, style, visibility, and width.
Definition ClientCountryModel.hpp:79
static const QSize kDefaultWindowSize
Default window size for the country list window.
Definition ClientCountryModel.hpp:142
static std::vector< column_style > const & columnStyles()
Returns a static vector of column styles (built once per process).
Definition ClientCountryModel.hpp:152
std::uint32_t total_available_count() const
Get the total number of records available on the server.
Definition ClientCountryModel.hpp:229
std::vector< refdata::domain::country > getCountries() const
Get all countries.
Definition ClientCountryModel.cpp:293
static QVector< int > defaultHiddenColumns()
Returns a static QVector of hidden column indices (built once per process).
Definition ClientCountryModel.hpp:166
const refdata::domain::country * getCountry(int row) const
Get country at the specified row.
Definition ClientCountryModel.cpp:286
void refresh(bool replace=true)
Refresh country data from server asynchronously.
Definition ClientCountryModel.cpp:156
void load_page(std::uint32_t offset, std::uint32_t limit)
Load a specific page of country data.
Definition ClientCountryModel.cpp:181
std::uint32_t page_size() const
Get the page size used for pagination.
Definition ClientCountryModel.hpp:217
Column
Enumeration of table columns for type-safe column access.
Definition ClientCountryModel.hpp:62
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:109
Cache for dynamically loaded images (flags, icons) from the server.
Definition ImageCache.hpp:53
Represents a country using ISO 3166-1 standard codes.
Definition country.hpp:34