ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientOriginDimensionModel.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 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_ORIGIN_DIMENSION_MODEL_HPP
21#define ORES_QT_CLIENT_ORIGIN_DIMENSION_MODEL_HPP
22
23#include <vector>
24#include <QSize>
25#include <QFutureWatcher>
26#include <QAbstractTableModel>
27#include "ores.qt/AbstractClientModel.hpp"
28#include "ores.qt/ClientManager.hpp"
29#include "ores.qt/ColumnMetadata.hpp"
30#include "ores.qt/RecencyPulseManager.hpp"
31#include "ores.qt/RecencyTracker.hpp"
32#include "ores.logging/make_logger.hpp"
33#include "ores.dq.api/domain/origin_dimension.hpp"
34
35namespace ores::qt {
36
44 Q_OBJECT
45
46private:
47 inline static std::string_view logger_name =
48 "ores.qt.client_origin_dimension_model";
49
50 [[nodiscard]] static auto& lg() {
51 using namespace ores::logging;
52 static auto instance = make_logger(logger_name);
53 return instance;
54 }
55
56public:
60 enum Column {
61 Code,
62 Name,
63 Description,
64 Version,
65 ModifiedBy,
66 RecordedAt,
67 ColumnCount
68 };
69
75 static constexpr std::size_t kColumnCount = std::size_t(ColumnCount);
76 static constexpr std::array<ColumnMetadata, kColumnCount> kColumns = {{
77 {
78 .column = Code,
79 .header = std::string_view("Code"),
81 .hidden_by_default = false,
82 .default_width = kColumnWidthAuto
83 },
84 {
85 .column = Name,
86 .header = std::string_view("Name"),
88 .hidden_by_default = false,
89 .default_width = kColumnWidthAuto
90 },
91 {
92 .column = Description,
93 .header = std::string_view("Description"),
95 .hidden_by_default = false,
96 .default_width = kColumnWidthAuto
97 },
98 {
99 .column = Version,
100 .header = std::string_view("Version"),
102 .hidden_by_default = false,
103 .default_width = 70
104 },
105 {
106 .column = ModifiedBy,
107 .header = std::string_view("Modified By"),
109 .hidden_by_default = false,
110 .default_width = kColumnWidthAuto
111 },
112 {
113 .column = RecordedAt,
114 .header = std::string_view("Recorded At"),
116 .hidden_by_default = false,
117 .default_width = kColumnWidthAuto
118 }
119 }};
120
124 inline static const QSize kDefaultWindowSize = {800, 400};
125
129 static constexpr std::string_view kSettingsGroup = "OriginDimensionListWindow";
133 static std::vector<column_style> const& columnStyles() {
134 static std::vector<column_style> const kStylesVector = []() {
135 std::vector<column_style> result;
136 result.reserve(kColumnCount);
137 for (std::size_t i = 0; i < kColumnCount; ++i)
138 result.push_back(kColumns[i].style);
139 return result;
140 }();
141 return kStylesVector;
142 }
143
147 static QVector<int> defaultHiddenColumns() {
148 static QVector<int> const result =
149 ::ores::qt::defaultHiddenColumns<kColumnCount>(kColumns);
150 return result;
151 }
152
153 explicit ClientOriginDimensionModel(ClientManager* clientManager,
154 QObject* parent = nullptr);
155 ~ClientOriginDimensionModel() override = default;
156
157 // QAbstractTableModel interface
158 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
159 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
160 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
161 QVariant headerData(int section, Qt::Orientation orientation,
162 int role = Qt::DisplayRole) const override;
163
167 void refresh();
168
175 const dq::domain::origin_dimension* getDimension(int row) const;
176
177signals:
186private slots:
187 void onDimensionsLoaded();
188 void onPulseStateChanged(bool isOn);
189 void onPulsingComplete();
190
191private:
192 QVariant recency_foreground_color(const std::string& code) const;
193
194 struct FetchResult {
195 bool success;
196 std::vector<dq::domain::origin_dimension> dimensions;
197 QString error_message;
198 QString error_details;
199 };
200
201 ClientManager* clientManager_;
202 std::vector<dq::domain::origin_dimension> dimensions_;
203 QFutureWatcher<FetchResult>* watcher_;
204 bool is_fetching_{false};
205
206 using OriginDimensionKeyExtractor = std::string(*)(const dq::domain::origin_dimension&);
207 RecencyTracker<dq::domain::origin_dimension, OriginDimensionKeyExtractor> recencyTracker_;
208 RecencyPulseManager* pulseManager_;
209};
210
211}
212
213#endif
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_left
Monospace, left-aligned.
Classifies datasets by their origin or source type.
Definition origin_dimension.hpp:40
Base class for all client-side entity models.
Definition AbstractClientModel.hpp:36
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:109
Model for displaying origin dimensions fetched from the server.
Definition ClientOriginDimensionModel.hpp:43
static constexpr std::string_view kSettingsGroup
Settings group name for persisting window and column state.
Definition ClientOriginDimensionModel.hpp:129
static constexpr std::size_t kColumnCount
Column metadata: header text, style, visibility, and width.
Definition ClientOriginDimensionModel.hpp:75
static const QSize kDefaultWindowSize
Default window size for the origin dimension list window.
Definition ClientOriginDimensionModel.hpp:124
static std::vector< column_style > const & columnStyles()
Returns a static vector of column styles (built once per process).
Definition ClientOriginDimensionModel.hpp:133
const dq::domain::origin_dimension * getDimension(int row) const
Get dimension at the specified row.
Definition ClientOriginDimensionModel.cpp:198
void refresh()
Refresh dimension data from server asynchronously.
Definition ClientOriginDimensionModel.cpp:127
static QVector< int > defaultHiddenColumns()
Returns a static QVector of hidden column indices (built once per process).
Definition ClientOriginDimensionModel.hpp:147
Column
Enumeration of table columns for type-safe column access.
Definition ClientOriginDimensionModel.hpp:60