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 static QString format_state(int server_state);
84 static QString format_outcome(int outcome);
85
86 // QAbstractTableModel interface
87 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
88 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
89 QVariant data(const QModelIndex& index,
90 int role = Qt::DisplayRole) const override;
91 QVariant headerData(int section, Qt::Orientation orientation,
92 int role = Qt::DisplayRole) const override;
93
97 void refresh();
98
102 const compute_task* get_task(int row) const;
103
108
109private slots:
110 void onTasksLoaded();
111
112private:
113 struct FetchResult {
114 bool success = false;
115 std::vector<compute_task> tasks;
116 QString error_message;
117 QString error_details;
118 };
119
120 void fetch_tasks();
121
122 ClientManager* clientManager_;
123 HostDisplayNameCache* host_name_cache_{nullptr};
124 std::vector<compute_task> tasks_;
125 QFutureWatcher<FetchResult>* watcher_;
126 bool is_fetching_{false};
127};
128
129} // namespace ores::qt
130
131#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AccountController.hpp:32
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:37
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:123
Shared cache mapping host UUID strings to whimsical display names.
Definition HostDisplayNameCache.hpp:42
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