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