#include "parametersetdialog.h"
#include "ui_parametersetdialog.h"

ParameterSetDialog::ParameterSetDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ParameterSetDialog),
    m_itemPerPage(12)
{
    ui->setupUi(this);
    setWindowFlags (Qt::Window | Qt::FramelessWindowHint);
    setWindowModality(Qt::ApplicationModal);

    this->move(0+g_mainWidgetPos.x(),0+g_mainWidgetPos.y());
    m_setedFlag = 0;
    m_hcpsFlag = 0;
    m_curPage = 0;
    m_rootCurPage = 0;

    //获取网卡ID
    m_networkCardID.clear();
    QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
    if(interfaces.size() == 1)
    {
        QNetworkInterface item = interfaces.at(0);
        m_networkCardID = item.hardwareAddress();
    }
    else
    {
        int nCnt = interfaces.count();
        for(int i = 0; i < nCnt; i++)
        {
            //QNetworkInterface item = interfaces.at(i);
            //m_networkCardID = item.hardwareAddress();

            // 如果此网络接口被激活并且正在运行并且不是回环地址，则就是我们需要找的Mac地址
            if(interfaces[i].flags().testFlag(QNetworkInterface::IsUp) &&
                    interfaces[i].flags().testFlag(QNetworkInterface::IsRunning) &&
                    !interfaces[i].flags().testFlag(QNetworkInterface::IsLoopBack))
            {
                m_networkCardID = interfaces[i].hardwareAddress();
                qDebug()<<m_networkCardID;
                break;
            }
        }
    }

    initData();
    initControl();
    initArabControlPos();
    refreshUi();
}

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

//初始化窗体控件，包括位置、尺寸、样式
void ParameterSetDialog::initControl()
{
    m_itemBtnList.clear();
    m_itemBtnList.append(ui->button1);
    m_itemBtnList.append(ui->button2);
    m_itemBtnList.append(ui->button3);
    m_itemBtnList.append(ui->button4);
    m_itemBtnList.append(ui->button5);
    ui->button6->setVisible(false);//隐藏
    ui->button7->setVisible(false);
    ui->button8->setVisible(false);
    ui->button9->setVisible(false);
    ui->button10->setVisible(false);
    ui->button11->setVisible(false);
    ui->button12->setVisible(false);

    if(g_emResolut == resolution1910)//1920x1080的分辨率每页显示12个条目
    {
        ui->button6->setVisible(true);
        ui->button7->setVisible(true);
        ui->button8->setVisible(true);
        ui->button9->setVisible(true);
        ui->button10->setVisible(true);
        ui->button11->setVisible(true);
        ui->button12->setVisible(true);
        m_itemBtnList.append(ui->button6);
        m_itemBtnList.append(ui->button7);
        m_itemBtnList.append(ui->button8);
        m_itemBtnList.append(ui->button9);
        m_itemBtnList.append(ui->button10);
        m_itemBtnList.append(ui->button11);
        m_itemBtnList.append(ui->button12);
    }
    else if(g_emResolut == resolution1006)//1024x600的分辨率每页显示8个条目
    {
        ui->button6->setVisible(true);//显示
        ui->button7->setVisible(true);
        ui->button8->setVisible(true);
        m_itemBtnList.append(ui->button6);
        m_itemBtnList.append(ui->button7);
        m_itemBtnList.append(ui->button8);
    }

    //根据不同分辨率设置控件的位置和尺寸
    switch (g_emResolut)
    {
    case resolution1910:
        initResolution1910();
        break;
    case resolution1006:
        initResolution1006();
        break;
    default:
        this->resize(1920,1080);
        break;
    }

    initControlStyle();//初始化窗体控件样式
}

//初始化窗体控件为1920x1080分辨率
void ParameterSetDialog::initResolution1910()
{
    this->resize(1920,1080);
    ui->frameBack->setGeometry(0,0,1920,1080);
    ui->buttonTypeLogo->setGeometry(128,66,78,78);
    ui->labelMainTitle->setGeometry(226,60,1000,48);
    ui->labelSubTitle->setGeometry(302,112,1000,36);
    ui->labelRepetitions->setGeometry(702,112,1000,36);

    ui->frameRightUp->setGeometry(1468,92,406,72);
    ui->buttonPatchParaClear->setGeometry(340,0,66,66);
    ui->buttonPatchParaNeedle->setGeometry(252,0,66,66);
    ui->buttonPatchParaColor->setGeometry(164,0,66,66);

    ui->buttonHeadParaImport->setGeometry(76,0,66,66);
    ui->buttonHeadParaExport->setGeometry(164,0,66,66);
    ui->buttonEXBParaRestore->setGeometry(252,0,66,66);
    ui->buttonReturn->setGeometry(340,0,66,66);

    QRect rectName(40,0,925,58);
    QRect rectValue(1040,0,272,58);
    for(int i = 0; i < m_itemPerPage; i++)
    {
        m_itemBtnList[i]->setGeometry(295,180 + i * 64,1340,58);
        m_itemBtnList[i]->initLeftNameRightValue(rectName,rectValue,1);
    }

    ui->framePageBtn->setGeometry(1120,990,800,70);
    ui->labelPage->setGeometry(32,1008,400,40);
    ui->buttonPgUp->setGeometry(0,0,168,70);
    ui->buttonPgDn->setGeometry(200,0,168,70);
    ui->buttonOk->setGeometry(400,0,168,70);
    ui->buttonCancel->setGeometry(600,0,168,70);
}

//初始化窗体控件为1024x600分辨率
void ParameterSetDialog::initResolution1006()
{
    m_itemPerPage = m_itemPerPage - 4;
    this->resize(1024,600);
    ui->frameBack->setGeometry(0,0,1024,600);
    ui->buttonTypeLogo->setGeometry(25,30,60,60);
    ui->labelMainTitle->setGeometry(100,30,200,24);
    ui->labelSubTitle->setGeometry(130,64,240,21);
    ui->labelRepetitions->setGeometry(330,64,340,21);

    ui->frameRightUp->setGeometry(746,40,800,61);
    ui->buttonPatchParaClear->setGeometry(150,0,50,50);
    ui->buttonPatchParaNeedle->setGeometry(93,0,50,50);
    ui->buttonPatchParaColor->setGeometry(37,0,50,50);

    ui->buttonHeadParaImport->setGeometry(22,0,50,50);
    ui->buttonHeadParaExport->setGeometry(86,0,50,50);
    ui->buttonEXBParaRestore->setGeometry(150,0,50,50);
    ui->buttonReturn->setGeometry(214,0,50,50);

    //内容的位置
    QRect rectName(40,-1,400,53);
    QRect rectValue(460,-1,220,53);
    for(int i = 0; i < m_itemPerPage; i++)//白色按下的效果
    {
        m_itemBtnList[i]->setGeometry(153,96 + i * 53,718,53);
        m_itemBtnList[i]->initLeftNameRightValue(rectName,rectValue,1);
    }

    ui->framePageBtn->setGeometry(595,545,600,45);
    ui->labelPage->setGeometry(20,550,135,45);
    ui->buttonPgUp->setGeometry(0,0,96,40);
    ui->buttonPgDn->setGeometry(106,0,96,40);
    ui->buttonOk->setGeometry(212,0,96,40);
    ui->buttonCancel->setGeometry(318,0,96,40);
}

//初始化窗体控件样式
void ParameterSetDialog::initControlStyle()
{
    SetControlStyle setControlStyle;
    setControlStyle.setUiName(this->objectName());

    //背景图
    QString frameBackImgPath = setControlStyle.getSharedStyleSheet();
    ui->frameBack->setStyleSheet(frameBackImgPath);

    ui->labelMainTitle->setFont(fontBold_1);
    ui->labelMainTitle->setStyleSheet(LABELWHITESTYLE);
    ui->labelSubTitle->setFont(fontNormal_1);
    ui->labelSubTitle->setStyleSheet(LABELWHITESTYLE);
    ui->labelPage->setFont(fontNormal_1);
    ui->labelPage->setStyleSheet(LABELWHITESTYLE);
    ui->labelRepetitions->setFont(fontNormal_1);
    ui->labelRepetitions->setStyleSheet(LABELWHITESTYLE);

    //右上方
    ui->frameRightUp->setStyleSheet(TRANSPARENTSTYLE);
    ui->buttonPatchParaClear->setGreenGradientBottomStyle(BORDER_RADIUS1);
    ui->buttonPatchParaClear->setTopImage(setControlStyle.getTopStyleSheet(ui->buttonPatchParaClear->objectName()));
    ui->buttonPatchParaColor->setGreenGradientBottomStyle(BORDER_RADIUS1);
    ui->buttonPatchParaColor->setTopImage(setControlStyle.getTopStyleSheet(ui->buttonPatchParaColor->objectName()));
    ui->buttonPatchParaNeedle->setGreenGradientBottomStyle(BORDER_RADIUS1);
    ui->buttonPatchParaNeedle->setTopImage(setControlStyle.getTopStyleSheet(ui->buttonPatchParaNeedle->objectName()));
    ui->buttonEXBParaRestore->setGreenGradientBottomStyle(BORDER_RADIUS1);
    ui->buttonEXBParaRestore->setTopImage(setControlStyle.getTopStyleSheet(ui->buttonEXBParaRestore->objectName()));
    ui->buttonReturn->setGreenGradientBottomStyle(BORDER_RADIUS1);
    ui->buttonReturn->setTopImage(setControlStyle.getTopStyleSheet(ui->buttonReturn->objectName()));
    ui->buttonHeadParaImport->setGreenGradientBottomStyle(BORDER_RADIUS1);
    ui->buttonHeadParaImport->setTopImage(setControlStyle.getTopStyleSheet(ui->buttonHeadParaImport->objectName()));
    ui->buttonHeadParaExport->setGreenGradientBottomStyle(BORDER_RADIUS1);
    ui->buttonHeadParaExport->setTopImage(setControlStyle.getTopStyleSheet(ui->buttonHeadParaExport->objectName()));

    //条目
    for(int i = 0; i < m_itemPerPage; i++)
    {
        m_itemBtnList[i]->setLabelFont(fontNormal_1);
    }

    //四个按钮样式表一样
    ui->buttonPgUp->setOrangeGradientBottomStyle(BORDER_RADIUS2);
    ui->buttonPgUp->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonPgUp->objectName()),12);

    ui->buttonPgDn->setOrangeGradientBottomStyle(BORDER_RADIUS2);
    ui->buttonPgDn->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonPgDn->objectName()),12);

    ui->buttonOk->setOrangeGradientBottomStyle(BORDER_RADIUS2);
    ui->buttonOk->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonOk->objectName()),12);

    ui->buttonCancel->setOrangeGradientBottomStyle(BORDER_RADIUS2);
    ui->buttonCancel->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonCancel->objectName()),12);
}

void ParameterSetDialog::refreshUi()
{
    ui->buttonOk->setVisible(true);//再进入界面时,刷新界面确认按钮就显示
    ui->labelRepetitions->setVisible(false);//先隐藏

    if(m_paraType == PARA_TYPE_REPEATEMBPARA)//反复绣界面显示反复绣次数显示
    {
        ui->labelRepetitions->setVisible(true);
    }

    if(m_paraType == PARA_TYPE_HMICONFIGURATION)//等于界面配置
    {
        refreshProductType();//刷新产品类型
    }

    if (m_itemList.size() <= 0)//参数列表
    {
        for (int i = 0; i < m_itemPerPage; i++)
        {
            m_itemBtnList.at(i)->hide();
        }
        ui->labelPage->setText("PageNum: 0/0");
        ui->buttonPgUp->setEnabled(false);
        ui->buttonPgDn->setEnabled(false);
        ui->buttonOk->setEnabled(false);
        ui->frameRightUp->setVisible(false);
        //贴布绣不显示第一个色序
        if(m_paraType == (PARA_TYPE_PATTERNPATCH_COLOR | PARA_TYPE_PATTERNPATCH_NEEDLE))
        {
            ui->frameRightUp->setVisible(true);
            ui->buttonPatchParaClear->setVisible(true);
            ui->buttonPatchParaColor->setVisible(true);
            ui->buttonPatchParaNeedle->setVisible(true);
        }

        return;//下边的代码不执行
    }

    if(m_itemPerPage <= 0)
    {
        return;
    }

    if(m_patchMode == PATCH_COLOR)
    {
        ui->buttonPatchParaColor->setCheckable(true);
        ui->buttonPatchParaColor->setChecked(true);
        ui->buttonPatchParaNeedle->setChecked(false);
        ui->buttonPatchParaNeedle->setCheckable(false);
    }
    else if(m_patchMode == PATCH_NEEDLE)
    {
        ui->buttonPatchParaNeedle->setCheckable(true);
        ui->buttonPatchParaNeedle->setChecked(true);
        ui->buttonPatchParaColor->setChecked(false);
        ui->buttonPatchParaColor->setCheckable(false);
    }

    ui->buttonOk->setEnabled(true);
    QString split1 = ":";
    QString split2 = ";";
    QString str;

    //-----------
    int itemNum, pageNums;
    itemNum = m_itemList.size();//列表总个数
    pageNums = (itemNum+m_itemPerPage-1) / m_itemPerPage;//一共有的页数

    if(m_paraType == PARA_TYPE_ROOT)//等于超级用户界面
    {
        if (m_rootCurPage > pageNums)                 // 当前页
        {
            m_rootCurPage = pageNums;
        }
        if (m_rootCurPage <= 1)
        {
            m_rootCurPage = 1;
        }
    }
    else
    {
        if (m_curPage > pageNums)                 // 当前页
        {
            m_curPage = pageNums;
        }
        if (m_curPage <= 1)
        {
            m_curPage = 1;
        }
    }

    // 条目信息
    int i, itemidx;
    if(m_paraType == PARA_TYPE_ROOT)//等于超级用户界面
    {
        itemidx = (m_rootCurPage-1) * m_itemPerPage;
    }
    else
    {
        itemidx = (m_curPage-1) * m_itemPerPage;
    }


    for (i = 0; i < m_itemPerPage; i++)
    {
        if (itemidx < m_itemList.size())
        {
            ParaItem item = m_itemList.at(itemidx);

            if (item.readonly != 0) // 只读，不能设置
            {
                m_itemBtnList.at(i)->show();
                m_itemBtnList.at(i)->setEnabled(false);
                if(item.paraTypeSort == PARA_TYPE_MACH)//机器参数
                {
                    //读取平绣机头个数(遍历功能)
                    if(m_nodeType == FLATEMB)
                    {
                        m_itemList[i].value = m_mcParaValues.buf[2];//平绣机头个数
                        item.value = m_mcParaValues.buf[2];//平绣机头个数
                    }
                    else if(m_nodeType == TOWEL)
                    {
                        m_itemList[i].value = m_mcParaValues.buf[8];//毛巾机头个数
                        item.value = m_mcParaValues.buf[8];//毛巾机头个数
                    }
                    else if(m_nodeType == COIL)
                    {
                        m_itemList[i].value = m_mcParaValues.buf[7];//缠绕机头个数
                        item.value = m_mcParaValues.buf[7];//缠绕机头个数
                    }
                }
                int towel = g_pSettings->readFromInHMIiFile("HMI/towel").toInt();//是否有毛巾功能
                int coil = g_pSettings->readFromInHMIiFile("HMI/coil").toInt();//是否有缠绕功能
                if(towel == 1 || coil == 1)
                {
                    if(item.paraTypeSort == ROOT_SORT_CHENSENSOR)
                    {
                        int w = m_itemBtnList[i]->labelName->width()+m_itemBtnList[i]->labelValue->width();
                        int h = m_itemBtnList[i]->labelName->height();
                        //重新设置宽度，整行都显示遍历状态信号，无value
                        m_itemBtnList[i]->labelName->resize(w,h);
                    }
                }
                else
                {
                    if(item.paraTypeSort == ROOT_SORT_EMBSENSOR)//信号参数
                    {
                        int w = m_itemBtnList[i]->labelName->width()+m_itemBtnList[i]->labelValue->width();
                        int h = m_itemBtnList[i]->labelName->height();
                        //重新设置宽度，整行都显示遍历状态信号，无value
                        m_itemBtnList[i]->labelName->resize(w,h);
                    }
                }
            }
            else
            {
                //超级用户选择工作参数开关型后回到遍历设置会显示开关，以下代码隐藏开关
                if(item.valueType == PARA_VALUE_TYPE_CLICK)
                {
                    m_itemBtnList.at(i)->setLabelValueImage("");
                }
                m_itemBtnList.at(i)->show();
                m_itemBtnList.at(i)->setEnabled(true);
            }

            m_itemBtnList.at(i)->setLabelName(item.paraName);

            if (item.valueType == PARA_VALUE_TYPE_INT)    // = 1, 数字输入型
            {
                str = getValueStr(item.value, item.afterPoint);//显示的是默认参数
                str += " " + item.unitStr;
                //    qDebug()<< item.value << item.afterpoint << item.unitstr;
                m_itemBtnList.at(i)->setLabelValue(str);//设置参数显示的值，没连上就显示的默认参数
                m_itemBtnList.at(i)->show();
            }
            else if (item.valueType == PARA_VALUE_TYPE_SW)   // = 2, 开关选择型
            {
                SetControlStyle setControlStyle;
                setControlStyle.setUiName(this->objectName());

                QString path;
                path = setControlStyle.getBottomStyleSheet1("");

                if (item.value != 0)//打开
                {
                    path += "switchOn_logo.png";
                }
                else
                {
                    path += "switchOff_logo.png";
                }

                m_itemBtnList.at(i)->setLabelValueImage(path);
            }
            else if (item.valueType == PARA_VALUE_TYPE_LIST)   // = 3, 列表选择型
            {
                QStringList vallist;
                if(item.selList.indexOf(split1) == -1)//查找 ”: “在 列表里的位置
                {
                    // 没找到 二级分割
                    vallist = item.selList.split(split2, QString::SkipEmptyParts);
                    if (vallist.size() <= 0)
                    {
                        str = "";
                    }
                    else
                    {
                        int selIdx = item.selIdx;
                        if (selIdx < 0)
                        {
                            selIdx = 0;
                        }
                        if (selIdx >= vallist.size())
                        {
                            selIdx = vallist.size() - 1;
                        }
                        str = vallist.at(selIdx);
                    }
                }
                else
                {
                    // 二级分割
                    vallist = item.selList.split(split2, QString::SkipEmptyParts);
                    if (vallist.size() <= 0)
                    {
                        str = "";
                    }
                    else
                    {
                        int miniIndex = vallist.first().split(split1, QString::SkipEmptyParts).at(1).toInt();
                        int maxIndex = vallist.last().split(split1, QString::SkipEmptyParts).at(1).toInt();

                        //int selIdx = item.value;
                        int selIdx = item.selIdx;//默认值
                        if (selIdx < miniIndex)
                        {
                            selIdx = miniIndex;
                        }
                        if (selIdx >= maxIndex)
                        {
                            selIdx = maxIndex;
                        }
                        for (int var = 0; var < vallist.size(); ++var)
                        {
                            QStringList sublist = vallist.at(var).split(split1, QString::SkipEmptyParts);
                            if(sublist.at(1).toInt() == selIdx)//列表里的索引等于item里的默认值
                            {
                                str = sublist.at(0);
                            }
                        }
                    }
                }
                if((m_paraType == PARA_TYPE_PATTERN && item.indexInPara == SET_ROTATESTYLE) ||	//旋转式样
                        (m_paraType == PARA_TYPE_PATTERN && item.indexInPara == SET_HORIZONTALSTYLE) ||	//水平翻转
                        (m_paraType == PARA_TYPE_PATTERN && item.indexInPara == SET_VERTICALSTYLE))	//垂直翻转
                {
                    //旋转式样加载P的图片
                    SetControlStyle setControlStyle;
                    setControlStyle.setUiName(this->objectName());

                    QString path = setControlStyle.getSharedBottomStyleSheet("") + str + "_logo.png";
                    m_itemBtnList.at(i)->setLabelValueImage(path);
                }
                else
                {
                    m_itemBtnList.at(i)->setLabelValue(str);
                }
            }
            else if (item.valueType == PARA_VALUE_TYPE_STRINPUT)   // = 4, 字符串输入型
            {
                str = item.valueStr;
                m_itemBtnList.at(i)->setLabelValue(str);
                m_itemBtnList.at(i)->show();
            }
            else    //  = 0, 无值
            {
                m_itemBtnList.at(i)->setLabelValue("");
            }
            itemidx++;
        }
        else
        {
            m_itemBtnList.at(i)->setEnabled(false);
            m_itemBtnList.at(i)->hide();
        }
    }

    if(m_paraType == PARA_TYPE_ROOT)//等于超级用户界面
    {
        // 超级用户界面按钮
        if (m_rootCurPage <= 1)
        {
            ui->buttonPgUp->setEnabled(false);
        }
        else
        {
            ui->buttonPgUp->setEnabled(true);
        }

        if (m_rootCurPage >= pageNums)
        {
            ui->buttonPgDn->setEnabled(false);
        }
        else
        {
            ui->buttonPgDn->setEnabled(true);
        }
    }
    else
    {
        // 按钮
        if (m_curPage <= 1)
        {
            ui->buttonPgUp->setEnabled(false);
        }
        else
        {
            ui->buttonPgUp->setEnabled(true);
        }

        if (m_curPage >= pageNums)
        {
            ui->buttonPgDn->setEnabled(false);
        }
        else
        {
            ui->buttonPgDn->setEnabled(true);
        }
    }

    // 页信息
    QString strPage;
    if(m_paraType == PARA_TYPE_ROOT)//等于超级用户界面
    {
        strPage = tr("pageNum: ") + QString("%1/%2").arg(m_rootCurPage).arg(pageNums);//页数:
    }
    else
    {
        strPage = tr("pageNum: ") + QString("%1/%2").arg(m_curPage).arg(pageNums);//页数:
    }

    ui->labelPage->setText(strPage);

    if(m_paraType == PARA_TYPE_EXBUPGRADE)//外围板升级参数
    {
        ui->buttonOk->setEnabled(false);
    }
    if(m_paraType == PARA_TYPE_ROOT)
    {
        ui->buttonOk->setEnabled(false);
        //ui->buttonOk->setEnabled(true);//增加了界面调试模式,超级用户界面按钮可用
    }
    //按色贴布绣或按针贴布绣
    if(m_paraType == (PARA_TYPE_PATTERNPATCH_COLOR | PARA_TYPE_PATTERNPATCH_NEEDLE))
    {
        ui->frameRightUp->setVisible(true);
        ui->buttonPatchParaClear->setVisible(true);
        ui->buttonPatchParaColor->setVisible(true);
        ui->buttonPatchParaNeedle->setVisible(true);
        ui->buttonEXBParaRestore->setVisible(false);
        ui->buttonReturn->setVisible(false);
        ui->buttonHeadParaImport->setVisible(false);
        ui->buttonHeadParaExport->setVisible(false);
    }
    else if(m_paraType == PARA_TYPE_HEADPARAMETER ||      //平绣机头板
            m_paraType == PARA_TYPE_TOWELHEADPARAMETER ||   //毛巾机头板
            m_paraType == PARA_TYPE_COILHEADPARAMETER ||   //缠绕机头板
            m_paraType == PARA_TYPE_HCPSPARAMETER ||    //平绣换色板
            m_paraType == PARA_TYPE_TOWELHCPSPARAMETER ||    //毛巾换色板
            m_paraType == PARA_TYPE_MACH ||
            m_paraType == PARA_TYPE_WORK)//机头板参数或换色板参数或机器参数或工作参数(机器参数或工作参数为超级用户目录下的)
    {
        ui->frameRightUp->setVisible(true);
        ui->buttonPatchParaClear->setVisible(false);
        ui->buttonPatchParaColor->setVisible(false);
        ui->buttonPatchParaNeedle->setVisible(false);
        ui->buttonEXBParaRestore->setVisible(true);//恢复默认参数按钮
        ui->buttonReturn->setVisible(true);//返回上一级按钮或重置反复绣次数
        ui->buttonHeadParaImport->setVisible(true);
        ui->buttonHeadParaExport->setVisible(true);
    }
    else if( m_paraType == PARA_TYPE_HMICONFIGURATION||//超级用户花样参数
             m_paraType == PARA_TYPE_ROOTTRAVERSE ||//遍历设置
             m_paraType == PARA_TYPE_EMBLOCKTEST ||//平绣锁头测试
             m_paraType == PARA_TYPE_IOTCONFIGURATION ||//物联网配置
             m_paraType == PARA_TYPE__ROOT_PATTERN   //界面配置
              )
    {
        ui->frameRightUp->setVisible(true);
        ui->buttonPatchParaClear->setVisible(false);
        ui->buttonPatchParaColor->setVisible(false);
        ui->buttonPatchParaNeedle->setVisible(false);
        ui->buttonEXBParaRestore->setVisible(false);
        ui->buttonHeadParaImport->setVisible(false);
        ui->buttonHeadParaExport->setVisible(false);
        ui->buttonReturn->setVisible(true);//返回上一级按钮
    }
    else if(m_paraType == PARA_TYPE_REPEATEMBPARA)  //反复绣
    {
        ui->frameRightUp->setVisible(true);
        ui->buttonPatchParaClear->setVisible(false);//也用于重置反复绣次数
        ui->buttonPatchParaColor->setVisible(false);
        ui->buttonPatchParaNeedle->setVisible(false);
        ui->buttonEXBParaRestore->setVisible(true);
        ui->buttonHeadParaImport->setVisible(false);
        ui->buttonHeadParaExport->setVisible(false);
        ui->buttonReturn->setVisible(false);
    }
    else
    {
        ui->frameRightUp->setVisible(false);
    }
    //超级用户界面配置
    if(m_paraType == PARA_TYPE_HMICONFIGURATION)
    {
        ui->buttonOk->setEnabled(true);      
    }
    // //如果等于主控机器参数并且等于亮片参数,或者等于主控工作参数并且等于亮片参数
    //    if(((m_paraType == (PARA_TYPE_MACH | PARA_TYPE_WORK)) &&(m_paraTypeSort == MC_SORT_DOUBLE_SEQUIN))||
    //        (m_paraType == (PARA_TYPE_TOWELDEBUG | PARA_TYPE_TOWELDEBUG)))//等于毛巾调试，也没有确认按钮
    if((m_paraType == (PARA_TYPE_TOWELDEBUG | PARA_TYPE_TOWELDEBUG)))//等于毛巾调试，也没有确认按钮
    {
        ui->buttonOk->setEnabled(false);
    }
}

