ORE Studio 0.0.4
Loading...
Searching...
No Matches
EntityController.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2024 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_ENTITY_CONTROLLER_HPP
21#define ORES_QT_ENTITY_CONTROLLER_HPP
22
23#include <QObject>
24#include <QPointer>
25#include <QMainWindow>
26#include <QMdiArea>
27#include <QString>
28#include <QStringList>
29#include <QDateTime>
30#include <QMap>
31#include <memory>
32#include <string>
33#include <string_view>
34#include "ores.qt/ClientManager.hpp"
35#include "ores.qt/DetailDialogBase.hpp"
36#include "ores.logging/make_logger.hpp"
37#include "ores.qt/export.hpp"
38
39namespace ores::qt {
40
41class DetachableMdiSubWindow;
42class EntityListMdiWindow;
43
52class ORES_QT_API EntityController : public QObject {
53 Q_OBJECT
54
55private:
56 inline static std::string_view logger_name = "ores.qt.entity_controller";
57
58 [[nodiscard]] static auto& lg() {
59 using namespace ores::logging;
60 static auto instance = make_logger(logger_name);
61 return instance;
62 }
63
64public:
76 QMainWindow* mainWindow,
77 QMdiArea* mdiArea,
78 ClientManager* clientManager,
79 const QString& username,
80 std::string_view eventName = {},
81 QObject* parent = nullptr);
82
83 ~EntityController() override;
84
88 void setClientManager(ClientManager* clientManager, const QString& username);
89
93 void setUsername(const QString& username) { username_ = username; }
94
99 virtual void showListWindow() = 0;
100
105 virtual void closeAllWindows() = 0;
106
113 void setAutoReloadOnSave(bool enabled) { autoReloadOnSave_ = enabled; }
114
115signals:
117 void statusMessage(const QString& message);
118
120 void errorMessage(const QString& message);
121
129
134
135protected:
142 QString build_window_key(const QString& windowType, const QString& identifier) const;
143
149 bool try_reuse_window(const QString& key);
150
154 void bring_window_to_front(DetachableMdiSubWindow* window);
155
159 void track_window(const QString& key, DetachableMdiSubWindow* window);
160
164 void untrack_window(const QString& key);
165
178 void show_managed_window(DetachableMdiSubWindow* window,
179 DetachableMdiSubWindow* referenceWindow = nullptr,
180 QPoint offset = QPoint(30, 30));
181
191 void connect_dialog_close(DetailDialogBase* dialog, DetachableMdiSubWindow* window);
192
201 void register_detachable_window(DetachableMdiSubWindow* window);
202
211 virtual EntityListMdiWindow* listWindow() const { return nullptr; }
212
217 virtual void reloadListWindow() = 0;
218
225 void handleEntitySaved();
226
233 void handleEntityDeleted();
234
235private slots:
241 void onNotificationReceived(const QString& eventType,
242 const QDateTime& timestamp,
243 const QStringList& entityIds,
244 const QString& tenantId);
245
246private:
247 void setupEventSubscription();
248 void teardownEventSubscription();
249
250protected:
251 QMainWindow* mainWindow_;
252 QMdiArea* mdiArea_;
253 QPointer<ClientManager> clientManager_;
254 QString username_;
255
257 QMap<QString, DetachableMdiSubWindow*> managed_windows_;
258
260 bool autoReloadOnSave_ = false;
261
262private:
264 std::string eventName_;
265};
266
267}
268
269#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AccountController.hpp:32
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:123
QMdiSubWindow that can be detached to become a floating window.
Definition DetachableMdiSubWindow.hpp:40
Base class for all detail dialogs.
Definition DetailDialogBase.hpp:75
Abstract base class for entity controllers.
Definition EntityController.hpp:52
virtual EntityListMdiWindow * listWindow() const
Returns the list window for marking as stale on notifications.
Definition EntityController.hpp:211
QMap< QString, DetachableMdiSubWindow * > managed_windows_
Map of active windows indexed by unique key.
Definition EntityController.hpp:257
void setAutoReloadOnSave(bool enabled)
Sets whether the list window should auto-reload after save/delete.
Definition EntityController.hpp:113
void detachableWindowDestroyed(DetachableMdiSubWindow *window)
Emitted when a detachable window managed by this controller is destroyed.
void statusMessage(const QString &message)
Emitted when a status message should be shown to the user.
virtual void closeAllWindows()=0
Closes all windows managed by this controller. Must be implemented by derived classes.
void detachableWindowCreated(DetachableMdiSubWindow *window)
Emitted when a detachable window is created by this controller.
virtual void showListWindow()=0
Shows the main list window for this entity. Must be implemented by derived classes.
virtual void reloadListWindow()=0
Reloads the list window. Must be implemented by derived classes.
void setUsername(const QString &username)
Updates just the username.
Definition EntityController.hpp:93
void errorMessage(const QString &message)
Emitted when an error message should be shown to the user.
Base class for entity list MDI windows providing stale indicator support.
Definition EntityListMdiWindow.hpp:63