ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientMethodologyModel.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_METHODOLOGY_MODEL_HPP
21#define ORES_QT_CLIENT_METHODOLOGY_MODEL_HPP
22
23#include <vector>
24#include <QSize>
25#include <QFutureWatcher>
26#include <QAbstractTableModel>
27#include "ores.qt/AbstractClientModel.hpp"
28#include <boost/uuid/uuid.hpp>
29#include <boost/uuid/uuid_io.hpp>
30#include "ores.qt/ClientManager.hpp"
31#include "ores.qt/ColumnMetadata.hpp"
32#include "ores.qt/RecencyPulseManager.hpp"
33#include "ores.qt/RecencyTracker.hpp"
34#include "ores.logging/make_logger.hpp"
35#include "ores.dq.api/domain/methodology.hpp"
36
37namespace ores::qt {
38
39class ClientMethodologyModel final : public AbstractClientModel {
40 Q_OBJECT
41
42private:
43 inline static std::string_view logger_name =
44 "ores.qt.client_methodology_model";
45
46 [[nodiscard]] static auto& lg() {
47 using namespace ores::logging;
48 static auto instance = make_logger(logger_name);
49 return instance;
50 }
51
52public:
53 enum Column {
54 Name,
55 Description,
56 LogicReference,
57 Version,
58 ModifiedBy,
59 RecordedAt,
60 ColumnCount
61 };
62
68 static constexpr std::size_t kColumnCount = std::size_t(ColumnCount);
69 static constexpr std::array<ColumnMetadata, kColumnCount> kColumns = {{
70 {
71 .column = Name,
72 .header = std::string_view("Name"),
74 .hidden_by_default = false,
75 .default_width = kColumnWidthAuto
76 },
77 {
78 .column = Description,
79 .header = std::string_view("Description"),
81 .hidden_by_default = false,
82 .default_width = kColumnWidthAuto
83 },
84 {
85 .column = LogicReference,
86 .header = std::string_view("Logic Reference"),
88 .hidden_by_default = false,
89 .default_width = kColumnWidthAuto
90 },
91 {
92 .column = Version,
93 .header = std::string_view("Version"),
95 .hidden_by_default = false,
96 .default_width = 70
97 },
98 {
99 .column = ModifiedBy,
100 .header = std::string_view("Modified By"),
102 .hidden_by_default = false,
103 .default_width = kColumnWidthAuto
104 },
105 {
106 .column = RecordedAt,
107 .header = std::string_view("Recorded At"),
109 .hidden_by_default = false,
110 .default_width = kColumnWidthAuto
111 }
112 }};
113
117 inline static const QSize kDefaultWindowSize = {900, 400};
118
122 static constexpr std::string_view kSettingsGroup = "MethodologyMdiWindow";
126 static std::vector<column_style> const& columnStyles() {
127 static std::vector<column_style> const kStylesVector = []() {
128 std::vector<column_style> result;
129 result.reserve(kColumnCount);
130 for (std::size_t i = 0; i < kColumnCount; ++i)
131 result.push_back(kColumns[i].style);
132 return result;
133 }();
134 return kStylesVector;
135 }
136
140 static QVector<int> defaultHiddenColumns() {
141 static QVector<int> const result =
142 ::ores::qt::defaultHiddenColumns<kColumnCount>(kColumns);
143 return result;
144 }
145
146 explicit ClientMethodologyModel(ClientManager* clientManager,
147 QObject* parent = nullptr);
148 ~ClientMethodologyModel() override = default;
149
150 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
151 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
152 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
153 QVariant headerData(int section, Qt::Orientation orientation,
154 int role = Qt::DisplayRole) const override;
155
156 void refresh();
157 const dq::domain::methodology* getMethodology(int row) const;
158
159signals:
160
161private slots:
162 void onMethodologiesLoaded();
163 void onPulseStateChanged(bool isOn);
164 void onPulsingComplete();
165
166private:
167 QVariant recency_foreground_color(const boost::uuids::uuid& id) const;
168
169 struct FetchResult {
170 bool success;
171 std::vector<dq::domain::methodology> methodologies;
172 QString error_message;
173 QString error_details;
174 };
175
176 ClientManager* clientManager_;
177 std::vector<dq::domain::methodology> methodologies_;
178 QFutureWatcher<FetchResult>* watcher_;
179 bool is_fetching_{false};
180
181 using MethodologyKeyExtractor = std::string(*)(const dq::domain::methodology&);
182 RecencyTracker<dq::domain::methodology, MethodologyKeyExtractor> recencyTracker_;
183 RecencyPulseManager* pulseManager_;
184};
185
186}
187
188#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.
Describes a methodology for data processing or transformation.
Definition methodology.hpp:33