void ParameterSetDialog::initArabControlPos()
{
    int language = g_pSettings->readFromInHMIiFile("HMI/language").toInt();
    if(language != arabic)
    {
        return;
    }

    ui->labelMainTitle->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    ui->labelSubTitle->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    ui->labelRepetitions->setAlignment(Qt::AlignRight | Qt::AlignVCenter);

    //内容的位置
    for(int i = 0; i < m_itemBtnList.size(); i++)//白色按下的效果
    {
        m_itemBtnList[i]->setLabelNamePos(1);
        m_itemBtnList[i]->setLabelValuePos(1);
    }
}

QString ParameterSetDialog::getValueStr(int64_t val, int afterpoint)
{
    QString str;
    double value = val;
    if (afterpoint <= 0)
    {
        str.sprintf("%.0f", value);
    }
    else if (afterpoint == 1)
    {
        value /= 10;
        str.sprintf("%.1f", value);
    }
    else if (afterpoint == 2)
    {
        value /= 100;
        str.sprintf("%.2f", value);
    }
    else if (afterpoint == 3)
    {
        value /= 1000;
        str.sprintf("%.3f", value);
    }
    else // if (afterpoint >= 4)
    {
        value /= 10000;
        str.sprintf("%.4f", value);
    }
    return str;
}

void ParameterSetDialog::changeValue(int buttenidx)
{
#if(0)
    //等于机器参数或工作参数
    if(((m_paraType & PARA_TYPE_MACH) == PARA_TYPE_MACH) ||
            ((m_paraType & PARA_TYPE_WORK) == PARA_TYPE_WORK))
    {
        if(g_emUser != repair)//权限不够先登录
        {
            emit siUserLogin(repair);
            if(g_emUser != repair)//发送登录信号后，权限如果还没改变就返回
                return;
        }
    }
#endif

    QString split1 = ":";
    QString split2 = ";";

    if (buttenidx < 0 || buttenidx >= m_itemPerPage)
    {
        return ;
    }

    int itemidx;
    int selIdx = 0;
    if(m_paraType == PARA_TYPE_ROOT)//等于超级用户界面
    {
        itemidx = (m_rootCurPage-1) * m_itemPerPage;
    }
    else
    {
        itemidx = (m_curPage-1) * m_itemPerPage;
    }

    itemidx += buttenidx;

    if (itemidx < m_itemList.size())
    {
        int chgflag = 0;
        s32 newvalue;
        QString newStrValue;
        const ParaItem & item = m_itemList.at(itemidx);
        newvalue = item.value;//等于这个列表现在的值
        newStrValue = item.valueStr;

        if (item.valueType == PARA_VALUE_TYPE_INT)    // 数字型
        {
            int rslt;
            NumerInputDialog ndlg(this);
            ndlg.setTitleStr(item.paraName);
            ndlg.setUnitStr(item.unitStr);
            ndlg.setValueAndRange(item.value, item.minVal, item.maxVal, item.afterPoint);
            rslt = ndlg.exec();

            if (rslt == 1)//点了确认按钮
            {
                s32 val = ndlg.getValue();
                if (val != newvalue)//更改后的值不等于之前存的值
                {
                    chgflag = 1;
                    newvalue = val;
                }
            }
        }
        else if (item.valueType == PARA_VALUE_TYPE_SW)    // 开关型
        {
            if (newvalue == 0)
            {
                newvalue = 1;
            }
            else
            {
                newvalue = 0;
            }
            chgflag = 1;
        }
        else if (item.valueType == PARA_VALUE_TYPE_LIST)
        {
            QStringList vallist;
            if(item.selList.indexOf(split2) == -1)
            {  //没找到 二级分割
                vallist = item.selList.split(split1, QString::SkipEmptyParts);
                if (vallist.size() > 0)
                {
                    selIdx = item.selIdx + 1;
                    if (selIdx < 0)
                    {
                        selIdx = 0;
                    }
                    if (selIdx >= vallist.size())   // 循环选择
                    {
                        selIdx = 0;
                    }
                    chgflag = 1;
                }
            }
            else
            {
                //二级分割  注意 key 是 int  val是字符串
                //分清楚 key 并不是 字符串的index  需要区分
                vallist = item.selList.split(split2, QString::SkipEmptyParts);
                if (vallist.size() <= 0)
                {
                    return;
                }
                else
                {
                    // 使用 qmap 组成key: val
                    int miniVal = vallist.first().split(split1, QString::SkipEmptyParts).at(1).toInt();
                    int maxVal  = vallist.last().split(split1, QString::SkipEmptyParts).at(1).toInt();
                    QMap <int,QString> seachDat ;

                    for (int var = 0; var < vallist.size(); ++var)
                    {
                        QStringList mapDatList = vallist.at(var).split(split1, QString::SkipEmptyParts);
                        seachDat.insert(mapDatList.at(1).toInt(),mapDatList.at(0));
                    }

                    selIdx = item.selIdx;

                    if(seachDat.contains(selIdx))
                    {
                        //存在这个key

                    }
                    else
                    {
                        //不存在这个key 用默认值存储
                        selIdx = item.defValue;
                    }

                    //找到下一个val  vallist seach_dat

                    for (int var = 0; var < vallist.size(); ++var)
                    {
                        if( vallist.at(var).split(split1, QString::SkipEmptyParts).at(1).toInt() == selIdx)
                        {
                            var++ ;
                            if( var >= vallist.size())
                            {
                                var = 0 ;
                            }
                            selIdx = vallist.at(var).split(split1, QString::SkipEmptyParts).at(1).toInt();
                            break;
                        }
                    }
                    if (selIdx < miniVal)
                    {
                        selIdx = miniVal;
                    }
                    if (selIdx > maxVal)
                    {
                        selIdx = maxVal;
                    }
                    chgflag = 1;
                }
            }
        }
        else if (item.valueType == PARA_VALUE_TYPE_STRINPUT)    // 字符输入型
        {
            PassWordDialog passWordDlg(this);
            QString str("");
            passWordDlg.setTitleStr(tr("Input"),-1);//输入
            passWordDlg.setShowIfVisible(true);
            int rslt = passWordDlg.exec();
            if(rslt == 1)
            {
                str = passWordDlg.getInputStr();
                if (str != item.valueStr)
                {
                    chgflag = 1;
                    newStrValue = str;
                }
            }
        }
        else if (item.valueType == PARA_VALUE_TYPE_CLICK)    // 点击触发型
        {
            s16 fun = item.indexInPara;
            execItemClickEvent(fun);
            return;
        }

        if (chgflag != 0)
        {
            if(item.valueType == PARA_VALUE_TYPE_LIST)
            {
                m_itemList[itemidx].selIdx = selIdx;
                m_itemList[itemidx].value = selIdx;
            }
            else if(item.valueType == PARA_VALUE_TYPE_STRINPUT)
            {
                m_itemList[itemidx].valueStr = newStrValue;
            }
            else
            {
                m_itemList[itemidx].value = newvalue;//列表里的值等于弹窗输入的值

                //等于贴布绣参数时总的列表值与m_itemList列表值同步
                if(m_paraType == (PARA_TYPE_PATTERNPATCH_COLOR | PARA_TYPE_PATTERNPATCH_NEEDLE))
                {
                    int paraType = m_itemList[itemidx].paraType;
                    for(int i = 0; i < m_patchItemList.size(); i++)
                    {
                        int pType = m_patchItemList[i].paraType;
                        int sort = m_patchItemList[i].paraTypeSort;
                        int idx = m_patchItemList[i].indexInPara;
                        if(paraType == pType && m_itemList[itemidx].paraTypeSort == sort && m_itemList[itemidx].indexInPara == idx)
                        {
                            m_patchItemList[i].value = newvalue;
                        }
                    }
                }
            }
            //   qDebug()<< " newvalue " << newvalue;

            //等于遍历参数
            if((m_paraType & PARA_TYPE_ROOTTRAVERSE) == PARA_TYPE_ROOTTRAVERSE)
            {
                // - rq
                //点击节点类型的时候，显示平绣，毛巾等机头个数
                if(m_itemList[1].value == FLATEMB)//平绣机头
                {
                    //只是改了，参数的名称，这里并不刷新
                    m_itemList[4].paraName = tr("EnableNumber of flat embroidery heads");//平绣机头个数
                    m_nodeType = FLATEMB;
                }
                else if(m_itemList[1].value == TOWEL)//毛巾机头
                {
                    m_itemList[4].paraName = tr("Number of chenille heads");//毛巾机头个数
                    m_nodeType = TOWEL;
                }
                else if(m_itemList[1].value == COIL)//缠绕机头
                {
                    m_itemList[4].paraName = tr("Number of coil heads");//缠绕机头个数
                    m_nodeType = COIL;
                }
                if(m_itemList[2].value == 2)//全部遍历
                {
                    if(m_itemList[1].value == FLATEMB)//平绣机头
                    {
                        m_itemList[2].value = m_mcParaValues.buf[2];//遍历次数改为平绣机头个数
                    }
                    else if(m_itemList[1].value == TOWEL)//毛巾机头
                    {
                        m_itemList[2].value = m_mcParaValues.buf[8];//遍历次数改为毛巾机头个数
                    }
                    else if(m_itemList[1].value == COIL)//缠绕机头
                    {
                        m_itemList[2].value = m_mcParaValues.buf[7];//遍历次数改为缠绕机头个数
                    }

                    m_itemList[3].value = 1;//机头号置为1
                    m_itemList[3].readonly = 1;//机头号置为可读
                }
                else if(m_itemList[2].value == 1)//单独遍历
                {
                    m_itemList[3].readonly = 0;//机头号置为可设置
                }
            }

            refreshUi();//在这个函数里刷新
            //如果等于主控机器参数并且等于亮片参数,或者等于主控工作参数并且等于亮片参数(亮片调试)
            //            if((m_paraType == (PARA_TYPE_MACH | PARA_TYPE_WORK)) &&(m_paraTypeSort == MC_SORT_SEQUIN))
            //            {
            //                //单个保存
            //                saveParas(itemidx);
            //            }
        }
    }
}

//刷新参数值
void ParameterSetDialog::refreshValue()
{
    m_mcParaValues = m_mcParaValues;
    m_wkParaValues = m_wkParaValues;

    for (int i = 0; i < m_itemList.size(); i++)
    {
        int type = m_itemList[i].paraType;
        int idx = m_itemList.at(i).indexInPara;
        int bitInWord = m_itemList[i].bitInWord;
        s32 mcTempValue = m_mcParaValues.buf[idx];
        s32 wkTempValue = m_wkParaValues.buf[idx];

        s32 headTempValue = m_headParaValues.paraBuf[idx];
        s32 hcpsTempValue = m_hcpsParaValues.paraBuf[idx];

        if (idx < PARA_NUM)
        {
            if (type == PARA_TYPE_MACH)
            {
                // ljs++
                if (bitInWord == 0)
                {
                    m_itemList[i].value = mcTempValue;//列表里的值，变成主控里的值
                    if(m_itemList[i].valueType == PARA_VALUE_TYPE_LIST)
                    {
                        m_itemList[i].selIdx = mcTempValue;
                    }
                }
                else
                {
                    u32 bitval = 0x01;
                    bitval <<= (bitInWord - 1);
                    if ((mcTempValue & bitval) == 0)
                    {
                        m_itemList[i].selIdx = 0;
                        m_itemList[i].value = 0;
                    }
                    else
                    {
                        m_itemList[i].selIdx = 1;
                        m_itemList[i].value = 1;
                    }
                }
            }
            else if (type == PARA_TYPE_WORK)
            {
                // ljs++
                if (bitInWord == 0)
                {
                    //界面处理加油时间间隔，加油储气时长 单位换算
                    if(idx == 181 || idx == 211)
                    {
                        m_itemList[i].value = wkTempValue/60;
                    }
                    else
                    {
                         m_itemList[i].value = wkTempValue;
                    }
                    if(m_itemList[i].valueType == PARA_VALUE_TYPE_LIST)
                    {
                        m_itemList[i].selIdx = wkTempValue;
                    }
                }
                else
                {
                    u32 bitval = 0x01;
                    bitval <<= (bitInWord - 1);
                    if ((wkTempValue & bitval) == 0)
                    {
                        m_itemList[i].selIdx = 0;
                        m_itemList[i].value = 0;
                    }
                    else
                    {
                        m_itemList[i].selIdx = 1;
                        m_itemList[i].value = 1;
                    }
                }
            }
            else if (type == PARA_TYPE_HEADPARAMETER||
                     type == PARA_TYPE_COILHEADPARAMETER||
                     type == PARA_TYPE_TOWELHEADPARAMETER
                     )
            {
                if (bitInWord == 0)
                {
                    m_itemList[i].value = headTempValue;
                    if(m_itemList[i].valueType == PARA_VALUE_TYPE_LIST)
                    {
                        m_itemList[i].selIdx = headTempValue;
                    }
                }
                else
                {
                    u32 bitval = 0x01;
                    bitval <<= (bitInWord - 1);
                    if ((headTempValue & bitval) == 0)
                    {
                        m_itemList[i].selIdx = 0;
                        m_itemList[i].value = 0;
                    }
                    else
                    {
                        m_itemList[i].selIdx = 1;
                        m_itemList[i].value = 1;
                    }
                }
            }
            else if (type == PARA_TYPE_HCPSPARAMETER ||
                     type == PARA_TYPE_TOWELHCPSPARAMETER
                     )
            {
                if (bitInWord == 0)
                {
                    m_itemList[i].value = hcpsTempValue;
                    if(m_itemList[i].valueType == PARA_VALUE_TYPE_LIST)
                    {
                        m_itemList[i].selIdx = hcpsTempValue;
                    }
                }
                else
                {
                    u32 bitval = 0x01;
                    bitval <<= (bitInWord - 1);
                    if ((hcpsTempValue & bitval) == 0)
                    {
                        m_itemList[i].selIdx = 0;
                        m_itemList[i].value = 0;
                    }
                    else
                    {
                        m_itemList[i].selIdx = 1;
                        m_itemList[i].value = 1;
                    }
                }
            }
        }
    }
}

