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 <QMainWindow>
25#include <QMdiArea>
26#include <QString>
27#include <QMap>
28#include <memory>
29#include "ores.qt/ClientManager.hpp"
30
31namespace ores::qt {
32
33class DetachableMdiSubWindow;
34
43class EntityController : public QObject {
44 Q_OBJECT
45
46public:
56 QMainWindow* mainWindow,
57 QMdiArea* mdiArea,
58 ClientManager* clientManager,
59 const QString& username,
60 QObject* parent = nullptr);
61
62 virtual ~EntityController() = default;
63
67 void setClientManager(ClientManager* clientManager, const QString& username);
68
72 void setUsername(const QString& username) { username_ = username; }
73
78 virtual void showListWindow() = 0;
79
84 virtual void closeAllWindows() = 0;
85
86signals:
88 void statusMessage(const QString& message);
89
91 void errorMessage(const QString& message);
92
93protected:
100 QString build_window_key(const QString& windowType, const QString& identifier) const;
101
107 bool try_reuse_window(const QString& key);
108
113
117 void track_window(const QString& key, DetachableMdiSubWindow* window);
118
122 void untrack_window(const QString& key);
123
124protected:
125 QMainWindow* mainWindow_;
126 QMdiArea* mdiArea_;
127 ClientManager* clientManager_;
128 QString username_;
129
131 QMap<QString, DetachableMdiSubWindow*> managed_windows_;
132};
133
134}
135
136#endif
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:35
Manages the lifecycle of the network client and IO context.
Definition ClientManager.hpp:56
QMdiSubWindow that can be detached to become a floating window.
Definition DetachableMdiSubWindow.hpp:39
Abstract base class for entity controllers.
Definition EntityController.hpp:43
QMap< QString, DetachableMdiSubWindow * > managed_windows_
Map of active windows indexed by unique key.
Definition EntityController.hpp:131
void bring_window_to_front(DetachableMdiSubWindow *window)
Activates the specified window, handling detached state.
Definition EntityController.cpp:60
void untrack_window(const QString &key)
Unregisters a window from tracking.
Definition EntityController.cpp:79
QString build_window_key(const QString &windowType, const QString &identifier) const
Generates a unique key for tracking windows.
Definition EntityController.cpp:44
void statusMessage(const QString &message)
Emitted when a status message should be shown to the user.
bool try_reuse_window(const QString &key)
Tries to reuse an existing window if one exists for the key.
Definition EntityController.cpp:49
virtual void closeAllWindows()=0
Closes all windows managed by this controller. Must be implemented by derived classes.
void track_window(const QString &key, DetachableMdiSubWindow *window)
Registers a window for tracking.
Definition EntityController.cpp:74
void setClientManager(ClientManager *clientManager, const QString &username)
Updates the client manager and username (e.g. after re-login).
Definition EntityController.cpp:38
virtual void showListWindow()=0
Shows the main list window for this entity. Must be implemented by derived classes.
void setUsername(const QString &username)
Updates just the username.
Definition EntityController.hpp:72
void errorMessage(const QString &message)
Emitted when an error message should be shown to the user.