UnionComDLL/macrossetting.cpp

454 lines
17 KiB
C++

#include "macrossetting.h"
#include "ui_macrossetting.h"
MacrosSetting::MacrosSetting(QWidget *parent) :
QDialog(parent),
ui(new Ui::MacrosSetting)
{
ui->setupUi(this);
Init();
}
MacrosSetting::~MacrosSetting()
{
delete ui;
}
void MacrosSetting::Init()
{
//EID
{
MacrosSettingKit[0].EID = ui->checkEID_01;
MacrosSettingKit[1].EID = ui->checkEID_02;
MacrosSettingKit[2].EID = ui->checkEID_03;
MacrosSettingKit[3].EID = ui->checkEID_04;
MacrosSettingKit[4].EID = ui->checkEID_05;
MacrosSettingKit[5].EID = ui->checkEID_06;
MacrosSettingKit[6].EID = ui->checkEID_07;
MacrosSettingKit[7].EID = ui->checkEID_08;
MacrosSettingKit[8].EID = ui->checkEID_09;
MacrosSettingKit[9].EID = ui->checkEID_10;
MacrosSettingKit[10].EID = ui->checkEID_11;
MacrosSettingKit[11].EID = ui->checkEID_12;
MacrosSettingKit[12].EID = ui->checkEID_13;
MacrosSettingKit[13].EID = ui->checkEID_14;
MacrosSettingKit[14].EID = ui->checkEID_15;
}
//ID
{
MacrosSettingKit[0].ID = ui->lineID_01;
MacrosSettingKit[1].ID = ui->lineID_02;
MacrosSettingKit[2].ID = ui->lineID_03;
MacrosSettingKit[3].ID = ui->lineID_04;
MacrosSettingKit[4].ID = ui->lineID_05;
MacrosSettingKit[5].ID = ui->lineID_06;
MacrosSettingKit[6].ID = ui->lineID_07;
MacrosSettingKit[7].ID = ui->lineID_08;
MacrosSettingKit[8].ID = ui->lineID_09;
MacrosSettingKit[9].ID = ui->lineID_10;
MacrosSettingKit[10].ID = ui->lineID_11;
MacrosSettingKit[11].ID = ui->lineID_12;
MacrosSettingKit[12].ID = ui->lineID_13;
MacrosSettingKit[13].ID = ui->lineID_14;
MacrosSettingKit[14].ID = ui->lineID_15;
}
//IsHEX
{
MacrosSettingKit[0].IsHEX = ui->checkHEX_01;
MacrosSettingKit[1].IsHEX = ui->checkHEX_02;
MacrosSettingKit[2].IsHEX = ui->checkHEX_03;
MacrosSettingKit[3].IsHEX = ui->checkHEX_04;
MacrosSettingKit[4].IsHEX = ui->checkHEX_05;
MacrosSettingKit[5].IsHEX = ui->checkHEX_06;
MacrosSettingKit[6].IsHEX = ui->checkHEX_07;
MacrosSettingKit[7].IsHEX = ui->checkHEX_08;
MacrosSettingKit[8].IsHEX = ui->checkHEX_09;
MacrosSettingKit[9].IsHEX = ui->checkHEX_10;
MacrosSettingKit[10].IsHEX = ui->checkHEX_11;
MacrosSettingKit[11].IsHEX = ui->checkHEX_12;
MacrosSettingKit[12].IsHEX = ui->checkHEX_13;
MacrosSettingKit[13].IsHEX = ui->checkHEX_14;
MacrosSettingKit[14].IsHEX = ui->checkHEX_15;
}
//Name
{
MacrosSettingKit[0].Name = ui->lineMcrsName_01;
MacrosSettingKit[1].Name = ui->lineMcrsName_02;
MacrosSettingKit[2].Name = ui->lineMcrsName_03;
MacrosSettingKit[3].Name = ui->lineMcrsName_04;
MacrosSettingKit[4].Name = ui->lineMcrsName_05;
MacrosSettingKit[5].Name = ui->lineMcrsName_06;
MacrosSettingKit[6].Name = ui->lineMcrsName_07;
MacrosSettingKit[7].Name = ui->lineMcrsName_08;
MacrosSettingKit[8].Name = ui->lineMcrsName_09;
MacrosSettingKit[9].Name = ui->lineMcrsName_10;
MacrosSettingKit[10].Name = ui->lineMcrsName_11;
MacrosSettingKit[11].Name = ui->lineMcrsName_12;
MacrosSettingKit[12].Name = ui->lineMcrsName_13;
MacrosSettingKit[13].Name = ui->lineMcrsName_14;
MacrosSettingKit[14].Name = ui->lineMcrsName_15;
}
//Mcrs
{
MacrosSettingKit[0].Mcrs = ui->lineMcrs_01;
MacrosSettingKit[1].Mcrs = ui->lineMcrs_02;
MacrosSettingKit[2].Mcrs = ui->lineMcrs_03;
MacrosSettingKit[3].Mcrs = ui->lineMcrs_04;
MacrosSettingKit[4].Mcrs = ui->lineMcrs_05;
MacrosSettingKit[5].Mcrs = ui->lineMcrs_06;
MacrosSettingKit[6].Mcrs = ui->lineMcrs_07;
MacrosSettingKit[7].Mcrs = ui->lineMcrs_08;
MacrosSettingKit[8].Mcrs = ui->lineMcrs_09;
MacrosSettingKit[9].Mcrs = ui->lineMcrs_10;
MacrosSettingKit[10].Mcrs = ui->lineMcrs_11;
MacrosSettingKit[11].Mcrs = ui->lineMcrs_12;
MacrosSettingKit[12].Mcrs = ui->lineMcrs_13;
MacrosSettingKit[13].Mcrs = ui->lineMcrs_14;
MacrosSettingKit[14].Mcrs = ui->lineMcrs_15;
}
//Count
{
MacrosSettingKit[0].Count = ui->spinCount_01;
MacrosSettingKit[1].Count = ui->spinCount_02;
MacrosSettingKit[2].Count = ui->spinCount_03;
MacrosSettingKit[3].Count = ui->spinCount_04;
MacrosSettingKit[4].Count = ui->spinCount_05;
MacrosSettingKit[5].Count = ui->spinCount_06;
MacrosSettingKit[6].Count = ui->spinCount_07;
MacrosSettingKit[7].Count = ui->spinCount_08;
MacrosSettingKit[8].Count = ui->spinCount_09;
MacrosSettingKit[9].Count = ui->spinCount_10;
MacrosSettingKit[10].Count = ui->spinCount_11;
MacrosSettingKit[11].Count = ui->spinCount_12;
MacrosSettingKit[12].Count = ui->spinCount_13;
MacrosSettingKit[13].Count = ui->spinCount_14;
MacrosSettingKit[14].Count = ui->spinCount_15;
}
//IsPeriod
{
MacrosSettingKit[0].IsPeriod = ui->checkPeriod_01;
MacrosSettingKit[1].IsPeriod = ui->checkPeriod_02;
MacrosSettingKit[2].IsPeriod = ui->checkPeriod_03;
MacrosSettingKit[3].IsPeriod = ui->checkPeriod_04;
MacrosSettingKit[4].IsPeriod = ui->checkPeriod_05;
MacrosSettingKit[5].IsPeriod = ui->checkPeriod_06;
MacrosSettingKit[6].IsPeriod = ui->checkPeriod_07;
MacrosSettingKit[7].IsPeriod = ui->checkPeriod_08;
MacrosSettingKit[8].IsPeriod = ui->checkPeriod_09;
MacrosSettingKit[9].IsPeriod = ui->checkPeriod_10;
MacrosSettingKit[10].IsPeriod = ui->checkPeriod_11;
MacrosSettingKit[11].IsPeriod = ui->checkPeriod_12;
MacrosSettingKit[12].IsPeriod = ui->checkPeriod_13;
MacrosSettingKit[13].IsPeriod = ui->checkPeriod_14;
MacrosSettingKit[14].IsPeriod = ui->checkPeriod_15;
}
//Period
{
MacrosSettingKit[0].Period = ui->spinPeriod_01;
MacrosSettingKit[1].Period = ui->spinPeriod_02;
MacrosSettingKit[2].Period = ui->spinPeriod_03;
MacrosSettingKit[3].Period = ui->spinPeriod_04;
MacrosSettingKit[4].Period = ui->spinPeriod_05;
MacrosSettingKit[5].Period = ui->spinPeriod_06;
MacrosSettingKit[6].Period = ui->spinPeriod_07;
MacrosSettingKit[7].Period = ui->spinPeriod_08;
MacrosSettingKit[8].Period = ui->spinPeriod_09;
MacrosSettingKit[9].Period = ui->spinPeriod_10;
MacrosSettingKit[10].Period = ui->spinPeriod_11;
MacrosSettingKit[11].Period = ui->spinPeriod_12;
MacrosSettingKit[12].Period = ui->spinPeriod_13;
MacrosSettingKit[13].Period = ui->spinPeriod_14;
MacrosSettingKit[14].Period = ui->spinPeriod_15;
}
//RTR
{
MacrosSettingKit[0].RTR = ui->checkRTR_01;
MacrosSettingKit[1].RTR = ui->checkRTR_02;
MacrosSettingKit[2].RTR = ui->checkRTR_03;
MacrosSettingKit[3].RTR = ui->checkRTR_04;
MacrosSettingKit[4].RTR = ui->checkRTR_05;
MacrosSettingKit[5].RTR = ui->checkRTR_06;
MacrosSettingKit[6].RTR = ui->checkRTR_07;
MacrosSettingKit[7].RTR = ui->checkRTR_08;
MacrosSettingKit[8].RTR = ui->checkRTR_09;
MacrosSettingKit[9].RTR = ui->checkRTR_10;
MacrosSettingKit[10].RTR = ui->checkRTR_11;
MacrosSettingKit[11].RTR = ui->checkRTR_12;
MacrosSettingKit[12].RTR = ui->checkRTR_13;
MacrosSettingKit[13].RTR = ui->checkRTR_14;
MacrosSettingKit[14].RTR = ui->checkRTR_15;
}
//DLC
{
MacrosSettingKit[0].DLC = ui->comboDLC_01;
MacrosSettingKit[1].DLC = ui->comboDLC_02;
MacrosSettingKit[2].DLC = ui->comboDLC_03;
MacrosSettingKit[3].DLC = ui->comboDLC_04;
MacrosSettingKit[4].DLC = ui->comboDLC_05;
MacrosSettingKit[5].DLC = ui->comboDLC_06;
MacrosSettingKit[6].DLC = ui->comboDLC_07;
MacrosSettingKit[7].DLC = ui->comboDLC_08;
MacrosSettingKit[8].DLC = ui->comboDLC_09;
MacrosSettingKit[9].DLC = ui->comboDLC_10;
MacrosSettingKit[10].DLC = ui->comboDLC_11;
MacrosSettingKit[11].DLC = ui->comboDLC_12;
MacrosSettingKit[12].DLC = ui->comboDLC_13;
MacrosSettingKit[13].DLC = ui->comboDLC_14;
MacrosSettingKit[14].DLC = ui->comboDLC_15;
}
for(int i = 0; i < 15; i++)
{
MacrosSettingKit[i].Period->setEnabled(false);
MacrosSettingKit[i].DLC->setEnabled(false);
EnterErrors.ID[i] = EnterErrors.Mcrs[i] = 0;
}
}
void MacrosSetting::GetMcrs()
{
// for (int i = 0; i < 15; i++)
// {
// MacrosKit[i].IsHEX = MacrosSettingKit[i].IsHEX->checkState();
// MacrosKit[i].Name = MacrosSettingKit[i].Name->text();
// MacrosKit[i].Mcrs = MacrosSettingKit[i].Mcrs->text();
// }
// IsOK = TRUE;
}
void MacrosSetting::SetStart(Qt::CheckState *ptrEID, DWORD *ptrID, Qt::CheckState *ptrRTR,
Qt::CheckState *ptrHEX, int *ptrDLC, QString *ptrName, QString *ptrMcrs,
int *ptrCount, Qt::CheckState *ptrIsPeriod, int *ptrPeriod)
{
McrsReturn.EID = ptrEID;
McrsReturn.ID = ptrID;
McrsReturn.RTR = ptrRTR;
McrsReturn.IsHEX = ptrHEX;
McrsReturn.DLC = ptrDLC;
McrsReturn.Name = ptrName;
McrsReturn.Mcrs = ptrMcrs;
McrsReturn.Count = ptrCount;
McrsReturn.IsPeriod = ptrIsPeriod;
McrsReturn.Period = ptrPeriod;
for(int i = 0; i < 15; i++)
{
MacrosSettingKit[i].EID->setCheckState(ptrEID[i]);
if(ptrEID[i]==Qt::Checked)
{
MacrosSettingKit[i].ID->setText(QStringLiteral("%1").arg(ptrID[i], 8, 16, QLatin1Char('0')).toUpper());
}
else
{
MacrosSettingKit[i].ID->setText(QStringLiteral("%1").arg(ptrID[i], 3, 16, QLatin1Char('0')).toUpper());
}
MacrosSettingKit[i].RTR->setCheckState(ptrRTR[i]);
MacrosSettingKit[i].IsHEX->setCheckState(ptrHEX[i]);
MacrosSettingKit[i].DLC->setCurrentIndex(ptrDLC[i]);
comboDLC_stateChanged(i+1);
MacrosSettingKit[i].Name->setText(ptrName[i]);
MacrosSettingKit[i].Mcrs->setText(ptrMcrs[i]);
MacrosSettingKit[i].Count->setValue(ptrCount[i]);
MacrosSettingKit[i].IsPeriod->setCheckState(ptrIsPeriod[i]);
MacrosSettingKit[i].Period->setValue(ptrPeriod[i]);
}
}
void MacrosSetting::on_buttonBox_accepted()
{
for (int i = 0; i < 15; i++)
{
McrsReturn.EID[i] = MacrosSettingKit[i].EID->checkState();
McrsReturn.ID[i] = MacrosSettingKit[i].ID->text().toInt(nullptr, 16);
McrsReturn.RTR[i] = MacrosSettingKit[i].RTR->checkState();
McrsReturn.IsHEX[i] = MacrosSettingKit[i].IsHEX->checkState();
McrsReturn.DLC[i] = MacrosSettingKit[i].DLC->currentIndex();
McrsReturn.Name[i] = MacrosSettingKit[i].Name->text();
// if (!ValidationMcrs(i+1))
// {
// QDialog *McrsError = new QDialog;
// McrsError->setWindowTitle(QString("Ошибка заполнения"));
// McrsError->setMinimumSize(260, 70);
// McrsError->setMaximumSize(260, 70);
// QVBoxLayout *layoutCTX = new QVBoxLayout(McrsError);
// McrsError->setLayout(layoutCTX);
// QLabel *ErrorMSG = new QLabel;
// ErrorMSG->setText(QString("Некорректное значение поля макроса %1.").arg(MacrosSettingKit[i].Name->text()));
// layoutCTX->addWidget(ErrorMSG);
// QDialogButtonBox *yesOrNo = new QDialogButtonBox(McrsError);
// yesOrNo->addButton("Продолжить без HEX", QDialogButtonBox::AcceptRole);
// yesOrNo->addButton("Очистить макрос", QDialogButtonBox::RejectRole);
// layoutCTX->addWidget(yesOrNo);
// connect(yesOrNo, &QDialogButtonBox::accepted, McrsError, &QDialog::accept);
// connect(yesOrNo, &QDialogButtonBox::rejected, McrsError, &QDialog::reject);
// McrsError->exec();
// if(McrsError->result()==QDialog::Accepted)
// {
// MacrosSettingKit[i].IsHEX->setCheckState(Qt::Unchecked);
// McrsReturn.IsHEX[i] = Qt::Unchecked;
// McrsReturn.Mcrs[i] = MacrosSettingKit[i].Mcrs->text();
// }
// else
// {
// MacrosSettingKit[i].Mcrs->clear();
// McrsReturn.Mcrs[i] = MacrosSettingKit[i].Mcrs->text();
// }
// }
// else
// {
//
// }
McrsReturn.Mcrs[i] = MacrosSettingKit[i].Mcrs->text();
McrsReturn.Count[i] = MacrosSettingKit[i].Count->value();
McrsReturn.IsPeriod[i] = MacrosSettingKit[i].IsPeriod->checkState();
McrsReturn.Period[i] = MacrosSettingKit[i].Period->value();
}
IsOK = TRUE;
}
void MacrosSetting::on_buttonBox_rejected()
{
IsOK = FALSE;
}
void MacrosSetting::checkPeriod_stateChanged(int index, int arg1)
{
index--;
MacrosSettingKit[index].Period->setEnabled(arg1);
}
void MacrosSetting::ValidationID(unsigned int numID)
{
numID--;
QString buffer = QString::number(MacrosSettingKit[numID].ID->text().toUInt(nullptr, 16), 10);
int pos = 0;
unsigned long long maxRange;
if(MacrosSettingKit[numID].EID->checkState()==Qt::Checked)
{
maxRange = 0x1FFFFFFF;
}
else
{
maxRange = 0x7FF;
}
if((unsigned long long)buffer.toUInt(nullptr, 10) > (unsigned long long) maxRange)
{
MacrosSettingKit[numID].ID->setStyleSheet("border: 1px solid red");
MacrosSettingKit[numID].ID->setToolTip(QString("Valid ID: 0 - 0x%1").arg(QString::number(maxRange, 16).toUpper()));
EnterErrors.ID[numID] = true;
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
}
else
{
MacrosSettingKit[numID].ID->setStyleSheet("");
MacrosSettingKit[numID].ID->setToolTip(QString());
EnterErrors.ID[numID] = false;
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(checkErrors());
}
}
bool MacrosSetting::ValidationMcrs(unsigned int numID)
{
numID--;
if(MacrosSettingKit[numID].IsHEX->checkState()==Qt::Checked)
{
QString buffer = MacrosSettingKit[numID].Mcrs->text();
for(int i = 0; i < buffer.size(); i++)
{
if(buffer.at(i) < '0' || (buffer.at(i) > '9' && buffer.at(i) < 'A') || (buffer.at(i) > 'F' && buffer.at(i) < 'a') || buffer.at(i) > 'f')
{
MacrosSettingKit[numID].Mcrs->setStyleSheet("border: 1px solid red");
MacrosSettingKit[numID].Mcrs->setToolTip(QString("Hexadecimal character required. A-F, 0-9."));
EnterErrors.Mcrs[numID] = true;
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
return false;
}
}
MacrosSettingKit[numID].Mcrs->setStyleSheet("");
MacrosSettingKit[numID].Mcrs->setToolTip(QString());
MacrosSettingKit[numID].Mcrs->setText(buffer.toUpper());
}
EnterErrors.Mcrs[numID] = false;
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(checkErrors());
return true;
}
void MacrosSetting::checkEID_stateChanged(int index)
{
index--;
if(MacrosSettingKit[index].EID->checkState()==Qt::Checked)
{
MacrosSettingKit[index].ID->setInputMask(">HHHHHHHH");
}
else
{
MacrosSettingKit[index].ID->setInputMask(">HHH");
}
}
void MacrosSetting::checkRTR_stateChanged(int index)
{
index--;
if(MacrosSettingKit[index].RTR->checkState()==Qt::Checked)
{
MacrosSettingKit[index].IsHEX->setEnabled(false);
MacrosSettingKit[index].Mcrs->setEnabled(false);
MacrosSettingKit[index].DLC->setEnabled(true);
}
else
{
MacrosSettingKit[index].IsHEX->setEnabled(true);
MacrosSettingKit[index].Mcrs->setEnabled(true);
if(MacrosSettingKit[index].IsHEX->checkState()!=Qt::Checked)
{
MacrosSettingKit[index].DLC->setEnabled(false);
}
}
}
void MacrosSetting::checkHEX_stateChanged(int index)
{
index--;
if(MacrosSettingKit[index].IsHEX->checkState()==Qt::Checked)
{
MacrosSettingKit[index].DLC->setEnabled(true);
comboDLC_stateChanged(index+1);
ValidationMcrs(index+1);
//MacrosSettingKit[index].Mcrs->setInputMask(">");
}
else
{
MacrosSettingKit[index].DLC->setEnabled(false);
MacrosSettingKit[index].Mcrs->setInputMask("");
MacrosSettingKit[index].Mcrs->setMaxLength(32767);
//MacrosSettingKit[index].Mcrs->setInputMask("");
}
}
void MacrosSetting::comboDLC_stateChanged(int index)
{
index--;
if(MacrosSettingKit[index].IsHEX->checkState()==Qt::Checked)
{
int currentDLC = MacrosSettingKit[index].DLC->currentIndex();
//QString buffer = ">";
// for (int i = 1; i < currentDLC; i++)
// {
// buffer += "HH";
// }
//MacrosSettingKit[index].Mcrs->setInputMask(buffer);
MacrosSettingKit[index].Mcrs->setMaxLength((MacrosSettingKit[index].DLC->currentIndex())*2);
}
}
bool MacrosSetting::checkErrors()
{
for(int i = 0; i < 15; i++)
{
if (EnterErrors.ID[i] || EnterErrors.Mcrs[i])
{
return false;
}
}
return true;
}