ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientOriginDimensionModel.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_ORIGIN_DIMENSION_MODEL_HPP
21#define ORES_QT_CLIENT_ORIGIN_DIMENSION_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/origin_dimension.hpp"
31
32namespace ores::qt {
33
40class ClientOriginDimensionModel final : public QAbstractTableModel {
41 Q_OBJECT
42
43private:
44 inline static std::string_view logger_name =
45 "ores.qt.client_origin_dimension_model";
46
47 [[nodiscard]] static auto& lg() {
48 using namespace ores::logging;
49 static auto instance = make_logger(logger_name);
50 return instance;
51 }
52
53public:
57 enum Column {
58 Code,
59 Name,
60 Description,
61 Version,
62 RecordedBy,
63 RecordedAt,
64 ColumnCount
65 };
66
67 explicit ClientOriginDimensionModel(ClientManager* clientManager,
68 QObject* parent = nullptr);
69 ~ClientOriginDimensionModel() override = default;
70
71 // QAbstractTableModel interface
72 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
73 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
74 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
75 QVariant headerData(int section, Qt::Orientation orientation,
76 int role = Qt::DisplayRole) const override;
77
81 void refresh();
82
89 const dq::domain::origin_dimension* getDimension(int row) const;
90
91signals:
95 void dataLoaded();
96
100 void loadError(const QString& error_message, const QString& details = {});
101
102private slots:
103 void onDimensionsLoaded();
104 void onPulseStateChanged(bool isOn);
105 void onPulsingComplete();
106
107private:
108 QVariant recency_foreground_color(const std::string& code) const;
109
110 struct FetchResult {
111 bool success;
112 std::vector<dq::domain::origin_dimension> dimensions;
113 QString error_message;
114 QString error_details;
115 };
116
117 ClientManager* clientManager_;
118 std::vector<dq::domain::origin_dimension> dimensions_;
119 QFutureWatcher<FetchResult>* watcher_;
120 bool is_fetching_{false};
121
122 using OriginDimensionKeyExtractor = std::string(*)(const dq::domain::origin_dimension&);
123 RecencyTracker<dq::domain::origin_dimension, OriginDimensionKeyExtractor> recencyTracker_;
124 RecencyPulseManager* pulseManager_;
125};
126
127}
128
129#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 datasets by their origin or source type.
Definition origin_dimension.hpp:39
Manages the lifecycle of the network client and IO context.
Definition ClientManager.hpp:90
Model for displaying origin dimensions fetched from the server.
Definition ClientOriginDimensionModel.hpp:40
const dq::domain::origin_dimension * getDimension(int row) const
Get dimension at the specified row.
Definition ClientOriginDimensionModel.cpp:235
void refresh()
Refresh dimension data from server asynchronously.
Definition ClientOriginDimensionModel.cpp:130
void dataLoaded()
Emitted when data has been successfully loaded.
void loadError(const QString &error_message, const QString &details={})
Emitted when an error occurs during data loading.
Column
Enumeration of table columns for type-safe column access.
Definition ClientOriginDimensionModel.hpp:57