#include "instrumentcoefficientform.h"
#include "ui_instrumentcoefficientform.h"
#include "confighandler.h"

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

    setWindowTitle("仪器系数");

    ui->LineEditCoefficient->setText(
                QString::number(
                    ConfigHandler::_configMap[ConfigHandler::ConInstrumentCoefficientStr].toFloat(),
                    'f',3));

    ui->LineEditTheory->text().clear();
    ui->LineEditActualMeasurement->text().clear();
}

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

void InstrumentCoefficientForm::on_pushButtonCalculate_clicked()
{
    float theory = ui->LineEditTheory->text().toFloat();
    float measure = ui->LineEditActualMeasurement->text().toFloat();

    float instrumentCoefficient = theory/measure;
    ConfigHandler::_configMap[ConfigHandler::ConInstrumentCoefficientStr] = instrumentCoefficient;
    ConfigHandler::writer();

    ui->LineEditCoefficient->setText(QString::number(instrumentCoefficient,'f',3));
}

void InstrumentCoefficientForm::on_pushButtonCancel_clicked()
{
    hide();
}