//收到下位机参数改变信号的槽
void ParameterSetDialog::paraChange(int type, int id)
{
    //点了主板的按钮后，现在这个g_pMachine就是对应主板的
    if (type == SEW_MCPARA_MACH)
    {
        if (id == 0)
        {                                                  //得到当前主板的参数
            memcpy(&m_mcParaValues, &g_pMachine->getMcPara(), sizeof(ParaStruct));

            m_setedFlag |= 0x01;//当前的主板 收到参数包  的标志改变
        }
    }
    else if (type == SEW_MCPARA_WORK)
    {
        if (id == 0)
        {
            memcpy(&m_wkParaValues, &g_pMachine->getWkPara(), sizeof(ParaStruct));
            m_setedFlag |= 0x02;
        }
    }

    //绣花机单主板
    m_mcParaValues = m_mcParaValues;
    m_wkParaValues = m_wkParaValues;

    //等于机器参数或工作参数
    if(((m_paraType & PARA_TYPE_MACH) == PARA_TYPE_MACH) ||
            ((m_paraType & PARA_TYPE_WORK) == PARA_TYPE_WORK))
    {
        if (m_setedFlag == 0x03)// = 0x03就是机器参数和主控参数都读过
        {
            if (m_itemList.size() > 0)//参数列表
            {
                ui->buttonOk->setEnabled(true);//如果从下位机得到了数据包，说明与下位机建立了联系。可以点击确认按钮
            }
            refreshValue();
            refreshUi();
        }
    }
}
//外围板参数改变的槽函数
void ParameterSetDialog::EXBParaChange()
{
    if (m_paraType == PARA_TYPE_HEADPARAMETER)
    {
        if(g_pMachine->getHeadPara(0,FLATEMB) != NULL)
        {
            memcpy(&m_headParaValues, g_pMachine->getHeadPara(0,FLATEMB), sizeof(HeadInfo));
            m_hcpsFlag |= 0x01;
        }
    }
    else if (m_paraType == PARA_TYPE_TOWELHEADPARAMETER)
    {
        if(g_pMachine->getHeadPara(0,TOWEL) != NULL)//找到的数据包不是空
        {
            memcpy(&m_headParaValues, g_pMachine->getHeadPara(0,TOWEL), sizeof(HeadInfo));
            m_hcpsFlag |= 0x02;
        }
    }
    else if (m_paraType == PARA_TYPE_COILHEADPARAMETER)
    {
        if(g_pMachine->getHeadPara(0,COIL) != NULL)//找到的数据包不是空
        {
            memcpy(&m_headParaValues, g_pMachine->getHeadPara(0,COIL), sizeof(HeadInfo));
            m_hcpsFlag |= 0x02;
        }
    }
    else if (m_paraType == PARA_TYPE_HCPSPARAMETER)//平绣换色板
    {
        memcpy(&m_hcpsParaValues, &g_pMachine->getHcpsPara(0), sizeof(HcpsInfo));
        m_hcpsFlag |= 0x03;
    }
    else if ( m_paraType ==  PARA_TYPE_TOWELHCPSPARAMETER)//毛巾换色板
    {
        memcpy(&m_hcpsParaValues, &g_pMachine->getHcpsPara(1), sizeof(HcpsInfo));
        m_hcpsFlag |= 0x03;
    }
    //等于(毛巾，平绣)机头板参数或换色板参数
    if(((m_paraType & PARA_TYPE_HEADPARAMETER) == PARA_TYPE_HEADPARAMETER) ||
            ((m_paraType & PARA_TYPE_HCPSPARAMETER) == PARA_TYPE_HCPSPARAMETER) ||
            ((m_paraType & PARA_TYPE_TOWELHCPSPARAMETER) == PARA_TYPE_TOWELHCPSPARAMETER) ||
            ((m_paraType & PARA_TYPE_COILHEADPARAMETER) == PARA_TYPE_COILHEADPARAMETER) ||
            ((m_paraType & PARA_TYPE_TOWELHEADPARAMETER) == PARA_TYPE_TOWELHEADPARAMETER)
            )
    {
        if (m_hcpsFlag != 0)// 就是机头板参数或换色板参数读过
        {
            refreshValue();
            refreshUi();
        }
    }
}

void ParameterSetDialog::slotRefreshHeadPara(int type)
{
    if(type == PARA_TYPE_HEADPARAMETER)
    {
        g_pMachine->getHeadParasFromMachine(1,FLATEMB);//获取平绣机头板参数
    }
    else if(type == PARA_TYPE_TOWELHEADPARAMETER)
    {
        g_pMachine->getHeadParasFromMachine(1,TOWEL);//获取平绣机头板参数
    }
    else if(type == PARA_TYPE_COILHEADPARAMETER)
    {
        g_pMachine->getHeadParasFromMachine(1,COIL);//获取缠绕机头板参数
    }
    else if(type == PARA_TYPE_HCPSPARAMETER)
    {
        g_pMachine->getHcpsParasFromMachine(2);//获取换色板参数
    }
    else if(type == PARA_TYPE_TOWELHCPSPARAMETER)
    {
        g_pMachine->getHcpsParasFromMachine(2);//获取毛巾换色板参数
    }
}

//刷新遍历参数信息
void ParameterSetDialog::refreshSensorPara(int min, int max, int num, ParaItem &item, u32 traverseState, u32 traverseState1, int m_nodeType)
{
    //等于绣花机并为带毛巾
    int towel = g_pSettings->readFromInHMIiFile("HMI/towel").toInt();//是否有毛巾功能
    int coil = g_pSettings->readFromInHMIiFile("HMI/coil").toInt();//是否有缠绕功能

    item.paraName.clear();
    int nType = m_nodeType;//当前的节点类型（毛巾/平绣/缠绕）
    int EMBNum = m_mcParaValues.buf[2];//平绣机头个数
    int TOWELNum = m_mcParaValues.buf[8];//毛巾机头个数（有几个毛巾机头就有几个毛巾下机头）
    int COILNum = m_mcParaValues.buf[7];//缠绕机头个数
    //int showNum = 17;

    QString sensorN = "-N";//未遍历成功
    QString sensorY = "-Y";//已遍历成功

    if(max > num)//如果最大值15大于机头数，最大值减1
    {
        max = num - 1;
    }
    //traverseState：遍历状态（每一位表示机头的状态   毛巾下机头个数 -毛巾上机头个数-平绣机头个数-缠绕）
    //num：机头个数
    if(g_emMacType == MACHINE_EMB && towel ==1)
    {
        int boardNum = TOWELNum / 4;//板卡数，一块板卡带4个机头
        if(TOWELNum % 4 != 0)
        {
            boardNum += 1;
        }
        int dnTowelOft = boardNum * 4;//下毛巾机头移位
        int embOft = dnTowelOft + TOWELNum;

        if(nType == FLATEMB)//默认是平绣的
        {
            if(EMBNum == 0)
            {
                return;
            }
            else
            {
                for(int i = embOft; i <= embOft+EMBNum; i++)//i等于最小值0  循环16次,一个u32有32位
                {
                    if(min > EMBNum)
                    {
                        return;
                    }

                    if((i - embOft) == EMBNum)
                    {
                        break;
                    }

                    item.paraName += QString::number(i-embOft+1);//1-Y   2-Y  3-Y  4-Y   //30+1-30  31+1-30
                    if(i <= 32)
                    {
                        if(traverseState>>i & 1)//会加上毛巾的机头数，从毛巾的机头数bit位开始平绣会移位16次，判读每位是0还是1
                        {
                            item.paraName += sensorY;
                        }
                        else
                        {
                            item.paraName += sensorN;
                        }
                    }
                    else
                    {
                        if(traverseState1>>(i-32) & 1)//会加上毛巾的机头数，从毛巾的机头数bit位开始平绣会移位16次，判读每位是0还是1
                        {
                            item.paraName += sensorY;
                        }
                        else
                        {
                            item.paraName += sensorN;
                        }
                    }
                    item.paraName += "  ";//添加空格
                    refreshUi();
                }
            }
        }
        else if(nType == TOWEL)
        {
            if(TOWELNum == 0)
            {
                return;
            }
            else
            {
                int maxBitChen = TOWELNum+TOWELNum;//实际的毛巾头数
                int val = item.indexInPara;

                if(val == 1)//下毛巾机头
                {
                    for(int i = 0; i <= dnTowelOft; i++)//i等于最小值0  循环16次,一个u32有32位
                    {
                        if(i == TOWELNum)
                        {
                            break;
                        }

                        item.paraName += QString::number(i+1);//1-Y   2-Y  3-Y  4-Y
                        if(traverseState>>i & 1)//判读每位是0还是1
                        {
                            item.paraName += sensorY;
                        }
                        else
                        {
                            item.paraName += sensorN;
                        }
                        item.paraName += "  ";//添加空格
                    }
                }
                else if (val == 2)//上毛巾机头
                {
                    for(int i = dnTowelOft; i <= maxBitChen; i++)//i等于最小值0  循环16次,一个u32有32位
                    {
                        TOWELNum++;
                        item.paraName += QString::number(TOWELNum);//1-Y   2-Y  3-Y  4-Y
                        if(traverseState>>i & 1)//判读每位是0还是1
                        {
                            item.paraName += sensorY;
                        }
                        else
                        {
                            item.paraName += sensorN;
                        }
                        item.paraName += "  ";//添加空格

                        if(i == maxBitChen)
                        {
                            break;
                        }
                    }
                }
                refreshUi();
            }
        }
    }

    else if (g_emMacType == MACHINE_EMB && coil ==1)
    {
        //min 是0；max是11
        //int EMBMax = max - EMBNum - 1;
        if(nType == FLATEMB)//默认是平绣的
        {
            if(EMBNum == 0)
            {
                return;
            }
            else
            {
                int maxBitEMB = EMBNum-1;
                for(int i = min; i <= maxBitEMB; i++)//i等于最小值0  循环16次,一个u32有32位
                {
                    item.paraName += QString::number(i+1);//1-Y   2-Y  3-Y  4-Y
                    if(traverseState>>i & 1)//判读每位是0还是1
                    {
                        item.paraName += sensorY;
                    }
                    else
                    {
                        item.paraName += sensorN;
                    }
                    item.paraName += "  ";//添加空格
                    refreshUi();
                }
            }
        }
        else if(nType == COIL)//缠绕
        {
            int COILMin = EMBNum;
            int COILMAX = COILMin+ COILNum-1;

            if(COILNum == 0)
            {
                return;
            }
            else
            {   //13~25
                for(int i = COILMin; i <= COILMAX; i++)//i等于最小值0  循环16次,一个u32有32位
                {
                    item.paraName += QString::number(i+1-COILMin);//1-Y   2-Y  3-Y  4-Y
                    if(traverseState>>i & 1)//判读每位是0还是1
                    {
                        item.paraName += sensorY;
                    }
                    else
                    {
                        item.paraName += sensorN;
                    }
                    item.paraName += "  ";//添加空格
                    refreshUi();
                }
            }
        }

    }

    else if(g_emMacType == MACHINE_EMB  && g_emProductType == PRODUCT_CHEN)//纯毛巾
    {
        int boardNum = TOWELNum / 4;//板卡数，一块板卡带4个机头
        if(TOWELNum % 4 != 0)
        {
            boardNum += 1;
        }
        int dnTowelOft = boardNum * 4;//下毛巾机头移位
        if(TOWELNum == 0)
        {
            return;
        }
        else
        {
            int maxBitChen = TOWELNum+TOWELNum;//实际的毛巾头数
            int val = item.indexInPara;

            if(val == 1)//下毛巾机头
            {
                for(int i = 0; i <= dnTowelOft; i++)//i等于最小值0  循环16次,一个u32有32位
                {
                    if(i == TOWELNum)
                    {
                        break;
                    }

                    item.paraName += QString::number(i+1);//1-Y   2-Y  3-Y  4-Y
                    if(traverseState>>i & 1)//判读每位是0还是1
                    {
                        item.paraName += sensorY;
                    }
                    else
                    {
                        item.paraName += sensorN;
                    }
                    item.paraName += "  ";//添加空格
                }
            }
            else if (val == 2)//上毛巾机头
            {
                for(int i = dnTowelOft; i <= maxBitChen; i++)//i等于最小值0  循环16次,一个u32有32位
                {
                    TOWELNum++;
                    item.paraName += QString::number(TOWELNum);//1-Y   2-Y  3-Y  4-Y
                    if(traverseState>>i & 1)//判读每位是0还是1
                    {
                        item.paraName += sensorY;
                    }
                    else
                    {
                        item.paraName += sensorN;
                    }
                    item.paraName += "  ";//添加空格

                    if(i == maxBitChen)
                    {
                        break;
                    }
                }
            }
            refreshUi();
        }
    }

    else if (g_emMacType == MACHINE_EMB && coil !=1 && towel !=1)//纯平绣
    {
        if(EMBNum == 0)
        {
            return;
        }
        else
        {
            for(int i = min; i <= max; i++)//i等于最小值0  循环32次,一个u32有32位
            {
                item.paraName += QString::number(i+1);//1-Y   2-Y  3-Y  4-Y
                if(traverseState>>i & 1)//判读每位是0还是1
                {
                    item.paraName += sensorY;
                }
                else
                {
                    item.paraName += sensorN;
                }
                item.paraName += "  ";//添加空格
                refreshUi();
            }
        }
    }

}

void ParameterSetDialog::saveParas(int idx)
{
    qDebug()<<"step 1";
    if (m_setedFlag == 0x03 &&
            (m_paraType == (PARA_TYPE_MACH | PARA_TYPE_WORK) ||
             m_paraType == PARA_TYPE_MACH || m_paraType == PARA_TYPE_WORK))
    {
        int size = m_itemList.size();
        if (idx < 0)
        {
            int i;
            for (i = 0; i < size; i++)
            {
                int id = m_itemList.at(i).indexInPara;
                int type = m_itemList.at(i).paraType;
                int bitInWord = m_itemList.at(i).bitInWord;
                int value = m_itemList.at(i).value;
                if (id < PARA_NUM && type == PARA_TYPE_MACH)
                {
                    if (bitInWord == 0)        // ljs++
                    {
                        m_mcParaValues.buf[id] = m_itemList.at(i).value;
                    }
                    else
                    {
                        u32 bitval = 0x01;
                        bitval <<= (bitInWord - 1);
                        if (value == 0)
                        {
                            m_mcParaValues.buf[id] &= ~bitval;
                        }
                        else
                        {
                            m_mcParaValues.buf[id] |= bitval;
                        }
                    }
                }
            }

            qDebug()<<"step 2";
#if(0)
            for(int i = 0; i < MACHINE_NUMBER; i++)
            {
                g_pMachine[i]->setMcPara(&m_mcParaValues);
            }
#endif
            //当前主板的g_pMachine
            g_pMachine->setMcPara(&m_mcParaValues);
            qDebug()<<"step 3";
           //工作参数
            for (i = 0; i < size; i++)
            {
                int id = m_itemList.at(i).indexInPara;
                int type = m_itemList.at(i).paraType;
                int bitInWord = m_itemList.at(i).bitInWord;
                int value = m_itemList.at(i).value;
                if (id < PARA_NUM && type == PARA_TYPE_WORK)
                {

                    if (bitInWord == 0)        // ljs++
                    {
                        //界面处理单位换算
                        if(id == 181|| id == 211)
                        {
                            value = value*60;
                            m_wkParaValues.buf[id] = value;
                        }
                        else
                        {
                             m_wkParaValues.buf[id] = m_itemList.at(i).value;
                        }
                    }
                    else
                    {
                        u32 bitval = 0x01;
                        bitval <<= (bitInWord - 1);
                        if (value == 0)
                        {
                            m_wkParaValues.buf[id] &= ~bitval;
                        }
                        else
                        {
                            m_wkParaValues.buf[id] |= bitval;
                        }
                    }
                }
            }

            qDebug()<<"step 4";
#if(0)
            for(int i = 0; i < MACHINE_NUMBER; i++)
            {
                g_pMachine[i]->setWkPara(&m_wkParaValues);
            }
#endif
            g_pMachine->setWkPara(&m_wkParaValues);
            qDebug()<<"step 5";
        }
        else if (idx < size)
        {
            int id = m_itemList.at(idx).indexInPara;
            int type = m_itemList.at(idx).paraType;
            int value = m_itemList.at(idx).value;
            int bitInWord = m_itemList.at(idx).bitInWord;       // ljs++
            if (id < PARA_NUM && type == PARA_TYPE_MACH)
            {
                if (bitInWord == 0)
                {
                    m_mcParaValues.buf[id] = value;
                }
                else
                {
                    u32 bitval = 0x01;
                    bitval <<= (bitInWord - 1);
                    if (value == 0)
                    {
                        m_mcParaValues.buf[id] &= ~bitval;
                    }
                    else
                    {
                        m_mcParaValues.buf[id] |= bitval;
                    }
                    value = m_mcParaValues.buf[id];
                }

                qDebug()<<"step 6";
#if(0)
                for(int i = 0; i < MACHINE_NUMBER; i++)
                {
                    g_pMachine[i]->setAMcPara(id+1, value);
                }
#endif
                g_pMachine->setAMcPara(id+1, value);
                qDebug()<<"step 7";
            }
            else if (id < PARA_NUM && type == PARA_TYPE_WORK)
            {
                if (bitInWord == 0)
                {
                    m_wkParaValues.buf[id] = value;
                }
                else
                {
                    u32 bitval = 0x01;
                    bitval <<= (bitInWord - 1);
                    if (value == 0)
                    {
                        m_wkParaValues.buf[id] &= ~bitval;
                    }
                    else
                    {
                        m_wkParaValues.buf[id] |= bitval;
                    }
                    value = m_wkParaValues.buf[id];
                }

                qDebug()<<"step 8";
#if(0)
                for(int i = 0; i < MACHINE_NUMBER; i++)
                {
                    g_pMachine[i]->setAWkPara(id+1, value);
                }
#endif
                g_pMachine->setAWkPara(id+1, value);
                qDebug()<<"step 9";
            }
        }
    }

    if (m_hcpsFlag !=0 && m_paraType == PARA_TYPE_HEADPARAMETER )
    {
        int size = m_itemList.size();
        if (idx < 0)
        {
            int i;
            for (i = 0; i < size; i++)
            {
                int id = m_itemList.at(i).indexInPara;
                int type = m_itemList.at(i).paraType;
                int bitInWord = m_itemList.at(i).bitInWord;
                int value = m_itemList.at(i).value;
                if ((id < PARA_NUM) && (type == PARA_TYPE_HEADPARAMETER))
                {
                    if (bitInWord == 0)
                    {
                        m_headParaValues.paraBuf[id] = m_itemList.at(i).value;
                    }
                    else
                    {
                        u32 bitval = 0x01;
                        bitval <<= (bitInWord - 1);
                        if (value == 0)
                        {
                            m_headParaValues.paraBuf[id] &= ~bitval;
                        }
                        else
                        {
                            m_headParaValues.paraBuf[id] |= bitval;
                        }
                    }
                }
            }

            //外围板只有一块主板时有
            g_pMachine->setHeadBoardPara(&m_headParaValues, FLATEMB);
        }
    }
    else if(m_hcpsFlag !=0 && m_paraType == PARA_TYPE_TOWELHEADPARAMETER)
    {
        int size = m_itemList.size();
        if (idx < 0)
        {
            int i;
            for (i = 0; i < size; i++)
            {
                int id = m_itemList.at(i).indexInPara;
                int type = m_itemList.at(i).paraType;
                int bitInWord = m_itemList.at(i).bitInWord;
                int value = m_itemList.at(i).value;
                if ((id < PARA_NUM) && (type == PARA_TYPE_TOWELHEADPARAMETER))
                {
                    if (bitInWord == 0)
                    {
                        m_headParaValues.paraBuf[id] = m_itemList.at(i).value;
                    }
                    else
                    {
                        u32 bitval = 0x01;
                        bitval <<= (bitInWord - 1);
                        if (value == 0)
                        {
                            m_headParaValues.paraBuf[id] &= ~bitval;
                        }
                        else
                        {
                            m_headParaValues.paraBuf[id] |= bitval;
                        }
                    }
                }
            }
            //外围板只有一块主板时有
            g_pMachine->setHeadBoardPara(&m_headParaValues, TOWEL);
        }
    }

    else if(m_hcpsFlag !=0 && m_paraType == PARA_TYPE_COILHEADPARAMETER)
    {
        int size = m_itemList.size();
        if (idx < 0)
        {
            int i;
            for (i = 0; i < size; i++)
            {
                int id = m_itemList.at(i).indexInPara;
                int type = m_itemList.at(i).paraType;
                int bitInWord = m_itemList.at(i).bitInWord;
                int value = m_itemList.at(i).value;
                if ((id < PARA_NUM) && (type == PARA_TYPE_COILHEADPARAMETER))
                {
                    if (bitInWord == 0)
                    {
                        m_headParaValues.paraBuf[id] = m_itemList.at(i).value;
                    }
                    else
                    {
                        u32 bitval = 0x01;
                        bitval <<= (bitInWord - 1);
                        if (value == 0)
                        {
                            m_headParaValues.paraBuf[id] &= ~bitval;
                        }
                        else
                        {
                            m_headParaValues.paraBuf[id] |= bitval;
                        }
                    }
                }
            }
            //外围板只有一块主板时有
            g_pMachine->setHeadBoardPara(&m_headParaValues, COIL);
        }
    }
    //机头板参数和换色板参数分开给主控发送 -rq
    else if(m_hcpsFlag !=0 &&
            (m_paraType == PARA_TYPE_TOWELHCPSPARAMETER ||
             m_paraType == PARA_TYPE_HCPSPARAMETER))
    {
        int size = m_itemList.size();
        if (idx < 0)
        {
            int i;
            for (i = 0; i < size; i++)
            {
                int id = m_itemList.at(i).indexInPara;
                int type = m_itemList.at(i).paraType;
                int bitInWord = m_itemList.at(i).bitInWord;
                int value = m_itemList.at(i).value;
                if ((id < PARA_NUM) && (type == PARA_TYPE_HCPSPARAMETER || type ==PARA_TYPE_TOWELHCPSPARAMETER))
                {
                    if (bitInWord == 0)        // ljs++
                    {
                        m_hcpsParaValues.paraBuf[id] = m_itemList.at(i).value;
                    }
                    else
                    {
                        u32 bitval = 0x01;
                        bitval <<= (bitInWord - 1);
                        if (value == 0)
                        {
                            m_hcpsParaValues.paraBuf[id] &= ~bitval;
                        }
                        else
                        {
                            m_hcpsParaValues.paraBuf[id] |= bitval;
                        }
                    }
                }
            }
            g_pMachine->setHcpsBoardPara(&m_hcpsParaValues,1);//-rq   不用nodeType，用nodeID = idx+1
        }
    }

}

