Skip to content

Commit

Permalink
#47: Created header and cpp file which contain qproperties of critica…
Browse files Browse the repository at this point in the history
…l faults, non-critical faults, and microphone
  • Loading branch information
sumershinde22 committed Feb 6, 2024
1 parent e9d5892 commit 4090d59
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
46 changes: 46 additions & 0 deletions NERODevelopment/src/controllers/headercontroller.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "headercontroller.h"

HeaderController::HeaderController(Model *model, QObject *parent)
: QObject{parent}, m_numCriticalWarnings(0), m_numNonCriticalWarnings(0),
m_isTalking(false) {
this->m_model = model;
connect(m_model, &Model::onCurrentDataChange, this,
&HeaderController::currentDataDidChange);
}

int HeaderController::numCriticalWarnings() const {
return m_numCriticalWarnings;
}

void HeaderController::setNumCriticalWarnings(int numCriticalWarnings) {
if (m_numCriticalWarnings != numCriticalWarnings) {
m_numCriticalWarnings = numCriticalWarnings;
emit numCriticalWarningsChanged(numCriticalWarnings);
}
}

int HeaderController::numNonCriticalWarnings() const {
return m_numNonCriticalWarnings;
}

void HeaderController::setNumNonCriticalWarnings(int numNonCriticalWarnings) {
if (m_numNonCriticalWarnings != numNonCriticalWarnings) {
m_numNonCriticalWarnings = numNonCriticalWarnings;
emit numCriticalWarningsChanged(numNonCriticalWarnings);
}
}

bool HeaderController::isTalking() const { return m_isTalking; }

void HeaderController::setIsTalking(bool isTalking) {
if (m_isTalking != isTalking) {
m_isTalking = isTalking;
emit isTalkingChanged(isTalking);
}
}

void HeaderController::currentDataDidChange() {
setNumCriticalWarnings(*m_model->getNumCriticalWarnings());
setNumNonCriticalWarnings(*m_model->getNumNonCriticalWarnings());
setIsTalking(*m_model->getIsTalking());
}
45 changes: 45 additions & 0 deletions NERODevelopment/src/controllers/headercontroller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef HEADERCONTROLLER_H
#define HEADERCONTROLLER_H

#include "../models/model.h"
#include <QObject>

/**
* @brief The HeaderController class
* Controller for the views.
*/
class HeaderController : public QObject {
Q_OBJECT
Q_PROPERTY(int numCriticalWarnings READ numCriticalWarnings WRITE
setNumCriticalWarnings NOTIFY numCriticalWarningsChanged FINAL)
Q_PROPERTY(
int numNonCriticalWarnings READ numNonCriticalWarnings WRITE
setNumNonCriticalWarnings NOTIFY numNonCriticalWarningsChanged FINAL)
Q_PROPERTY(bool isTalking READ isTalking WRITE setIsTalking NOTIFY
isTalkingChanged FINAL)

public:
explicit HeaderController(Model *model, QObject *parent = nullptr);
int numCriticalWarnings() const;
int numNonCriticalWarnings() const;
bool isTalking() const;

signals:
void numCriticalWarningsChanged(int);
void numNonCriticalWarningsChanged(int);
void isTalkingChanged(bool);

public slots:
void setNumCriticalWarnings(int);
void setNumNonCriticalWarnings(int);
void setIsTalking(bool);
void currentDataDidChange();

private:
Model *m_model;
int m_numCriticalWarnings;
int m_numNonCriticalWarnings;
bool m_isTalking;
};

#endif // HEADERCONTROLLER_H

0 comments on commit 4090d59

Please sign in to comment.