VR-Engage  2.2
Loading...
Searching...
No Matches
vreChatWindowModel.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file vreChatWindowModel.h
7//! \brief Defines the data model for the chat window in VR-Engage
8//!
9//! This file contains the data model classes used by the chat window system,
10//! including DtChatEntry for individual chat messages and DtVreChatModel
11//! for the collection of messages displayed in the chat UI.
12
13#pragma once
14
16
17#include <QObject>
18
19namespace makVre
20{
21//! \brief Represents a single chat message entry
22//!
23//! DtChatEntry encapsulates a single chat message in the chat system,
24//! including the sender's username, force affiliation, target channel,
25//! message content, and display properties such as opacity and visibility.
26//! Each entry corresponds to one message bubble in the chat UI.
28{
29public:
30 //! \brief Constructor
31 //! \param username Name of the user who sent the message
32 //! \param force Force identifier of the sender (friendly=1, enemy=2, etc.)
33 //! \param channel Target channel for the message
34 //! \param message Content of the chat message
35 //!
36 //! Creates a new chat entry with the specified sender information and message content.
37 DtChatEntry(const std::string& username, int force, const std::string& channel, const std::string& message);
38
39 //! \brief Default destructor
40 ~DtChatEntry() = default;
41
42 //! \brief Gets the username of the message sender
43 //! \return Username as a QString
44 QString username() const;
45
46 //! \brief Sets the username of the message sender
47 //! \param val New username
48 void setUsername(QString val);
49
50 //! \brief Gets the channel the message was sent to
51 //! \return Channel name as a QString
52 QString channel() const;
53
54 //! \brief Sets the channel for the message
55 //! \param val New channel name
56 void setChannel(QString val);
57
58 //! \brief Gets the force identifier of the sender
59 //! \return Force identifier (friendly=1, enemy=2, etc.)
60 int force() const;
61
62 //! \brief Sets the force identifier of the sender
63 //! \param val New force identifier
64 void setForce(int val);
65
66 //! \brief Gets the content of the message
67 //! \return Message text as a QString
68 QString message() const;
69
70 //! \brief Sets the content of the message
71 //! \param val New message text
72 void setMessage(QString val);
73
74 //! \brief Gets the opacity of the message in the UI
75 //! \return Opacity value (0.0 to 1.0)
76 double opacity() const;
77
78 //! \brief Sets the opacity of the message in the UI
79 //! \param val New opacity value
80 void setOpacity(double val);
81
82 //! \brief Checks if the message fade timer has started
83 //! \return True if timer has started, false otherwise
84 bool timerStarted() const;
85
86 //! \brief Sets the timer started flag for message fading
87 //! \param val New timer started state
88 void setTimerStarted(bool val);
89
90 //! \brief Checks if the message is visible in the UI
91 //! \return True if visible, false if hidden
92 bool visible() const;
93
94 //! \brief Sets the visibility of the message in the UI
95 //! \param val New visibility state
96 void setVisible(bool val);
97
98protected:
99 //! \brief Username of the message sender
100 QString myUsername;
101
102 //! \brief Channel the message was sent to
103 QString myChannel;
104
105 //! \brief Force identifier of the sender (friendly=1, enemy=2, etc.)
107
108 //! \brief Content of the chat message
109 QString myMessage;
110
111 //! \brief Opacity of the message in the UI (0.0 to 1.0)
112 double myOpacity;
113
114 //! \brief Flag indicating if the fade timer has started
116
117 //! \brief Flag indicating if the message is visible in the UI
119};
120
121//! \brief Data model for the chat window contents
122//!
123//! DtVreChatModel is a list model that maintains the collection of chat messages
124//! displayed in the chat UI. It extends QAbstractListModel to provide a Qt-compatible
125//! interface for the QML-based chat window, exposing properties of DtChatEntry
126//! objects as roles that can be bound to UI elements.
127class PLAYERSTATION_DLL DtVreChatModel : public QAbstractListModel
128{
129 Q_OBJECT;
130
131public:
132 //! \brief Enumeration of data roles for accessing chat entry properties
133 //!
134 //! Defines the roles used to access specific properties of chat entries
135 //! in the QML view. These roles are used in QML bindings to display the
136 //! appropriate data for each chat message.
138 {
139 UsernameRole = Qt::UserRole + 1, //!< Role for accessing the sender's username
140 ChannelRole, //!< Role for accessing the message channel
141 ForceRole, //!< Role for accessing the sender's force identifier
142 MessageRole, //!< Role for accessing the message content
143 OpacityRole, //!< Role for accessing the message opacity
144 TimerStartedRole, //!< Role for accessing the timer started flag
145 VisibleRole //!< Role for accessing the message visibility
146 };
147
148public:
149 //! \brief Constructor
150 //! \param parent Parent QObject (default: nullptr)
151 //!
152 //! Creates a new chat model with the specified parent object.
153 DtVreChatModel(QObject* parent = nullptr);
154
155 //! \brief Default destructor
156 virtual ~DtVreChatModel() override = default;
157
158 //! \brief Clears all messages from the model
159 //!
160 //! Removes all chat entries from the model, effectively clearing
161 //! the chat window display.
162 virtual void clear();
163
164 //! \brief Adds a new chat message to the model
165 //! \param entry Chat entry to add
166 //!
167 //! Adds a new chat message to the model, which will then appear
168 //! in the chat window UI.
169 virtual void addChat(const DtChatEntry& entry);
170
171 //! \brief Sorts the model contents
172 //! \param column Column to sort by
173 //! \param order Sort order (ascending or descending)
174 //!
175 //! Required implementation from QAbstractListModel. Sorts the chat
176 //! entries according to the specified criteria.
177 virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
178
179 //! \brief Removes rows from the model
180 //! \param row Starting row to remove
181 //! \param column Column (unused in list models)
182 //! \param parent Parent index (unused in list models)
183 //! \return True if rows were successfully removed
184 //!
185 //! Removes the specified chat entries from the model.
186 virtual bool removeRows(int row, int column = 0, const QModelIndex& parent = QModelIndex()) override;
187
188 //! \brief Gets the number of chat entries in the model
189 //! \param parent Parent index (unused in list models)
190 //! \return Number of chat entries
191 //!
192 //! Returns the total number of chat messages in the model.
193 virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override;
194
195 //! \brief Gets data for a specific role and index
196 //! \param index Model index to get data for
197 //! \param role Data role to retrieve
198 //! \return QVariant containing the requested data
199 //!
200 //! Retrieves specific property data from a chat entry based on the
201 //! specified role. This is used by the QML view to display chat messages.
202 virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
203
204 //! \brief Sets data for a specific role and index
205 //! \param index Model index to set data for
206 //! \param value New value to set
207 //! \param role Data role to set
208 //! \return True if data was successfully set
209 //!
210 //! Updates a specific property of a chat entry based on the
211 //! specified role and value.
212 virtual bool setData(const QModelIndex& index, const QVariant& value, int role) override;
213
214protected:
215 //! \brief Maps role enum values to role name strings
216 //! \return Hash mapping role IDs to role names
217 //!
218 //! Provides the mapping between role enum values and their string names,
219 //! which is required for QML access to the model data.
220 virtual QHash<int, QByteArray> roleNames() const override;
221
222protected:
223 //! \brief List of chat entries in the model
224 //!
225 //! Contains all the chat messages currently displayed in the chat window.
226 QList<DtChatEntry> myChat;
227};
228} // namespace makVre
Represents a single chat message entry.
Definition vreChatWindowModel.h:28
QString message() const
Gets the content of the message.
DtChatEntry(const std::string &username, int force, const std::string &channel, const std::string &message)
Constructor.
void setChannel(QString val)
Sets the channel for the message.
double opacity() const
Gets the opacity of the message in the UI.
void setOpacity(double val)
Sets the opacity of the message in the UI.
void setTimerStarted(bool val)
Sets the timer started flag for message fading.
void setForce(int val)
Sets the force identifier of the sender.
QString username() const
Gets the username of the message sender.
bool myVisible
Flag indicating if the message is visible in the UI.
Definition vreChatWindowModel.h:118
QString channel() const
Gets the channel the message was sent to.
bool myTimerStarted
Flag indicating if the fade timer has started.
Definition vreChatWindowModel.h:115
QString myUsername
Username of the message sender.
Definition vreChatWindowModel.h:100
bool timerStarted() const
Checks if the message fade timer has started.
void setMessage(QString val)
Sets the content of the message.
QString myMessage
Content of the chat message.
Definition vreChatWindowModel.h:109
bool visible() const
Checks if the message is visible in the UI.
void setUsername(QString val)
Sets the username of the message sender.
int myForce
Force identifier of the sender (friendly=1, enemy=2, etc.)
Definition vreChatWindowModel.h:106
double myOpacity
Opacity of the message in the UI (0.0 to 1.0)
Definition vreChatWindowModel.h:112
void setVisible(bool val)
Sets the visibility of the message in the UI.
~DtChatEntry()=default
Default destructor.
QString myChannel
Channel the message was sent to.
Definition vreChatWindowModel.h:103
int force() const
Gets the force identifier of the sender.
virtual void sort(int column, Qt::SortOrder order=Qt::AscendingOrder) override
Sorts the model contents.
virtual void addChat(const DtChatEntry &entry)
Adds a new chat message to the model.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const override
Gets the number of chat entries in the model.
virtual bool removeRows(int row, int column=0, const QModelIndex &parent=QModelIndex()) override
Removes rows from the model.
virtual bool setData(const QModelIndex &index, const QVariant &value, int role) override
Sets data for a specific role and index.
virtual QHash< int, QByteArray > roleNames() const override
Maps role enum values to role name strings.
virtual ~DtVreChatModel() override=default
Default destructor.
virtual void clear()
Clears all messages from the model.
QList< DtChatEntry > myChat
List of chat entries in the model.
Definition vreChatWindowModel.h:226
ChatRoles
Enumeration of data roles for accessing chat entry properties.
Definition vreChatWindowModel.h:138
@ OpacityRole
Role for accessing the message opacity.
Definition vreChatWindowModel.h:143
@ UsernameRole
Role for accessing the sender's username.
Definition vreChatWindowModel.h:139
@ TimerStartedRole
Role for accessing the timer started flag.
Definition vreChatWindowModel.h:144
@ ChannelRole
Role for accessing the message channel.
Definition vreChatWindowModel.h:140
@ MessageRole
Role for accessing the message content.
Definition vreChatWindowModel.h:142
@ ForceRole
Role for accessing the sender's force identifier.
Definition vreChatWindowModel.h:141
@ VisibleRole
Role for accessing the message visibility.
Definition vreChatWindowModel.h:145
DtVreChatModel(QObject *parent=nullptr)
Constructor.
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Gets data for a specific role and index.
Defines export macros for the VR-Engage Player Station library.
#define PLAYERSTATION_DLL
Definition export.h:24
Include export definitions for this library.
Definition glsVreMessageUtil.h:49