ORE Studio 0.0.4
Loading...
Searching...
No Matches
ComputeTaskViewModel.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2026 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_COMPUTE_TASK_VIEW_MODEL_HPP
21#define ORES_QT_COMPUTE_TASK_VIEW_MODEL_HPP
22
23#include <vector>
24#include <QFutureWatcher>
25#include <QAbstractTableModel>
26#include "ores.qt/AbstractClientModel.hpp"
27#include "ores.qt/ClientManager.hpp"
28#include "ores.qt/HostDisplayNameCache.hpp"
29#include "ores.logging/make_logger.hpp"
30#include "ores.compute.api/domain/batch.hpp"
31#include "ores.compute.api/domain/workunit.hpp"
32#include "ores.compute.api/domain/result.hpp"
33
34namespace ores::qt {
35
46
55 Q_OBJECT
56
57private:
58 inline static std::string_view logger_name =
59 "ores.qt.compute_task_view_model";
60
61 [[nodiscard]] static auto& lg() {
62 using namespace ores::logging;
63 static auto instance = make_logger(logger_name);
64 return instance;
65 }
66
67public:
68 enum Column {
69 Label,
70 State,
71 Outcome,
72 Host,
73 Duration,
74 Batch,
75 Received,
76 ColumnCount
77 };
78
79 explicit ComputeTaskViewModel(ClientManager* clientManager,
80 QObject* parent = nullptr);
81 ~ComputeTaskViewModel() override = default;
82
83 // QAbstractTableModel interface
84 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
85 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
86 QVariant data(const QModelIndex& index,
87 int role = Qt::DisplayRole) const override;
88 QVariant headerData(int section, Qt::Orientation orientation,
89 int role = Qt::DisplayRole) const override;
90
94 void refresh();
95
99 const compute_task* get_task(int row) const;
100
105
106private slots:
107 void onTasksLoaded();
108
109private:
110 struct FetchResult {
111 bool success = false;
112 std::vector<compute_task> tasks;
113 QString error_message;
114 QString error_details;
115 };
116
117 void fetch_tasks();
118
119 ClientManager* clientManager_;
120 HostDisplayNameCache* host_name_cache_{nullptr};
121 std::vector<compute_task> tasks_;
122 QFutureWatcher<FetchResult>* watcher_;
123 bool is_fetching_{false};
124};
125
126} // namespace ores::qt
127
128#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
A logical grouping of workunits forming a financial computation batch.
Definition batch.hpp:35
A specific execution instance of a workunit assigned to a host.
Definition result.hpp:38
An abstract job template within a compute batch.
Definition workunit.hpp:36
Base class for all client-side entity models.
Definition AbstractClientModel.hpp:36
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:109
A joined view row: one result with its workunit and batch context.
Definition ComputeTaskViewModel.hpp:39
int batch_ordinal
1-based position in the loaded batch list
Definition ComputeTaskViewModel.hpp:43
int task_ordinal
1-based position within its batch
Definition ComputeTaskViewModel.hpp:44
Read-only table model that joins results, workunits, and batches.
Definition ComputeTaskViewModel.hpp:54
void refresh()
Fetch and join all batches, workunits, and results.
Definition ComputeTaskViewModel.cpp:163
void set_host_name_cache(HostDisplayNameCache *cache)
Sets the host display-name cache (not owned).
Definition ComputeTaskViewModel.cpp:297
const compute_task * get_task(int row) const
Returns the task at the given row, or nullptr if out of range.
Definition ComputeTaskViewModel.cpp:291
Shared cache mapping host UUID strings to whimsical display names.
Definition HostDisplayNameCache.hpp:41