#ifndef SERVERAPP_H #define SERVERAPP_H #include #include #include class QSettings; struct Room { Room(const QMap &cPos, const QSize &grid, const QSize &client, const QString &image, const QString &tutor) : clientPositions(cPos), gridSize(grid), clientSize(client), imagePath(image), tutorIP(tutor) {}; QMap 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(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 _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 &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