operationtimeparts.cpp 2.88 KB
#include <qdebug.h>
#include "operationtimeparts.h"
#include "ui_operationtimeparts.h"
#include "ovenstatics.h"

operationTimeParts::operationTimeParts(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::operationTimeParts)
{
    int i=0;
    OvenStatics* ovs = OvenStatics::getInstance();
    ui->setupUi(this);

    m_arrTimeLabels[0] = ui->m_ctrlLbListTime_1;
    m_arrTimeLabels[1] = ui->m_ctrlLbListTime_2;
    m_arrTimeLabels[2] = ui->m_ctrlLbListTime_3;
    m_arrTimeLabels[3] = ui->m_ctrlLbListTime_4;
    m_arrTimeLabels[4] = ui->m_ctrlLbListTime_5;
    m_arrTimeLabels[5] = ui->m_ctrlLbListTime_6;
    m_arrTimeLabels[6] = ui->m_ctrlLbListTime_7;
    m_arrTimeLabels[7] = ui->m_ctrlLbListTime_8;
    m_arrTimeLabels[8] = ui->m_ctrlLbListTime_9;
    m_arrTimeLabels[9] = ui->m_ctrlLbListTime_10;
    m_arrTimeLabels[10] = ui->m_ctrlLbListTime_11;

    m_arrResetBtn[0] = ui->btnReset_1;
    m_arrResetBtn[1] = ui->btnReset_2;
    m_arrResetBtn[2] = ui->btnReset_3;
    m_arrResetBtn[3] = ui->btnReset_4;
    m_arrResetBtn[4] = ui->btnReset_5;
    m_arrResetBtn[5] = ui->btnReset_6;
    m_arrResetBtn[6] = ui->btnReset_7;
    m_arrResetBtn[7] = ui->btnReset_8;
    m_arrResetBtn[8] = ui->btnReset_9;
    m_arrResetBtn[9] = ui->btnReset_10;
    m_arrResetBtn[10] = ui->btnReset_11;


    m_btnGrops = new QButtonGroup();

    for(i=0;i<OPERATION_TIME_CONTROL_MAX;i++){
        m_btnGrops->addButton(m_arrResetBtn[i],i);
    }

    connect(m_btnGrops,SIGNAL(buttonClicked(int)),this,SLOT(on_btnResets_clicked(int)));

    if(ovs != NULL){
        for( i =0;i<OPERATION_TIME_PARTS_MAX_ITEM;i++){
            if(m_arrPartItemIdxs[i] != 0xffff){
                m_arrUseItems[i] = &(ovs->srvdatas->use_log.values[m_arrPartItemIdxs[i]]);
            }
            else m_arrUseItems[i] = NULL;
        }
    }
    reloadUi();
}

operationTimeParts::~operationTimeParts()
{
    delete ui;
}

void operationTimeParts::on_backButton_clicked()
{
    deleteLater();
}

void operationTimeParts::reloadUi(void){
    uint32_t timetemp;
    OvenStatics* ovs = OvenStatics::getInstance();
    QString strTemp="";
    int i = 0;

    if(ovs != NULL){
        for(i = 0; i<OPERATION_TIME_PARTS_MAX_ITEM;i++){
            if(m_arrUseItems[i] != NULL){
                timetemp = *m_arrUseItems[i];
                strTemp.sprintf("%d min", timetemp/60);
                m_arrTimeLabels[i]->setText(strTemp);
            }
            else{
                m_arrTimeLabels[i]->setText("-");
            }
        }
    }
    else{
        for(i=0;i<OPERATION_TIME_PARTS_MAX_ITEM;i++){
            m_arrTimeLabels[i]->setText("-");
        }
    }
}

void operationTimeParts::on_btnReset_2_clicked()
{

}

void operationTimeParts::on_btnResets_clicked(int idx){
    qDebug() << "PUSH BUTTON " << idx;
    if(idx < OPERATION_TIME_CONTROL_MAX){
        if(m_arrUseItems[idx] !=NULL){
            *m_arrUseItems[idx]=0;
            reloadUi();
        }
    }

}