ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientDatasetModel.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_DATASET_MODEL_HPP
21#define ORES_QT_CLIENT_DATASET_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/dataset.hpp"
33
34namespace ores::qt {
35
36class ClientDatasetModel final : public QAbstractTableModel {
37 Q_OBJECT
38
39private:
40 inline static std::string_view logger_name =
41 "ores.qt.client_dataset_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 Code,
53 Catalog,
54 SubjectArea,
55 Domain,
56 Origin,
57 Nature,
58 Treatment,
59 SourceSystem,
60 AsOfDate,
61 Version,
62 RecordedBy,
63 RecordedAt,
64 Tags,
65 ColumnCount
66 };
67
68 // Custom roles for Tags column data
69 static constexpr int OriginRole = Qt::UserRole + 100;
70 static constexpr int NatureRole = Qt::UserRole + 101;
71 static constexpr int TreatmentRole = Qt::UserRole + 102;
72
73 explicit ClientDatasetModel(ClientManager* clientManager,
74 QObject* parent = nullptr);
75 ~ClientDatasetModel() override = default;
76
77 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
78 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
79 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
80 QVariant headerData(int section, Qt::Orientation orientation,
81 int role = Qt::DisplayRole) const override;
82
83 void refresh();
84 const dq::domain::dataset* getDataset(int row) const;
85
86signals:
87 void dataLoaded();
88 void loadError(const QString& error_message, const QString& details = {});
89
90private slots:
91 void onDatasetsLoaded();
92 void onPulseStateChanged(bool isOn);
93 void onPulsingComplete();
94
95private:
96 QVariant recency_foreground_color(const boost::uuids::uuid& id) const;
97
98 struct FetchResult {
99 bool success;
100 std::vector<dq::domain::dataset> datasets;
101 QString error_message;
102 QString error_details;
103 };
104
105 ClientManager* clientManager_;
106 std::vector<dq::domain::dataset> datasets_;
107 QFutureWatcher<FetchResult>* watcher_;
108 bool is_fetching_{false};
109
110 using DatasetKeyExtractor = std::string(*)(const dq::domain::dataset&);
111 RecencyTracker<dq::domain::dataset, DatasetKeyExtractor> recencyTracker_;
112 RecencyPulseManager* pulseManager_;
113};
114
115}
116
117#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:35
Represents a data quality dataset with lineage tracking.
Definition dataset.hpp:36