ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientCatalogModel.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_CATALOG_MODEL_HPP
21#define ORES_QT_CLIENT_CATALOG_MODEL_HPP
22
23#include <QSize>
24#include <QAbstractTableModel>
25#include <vector>
26#include "ores.dq.api/domain/catalog.hpp"
27#include "ores.qt/AbstractClientModel.hpp"
28#include "ores.qt/ClientManager.hpp"
29#include "ores.qt/ColumnMetadata.hpp"
30#include "ores.qt/RecencyPulseManager.hpp"
31#include "ores.qt/RecencyTracker.hpp"
32#include "ores.logging/make_logger.hpp"
33
34namespace ores::qt {
35
44 Q_OBJECT
45
46private:
47 inline static std::string_view logger_name = "ores.qt.client_catalog_model";
48
49 [[nodiscard]] static auto& lg() {
50 using namespace ores::logging;
51 static auto instance = make_logger(logger_name);
52 return instance;
53 }
54
55public:
56 enum Column {
57 Name = 0,
58 Description,
59 Owner,
60 Version,
61 ModifiedBy,
62 RecordedAt,
63 ColumnCount
64 };
65
71 static constexpr std::size_t kColumnCount = std::size_t(ColumnCount);
72 static constexpr std::array<ColumnMetadata, kColumnCount> kColumns = {{
73 {
74 .column = Name,
75 .header = std::string_view("Name"),
77 .hidden_by_default = false,
78 .default_width = kColumnWidthAuto
79 },
80 {
81 .column = Description,
82 .header = std::string_view("Description"),
84 .hidden_by_default = false,
85 .default_width = kColumnWidthAuto
86 },
87 {
88 .column = Owner,
89 .header = std::string_view("Owner"),
91 .hidden_by_default = false,
92 .default_width = kColumnWidthAuto
93 },
94 {
95 .column = Version,
96 .header = std::string_view("Version"),
98 .hidden_by_default = false,
99 .default_width = 70
100 },
101 {
102 .column = ModifiedBy,
103 .header = std::string_view("Modified By"),
105 .hidden_by_default = false,
106 .default_width = kColumnWidthAuto
107 },
108 {
109 .column = RecordedAt,
110 .header = std::string_view("Recorded At"),
112 .hidden_by_default = false,
113 .default_width = kColumnWidthAuto
114 }
115 }};
116
120 inline static const QSize kDefaultWindowSize = {800, 500};
121
125 static constexpr std::string_view kSettingsGroup = "CatalogListWindow";
129 static std::vector<column_style> const& columnStyles() {
130 static std::vector<column_style> const kStylesVector = []() {
131 std::vector<column_style> result;
132 result.reserve(kColumnCount);
133 for (std::size_t i = 0; i < kColumnCount; ++i)
134 result.push_back(kColumns[i].style);
135 return result;
136 }();
137 return kStylesVector;
138 }
139
143 static QVector<int> defaultHiddenColumns() {
144 static QVector<int> const result =
145 ::ores::qt::defaultHiddenColumns<kColumnCount>(kColumns);
146 return result;
147 }
148
149 explicit ClientCatalogModel(ClientManager* clientManager,
150 QObject* parent = nullptr);
151
152 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
153 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
154 QVariant data(const QModelIndex& index,
155 int role = Qt::DisplayRole) const override;
156 QVariant headerData(int section, Qt::Orientation orientation,
157 int role = Qt::DisplayRole) const override;
158
159 void loadData();
160 const dq::domain::catalog& catalogAt(int row) const;
161
162signals:
163 void loadStarted();
164 void loadFinished();
165 void errorOccurred(const QString& message, const QString& details = {});
166
167private slots:
168 void onPulseStateChanged(bool isOn);
169 void onPulsingComplete();
170
171private:
172 QVariant foregroundColor(const std::string& name) const;
173
174 ClientManager* clientManager_;
175 std::vector<dq::domain::catalog> catalogs_;
176
177 // Recency highlighting
178 using CatalogKeyExtractor = std::string(*)(const dq::domain::catalog&);
179 RecencyTracker<dq::domain::catalog, CatalogKeyExtractor> recencyTracker_;
180 RecencyPulseManager* pulseManager_;
181};
182
183}
184
185#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AccountController.hpp:32
constexpr int kColumnWidthAuto
Sentinel value for column default width meaning "auto-size to contents".
Definition ColumnMetadata.hpp:38
@ mono_center
Monospace, centered.
@ text_left
Proportional font, left-aligned (default).
@ mono_left
Monospace, left-aligned.
Represents a logical grouping of related datasets.
Definition catalog.hpp:39
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
Table model for displaying catalogs in a QTableView.
Definition ClientCatalogModel.hpp:43
static constexpr std::string_view kSettingsGroup
Settings group name for persisting window and column state.
Definition ClientCatalogModel.hpp:125
static constexpr std::size_t kColumnCount
Column metadata: header text, style, visibility, and width.
Definition ClientCatalogModel.hpp:71
static const QSize kDefaultWindowSize
Default window size for the catalog list window.
Definition ClientCatalogModel.hpp:120
static std::vector< column_style > const & columnStyles()
Returns a static vector of column styles (built once per process).
Definition ClientCatalogModel.hpp:129
static QVector< int > defaultHiddenColumns()
Returns a static QVector of hidden column indices (built once per process).
Definition ClientCatalogModel.hpp:143