//执行点击触发型参数的触发事件
void ParameterSetDialog::execItemClickEvent(s16 fun)
{
    g_pMachine->getParasFromMachine();//读取参数

    switch (fun)
    {
    case ROOT_HMICONFIGURATION://进入界面配置
        setMainTitle(tr("HMI Configuration"));
        setSubTitle(tr("Root > HMI Configuration"));
        //得到界面配置列表
        if(g_emDebugMode == nodebugMode)
        {
            if(g_emUser == factory)
            {
                setItemList(factory,PARA_TYPE_HMICONFIGURATION);//最高权限
            }
            else if(g_emUser == root)
            {
                setItemList(root,PARA_TYPE_HMICONFIGURATION);//最高权限
            }
        }
        else
        {
            setItemList(root,PARA_TYPE_HMICONFIGURATION);//最高权限
        }
        //设置参数值
        setItemValue(ROOT_RESOLUTION,g_emResolut);   //分辨率
        setItemValue(SET_CONNECTMODE,g_pSettings->readFromIniFile("HMI/connectMode").toInt());
        setItemValue(ROOT_MACTYPE,g_emMacType);  //机器类型
        setItemValue(ROOT_PRODUCTTYPE,g_emProductType);  //产品类型
        setItemValue(ROOT_COMBINEEMB,g_pSettings->readFromInHMIiFile("HMI/combineEmb").toInt());
        setItemValue(ROOT_THREECOMBINEEMB,g_pSettings->readFromInHMIiFile("HMI/threeCombineEmb").toInt());
        setItemValue(ROOT_HEADEMB,g_pSettings->readFromInHMIiFile("HMI/headEmb").toInt());
        setItemValue(ROOT_LASER,g_pSettings->readFromInHMIiFile("HMI/laser").toInt());//激光
        setItemValue(ROOT_SHUTTLECHANGE,g_pSettings->readFromInHMIiFile("HMI/shuttleChange").toInt());//自动换梭
        setItemValue(ROOT_TRACKROPEEMB,g_pSettings->readFromInHMIiFile("HMI/trackropeEmb").toInt());//跟踪绳绣
        setItemValue(ROOT_STEPPERDRIVE,g_pSettings->readFromInHMIiFile("HMI/stepDrive").toInt());//步进驱动
        setItemValue(ROOT_CAMCOLORCHANGE,g_pSettings->readFromInHMIiFile("HMI/camColorChange").toInt());//凸轮换色
        setItemValue(ROOT_BEAD,g_pSettings->readFromInHMIiFile("HMI/bead").toInt());//散珠
        setItemValue(ROOT_SEQUIN,g_pSettings->readFromInHMIiFile("HMI/sequin").toInt());//亮片
        setItemValue(ROOT_TOWEL,g_pSettings->readFromInHMIiFile("HMI/towel").toInt());//毛巾
        setItemValue(ROOT_COIL,g_pSettings->readFromInHMIiFile("HMI/coil").toInt());//缠绕
        setItemValue(ROOT_SIMPLETOWEL,g_pSettings->readFromInHMIiFile("HMI/simpleTowel").toInt());//简易毛巾
        setItemValue(ROOT_INDEFOOT,g_pSettings->readFromInHMIiFile("HMI/foot").toInt());//独立压脚
        setItemValue(ROOT_WATERMARKSET,g_pSettings->readFromInHMIiFile("HMI/waterMark").toInt());
        setItemValue(ROOT_WIFI,g_pSettings->readFromInHMIiFile("HMI/wifi").toInt());
        setItemValue(ROOT_GRADIENT,g_pSettings->readFromInHMIiFile("HMI/gradient").toInt());
        setItemValue(ROOT_PARASORTSET,g_pSettings->readFromInHMIiFile("HMI/paraSort").toInt());
        setItemValue(ROOT_FILESENDMODE,g_pSettings->readFromInHMIiFile("HMI/fileMode").toInt());
        refreshUi();
        break;

    case ROOT_IOTCONFIGURATION: //物联网配置
        setMainTitle(tr("IOT Configuration"));
        setSubTitle(tr("Root > IOT Configuration"));
        // 得到界面配置列表
        setItemList(factory,PARA_TYPE_IOTCONFIGURATION);//最高权限
        //设置参数值
        setItemValue(ROOT_GATEWAYCONNECTIONMETHOD,g_pSettings->readFromInHMIiFile("IOT/gatewayConnectMode").toInt()); //网关连接
        setItemValue(ROOT_RACKNUMBERINPUT,g_pSettings->readFromIniFile("IOT/rackNumber").toInt());//机架号
        setItemStr(ROOT_DELIVERYTIME,g_pSettings->readFromIniFile("IOT/deliveryTime").toString()); //工厂预计交货时间
        setItemValue(ROOT_DEBUGPROGRESS,g_pSettings->readFromIniFile("IOT/debugProgress").toInt());//调试进度

        refreshUi();
        break;

    case ROOT_FRAMEANGLESETTING: //动框角度设置
        emit siFrameAngleSet();
        break;

    case  ROOT_NETWORKSETTINGS: //网络设置
        setMainTitle(tr("Network Settings"));
        setSubTitle(tr("IOT Configuration > Network Settings"));
        //得到界面配置列表
        //setItemList(factory,PARA_TYPE_NETWORKSETTINGS);

        //设置参数值
        //setItemValue(ROOT_SERVERIPSETTINGS,g_pSettings->readFromIniFile("server/ip").toInt());  //服务器ip设置
        //setItemValue(ROOT_SERVERPORTSETTINGS);

        setGatewayNetworkItemList(PARA_TYPE_NETWORKSETTINGS);

        refreshUi();
        break;

    case ROOT_MACHINEPARA://加载机器参数
        //也用此窗体加载参数
        setMainTitle(tr("Machine parameters"));
        setSubTitle(tr("Root > Machine parameters"));
        //机器参数
        if(g_emUser == factory)
        {
            setItemList(factory,PARA_TYPE_MACH);//二级权限  262574
        }
        else
        {
            setItemList(root,PARA_TYPE_MACH);//最高权限  951103
        }

        if(m_setedFlag == 0x03)//如果有从下位机得到过参数包
        {
            refreshValue();//不管连没连上，都显示上次保存的值
        }
        if(g_pMachine->isConnected() == 3)
        {
            if(m_setedFlag != 0x03)//界面上显示已就绪  但是没有从下位机得到过参数包（刚上电时）
            {
                PromptDialog dlg(this);
                dlg.initDialog(PromptDialog::BTN_OK);
                dlg.setTitleStr(tr("Network error"));
                dlg.setContentStr(tr("read parameter..."));//读取参数中...
                dlg.exec();
            }
        }
        else
        {
#ifdef Q_OS_LINUX//为了方便windows下查看参数所以加了linux编译条件
            PromptDialog dlg(this);
            dlg.initDialog(PromptDialog::BTN_OK);
            dlg.setTitleStr(tr("Network error"));
            dlg.setContentStr(tr("No connection"));
            dlg.exec();
            done(0);
#endif
        }
        refreshUi();
        break;

    case ROOT_WORKPARA://加载工作参数
        //也用此窗体加载参数
        setMainTitle(tr("Work parameters"));
        setSubTitle(tr("Root > Work parameters"));
        //工作参数
        if(g_emUser == factory)
        {
            setItemList(factory,PARA_TYPE_WORK);//二级权限  262574
        }
        else
        {
            setItemList(root,PARA_TYPE_WORK);//最高权限  951103
        }

        if(m_setedFlag == 0x03)//如果有从下位机得到过参数包
        {
            refreshValue();//不管连没连上，都显示上次保存的值
        }
        if(g_pMachine->isConnected() == 3)
        {
            if(m_setedFlag != 0x03)//界面上显示已就绪  但是没有从下位机得到过参数包（刚上电时）
            {
                PromptDialog dlg(this);
                dlg.initDialog(PromptDialog::BTN_OK);
                dlg.setTitleStr(tr("Network error"));
                dlg.setContentStr(tr("read parameter..."));//读取参数中...
                dlg.exec();
            }
        }
        else
        {
#ifdef Q_OS_LINUX//为了方便windows下查看参数所以加了linux编译条件
            PromptDialog dlg(this);
            dlg.initDialog(PromptDialog::BTN_OK);
            dlg.setTitleStr(tr("Network error"));
            dlg.setContentStr(tr("No connection"));
            dlg.exec();
            done(0);
#endif
        }
        refreshUi();
        break;

    case ROOT_EMBHEADPARAMETER://加载平绣机头板参数
        g_pMachine->getHeadParasFromMachine(1,FLATEMB);//获取平绣机头板参数
        //也用此窗体加载参数
        setMainTitle(tr("EMB Head board parameters"));
        setSubTitle(tr("Root > EMB Head board parameters"));//超级用户 > 机头板参数
        //机头板参数
        setItemList(factory,PARA_TYPE_HEADPARAMETER);//最高权限
        if(m_hcpsFlag != 0)//如果有从下位机得到过参数包
        {
            refreshValue();//不管连没连上，都显示上次保存的值
        }
        if(g_pMachine->isConnected() == 3)
        {
            if(m_hcpsFlag == 0)//界面上显示已就绪  但是没有从下位机得到过参数包（刚上电时）
            {
                PromptDialog dlg(this);
                dlg.initDialog(PromptDialog::BTN_OK);
                dlg.setTitleStr(tr("Network error"));
                dlg.setContentStr(tr("read parameter..."));//读取参数中...
                dlg.exec();
            }
        }
        else
        {
#ifdef Q_OS_LINUX//为了方便windows下查看参数所以加了linux编译条件
            PromptDialog dlg(this);
            dlg.initDialog(PromptDialog::BTN_OK);
            dlg.setTitleStr(tr("Network error"));
            dlg.setContentStr(tr("No connection"));
            dlg.exec();
            done(0); //退出这个界面
            //加return 是不进行下边的函数，所以删掉
#endif
        }
        refreshUi();
        break;

    case ROOT_TOWELHEADPARAMETER://加载毛巾机头板参数
        g_pMachine->getHeadParasFromMachine(1,TOWEL);//获取平绣机头板参数
        //也用此窗体加载参数
        setMainTitle(tr("Chenille Head board parameters"));
        setSubTitle(tr("Root > Chenille Head board parameters"));//超级用户 > 毛巾机头板参数
        //机头板参数
        setItemList(factory,PARA_TYPE_TOWELHEADPARAMETER);//最高权限
        if(m_hcpsFlag != 0)//如果有从下位机得到过参数包
        {
            refreshValue();//不管连没连上，都显示上次保存的值
        }
        if(g_pMachine->isConnected() == 3)
        {
            if(m_hcpsFlag == 0)//界面上显示已就绪  但是没有从下位机得到过参数包（刚上电时）
            {
                PromptDialog dlg(this);
                dlg.initDialog(PromptDialog::BTN_OK);
                dlg.setTitleStr(tr("Network error"));
                dlg.setContentStr(tr("read parameter..."));//读取参数中...
                dlg.exec();
            }
        }
        else
        {
#ifdef Q_OS_LINUX//为了方便windows下查看参数所以加了linux编译条件
            PromptDialog dlg(this);
            dlg.initDialog(PromptDialog::BTN_OK);
            dlg.setTitleStr(tr("Network error"));
            dlg.setContentStr(tr("No connection"));
            dlg.exec();
            done(0); //退出这个界面
            //加return 是不进行下边的函数，所以删掉
#endif
        }
        refreshUi();
        break;

    case ROOT_COILHEADPARAMETER://加载缠绕机头板参数
        g_pMachine->getHeadParasFromMachine(1,COIL);//获取缠绕机头板参数
        //也用此窗体加载参数
        setMainTitle(tr("Coil Head board parameters"));
        setSubTitle(tr("Root > Coil Head board parameters"));//超级用户 > 缠绕机头板参数
        //机头板参数
        setItemList(factory,PARA_TYPE_COILHEADPARAMETER);//最高权限
        if(m_hcpsFlag != 0)//如果有从下位机得到过参数包
        {
            refreshValue();//不管连没连上，都显示上次保存的值
        }
        if(g_pMachine->isConnected() == 3)
        {
            if(m_hcpsFlag == 0)//界面上显示已就绪  但是没有从下位机得到过参数包（刚上电时）
            {
                PromptDialog dlg(this);
                dlg.initDialog(PromptDialog::BTN_OK);
                dlg.setTitleStr(tr("Network error"));
                dlg.setContentStr(tr("read parameter..."));//读取参数中...
                dlg.exec();
            }
        }
        else
        {
#ifdef Q_OS_LINUX//为了方便windows下查看参数所以加了linux编译条件
            PromptDialog dlg(this);
            dlg.initDialog(PromptDialog::BTN_OK);
            dlg.setTitleStr(tr("Network error"));
            dlg.setContentStr(tr("No connection"));
            dlg.exec();
            done(0); //退出这个界面
            //加return 是不进行下边的函数，所以删掉
#endif
        }
        refreshUi();
        break;

    case ROOT_HCPSPARAMETER://加载平绣换色板参数    //目前没用到
        g_pMachine->getHcpsParasFromMachine(2);//获取换色板参数
        //也用此窗体加载参数
        setMainTitle(tr("Color board parameters"));
        setSubTitle(tr("Root > Color board parameters"));//超级用户 > 换色板参数
        //换色板参数
        setItemList(factory,PARA_TYPE_HCPSPARAMETER);//最高权限
        if(m_hcpsFlag != 0)//如果有从下位机得到过参数包
        {
            refreshValue();//不管连没连上，都显示上次保存的值
        }
        if(g_pMachine->isConnected() == 3)
        {
            if(m_hcpsFlag == 0)//界面上显示已就绪  但是没有从下位机得到过参数包（刚上电时）
            {
                PromptDialog dlg(this);
                dlg.initDialog(PromptDialog::BTN_OK);
                dlg.setTitleStr(tr("Network error"));
                dlg.setContentStr(tr("read parameter..."));//读取参数中...
                dlg.exec();
            }
        }
        else
        {
#ifdef Q_OS_LINUX//为了方便windows下查看参数所以加了linux编译条件
            PromptDialog dlg(this);
            dlg.initDialog(PromptDialog::BTN_OK);
            dlg.setTitleStr(tr("Network error"));
            dlg.setContentStr(tr("No connection"));
            dlg.exec();
            done(0);
#endif
        }
        refreshUi();
        break;

    case ROOT_TOWELHCPSPARAMETER://加载毛巾换色板参数
        g_pMachine->getHcpsParasFromMachine(2);//获取毛巾换色板参数，nodeType=2
        //也用此窗体加载参数
        setMainTitle(tr("Chenille Color board parameters"));
        setSubTitle(tr("Root > Chenille Color board parameters"));//超级用户 > 换色板参数
        //换色板参数
        setItemList(factory,PARA_TYPE_TOWELHCPSPARAMETER);//最高权限
        if(m_hcpsFlag != 0)//如果有从下位机得到过参数包
        {
            refreshValue();//不管连没连上，都显示上次保存的值
        }
        if(g_pMachine->isConnected() == 3)
        {
            if(m_hcpsFlag == 0)//界面上显示已就绪  但是没有从下位机得到过参数包（刚上电时）
            {
                PromptDialog dlg(this);
                dlg.initDialog(PromptDialog::BTN_OK);
                dlg.setTitleStr(tr("Network error"));
                dlg.setContentStr(tr("read parameter..."));//读取参数中...
                dlg.exec();
            }
        }
        else
        {
#ifdef Q_OS_LINUX//为了方便windows下查看参数所以加了linux编译条件
            PromptDialog dlg(this);
            dlg.initDialog(PromptDialog::BTN_OK);
            dlg.setTitleStr(tr("Network error"));
            dlg.setContentStr(tr("No connection"));
            dlg.exec();
            done(0);
#endif
        }
        refreshUi();
        break;

    case ROOT_PATTERNPARAMETERS://超级用户花样参数
        //也用此窗体加载参数
        setMainTitle(tr("Pattern parameters"));
        setSubTitle(tr("Root > Pattern parameters"));
        //锁头测试参数
        setItemList(factory,PARA_TYPE__ROOT_PATTERN);//最高权限
        //setItemValue(SET_STEPCOMPENSATE,g_pSettings->readFromIniFile( "PatternPara/stepCompensation").toInt());
        setItemValue(SET_XCOMPENSATE,g_pSettings->readFromInHMIiFile("PatternPara/xCompensation").toInt());
        setItemValue(SET_YCOMPENSATE,g_pSettings->readFromInHMIiFile("PatternPara/yCompensation").toInt());
        //setItemValue(SET_LOCKNEEDLESNUM,g_pSettings->readFromInHMIiFile("PatternPara/lockNeedlesNum").toInt());// 锁针次数
        setItemValue(SET_LOCKNEEDLESSTEPNUM,g_pSettings->readFromInHMIiFile("PatternPara/lockNeedlesStepNum").toInt());// 锁针步数
        setItemValue(SET_LOCKNEEDLESSTEPLENTH,g_pSettings->readFromInHMIiFile("PatternPara/lockNeedlesStepLength").toInt());// 锁针针步长度
        setItemValue(SET_MINSTEP,g_pSettings->readFromInHMIiFile("PatternPara/minStep").toInt());// 过滤针步长度
        refreshUi();
        break;

    case ROOT_TRAVERSESET://进入遍历功能设置
        //也用此窗体加载参数
        setMainTitle(tr("Traverse settings"));
        setSubTitle(tr("Root > Traverse settings"));
        //遍历设置参数
        setItemList(factory,PARA_TYPE_ROOTTRAVERSE);//最高权限
        refreshUi();
        emit siTraverseSet(CSV_00_CODE_9);
        break;

    case ROOT_HEADBOARDBUSDETECT://机头板总线检测
        emit siHeadBoardBusDetect();
        break;

    case ROOT_AUTOSETSOFTLIMIT://自动定软限位
        emit siAutoSetSoftLimit();
        break;

    case ROOT_EMBLOCKTEST://进入平绣锁头测试
        //也用此窗体加载参数
        setMainTitle(tr("Embroidery lock test"));
        setSubTitle(tr("Root > Embroidery lock test"));
        //锁头测试参数
        setItemList(factory,PARA_TYPE_EMBLOCKTEST);//最高权限
        refreshUi();
        break;

    case ROOT_EMBHOOKTEST://进入平绣勾刀测试
        emit siHookTest();
        break;

    case ROOT_HMIDECRYPT://界面解密
        emit siHMIDecrypt(m_networkCardID);
        break;

    case ROOT_HEADUPDATE://平绣机头板升级
        emit siEXBBoardUpgrade(BN_PROTOCOL_HEAD,0,FLATEMB);
        break;

    case ROOT_TOWELHEADUPDATE://毛巾机头板升级
        emit siEXBBoardUpgrade(BN_PROTOCOL_HEAD,0,TOWEL);
        break;

    case ROOT_COILHEADUPDATE://缠绕机头板升级
        emit siEXBBoardUpgrade(BN_PROTOCOL_HEAD,0,COIL);
        break;

    case ROOT_HCPSUPDATE://换色板升级
        emit siEXBBoardUpgrade(BN_PROTOCOL_HCPS,0,0);
        break;

    case ROOT_CLEARPATTERN://花样总清
        emit siPatternClear();
        break;

    case ROOT_CHANGEPASSWORD://修改一级密码
        emit siChangePassword();
        break;

    case ROOT_DELETEINI://删除配置文件
        emit siDeleteIni();//删除执行目录下的config
        break;

    case ROOT_IMPORTCSV://导入CSV文件
        emit siImportCSV();
        break;

    case ROOT_DELETECSV://删除CSV文件
        emit siDeleteCSV();
        break;

    case ROOT_RESETCSV://重置安装调试进度
        emit siResetCSV();
        break;

    case ROOT_DEBUGMODE://界面进入调试模式
        emit siDebugMode();
        break;

    case ROOT_LIFTMOTORCONTROL://提升电机控制
        emit siLiftMotor();
        break;

    case ROOT_ELASTICCONTROL://松紧线控制
        emit siElasticCtrl();
        break;

    case ROOT_CHENILLECOLORDEBUG://毛巾换色调试
        emit siChenilleColorDebug();
        break;

    case ROOT_EMBSPINDlLEGEARRATIO://平绣主轴齿轮比测试
        emit siEMBSpindleTest();
        break;

    case ROOT_FLAT_ECD_WIDTH://测试平绣主轴编码器宽度
        emit siEcdWidthTest();
        break;

    case ROOT_FOOTTEST://独立压脚测试
        emit siFootTest();
        break;

    case ROOT_TOWELSPINDlLEGEARRATIO://毛巾主轴齿轮比测试
        emit siChenSpindleTest();
        break;

    case ROOT_EMBWORKAREA://平绣设置可工作区域
        emit siEmbWorkArea();
        done(0);
        break;

    case ROOT_CHENWORKAREA://毛巾设置可工作区域
        emit siChenWorkArea();
        done(0);
        break;

    case ROOT_COILWORKAREA://缠绕设置可工作区域
        emit siCoilWorkArea();
        done(0);
        break;

    case ROOT_FRAMEIMPORTPARA://动框参数导入
        emit siFrameParaImport();
        break;

    case ROOT_FRAMEEXPORTPARA://动框参数导出
        emit siFrameParaExport();
        break;

    case PSE_SOFTWAREPARA_IMPORTPARA://参数导入
        emit siParameterImport();
        break;

    case PSE_SOFTWAREPARA_EXPORTPARA://参数导出
        emit siParameterExport();
        break;

    case ROOT_CLEARPATTERNFCG://花样fcg删除
        emit siPatternFcgClear();
        break;

    case ROOT_CLEARPATTERNFCG_FILEID://删除花样fcg文件影响fileid的数据
        emit siPatternFcgClearFileid();
        break;

    case PSE_SOFTWAREPARA_HMIUPDATE://界面升级
        emit siHMIUpgrade();
        break;

    case PSE_SOFTWAREPARA_MCUPDATE://主控升级
        emit siMCUpgrade();
        break;
    case PSE_SOFTWAREPARA_EXIT://退出程序
        emit siExit();
        break;
    default:
        break;
    }
}

