1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#ifndef SERVERAPP_H
#define SERVERAPP_H
#include <QApplication>
#include <QStringList>
#include <QMap>
class QSettings;
struct Room {
Room(const QMap<QString, QPoint> &cPos, const QSize &grid, const QSize &client, const QString &image, const QString &tutor) :
clientPositions(cPos),
gridSize(grid),
clientSize(client),
imagePath(image),
tutorIP(tutor) {};
QMap<QString, QPoint> clientPositions;
QSize gridSize;
QSize clientSize;
QString imagePath;
QString tutorIP;
};
/* define a macro `serverApp` that can be used anywhere in the program and
* returns a reference to the current ServerApp instance */
#if defined(serverApp)
#undef serverApp
#endif
#define serverApp (static_cast<ServerApp*>(QCoreApplication::instance())) // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast)
/* this class is supposed to (after complete refactoring) to encapsulate all
* state of the application. At the moment, the state is distributed within
* several widgets. With this class information access will also be easier as
* it is possible to access the current ServerApp instance from anywhere with
* the serverApp macro (like qApp) */
class ServerApp : public QApplication
{
Q_OBJECT
private:
QStringList _arguments;
QString _sessionName;
QByteArray _sessionNameArray;
QMap<QString, Room*> _rooms;
QString _currentRoom;
bool _doExit{};
bool _managerOnly{};
bool _isExam{};
QString _iniPath;
QStringList parseParameters();
void loadRooms();
public:
ServerApp(int& argc, char** argv);
virtual QStringList arguments();
/* getters */
const QString &sessionName() const { return _sessionName; }
const QByteArray &sessionNameArray() const { return _sessionNameArray; }
const QMap<QString, Room *> &getRooms() const { return _rooms; }
bool isExam() const { return _isExam; }
const Room* getCurrentRoom() const;
QSettings * getSettings();
/* setters */
void setSessionName(const QString& name);
void setSessionName();
void setCurrentRoom(const QString& room) { _currentRoom = room; }
void setExam(bool exam) { _isExam = exam; }
bool shouldExit() const { return _doExit; }
};
#endif
|