#include "CalibrationMainForm.h"
#include "ui_CalibrationMainForm.h"

CalibrationMainForm::CalibrationMainForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::CalibrationMainForm)
{
    ui->setupUi(this);

    initFormWidgets();
    bindSignalAndHandlers();
}

CalibrationMainForm::~CalibrationMainForm()
{
    qDebug() << "~CalibrationMainForm";
    delete ui;
}

QMap<QString, TaskDTO> & CalibrationMainForm::getSelectedTask()
{
    return selectedTask;
}
QStringList CalibrationMainForm::getVerificationItemCatIds()
{
    return verificationItemCatIds;
}
void CalibrationMainForm::setVerificationItemCatIds(QStringList itemCatIds)
{
    verificationItemCatIds = itemCatIds;
}

void CalibrationMainForm::showEvent(QShowEvent * event)
{
    selectedTask.clear();
    verificationItemCatIds.clear();

    ui->wdgtCalMain->setCurrentIndex(0);
}

void CalibrationMainForm::initFormWidgets()
{
    wdgtTask = new TaskListWidget(this);
    wdgtConf = new ConfigurationWidget(this);
//    wdgtStandardList = new StandardListWidget(this);
//    wdgtConnectState = new ConnectStateWidget(this);

    ui->wdgtCalMain->addWidget(wdgtTask);
    ui->wdgtCalMain->addWidget(wdgtConf);
//    ui->wdgtContent->addWidget(wdgtStandardList);
//    ui->wdgtContent->addWidget(wdgtConnectState);

    ui->wdgtCalMain->setCurrentIndex(0);
}

void CalibrationMainForm::bindSignalAndHandlers()
{
    // 待检设备清单 下一步 切换到 配置检定项和流程
    connect(wdgtTask, &TaskListWidget::taskEquipmentSelected, this, &CalibrationMainForm::nextToConfiguration);

    // 检定程序 上一步 下一步
//    connect(wdgtCheckProgram, &CheckProgramWidget::switchToReSelectTaskEquipment, this, &CalibrationForm::forwardToReSelectTaskEquipment);
//    connect(wdgtCheckProgram, &CheckProgramWidget::switchToNextWidget, this, &CalibrationForm::nextToSelectStandardEquipment);

    // 标准设备 上一步 下一步
//    connect(wdgtStandardList, &StandardListWidget::switchToReSelectCheckProgram, this, &CalibrationForm::forwardToReSelectCheckProgram);
//    connect(wdgtStandardList, &StandardListWidget::switchToNextWidget, this, &CalibrationForm::nextToConnectionState);

    // 查看连接状态
//    connect(wdgtConnectState, &ConnectStateWidget::switchToReSelectStandardEqpt, this, &CalibrationForm::forwardToReSelectTaskEquipment);
//    connect(wdgtConnectState, &ConnectStateWidget::startAutoCalibration, this, &CalibrationForm::nextToAutoCalibration);
}

void CalibrationMainForm::nextToConfiguration()
{
    ui->wdgtCalMain->setCurrentWidget(wdgtConf);
}