void ParameterSetDialog::initData()
{
    m_curPage = 0;
    m_rootCurPage = 0;
    m_paraType = 0;    //参数类型(机器参数、工作参数、花样参数等)
    m_paraTypeSort = 0;   //参数类型分类型(动作参数、位置参数、亮片参数等)
    if(g_emProductType == PRODUCT_EMB_EMB ||
            g_emMacType == QUIMACHINE_EMB)
    {
        m_nodeType = FLATEMB;//节点类型
    }
    else if(g_emProductType == PRODUCT_CHEN)
    {
        m_nodeType = TOWEL;//节点类型
    }

    ui->labelRepetitions->setText(tr("Repetitions : 0"));    //反复次数：0
    m_itemList.clear();
    m_patchItemList.clear();
    m_allItemList.clear();

    m_patchMode = PATCH_COLOR;
    if (m_setedFlag == 0)
    {
        memset(m_mcParaValues.buf, 0, sizeof(ParaStruct));
        memset(m_wkParaValues.buf, 0, sizeof(ParaStruct));
    }

    memset(m_headParaValues.paraBuf, 0, sizeof(m_headParaValues.paraBuf));
    memset(m_hcpsParaValues.paraBuf, 0, sizeof(m_hcpsParaValues.paraBuf));

    m_filePath.clear();
    memset(m_patchColorBuf, 0, sizeof(m_patchColorBuf));
    memset(m_patchNeedleBuf, 0, sizeof(m_patchNeedleBuf));
}

//设置类型图标
void ParameterSetDialog::setTypeLogo(QString tStyle)
{
    ui->buttonTypeLogo->setUnPreBtnLogo(tStyle);
}

//设置主title
void ParameterSetDialog::setMainTitle(QString str)
{
    ui->labelMainTitle->setText(str);
}

//设置副title
void ParameterSetDialog::setSubTitle(QString str)
{
    ui->labelSubTitle->setText(str);
}

