ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientCodingSchemeAuthorityTypeModel.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_AUTHORITY_TYPE_MODEL_HPP
21#define ORES_QT_CLIENT_CODING_SCHEME_AUTHORITY_TYPE_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_authority_type.hpp"
31
32namespace ores::qt {
33
34class ClientCodingSchemeAuthorityTypeModel final : public QAbstractTableModel {
35 Q_OBJECT
36
37private:
38 inline static std::string_view logger_name =
39 "ores.qt.client_coding_scheme_authority_type_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 Description,
52 Version,
53 RecordedBy,
54 RecordedAt,
55 ColumnCount
56 };
57
58 explicit ClientCodingSchemeAuthorityTypeModel(ClientManager* clientManager,
59 QObject* parent = nullptr);
60 ~ClientCodingSchemeAuthorityTypeModel() override = default;
61
62 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
63 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
64 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
65 QVariant headerData(int section, Qt::Orientation orientation,
66 int role = Qt::DisplayRole) const override;
67
68 void refresh();
69 const dq::domain::coding_scheme_authority_type* getAuthorityType(int row) const;
70
71signals:
72 void dataLoaded();
73 void loadError(const QString& error_message, const QString& details = {});
74
75private slots:
76 void onAuthorityTypesLoaded();
77 void onPulseStateChanged(bool isOn);
78 void onPulsingComplete();
79
80private:
81 QVariant recency_foreground_color(const std::string& code) const;
82
83 struct FetchResult {
84 bool success;
85 std::vector<dq::domain::coding_scheme_authority_type> authority_types;
86 QString error_message;
87 QString error_details;
88 };
89
90 ClientManager* clientManager_;
91 std::vector<dq::domain::coding_scheme_authority_type> authorityTypes_;
92 QFutureWatcher<FetchResult>* watcher_;
93 bool is_fetching_{false};
94
95 using CodingSchemeAuthorityTypeKeyExtractor = std::string(*)(const dq::domain::coding_scheme_authority_type&);
96 RecencyTracker<dq::domain::coding_scheme_authority_type, CodingSchemeAuthorityTypeKeyExtractor> recencyTracker_;
97 RecencyPulseManager* pulseManager_;
98};
99
100}
101
102#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:35
Classifies coding schemes by the type of authority that defines them.
Definition coding_scheme_authority_type.hpp:40