//In Mainwindow
{
ui->setupUi(this);
Api *api = new Api(this);
Class1 *one = new Class1(this);
Class2 *two = new Class2(this);
Class3 *three = new Class3(this);
connect(timer, SIGNAL(timeout()), this, SLOT(findUpdate()));
timer->start(1000);
}
void MainWindow::findUpdate()
{
for(int i = 0; i < listone.size(); i++)
{
one->update(i);
}
for(int i = 0; i < listtwo.size(); i++)
{
two->update(i);
}
for(int i = 0; i < listthree.size(); i++)
{
three->update(i);
}
}
//In ClassOne
void ClassOne::update()
{
if(updatePlotFinished==0)
{
updatePlot();
updatePlotFinished = 1;
}
if(updateLEDFinished==0)
{
updateLED();
updateLEDFinished = 1;
}
}
void ClassOne::updatePlot()
{
api->getDataplotOne(url);
connect(api,&Api::getDataPlotReplyOne,this,&ClassOne::updatePlotValue);
}
void ClassOne::updateLED()
{
api->getDataLEDOne(url);
connect(api,&Api::getDataLEDOneReply,this,&ClassOne::updateLEDValue);
}
void ClassOne::updatePlotValue(QJsonObject obj)
{
updatePlotFinished = 0;
//updating plot
}
void ClassOne::updateLEDValue(QJsonObject obj)
{
updateLEDFinished = 0;
//Updating LED status
}
//In ClassTwo
void ClassTwo::update()
{
if(updatePlotFinished==0)
{
updatePlot();
updatePlotFinished = 1;
}
if(updateLEDFinished==0)
{
updateLED();
updateLEDFinished = 1;
}
}
void ClassTwo::updatePlot()
{
api->getDataplotTwo(url);
connect(api,&Api::getDataPlotTwoReply,this,&ClassTwo::updatePlotValue);
}
void ClassTwo::updateLED()
{
api->getDataLEDTwo(url);
connect(api,&Api::getDataLEDTwoReply,this,&ClassTwo::updateLEDValue);
}
void ClassTwo::updatePlotValue(QJsonObject obj)
{
updatePlotFinished = 0;
//updating plot
}
void ClassTwo::updateLEDValue(QJsonObject obj)
{
updateLEDFinished = 0;
//Updating LED status
}
// In ClassThree
void ClassThree::update()
{
if(updatePlotFinished==0)
{
updatePlot();
updatePlotFinished = 1;
}
if(updateLEDFinished==0)
{
updateLED();
updateLEDFinished = 1;
}
}
void ClassThree::updatePlot()
{
api->getDataplotThree(url);
connect(api,&Api::getDataPlotThreeReply,this,&ClassThree::updatePlotValue);
}
void ClassThree::updateLED()
{
api->getDataLEDThree(url);
connect(api,&Api::getDataLEDThreeReply,this,&ClassThree::updateLEDValue);
}
void ClassTwo::updatePlotValue(QJsonObject obj)
{
updatePlotFinished = 0;
//updating plot
}
void ClassTwo::updateLEDValue(QJsonObject obj)
{
updateLEDFinished = 0;
//Updating LED status
}
// In Api Class
void Api
::getDataPlotOne(QString url
) {
QNetworkRequest request
(QUrl(url
));
QNetworkReply *reply = manager.get(request);
connect(reply,SIGNAL(finished()),this,SLOT(replydata1plot));
}
void Api::replyData1plot()
{
QNetworkReply
*reply
= qobject_cast<QNetworkReply
*>
(QObject::sender());
if(reply)
{
QJsonDocument json = QJsonDocument::fromJson(response.toUtf8());
list = json.object();
delete reply;
}
else
{
qDebug() << "Failure" << reply->errorString();
delete reply;
}
emit getDataPlotReplyOne(list);
}
void Api
::getDataLEDTwo(QString url
) {
QNetworkRequest request
(QUrl(url
));
QNetworkReply *reply = manager.get(request);
connect(reply,SIGNAL(finished()),this,SLOT(replydata2led));
}
void Api::replyData1led()
{
QNetworkReply
*reply
= qobject_cast<QNetworkReply
*>
(QObject::sender());
if(reply)
{
QJsonDocument json = QJsonDocument::fromJson(response.toUtf8());
list = json.object();
delete reply;
}
else
{
qDebug() << "Failure" << reply->errorString();
delete reply;
}
emit getDataLEDReplyTwo(list);
}
void Api::replyData2plot()
{
QNetworkReply
*reply
= qobject_cast<QNetworkReply
*>
(QObject::sender());
if(reply)
{
QJsonDocument json = QJsonDocument::fromJson(response.toUtf8());
list = json.object();
delete reply;
}
else
{
qDebug() << "Failure" << reply->errorString();
delete reply;
}
emit getDataPlotReplyTwo(list);
}
void Api
::getDataLEDTwo(QString url
) {
QNetworkRequest request
(QUrl(url
));
QNetworkReply *reply = manager.get(request);
connect(reply,SIGNAL(finished()),this,SLOT(replydata2led));
}
void Api::replyData2led()
{
QNetworkReply
*reply
= qobject_cast<QNetworkReply
*>
(QObject::sender());
if(reply)
{
QJsonDocument json = QJsonDocument::fromJson(response.toUtf8());
list = json.object();
delete reply;
}
else
{
qDebug() << "Failure" << reply->errorString();
delete reply;
}
emit getDataLEDReplyTwo(list);
}