//(参数权限、参数类型、参数种类)得到相应参数类型列表
// sort参数分类的小分类
void ParameterSetDialog::setItemList(int authority,int64_t type,int64_t sort)
{
    int language = g_pSettings->readFromInHMIiFile("HMI/language").toInt();

    m_paraType = type;
    m_paraTypeSort = sort;
    m_itemList.clear();//最后筛选出的列表

    //参数筛选
    for(int i = 0; i < m_allItemList.size(); i++)
    {
        int aType= m_allItemList.at(i).paraType;
        int aAuthority = m_allItemList.at(i).authority;

        //如果是界面配置且机型不为绣花机时无组合绣和隔头绣和激光，，自动换梭，散珠，亮片，毛巾,独立压脚配置功能
        if(type == PARA_TYPE_HMICONFIGURATION && g_emMacType != MACHINE_EMB)
        {
            if(m_allItemList[i].indexInPara == ROOT_COIL ||
                    m_allItemList[i].indexInPara == ROOT_SIMPLETOWEL ||
                    m_allItemList[i].indexInPara == ROOT_LASER ||
                    m_allItemList[i].indexInPara == ROOT_SHUTTLECHANGE ||
                    m_allItemList[i].indexInPara == ROOT_TRACKROPEEMB ||
                    m_allItemList[i].indexInPara == ROOT_STEPPERDRIVE ||
                    m_allItemList[i].indexInPara == ROOT_CAMCOLORCHANGE ||
                    m_allItemList[i].indexInPara == ROOT_BEAD ||
                    m_allItemList[i].indexInPara == ROOT_SEQUIN ||
                    m_allItemList[i].indexInPara == ROOT_TOWEL||
                    m_allItemList[i].indexInPara == ROOT_INDEFOOT
                    )
            {
                continue;//只结束本次循环,接着下一次的循环
            }
        }

        if((aType & type) == aType)
        {
            int aSort= m_allItemList.at(i).paraTypeSort;
            if(sort == -1)//等于-1加载全部
            {
                //外边传进来的权限  等于   factory
                if(authority == factory)//加载除了root所有的
                {
                    if(aAuthority != root)//如果当前的权限不是root，就是 factory和 operate repair的参数
                    {
                        m_itemList.append(m_allItemList.at(i));
                    }
                }
                else if(authority == root)
                {
                    m_itemList.append(m_allItemList.at(i));
                }
                else
                { //当前列表里的权限  等于  传进来的权限
                    if(aAuthority == authority)//参数权限
                    {
                        m_itemList.append(m_allItemList.at(i));
                        if(language == arabic)//阿拉伯语此字符不会加载出来，所以手动添加
                        {
                            if(m_itemList.last().paraType == PARA_TYPE_PATTERN &&
                                    m_itemList.last().indexInPara == SET_ROTATESTYLE &&
                                    m_itemList.last().valueType == PARA_VALUE_TYPE_LIST)
                            {
                                if(m_itemList.last().selList.size() <= 0)
                                {
                                    m_itemList.last().selList = "normalP:0;nRight90P:1;nRight180P:2;nRight270P:3;mirrorP:4;mRight90P:5;mRight180P:6;mRight270P:7";
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if((aSort & sort)== aSort)//参数类型
                {
                    if(authority == factory)//最高参数权限
                    {
                        if(aAuthority != root)
                        {
                            m_itemList.append(m_allItemList.at(i));
                        }
                    }
                    else if(authority == root)
                    {
                        m_itemList.append(m_allItemList.at(i));
                    }
                    else
                    {
                        if(aAuthority == authority)//参数权限
                        {
                            m_itemList.append(m_allItemList.at(i));
                        }
                    }
                }
            }
        }
    }
}

void ParameterSetDialog::refreshProductType()
{
    int mcType = 0;
    for(int i = 0; i < m_itemList.size(); i++)
    {
        if(m_itemList[i].indexInPara == ROOT_MACTYPE)
        {
            mcType = m_itemList[i].selIdx;
            break;
        }
    }

    for(int i = 0; i < m_itemList.size(); i++)
    {
        int index = m_itemList.at(i).indexInPara;

        if(index == ROOT_PRODUCTTYPE)//等于产品类型
        {
            switch (mcType) //机器类型
            {
            case MACHINE_EMB://绣花机
                if(m_itemList[i].selIdx > PRODUCT_EMB_FEED || m_itemList[i].selIdx < PRODUCT_EMB_EMB)   //  可选产品类型最大值最小值得范围
                {
                    g_emProductType = PRODUCT_EMB_EMB;
                    m_itemList[i].value = g_emProductType;
                    m_itemList[i].selIdx = g_emProductType;
                }
                m_itemList[i].minVal = PRODUCT_EMB_EMB;         //      可选最小值
                m_itemList[i].maxVal = PRODUCT_EMB_FEED;        //      可选最大值
                break;

            case QUIMACHINE_EMB://绗绣机
                if(m_itemList[i].selIdx > PRODUCT_QUI_DOUBLE || m_itemList[i].selIdx < PRODUCT_QUI_SINGLE)   //  可选产品类型最大值最小值得范围
                {
                    g_emProductType = PRODUCT_QUI_SINGLE;
                    m_itemList[i].value = g_emProductType;
                    m_itemList[i].selIdx = g_emProductType;
                }
                m_itemList[i].minVal = PRODUCT_QUI_SINGLE;         //      可选最小值
                m_itemList[i].maxVal = PRODUCT_QUI_DOUBLE;        //      可选最大值
                break;

            default://其他机型
                g_emProductType = PRODUCT_NULL;
                m_itemList[i].minVal = PRODUCT_NULL;
                m_itemList[i].maxVal = PRODUCT_NULL;
                m_itemList[i].value = PRODUCT_NULL;
                m_itemList[i].selIdx = g_emProductType;
                break;
            }
            break;
        }
    }
}

//设置贴布绣参数
void ParameterSetDialog::setPatchItemList(int64_t type,int64_t snum,int64_t cnum,QString filePath)
{
    m_paraType = type;
    m_itemList.clear();
    m_patchItemList.clear();

    ParaItem item;

    //按色贴布参数++++++
    //参数筛选(按色贴布参数)
    for(int i = 0; i < m_allItemList.size(); i++)
    {
        int aType= m_allItemList.at(i).paraType;

        if(aType == PARA_TYPE_PATTERNPATCH_COLOR)//按色贴布绣参数
        {
            item = m_allItemList.at(i);
            break;
        }
    }

    memset(m_patchColorBuf,0,sizeof(m_patchColorBuf));
    memset(m_patchNeedleBuf, 0, sizeof(m_patchNeedleBuf));

    m_filePath = filePath + ".fcg";
    QFile file(m_filePath);

    QByteArray fileAry;
    fileAry.clear();

    if(file.exists())//存在fcg文件
    {
        if(file.open(QIODevice::ReadOnly))
        {
            fileAry = file.readAll();
            int ofst = sizeof(DataFileHead)+HEADBUF+sizeof(m_patchColorBuf);

            if(fileAry.size() >= ofst)
            {
                ofst = sizeof(DataFileHead)+HEADBUF;
                memcpy(m_patchColorBuf,fileAry.data()+ofst,sizeof(m_patchColorBuf));
            }

            int nofst = sizeof(DataFileHead)+HEADBUF+PATCHCOLORBUF*sizeof(u16)+sizeof(m_patchNeedleBuf);
            if(fileAry.size() >= nofst)
            {
                nofst = sizeof(DataFileHead)+HEADBUF+PATCHCOLORBUF*sizeof(u16);
                memcpy(m_patchNeedleBuf,fileAry.data()+nofst,sizeof(m_patchNeedleBuf));
            }
        }
        file.close();
    }

    //    QFileInfo fileInfo(filePath);
    //    QString fileName = fileInfo.fileName();

    //添加色序对应的贴布绣参数
    for(int i = 1; i < cnum; i++)//8个色序
    {
        u16 val = m_patchColorBuf[i];
        //item.paraName = fileName + "    " + tr("colorOrder") + QString::number(i+1);//色序
        item.paraName = tr("colorOrder") + QString::number(i+1);//色序
        item.indexInPara = i+1;//贴布绣不显示第一个色序
        item.value = val;
        m_patchItemList.append(item);
    }
    //按色贴布参数++++++

    //按针贴布参数++++++
    //参数筛选
    for(int i = 0; i < m_allItemList.size(); i++)
    {
        int aType= m_allItemList.at(i).paraType;

        if(aType == PARA_TYPE_PATTERNPATCH_NEEDLE)
        {
            int idx = m_allItemList[i].indexInPara;
            if(idx < 1 || idx > 10)
            {
                return;
            }
            //m_allItemList[i].paraName = fileName + "    " + m_allItemList[i].paraName;
            if(m_allItemList[i].paraTypeSort == PATCH_SORT_IDX)
            {
                m_allItemList[i].maxVal = snum;
                m_allItemList[i].value = m_patchNeedleBuf[idx-1].needleIdx;
            }
            else  if(m_allItemList[i].paraTypeSort == PATCH_SORT_MOVE)
            {
                m_allItemList[i].value = m_patchNeedleBuf[idx-1].move;
            }
            m_patchItemList.append(m_allItemList.at(i));
        }
    }
    //按针贴布参数++++++

    //显示相应模式的贴布绣参数
    for(int i = 0; i < m_patchItemList.size(); i++)
    {
        int type = m_patchItemList[i].paraType;

        if(m_patchMode == PATCH_COLOR)
        {
            if(type == PARA_TYPE_PATTERNPATCH_COLOR)
            {
                m_itemList.append(m_patchItemList[i]);
            }
        }
        else
        {
            if(type == PARA_TYPE_PATTERNPATCH_NEEDLE)
            {
                m_itemList.append(m_patchItemList[i]);
            }
        }
    }
}

//设置网关网络参数(IP和端口)
void ParameterSetDialog::setGatewayNetworkItemList(int64_t type)
{
    m_paraType = type;
    m_itemList.clear();

    QDir apppath(qApp->applicationDirPath());
    QString serverip, localip;
    quint16  serverport, localport;
    //服务器IP及端口设置
    int idx = 0;
    QString  configfile;
    configfile = apppath.path() + apppath.separator() + "lotconfig.ini";
    QSettings configIni(configfile, QSettings::IniFormat);

    serverip = configIni.value("server/ip", QVariant("192.168.16.250")).toString();
    ParaItem slpItem;
    slpItem.indexInPara = idx;
    slpItem.readonly = 0;
    slpItem.valueType = PARA_VALUE_TYPE_STRINPUT;
    slpItem.paraName = tr("Server IP  settings"); //服务器IP设置;
    slpItem.valueStr = serverip;
    m_itemList.append(slpItem);

    serverport = configIni.value("server/port", QVariant(5001)).toInt();
    idx++;
    ParaItem sPortItem;
    sPortItem.indexInPara = idx;
    sPortItem.readonly = 0;
    sPortItem.valueType = PARA_VALUE_TYPE_INT;
    sPortItem.paraName = tr("Server Port settings") ;//服务器端口设置
    sPortItem.value = serverport;
    sPortItem.minVal = 0;
    sPortItem.maxVal = U16_MAX;
    sPortItem.defValue = serverport;
    m_itemList.append(sPortItem);

    //本地IP设置条目
    localip = configIni.value("local/ip", QVariant("192.168.16.100")).toString();
    idx ++;
    ParaItem lIpItem;
    lIpItem.indexInPara = idx;
    lIpItem.readonly = 0;
    lIpItem.valueType = PARA_VALUE_TYPE_STRINPUT;
    lIpItem.paraName = tr("Local IP settings");//本地IP设置
    lIpItem.valueStr = localip;
    m_itemList.append(lIpItem);

    localport = configIni.value("local/port", QVariant(5000)).toInt();
    idx++;
    ParaItem lPortItem;
    lPortItem.indexInPara = idx;
    lPortItem.readonly = 0;
    lPortItem.valueType = PARA_VALUE_TYPE_INT;
    lPortItem.paraName = tr("Local Port  settings");//本口端口设置
    lPortItem.value = localport;
    lPortItem.minVal = 0;
    lPortItem.maxVal = U16_MAX;
    lPortItem.defValue = localport;
    m_itemList.append(lPortItem);
}

//设置网络参数(IP和端口)
void ParameterSetDialog::setNetworkItemList(int64_t type)
{
    m_paraType = type;
    m_itemList.clear();

    QDir apppath(qApp->applicationDirPath());
    QString serverip,localip;
    quint16 serverport,localport;
    //服务器IP及端口设置条目(包括网关)
    int idx = 0;
    QString configfile;
    configfile = apppath.path() + apppath.separator() + "mcconfig.ini";//读取的配置文件名字
    QSettings configIni(configfile, QSettings::IniFormat);
    serverip = configIni.value("server/ip", QVariant("192.168.16.253")).toString();//把配置文件里的号转换成字符串
    localip = configIni.value("local/ip", QVariant("192.168.16.41")).toString();

    ParaItem sIpItem;
    sIpItem.indexInPara = idx;
    sIpItem.readonly = 0;
    sIpItem.valueType = PARA_VALUE_TYPE_STRINPUT;
    sIpItem.paraName = tr("Board IP settings");//主板IP设置
    sIpItem.valueStr = serverip;//列表里的值就显示从配置文件读上来的
    m_itemList.append(sIpItem);//把这行加到列表里

    serverport = configIni.value("server/port", QVariant(5000)).toInt();
    idx++;
    ParaItem sPortItem;
    sPortItem.indexInPara = idx;
    sPortItem.readonly = 0;
    sPortItem.valueType = PARA_VALUE_TYPE_INT;
    sPortItem.paraName = tr("Board port settings");//主板端口设置
    sPortItem.value = serverport;
    sPortItem.minVal = 0;
    sPortItem.maxVal = U16_MAX;
    sPortItem.defValue = serverport;
    m_itemList.append(sPortItem);

    idx++;

    //本地IP设置条目
    ParaItem lIpItem;
    lIpItem.indexInPara = idx;
    lIpItem.readonly = 0;
    lIpItem.valueType = PARA_VALUE_TYPE_STRINPUT;
    lIpItem.paraName = tr("Local IP settings");//本地IP设置
    lIpItem.valueStr = localip;
    m_itemList.append(lIpItem);
    idx++;

    //本地端口设置条目
    localport = configIni.value("local/port", QVariant(5000)).toInt();

    ParaItem lPortItem;
    lPortItem.indexInPara = idx;
    lPortItem.readonly = 0;
    lPortItem.valueType = PARA_VALUE_TYPE_INT;
    lPortItem.paraName = tr("Local port settings");//本地端口设置
    lPortItem.value = localport;
    lPortItem.minVal = 0;
    lPortItem.maxVal = U16_MAX;
    lPortItem.defValue = 5000;
    m_itemList.append(lPortItem);
}

void ParameterSetDialog::setCurPage(int idx)
{
    if(m_paraType == PARA_TYPE_ROOT)//等于超级用户界面
    {
        m_rootCurPage = idx;
    }
    else
    {
        m_curPage = idx;
    }
}

//设置参数值
void ParameterSetDialog::setItemValue(int idx,int value)
{
    for(int i = 0; i < m_itemList.size(); i++)
    {
        int index = m_itemList.at(i).indexInPara;
        int min = m_itemList.at(i).minVal;
        int max = m_itemList.at(i).maxVal;

        if(idx == index)//参数枚举
        {
            if(value > max || value < min) //
            {
                value = m_itemList.at(i).defValue;
            }
            m_itemList[i].selIdx = value;
            m_itemList[i].value = value;
        }
    }
}

void ParameterSetDialog::addBeadSequinParaItem(int idx, int value)
{
    ParaItem item;
    item.clean();
    item.paraType = PARA_TYPE_REPEATEMBPARA;
    item.indexInPara = idx;
    item.valueType = PARA_VALUE_TYPE_LIST;  // PARA_VALUE_TYPE_INT;
    QString str = tr("Bead sequin") + QString::number(idx-SET_BEADSEQUIN);
    item.paraName = str;
    item.minVal = 0;
    item.maxVal = 31;
    item.value = value;
    item.authority = 0x1000;

    int sequin = g_pSettings->readFromInHMIiFile("HMI/sequin").toInt();//是否有亮片功能
    int bead = g_pSettings->readFromInHMIiFile("HMI/bead").toInt();//是否有散珠功能

    if ((sequin == 1) && (bead == 1))
    {// 亮片散珠都有
        item.selList = (tr("Embroider:0;"      // 平绣
                        "Sequin 1:1;"       // 亮片1
                        "Sequin 2:2;"       // 亮片2
                        "Sequin 3:3;"       // 亮片3
                        "Sequin 4:4;"       // 亮片4
                        "Sequin 5:5;"       // 亮片5
                        "Sequin 6:6;"       // 亮片6
                        "Sequin 7:7;"       // 亮片7
                        "Sequin 8:8;"       // 亮片8
                        "Sequin double:16;" // 叠片
                        "Bead 1:17;"        // 散珠1
                        "Bead 2:18;"        // 散珠2
                        "Bead 3:19")        // 散珠3
                             );
    }
    else if ((sequin == 1) && (bead == 0))
    {// 只有亮片
        if ((value >= 0x11) && (value <= 0x1f))
        {
            value = 0;
        }

        item.selList = (tr("Embroider:0;"      // 平绣
                        "Sequin 1:1;"       // 亮片1
                        "Sequin 2:2;"       // 亮片2
                        "Sequin 3:3;"       // 亮片3
                        "Sequin 4:4;"       // 亮片4
                        "Sequin 5:5;"       // 亮片5
                        "Sequin 6:6;"       // 亮片6
                        "Sequin 7:7;"       // 亮片7
                        "Sequin 8:8;"       // 亮片8
                        "Sequin double:16") // 叠片
                             );
    }
    else if ((sequin == 0) && (bead == 1))
    {// 只有散珠
        if ((value >= 0x01) && (value <= 0x10))
        {
            value = 0;
        }

        item.selList = (tr("Embroider:0;"      // 平绣
                        "Bead 1:17;"        // 散珠1
                        "Bead 2:18;"        // 散珠2
                        "Bead 3:19")        // 散珠3
                             );
    }

    item.selIdx = value;
    item.defIdx = 0;

    m_itemList.append(item);
}
/*
 *
    int64_t mcenSel;        // 机型选择
    int     paraType;       // 参数类型(机器参数、工作参数、花样设置参数...)
    int     paraTypeSort;   // 参数类型分类(机器参数的速度参数、机器参数的动作参数...)

    int     indexInPara;    // 参数索引，-1，提示型显示; >= 0，该条目在参数中的位置
    int     bitInWord;      // 参数位索引
    int     readonly;       // 只读标志
    int     valueType;      // 参数值类型 = 0, 无值; = 1, 数字输入型; = 2, 开关选择型; = 3, 列表选择型; = 4, 字符输入型
public:
    QString paraName;       // 参数名称
public:
    int64_t value;          // 数字输入型数值
    int64_t minVal;         // 输入值范围下限
    int64_t maxVal;         // 输入值范围上限
    int64_t defValue;       // 默认值
    int     afterPoint;     // 保留小数位数
    QString unitStr;        // 单位
    QString valueStr;       // 字符输入型字符

public:
    QString selList;        // 列表选择型参数列表,通过"\n"来分割
    int     selIdx;         // 选择项目
    int     defIdx;         // 默认选择
public:
    int     showPriority;   // 显示优先级
    int     authority;      // 参数权限
*/

void ParameterSetDialog::setItemStr(int idx, QString str)
{
    for(int i = 0; i < m_itemList.size(); i++)
    {
        int index = m_itemList.at(i).indexInPara;

        if(idx == index)
        {
            m_itemList[i].valueStr = str;
        }
    }
}

int ParameterSetDialog::getItemValue(int idx)
{
    int value = 0;
    for(int i = 0; i < m_itemList.size(); i++)
    {
        if(idx == m_itemList.at(i).indexInPara)
        {
            value = m_itemList.at(i).value;
        }
    }
    return value;
}

int ParameterSetDialog::exec()
{
    //等于机器参数或工作参数
    if(((m_paraType & PARA_TYPE_MACH) == PARA_TYPE_MACH) ||
            ((m_paraType & PARA_TYPE_WORK) == PARA_TYPE_WORK) ||
            ((m_paraType & PARA_TYPE_HEADPARAMETER) == PARA_TYPE_HEADPARAMETER) ||
            ((m_paraType & PARA_TYPE_TOWELHEADPARAMETER) == PARA_TYPE_TOWELHEADPARAMETER) ||
            ((m_paraType & PARA_TYPE_TOWELHCPSPARAMETER) == PARA_TYPE_TOWELHCPSPARAMETER) ||
            ((m_paraType & PARA_TYPE_COILHEADPARAMETER) == PARA_TYPE_COILHEADPARAMETER) ||
            ((m_paraType & PARA_TYPE_HCPSPARAMETER) == PARA_TYPE_HCPSPARAMETER) )
    {
        if (g_pMachine != NULL)
        {
            qDebug("send GetParasFromMachine");

            if(m_setedFlag == 0x03)//如果有从下位机得到过参数包
            {
                //这个函数会把从主控得到的参数保存在item.value里
                refreshValue();//不管连没连上，都显示上次保存的值，多主板保存各自主板的值
            }

            if(g_pMachine->isConnected() == 3)//这个isConnected检测机制是5秒
            {
                if(((m_paraType & PARA_TYPE_MACH) == PARA_TYPE_MACH) ||
                        ((m_paraType & PARA_TYPE_WORK) == PARA_TYPE_WORK))
                {
                    // 多主板的之前就设置好了g_pMachine   点哪个按钮，就用向哪个主板获取参数
                    g_pMachine->getParasFromMachine();//如果连上了主板，发送一个读取参数信息的包
                }
                else if((m_paraType & PARA_TYPE_HEADPARAMETER) == PARA_TYPE_HEADPARAMETER)
                {
                    g_pMachine->getHeadParasFromMachine(1,FLATEMB);//获取平绣机头板参数
                }
                else if((m_paraType & PARA_TYPE_TOWELHEADPARAMETER) == PARA_TYPE_TOWELHEADPARAMETER)
                {
                    g_pMachine->getHeadParasFromMachine(1,TOWEL);//获取毛巾机头板参数
                }
                else if((m_paraType & PARA_TYPE_COILHEADPARAMETER) == PARA_TYPE_COILHEADPARAMETER)
                {
                    g_pMachine->getHeadParasFromMachine(1,COIL);//获取缠绕机头板参数
                }
                else if((m_paraType & PARA_TYPE_HCPSPARAMETER) == PARA_TYPE_HCPSPARAMETER)
                {
                    //根据nodeType判断是读取毛巾还是平绣
                    g_pMachine->getHcpsParasFromMachine(2);//获取毛巾换色板参数
                }
                if(m_setedFlag != 0x03)//界面上显示已就绪  但是没有从下位机得到过参数包（刚上电时）
                {
                    PromptDialog dlg(this);
                    dlg.initDialog(PromptDialog::BTN_OK);
                    dlg.setTitleStr(tr("Network error"));
                    dlg.setContentStr(tr("read parameter..."));//读取参数中...
                    dlg.exec();
                    return -1;
                }
            }
            else//如果没连接上
            {
#ifdef Q_OS_LINUX//为了方便windows下查看参数所以加了linux编译条件
                PromptDialog dlg(this);
                dlg.initDialog(PromptDialog::BTN_OK);
                dlg.setTitleStr(tr("Network error"));
                dlg.setContentStr(tr("No connection"));
                dlg.exec();
                return -1;
                //不进行下边的函数
#endif
            }
        }
    }
    //刷新这个函数，就显示item.value的值
    //ui->buttonOk->setEnabled(false);
    refreshUi();//没连接主板的时候就先进到这个函数,就会显示的默认参数
    return QDialog::exec();
}

int ParameterSetDialog::addParaItem(const QList<ParaItem> &itemList)
{
    int size = m_allItemList.size();
    m_allItemList.append(itemList);
    return size;
}

int ParameterSetDialog::addParaItem(const ParaItem &item)
{
    int size = m_allItemList.size();
    m_allItemList.append(item);
    return size;
}

//设置机器状态(用于刷新遍历状态)
void ParameterSetDialog::setMcStates(MCStatus mcStatus)
{
    memset((char*)&m_mcStatus,0,sizeof(MCStatus));
    memcpy((char*)&m_mcStatus,(char*)&mcStatus,sizeof(MCStatus));

    if(m_paraType == PARA_TYPE_REPEATEMBPARA)
    {
        u32 iterationsNum = (m_mcStatus.iterationsNum & 0x000000FF);
        ui->labelRepetitions->setText(tr("Repetitions : ")+QString::number(iterationsNum));//反复次数：
        return;
    }
    //等于遍历参数
    if((m_paraType & PARA_TYPE_ROOTTRAVERSE) == PARA_TYPE_ROOTTRAVERSE)
    {
        u32 traverseState = m_mcStatus.traverseState;//遍历状态
        u32 traverseState1 = m_mcStatus.tempdat2;//遍历状态2
        int towel = g_pSettings->readFromInHMIiFile("HMI/towel").toInt();//是否有毛巾功能
        int coil = g_pSettings->readFromInHMIiFile("HMI/coil").toInt();//是否有缠绕功能
        if ((towel == 1) ||
                ( coil == 1)||
                (g_emProductType == PRODUCT_CHEN)
                )
        {
            //刷新遍历状态
            for(int i = 0; i < m_itemList.size(); i++)
            {
                if(m_itemList[i].paraTypeSort == ROOT_SORT_CHENSENSOR)//信号参数
                {
                    //读取机头遍历状态(遍历功能)
                    int NoseNum = 0;//不赋初值，就要保证在各种情况下都有值   -rq
                    if(m_nodeType == FLATEMB)
                    {
                        NoseNum = m_mcParaValues.buf[2];//平绣机头个
                    }
                    else if(m_nodeType == TOWEL)
                    {
                        NoseNum = m_mcParaValues.buf[8];//毛巾机头个数
                    }
                    else if(m_nodeType == COIL)
                    {
                        NoseNum = m_mcParaValues.buf[7];//缠绕机头个数
                    }
                    //刷新信号参数 （-N -Y）
                    refreshSensorPara(m_itemList[i].minVal,m_itemList[i].maxVal,NoseNum,m_itemList[i],traverseState,traverseState1,m_nodeType);
                }
            }
        }
        else
        {
            //刷新遍历状态
            for(int i = 0; i < m_itemList.size(); i++)
            {
                if(m_itemList[i].paraTypeSort == ROOT_SORT_EMBSENSOR)//信号参数
                {
                    //读取机头遍历状态(遍历功能)
                    int NoseNum = 0;//不赋初值，就要保证在各种情况下都有值   -rq
                    if(m_nodeType == FLATEMB)
                    {
                        NoseNum = m_mcParaValues.buf[2];//平绣机头个
                    }
                    //刷新信号参数 （-N -Y）
                    refreshSensorPara(m_itemList[i].minVal,m_itemList[i].maxVal,NoseNum,m_itemList[i],traverseState,traverseState1,m_nodeType);
                }
            }
        }
    }
}

void ParameterSetDialog::on_button1_clicked()
{
    changeValue(0);
}

void ParameterSetDialog::on_button2_clicked()
{
    changeValue(1);
}

void ParameterSetDialog::on_button3_clicked()
{
    changeValue(2);
}

void ParameterSetDialog::on_button4_clicked()
{
    changeValue(3);
}

void ParameterSetDialog::on_button5_clicked()
{
    changeValue(4);
}

void ParameterSetDialog::on_button6_clicked()
{
    changeValue(5);
}

void ParameterSetDialog::on_button7_clicked()
{
    changeValue(6);
}

void ParameterSetDialog::on_button8_clicked()
{
    changeValue(7);
}

void ParameterSetDialog::on_button9_clicked()
{
    changeValue(8);
}

void ParameterSetDialog::on_button10_clicked()
{
    changeValue(9);
}

void ParameterSetDialog::on_button11_clicked()
{
    changeValue(10);
}

void ParameterSetDialog::on_button12_clicked()
{
    changeValue(11);
}

void ParameterSetDialog::on_buttonPgUp_clicked()
{
    if(m_paraType == PARA_TYPE_ROOT)//等于超级用户界面
    {
        m_rootCurPage--;
    }
    else
    {
        m_curPage--;
    }

    refreshUi();
}

void ParameterSetDialog::on_buttonPgDn_clicked()
{
    if(m_paraType == PARA_TYPE_ROOT)//等于超级用户界面
    {
        m_rootCurPage++;
    }
    else
    {
        m_curPage++;
    }
    refreshUi();
}

void ParameterSetDialog::on_buttonOk_clicked()
{
    PromptDialog promptDlg(this);
    qDebug()<<"para ok 1";

    //等于遍历参数
    if((m_paraType & PARA_TYPE_ROOTTRAVERSE) == PARA_TYPE_ROOTTRAVERSE)
    {
        qDebug()<<"para ok 2";

        int para1,para2,para3,para4;
        para1 = para2 = para3 = para4 = 0;

        promptDlg.initDialog(PromptDialog::BTN_OK_CANCEL);
        promptDlg.setTitleStr(tr("Prompt"));
        promptDlg.setContentStr(tr("Whether to start traversing settings?"));//是否开始遍历设置?
        if(promptDlg.exec() == 1)
        {
            if(m_itemList.size() <= 0){return;}

            para1 = m_itemList[0].value;//协议类型
            para2 = m_itemList[1].value;//节点类型
            para3 = m_itemList[2].value;//遍历模式

            if(para3)//单独遍历
            {
                //起始ID等于设置的机头号
                para4 = m_itemList[3].value;
            }
            else //全部遍历(数值为1)
            {
                //起始ID等于1
                para4 = 1;
            }

            if(g_pMachine != NULL)
            {
                g_pMachine->enterOrExitStates(UCMD_TRA_BOARD,para1,para2,para3,para4);
            }
        }

        qDebug()<<"para ok 3";
        return;
    }

    //等于平绣锁头测试参数
    if((m_paraType & PARA_TYPE_EMBLOCKTEST) == PARA_TYPE_EMBLOCKTEST)
    {
        int para = 0;
        promptDlg.initDialog(PromptDialog::BTN_OK_CANCEL);
        promptDlg.setTitleStr(tr("Prompt"));
        promptDlg.setContentStr(tr("Whether to start embroidery lock test?"));//是否开始平绣锁头测试?
        if(promptDlg.exec() == 1)
        {
            if(m_itemList.size() <= 0){return;}
            para = m_itemList[0].value;

            if(g_pMachine != NULL)
            {
                g_pMachine->testLockMoto(para);
                //g_pMachine->lockTest(TEST_EMBROIDERY,para);
            }
        }
        return;
    }

    //等于超级用户花样参数
    if((m_paraType & PARA_TYPE__ROOT_PATTERN) == PARA_TYPE__ROOT_PATTERN)
    {
        // int para = 0;
        if(m_itemList.size() <= 0){return;}//是超级用户的花样参数
        //        int StepCompensation = getItemValue(SET_STEPCOMPENSATE);    //针步补偿
        //        g_pSettings->writeToIniFile("PatternPara/stepCompensation",StepCompensation);
        int StepXCompensation = getItemValue(SET_XCOMPENSATE);    //X针步补偿
        g_pSettings->writeToInHMIiFile("PatternPara/xCompensation",StepXCompensation);
        int StepYCompensation = getItemValue(SET_YCOMPENSATE);    //Y针步补偿
        g_pSettings->writeToInHMIiFile("PatternPara/yCompensation",StepYCompensation);
//        int StepLockNeedlesNum = getItemValue(SET_LOCKNEEDLESNUM);    // 锁针次数
//        g_pSettings->writeToInHMIiFile("PatternPara/lockNeedlesNum",StepLockNeedlesNum);
        int StepLockNeedlesStepNum = getItemValue(SET_LOCKNEEDLESSTEPNUM);    // 锁针步数
        g_pSettings->writeToInHMIiFile("PatternPara/lockNeedlesStepNum",StepLockNeedlesStepNum);
        int StepLockNeedlesStepLength = getItemValue(SET_LOCKNEEDLESSTEPLENTH);    // 锁针针步长度
        g_pSettings->writeToInHMIiFile("PatternPara/lockNeedlesStepLength",StepLockNeedlesStepLength);
        int MinStep = getItemValue(SET_MINSTEP);    // 过滤针步长度
        g_pSettings->writeToInHMIiFile("PatternPara/minStep",MinStep);

        done(1);//关闭窗体，并返回1
    }

    //等于机器参数或工作参数
    if(((m_paraType & PARA_TYPE_MACH) == PARA_TYPE_MACH) ||
            ((m_paraType & PARA_TYPE_WORK) == PARA_TYPE_WORK))
    {
        qDebug()<<"para ok 4";
        saveParas();
        if(g_pMachine->isConnected() == 3)
        {
            promptDlg.initDialog(PromptDialog::BTN_OK);
            promptDlg.setTitleStr(tr("Prompt"));
            QString str;
            str = tr("Parameters saved successfully!");//参数保存成功！
            promptDlg.setContentStr(str);
            promptDlg.exec();
        }
    }

    //等于机头板参数或换色板参数
    if(((m_paraType & PARA_TYPE_HEADPARAMETER) == PARA_TYPE_HEADPARAMETER) ||
            ((m_paraType & PARA_TYPE_TOWELHEADPARAMETER) == PARA_TYPE_TOWELHEADPARAMETER) ||
            ((m_paraType & PARA_TYPE_TOWELHCPSPARAMETER) == PARA_TYPE_TOWELHCPSPARAMETER) ||
            ((m_paraType & PARA_TYPE_COILHEADPARAMETER) == PARA_TYPE_COILHEADPARAMETER) ||
            ((m_paraType & PARA_TYPE_HCPSPARAMETER) == PARA_TYPE_HCPSPARAMETER))
    {
        saveParas();
        if(g_pMachine->isConnected() == 3)
        {
            promptDlg.initDialog(PromptDialog::BTN_OK);
            promptDlg.setTitleStr(tr("Prompt"));
            QString str;
            str = tr("Parameters saved successfully!");//参数保存成功！
            promptDlg.setContentStr(str);
            promptDlg.exec();
        }
    }

    //等于软件设置参数
    if((m_paraType & PARA_TYPE_SOFTWARESET) == PARA_TYPE_SOFTWARESET)
    {
        qDebug()<<"para ok 5";

        promptDlg.initDialog(PromptDialog::BTN_OK_CANCEL);
        promptDlg.setTitleStr(tr("Prompt"));

        QString str;
        str = tr("The settings take effect after restarting the interface!");//重启界面后设置生效!
        promptDlg.setContentStr(str);
        if(promptDlg.exec() == 1)
        {
            g_emTheme = (Theme)(m_itemList.at((s16)SET_THEME).value);//主题
            int language = m_itemList.at((s16)SET_LANGUAGE).value;//语言
            int fontsize =  m_itemList.at((s16)SET_FONTSIZE).value;//字体大小
            //int connectMode = m_itemList.at((s16)SET_CONNECTMODE).value;//连接通讯方式

            g_pSettings->writeToIniFile("HMI/theme",g_emTheme);
            g_pSettings->writeToInHMIiFile("HMI/language",language);
            g_pSettings->writeToInHMIiFile("HMI/fontsize",fontsize);
            //g_pSettings->writeToIniFile("HMI/connectMode",connectMode);

#ifdef Q_OS_LINUX
            //因为韩语需要batang.ttf的字体才能显示，所以需要将batang.ttf拷贝到user/lib/fonts目录中
            QDir apppath(qApp->applicationDirPath());
            if(language == korean)
            {
                QString skoreanFontPath = apppath.path()+apppath.separator()+"batang.ttf";
                QString tkoreanFontPath = LINUXFONTPATH;
                tkoreanFontPath += "batang.ttf";
                QFile::copy(skoreanFontPath,tkoreanFontPath);
                system("sync");
            }
#endif

#ifdef Q_OS_WIN
            qApp->exit();
#endif

#ifdef Q_OS_LINUX
            qDebug()<<"reboot before";
            system("reboot");
            qDebug()<<"reboot end";
#endif
        }

        qDebug()<<"para ok 6";
        return;
    }

    //等于网络管理参数
    if((m_paraType & PARA_TYPE_NETWORKSET) == PARA_TYPE_NETWORKSET)
    {
        qDebug()<<"para ok 7";

        //网络设置完成,需重启后重新建立连接
        promptDlg.initDialog(PromptDialog::BTN_OK_CANCEL);
        QString str = tr("Network settings are completed, re-establish after reboot");
        promptDlg.setTitleStr(tr("Prompt"));
        promptDlg.setContentStr(str);
        if(promptDlg.exec() == 1)
        {
            QDir apppath(qApp->applicationDirPath());

            s16 idx = 0;//参数索引
            QString configfile;
            configfile = apppath.path() + apppath.separator() + "mcconfig.ini";
            QSettings configIni(configfile, QSettings::IniFormat);

            QString serverip = m_itemList.at(idx).valueStr;//服务器IP
            idx++;
            int serverport = m_itemList.at(idx).value;//服务器端口

            // 回写参数
            configIni.setValue("server/ip", serverip);
            configIni.setValue("server/port", serverport);

            idx++;

            QString localip = m_itemList.at(idx).valueStr;//本地IP
            // 回写参数
            configIni.setValue("local/ip", localip);

            idx++;

            int localport = m_itemList.at(idx).value;//本地端口
            // 回写参数
            configIni.setValue("local/port", localport);

#ifdef Q_OS_WIN
            qApp->exit();
#endif

#ifdef Q_OS_LINUX
            system("reboot");
#endif
        }
        return;
    }

    //等于网关网络设置参数
    if((m_paraType & PARA_TYPE_NETWORKSETTINGS) == PARA_TYPE_NETWORKSETTINGS)
    {
        //网络设置完成,需重启后重新建立连接
        promptDlg.initDialog(PromptDialog::BTN_OK_CANCEL);
        QString str = tr("Network settings are completed, re-establish after reboot");
        promptDlg.setTitleStr(tr("Prompt"));
        promptDlg.setContentStr(str);
        if(promptDlg.exec() == 1)
        {
            QDir apppath(qApp->applicationDirPath());

            s16 idx =0; //参数索引
            QString  configfile;
            configfile = apppath.path() + apppath.separator() +"lotconfig.ini";
            QSettings configIni(configfile, QSettings::IniFormat);

            QString serverip = m_itemList.at(idx).valueStr;//服务器IP
            idx++;
            int serverport = m_itemList.at(idx).value;//服务器端口
            idx++;
            QString localip = m_itemList.at(idx).valueStr;//本地IP
            idx++;
            int localport = m_itemList.at(idx).value;//本地端口

            // 回写参数
            configIni.setValue("server/ip", serverip);
            configIni.setValue("server/port", serverport);
            configIni.setValue("local/ip", localip);
            configIni.setValue("local/port", localport);

#ifdef Q_OS_WIN
            qApp->exit();
#endif

#ifdef Q_OS_LINUX
            system("reboot");
#endif
        }
        return;
    }

    //等于时间设置参数
    if((m_paraType & PARA_TYPE_TIMESET) == PARA_TYPE_TIMESET)
    {
        int yearValue = m_itemList.at(0).value;
        int monthValue = m_itemList.at(1).value;
        int dayValue = m_itemList.at(2).value;

#ifdef Q_OS_LINUX
        int hourValue = m_itemList.at(3).value;
        int minuteValue = m_itemList.at(4).value;
        int secondValue = m_itemList.at(5).value;
#endif

        int temp = 0;

        //判断是否为闰年，闰年2月份是29天，其他是28天
        if((yearValue % 4 == 0) && (yearValue % 100 != 0))
        {
            if(monthValue == 2)
            {
                if(dayValue > 29)
                {
                    temp = -1;
                }
            }
        }
        else
        {
            if(monthValue == 2)
            {
                if(dayValue > 28)
                {
                    temp = -1;
                }
            }
        }

        //1、3、5、7、8、10、12是31天，其他是30天
        if(monthValue == 4 || monthValue == 6 || monthValue == 9 || monthValue == 11)
        {
            if(dayValue > 30)
            {
                temp = -1;
            }
        }

        QString  showStr;
        if(temp == 0)
        {
            //设置时间
#ifdef Q_OS_LINUX
            struct tm rtcTime;
            rtcTime.tm_year = yearValue - 1900;
            rtcTime.tm_mon = monthValue - 1;
            rtcTime.tm_mday = dayValue;
            rtcTime.tm_hour = hourValue;
            rtcTime.tm_min = minuteValue;
            rtcTime.tm_sec = secondValue;
            rtcTime.tm_isdst = 0;
            rtcTime.tm_yday = 0;
            rtcTime.tm_wday = 0;

            int retval = hal_set_rtc_time(&rtcTime);
            if(retval != 0)
            {
                qDebug("set_rtc_time failed: %d!", retval);
                temp = -2;
            }
#endif
            //时间设置完成,重启后生效
            promptDlg.initDialog(PromptDialog::BTN_RESTART);
            showStr = tr("The time setting is completed and will take effect after restart");
        }
        else if(temp == -1)
        {
            //时间设置不合理,请重新设置
            promptDlg.initDialog(PromptDialog::BTN_OK);
            showStr = tr("Unreasonable time setting, please reset");
        }

        if(temp == -2)
        {
            //时间设置失败,请重新设置
            promptDlg.initDialog(PromptDialog::BTN_OK);
            showStr = tr("Time setting failed, please reset");
        }

        promptDlg.setTitleStr(tr("Prompt"));
        promptDlg.setContentStr(showStr);
        promptDlg.exec();
        return;
    }

    //等于贴布绣参数
    if(((m_paraType & PARA_TYPE_PATTERNPATCH_COLOR) == PARA_TYPE_PATTERNPATCH_COLOR) ||
            ((m_paraType & PARA_TYPE_PATTERNPATCH_NEEDLE) == PARA_TYPE_PATTERNPATCH_NEEDLE))
    {
        QList <ParaItem> itemColorList;
        itemColorList.clear();
        QList <ParaItem> itemNeedleList;
        itemNeedleList.clear();

        for(int i = 0; i < m_patchItemList.size(); i++)
        {
            if(m_patchItemList[i].paraType == PARA_TYPE_PATTERNPATCH_COLOR)
            {
                itemColorList.append(m_patchItemList[i]);
            }
            if(m_patchItemList[i].paraType == PARA_TYPE_PATTERNPATCH_NEEDLE)
            {
                itemNeedleList.append(m_patchItemList[i]);
            }
        }

        for(int i = 0; i < itemColorList.size(); i++)
        {
            u16 value = itemColorList[i].value;
            m_patchColorBuf[i+1] = value;//贴布绣不显示第一个色序，从第二个开始
        }

        int j = 0;
        for(int i = 0; i < itemNeedleList.size();)
        {
            m_patchNeedleBuf[j].needleIdx = itemNeedleList[i].value;
            m_patchNeedleBuf[j].move = itemNeedleList[i+1].value;
            j++;
            i += 2;
        }
    }

    //等于超级用户界面配置参数
    if((m_paraType & PARA_TYPE_HMICONFIGURATION) == PARA_TYPE_HMICONFIGURATION)
    {
        qDebug()<<"para ok 5";

        promptDlg.initDialog(PromptDialog::BTN_OK_CANCEL);
        promptDlg.setTitleStr(tr("Prompt"));

        QString str;
        str = tr("The settings take effect after restarting the interface!");//重启界面后设置生效!
        promptDlg.setContentStr(str);
        if(promptDlg.exec() == 1)
        {
            //界面配置里的参数都放在了 点击触发型参数枚举 里,要筛选才能获取到相应的value值
            for(int i = 0; i < m_itemList.size(); i++)
            {
                if(m_itemList[i].indexInPara == ROOT_RESOLUTION)
                {
                    g_emResolut = (Resolution)(m_itemList[i].value);//分辨率
                    g_pSettings->writeToIniFile("HMI/resolution",g_emResolut);
                }
                else if (m_itemList[i].indexInPara == SET_CONNECTMODE)
                {
                    int connectMode = (s16)m_itemList[i].value;//连接通讯方式
                    g_pSettings->writeToIniFile("HMI/connectMode",connectMode);
                }

                else if(m_itemList[i].indexInPara == ROOT_PRODUCTTYPE)
                {
                    g_emProductType =(ProductType)(m_itemList[i].value);//产品类型
                    g_pSettings->writeToIniFile("HMI/productType",g_emProductType);
                }

                else if(m_itemList[i].indexInPara == ROOT_COMBINEEMB)
                {
                    s16 combineEmb =(s16)(m_itemList[i].value);//双头组合绣
                    g_pSettings->writeToInHMIiFile("HMI/combineEmb",combineEmb);
                }
                else if(m_itemList[i].indexInPara == ROOT_THREECOMBINEEMB)
                {
                    s16 threeCombineEmb =(s16)(m_itemList[i].value);//三头组合绣
                    g_pSettings->writeToInHMIiFile("HMI/threeCombineEmb",threeCombineEmb);
                }

                else if(m_itemList[i].indexInPara == ROOT_HEADEMB)
                {
                    s16 headEmb =(s16)(m_itemList[i].value);//隔头绣
                    g_pSettings->writeToInHMIiFile("HMI/headEmb",headEmb);
                }
                else if(m_itemList[i].indexInPara == ROOT_LASER)
                {
                    s16 laser =(s16)(m_itemList[i].value);//激光
                    g_pSettings->writeToInHMIiFile("HMI/laser",laser);
                }
                else if(m_itemList[i].indexInPara == ROOT_SHUTTLECHANGE)
                {
                    s16 shuttleChange =(s16)(m_itemList[i].value);//自动换梭
                    g_pSettings->writeToInHMIiFile("HMI/shuttleChange",shuttleChange);
                }
                else if(m_itemList[i].indexInPara == ROOT_TRACKROPEEMB)
                {
                    s16 trackropeEmb =(s16)(m_itemList[i].value);//跟踪绳绣
                    g_pSettings->writeToInHMIiFile("HMI/trackropeEmb",trackropeEmb);
                }
                else if(m_itemList[i].indexInPara == ROOT_STEPPERDRIVE)
                {
                    s16 stepDrive =(s16)(m_itemList[i].value);//步进驱动
                    g_pSettings->writeToInHMIiFile("HMI/stepDrive",stepDrive);
                }

                else if(m_itemList[i].indexInPara == ROOT_CAMCOLORCHANGE)
                {
                    s16 camColorChange =(s16)(m_itemList[i].value);//凸轮换色
                    g_pSettings->writeToInHMIiFile("HMI/camColorChange",camColorChange);
                }
                else if(m_itemList[i].indexInPara == ROOT_BEAD)
                {
                    s16 bead =(s16)(m_itemList[i].value);//散珠
                    g_pSettings->writeToInHMIiFile("HMI/bead",bead);
                }
                else if(m_itemList[i].indexInPara == ROOT_SEQUIN)
                {
                    s16 sequin =(s16)(m_itemList[i].value);//亮片
                    g_pSettings->writeToInHMIiFile("HMI/sequin",sequin);
                }
                else if(m_itemList[i].indexInPara == ROOT_TOWEL)
                {
                    s16 towel =(s16)(m_itemList[i].value);//毛巾
                    g_pSettings->writeToInHMIiFile("HMI/towel",towel);
                }
                else if(m_itemList[i].indexInPara == ROOT_COIL)
                {
                    s16 coil =(s16)(m_itemList[i].value);//缠绕
                    g_pSettings->writeToInHMIiFile("HMI/coil",coil);
                }
                else if(m_itemList[i].indexInPara == ROOT_SIMPLETOWEL)
                {
                    s16 simpleTowel =(s16)(m_itemList[i].value);//简易毛巾
                    g_pSettings->writeToInHMIiFile("HMI/simpleTowel",simpleTowel);
                }
                else if(m_itemList[i].indexInPara == ROOT_INDEFOOT)
                {
                    s16 foot =(s16)(m_itemList[i].value);//独立压脚
                    g_pSettings->writeToInHMIiFile("HMI/foot",foot);
                }
                else if(m_itemList[i].indexInPara == ROOT_WATERMARKSET)
                {
                    s16 waterMark =(s16)(m_itemList[i].value);//主背景是否带水印
                    g_pSettings->writeToInHMIiFile("HMI/waterMark",waterMark);
                }
                else if(m_itemList[i].indexInPara == ROOT_WIFI)
                {
                    s16 wifi =(s16)(m_itemList[i].value);//是否带wifi
                    g_pSettings->writeToInHMIiFile("HMI/wifi",wifi);
                }
                else if(m_itemList[i].indexInPara == ROOT_GRADIENT)
                {
                    s16 gradient =(s16)(m_itemList[i].value); //0:3D显示 1:2D显示
                    g_pSettings->writeToInHMIiFile("HMI/gradient",gradient);
                }

                else if(m_itemList[i].indexInPara == ROOT_PARASORTSET)
                {
                    s16 paraSort =(s16)(m_itemList[i].value);//参数是否分类显示
                    g_pSettings->writeToInHMIiFile("HMI/paraSort",paraSort);
                }
                else if(m_itemList[i].indexInPara == ROOT_FILESENDMODE)
                {
                    s16 fileMode =(s16)(m_itemList[i].value);//文件发送模式
                    g_pSettings->writeToInHMIiFile("HMI/fileMode",fileMode);
                }
                else if(m_itemList[i].indexInPara == ROOT_MACTYPE)
                {
                    g_emMacType = (MachineType)(m_itemList[i].value);//机器类型
                    g_pSettings->writeToIniFile("HMI/machineType",g_emMacType);
                }
            }

            g_pSettings->writeToIniFile("HMI/theme",theme1);
            int towel = g_pSettings->readFromInHMIiFile("HMI/towel").toInt();//是否有毛巾功能
            int coil = g_pSettings->readFromInHMIiFile("HMI/coil").toInt();//是否有缠绕功能
            int both = towel | coil;//有毛巾或有缠绕其中一中，常用功能按钮8变成 机头切换
            if(g_emMacType == MACHINE_EMB)//等于绣花机
            {
                g_pSettings->writeToIniFile("HMI/commonbtn1",FUN_PATTERNSELECT);//快捷按钮1的功能索引
                g_pSettings->writeToIniFile("HMI/commonbtn2",FUN_SETSTARTEMBPOINT);//快捷按钮2的功能索引
                g_pSettings->writeToIniFile("HMI/commonbtn3",FUN_BACKSTARTEMBPOINT);//快捷按钮3的功能索引
                g_pSettings->writeToIniFile("HMI/commonbtn4",FUN_CHECKFRAME);//快捷按钮4的功能索引
                g_pSettings->writeToIniFile("HMI/commonbtn5",FUN_BACKWORKPOINT);//快捷按钮5的功能索引
                g_pSettings->writeToIniFile("HMI/commonbtn6",FUN_NEEDLERODPOSITION);//快捷按钮6的功能索引
                g_pSettings->writeToIniFile("HMI/commonbtn7",FUN_BACKOFFSETPOINT);//快捷按钮7的功能索引
                if(both == 1)
                {
                    g_pSettings->writeToIniFile("HMI/commonbtn8",FUN_SWITCHHEAD);//快捷按钮8 默认是机头切换
                }
                else
                {
                    g_pSettings->writeToIniFile("HMI/commonbtn8",FUN_SPINDLEJOG);//快捷按钮8的功能索引
                }
                g_pSettings->writeToIniFile("HMI/commonbtn9",FUN_MANUALTRIM);//快捷按钮9的功能索引
                g_pSettings->writeToIniFile("HMI/commonbtn10",FUN_MANUALCHANGECOLOR);//快捷按钮10的功能索引
            }
            else if(g_emMacType == QUIMACHINE_EMB)//等于绗绣机
            {
                g_pSettings->writeToIniFile("HMI/commonbtn1",FUN_PATTERNSELECT);//快捷按钮1的功能索引
                g_pSettings->writeToIniFile("HMI/commonbtn2",FUN_SETSTARTEMBPOINT);//快捷按钮2的功能索引
                g_pSettings->writeToIniFile("HMI/commonbtn3",FUN_BACKSTARTEMBPOINT);//快捷按钮3的功能索引
                g_pSettings->writeToIniFile("HMI/commonbtn4",FUN_CHECKFRAME);//快捷按钮4的功能索引
                g_pSettings->writeToIniFile("HMI/commonbtn5",FUN_BACKWORKPOINT);//快捷按钮5的功能索引
                g_pSettings->writeToIniFile("HMI/commonbtn6",FUN_SETOFFSETPOINT);//快捷按钮6的功能索引
                g_pSettings->writeToIniFile("HMI/commonbtn7",FUN_BACKOFFSETPOINT);//快捷按钮7的功能索引
                g_pSettings->writeToIniFile("HMI/commonbtn8",FUN_SPINDLEJOG);//快捷按钮8的功能索引
                g_pSettings->writeToIniFile("HMI/commonbtn9",FUN_MANUALTRIM);//快捷按钮9的功能索引
                g_pSettings->writeToIniFile("HMI/commonbtn10",FUN_MANUALCHANGECOLOR);//快捷按钮10的功能索引
            }

#ifdef Q_OS_WIN
            qApp->exit();
#endif

#ifdef Q_OS_LINUX
            system("reboot");
#endif
        }
        return;
    }

    //等于超级用户物联网配置参数
    if((m_paraType & PARA_TYPE_IOTCONFIGURATION) == PARA_TYPE_IOTCONFIGURATION)
    {
        qDebug()<<"para ok 66";

        for(int i = 0; i<m_itemList.size();  i++)
        {
            if(m_itemList[i].indexInPara == ROOT_RACKNUMBERINPUT)
            {
                int RackNumber = m_itemList[i].value;//机架号
                g_pSettings->writeToIniFile("IOT/rackNumber",RackNumber);
            }
            else if(m_itemList[i].indexInPara == ROOT_DELIVERYTIME)
            {
                QString deliveryTime = m_itemList[i].valueStr;//工厂预计交货时间
                g_pSettings->writeToIniFile("IOT/deliveryTime",deliveryTime);
            }
            else if(m_itemList[i].indexInPara == ROOT_DEBUGPROGRESS)
            {
                int debugProgress = m_itemList[i].value;//调试进度
                g_pSettings->writeToIniFile("IOT/debugProgress",debugProgress);
            }
        }

        //网关连接方式改变时需要提示重启
        s16 cFlag = 0;
        for(int i = 0; i<m_itemList.size();  i++)
        {
            if(m_itemList[i].indexInPara == ROOT_GATEWAYCONNECTIONMETHOD)
            {
                int bVal = g_pSettings->readFromInHMIiFile("IOT/gatewayConnectMode").toInt();
                int eVal = m_itemList[i].value;//网关连接方式
                if(bVal != eVal)
                {
                    cFlag = 1;
                }
                break;
            }
        }

        if(cFlag == 1)
        {
            promptDlg.initDialog(PromptDialog::BTN_OK_CANCEL);
            promptDlg.setTitleStr(tr("Prompt"));
            QString str;
            str = tr("Connection mode changes, take effect after the reboot!");//连接方式改变，重启界面后生效!
            promptDlg.setContentStr(str);
            if(promptDlg.exec() == 1)
            {
                for(int i = 0; i<m_itemList.size();  i++)
                {
                    if(m_itemList[i].indexInPara == ROOT_GATEWAYCONNECTIONMETHOD)
                    {
                        int gatewayConnect = m_itemList[i].value;//网关连接方式
                        g_pSettings->writeToInHMIiFile("IOT/gatewayConnectMode",gatewayConnect);
                        break;
                    }
                }

#ifdef Q_OS_WIN
                qApp->exit();
#endif

#ifdef Q_OS_LINUX
                system("reboot");
#endif
            }
            return;
        }
        else
        {
            done(1);
        }
    }
    //超级用户密码权限,单次有效
    g_emUser = operate;
    done(1);//0是关掉

    qDebug()<<"para ok 8";

}

void ParameterSetDialog::on_buttonCancel_clicked()
{

    //等于遍历参数
    //    if((m_paraType & PARA_TYPE_ROOTTRAVERSE) == PARA_TYPE_ROOTTRAVERSE)
    //    {
    //        PromptDialog promptDlg(this);
    //        promptDlg.initDialog(PromptDialog::BTN_OK_CANCEL);
    //        promptDlg.setTitleStr(tr("Prompt"));
    //        promptDlg.setContentStr(tr("Whether to exit  traversing settings?"));//是否退出遍历设置?
    //        if(promptDlg.exec() == 1)
    //        {
    //            if(g_pMachine != NULL)
    //            {
    //                g_pMachine->exitTraverStates();
    //            }
    //            done(0);
    //        }
    //        return;
    //    }

    //    //等于平绣锁头测试参数
    //    if((m_paraType & PARA_TYPE_EMBLOCKTEST) == PARA_TYPE_EMBLOCKTEST)
    //    {
    //        PromptDialog promptDlg(this);
    //        promptDlg.initDialog(PromptDialog::BTN_OK_CANCEL);
    //        promptDlg.setTitleStr(tr("Prompt"));
    //        promptDlg.setContentStr(tr("Whether to exit embroidery lock test?"));//是否退出平绣锁头测试?
    //        if(promptDlg.exec() == 1)
    //        {
    //            if(g_pMachine != NULL)
    //            {
    //                g_pMachine->enterOrExitStates(MC_STA_EXIT_TRA);
    //            }
    //            done(0);
    //        }
    //        return;
    //    }
    //等于遍历参数
    if((m_paraType & PARA_TYPE_ROOTTRAVERSE) == PARA_TYPE_ROOTTRAVERSE)
    {
        if(g_pMachine != NULL)
        {
            g_pMachine->exitTraverStates();
        }
        g_emUser = operate;
        done(0);
        return;
    }

    //等于平绣锁头测试参数
    if((m_paraType & PARA_TYPE_EMBLOCKTEST) == PARA_TYPE_EMBLOCKTEST)
    {
        if(g_pMachine != NULL)
        {
            g_pMachine->enterOrExitStates(MC_STA_EXIT_TRA);
        }
        g_emUser = operate;
        done(0);
        return;
    }

    //超级用户密码权限,单次有效
    g_emUser = operate;
    done(0);
}

//清除贴布绣参数
void ParameterSetDialog::on_buttonPatchParaClear_clicked()
{
    //清空色序对应的贴布绣参数
    for(int i = 0; i < m_itemList.size(); i++)
    {
        m_itemList[i].value = 0;
    }

    if(m_patchMode == PATCH_COLOR)
    {
        for(int i = 0; i < m_patchItemList.size(); i++)
        {
            if(m_patchItemList[i].paraType == PARA_TYPE_PATTERNPATCH_COLOR)
            {
                m_patchItemList[i].value = 0;
            }
        }
    }
    else if(m_patchMode == PATCH_NEEDLE)
    {
        for(int i = 0; i < m_patchItemList.size(); i++)
        {
            if(m_patchItemList[i].paraType == PARA_TYPE_PATTERNPATCH_NEEDLE)
            {
                m_patchItemList[i].value = 0;
            }
        }
    }
    refreshUi();
}

//按色贴布绣
void ParameterSetDialog::on_buttonPatchParaColor_clicked()
{
    m_curPage = 1;
    m_patchMode = PATCH_COLOR;
    m_itemList.clear();

    //显示相应模式的贴布绣参数
    for(int i = 0; i < m_patchItemList.size(); i++)
    {
        int type = m_patchItemList[i].paraType;

        if(m_patchMode == PATCH_COLOR)
        {
            if(type == PARA_TYPE_PATTERNPATCH_COLOR)
            {
                m_itemList.append(m_patchItemList[i]);
            }
        }
        else
        {
            if(type == PARA_TYPE_PATTERNPATCH_NEEDLE)
            {
                m_itemList.append(m_patchItemList[i]);
            }
        }
    }
    refreshUi();
}

//按针贴布绣
void ParameterSetDialog::on_buttonPatchParaNeedle_clicked()
{
    m_curPage = 1;
    m_patchMode = PATCH_NEEDLE;
    m_itemList.clear();

    //显示相应模式的贴布绣参数
    for(int i = 0; i < m_patchItemList.size(); i++)
    {
        int type = m_patchItemList[i].paraType;

        if(m_patchMode == PATCH_COLOR)
        {
            if(type == PARA_TYPE_PATTERNPATCH_COLOR)
            {
                m_itemList.append(m_patchItemList[i]);
            }
        }
        else
        {
            if(type == PARA_TYPE_PATTERNPATCH_NEEDLE)
            {
                m_itemList.append(m_patchItemList[i]);
            }
        }
    }
    refreshUi();
}

//恢复默认的参数(主板和外围板)
void ParameterSetDialog::on_buttonEXBParaRestore_clicked()
{
    UserRoles emUser = g_emUser;
#if (1)
    if(m_paraType == PARA_TYPE_REPEATEMBPARA)  //重置反复绣
    {
        PromptDialog promptDlg(this);
        promptDlg.initDialog(PromptDialog::BTN_OK_CANCEL);
        promptDlg.setTitleStr(tr("Prompt"));
        promptDlg.setContentStr(tr("Whether to reset the number of repeated embroideries?"));//是否重置反复绣次数?
        if(promptDlg.exec() == 1)
        {
            if(g_pMachine != NULL)
            {
                g_pMachine->manualAction(RESET_REPEAT_NUM);
            }
            return;
        }
        else
        {
            return;   //退出函数，不执行下边的代码
        }
    }

    if(g_emDebugMode == nodebugMode)
    {
        if(g_emUser != resetpara)//权限不够先登录
        {
            emit siUserLogin(resetpara);
            if(g_emUser != resetpara)//发送登录信号后，权限如果还没改变就返回
            {
                return;
            }
        }
        PromptDialog promptDlg(this);
        promptDlg.initDialog(PromptDialog::BTN_OK_CANCEL);
        promptDlg.setTitleStr(tr("Prompt"));
        if(m_paraType == PARA_TYPE_HEADPARAMETER)
        {
            promptDlg.setContentStr(tr("Whether to recover the default parameters for the Emb head board?"));//是否恢复为平绣机头板默认参数?
        }
        else if(m_paraType == PARA_TYPE_TOWELHEADPARAMETER)
        {
            promptDlg.setContentStr(tr("Whether to recover the default parameters for the Chenille head board?"));//是否恢复为毛巾机头板默认参数?
        }
        else if(m_paraType == PARA_TYPE_COILHEADPARAMETER)
        {
            promptDlg.setContentStr(tr("Whether to recover the default parameters for the Coil head board?"));//是否恢复为缠绕机头板默认参数?
        }
        else if(m_paraType == PARA_TYPE_HCPSPARAMETER)
        {
            promptDlg.setContentStr(tr("Whether to recover the default parameters for the Emb color board?"));//是否恢复为平绣换色板默认参数?
        }
        else if(m_paraType == PARA_TYPE_TOWELHCPSPARAMETER)
        {
            promptDlg.setContentStr(tr("Whether to recover the default parameters for the Chenille color board?"));//是否恢复为毛巾换色板默认参数?
        }
        else if(m_paraType == PARA_TYPE_MACH ||
                m_paraType == PARA_TYPE_WORK)
        {
            promptDlg.setContentStr(tr("Whether to recover the default parameters for the board?"));//是否恢复为主板默认参数?
        }

        if(promptDlg.exec() == 1)
        {
            if(g_pMachine != NULL)
            {
                if(m_paraType == PARA_TYPE_HEADPARAMETER)//设置平绣机头板默认参数
                {
                    g_pMachine->setToDefaultParas(UCMD_SET_HEADDEF_PARA, 0,FLATEMB);
                }
                if(m_paraType == PARA_TYPE_TOWELHEADPARAMETER)//设置毛巾机头板默认参数
                {
                    g_pMachine->setToDefaultParas(UCMD_SET_HEADDEF_PARA, 0,TOWEL);
                }
                if(m_paraType == PARA_TYPE_COILHEADPARAMETER)//设置缠绕机头板默认参数
                {
                    g_pMachine->setToDefaultParas(UCMD_SET_HEADDEF_PARA, 0,COIL);
                }
                else if(m_paraType == PARA_TYPE_HCPSPARAMETER)//设置平绣换色板默认参数
                {
                    g_pMachine->setToDefaultParas(UCMD_SET_HCPSDEF_PARA, 1, 0);
                }
                else if(m_paraType == PARA_TYPE_TOWELHCPSPARAMETER)//设置毛巾换色板默认参数
                {
                    g_pMachine->setToDefaultParas(UCMD_SET_HCPSDEF_PARA, 2, 0);
                }
                else if(m_paraType == PARA_TYPE_MACH ||
                        m_paraType == PARA_TYPE_WORK)//设置主板默认参数
                {
                    g_pMachine->setToDefaultParas(UCMD_SET_DEF_PARA, 0);
                }

                setMainTitle(tr("Root"));
                setSubTitle(tr("Accessibility > Root"));
                //超级用户参数
                setItemList(root,PARA_TYPE_ROOT);
                refreshUi();


            }
        }
    }
    else
#endif
    {
        PromptDialog promptDlg(this);
        promptDlg.initDialog(PromptDialog::BTN_OK_CANCEL);
        promptDlg.setTitleStr(tr("Prompt"));
        if(m_paraType == PARA_TYPE_HEADPARAMETER)
        {
            promptDlg.setContentStr(tr("Whether to recover the default parameters for the Emb head board?"));//是否恢复为平绣机头板默认参数?
        }
        else if(m_paraType == PARA_TYPE_TOWELHEADPARAMETER)
        {
            promptDlg.setContentStr(tr("Whether to recover the default parameters for the Chenille head board?"));//是否恢复为毛巾机头板默认参数?
        }
        else if(m_paraType == PARA_TYPE_COILHEADPARAMETER)
        {
            promptDlg.setContentStr(tr("Whether to recover the default parameters for the Coil head board?"));//是否恢复为缠绕机头板默认参数?
        }
        else if(m_paraType == PARA_TYPE_HCPSPARAMETER)
        {
            promptDlg.setContentStr(tr("Whether to recover the default parameters for the Emb color board?"));//是否恢复为平绣换色板默认参数?
        }
        else if(m_paraType == PARA_TYPE_TOWELHCPSPARAMETER)
        {
            promptDlg.setContentStr(tr("Whether to recover the default parameters for the Chenille color board?"));//是否恢复为毛巾换色板默认参数?
        }
        else if(m_paraType == PARA_TYPE_MACH ||
                m_paraType == PARA_TYPE_WORK)
        {
            promptDlg.setContentStr(tr("Whether to recover the default parameters for the board?"));//是否恢复为主板默认参数?
        }

        if(promptDlg.exec() == 1)
        {
            if(g_pMachine != NULL)
            {
                if(m_paraType == PARA_TYPE_HEADPARAMETER)//设置平绣机头板默认参数
                {
                    g_pMachine->setToDefaultParas(UCMD_SET_HEADDEF_PARA, 0,FLATEMB);
                }
                if(m_paraType == PARA_TYPE_TOWELHEADPARAMETER)//设置毛巾机头板默认参数
                {
                    g_pMachine->setToDefaultParas(UCMD_SET_HEADDEF_PARA, 0,TOWEL);
                }
                if(m_paraType == PARA_TYPE_COILHEADPARAMETER)//设置缠绕机头板默认参数
                {
                    g_pMachine->setToDefaultParas(UCMD_SET_HEADDEF_PARA, 0,COIL);
                }
                else if(m_paraType == PARA_TYPE_HCPSPARAMETER)//设置平绣换色板默认参数
                {
                    g_pMachine->setToDefaultParas(UCMD_SET_HCPSDEF_PARA, 1, 0);
                }
                else if(m_paraType == PARA_TYPE_TOWELHCPSPARAMETER)//设置毛巾换色板默认参数
                {
                    g_pMachine->setToDefaultParas(UCMD_SET_HCPSDEF_PARA, 2, 0);
                }
                else if(m_paraType == PARA_TYPE_MACH ||
                        m_paraType == PARA_TYPE_WORK)//设置主板默认参数
                {
                    g_pMachine->setToDefaultParas(UCMD_SET_DEF_PARA, 0);
                }

                setMainTitle(tr("Root"));
                setSubTitle(tr("Accessibility > Root"));
                //超级用户参数
                setItemList(root,PARA_TYPE_ROOT);
                refreshUi();
            }
        }
    }

    g_emUser = emUser;
}

//返回上一级菜单
void ParameterSetDialog::on_buttonReturn_clicked()
{
    //等于遍历参数
    if((m_paraType & PARA_TYPE_ROOTTRAVERSE) == PARA_TYPE_ROOTTRAVERSE)
    {
        PromptDialog promptDlg(this);
        promptDlg.initDialog(PromptDialog::BTN_OK_CANCEL);
        promptDlg.setTitleStr(tr("Prompt"));
        promptDlg.setContentStr(tr("Whether to exit traversing settings?"));//是否退出遍历设置?
        if(promptDlg.exec() == 1)
        {
            if(g_pMachine != NULL)
            {
                g_pMachine->exitTraverStates();
            }
        }
        else
        {
            return;   //退出函数，不执行下边的代码
        }
    }
    //等于平绣锁头测试参数
    if((m_paraType & PARA_TYPE_EMBLOCKTEST) == PARA_TYPE_EMBLOCKTEST)
    {
        PromptDialog promptDlg(this);
        promptDlg.initDialog(PromptDialog::BTN_OK_CANCEL);
        promptDlg.setTitleStr(tr("Prompt"));
        promptDlg.setContentStr(tr("Whether to exit embroidery lock test?"));//是否退出平绣锁头测试?
        if(promptDlg.exec() == 1)
        {
            if(g_pMachine != NULL)
            {
                g_pMachine->enterOrExitStates(MC_STA_EXIT_TRA);
            }
        }
        else
        {
            return;   //退出函数，不执行下边的代码
        }
    }

    if(g_emDebugMode == nodebugMode)
    {
        if(g_emUser == factory)
        {
            setMainTitle(tr("Root"));
            setSubTitle(tr("Accessibility > Root"));
            //超级用户参数
            setItemList(factory,PARA_TYPE_ROOT);
            refreshUi();
        }
        else if (g_emUser == root)
        {
            setMainTitle(tr("Root"));
            setSubTitle(tr("Accessibility > Root"));
            //超级用户参数
            setItemList(root,PARA_TYPE_ROOT);
            refreshUi();
        }
    }
    else
    {
        setMainTitle(tr("Root"));
        setSubTitle(tr("Accessibility > Root"));
        //超级用户参数
        setItemList(root,PARA_TYPE_ROOT);
        refreshUi();
    }
}

//机头板参数导入
void ParameterSetDialog::on_buttonHeadParaImport_clicked()
{
    SetControlStyle setControlStyle;
    setControlStyle.setUiName(this->objectName());
    QString tStyle = setControlStyle.getTopStyleSheet(ui->buttonHeadParaImport->objectName());
    emit siHeadParaImport(tStyle,m_paraType);
}

//机头板参数导出
void ParameterSetDialog::on_buttonHeadParaExport_clicked()
{
    emit siHeadParaExport(m_paraType);
}
