ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientTreatmentDimensionModel.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_TREATMENT_DIMENSION_MODEL_HPP
21#define ORES_QT_CLIENT_TREATMENT_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/treatment_dimension.hpp"
34
35namespace ores::qt {
36
37class ClientTreatmentDimensionModel final : public AbstractClientModel {
38 Q_OBJECT
39
40private:
41 inline static std::string_view logger_name =
42 "ores.qt.client_treatment_dimension_model";
43
44 [[nodiscard]] static auto& lg() {
45 using namespace ores::logging;
46 static auto instance = make_logger(logger_name);
47 return instance;
48 }
49
50public:
51 enum Column {
52 Code,
53 Name,
54 Description,
55 Version,
56 ModifiedBy,
57 RecordedAt,
58 ColumnCount
59 };
60
66 static constexpr std::size_t kColumnCount = std::size_t(ColumnCount);
67 static constexpr std::array<ColumnMetadata, kColumnCount> kColumns = {{
68 {
69 .column = Code,
70 .header = std::string_view("Code"),
72 .hidden_by_default = false,
73 .default_width = kColumnWidthAuto
74 },
75 {
76 .column = Name,
77 .header = std::string_view("Name"),
79 .hidden_by_default = false,
80 .default_width = kColumnWidthAuto
81 },
82 {
83 .column = Description,
84 .header = std::string_view("Description"),
86 .hidden_by_default = false,
87 .default_width = kColumnWidthAuto
88 },
89 {
90 .column = Version,
91 .header = std::string_view("Version"),
93 .hidden_by_default = false,
94 .default_width = 70
95 },
96 {
97 .column = ModifiedBy,
98 .header = std::string_view("Modified By"),
100 .hidden_by_default = false,
101 .default_width = kColumnWidthAuto
102 },
103 {
104 .column = RecordedAt,
105 .header = std::string_view("Recorded At"),
107 .hidden_by_default = false,
108 .default_width = kColumnWidthAuto
109 }
110 }};
111
115 inline static const QSize kDefaultWindowSize = {900, 400};
116
120 static constexpr std::string_view kSettingsGroup = "TreatmentDimensionMdiWindow";
124 static std::vector<column_style> const& columnStyles() {
125 static std::vector<column_style> const kStylesVector = []() {
126 std::vector<column_style> result;
127 result.reserve(kColumnCount);
128 for (std::size_t i = 0; i < kColumnCount; ++i)
129 result.push_back(kColumns[i].style);
130 return result;
131 }();
132 return kStylesVector;
133 }
134
138 static QVector<int> defaultHiddenColumns() {
139 static QVector<int> const result =
140 ::ores::qt::defaultHiddenColumns<kColumnCount>(kColumns);
141 return result;
142 }
143
144 explicit ClientTreatmentDimensionModel(ClientManager* clientManager,
145 QObject* parent = nullptr);
146 ~ClientTreatmentDimensionModel() override = default;
147
148 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
149 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
150 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
151 QVariant headerData(int section, Qt::Orientation orientation,
152 int role = Qt::DisplayRole) const override;
153
154 void refresh();
155 const dq::domain::treatment_dimension* getDimension(int row) const;
156
157signals:
158
159private slots:
160 void onDimensionsLoaded();
161 void onPulseStateChanged(bool isOn);
162 void onPulsingComplete();
163
164private:
165 QVariant recency_foreground_color(const std::string& code) const;
166
167 struct FetchResult {
168 bool success;
169 std::vector<dq::domain::treatment_dimension> dimensions;
170 QString error_message;
171 QString error_details;
172 };
173
174 ClientManager* clientManager_;
175 std::vector<dq::domain::treatment_dimension> dimensions_;
176 QFutureWatcher<FetchResult>* watcher_;
177 bool is_fetching_{false};
178
179 using TreatmentDimensionKeyExtractor = std::string(*)(const dq::domain::treatment_dimension&);
180 RecencyTracker<dq::domain::treatment_dimension, TreatmentDimensionKeyExtractor> recencyTracker_;
181 RecencyPulseManager* pulseManager_;
182};
183
184}
185
186#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AccountController.hpp:32
QVector< int > defaultHiddenColumns(const std::array< ColumnMetadata, N > &columns)
Builds a QVector of hidden column indices from a metadata array.
Definition ColumnMetadata.hpp:99
constexpr int kColumnWidthAuto
Sentinel value for column default width meaning "auto-size to contents".
Definition ColumnMetadata.hpp:38
@ mono_center
Monospace, centered.
@ text_left
Proportional font, left-aligned (default).
@ mono_left
Monospace, left-aligned.
Classifies datasets by their processing treatment level.
Definition treatment_dimension.hpp:41