ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientCodingSchemeModel.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_CODING_SCHEME_MODEL_HPP
21#define ORES_QT_CLIENT_CODING_SCHEME_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/coding_scheme.hpp"
34
35namespace ores::qt {
36
37class ClientCodingSchemeModel final : public AbstractClientModel {
38 Q_OBJECT
39
40private:
41 inline static std::string_view logger_name =
42 "ores.qt.client_coding_scheme_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 AuthorityType,
55 SubjectArea,
56 Domain,
57 Description,
58 Version,
59 ModifiedBy,
60 RecordedAt,
61 ColumnCount
62 };
63
69 static constexpr std::size_t kColumnCount = std::size_t(ColumnCount);
70 static constexpr std::array<ColumnMetadata, kColumnCount> kColumns = {{
71 {
72 .column = Code,
73 .header = std::string_view("Code"),
75 .hidden_by_default = false,
76 .default_width = kColumnWidthAuto
77 },
78 {
79 .column = Name,
80 .header = std::string_view("Name"),
82 .hidden_by_default = false,
83 .default_width = kColumnWidthAuto
84 },
85 {
86 .column = AuthorityType,
87 .header = std::string_view("Authority Type"),
89 .hidden_by_default = false,
90 .default_width = kColumnWidthAuto
91 },
92 {
93 .column = SubjectArea,
94 .header = std::string_view("Subject Area"),
96 .hidden_by_default = false,
97 .default_width = kColumnWidthAuto
98 },
99 {
100 .column = Domain,
101 .header = std::string_view("Domain"),
103 .hidden_by_default = false,
104 .default_width = kColumnWidthAuto
105 },
106 {
107 .column = Description,
108 .header = std::string_view("Description"),
110 .hidden_by_default = false,
111 .default_width = kColumnWidthAuto
112 },
113 {
114 .column = Version,
115 .header = std::string_view("Version"),
117 .hidden_by_default = false,
118 .default_width = 70
119 },
120 {
121 .column = ModifiedBy,
122 .header = std::string_view("Modified By"),
124 .hidden_by_default = false,
125 .default_width = kColumnWidthAuto
126 },
127 {
128 .column = RecordedAt,
129 .header = std::string_view("Recorded At"),
131 .hidden_by_default = false,
132 .default_width = kColumnWidthAuto
133 }
134 }};
135
139 inline static const QSize kDefaultWindowSize = {900, 400};
140
144 static constexpr std::string_view kSettingsGroup = "CodingSchemeMdiWindow";
148 static std::vector<column_style> const& columnStyles() {
149 static std::vector<column_style> const kStylesVector = []() {
150 std::vector<column_style> result;
151 result.reserve(kColumnCount);
152 for (std::size_t i = 0; i < kColumnCount; ++i)
153 result.push_back(kColumns[i].style);
154 return result;
155 }();
156 return kStylesVector;
157 }
158
162 static QVector<int> defaultHiddenColumns() {
163 static QVector<int> const result =
164 ::ores::qt::defaultHiddenColumns<kColumnCount>(kColumns);
165 return result;
166 }
167
168 explicit ClientCodingSchemeModel(ClientManager* clientManager,
169 QObject* parent = nullptr);
170 ~ClientCodingSchemeModel() override = default;
171
172 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
173 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
174 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
175 QVariant headerData(int section, Qt::Orientation orientation,
176 int role = Qt::DisplayRole) const override;
177
178 void refresh();
179 const dq::domain::coding_scheme* getScheme(int row) const;
180
181signals:
182
183private slots:
184 void onSchemesLoaded();
185 void onPulseStateChanged(bool isOn);
186 void onPulsingComplete();
187
188private:
189 QVariant recency_foreground_color(const std::string& code) const;
190
191 struct FetchResult {
192 bool success;
193 std::vector<dq::domain::coding_scheme> schemes;
194 QString error_message;
195 QString error_details;
196 };
197
198 ClientManager* clientManager_;
199 std::vector<dq::domain::coding_scheme> schemes_;
200 QFutureWatcher<FetchResult>* watcher_;
201 bool is_fetching_{false};
202
203 using CodingSchemeKeyExtractor = std::string(*)(const dq::domain::coding_scheme&);
204 RecencyTracker<dq::domain::coding_scheme, CodingSchemeKeyExtractor> recencyTracker_;
205 RecencyPulseManager* pulseManager_;
206};
207
208}
209
210#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.
Defines a coding or identification standard used to identify entities.
Definition coding_scheme.hpp:36