204 lines
6.0 KiB
C++
204 lines
6.0 KiB
C++
#include "GeneralStatusPage.h"
|
|
#include "ui_GeneralStatusPage.h"
|
|
#include "QStringList"
|
|
#include <QScrollBar>
|
|
#include <QLibrary>
|
|
#include "OtarcikCan.h"
|
|
|
|
CGeneralStatusPage::CGeneralStatusPage(QWidget *parent) :
|
|
QWidget(parent),
|
|
ui(new Ui::CGeneralStatusPage)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
connect(ui->mClearGenMsgTxtBtn,&QPushButton::clicked,this,&CGeneralStatusPage::ClearGenMsgAreaBtnPressed);
|
|
connect(ui->mQuitAppBtn,&QPushButton::clicked,this,&CGeneralStatusPage::QuitAppBtnPressed);
|
|
SetMQTTConnectionStatus(false);
|
|
SetCANConnectionStatus(false);
|
|
|
|
ui->mCANModuleStatusTableWdgt->setColumnCount(3);
|
|
ui->mCANModuleStatusTableWdgt->setHorizontalHeaderLabels(QStringList() << "Nom" << "Statut" << "Buffer");
|
|
|
|
ui->mPuckCANConStatLbl->setVisible(false);
|
|
ui->mPuckCANLbl->setVisible(false);
|
|
}
|
|
|
|
CGeneralStatusPage::~CGeneralStatusPage()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
int CGeneralStatusPage::SetGeneralMsgText(QStringList Txt)
|
|
{
|
|
Q_UNUSED(Txt)
|
|
/*if you're populating the text box programatically, is to use textEdit->setTextColor(QColor&).You can create the QColor object yourself, or use one of the predefined colours in the Qt namespace (Qt::black, Qt::red, etc). It will apply the specified colour to any text you add, until it is called again with a different one.*/
|
|
|
|
return RET_OK;
|
|
}
|
|
|
|
int CGeneralStatusPage::AddGeneralMsgBoxLineEntry(QString LineTxt)
|
|
{
|
|
|
|
//Limit the number of lines in the MsgBox to avoid overruns...
|
|
if(mGenMsgListBoxTextLines.size() >= GENERAL_MESSAGES_MAX_LOG_LINES)
|
|
{
|
|
mGenMsgListBoxTextLines.removeFirst();
|
|
mGenMsgListBoxTextLines.append(LineTxt);
|
|
|
|
ui->mGenMsgTextEdit->clear();
|
|
for(int i = 0; i < mGenMsgListBoxTextLines.size(); i++)
|
|
{
|
|
AddColoredLineToGenMsgBox(mGenMsgListBoxTextLines[i]);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
mGenMsgListBoxTextLines.append(LineTxt);
|
|
AddColoredLineToGenMsgBox(LineTxt);
|
|
}
|
|
|
|
ui->mGenMsgTextEdit->verticalScrollBar()->setValue(ui->mGenMsgTextEdit->verticalScrollBar()->maximum());
|
|
|
|
|
|
return RET_OK;
|
|
|
|
}
|
|
|
|
int CGeneralStatusPage::AddColoredLineToGenMsgBox(QString Line)
|
|
{
|
|
if(Line.isEmpty())
|
|
{
|
|
return RET_GENERAL_ERROR;
|
|
}
|
|
|
|
if(Line.at(0) == QChar('%'))
|
|
{
|
|
if(Line.at(1) == QChar('E')) //The line is describing an error... write it red
|
|
{
|
|
ui->mGenMsgTextEdit->setTextColor(Qt::red);
|
|
}
|
|
else if(Line.at(1) == QChar('W')) //The line is describing a warning... write it yellow
|
|
{
|
|
ui->mGenMsgTextEdit->setTextColor(Qt::blue);
|
|
}
|
|
else if(Line.at(1) == QChar('S')) //The line is describing a warning... write it yellow
|
|
{
|
|
ui->mGenMsgTextEdit->setTextColor(Qt::darkGreen);
|
|
}
|
|
else
|
|
{
|
|
qDebug("GeneralStatusPage: Logic error in general message box line encoding... you should check into that");
|
|
return RET_GENERAL_ERROR;
|
|
}
|
|
|
|
Line.remove(0,2);
|
|
}
|
|
|
|
ui->mGenMsgTextEdit->insertPlainText(Line);
|
|
ui->mGenMsgTextEdit->setTextColor(Qt::black);
|
|
|
|
return RET_OK;
|
|
|
|
}
|
|
|
|
void CGeneralStatusPage::ClearGenMsgAreaBtnPressed()
|
|
{
|
|
mGenMsgListBoxTextLines.clear();
|
|
ui->mGenMsgTextEdit->clear();
|
|
}
|
|
|
|
int CGeneralStatusPage::SetMQTTConnectionStatus(bool Connected)
|
|
{
|
|
if(Connected)
|
|
{
|
|
ui->mClientMQTTConnStatLbl->setText("CONNECTÉ");
|
|
QPalette pal = QPalette(ui->mClientMQTTConnStatLbl->palette());
|
|
pal.setColor(QPalette::WindowText,QColor(Qt::darkGreen));
|
|
ui->mClientMQTTConnStatLbl->setPalette(pal);
|
|
}
|
|
else
|
|
{
|
|
ui->mClientMQTTConnStatLbl->setText("DÉCONNECTÉ");
|
|
QPalette pal = QPalette(ui->mClientMQTTConnStatLbl->palette());
|
|
pal.setColor(QPalette::WindowText,QColor(Qt::red));
|
|
ui->mClientMQTTConnStatLbl->setPalette(pal);
|
|
}
|
|
|
|
return RET_OK;
|
|
}
|
|
|
|
int CGeneralStatusPage::SetCANConnectionStatus(bool Connected)
|
|
{
|
|
if(Connected)
|
|
{
|
|
ui->mPuckCANConStatLbl->setText("CONNECTÉE");
|
|
QPalette pal = QPalette(ui->mPuckCANConStatLbl->palette());
|
|
pal.setColor(QPalette::WindowText,QColor(Qt::darkGreen));
|
|
ui->mPuckCANConStatLbl->setPalette(pal);
|
|
}
|
|
else
|
|
{
|
|
ui->mPuckCANConStatLbl->setText("DÉCONNECTÉE");
|
|
QPalette pal = QPalette(ui->mPuckCANConStatLbl->palette());
|
|
pal.setColor(QPalette::WindowText,QColor(Qt::red));
|
|
ui->mPuckCANConStatLbl->setPalette(pal);
|
|
}
|
|
|
|
return RET_OK;
|
|
}
|
|
|
|
int CGeneralStatusPage::ClearCANModuleStatusTable()
|
|
{
|
|
ui->mCANModuleStatusTableWdgt->clearContents();
|
|
ui->mCANModuleStatusTableWdgt->setRowCount(0);
|
|
return RET_OK;
|
|
}
|
|
|
|
int CGeneralStatusPage::UpdateCANModuleStatus(QString ModuleName, QString ModuleStatus, QString Buffer)
|
|
{
|
|
QList<QTableWidgetItem *> Items = ui->mCANModuleStatusTableWdgt->findItems(ModuleName,Qt::MatchFixedString);
|
|
|
|
if(Items.isEmpty())
|
|
{
|
|
//first update, we add the item to the table
|
|
QTableWidgetItem *NewItem;
|
|
int row = ui->mCANModuleStatusTableWdgt->rowCount();
|
|
ui->mCANModuleStatusTableWdgt->setRowCount(row + 1);
|
|
|
|
NewItem = new QTableWidgetItem(ModuleName);
|
|
ui->mCANModuleStatusTableWdgt->setItem(row,0,NewItem);
|
|
|
|
NewItem = new QTableWidgetItem(ModuleStatus);
|
|
ui->mCANModuleStatusTableWdgt->setItem(row,1,NewItem);
|
|
|
|
if(Buffer == "NOUPDATE")
|
|
Buffer = "?";
|
|
NewItem = new QTableWidgetItem(Buffer);
|
|
ui->mCANModuleStatusTableWdgt->setItem(row,2,NewItem);
|
|
}
|
|
else if(Items.size() == 1)
|
|
{
|
|
int row = ui->mCANModuleStatusTableWdgt->row(Items.at(0));
|
|
|
|
if(ModuleStatus != "NOUPDATE")
|
|
{
|
|
ui->mCANModuleStatusTableWdgt->item(row,1)->setText(ModuleStatus);
|
|
}
|
|
if(Buffer != "NOUPDATE")
|
|
{
|
|
ui->mCANModuleStatusTableWdgt->item(row,2)->setText(Buffer);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
qDebug("Two CAN modules with same name in the Modules Status Table");
|
|
}
|
|
|
|
return RET_OK;
|
|
}
|
|
|
|
void CGeneralStatusPage::QuitAppBtnPressed()
|
|
{
|
|
mProgramPtr->QuitApplicationRequest();
|
|
}
|