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