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 <QFutureWatcher>
25#include <QAbstractTableModel>
26#include "ores.qt/ClientManager.hpp"
27#include "ores.qt/RecencyPulseManager.hpp"
28#include "ores.qt/RecencyTracker.hpp"
29#include "ores.logging/make_logger.hpp"
30#include "ores.dq/domain/coding_scheme.hpp"
31
32namespace ores::qt {
33
34class ClientCodingSchemeModel final : public QAbstractTableModel {
35 Q_OBJECT
36
37private:
38 inline static std::string_view logger_name =
39 "ores.qt.client_coding_scheme_model";
40
41 [[nodiscard]] static auto& lg() {
42 using namespace ores::logging;
43 static auto instance = make_logger(logger_name);
44 return instance;
45 }
46
47public:
48 enum Column {
49 Code,
50 Name,
51 AuthorityType,
52 SubjectArea,
53 Domain,
54 Description,
55 Version,
56 RecordedBy,
57 RecordedAt,
58 ColumnCount
59 };
60
61 explicit ClientCodingSchemeModel(ClientManager* clientManager,
62 QObject* parent = nullptr);
63 ~ClientCodingSchemeModel() override = default;
64
65 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
66 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
67 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
68 QVariant headerData(int section, Qt::Orientation orientation,
69 int role = Qt::DisplayRole) const override;
70
71 void refresh();
72 const dq::domain::coding_scheme* getScheme(int row) const;
73
74signals:
75 void dataLoaded();
76 void loadError(const QString& error_message, const QString& details = {});
77
78private slots:
79 void onSchemesLoaded();
80 void onPulseStateChanged(bool isOn);
81 void onPulsingComplete();
82
83private:
84 QVariant recency_foreground_color(const std::string& code) const;
85
86 struct FetchResult {
87 bool success;
88 std::vector<dq::domain::coding_scheme> schemes;
89 QString error_message;
90 QString error_details;
91 };
92
93 ClientManager* clientManager_;
94 std::vector<dq::domain::coding_scheme> schemes_;
95 QFutureWatcher<FetchResult>* watcher_;
96 bool is_fetching_{false};
97
98 using CodingSchemeKeyExtractor = std::string(*)(const dq::domain::coding_scheme&);
99 RecencyTracker<dq::domain::coding_scheme, CodingSchemeKeyExtractor> recencyTracker_;
100 RecencyPulseManager* pulseManager_;
101};
102
103}
104
105#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:35
Defines a coding or identification standard used to identify entities.
Definition coding_scheme.hpp:36