ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientPricingModelProductModel.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_PRICING_MODEL_PRODUCT_MODEL_HPP
21#define ORES_QT_CLIENT_PRICING_MODEL_PRODUCT_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.analytics.api/domain/pricing_model_product.hpp"
32
33namespace ores::qt {
34
42 Q_OBJECT
43
44private:
45 inline static std::string_view logger_name =
46 "ores.qt.client_pricing_model_product_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 PricingEngineTypeCode,
60 Model,
61 Engine,
62 Version,
63 ModifiedBy,
64 RecordedAt,
65 ColumnCount
66 };
67
68 explicit ClientPricingModelProductModel(ClientManager* clientManager,
69 QObject* parent = nullptr);
70 ~ClientPricingModelProductModel() override = default;
71
72 // QAbstractTableModel interface
73 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
74 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
75 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
76 QVariant headerData(int section, Qt::Orientation orientation,
77 int role = Qt::DisplayRole) const override;
78
82 void refresh();
83
91
95 void load_page(std::uint32_t offset, std::uint32_t limit);
96
100 std::uint32_t page_size() const { return page_size_; }
101
105 void set_page_size(std::uint32_t size);
106
110 std::uint32_t total_available_count() const { return total_available_count_; }
111
112private slots:
113 void onProductsLoaded();
114 void onPulseStateChanged(bool isOn);
115 void onPulsingComplete();
116
117private:
118 QVariant recency_foreground_color(const std::string& code) const;
119
120 struct FetchResult {
121 bool success;
122 std::vector<analytics::domain::pricing_model_product> products;
123 std::uint32_t total_available_count;
124 QString error_message;
125 QString error_details;
126 };
127
128 void fetch_products(std::uint32_t offset, std::uint32_t limit);
129
130 ClientManager* clientManager_;
131 std::vector<analytics::domain::pricing_model_product> products_;
132 QFutureWatcher<FetchResult>* watcher_;
133 std::uint32_t page_size_{100};
134 std::uint32_t total_available_count_{0};
135 bool is_fetching_{false};
136
137 using PricingModelProductKeyExtractor = std::string(*)(const analytics::domain::pricing_model_product&);
138 RecencyTracker<analytics::domain::pricing_model_product, PricingModelProductKeyExtractor> recencyTracker_;
139 RecencyPulseManager* pulseManager_;
140};
141
142}
143
144#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AccountController.hpp:32
Per-product model and engine assignment within a pricing model config.
Definition pricing_model_product.hpp:38
Model for displaying pricing model products fetched from the server.
Definition ClientPricingModelProductModel.hpp:41
const analytics::domain::pricing_model_product * getProduct(int row) const
Get pricing model product at the specified row.
Definition ClientPricingModelProductModel.cpp:270
void set_page_size(std::uint32_t size)
Set the page size for pagination.
Definition ClientPricingModelProductModel.cpp:258
void refresh()
Refresh pricing model product data from server asynchronously.
Definition ClientPricingModelProductModel.cpp:128
std::uint32_t total_available_count() const
Get the total number of records available on the server.
Definition ClientPricingModelProductModel.hpp:110
void load_page(std::uint32_t offset, std::uint32_t limit)
Load a specific page of data.
Definition ClientPricingModelProductModel.cpp:154
std::uint32_t page_size() const
Get the page size used for pagination.
Definition ClientPricingModelProductModel.hpp:100
Column
Enumeration of table columns for type-safe column access.
Definition ClientPricingModelProductModel.hpp:58
Base class for all client-side entity models.
Definition AbstractClientModel.hpp:37
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:123