#include "mainwindow.h"
#include "modbus-private.h"
#include "ui_mainwindow.h"
#include "appproto.h"
#include "appproto_english.h"
#include "delegate.h"
#include <QApplication>
#include <QTranslator>
#include <QFile>
#include <QFileDialog>
#include <QTextStream>
#include <QSettings>
#include <QLabel>
#include <QDebug>
#include <QTime>
#include <QTreeView>
#include <QStandardItem>
#include <QStandardItemModel>
#include "proto/battery.pb.h"
#include "proto/battery_english.pb.h"
#include "chartpaint.h"
#include <fstream>
#include <QToolTip>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QMetaType>
#include <QTreeView>
#include "modbusrtu.h"
#include <QWidget>
#include <QCloseEvent>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->init();
    this->setMenuStyle();
    trubleListInit();
    m_AppProto = new AppProto;
    m_AppProto_English = new Appproto_English;
    connect(ui->tabWidget_paraset, SIGNAL(currentChanged(int)), this, SLOT(on_tabChanged(int)));
    connect(ui->comboBoxBCUSelect, SIGNAL(currentIndexChanged(int)), this, SLOT(on_comBoxBCUSelect(int)));
}

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

void MainWindow::init()
{
    /*  设置标题  */
    setWindowTitle("Battery Monitor");
    /*  设置Logo  */
    setWindowIcon(QIcon(":/Image/icon.png"));
    // this->showMaximized();
    /*  读取配置文件  */
    ini = new QSettings("config.ini", QSettings::IniFormat);
    if(QFile::exists("config.ini")) {
        /*  状态栏显示  */
        if(ini->value("Window/ShowStatusbar") == "true") {
            statusBar()->show();
            ui->actionShow_Status_bar->setChecked(true);
        }
        else {
            statusBar()->hide();
            ui->actionShow_Status_bar->setChecked(false);
        }
    }
    else{
        ini->setValue("System/Language", LANGUAGE_ENG);
        ini->setValue("Window/ShowStatusbar", true);
        ini->sync();
    }

    /*  设置初始界面语言  */
    if(ini->value("System/Language") == LANGUAGE_ENG) {
        QTranslator trans;
        qDebug() << "ini in the mainwindow :" << ini->value("System/Language");
        trans.load(":/Language/BatteryMonitor_ENG.qm");
        QApplication::installTranslator(&trans);
        ui->retranslateUi(this);
    }
    else if(ini->value("System/Language") == LANGUAGE_CHN) {
        qDebug() << "ini in the mainwindow :" << ini->value("System/Language");
        QTranslator trans;
        trans.load(":/Language/BatteryMonitor_CHN.qm");
        QApplication::installTranslator(&trans);
        ui->retranslateUi(this);
    }

    // connect(ui->actionChinese, &QAction::triggered, this, [=]{
    //     ini->setValue("System/Language", LANGUAGE_CHN);
    //     ini->sync();
    //     QTranslator trans;
    //     trans.load(":/Language/BatteryMonitor_CHN.qm");
    //     QApplication::installTranslator(&trans);
    //     ui->retranslateUi(this);
    // });

    // connect(ui->actionEnglish, &QAction::triggered, this, [=]{
    //     ini->setValue("System/Language", LANGUAGE_ENG);
    //     ini->sync();
    //     QTranslator trans;
    //     trans.load(":/Language/BatteryMonitor_ENG.qm");
    //     QApplication::installTranslator(&trans);
    //     ui->retranslateUi(this);
    // });

    //历史报警标志位初始化为0
    for (int i = 0; i < 56; i++)
    {
        trouble_list_flag.append(0);
    }

    /*  状态栏设置  */
    statusBarConnectedIcon = new QLabel();
    statusBarConnectedType = new QLabel();
    statusBarCompany = new QLabel();
    statusBarBcu = new QLabel();
    statusBarVersion = new QLabel();
    statusBarConnectedIcon->setPixmap(QPixmap(QIcon(":/Image/connected1.png").pixmap(QSize(24, 24))));
    statusBarConnectedType->setText("RS485");
    statusBarCompany->setText("BLUESUN");

    statusBarBcu->setText("Current BCU:  BCU01");
    statusBarVersion->setText("UpperComputer Version : 1.0.0  ");

    ui->statusbar->addWidget(statusBarConnectedIcon);
    ui->statusbar->addWidget(statusBarConnectedType);
    ui->statusbar->addWidget(statusBarVersion);
    ui->statusbar->addWidget(statusBarBcu);
    ui->statusbar->addPermanentWidget(statusBarCompany);

    /*  菜单栏设置  */
    connect(ui->actionExit, &QAction::triggered, this, [=]{
        this->close();
    });

    connect(ui->actionConnect, &QAction::triggered, this, [=]{

    });

    connect(ui->actionDisconnect, &QAction::triggered, this, [=]{

    });

    connect(ui->actionAuto_Connect, &QAction::triggered, this, [=]{

    });

    connect(ui->actionShow_Status_bar, &QAction::triggered, this, [=]{
        if(ini->value("Window/ShowStatusbar") == true) {
            this->statusBar()->hide();
            ui->actionShow_Status_bar->setChecked(false);
            ini->setValue("Window/ShowStatusbar", false);
            ini->sync();
        }
        else {
            this->statusBar()->show();
            ui->actionShow_Status_bar->setChecked(true);
            ini->setValue("Window/ShowStatusbar", true);
            ini->sync();
        }
    });

    /*  设置初始页  */
    ui->stackedWidget->setCurrentIndex(PAGE_HOME);

    /*  Debug页面槽函数  */
    connect(ui->pageDebugBtnClear, &QPushButton::pressed, this, [=]{
        ui->pageDebugTextBrowser->clear();
    });

    // connect(ui->pageDebugCheckBoxSaveLog, &QCheckBox::stateChanged, this, [=]{
    //     if(ui->pageDebugCheckBoxSaveLog->isChecked()) {
    //         pageDebugLogFlag = true;
    //         QString filename = QFileDialog::getSaveFileName(this, "Save log", "Communication log", "Log Files (*.txt);;All Files (*)");
    //         logFile = new QFile(filename);
    //         if (logFile->open(QIODevice::Append | QIODevice::Text)) {

    //         }
    //     }
    //     else {
    //         pageDebugLogFlag = false;
    //         logFile->close();
    //     }
    // });

    //初始化batt
    bat = new batt();

    //初始化绘制柱状图
    // chartPat = new ChartPaint();
    // //电量充，电量放，时间充，时间放
    // // int array[] = {20, 30, 12, 12};
    // // int array1[] = {1000, 1200, 500, 600};
    // // int array_day_chart[] = {base_info1_45[39], base_info1_45[41], base_info1_45[42], base_info1_45[43]};
    // // QChartView *chartView = chartPat->Paint("日", array);
    // // QChartView *chartView1 = chartPat->Paint("累计", array1);
    // gridLayout = new QGridLayout();
    // QHBoxLayout *hBoxLayout = new QHBoxLayout();
    // hBoxLayout->addLayout(gridLayout);
    // ui->tab_charts->setLayout(hBoxLayout);

    //绘制单体表格
    // sglChartInit(7);
    // ui->groupBox_color_sgl->setStyleSheet("QGroupBox { border: none; }");
    // ui->scrollArea_sgl_charts->setFrameShape(QFrame::NoFrame);
    // ui->scrollAreaChart->setFrameShape(QFrame::NoFrame);

    // ui->scrollAreaChart->setStyleSheet("background-color: #FFFFFF;"); //设置背景颜色为纯白色
    ui->scrollArea_trouble->setStyleSheet("border: none;");
    ui->widgetControl->setStyleSheet("background-color: #FFFFFF;");
    ui->groupBox->setStyleSheet("background-color: #FFFFFF;");
    ui->groupBox_trouble_control->setStyleSheet("background-color: #FFFFFF;");
    // ui->groupBox_chart->setStyleSheet("background-color: #FFFFFF;");
    ui->groupBox_class_color->setStyleSheet("QGroupBox { border: none; }");
    ui->widget_historyAlarm->setStyleSheet("background-color: #FFFFFF;");
    // ui->widget_BCUSelect->setStyleSheet("background-color: #FFFFFF;");
    ui->pageHome->setStyleSheet("background-color: #FFFFFF;");
    ui->comboBoxBCUSelect->setStyleSheet("background-color: #F8F8FF;");
    ui->pageBatteryStackWidget->setStyleSheet("background-color: #FFFFFF;");
    // ui->comboBoxBCUSelect->setStyleSheet("QComboBox QAbstractItemView { background-color: #f0f0f0;}");


    // ui->BCU_DIDO->setStyleSheet("background-color: #FFFFFF;");
    // ui->BCU_alarm->setStyleSheet("background-color: #FFFFFF;");
    ui->BCU_statisInfo->setStyleSheet("background-color: #FFFFFF;");
    ui->BCU_sysInfo->setStyleSheet("background-color: #FFFFFF;");




    //设置按钮的提示文本
    ui->btnHome->setToolTip("概述信息(Overview Information)");
    ui->btnBattery->setToolTip("详细信息(Detailed Information)");
    ui->btnParaSet->setToolTip("参数设置(Parameter Settings)");
    ui->btnDebug->setToolTip("报文信息(Message Information)");
    ui->btnFlash->setToolTip("升级调试(Upgrade Debugging)");
    // ui->btnRecord->setToolTip("记录导出");


    //设置初始颜色
    // ui->close_color->setStyleSheet("QLabel{"
    //                                "background-image: url(:/Image/trouble-background-normal.png);"
    //                                "border: 1px solid gray;"
    //                                "}");
    // ui->open_color->setStyleSheet("QLabel{"
    //                               "background-image: url(:/Image/trouble-background-default.png);"
    //                               "border: 1px solid gray;"
    //                               "}");

    ui->relay_negative->setStyleSheet("QLabel{"
                                      "background-image: url(:/Image/trouble-background-default.png);"
                                      "border: 1px solid gray;"
                                      "}");
    ui->relay_positive->setStyleSheet("QLabel{"
                                      "background-image: url(:/Image/trouble-background-default.png);"
                                      "border: 1px solid gray;"
                                      "}");
    ui->relay_precharge->setStyleSheet("QLabel{"
                                       "background-image: url(:/Image/trouble-background-default.png);"
                                       "border: 1px solid gray;"
                                       "}");
    ui->relay_disconnector->setStyleSheet("QLabel{"
                                          "background-image: url(:/Image/trouble-background-default.png);"
                                          "border: 1px solid gray;"
                                          "}");

    ui->color_trouble_1->setStyleSheet("background-image: url(:/Image/trouble-background-1.png);");
    ui->color_trouble_2->setStyleSheet("background-image: url(:/Image/trouble-background-2.png);");
    ui->color_trouble_3->setStyleSheet("background-image: url(:/Image/trouble-background-3.png);");
    ui->color_trouble_normal->setStyleSheet("background-image: url(:/Image/trouble-background-normal.png);");

    // ui->color_sgl_high->setStyleSheet("background-color: rgb(255, 0, 0);");
    // ui->color_sgl_low->setStyleSheet("background-color: rgb(0, 255, 0);");
    // ui->color_equilibrium->setStyleSheet("background-color: rgb(0, 0, 200);");
    // ui->color_short_circuit->setStyleSheet("background-color: rgb(255, 165, 0);");
    // ui->groupBox_color_sgl->setStyleSheet("QGroupBox { border: none; }");

    ui->label_trouble_1->setStyleSheet("QLabel{"
                                         "background-image: url(:/Image/trouble-background-default.png);"
                                         "border: 1px solid gray;"
                                         "}");
    ui->label_trouble_2->setStyleSheet("QLabel{"
                                          "background-image: url(:/Image/trouble-background-default.png);"
                                          "border: 1px solid gray;"
                                          "}");
    ui->label_trouble_3->setStyleSheet("QLabel{"
                                         "background-image: url(:/Image/trouble-background-default.png);"
                                         "border: 1px solid gray;"
                                         "}");
    ui->label_trouble_4->setStyleSheet("QLabel{"
                                          "background-image: url(:/Image/trouble-background-default.png);"
                                          "border: 1px solid gray;"
                                          "}");
    ui->label_trouble_5->setStyleSheet("QLabel{"
                                           "background-image: url(:/Image/trouble-background-default.png);"
                                           "border: 1px solid gray;"
                                           "}");
    ui->label_trouble_6->setStyleSheet("QLabel{"
                                            "background-image: url(:/Image/trouble-background-default.png);"
                                            "border: 1px solid gray;"
                                            "}");
    ui->label_trouble_7->setStyleSheet("QLabel{"
                                             "background-image: url(:/Image/trouble-background-default.png);"
                                             "border: 1px solid gray;"
                                             "}");
    ui->label_trouble_8->setStyleSheet("QLabel{"
                                             "background-image: url(:/Image/trouble-background-default.png);"
                                             "border: 1px solid gray;"
                                             "}");
    ui->label_trouble_9->setStyleSheet("QLabel{"
                                       "background-image: url(:/Image/trouble-background-default.png);"
                                       "border: 1px solid gray;"
                                       "}");
    ui->label_trouble_10->setStyleSheet("QLabel{"
                                              "background-image: url(:/Image/trouble-background-default.png);"
                                              "border: 1px solid gray;"
                                              "}");
    ui->label_trouble_11->setStyleSheet("QLabel{"
                                           "background-image: url(:/Image/trouble-background-default.png);"
                                           "border: 1px solid gray;"
                                           "}");
    ui->label_trouble_12->setStyleSheet("QLabel{"
                                         "background-image: url(:/Image/trouble-background-default.png);"
                                         "border: 1px solid gray;"
                                         "}");
    ui->label_trouble_13->setStyleSheet("QLabel{"
                                         "background-image: url(:/Image/trouble-background-default.png);"
                                         "border: 1px solid gray;"
                                         "}");
    ui->label_trouble_14->setStyleSheet("QLabel{"
                                      "background-image: url(:/Image/trouble-background-default.png);"
                                      "border: 1px solid gray;"
                                      "}");
    ui->label_trouble_15->setStyleSheet("QLabel{"
                                       "background-image: url(:/Image/trouble-background-default.png);"
                                       "border: 1px solid gray;"
                                       "}");
    ui->label_trouble_16->setStyleSheet("QLabel{"
                                       "background-image: url(:/Image/trouble-background-default.png);"
                                       "border: 1px solid gray;"
                                       "}");
    ui->label_trouble_17->setStyleSheet("QLabel{"
                                      "background-image: url(:/Image/trouble-background-default.png);"
                                      "border: 1px solid gray;"
                                      "}");
    ui->label_trouble_18->setStyleSheet("QLabel{"
                                           "background-image: url(:/Image/trouble-background-default.png);"
                                           "border: 1px solid gray;"
                                           "}");
    ui->label_trouble_19->setStyleSheet("QLabel{"
                                         "background-image: url(:/Image/trouble-background-default.png);"
                                         "border: 1px solid gray;"
                                         "}");
    ui->label_trouble_20->setStyleSheet("QLabel{"
                                          "background-image: url(:/Image/trouble-background-default.png);"
                                          "border: 1px solid gray;"
                                          "}");
    ui->label_trouble_21->setStyleSheet("QLabel{"
                                          "background-image: url(:/Image/trouble-background-default.png);"
                                          "border: 1px solid gray;"
                                          "}");
    ui->label_trouble_22->setStyleSheet("QLabel{"
                                           "background-image: url(:/Image/trouble-background-default.png);"
                                           "border: 1px solid gray;"
                                           "}");
    ui->label_trouble_23->setStyleSheet("QLabel{"
                                          "background-image: url(:/Image/trouble-background-default.png);"
                                          "border: 1px solid gray;"
                                          "}");
    ui->label_trouble_24->setStyleSheet("QLabel{"
                                           "background-image: url(:/Image/trouble-background-default.png);"
                                           "border: 1px solid gray;"
                                           "}");
    ui->label_trouble_25->setStyleSheet("QLabel{"
                                               "background-image: url(:/Image/trouble-background-default.png);"
                                               "border: 1px solid gray;"
                                               "}");
    ui->label_trouble_26->setStyleSheet("QLabel{"
                                      "background-image: url(:/Image/trouble-background-default.png);"
                                      "border: 1px solid gray;"
                                      "}");
    ui->label_trouble_27->setStyleSheet("QLabel{"
                                          "background-image: url(:/Image/trouble-background-default.png);"
                                          "border: 1px solid gray;"
                                          "}");
    ui->label_trouble_28->setStyleSheet("QLabel{"
                                          "background-image: url(:/Image/trouble-background-default.png);"
                                          "border: 1px solid gray;"
                                          "}");
    ui->label_trouble_29->setStyleSheet("QLabel{"
                                            "background-image: url(:/Image/trouble-background-default.png);"
                                            "border: 1px solid gray;"
                                            "}");
    ui->label_trouble_30->setStyleSheet("QLabel{"
                                      "background-image: url(:/Image/trouble-background-default.png);"
                                      "border: 1px solid gray;"
                                      "}");
    ui->label_trouble_31->setStyleSheet("QLabel{"
                                      "background-image: url(:/Image/trouble-background-default.png);"
                                      "border: 1px solid gray;"
                                      "}");
    ui->label_trouble_32->setStyleSheet("QLabel{"
                                        "background-image: url(:/Image/trouble-background-default.png);"
                                        "border: 1px solid gray;"
                                        "}");
    ui->label_trouble_33->setStyleSheet("QLabel{"
                                        "background-image: url(:/Image/trouble-background-default.png);"
                                        "border: 1px solid gray;"
                                        "}");
    ui->label_trouble_34->setStyleSheet("QLabel{"
                                         "background-image: url(:/Image/trouble-background-default.png);"
                                         "border: 1px solid gray;"
                                         "}");
    ui->label_trouble_35->setStyleSheet("QLabel{"
                                           "background-image: url(:/Image/trouble-background-default.png);"
                                           "border: 1px solid gray;"
                                           "}");
    ui->label_trouble_36->setStyleSheet("QLabel{"
                                           "background-image: url(:/Image/trouble-background-default.png);"
                                           "border: 1px solid gray;"
                                           "}");
    ui->label_trouble_37->setStyleSheet("QLabel{"
                                        "background-image: url(:/Image/trouble-background-default.png);"
                                        "border: 1px solid gray;"
                                        "}");
    ui->label_trouble_38->setStyleSheet("QLabel{"
                                        "background-image: url(:/Image/trouble-background-default.png);"
                                        "border: 1px solid gray;"
                                        "}");
    ui->label_trouble_39->setStyleSheet("QLabel{"
                                       "background-image: url(:/Image/trouble-background-default.png);"
                                       "border: 1px solid gray;"
                                       "}");
    ui->label_trouble_40->setStyleSheet("QLabel{"
                                            "background-image: url(:/Image/trouble-background-default.png);"
                                            "border: 1px solid gray;"
                                            "}");
    ui->label_trouble_41->setStyleSheet("QLabel{"
                                              "background-image: url(:/Image/trouble-background-default.png);"
                                              "border: 1px solid gray;"
                                              "}");
    ui->label_trouble_42->setStyleSheet("QLabel{"
                                         "background-image: url(:/Image/trouble-background-default.png);"
                                         "border: 1px solid gray;"
                                         "}");
    ui->label_trouble_43->setStyleSheet("QLabel{"
                                            "background-image: url(:/Image/trouble-background-default.png);"
                                            "border: 1px solid gray;"
                                            "}");
    ui->label_trouble_44->setStyleSheet("QLabel{"
                                       "background-image: url(:/Image/trouble-background-default.png);"
                                       "border: 1px solid gray;"
                                       "}");
    ui->label_trouble_45->setStyleSheet("QLabel{"
                                        "background-image: url(:/Image/trouble-background-default.png);"
                                        "border: 1px solid gray;"
                                        "}");
    ui->label_trouble_46->setStyleSheet("QLabel{"
                                              "background-image: url(:/Image/trouble-background-default.png);"
                                              "border: 1px solid gray;"
                                              "}");
    ui->label_trouble_47->setStyleSheet("QLabel{"
                                      "background-image: url(:/Image/trouble-background-default.png);"
                                      "border: 1px solid gray;"
                                      "}");
    ui->label_trouble_48->setStyleSheet("QLabel{"
                                            "background-image: url(:/Image/trouble-background-default.png);"
                                            "border: 1px solid gray;"
                                            "}");
    ui->label_trouble_49->setStyleSheet("QLabel{"
                                             "background-image: url(:/Image/trouble-background-default.png);"
                                             "border: 1px solid gray;"
                                             "}");
    ui->label_trouble_50->setStyleSheet("QLabel{"
                                              "background-image: url(:/Image/trouble-background-default.png);"
                                              "border: 1px solid gray;"
                                              "}");
    ui->label_trouble_51->setStyleSheet("QLabel{"
                                             "background-image: url(:/Image/trouble-background-default.png);"
                                             "border: 1px solid gray;"
                                             "}");
    ui->label_trouble_52->setStyleSheet("QLabel{"
                                      "background-image: url(:/Image/trouble-background-default.png);"
                                      "border: 1px solid gray;"
                                      "}");
    ui->label_trouble_53->setStyleSheet("QLabel{"
                                       "background-image: url(:/Image/trouble-background-default.png);"
                                       "border: 1px solid gray;"
                                       "}");
    ui->label_trouble_54->setStyleSheet("QLabel{"
                                                  "background-image: url(:/Image/trouble-background-default.png);"
                                                  "border: 1px solid gray;"
                                                  "}");
    ui->label_trouble_55->setStyleSheet("QLabel{"
                                         "background-image: url(:/Image/trouble-background-default.png);"
                                         "border: 1px solid gray;"
                                         "}");
    ui->label_trouble_56->setStyleSheet("QLabel{"
                                           "background-image: url(:/Image/trouble-background-default.png);"
                                           "border: 1px solid gray;"
                                           "}");

    // QStandardItemModel *model = new QStandardItemModel(ui->treeViewBCUbmu);

    // // 创建一级目录项
    // QStandardItem *rootItem = new QStandardItem("BCU01");
    // // 设置一级目录项的字体为加粗
    // QFont boldFont = rootItem->font();
    // boldFont.setBold(true);
    // rootItem->setFont(boldFont);
    // model->appendRow(rootItem);

    // ui->tabWidgetBCU->setCurrentIndex(0);
    // ui->tabWidgetBMU->setCurrentIndex(0);

    // connect(ui->treeViewBCUbmu, &QTreeView::clicked, [=](const QModelIndex index){
    //     if(index.parent().isValid())
    //     {
    //         qDebug() << "BMU" << index.column() << index.row();
    //         ui->pageBatteryStackWidget->setCurrentIndex(1);
    //     }
    //     else
    //     {
    //         qDebug() << "BCU" << index.column() << index.row();
    //         ui->pageBatteryStackWidget->setCurrentIndex(0);
    //     }
    // });

    // for (int i = 1; i <= 26; ++i) {
    //     QString bmuName = QString("BMU%1").arg(i);
    //     QStandardItem *bmuItem = new QStandardItem(bmuName);
    //     rootItem->appendRow(bmuItem);
    // }

    // ui->treeViewBCUbmu->setModel(model);
    // ui->treeViewBCUbmu->setHeaderHidden(true);
    // ui->treeViewBCUbmu->setAnimated(true);
    // ui->treeViewBCUbmu->expandAll();
    // ui->treeViewBCUbmu->setEditTriggers(QAbstractItemView::NoEditTriggers);
    // ui->treeViewBCUbmu->show();
}

void MainWindow::sglChartInit(int bat_count)
{
    // ui->tabWidget_sgl_info->setCurrentWidget(ui->tab_vol);
    QStringList labels = {
        "Bmu", "C1", "C2",
        "C3", "C4", "C5", "C6", "C7",
        "C8", "C9", "C10", "C11", "C12",
        "C13", "C14", "C15", "C16",
    };

    //单体电压
    QTableWidget *page_paraset_sys_sgl_vol = new QTableWidget(bat_count, 17);
    page_paraset_sys_sgl_vol->horizontalHeader()->setDefaultSectionSize(40);
    page_paraset_sys_sgl_vol->verticalHeader()->setDefaultSectionSize(30);
    page_paraset_sys_sgl_vol->verticalHeader()->setVisible(false);
    page_paraset_sys_sgl_vol->setHorizontalHeaderLabels(QStringList(labels));

    //row的索引比row的值要小1
    for (int row = 0; row < page_paraset_sys_sgl_vol->rowCount(); ++row) {
        for (int col = 0; col < page_paraset_sys_sgl_vol->columnCount(); ++col) {
            if (col == 0)
            {
                QLabel *label = new QLabel(QString::number(row+1), this);
                label->setAlignment(Qt::AlignCenter);
                QFont font("黑体", 10);
                label->setFont(font);
                label->setFixedSize(40, 30);
                page_paraset_sys_sgl_vol->setCellWidget(row, col, label);
            }

            if(col >= 1)
            {
                QLabel *label = new QLabel(this);
                labelListVol.append(label);
                // QFont font("黑体", 10);
                // label->setFont(font);
                label->setFixedSize(40, 30);
                page_paraset_sys_sgl_vol->setCellWidget(row, col, label);
            }
        }
    }

    //单体温度
    QTableWidget *page_paraset_sys_sgl_temp = new QTableWidget(bat_count, 17);
    page_paraset_sys_sgl_temp->horizontalHeader()->setDefaultSectionSize(40);
    page_paraset_sys_sgl_temp->verticalHeader()->setDefaultSectionSize(30);
    page_paraset_sys_sgl_temp->verticalHeader()->setVisible(false);
    page_paraset_sys_sgl_temp->setHorizontalHeaderLabels(QStringList(labels));

    //row的索引比row的值要小1
    for (int row = 0; row < page_paraset_sys_sgl_temp->rowCount(); ++row) {
        for (int col = 0; col < page_paraset_sys_sgl_temp->columnCount(); ++col) {
            if (col == 0)
            {
                QLabel *label = new QLabel(QString::number(row+1), this);
                label->setAlignment(Qt::AlignCenter);
                QFont font("黑体", 10);
                label->setFont(font);
                label->setFixedSize(40, 30);
                page_paraset_sys_sgl_temp->setCellWidget(row, col, label);
            }

            if(col >= 1)
            {
                QLabel *label = new QLabel(this);
                labelListTempt.append(label);
                // QFont font("黑体", 10);
                // label->setFont(font);
                label->setFixedSize(40, 30);
                page_paraset_sys_sgl_temp->setCellWidget(row, col, label);
            }
        }
    }

    QHBoxLayout *hBoxLayout_vol = new QHBoxLayout();

    QHBoxLayout *hBoxLayout_tempt = new QHBoxLayout();


    hBoxLayout_vol->addWidget(page_paraset_sys_sgl_vol);
    hBoxLayout_tempt->addWidget(page_paraset_sys_sgl_temp);

    // ui->tab_vol->setLayout(hBoxLayout_vol);
    // ui->tab_tempt->setLayout(hBoxLayout_tempt);
}

void MainWindow::setMenuStyle()
{
    /*  设置菜单按钮样式表  */
    connect(ui->btnHome, &QPushButton::pressed, this, [=]{
        ui->stackedWidget->setCurrentIndex(PAGE_HOME);
        ui->btnHome->setStyleSheet("#btnHome{"
                                   "background-image: url(:/Image/home2.png);"
                                   "background-repeat: no-repeat;"
                                   "background-position: center;"
                                   "background-color: rgba(255, 255, 255, 0);"
                                   "}");

        ui->btnBattery->setStyleSheet("#btnBattery{"
                                      "background-image: url(:/Image/battery.png);"
                                      "background-repeat: no-repeat;"
                                      "background-position: center;"
                                      "background-color: rgba(255, 255, 255, 0);"
                                      "}"
                                      "#btnBattery::hover{"
                                      "background-image: url(:/Image/battery1.png);"
                                      "background-repeat: no-repeat;"
                                      "background-position: center;"
                                      "background-color: rgba(255, 255, 255, 0);"
                                      "}"
                                      );

        ui->btnParaSet->setStyleSheet("#btnParaSet{"
                                      "background-image: url(:/Image/paraSet.png);"
                                      "background-repeat: no-repeat;"
                                      "background-position: center;"
                                      "background-color: rgba(255, 255, 255, 0);"
                                      "}"
                                      "#btnParaSet::hover{"
                                      "background-image: url(:/Image/paraSet1.png);"
                                      "background-repeat: no-repeat;"
                                      "background-position: center;"
                                      "background-color: rgba(255, 255, 255, 0);"
                                      "}");

        ui->btnDebug->setStyleSheet("#btnDebug{"
                                    "background-image: url(:/Image/debug.png);"
                                    "background-repeat: no-repeat;"
                                    "background-position: center;"
                                    "background-color: rgba(255, 255, 255, 0);"
                                    "}"
                                    "#btnDebug::hover{"
                                    "background-image: url(:/Image/debug1.png);"
                                    "background-repeat: no-repeat;"
                                    "background-position: center;"
                                    "background-color: rgba(255, 255, 255, 0);"
                                    "}");

        ui->btnFlash->setStyleSheet("#btnFlash{"
                                    "background-image: url(:/Image/hardware-line.png);"
                                    "background-repeat: no-repeat;"
                                    "background-position: center;"
                                    "background-color: rgba(255, 255, 255, 0);"
                                    "}"
                                    "#btnFlash::hover{"
                                    "background-image: url(:/Image/hardware-line1.png);"
                                    "background-repeat: no-repeat;"
                                    "background-position: center;"
                                    "background-color: rgba(255, 255, 255, 0);"
                                    "}");

        // ui->btnSetup->setStyleSheet("#btnSetup{"
        //                             "background-image: url(:/Image/advance-set-line.png);"
        //                             "background-repeat: no-repeat;"
        //                             "background-position: center;"
        //                             "background-color: rgba(255, 255, 255, 0);"
        //                             "}"
        //                             "#btnSetup::hover{"
        //                             "background-image: url(:/Image/advance-set-line1.png);"
        //                             "background-repeat: no-repeat;"
        //                             "background-position: center;"
        //                             "background-color: rgba(255, 255, 255, 0);"
        //                             "}");

        // ui->btnRecord->setStyleSheet("#btnRecord{"
        //                             "background-image: url(:/Image/record-out-black.png);"
        //                             "background-repeat: no-repeat;"
        //                             "background-position: center;"
        //                             "background-color: rgba(255, 255, 255, 0);"
        //                             "}"
        //                             "#btnRecord::hover{"
        //                             "background-image: url(:/Image/record-out-gray.png);"
        //                             "background-repeat: no-repeat;"
        //                             "background-position: center;"
        //                             "background-color: rgba(255, 255, 255, 0);"
        //                             "}");
    });

    connect(ui->btnBattery, &QPushButton::pressed, this, [=]{
        ui->stackedWidget->setCurrentIndex(PAGE_BATTERY);
        ui->btnBattery->setStyleSheet("#btnBattery{"
                                      "background-image: url(:/Image/battery2.png);"
                                      "background-repeat: no-repeat;"
                                      "background-position: center;"
                                      "background-color: rgba(255, 255, 255, 0);"
                                      "}");

        ui->btnHome->setStyleSheet("#btnHome{"
                                   "background-image: url(:/Image/home.png);"
                                   "background-repeat: no-repeat;"
                                   "background-position: center;"
                                   "background-color: rgba(255, 255, 255, 0);"
                                   "}"
                                   "#btnHome::hover{"
                                   "background-image: url(:/Image/home1.png);"
                                   "background-repeat: no-repeat;"
                                   "background-position: center;"
                                   "background-color: rgba(255, 255, 255, 0);"
                                   "}");

        ui->btnParaSet->setStyleSheet("#btnParaSet{"
                                      "background-image: url(:/Image/paraSet.png);"
                                      "background-repeat: no-repeat;"
                                      "background-position: center;"
                                      "background-color: rgba(255, 255, 255, 0);"
                                      "}"
                                      "#btnParaSet::hover{"
                                      "background-image: url(:/Image/paraSet1.png);"
                                      "background-repeat: no-repeat;"
                                      "background-position: center;"
                                      "background-color: rgba(255, 255, 255, 0);"
                                      "}");

        ui->btnDebug->setStyleSheet("#btnDebug{"
                                    "background-image: url(:/Image/debug.png);"
                                    "background-repeat: no-repeat;"
                                    "background-position: center;"
                                    "background-color: rgba(255, 255, 255, 0);"
                                    "}"
                                    "#btnDebug::hover{"
                                    "background-image: url(:/Image/debug1.png);"
                                    "background-repeat: no-repeat;"
                                    "background-position: center;"
                                    "background-color: rgba(255, 255, 255, 0);"
                                    "}");

        ui->btnFlash->setStyleSheet("#btnFlash{"
                                    "background-image: url(:/Image/hardware-line.png);"
                                    "background-repeat: no-repeat;"
                                    "background-position: center;"
                                    "background-color: rgba(255, 255, 255, 0);"
                                    "}"
                                    "#btnFlash::hover{"
                                    "background-image: url(:/Image/hardware-line1.png);"
                                    "background-repeat: no-repeat;"
                                    "background-position: center;"
                                    "background-color: rgba(255, 255, 255, 0);"
                                    "}");

        // ui->btnSetup->setStyleSheet("#btnSetup{"
        //                             "background-image: url(:/Image/advance-set-line.png);"
        //                             "background-repeat: no-repeat;"
        //                             "background-position: center;"
        //                             "background-color: rgba(255, 255, 255, 0);"
        //                             "}"
        //                             "#btnSetup::hover{"
        //                             "background-image: url(:/Image/advance-set-line1.png);"
        //                             "background-repeat: no-repeat;"
        //                             "background-position: center;"
        //                             "background-color: rgba(255, 255, 255, 0);"
        //                             "}");

        // ui->btnRecord->setStyleSheet("#btnRecord{"
        //                             "background-image: url(:/Image/record-out-black.png);"
        //                             "background-repeat: no-repeat;"
        //                             "background-position: center;"
        //                             "background-color: rgba(255, 255, 255, 0);"
        //                             "}"
        //                             "#btnRecord::hover{"
        //                             "background-image: url(:/Image/record-out-gray.png);"
        //                             "background-repeat: no-repeat;"
        //                             "background-position: center;"
        //                             "background-color: rgba(255, 255, 255, 0);"
        //                             "}");
    });

    connect(ui->btnParaSet, &QPushButton::pressed, this, [=]{
        ui->stackedWidget->setCurrentIndex(PAGE_PARASET);
        ui->btnParaSet->setStyleSheet("#btnParaSet{"
                                      "background-image: url(:/Image/paraSet2.png);"
                                      "background-repeat: no-repeat;"
                                      "background-position: center;"
                                      "background-color: rgba(255, 255, 255, 0);"
                                      "}");

        ui->btnHome->setStyleSheet("#btnHome{"
                                   "background-image: url(:/Image/home.png);"
                                   "background-repeat: no-repeat;"
                                   "background-position: center;"
                                   "background-color: rgba(255, 255, 255, 0);"
                                   "}"
                                   "#btnHome::hover{"
                                   "background-image: url(:/Image/home1.png);"
                                   "background-repeat: no-repeat;"
                                   "background-position: center;"
                                   "background-color: rgba(255, 255, 255, 0);"
                                   "}");

        ui->btnBattery->setStyleSheet("#btnBattery{"
                                      "background-image: url(:/Image/battery.png);"
                                      "background-repeat: no-repeat;"
                                      "background-position: center;"
                                      "background-color: rgba(255, 255, 255, 0);"
                                      "}"
                                      "#btnBattery::hover{"
                                      "background-image: url(:/Image/battery1.png);"
                                      "background-repeat: no-repeat;"
                                      "background-position: center;"
                                      "background-color: rgba(255, 255, 255, 0);"
                                      "}");

        ui->btnDebug->setStyleSheet("#btnDebug{"
                                    "background-image: url(:/Image/debug.png);"
                                    "background-repeat: no-repeat;"
                                    "background-position: center;"
                                    "background-color: rgba(255, 255, 255, 0);"
                                    "}"
                                    "#btnDebug::hover{"
                                    "background-image: url(:/Image/debug1.png);"
                                    "background-repeat: no-repeat;"
                                    "background-position: center;"
                                    "background-color: rgba(255, 255, 255, 0);"
                                    "}");

        ui->btnFlash->setStyleSheet("#btnFlash{"
                                    "background-image: url(:/Image/hardware-line.png);"
                                    "background-repeat: no-repeat;"
                                    "background-position: center;"
                                    "background-color: rgba(255, 255, 255, 0);"
                                    "}"
                                    "#btnFlash::hover{"
                                    "background-image: url(:/Image/hardware-line1.png);"
                                    "background-repeat: no-repeat;"
                                    "background-position: center;"
                                    "background-color: rgba(255, 255, 255, 0);"
                                    "}");

        // ui->btnSetup->setStyleSheet("#btnSetup{"
        //                             "background-image: url(:/Image/advance-set-line.png);"
        //                             "background-repeat: no-repeat;"
        //                             "background-position: center;"
        //                             "background-color: rgba(255, 255, 255, 0);"
        //                             "}"
        //                             "#btnSetup::hover{"
        //                             "background-image: url(:/Image/advance-set-line1.png);"
        //                             "background-repeat: no-repeat;"
        //                             "background-position: center;"
        //                             "background-color: rgba(255, 255, 255, 0);"
        //                             "}");

        // ui->btnRecord->setStyleSheet("#btnRecord{"
        //                             "background-image: url(:/Image/record-out-black.png);"
        //                             "background-repeat: no-repeat;"
        //                             "background-position: center;"
        //                             "background-color: rgba(255, 255, 255, 0);"
        //                             "}"
        //                             "#btnRecord::hover{"
        //                             "background-image: url(:/Image/record-out-gray.png);"
        //                             "background-repeat: no-repeat;"
        //                             "background-position: center;"
        //                             "background-color: rgba(255, 255, 255, 0);"
        //                             "}");
    });

    connect(ui->btnDebug, &QPushButton::pressed, this, [=]{
        ui->stackedWidget->setCurrentIndex(PAGE_DEBUG);
        ui->btnDebug->setStyleSheet("#btnDebug{"
                                    "background-image: url(:/Image/debug2.png);"
                                    "background-repeat: no-repeat;"
                                    "background-position: center;"
                                    "background-color: rgba(255, 255, 255, 0);"
                                    "}");

        ui->btnHome->setStyleSheet("#btnHome{"
                                   "background-image: url(:/Image/home.png);"
                                   "background-repeat: no-repeat;"
                                   "background-position: center;"
                                   "background-color: rgba(255, 255, 255, 0);"
                                   "}"
                                   "#btnHome::hover{"
                                   "background-image: url(:/Image/home1.png);"
                                   "background-repeat: no-repeat;"
                                   "background-position: center;"
                                   "background-color: rgba(255, 255, 255, 0);"
                                   "}");

        ui->btnBattery->setStyleSheet("#btnBattery{"
                                      "background-image: url(:/Image/battery.png);"
                                      "background-repeat: no-repeat;"
                                      "background-position: center;"
                                      "background-color: rgba(255, 255, 255, 0);"
                                      "}"
                                      "#btnBattery::hover{"
                                      "background-image: url(:/Image/battery1.png);"
                                      "background-repeat: no-repeat;"
                                      "background-position: center;"
                                      "background-color: rgba(255, 255, 255, 0);"
                                      "}");

        ui->btnParaSet->setStyleSheet("#btnParaSet{"
                                      "background-image: url(:/Image/paraSet.png);"
                                      "background-repeat: no-repeat;"
                                      "background-position: center;"
                                      "background-color: rgba(255, 255, 255, 0);"
                                      "}"
                                      "#btnParaSet::hover{"
                                      "background-image: url(:/Image/paraSet1.png);"
                                      "background-repeat: no-repeat;"
                                      "background-position: center;"
                                      "background-color: rgba(255, 255, 255, 0);"
                                      "}");

        ui->btnFlash->setStyleSheet("#btnFlash{"
                                    "background-image: url(:/Image/hardware-line.png);"
                                    "background-repeat: no-repeat;"
                                    "background-position: center;"
                                    "background-color: rgba(255, 255, 255, 0);"
                                    "}"
                                    "#btnFlash::hover{"
                                    "background-image: url(:/Image/hardware-line1.png);"
                                    "background-repeat: no-repeat;"
                                    "background-position: center;"
                                    "background-color: rgba(255, 255, 255, 0);"
                                    "}");

        // ui->btnSetup->setStyleSheet("#btnSetup{"
        //                             "background-image: url(:/Image/advance-set-line.png);"
        //                             "background-repeat: no-repeat;"
        //                             "background-position: center;"
        //                             "background-color: rgba(255, 255, 255, 0);"
        //                             "}"
        //                             "#btnSetup::hover{"
        //                             "background-image: url(:/Image/advance-set-line1.png);"
        //                             "background-repeat: no-repeat;"
        //                             "background-position: center;"
        //                             "background-color: rgba(255, 255, 255, 0);"
        //                             "}");

        // ui->btnRecord->setStyleSheet("#btnRecord{"
        //                             "background-image: url(:/Image/record-out-black.png);"
        //                             "background-repeat: no-repeat;"
        //                             "background-position: center;"
        //                             "background-color: rgba(255, 255, 255, 0);"
        //                             "}"
        //                             "#btnRecord::hover{"
        //                             "background-image: url(:/Image/record-out-gray.png);"
        //                             "background-repeat: no-repeat;"
        //                             "background-position: center;"
        //                             "background-color: rgba(255, 255, 255, 0);"
        //                             "}");
    });

    connect(ui->btnFlash, &QPushButton::pressed, this, [=]{
        ui->stackedWidget->setCurrentIndex(PAGE_FLASH);
        ui->btnFlash->setStyleSheet("#btnFlash{"
                                    "background-image: url(:/Image/hardware-line2.png);"
                                    "background-repeat: no-repeat;"
                                    "background-position: center;"
                                    "background-color: rgba(255, 255, 255, 0);"
                                    "}");

        ui->btnHome->setStyleSheet("#btnHome{"
                                   "background-image: url(:/Image/home.png);"
                                   "background-repeat: no-repeat;"
                                   "background-position: center;"
                                   "background-color: rgba(255, 255, 255, 0);"
                                   "}"
                                   "#btnHome::hover{"
                                   "background-image: url(:/Image/home1.png);"
                                   "background-repeat: no-repeat;"
                                   "background-position: center;"
                                   "background-color: rgba(255, 255, 255, 0);"
                                   "}");

        ui->btnBattery->setStyleSheet("#btnBattery{"
                                      "background-image: url(:/Image/battery.png);"
                                      "background-repeat: no-repeat;"
                                      "background-position: center;"
                                      "background-color: rgba(255, 255, 255, 0);"
                                      "}"
                                      "#btnBattery::hover{"
                                      "background-image: url(:/Image/battery1.png);"
                                      "background-repeat: no-repeat;"
                                      "background-position: center;"
                                      "background-color: rgba(255, 255, 255, 0);"
                                      "}");

        ui->btnParaSet->setStyleSheet("#btnParaSet{"
                                      "background-image: url(:/Image/paraSet.png);"
                                      "background-repeat: no-repeat;"
                                      "background-position: center;"
                                      "background-color: rgba(255, 255, 255, 0);"
                                      "}"
                                      "#btnParaSet::hover{"
                                      "background-image: url(:/Image/paraSet1.png);"
                                      "background-repeat: no-repeat;"
                                      "background-position: center;"
                                      "background-color: rgba(255, 255, 255, 0);"
                                      "}");

        ui->btnDebug->setStyleSheet("#btnDebug{"
                                    "background-image: url(:/Image/debug.png);"
                                    "background-repeat: no-repeat;"
                                    "background-position: center;"
                                    "background-color: rgba(255, 255, 255, 0);"
                                    "}"
                                    "#btnDebug::hover{"
                                    "background-image: url(:/Image/debug1.png);"
                                    "background-repeat: no-repeat;"
                                    "background-position: center;"
                                    "background-color: rgba(255, 255, 255, 0);"
                                    "}");

        // ui->btnSetup->setStyleSheet("#btnSetup{"
        //                             "background-image: url(:/Image/advance-set-line.png);"
        //                             "background-repeat: no-repeat;"
        //                             "background-position: center;"
        //                             "background-color: rgba(255, 255, 255, 0);"
        //                             "}"
        //                             "#btnSetup::hover{"
        //                             "background-image: url(:/Image/advance-set-line1.png);"
        //                             "background-repeat: no-repeat;"
        //                             "background-position: center;"
        //                             "background-color: rgba(255, 255, 255, 0);"
        //                             "}");
    });

    // connect(ui->btnSetup, &QPushButton::pressed, this, [=]{
    //     emit showLogin();
    //     ui->btnSetup->setStyleSheet("#btnSetup{"
    //                                 "background-image: url(:/Image/advance-set-line2.png);"
    //                                 "background-repeat: no-repeat;"
    //                                 "background-position: center;"
    //                                 "background-color: rgba(255, 255, 255, 0);"
    //                                 "}");
    // });

    ui->btn_close_neg->setStyleSheet("QPushButton { background-color: #87CEFA; color: white; }"
                                     "QPushButton:hover { background-color: #77B5D6; color: white; }");
    ui->btn_close_pos->setStyleSheet("QPushButton { background-color: #87CEFA; color: white; }"
                                     "QPushButton:hover { background-color: #77B5D6; color: white; }");
    ui->btn_close_prechg->setStyleSheet("QPushButton { background-color: #87CEFA; color: white; }"
                                        "QPushButton:hover { background-color: #77B5D6; color: white; }");
    ui->btn_open_prechg->setStyleSheet("QPushButton { background-color: #87CEFA; color: white; }"
                                       "QPushButton:hover { background-color: #77B5D6; color: white; }");
    ui->btn_open_neg->setStyleSheet("QPushButton { background-color: #87CEFA; color: white; }"
                                    "QPushButton:hover { background-color: #77B5D6; color: white; }");
    ui->btn_open_pos->setStyleSheet("QPushButton { background-color: #87CEFA; color: white; }"
                                    "QPushButton:hover { background-color: #77B5D6; color: white; }");

    ui->pageParaSetRead->setStyleSheet("QPushButton { background-color: #87CEFA; color: white; }"
                                     "QPushButton:hover { background-color: #77B5D6; color: white; }");
    ui->pageParaSetWrite->setStyleSheet("QPushButton { background-color: #87CEFA; color: white; }"
                                     "QPushButton:hover { background-color: #77B5D6; color: white; }");
    ui->btnGetVersion->setStyleSheet("QPushButton { background-color: #87CEFA; color: white; }"
                                        "QPushButton:hover { background-color: #77B5D6; color: white; }");
    ui->btnStartUpgrade->setStyleSheet("QPushButton { background-color: #87CEFA; color: white; }"
                                       "QPushButton:hover { background-color: #77B5D6; color: white; }");
    ui->btnImport->setStyleSheet("QPushButton { background-color: #87CEFA; color: white; }"
                                    "QPushButton:hover { background-color: #77B5D6; color: white; }");
    ui->btnSendData->setStyleSheet("QPushButton { background-color: #87CEFA; color: white; }"
                                    "QPushButton:hover { background-color: #77B5D6; color: white; }");
    ui->pageDebugBtnClear->setStyleSheet("QPushButton { background-color: #87CEFA; color: white; }"
                                    "QPushButton:hover { background-color: #77B5D6; color: white; }");
}

void MainWindow::slot_pageDebugDisplayMessage(QByteArray byteArray, int dataType, uint16_t *data)
{
    // qDebug("#1");
    if(ui->pageDebugCheckBoxDisplay->isChecked() == true) {
        QString timeStr = QString(QDateTime::currentDateTime().toString("[yyyy-MM-dd hh:mm:ss.zzz] "));
        QString tmpStr;
        QString showStr;
        for(int i = 0; i < byteArray.size(); i++) {
            tmpStr += QString("%1 ").arg((quint8)byteArray.at(i), 2, 16, QChar('0'));
            // QString hexString = QString::number(tmpStr, 16);
            // qDebug() << "recvdata:" << tmpStr.toInt(&ok, 16);
        }
        if(dataType == TypeRecvData) {
            if(ui->pageDebugCheckBoxStarmp->isChecked()) {
                showStr = timeStr + "<html><span body><span style=\"color:blue;\">Rx: </span></span body></html>" + tmpStr;
            }
            else {
                showStr = "<html><span body><span style=\"color:blue;\">Rx: </span></span body></html>" + tmpStr;
            }
            // if(pageDebugLogFlag == true) {
            //     if(logFile->isOpen()) {
            //         QTextStream textStream(logFile);
            //         textStream << timeStr + "Rx: " + tmpStr + '\n';
            //     }
            // }
        }
        else if(dataType == TypeSendData) {
            if(ui->pageDebugCheckBoxStarmp->isChecked()) {
                showStr = timeStr + "<html><span body><span style=\"color:orange;\">Tx: </span></span body></html>" + tmpStr;
            }
            else {
                showStr = "<html><span body><span style=\"color:orange;\">Tx: </span></span body></html>" + tmpStr;
            }
            // if(pageDebugLogFlag == true) {
            //     if(logFile->isOpen()) {
            //         QTextStream textStream(logFile);
            //         textStream << timeStr + "Rx: " + tmpStr + '\n';
            //     }
            // }
        }

        ui->pageDebugTextBrowser->append(showStr);
    }
    // qDebug("#2");
}

void MainWindow::slot_pageHomeSglDataMessage(QByteArray byteArray, int dataType, uint16_t *data)
{
    if(dataType == TypeRecvData)
    {
        ui->labelVol1->setText(QString::number(data[0]));
        ui->labelVol2->setText(QString::number(data[1]));
        ui->labelVol3->setText(QString::number(data[2]));
        ui->labelVol4->setText(QString::number(data[3]));
        ui->labelVol5->setText(QString::number(data[4]));
        ui->labelVol6->setText(QString::number(data[5]));
        ui->labelVol7->setText(QString::number(data[6]));
        ui->labelVol8->setText(QString::number(data[7]));
        ui->labelVol9->setText(QString::number(data[8]));
        ui->labelVol10->setText(QString::number(data[9]));
        ui->labelVol11->setText(QString::number(data[10]));
        ui->labelVol12->setText(QString::number(data[11]));
        ui->labelVol13->setText(QString::number(data[12]));
        ui->labelVol14->setText(QString::number(data[13]));
        ui->labelVol15->setText(QString::number(data[14]));
        ui->labelVol16->setText(QString::number(data[15]));
    }
}

void MainWindow::slot_pageHomeSglTempt(QByteArray byteArray, int dataType, uint16_t *data)
{
    if(dataType == TypeRecvData)
    {
        ui->labelTemp1->setText(QString::number(data[0]));
        ui->labelTemp2->setText(QString::number(data[1]));
        ui->labelTemp3->setText(QString::number(data[2]));
        ui->labelTemp4->setText(QString::number(data[3]));
        ui->labelTemp5->setText(QString::number(data[4]));
        ui->labelTemp6->setText(QString::number(data[5]));
        ui->labelTemp7->setText(QString::number(data[6]));
        ui->labelTemp8->setText(QString::number(data[7]));
        ui->labelTemp9->setText(QString::number(data[8]));
        ui->labelTemp10->setText(QString::number(data[9]));
        ui->labelTemp11->setText(QString::number(data[10]));
        ui->labelTemp12->setText(QString::number(data[11]));
        ui->labelTemp13->setText(QString::number(data[12]));
        ui->labelTemp14->setText(QString::number(data[13]));
        ui->labelTemp15->setText(QString::number(data[14]));
        ui->labelTemp16->setText(QString::number(data[15]));
    }
}

void MainWindow::slot_pageHomeBaseInfo1_45(QByteArray byteArray, int dataType, uint16_t *data)
{
    if(dataType == TypeRecvData)
    {
        ui->volValue->setText(QString::number(data[0]));
        ui->batVal_vol_all->setText(QString::number(data[0]));
        
        ui->currValue->setText(QString::number(data[1]));
        ui->batVal_cur_all->setText(QString::number(data[1]));
        
        ui->batVal_soc->setText(QString::number(data[2]));
        ui->widgetBatt->setValue(data[2]);
        
        ui->batVal_soh->setText(QString::number(data[3]));
        ui->batVal_soe->setText(QString::number(data[4]));
        ui->batVal_rated_vol->setText(QString::number(data[5]));
        ui->batVal_rated_cap->setText(QString::number(data[6]));
        ui->batVal_remain_cap->setText(QString::number(data[7]));
        ui->batVal_bat_count->setText(QString::number(data[12]));

        battery_count = data[12];

        ui->batVal_tempt_count->setText(QString::number(data[14]));
        ui->batVal_max_dischg_cur->setText(QString::number(data[16]));
        ui->batVal_max_dischg_pwer->setText(QString::number(data[17]));
        ui->batVal_max_chg_cur->setText(QString::number(data[18]));
        ui->batVal_max_chg_pwer->setText(QString::number(data[19]));
        
        ui->batVal_pos_insu_res->setText(QString::number(data[20]));
        ui->batVal_neg_insu_res->setText(QString::number(data[21]));
        ui->batVal_sgl_vol_avg->setText(QString::number(data[22]));
        ui->batVal_sgl_max_press_diff->setText(QString::number(data[23]));
        ui->batVal_max_sgl_vol->setText(QString::number(data[24]));
        ui->batVal_max_sgl_vol_bmu_num->setText(QString::number(data[25]));
        ui->batVal_max_sgl_vol_serial_num->setText(QString::number(data[26]));
        ui->batVal_min_sgl_vol->setText(QString::number(data[27]));
        ui->batVal_min_sgl_vol_bmu_num->setText(QString::number(data[28]));
        ui->batVal_min_sgl_vol_serial_num->setText(QString::number(data[29]));
        ui->batVal_sgl_temp_avg->setText(QString::number(data[30]));
        ui->batVal_sgl_max_temp_diff->setText(QString::number(data[31]));
        ui->batVal_max_sgl_temp->setText(QString::number(data[32]));
        ui->batVal_max_sgl_temp_bmu_num->setText(QString::number(data[33]));
        ui->batVal_max_sgl_temp_serial_num->setText(QString::number(data[34]));
        ui->batVal_min_sgl_temp->setText(QString::number(data[35]));
        ui->batVal_min_sgl_temp_bmu_num->setText(QString::number(data[36]));
        ui->batVal_min_sgl_temp_serial_num->setText(QString::number(data[37]));
        ui->batVal_day_chg_cap->setText(QString::number(data[38]));
        ui->batVal_day_chg_ele->setText(QString::number(data[39]));
        ui->batVal_day_dischg_cap->setText(QString::number(data[40]));
        ui->batVal_day_dischg_ele->setText(QString::number(data[41]));
        ui->batVal_day_chg_time->setText(QString::number(data[42]));
        ui->batVal_day_dischg_time->setText(QString::number(data[43]));
        ui->batVal_leiji_chg_cap->setText(QString::number(data[44]));

        //主页单体值
        ui->label_home_max_sgl_vol->setText(QString::number(data[24]));
        ui->label_home_min_sgl_vol->setText(QString::number(data[27]));
        ui->label_home_max_sgl_temp->setText(QString::number(data[32]));
        ui->label_home_min_sgl_temp->setText(QString::number(data[35]));


        // int array_day_chart[] = {base_info1_45[39], base_info1_45[41], base_info1_45[42], base_info1_45[43]};
        // QChartView *chartView_day = chartPat->Paint("日", array_day_chart);
        // chartView_day->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
        // gridLayout->addWidget(chartView_day, 0, 0);
        // ui->batVal_leiji_chg_ele->setText(QString::number(base_info1_45[46]));
    }
}

void MainWindow::slot_pageHomeBaseInfo57_78(QByteArray byteArray, int dataType, uint16_t *data)
{
    if(dataType == TypeRecvData)
    {
        QList<int> result_int;

        bool ok;
        for (int i = 3; i < byteArray.size(); i += 2) {
            quint8 firstByte = (i < byteArray.size())? byteArray.at(i) : 0;
            quint8 secondByte = (i + 1 < byteArray.size())? byteArray.at(i + 1) : 0;
            QString hexValue = QString("%1%2")
                                   .arg(QString::number(firstByte, 16).rightJustified(2, '0'))
                                   .arg(QString::number(secondByte, 16).rightJustified(2, '0'));

            result_int += hexValue.toInt(&ok, 16);
        }
        base_info57_78 = result_int;
        ui->batVal_bcu_work_status->setText(QString::number(base_info57_78[0]));
        ui->batVal_relay_neg_status->setText(QString::number(base_info57_78[1]));
        ui->batVal_relay_pos_status->setText(QString::number(base_info57_78[2]));
        ui->batVal_relay_dischg_status->setText(QString::number(base_info57_78[3]));
        ui->batVal_relay_chg_status->setText(QString::number(base_info57_78[4]));
        ui->batVal_relay_prechg_status->setText(QString::number(base_info57_78[5]));
        ui->batVal_relay_status->setText(QString::number(base_info57_78[6]));
        ui->batVal_on_off_status->setText(QString::number(base_info57_78[7]));
        ui->batVal_trouble_status->setText(QString::number(base_info57_78[8]));

        /*66~73
            故障1~8的故障等级
            故障9~16的故障等级
            故障17~24的故障等级
            故障25~32的故障等级
            故障33~40的故障等级
            故障41~48的故障等级
            故障49~56的故障等级
            故障57~64的故障等级
        */

        ui->batVal_bat_cycle_number->setText(QString::number(base_info57_78[17]));
        ui->batVal_max_chg_cell_vol->setText(QString::number(base_info57_78[18]));
        ui->batVal_min_chg_cell_vol->setText(QString::number(base_info57_78[19]));

        /*77,78
            最大允许充电总压
            最小允许放电总压
        */
    }
}

void MainWindow::slot_pageHomeBaseInfo83_106(QByteArray byteArray, int dataType, uint16_t *data)
{
    if(dataType == TypeRecvData)
    {
        ui->batVal_samp_press_all->setText(QString::number(data[0]));

        /*84~95
            一级故障（故障位1~16）
            一级故障（故障位17~32）
            一级故障（故障位33~48）
            一级故障（故障位49~64）
            二级故障（故障位1~16）
            二级故障（故障位17~32）
            二级故障（故障位33~48）
            二级故障（故障位49~64）
            三级故障（故障位1~16）
            三级故障（故障位17~32）
            三级故障（故障位33~48）
            三级故障（故障位49~64）
        */

        ui->batVal_state_machine->setText(QString::number(data[13]));
        ui->batVal_chg_satus->setText(QString::number(data[14]));
        ui->batVal_dischg_satus->setText(QString::number(data[15]));
        ui->batVal_high_press_close_status->setText(QString::number(data[16]));
        ui->batVal_fan_status->setText(QString::number(data[17]));
        ui->batVal_all_alert->setText(QString::number(data[18]));
        ui->batVal__trouble_all->setText(QString::number(data[19]));

        /*103~106
            BCU地址
            BCU主回路状态
            BCU回路闭合指令
            BCU是否允许闭合主回路
        */

    }
}

void MainWindow::slot_pageHomeBaseInfo47_49_51_53_55(QList<int> byteArray, int dataType)
{
    if(dataType == TypeRecvData)
    {
        // QList<int> result_int;

        // bool ok;
        // for (int i = 3; i < byteArray.size(); i += 2) {
        //     quint8 firstByte = (i < byteArray.size())? byteArray.at(i) : 0;
        //     quint8 secondByte = (i + 1 < byteArray.size())? byteArray.at(i + 1) : 0;
        //     QString hexValue = QString("%1%2")
        //                            .arg(QString::number(firstByte, 16).rightJustified(2, '0'))
        //                            .arg(QString::number(secondByte, 16).rightJustified(2, '0'));

        //     result_int += hexValue.toInt(&ok, 16);
        // }

        // for (int i = 0; i < byteArray.size(); i += 2) {
        //     uint16_t value;
        //     memcpy(&value, byteArray.data() + i, 2);
        //     base_info47_49_51_53_55.append(value);
        //     // qDebug() << "Value: " << value;
        // }
        // base_info47_49_51_53_55 = result_int;

        // qDebug() << byteArray;
        ui->batVal_leiji_chg_ele->setText(QString::number(byteArray[0]));
        ui->batVal_leiji_dischg_cap->setText(QString::number(byteArray[1]));
        ui->batVal_leiji_dischg_ele->setText(QString::number(byteArray[2]));
        ui->batVal_leiji_chg_time->setText(QString::number(byteArray[3]));
        ui->batVal_leiji_dischg_time->setText(QString::number(byteArray[4]));

        // int array_leiji_chart[] = {byteArray[0], byteArray[2], byteArray[3], byteArray[4]};
        // QChartView *chartView_leiji = chartPat->Paint("累计", array_leiji_chart);
        // chartView_leiji->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
        // chartView_leiji->setSizeAdjustPolicy(QChartView::AdjustToContents);
        // gridLayout->addWidget(chartView_leiji, 0, 1);
    }
}

void MainWindow::sgl_info_process(QList<int> sgl_info, QList<QLabel*> labelList)
{
    // ui->tabWidget_sgl_info->update();
    int MaxIndex = findMaxIndex(sgl_info);
    int MinIndex = findMinIndex(sgl_info);

    /*
    ui->color_sgl_high->setStyleSheet("background-color: rgb(255, 0, 0);");
    ui->color_sgl_low->setStyleSheet("background-color: rgb(0, 255, 0);");
    ui->color_equilibrium->setStyleSheet("background-color: rgb(0, 0, 200);");
    ui->color_short_circuit->setStyleSheet("background-color: rgb(255, 165, 0);");
    */
    for (int i=0;i < sgl_info.size(); i++)
    {
        labelList[i]->setText(QString::number(sgl_info[i]));
        labelList[i]->setAlignment(Qt::AlignCenter);
        QFont font("黑体", 10);
        labelList[i]->setFont(font);

        if(i == MaxIndex)
        {
            labelList[MaxIndex]->setStyleSheet("QLabel{background-color:rgb(255, 0, 0);}");
        }
        else if (i == MinIndex)
        {
            labelList[MinIndex]->setStyleSheet("QLabel{background-color:rgb(0, 255, 0);}");
        }
        else
        {
            labelList[i]->setStyleSheet("QLabel{background-color:rgb(255, 255, 255);}");
        }
    }
}

int MainWindow::findMaxIndex(QList<int> sgl_info)
{
    if (sgl_info.isEmpty()) return -1;
    int maxValue = sgl_info.at(0);
    int maxIndex = 0;
    for (int i = 1; i < sgl_info.size(); ++i) {
        int value = sgl_info.at(i);
        if (value > maxValue) {
            maxValue = value;
            maxIndex = i;
        }
    }
    return maxIndex;
}

int MainWindow::findMinIndex(QList<int> sgl_info)
{
    if (sgl_info.isEmpty()) return -1;
    int minValue = sgl_info.at(0);
    int minIndex = 0;
    for (int i = 1; i < sgl_info.size(); ++i) {
        int value = sgl_info.at(i);
        if (value < minValue) {
            minValue = value;
            minIndex = i;
        }
    }
    return minIndex;
}

void MainWindow::getLanNumberSlot(int number)
{
    lan = number;
    qDebug() << "lan:" << lan;
    pageBatteryInit();
    pageParaSetInit();
    pageParaSetInit_alert_value();
    pageParaSetInit_alert_delay();
    pageParaSetInit_alert_release_value();
    pageParaSetInit_alert_release_delay();
    pageParaSetInit_alert_dropcurr_rate();
    pageParaSetInit_alert_solve_measure();
    pageParaSetInit_DIDO_setting();
    pageParaSetInit_balance_setting();
    pageParaSetInit_SOX_setting();
    pageParaSetInit_other_setting();
    pageHomeHistoryAlarm();
    pageFlashGetVersion();
}

void MainWindow::pageBatteryInit()
{

}

void MainWindow::pageHomeHistoryAlarm()
{
    ui->groupBox_history_alarm->setStyleSheet("background-color: #FFFFFF;");
    /*设置默认行高*/
    ui->tableView_history_alarm->verticalHeader()->setDefaultSectionSize(26);
    /*设置交替行颜色--允许交替行颜色*/
    ui->tableView_history_alarm->setAlternatingRowColors(true);
    /*设置水平/垂直滚动模式--一次滚动一个项目*/
    ui->tableView_history_alarm->setHorizontalScrollMode(QAbstractItemView::ScrollPerItem);
    ui->tableView_history_alarm->setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
    /*设置选择行为--每次选择只有一整行*/
    ui->tableView_history_alarm->setSelectionBehavior(QAbstractItemView::SelectRows);
    /*设置拖放行为--不允许拖放*/
    ui->tableView_history_alarm->setDragDropMode(QAbstractItemView::NoDragDrop);
    /*设置选择模式--只能选择一个项目*/
    ui->tableView_history_alarm->setSelectionMode(QAbstractItemView::SingleSelection);
    /*设置Tab导航键--允许使用Tab键导航，shift+tab反向导航*/
    ui->tableView_history_alarm->setTabKeyNavigation(true);
    /*设置是否自动换行--取消自动换行*/
    ui->tableView_history_alarm->setWordWrap(false);
    /*设置文本省略模式--省略号不会出现在文本中*/
    ui->tableView_history_alarm->setTextElideMode(Qt::ElideNone);
    /*设置左上角全选按钮--禁用*/
    ui->tableView_history_alarm->setCornerButtonEnabled(false);
    /*设置是否支持表头排序--应该和表头是否可以单击保持一致*/
    ui->tableView_history_alarm->setSortingEnabled(false);
    /*设置是否显示网格线*/
    ui->tableView_history_alarm->setShowGrid(true);
    ui->tableView_history_alarm->sizePolicy();
    /*设置垂直表头是否可见*/
    ui->tableView_history_alarm->verticalHeader()->setVisible(false);
    /*设置选中一行表头是否加粗--不加粗*/
    ui->tableView_history_alarm->horizontalHeader()->setHighlightSections(true);
    /*设置最后一行是否拉伸填充*/
    ui->tableView_history_alarm->horizontalHeader()->setStretchLastSection(true);
    /*设置行标题最小宽度尺寸*/
    ui->tableView_history_alarm->horizontalHeader()->setMinimumSectionSize(0);
    /*设置行标题最小高度*/
    ui->tableView_history_alarm->horizontalHeader()->setFixedHeight(30);
    /*设置表头是否可以单击--不可单击*/
    ui->tableView_history_alarm->horizontalHeader()->setSectionsClickable(false);
    ui->tableView_history_alarm->verticalHeader()->setHidden(false);

    ui->tableView_history_alarm->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    /*是否可编辑*/
    if(true)
    {
        ui->tableView_history_alarm->setEditTriggers(QAbstractItemView::CurrentChanged|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
    }
    else
    {
        ui->tableView_history_alarm->setEditTriggers(QAbstractItemView::NoEditTriggers);
    }

    QStringList columnNames;
    QList<int> columnWidths;
    columnNames << "时间" << "告警名称" << "BCUId" << "状态";
    columnWidths << 360 << 240 << 240 << 240;

    QStringList columnNames_english;
    QList<int> columnWidths_english;
    columnNames_english << "Time" << "Alarm Name" << "BCUId" << "Status";
    columnWidths_english << 360 << 240 << 240 << 240;

    if(lan == 0)
    {
        model_history_alarm = new QStandardItemModel;
        model_history_alarm->setHorizontalHeaderLabels(columnNames_english);
        ui->tableView_history_alarm->setModel(model_history_alarm);
        int count = columnNames_english.count();
        for(int i = 0; i< count;i++)
        {
            ui->tableView_history_alarm->setColumnWidth(i, columnWidths_english.at(i));
        }
    }
    else if(lan == 1)
    {
        model_history_alarm = new QStandardItemModel;
        model_history_alarm->setHorizontalHeaderLabels(columnNames);
        ui->tableView_history_alarm->setModel(model_history_alarm);
        int count = columnNames.count();
        for(int i = 0; i< count;i++)
        {
            ui->tableView_history_alarm->setColumnWidth(i, columnWidths.at(i));
        }
    }




    Delegate *labelDelegate = new Delegate;
    labelDelegate->setDelegateType("QLabel");
    ui->tableView_history_alarm->setItemDelegateForColumn(0, labelDelegate);

    Delegate *labelDelegate1 = new Delegate;
    labelDelegate1->setDelegateType("QLabel");
    ui->tableView_history_alarm->setItemDelegateForColumn(1,labelDelegate1);

    Delegate * labelDelegate2 = new Delegate;
    labelDelegate2->setDelegateType("QLabel");
    ui->tableView_history_alarm->setItemDelegateForColumn(2, labelDelegate2);

    Delegate *labelDelegate3 = new Delegate;
    labelDelegate3->setDelegateType("QLabel");
    ui->tableView_history_alarm->setItemDelegateForColumn(3,labelDelegate3);

    // if(lan == 0)
    // {

    // }
    // else if(lan == 1)
    // {

    // }

}

void MainWindow::pageFlashGetVersion()
{
    ui->tableView_Version->setStyleSheet("background-color: #FFFFFF;");
    /*设置默认行高*/
    ui->tableView_Version->verticalHeader()->setDefaultSectionSize(26);
    /*设置交替行颜色--允许交替行颜色*/
    ui->tableView_Version->setAlternatingRowColors(true);
    /*设置水平/垂直滚动模式--一次滚动一个项目*/
    ui->tableView_Version->setHorizontalScrollMode(QAbstractItemView::ScrollPerItem);
    ui->tableView_Version->setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
    /*设置选择行为--每次选择只有一整行*/
    ui->tableView_Version->setSelectionBehavior(QAbstractItemView::SelectRows);
    /*设置拖放行为--不允许拖放*/
    ui->tableView_Version->setDragDropMode(QAbstractItemView::NoDragDrop);
    /*设置选择模式--只能选择一个项目*/
    ui->tableView_Version->setSelectionMode(QAbstractItemView::SingleSelection);
    /*设置Tab导航键--允许使用Tab键导航，shift+tab反向导航*/
    ui->tableView_Version->setTabKeyNavigation(true);
    /*设置是否自动换行--取消自动换行*/
    ui->tableView_Version->setWordWrap(false);
    /*设置文本省略模式--省略号不会出现在文本中*/
    ui->tableView_Version->setTextElideMode(Qt::ElideNone);
    /*设置左上角全选按钮--禁用*/
    ui->tableView_Version->setCornerButtonEnabled(false);
    /*设置是否支持表头排序--应该和表头是否可以单击保持一致*/
    ui->tableView_Version->setSortingEnabled(false);
    /*设置是否显示网格线*/
    ui->tableView_Version->setShowGrid(true);
    /*设置垂直表头是否可见*/
    ui->tableView_Version->verticalHeader()->setVisible(false);
    /*设置选中一行表头是否加粗--不加粗*/
    ui->tableView_Version->horizontalHeader()->setHighlightSections(true);
    /*设置最后一行是否拉伸填充*/
    ui->tableView_Version->horizontalHeader()->setStretchLastSection(true);
    /*设置行标题最小宽度尺寸*/
    ui->tableView_Version->horizontalHeader()->setMinimumSectionSize(0);
    /*设置行标题最小高度*/
    ui->tableView_Version->horizontalHeader()->setFixedHeight(35);
    /*设置表头是否可以单击--不可单击*/
    ui->tableView_Version->horizontalHeader()->setSectionsClickable(false);
    ui->tableView_Version->verticalHeader()->setHidden(false);

    ui->tableView_Version->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    /*是否可编辑*/
    if(true)
    {
        ui->tableView_Version->setEditTriggers(QAbstractItemView::CurrentChanged|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
    }
    else
    {
        ui->tableView_Version->setEditTriggers(QAbstractItemView::NoEditTriggers);
    }

    QStringList columnNames;
    QList<int> columnWidths;
    columnNames << "ID" << "升级前版本号" << "升级后版本号" ;
    columnWidths << 120 << 360 << 360 ;

    QStringList columnNames_english;
    QList<int> columnWidths_english;
    columnNames_english << "ID" << "Version before upgrade" << "Version after upgrade" ;
    columnWidths_english << 120 << 360 << 360 ;

    if(lan == 0)
    {
        model_get_version = new QStandardItemModel;
        model_get_version->setHorizontalHeaderLabels(columnNames_english);
        ui->tableView_Version->setModel(model_get_version);
        int count = columnNames_english.count();
        for(int i = 0; i< count;i++)
        {
            ui->tableView_Version->setColumnWidth(i, columnWidths_english.at(i));
        }
    }
    else if(lan == 1)
    {
        model_get_version = new QStandardItemModel;
        model_get_version->setHorizontalHeaderLabels(columnNames);
        ui->tableView_Version->setModel(model_get_version);
        int count = columnNames.count();
        for(int i = 0; i< count;i++)
        {
            ui->tableView_Version->setColumnWidth(i, columnWidths.at(i));
        }
    }

    Delegate *labelDelegate = new Delegate;
    labelDelegate->setDelegateType("QLabel");
    ui->tableView_Version->setItemDelegateForColumn(0, labelDelegate);

    Delegate *labelDelegate1 = new Delegate;
    labelDelegate1->setDelegateType("QLabel");
    ui->tableView_Version->setItemDelegateForColumn(1,labelDelegate1);

    Delegate * labelDelegate2 = new Delegate;
    labelDelegate2->setDelegateType("QLabel");
    ui->tableView_Version->setItemDelegateForColumn(2, labelDelegate2);
}

void MainWindow::pageParaSetInit()
{
    ui->tabWidget_paraset->setCurrentIndex(0);
    ui->tabWidget_paraset->setStyleSheet("background-color: #FFFFFF;");
    ui->pageParaSet->setStyleSheet("background-color: #FFFFFF;");
    /*设置默认行高*/
    ui->tableView_paraset_sys->verticalHeader()->setDefaultSectionSize(26);
    /*设置交替行颜色--允许交替行颜色*/
    ui->tableView_paraset_sys->setAlternatingRowColors(true);
    /*设置水平/垂直滚动模式--一次滚动一个项目*/
    ui->tableView_paraset_sys->setHorizontalScrollMode(QAbstractItemView::ScrollPerItem);
    ui->tableView_paraset_sys->setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
    /*设置选择行为--每次选择只有一整行*/
    ui->tableView_paraset_sys->setSelectionBehavior(QAbstractItemView::SelectRows);
    /*设置拖放行为--不允许拖放*/
    ui->tableView_paraset_sys->setDragDropMode(QAbstractItemView::NoDragDrop);
    /*设置选择模式--只能选择一个项目*/
    ui->tableView_paraset_sys->setSelectionMode(QAbstractItemView::SingleSelection);
    /*设置Tab导航键--允许使用Tab键导航，shift+tab反向导航*/
    ui->tableView_paraset_sys->setTabKeyNavigation(true);
    /*设置是否自动换行--取消自动换行*/
    ui->tableView_paraset_sys->setWordWrap(false);
    /*设置文本省略模式--省略号不会出现在文本中*/
    ui->tableView_paraset_sys->setTextElideMode(Qt::ElideNone);
    /*设置左上角全选按钮--禁用*/
    ui->tableView_paraset_sys->setCornerButtonEnabled(false);
    /*设置是否支持表头排序--应该和表头是否可以单击保持一致*/
    ui->tableView_paraset_sys->setSortingEnabled(false);
    /*设置是否显示网格线*/
    ui->tableView_paraset_sys->setShowGrid(true);
    /*设置垂直表头是否可见*/
    ui->tableView_paraset_sys->verticalHeader()->setVisible(true);
    /*设置选中一行表头是否加粗--不加粗*/
    ui->tableView_paraset_sys->horizontalHeader()->setHighlightSections(true);
    /*设置最后一行是否拉伸填充*/
    ui->tableView_paraset_sys->horizontalHeader()->setStretchLastSection(true);
    /*设置行标题最小宽度尺寸*/
    ui->tableView_paraset_sys->horizontalHeader()->setMinimumSectionSize(0);
    /*设置行标题最小高度*/
    ui->tableView_paraset_sys->horizontalHeader()->setFixedHeight(35);
    /*设置表头是否可以单击--不可单击*/
    ui->tableView_paraset_sys->horizontalHeader()->setSectionsClickable(false);
    ui->tableView_paraset_sys->verticalHeader()->setHidden(false);
    /*是否可编辑*/
    if(true)
    {
        ui->tableView_paraset_sys->setEditTriggers(QAbstractItemView::CurrentChanged|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
    }
    else
    {
        ui->tableView_paraset_sys->setEditTriggers(QAbstractItemView::NoEditTriggers);
    }

    QStringList columnNames;
    QList<int> columnWidths;
    columnNames << "check" << "name" << "value" << "introduce";
    columnWidths << 60 << 420 << 120 << 120;

    model = new QStandardItemModel;
    model->setHorizontalHeaderLabels(columnNames);
    ui->tableView_paraset_sys->setModel(model);
    int count = columnNames.count();
    for(int i = 0; i< count;i++)
    {
        ui->tableView_paraset_sys->setColumnWidth(i, columnWidths.at(i));
    }


    Delegate *checkDelegate = new Delegate;
    checkDelegate->setDelegateType("QCheckBox");
    checkDelegate->setDelegateColumn(0);
    ui->tableView_paraset_sys->setItemDelegateForColumn(0, checkDelegate);

    Delegate *labelDelegate = new Delegate;
    labelDelegate->setDelegateType("QLabel");
    ui->tableView_paraset_sys->setItemDelegateForColumn(1,labelDelegate);
    Delegate * lineEidtDelegate1 = new Delegate;
    lineEidtDelegate1->setDelegateType("QLineEdit");
    ui->tableView_paraset_sys->setItemDelegateForColumn(2, lineEidtDelegate1);

    Delegate *labelDelegate1 = new Delegate;
    labelDelegate1->setDelegateType("QLabel");
    ui->tableView_paraset_sys->setItemDelegateForColumn(3,labelDelegate1);

    if(lan == 0)
    {
        BatteryConfig_English::Item item;
        std::ifstream finBetteryData("battery_english.data", std::ios::binary);
        if(!item.ParseFromIstream(&finBetteryData)) {
            qDebug() << __FUNCTION__ << __LINE__ << "proto parse failed";
            finBetteryData.close();
            finBetteryData.clear();
        }
        else {
            qDebug() << "english_item size: 11111111111111" << item.itemattr_size();
            for(int i = 0; i < item.itemattr_size(); i++)
            {
                for(int j = 0; j < 4; j++) {
                    if(j == 1) {
                        model->setItem(i, j, new QStandardItem(item.itemattr(i).name().c_str()));
                    }
                    else if(j == 2) {
                        model->setItem(i, j, new QStandardItem(QString::number(item.itemattr(i).value())));
                    }
                    else if(j == 3) {
                        model->setItem(i, j, new QStandardItem(item.itemattr(i).introduce().c_str()));
                    }
                }
            }
            finBetteryData.close();
            finBetteryData.clear();
        }
    }
    else if(lan == 1)
    {
        BatteryConfig::Item item;
        std::ifstream finBetteryData("battery.data", std::ios::binary);
        if(!item.ParseFromIstream(&finBetteryData)) {
            qDebug() << __FUNCTION__ << __LINE__ << "proto parse failed";
            finBetteryData.close();
            finBetteryData.clear();
        }
        else {
            qDebug() << "item size: 11111111111111" << item.itemattr_size();

            for(int i = 0; i < item.itemattr_size(); i++)
            {
                for(int j = 0; j < 4; j++) {
                    if(j == 1) {
                        model->setItem(i, j, new QStandardItem(item.itemattr(i).name().c_str()));
                    }
                    else if(j == 2) {
                        model->setItem(i, j, new QStandardItem(QString::number(item.itemattr(i).value())));
                    }
                    else if(j == 3) {
                        model->setItem(i, j, new QStandardItem(item.itemattr(i).introduce().c_str()));
                    }
                }
            }
            finBetteryData.close();
            finBetteryData.clear();
        }
    }


}

void MainWindow::pageParaSetInit_alert_value()
{
    // ui->tabWidget_paraset->setStyleSheet("background-color: #FFFFFF;");
    // ui->pageParaSet->setStyleSheet("background-color: #FFFFFF;");
    /*设置默认行高*/
    ui->tableView_paraset_alert_value->verticalHeader()->setDefaultSectionSize(26);
    /*设置交替行颜色--允许交替行颜色*/
    ui->tableView_paraset_alert_value->setAlternatingRowColors(true);
    /*设置水平/垂直滚动模式--一次滚动一个项目*/
    ui->tableView_paraset_alert_value->setHorizontalScrollMode(QAbstractItemView::ScrollPerItem);
    ui->tableView_paraset_alert_value->setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
    /*设置选择行为--每次选择只有一整行*/
    ui->tableView_paraset_alert_value->setSelectionBehavior(QAbstractItemView::SelectRows);
    /*设置拖放行为--不允许拖放*/
    ui->tableView_paraset_alert_value->setDragDropMode(QAbstractItemView::NoDragDrop);
    /*设置选择模式--只能选择一个项目*/
    ui->tableView_paraset_alert_value->setSelectionMode(QAbstractItemView::SingleSelection);
    /*设置Tab导航键--允许使用Tab键导航，shift+tab反向导航*/
    ui->tableView_paraset_alert_value->setTabKeyNavigation(true);
    /*设置是否自动换行--取消自动换行*/
    ui->tableView_paraset_alert_value->setWordWrap(false);
    /*设置文本省略模式--省略号不会出现在文本中*/
    ui->tableView_paraset_alert_value->setTextElideMode(Qt::ElideNone);
    /*设置左上角全选按钮--禁用*/
    ui->tableView_paraset_alert_value->setCornerButtonEnabled(false);
    /*设置是否支持表头排序--应该和表头是否可以单击保持一致*/
    ui->tableView_paraset_alert_value->setSortingEnabled(false);
    /*设置是否显示网格线*/
    ui->tableView_paraset_alert_value->setShowGrid(true);
    /*设置垂直表头是否可见*/
    ui->tableView_paraset_alert_value->verticalHeader()->setVisible(true);
    /*设置选中一行表头是否加粗--不加粗*/
    ui->tableView_paraset_alert_value->horizontalHeader()->setHighlightSections(true);
    /*设置最后一行是否拉伸填充*/
    ui->tableView_paraset_alert_value->horizontalHeader()->setStretchLastSection(true);
    /*设置行标题最小宽度尺寸*/
    ui->tableView_paraset_alert_value->horizontalHeader()->setMinimumSectionSize(0);
    /*设置行标题最小高度*/
    ui->tableView_paraset_alert_value->horizontalHeader()->setFixedHeight(35);
    /*设置表头是否可以单击--不可单击*/
    ui->tableView_paraset_alert_value->horizontalHeader()->setSectionsClickable(false);
    ui->tableView_paraset_alert_value->verticalHeader()->setHidden(false);
    /*是否可编辑*/
    if(true)
    {
        ui->tableView_paraset_alert_value->setEditTriggers(QAbstractItemView::CurrentChanged|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
    }
    else
    {
        ui->tableView_paraset_alert_value->setEditTriggers(QAbstractItemView::NoEditTriggers);
    }

    QStringList columnNames;
    QList<int> columnWidths;
    columnNames << "check" << "name" << "value" << "introduce";
    columnWidths << 60 << 420 << 120 << 120;

    model = new QStandardItemModel;
    model->setHorizontalHeaderLabels(columnNames);
    ui->tableView_paraset_alert_value->setModel(model);
    int count = columnNames.count();
    for(int i = 0; i< count;i++)
    {
        ui->tableView_paraset_alert_value->setColumnWidth(i, columnWidths.at(i));
    }


    Delegate *checkDelegate = new Delegate;
    checkDelegate->setDelegateType("QCheckBox");
    checkDelegate->setDelegateColumn(0);
    ui->tableView_paraset_alert_value->setItemDelegateForColumn(0, checkDelegate);

    Delegate *labelDelegate = new Delegate;
    labelDelegate->setDelegateType("QLabel");
    ui->tableView_paraset_alert_value->setItemDelegateForColumn(1,labelDelegate);
    Delegate * lineEidtDelegate1 = new Delegate;
    lineEidtDelegate1->setDelegateType("QLineEdit");
    ui->tableView_paraset_alert_value->setItemDelegateForColumn(2, lineEidtDelegate1);

    Delegate *labelDelegate1 = new Delegate;
    labelDelegate1->setDelegateType("QLabel");
    ui->tableView_paraset_alert_value->setItemDelegateForColumn(3,labelDelegate1);

    if(lan == 0)
    {
        BatteryConfig_English::Item item;
        std::ifstream finBetteryData("battery_english.data", std::ios::binary);
        if(!item.ParseFromIstream(&finBetteryData)) {
            qDebug() << __FUNCTION__ << __LINE__ << "proto parse failed";
            finBetteryData.close();
            finBetteryData.clear();
        }
        else {
            for(int i = 0; i < item.itemattr_alert_value_size(); i++) {
                for(int j = 0; j < 4; j++) {
                    if(j == 1) {
                        model->setItem(i, j, new QStandardItem(item.mutable_itemattr_alert_value(i)->name().c_str()));
                    }
                    else if(j == 2) {
                        model->setItem(i, j, new QStandardItem(QString::number(item.mutable_itemattr_alert_value(i)->value())));
                    }
                    else if(j == 3) {
                        model->setItem(i, j, new QStandardItem(item.mutable_itemattr_alert_value(i)->introduce().c_str()));
                    }
                }
            }

            finBetteryData.close();
            finBetteryData.clear();
        }
    }
    else if(lan == 1)
    {
        BatteryConfig::Item item;
        std::ifstream finBetteryData("battery.data", std::ios::binary);
        if(!item.ParseFromIstream(&finBetteryData)) {
            qDebug() << __FUNCTION__ << __LINE__ << "proto parse failed";
            finBetteryData.close();
            finBetteryData.clear();
        }
        else {
            for(int i = 0; i < item.itemattr_alert_value_size(); i++) {
                for(int j = 0; j < 4; j++) {
                    if(j == 1) {
                        model->setItem(i, j, new QStandardItem(item.mutable_itemattr_alert_value(i)->name().c_str()));
                    }
                    else if(j == 2) {
                        model->setItem(i, j, new QStandardItem(QString::number(item.mutable_itemattr_alert_value(i)->value())));
                    }
                    else if(j == 3) {
                        model->setItem(i, j, new QStandardItem(item.mutable_itemattr_alert_value(i)->introduce().c_str()));
                    }
                }
            }

            finBetteryData.close();
            finBetteryData.clear();
        }
    }
}

void MainWindow::pageParaSetInit_alert_delay()
{
    // ui->tabWidget_paraset->setStyleSheet("background-color: #FFFFFF;");
    // ui->pageParaSet->setStyleSheet("background-color: #FFFFFF;");
    /*设置默认行高*/
    ui->tableView_paraset_alert_delay->verticalHeader()->setDefaultSectionSize(26);
    /*设置交替行颜色--允许交替行颜色*/
    ui->tableView_paraset_alert_delay->setAlternatingRowColors(true);
    /*设置水平/垂直滚动模式--一次滚动一个项目*/
    ui->tableView_paraset_alert_delay->setHorizontalScrollMode(QAbstractItemView::ScrollPerItem);
    ui->tableView_paraset_alert_delay->setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
    /*设置选择行为--每次选择只有一整行*/
    ui->tableView_paraset_alert_delay->setSelectionBehavior(QAbstractItemView::SelectRows);
    /*设置拖放行为--不允许拖放*/
    ui->tableView_paraset_alert_delay->setDragDropMode(QAbstractItemView::NoDragDrop);
    /*设置选择模式--只能选择一个项目*/
    ui->tableView_paraset_alert_delay->setSelectionMode(QAbstractItemView::SingleSelection);
    /*设置Tab导航键--允许使用Tab键导航，shift+tab反向导航*/
    ui->tableView_paraset_alert_delay->setTabKeyNavigation(true);
    /*设置是否自动换行--取消自动换行*/
    ui->tableView_paraset_alert_delay->setWordWrap(false);
    /*设置文本省略模式--省略号不会出现在文本中*/
    ui->tableView_paraset_alert_delay->setTextElideMode(Qt::ElideNone);
    /*设置左上角全选按钮--禁用*/
    ui->tableView_paraset_alert_delay->setCornerButtonEnabled(false);
    /*设置是否支持表头排序--应该和表头是否可以单击保持一致*/
    ui->tableView_paraset_alert_delay->setSortingEnabled(false);
    /*设置是否显示网格线*/
    ui->tableView_paraset_alert_delay->setShowGrid(true);
    /*设置垂直表头是否可见*/
    ui->tableView_paraset_alert_delay->verticalHeader()->setVisible(true);
    /*设置选中一行表头是否加粗--不加粗*/
    ui->tableView_paraset_alert_delay->horizontalHeader()->setHighlightSections(true);
    /*设置最后一行是否拉伸填充*/
    ui->tableView_paraset_alert_delay->horizontalHeader()->setStretchLastSection(true);
    /*设置行标题最小宽度尺寸*/
    ui->tableView_paraset_alert_delay->horizontalHeader()->setMinimumSectionSize(0);
    /*设置行标题最小高度*/
    ui->tableView_paraset_alert_delay->horizontalHeader()->setFixedHeight(35);
    /*设置表头是否可以单击--不可单击*/
    ui->tableView_paraset_alert_delay->horizontalHeader()->setSectionsClickable(false);
    ui->tableView_paraset_alert_delay->verticalHeader()->setHidden(false);
    /*是否可编辑*/
    if(true)
    {
        ui->tableView_paraset_alert_delay->setEditTriggers(QAbstractItemView::CurrentChanged|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
    }
    else
    {
        ui->tableView_paraset_alert_delay->setEditTriggers(QAbstractItemView::NoEditTriggers);
    }

    QStringList columnNames;
    QList<int> columnWidths;
    columnNames << "check" << "name" << "value" << "introduce";
    columnWidths << 60 << 420 << 120 << 120;

    model = new QStandardItemModel;
    model->setHorizontalHeaderLabels(columnNames);
    ui->tableView_paraset_alert_delay->setModel(model);
    int count = columnNames.count();
    for(int i = 0; i< count;i++)
    {
        ui->tableView_paraset_alert_delay->setColumnWidth(i, columnWidths.at(i));
    }


    Delegate *checkDelegate = new Delegate;
    checkDelegate->setDelegateType("QCheckBox");
    checkDelegate->setDelegateColumn(0);
    ui->tableView_paraset_alert_delay->setItemDelegateForColumn(0, checkDelegate);

    Delegate *labelDelegate = new Delegate;
    labelDelegate->setDelegateType("QLabel");
    ui->tableView_paraset_alert_delay->setItemDelegateForColumn(1,labelDelegate);
    Delegate * lineEidtDelegate1 = new Delegate;
    lineEidtDelegate1->setDelegateType("QLineEdit");
    ui->tableView_paraset_alert_delay->setItemDelegateForColumn(2, lineEidtDelegate1);

    Delegate *labelDelegate1 = new Delegate;
    labelDelegate1->setDelegateType("QLabel");
    ui->tableView_paraset_alert_delay->setItemDelegateForColumn(3,labelDelegate1);

    if(lan == 0)
    {
        BatteryConfig_English::Item item;
        std::ifstream finBetteryData("battery_english.data", std::ios::binary);
        if(!item.ParseFromIstream(&finBetteryData)) {
            qDebug() << __FUNCTION__ << __LINE__ << "proto parse failed";
            finBetteryData.close();
            finBetteryData.clear();
        }
        else {
            for(int i = 0; i < item.itemattr_alert_delay_size(); i++)
            {
                for(int j = 0; j < 4; j++) {
                    if(j == 1) {
                        model->setItem(i, j, new QStandardItem(item.mutable_itemattr_alert_delay(i)->name().c_str()));
                    }
                    else if(j == 2) {
                        model->setItem(i, j, new QStandardItem(QString::number(item.mutable_itemattr_alert_delay(i)->value())));
                    }
                    else if(j == 3) {
                        model->setItem(i, j, new QStandardItem(item.mutable_itemattr_alert_delay(i)->introduce().c_str()));
                    }
                }
            }

            finBetteryData.close();
            finBetteryData.clear();
        }
    }
    else if(lan == 1)
    {
        BatteryConfig::Item item;
        std::ifstream finBetteryData("battery.data", std::ios::binary);
        if(!item.ParseFromIstream(&finBetteryData)) {
            qDebug() << __FUNCTION__ << __LINE__ << "proto parse failed";
            finBetteryData.close();
            finBetteryData.clear();
        }
        else {
            for(int i = 0; i < item.itemattr_alert_delay_size(); i++) {
                for(int j = 0; j < 4; j++) {
                    if(j == 1) {
                        model->setItem(i, j, new QStandardItem(item.mutable_itemattr_alert_delay(i)->name().c_str()));
                    }
                    else if(j == 2) {
                        model->setItem(i, j, new QStandardItem(QString::number(item.mutable_itemattr_alert_delay(i)->value())));
                    }
                    else if(j == 3) {
                        model->setItem(i, j, new QStandardItem(item.mutable_itemattr_alert_delay(i)->introduce().c_str()));
                    }
                }
            }
            finBetteryData.close();
            finBetteryData.clear();
        }
    }

}

void MainWindow::pageParaSetInit_alert_release_value()
{
    // ui->tabWidget_paraset->setStyleSheet("background-color: #FFFFFF;");
    // ui->pageParaSet->setStyleSheet("background-color: #FFFFFF;");
    /*设置默认行高*/
    ui->tableView_paraset_alert_release_value->verticalHeader()->setDefaultSectionSize(26);
    /*设置交替行颜色--允许交替行颜色*/
    ui->tableView_paraset_alert_release_value->setAlternatingRowColors(true);
    /*设置水平/垂直滚动模式--一次滚动一个项目*/
    ui->tableView_paraset_alert_release_value->setHorizontalScrollMode(QAbstractItemView::ScrollPerItem);
    ui->tableView_paraset_alert_release_value->setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
    /*设置选择行为--每次选择只有一整行*/
    ui->tableView_paraset_alert_release_value->setSelectionBehavior(QAbstractItemView::SelectRows);
    /*设置拖放行为--不允许拖放*/
    ui->tableView_paraset_alert_release_value->setDragDropMode(QAbstractItemView::NoDragDrop);
    /*设置选择模式--只能选择一个项目*/
    ui->tableView_paraset_alert_release_value->setSelectionMode(QAbstractItemView::SingleSelection);
    /*设置Tab导航键--允许使用Tab键导航，shift+tab反向导航*/
    ui->tableView_paraset_alert_release_value->setTabKeyNavigation(true);
    /*设置是否自动换行--取消自动换行*/
    ui->tableView_paraset_alert_release_value->setWordWrap(false);
    /*设置文本省略模式--省略号不会出现在文本中*/
    ui->tableView_paraset_alert_release_value->setTextElideMode(Qt::ElideNone);
    /*设置左上角全选按钮--禁用*/
    ui->tableView_paraset_alert_release_value->setCornerButtonEnabled(false);
    /*设置是否支持表头排序--应该和表头是否可以单击保持一致*/
    ui->tableView_paraset_alert_release_value->setSortingEnabled(false);
    /*设置是否显示网格线*/
    ui->tableView_paraset_alert_release_value->setShowGrid(true);
    /*设置垂直表头是否可见*/
    ui->tableView_paraset_alert_release_value->verticalHeader()->setVisible(true);
    /*设置选中一行表头是否加粗--不加粗*/
    ui->tableView_paraset_alert_release_value->horizontalHeader()->setHighlightSections(true);
    /*设置最后一行是否拉伸填充*/
    ui->tableView_paraset_alert_release_value->horizontalHeader()->setStretchLastSection(true);
    /*设置行标题最小宽度尺寸*/
    ui->tableView_paraset_alert_release_value->horizontalHeader()->setMinimumSectionSize(0);
    /*设置行标题最小高度*/
    ui->tableView_paraset_alert_release_value->horizontalHeader()->setFixedHeight(35);
    /*设置表头是否可以单击--不可单击*/
    ui->tableView_paraset_alert_release_value->horizontalHeader()->setSectionsClickable(false);
    ui->tableView_paraset_alert_release_value->verticalHeader()->setHidden(false);
    /*是否可编辑*/
    if(true)
    {
        ui->tableView_paraset_alert_release_value->setEditTriggers(QAbstractItemView::CurrentChanged|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
    }
    else
    {
        ui->tableView_paraset_alert_release_value->setEditTriggers(QAbstractItemView::NoEditTriggers);
    }

    QStringList columnNames;
    QList<int> columnWidths;
    columnNames << "check" << "name" << "value" << "introduce";
    columnWidths << 60 << 420 << 120 << 120;

    model = new QStandardItemModel;
    model->setHorizontalHeaderLabels(columnNames);
    ui->tableView_paraset_alert_release_value->setModel(model);
    int count = columnNames.count();
    for(int i = 0; i< count;i++)
    {
        ui->tableView_paraset_alert_release_value->setColumnWidth(i, columnWidths.at(i));
    }


    Delegate *checkDelegate = new Delegate;
    checkDelegate->setDelegateType("QCheckBox");
    checkDelegate->setDelegateColumn(0);
    ui->tableView_paraset_alert_release_value->setItemDelegateForColumn(0, checkDelegate);

    Delegate *labelDelegate = new Delegate;
    labelDelegate->setDelegateType("QLabel");
    ui->tableView_paraset_alert_release_value->setItemDelegateForColumn(1,labelDelegate);
    Delegate * lineEidtDelegate1 = new Delegate;
    lineEidtDelegate1->setDelegateType("QLineEdit");
    ui->tableView_paraset_alert_release_value->setItemDelegateForColumn(2, lineEidtDelegate1);

    Delegate *labelDelegate1 = new Delegate;
    labelDelegate1->setDelegateType("QLabel");
    ui->tableView_paraset_alert_release_value->setItemDelegateForColumn(3,labelDelegate1);

    if(lan == 0) {
        BatteryConfig_English::Item item;
        std::ifstream finBetteryData("battery_english.data", std::ios::binary);
        if(!item.ParseFromIstream(&finBetteryData)) {
            qDebug() << __FUNCTION__ << __LINE__ << "proto parse failed";
            finBetteryData.close();
            finBetteryData.clear();
        }
        else {
            for(int i = 0; i < item.itemattr_alert_release_value_size(); i++) {
                for(int j = 0; j < 4; j++) {
                    if(j == 1) {
                        model->setItem(i, j, new QStandardItem(item.mutable_itemattr_alert_release_value(i)->name().c_str()));
                    }
                    else if(j == 2) {
                        model->setItem(i, j, new QStandardItem(QString::number(item.mutable_itemattr_alert_release_value(i)->value())));
                    }
                    else if(j == 3) {
                        model->setItem(i, j, new QStandardItem(item.mutable_itemattr_alert_release_value(i)->introduce().c_str()));
                    }
                }
            }

            finBetteryData.close();
            finBetteryData.clear();
        }
    }
    else if(lan == 1) {
        BatteryConfig::Item item;
        std::ifstream finBetteryData("battery.data", std::ios::binary);
        if(!item.ParseFromIstream(&finBetteryData)) {
            qDebug() << __FUNCTION__ << __LINE__ << "proto parse failed";
            finBetteryData.close();
            finBetteryData.clear();
        }
        else {
            for(int i = 0; i < item.itemattr_alert_release_value_size(); i++) {
                for(int j = 0; j < 4; j++) {
                    if(j == 1) {
                        model->setItem(i, j, new QStandardItem(item.mutable_itemattr_alert_release_value(i)->name().c_str()));
                    }
                    else if(j == 2) {
                        model->setItem(i, j, new QStandardItem(QString::number(item.mutable_itemattr_alert_release_value(i)->value())));
                    }
                    else if(j == 3) {
                        model->setItem(i, j, new QStandardItem(item.mutable_itemattr_alert_release_value(i)->introduce().c_str()));
                    }
                }
            }

            finBetteryData.close();
            finBetteryData.clear();
        }
    }

}

void MainWindow::pageParaSetInit_alert_release_delay()
{
    // ui->tabWidget_paraset->setStyleSheet("background-color: #FFFFFF;");
    // ui->pageParaSet->setStyleSheet("background-color: #FFFFFF;");
    /*设置默认行高*/
    ui->tableView_paraset_alert_release_delay->verticalHeader()->setDefaultSectionSize(26);
    /*设置交替行颜色--允许交替行颜色*/
    ui->tableView_paraset_alert_release_delay->setAlternatingRowColors(true);
    /*设置水平/垂直滚动模式--一次滚动一个项目*/
    ui->tableView_paraset_alert_release_delay->setHorizontalScrollMode(QAbstractItemView::ScrollPerItem);
    ui->tableView_paraset_alert_release_delay->setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
    /*设置选择行为--每次选择只有一整行*/
    ui->tableView_paraset_alert_release_delay->setSelectionBehavior(QAbstractItemView::SelectRows);
    /*设置拖放行为--不允许拖放*/
    ui->tableView_paraset_alert_release_delay->setDragDropMode(QAbstractItemView::NoDragDrop);
    /*设置选择模式--只能选择一个项目*/
    ui->tableView_paraset_alert_release_delay->setSelectionMode(QAbstractItemView::SingleSelection);
    /*设置Tab导航键--允许使用Tab键导航，shift+tab反向导航*/
    ui->tableView_paraset_alert_release_delay->setTabKeyNavigation(true);
    /*设置是否自动换行--取消自动换行*/
    ui->tableView_paraset_alert_release_delay->setWordWrap(false);
    /*设置文本省略模式--省略号不会出现在文本中*/
    ui->tableView_paraset_alert_release_delay->setTextElideMode(Qt::ElideNone);
    /*设置左上角全选按钮--禁用*/
    ui->tableView_paraset_alert_release_delay->setCornerButtonEnabled(false);
    /*设置是否支持表头排序--应该和表头是否可以单击保持一致*/
    ui->tableView_paraset_alert_release_delay->setSortingEnabled(false);
    /*设置是否显示网格线*/
    ui->tableView_paraset_alert_release_delay->setShowGrid(true);
    /*设置垂直表头是否可见*/
    ui->tableView_paraset_alert_release_delay->verticalHeader()->setVisible(true);
    /*设置选中一行表头是否加粗--不加粗*/
    ui->tableView_paraset_alert_release_delay->horizontalHeader()->setHighlightSections(true);
    /*设置最后一行是否拉伸填充*/
    ui->tableView_paraset_alert_release_delay->horizontalHeader()->setStretchLastSection(true);
    /*设置行标题最小宽度尺寸*/
    ui->tableView_paraset_alert_release_delay->horizontalHeader()->setMinimumSectionSize(0);
    /*设置行标题最小高度*/
    ui->tableView_paraset_alert_release_delay->horizontalHeader()->setFixedHeight(35);
    /*设置表头是否可以单击--不可单击*/
    ui->tableView_paraset_alert_release_delay->horizontalHeader()->setSectionsClickable(false);
    ui->tableView_paraset_alert_release_delay->verticalHeader()->setHidden(false);
    /*是否可编辑*/
    if(true)
    {
        ui->tableView_paraset_alert_release_delay->setEditTriggers(QAbstractItemView::CurrentChanged|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
    }
    else
    {
        ui->tableView_paraset_alert_release_delay->setEditTriggers(QAbstractItemView::NoEditTriggers);
    }

    QStringList columnNames;
    QList<int> columnWidths;
    columnNames << "check" << "name" << "value" << "introduce";
    columnWidths << 60 << 420 << 120 << 120;

    model = new QStandardItemModel;
    model->setHorizontalHeaderLabels(columnNames);
    ui->tableView_paraset_alert_release_delay->setModel(model);
    int count = columnNames.count();
    for(int i = 0; i< count;i++)
    {
        ui->tableView_paraset_alert_release_delay->setColumnWidth(i, columnWidths.at(i));
    }


    Delegate *checkDelegate = new Delegate;
    checkDelegate->setDelegateType("QCheckBox");
    checkDelegate->setDelegateColumn(0);
    ui->tableView_paraset_alert_release_delay->setItemDelegateForColumn(0, checkDelegate);

    Delegate *labelDelegate = new Delegate;
    labelDelegate->setDelegateType("QLabel");
    ui->tableView_paraset_alert_release_delay->setItemDelegateForColumn(1,labelDelegate);
    Delegate * lineEidtDelegate1 = new Delegate;
    lineEidtDelegate1->setDelegateType("QLineEdit");
    ui->tableView_paraset_alert_release_delay->setItemDelegateForColumn(2, lineEidtDelegate1);

    Delegate *labelDelegate1 = new Delegate;
    labelDelegate1->setDelegateType("QLabel");
    ui->tableView_paraset_alert_release_delay->setItemDelegateForColumn(3,labelDelegate1);

    if(lan == 0)
    {
        BatteryConfig_English::Item item;
        std::ifstream finBetteryData("battery_english.data", std::ios::binary);
        if(!item.ParseFromIstream(&finBetteryData)) {
            qDebug() << __FUNCTION__ << __LINE__ << "proto parse failed";
            finBetteryData.close();
            finBetteryData.clear();
        }
        else {
            for(int i = 0; i < item.itemattr_alert_release_delay_size(); i++) {
                for(int j = 0; j < 4; j++) {
                    if(j == 1) {
                        model->setItem(i, j, new QStandardItem(item.mutable_itemattr_alert_release_delay(i)->name().c_str()));
                    }
                    else if(j == 2) {
                        model->setItem(i, j, new QStandardItem(QString::number(item.mutable_itemattr_alert_release_delay(i)->value())));
                    }
                    else if(j == 3) {
                        model->setItem(i, j, new QStandardItem(item.mutable_itemattr_alert_release_delay(i)->introduce().c_str()));
                    }
                }
            }
            finBetteryData.close();
            finBetteryData.clear();
        }
    }
    else if(lan == 1)
    {
        BatteryConfig::Item item;
        std::ifstream finBetteryData("battery.data", std::ios::binary);
        if(!item.ParseFromIstream(&finBetteryData)) {
            qDebug() << __FUNCTION__ << __LINE__ << "proto parse failed";
            finBetteryData.close();
            finBetteryData.clear();
        }
        else {
            for(int i = 0; i < item.itemattr_alert_release_delay_size(); i++) {
                for(int j = 0; j < 4; j++) {
                    if(j == 1) {
                        model->setItem(i, j, new QStandardItem(item.mutable_itemattr_alert_release_delay(i)->name().c_str()));
                    }
                    else if(j == 2) {
                        model->setItem(i, j, new QStandardItem(QString::number(item.mutable_itemattr_alert_release_delay(i)->value())));
                    }
                    else if(j == 3) {
                        model->setItem(i, j, new QStandardItem(item.mutable_itemattr_alert_release_delay(i)->introduce().c_str()));
                    }
                }
            }
            finBetteryData.close();
            finBetteryData.clear();
        }
    }
}

void MainWindow::pageParaSetInit_alert_dropcurr_rate()
{
    // ui->tabWidget_paraset->setStyleSheet("background-color: #FFFFFF;");
    // ui->pageParaSet->setStyleSheet("background-color: #FFFFFF;");
    /*设置默认行高*/
    ui->tableView_paraset_alert_dropcurr_rate->verticalHeader()->setDefaultSectionSize(26);
    /*设置交替行颜色--允许交替行颜色*/
    ui->tableView_paraset_alert_dropcurr_rate->setAlternatingRowColors(true);
    /*设置水平/垂直滚动模式--一次滚动一个项目*/
    ui->tableView_paraset_alert_dropcurr_rate->setHorizontalScrollMode(QAbstractItemView::ScrollPerItem);
    ui->tableView_paraset_alert_dropcurr_rate->setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
    /*设置选择行为--每次选择只有一整行*/
    ui->tableView_paraset_alert_dropcurr_rate->setSelectionBehavior(QAbstractItemView::SelectRows);
    /*设置拖放行为--不允许拖放*/
    ui->tableView_paraset_alert_dropcurr_rate->setDragDropMode(QAbstractItemView::NoDragDrop);
    /*设置选择模式--只能选择一个项目*/
    ui->tableView_paraset_alert_dropcurr_rate->setSelectionMode(QAbstractItemView::SingleSelection);
    /*设置Tab导航键--允许使用Tab键导航，shift+tab反向导航*/
    ui->tableView_paraset_alert_dropcurr_rate->setTabKeyNavigation(true);
    /*设置是否自动换行--取消自动换行*/
    ui->tableView_paraset_alert_dropcurr_rate->setWordWrap(false);
    /*设置文本省略模式--省略号不会出现在文本中*/
    ui->tableView_paraset_alert_dropcurr_rate->setTextElideMode(Qt::ElideNone);
    /*设置左上角全选按钮--禁用*/
    ui->tableView_paraset_alert_dropcurr_rate->setCornerButtonEnabled(false);
    /*设置是否支持表头排序--应该和表头是否可以单击保持一致*/
    ui->tableView_paraset_alert_dropcurr_rate->setSortingEnabled(false);
    /*设置是否显示网格线*/
    ui->tableView_paraset_alert_dropcurr_rate->setShowGrid(true);
    /*设置垂直表头是否可见*/
    ui->tableView_paraset_alert_dropcurr_rate->verticalHeader()->setVisible(true);
    /*设置选中一行表头是否加粗--不加粗*/
    ui->tableView_paraset_alert_dropcurr_rate->horizontalHeader()->setHighlightSections(true);
    /*设置最后一行是否拉伸填充*/
    ui->tableView_paraset_alert_dropcurr_rate->horizontalHeader()->setStretchLastSection(true);
    /*设置行标题最小宽度尺寸*/
    ui->tableView_paraset_alert_dropcurr_rate->horizontalHeader()->setMinimumSectionSize(0);
    /*设置行标题最小高度*/
    ui->tableView_paraset_alert_dropcurr_rate->horizontalHeader()->setFixedHeight(35);
    /*设置表头是否可以单击--不可单击*/
    ui->tableView_paraset_alert_dropcurr_rate->horizontalHeader()->setSectionsClickable(false);
    ui->tableView_paraset_alert_dropcurr_rate->verticalHeader()->setHidden(false);
    /*是否可编辑*/
    if(true)
    {
        ui->tableView_paraset_alert_dropcurr_rate->setEditTriggers(QAbstractItemView::CurrentChanged|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
    }
    else
    {
        ui->tableView_paraset_alert_dropcurr_rate->setEditTriggers(QAbstractItemView::NoEditTriggers);
    }

    QStringList columnNames;
    QList<int> columnWidths;
    columnNames << "check" << "name" << "value" << "introduce";
    columnWidths << 60 << 420 << 120 << 120;

    model = new QStandardItemModel;
    model->setHorizontalHeaderLabels(columnNames);
    ui->tableView_paraset_alert_dropcurr_rate->setModel(model);
    int count = columnNames.count();
    for(int i = 0; i< count;i++)
    {
        ui->tableView_paraset_alert_dropcurr_rate->setColumnWidth(i, columnWidths.at(i));
    }


    Delegate *checkDelegate = new Delegate;
    checkDelegate->setDelegateType("QCheckBox");
    checkDelegate->setDelegateColumn(0);
    ui->tableView_paraset_alert_dropcurr_rate->setItemDelegateForColumn(0, checkDelegate);

    Delegate *labelDelegate = new Delegate;
    labelDelegate->setDelegateType("QLabel");
    ui->tableView_paraset_alert_dropcurr_rate->setItemDelegateForColumn(1,labelDelegate);
    Delegate * lineEidtDelegate1 = new Delegate;
    lineEidtDelegate1->setDelegateType("QLineEdit");
    ui->tableView_paraset_alert_dropcurr_rate->setItemDelegateForColumn(2, lineEidtDelegate1);

    Delegate *labelDelegate1 = new Delegate;
    labelDelegate1->setDelegateType("QLabel");
    ui->tableView_paraset_alert_dropcurr_rate->setItemDelegateForColumn(3,labelDelegate1);

    if(lan == 0) {
        BatteryConfig_English::Item item;
        std::ifstream finBetteryData("battery_english.data", std::ios::binary);
        if(!item.ParseFromIstream(&finBetteryData)) {
            qDebug() << __FUNCTION__ << __LINE__ << "proto parse failed";
            finBetteryData.close();
            finBetteryData.clear();
        }
        else {
            for(int i = 0; i < item.itemattr_alert_dropcurr_rate_size(); i++) {
                for(int j = 0; j < 4; j++) {
                    if(j == 1) {
                        model->setItem(i, j, new QStandardItem(item.mutable_itemattr_alert_dropcurr_rate(i)->name().c_str()));
                    }
                    else if(j == 2) {
                        model->setItem(i, j, new QStandardItem(QString::number(item.mutable_itemattr_alert_dropcurr_rate(i)->value())));
                    }
                    else if(j == 3) {
                        model->setItem(i, j, new QStandardItem(item.mutable_itemattr_alert_dropcurr_rate(i)->introduce().c_str()));
                    }
                }
            }

            finBetteryData.close();
            finBetteryData.clear();
        }
    }
    else if(lan == 1)
    {
        BatteryConfig::Item item;
        std::ifstream finBetteryData("battery.data", std::ios::binary);
        if(!item.ParseFromIstream(&finBetteryData)) {
            qDebug() << __FUNCTION__ << __LINE__ << "proto parse failed";
            finBetteryData.close();
            finBetteryData.clear();
        }
        else {
            for(int i = 0; i < item.itemattr_alert_dropcurr_rate_size(); i++) {
                for(int j = 0; j < 4; j++) {
                    if(j == 1) {
                        model->setItem(i, j, new QStandardItem(item.mutable_itemattr_alert_dropcurr_rate(i)->name().c_str()));
                    }
                    else if(j == 2) {
                        model->setItem(i, j, new QStandardItem(QString::number(item.mutable_itemattr_alert_dropcurr_rate(i)->value())));
                    }
                    else if(j == 3) {
                        model->setItem(i, j, new QStandardItem(item.mutable_itemattr_alert_dropcurr_rate(i)->introduce().c_str()));
                    }
                }
            }

            finBetteryData.close();
            finBetteryData.clear();
        }
    }
}

void MainWindow::pageParaSetInit_alert_solve_measure()
{
    // ui->tabWidget_paraset->setStyleSheet("background-color: #FFFFFF;");
    // ui->pageParaSet->setStyleSheet("background-color: #FFFFFF;");
    /*设置默认行高*/
    ui->tableView_paraset_alert_solve_mease->verticalHeader()->setDefaultSectionSize(26);
    /*设置交替行颜色--允许交替行颜色*/
    ui->tableView_paraset_alert_solve_mease->setAlternatingRowColors(true);
    /*设置水平/垂直滚动模式--一次滚动一个项目*/
    ui->tableView_paraset_alert_solve_mease->setHorizontalScrollMode(QAbstractItemView::ScrollPerItem);
    ui->tableView_paraset_alert_solve_mease->setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
    /*设置选择行为--每次选择只有一整行*/
    ui->tableView_paraset_alert_solve_mease->setSelectionBehavior(QAbstractItemView::SelectRows);
    /*设置拖放行为--不允许拖放*/
    ui->tableView_paraset_alert_solve_mease->setDragDropMode(QAbstractItemView::NoDragDrop);
    /*设置选择模式--只能选择一个项目*/
    ui->tableView_paraset_alert_solve_mease->setSelectionMode(QAbstractItemView::SingleSelection);
    /*设置Tab导航键--允许使用Tab键导航，shift+tab反向导航*/
    ui->tableView_paraset_alert_solve_mease->setTabKeyNavigation(true);
    /*设置是否自动换行--取消自动换行*/
    ui->tableView_paraset_alert_solve_mease->setWordWrap(false);
    /*设置文本省略模式--省略号不会出现在文本中*/
    ui->tableView_paraset_alert_solve_mease->setTextElideMode(Qt::ElideNone);
    /*设置左上角全选按钮--禁用*/
    ui->tableView_paraset_alert_solve_mease->setCornerButtonEnabled(false);
    /*设置是否支持表头排序--应该和表头是否可以单击保持一致*/
    ui->tableView_paraset_alert_solve_mease->setSortingEnabled(false);
    /*设置是否显示网格线*/
    ui->tableView_paraset_alert_solve_mease->setShowGrid(true);
    /*设置垂直表头是否可见*/
    ui->tableView_paraset_alert_solve_mease->verticalHeader()->setVisible(true);
    /*设置选中一行表头是否加粗--不加粗*/
    ui->tableView_paraset_alert_solve_mease->horizontalHeader()->setHighlightSections(true);
    /*设置最后一行是否拉伸填充*/
    ui->tableView_paraset_alert_solve_mease->horizontalHeader()->setStretchLastSection(true);
    /*设置行标题最小宽度尺寸*/
    ui->tableView_paraset_alert_solve_mease->horizontalHeader()->setMinimumSectionSize(0);
    /*设置行标题最小高度*/
    ui->tableView_paraset_alert_solve_mease->horizontalHeader()->setFixedHeight(35);
    /*设置表头是否可以单击--不可单击*/
    ui->tableView_paraset_alert_solve_mease->horizontalHeader()->setSectionsClickable(false);
    ui->tableView_paraset_alert_solve_mease->verticalHeader()->setHidden(false);
    /*是否可编辑*/
    if(true)
    {
        ui->tableView_paraset_alert_solve_mease->setEditTriggers(QAbstractItemView::CurrentChanged|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
    }
    else
    {
        ui->tableView_paraset_alert_solve_mease->setEditTriggers(QAbstractItemView::NoEditTriggers);
    }

    QStringList columnNames;
    QList<int> columnWidths;
    columnNames << "check" << "name" << "value" << "introduce";
    columnWidths << 60 << 420 << 120 << 120;

    model = new QStandardItemModel;
    model->setHorizontalHeaderLabels(columnNames);
    ui->tableView_paraset_alert_solve_mease->setModel(model);
    int count = columnNames.count();
    for(int i = 0; i< count;i++)
    {
        ui->tableView_paraset_alert_solve_mease->setColumnWidth(i, columnWidths.at(i));
    }


    Delegate *checkDelegate = new Delegate;
    checkDelegate->setDelegateType("QCheckBox");
    checkDelegate->setDelegateColumn(0);
    ui->tableView_paraset_alert_solve_mease->setItemDelegateForColumn(0, checkDelegate);

    Delegate *labelDelegate = new Delegate;
    labelDelegate->setDelegateType("QLabel");
    ui->tableView_paraset_alert_solve_mease->setItemDelegateForColumn(1,labelDelegate);
    Delegate * lineEidtDelegate1 = new Delegate;
    lineEidtDelegate1->setDelegateType("QLineEdit");
    ui->tableView_paraset_alert_solve_mease->setItemDelegateForColumn(2, lineEidtDelegate1);

    Delegate *labelDelegate1 = new Delegate;
    labelDelegate1->setDelegateType("QLabel");
    ui->tableView_paraset_alert_solve_mease->setItemDelegateForColumn(3,labelDelegate1);

    if(lan == 0) {
        BatteryConfig_English::Item item;
        std::ifstream finBetteryData("battery_english.data", std::ios::binary);
        if(!item.ParseFromIstream(&finBetteryData)) {
            qDebug() << __FUNCTION__ << __LINE__ << "proto parse failed";
            finBetteryData.close();
            finBetteryData.clear();
        }
        else {
            for(int i = 0; i < item.itemattr_alert_solve_measure_size(); i++) {
                for(int j = 0; j < 4; j++) {
                    if(j == 1) {
                        model->setItem(i, j, new QStandardItem(item.mutable_itemattr_alert_solve_measure(i)->name().c_str()));
                    }
                    else if(j == 2) {
                        model->setItem(i, j, new QStandardItem(QString::number(item.mutable_itemattr_alert_solve_measure(i)->value())));
                    }
                    else if(j == 3) {
                        model->setItem(i, j, new QStandardItem(item.mutable_itemattr_alert_solve_measure(i)->introduce().c_str()));
                    }
                }
            }

            finBetteryData.close();
            finBetteryData.clear();
        }
    }
    else if(lan == 1)
    {
        BatteryConfig::Item item;
        std::ifstream finBetteryData("battery.data", std::ios::binary);
        if(!item.ParseFromIstream(&finBetteryData)) {
            qDebug() << __FUNCTION__ << __LINE__ << "proto parse failed";
            finBetteryData.close();
            finBetteryData.clear();
        }
        else {
            for(int i = 0; i < item.itemattr_alert_solve_measure_size(); i++) {
                for(int j = 0; j < 4; j++) {
                    if(j == 1) {
                        model->setItem(i, j, new QStandardItem(item.mutable_itemattr_alert_solve_measure(i)->name().c_str()));
                    }
                    else if(j == 2) {
                        model->setItem(i, j, new QStandardItem(QString::number(item.mutable_itemattr_alert_solve_measure(i)->value())));
                    }
                    else if(j == 3) {
                        model->setItem(i, j, new QStandardItem(item.mutable_itemattr_alert_solve_measure(i)->introduce().c_str()));
                    }
                }
            }

            finBetteryData.close();
            finBetteryData.clear();
        }
    }
}

void MainWindow::pageParaSetInit_DIDO_setting()
{
    // ui->tabWidget_paraset->setStyleSheet("background-color: #FFFFFF;");
    // ui->pageParaSet->setStyleSheet("background-color: #FFFFFF;");
    /*设置默认行高*/
    ui->tableView_DIDO_setting->verticalHeader()->setDefaultSectionSize(26);
    /*设置交替行颜色--允许交替行颜色*/
    ui->tableView_DIDO_setting->setAlternatingRowColors(true);
    /*设置水平/垂直滚动模式--一次滚动一个项目*/
    ui->tableView_DIDO_setting->setHorizontalScrollMode(QAbstractItemView::ScrollPerItem);
    ui->tableView_DIDO_setting->setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
    /*设置选择行为--每次选择只有一整行*/
    ui->tableView_DIDO_setting->setSelectionBehavior(QAbstractItemView::SelectRows);
    /*设置拖放行为--不允许拖放*/
    ui->tableView_DIDO_setting->setDragDropMode(QAbstractItemView::NoDragDrop);
    /*设置选择模式--只能选择一个项目*/
    ui->tableView_DIDO_setting->setSelectionMode(QAbstractItemView::SingleSelection);
    /*设置Tab导航键--允许使用Tab键导航，shift+tab反向导航*/
    ui->tableView_DIDO_setting->setTabKeyNavigation(true);
    /*设置是否自动换行--取消自动换行*/
    ui->tableView_DIDO_setting->setWordWrap(false);
    /*设置文本省略模式--省略号不会出现在文本中*/
    ui->tableView_DIDO_setting->setTextElideMode(Qt::ElideNone);
    /*设置左上角全选按钮--禁用*/
    ui->tableView_DIDO_setting->setCornerButtonEnabled(false);
    /*设置是否支持表头排序--应该和表头是否可以单击保持一致*/
    ui->tableView_DIDO_setting->setSortingEnabled(false);
    /*设置是否显示网格线*/
    ui->tableView_DIDO_setting->setShowGrid(true);
    /*设置垂直表头是否可见*/
    ui->tableView_DIDO_setting->verticalHeader()->setVisible(true);
    /*设置选中一行表头是否加粗--不加粗*/
    ui->tableView_DIDO_setting->horizontalHeader()->setHighlightSections(true);
    /*设置最后一行是否拉伸填充*/
    ui->tableView_DIDO_setting->horizontalHeader()->setStretchLastSection(true);
    /*设置行标题最小宽度尺寸*/
    ui->tableView_DIDO_setting->horizontalHeader()->setMinimumSectionSize(0);
    /*设置行标题最小高度*/
    ui->tableView_DIDO_setting->horizontalHeader()->setFixedHeight(35);
    /*设置表头是否可以单击--不可单击*/
    ui->tableView_DIDO_setting->horizontalHeader()->setSectionsClickable(false);
    ui->tableView_DIDO_setting->verticalHeader()->setHidden(false);
    /*是否可编辑*/
    if(true)
    {
        ui->tableView_DIDO_setting->setEditTriggers(QAbstractItemView::CurrentChanged|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
    }
    else
    {
        ui->tableView_DIDO_setting->setEditTriggers(QAbstractItemView::NoEditTriggers);
    }

    QStringList columnNames;
    QList<int> columnWidths;
    columnNames << "check" << "name" << "value" << "introduce";
    columnWidths << 60 << 420 << 120 << 120;

    model = new QStandardItemModel;
    model->setHorizontalHeaderLabels(columnNames);
    ui->tableView_DIDO_setting->setModel(model);
    int count = columnNames.count();
    for(int i = 0; i< count;i++)
    {
        ui->tableView_DIDO_setting->setColumnWidth(i, columnWidths.at(i));
    }


    Delegate *checkDelegate = new Delegate;
    checkDelegate->setDelegateType("QCheckBox");
    checkDelegate->setDelegateColumn(0);
    ui->tableView_DIDO_setting->setItemDelegateForColumn(0, checkDelegate);

    Delegate *labelDelegate = new Delegate;
    labelDelegate->setDelegateType("QLabel");
    ui->tableView_DIDO_setting->setItemDelegateForColumn(1,labelDelegate);
    Delegate * lineEidtDelegate1 = new Delegate;
    lineEidtDelegate1->setDelegateType("QLineEdit");
    ui->tableView_DIDO_setting->setItemDelegateForColumn(2, lineEidtDelegate1);

    Delegate *labelDelegate1 = new Delegate;
    labelDelegate1->setDelegateType("QLabel");
    ui->tableView_DIDO_setting->setItemDelegateForColumn(3,labelDelegate1);

    if(lan == 0)
    {
        BatteryConfig_English::Item item;
        std::ifstream finBetteryData("battery_english.data", std::ios::binary);
        if(!item.ParseFromIstream(&finBetteryData)) {
            qDebug() << __FUNCTION__ << __LINE__ << "proto parse failed";
            finBetteryData.close();
            finBetteryData.clear();
        }
        else {
            for(int i=0; i < item.itemattr_dido_size(); i++)
            {
                for(int j = 0; j < 4; j++) {
                    if(j == 1) {
                        model->setItem(i, j, new QStandardItem(item.itemattr_dido(i).name().c_str()));
                    }
                    else if(j == 2) {
                        model->setItem(i, j, new QStandardItem(QString::number(item.itemattr_dido(i).value())));
                    }
                    else if(j == 3) {
                        model->setItem(i, j, new QStandardItem(item.itemattr_dido(i).introduce().c_str()));
                    }
                }
            }
            finBetteryData.close();
            finBetteryData.clear();
        }
    }
    else if(lan == 1)
    {
        BatteryConfig::Item item;
        std::ifstream finBetteryData("battery.data", std::ios::binary);
        if(!item.ParseFromIstream(&finBetteryData)) {
            qDebug() << __FUNCTION__ << __LINE__ << "proto parse failed";
            finBetteryData.close();
            finBetteryData.clear();
        }
        else {
            for(int i=0; i < item.itemattr_dido_size(); i++)
            {
                for(int j = 0; j < 4; j++) {
                    if(j == 1) {
                        model->setItem(i, j, new QStandardItem(item.itemattr_dido(i).name().c_str()));
                    }
                    else if(j == 2) {
                        model->setItem(i, j, new QStandardItem(QString::number(item.itemattr_dido(i).value())));
                    }
                    else if(j == 3) {
                        model->setItem(i, j, new QStandardItem(item.itemattr_dido(i).introduce().c_str()));
                    }
                }
            }
            finBetteryData.close();
            finBetteryData.clear();
        }
    }
}

void MainWindow::pageParaSetInit_balance_setting()
{
    // ui->tabWidget_paraset->setStyleSheet("background-color: #FFFFFF;");
    // ui->pageParaSet->setStyleSheet("background-color: #FFFFFF;");
    /*设置默认行高*/
    ui->tableView_balance_setting->verticalHeader()->setDefaultSectionSize(26);
    /*设置交替行颜色--允许交替行颜色*/
    ui->tableView_balance_setting->setAlternatingRowColors(true);
    /*设置水平/垂直滚动模式--一次滚动一个项目*/
    ui->tableView_balance_setting->setHorizontalScrollMode(QAbstractItemView::ScrollPerItem);
    ui->tableView_balance_setting->setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
    /*设置选择行为--每次选择只有一整行*/
    ui->tableView_balance_setting->setSelectionBehavior(QAbstractItemView::SelectRows);
    /*设置拖放行为--不允许拖放*/
    ui->tableView_balance_setting->setDragDropMode(QAbstractItemView::NoDragDrop);
    /*设置选择模式--只能选择一个项目*/
    ui->tableView_balance_setting->setSelectionMode(QAbstractItemView::SingleSelection);
    /*设置Tab导航键--允许使用Tab键导航，shift+tab反向导航*/
    ui->tableView_balance_setting->setTabKeyNavigation(true);
    /*设置是否自动换行--取消自动换行*/
    ui->tableView_balance_setting->setWordWrap(false);
    /*设置文本省略模式--省略号不会出现在文本中*/
    ui->tableView_balance_setting->setTextElideMode(Qt::ElideNone);
    /*设置左上角全选按钮--禁用*/
    ui->tableView_balance_setting->setCornerButtonEnabled(false);
    /*设置是否支持表头排序--应该和表头是否可以单击保持一致*/
    ui->tableView_balance_setting->setSortingEnabled(false);
    /*设置是否显示网格线*/
    ui->tableView_balance_setting->setShowGrid(true);
    /*设置垂直表头是否可见*/
    ui->tableView_balance_setting->verticalHeader()->setVisible(true);
    /*设置选中一行表头是否加粗--不加粗*/
    ui->tableView_balance_setting->horizontalHeader()->setHighlightSections(true);
    /*设置最后一行是否拉伸填充*/
    ui->tableView_balance_setting->horizontalHeader()->setStretchLastSection(true);
    /*设置行标题最小宽度尺寸*/
    ui->tableView_balance_setting->horizontalHeader()->setMinimumSectionSize(0);
    /*设置行标题最小高度*/
    ui->tableView_balance_setting->horizontalHeader()->setFixedHeight(35);
    /*设置表头是否可以单击--不可单击*/
    ui->tableView_balance_setting->horizontalHeader()->setSectionsClickable(false);
    ui->tableView_balance_setting->verticalHeader()->setHidden(false);
    /*是否可编辑*/
    if(true)
    {
        ui->tableView_balance_setting->setEditTriggers(QAbstractItemView::CurrentChanged|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
    }
    else
    {
        ui->tableView_balance_setting->setEditTriggers(QAbstractItemView::NoEditTriggers);
    }

    QStringList columnNames;
    QList<int> columnWidths;
    columnNames << "check" << "name" << "value" << "introduce";
    columnWidths << 60 << 420 << 120 << 120;

    model = new QStandardItemModel;
    model->setHorizontalHeaderLabels(columnNames);
    ui->tableView_balance_setting->setModel(model);
    int count = columnNames.count();
    for(int i = 0; i< count;i++)
    {
        ui->tableView_balance_setting->setColumnWidth(i, columnWidths.at(i));
    }


    Delegate *checkDelegate = new Delegate;
    checkDelegate->setDelegateType("QCheckBox");
    checkDelegate->setDelegateColumn(0);
    ui->tableView_balance_setting->setItemDelegateForColumn(0, checkDelegate);

    Delegate *labelDelegate = new Delegate;
    labelDelegate->setDelegateType("QLabel");
    ui->tableView_balance_setting->setItemDelegateForColumn(1,labelDelegate);
    Delegate * lineEidtDelegate1 = new Delegate;
    lineEidtDelegate1->setDelegateType("QLineEdit");
    ui->tableView_balance_setting->setItemDelegateForColumn(2, lineEidtDelegate1);

    Delegate *labelDelegate1 = new Delegate;
    labelDelegate1->setDelegateType("QLabel");
    ui->tableView_balance_setting->setItemDelegateForColumn(3,labelDelegate1);

    if(lan == 0)
    {
        BatteryConfig_English::Item item;
        std::ifstream finBetteryData("battery_english.data", std::ios::binary);
        if(!item.ParseFromIstream(&finBetteryData)) {
            qDebug() << __FUNCTION__ << __LINE__ << "proto parse failed";
            finBetteryData.close();
            finBetteryData.clear();
        }
        else {
            for(int i = 0; i< item.itemattr_balance_size(); i++)
            {
                for(int j = 0; j < 4; j++) {
                    if(j == 1) {
                        model->setItem(i, j, new QStandardItem(item.itemattr_balance(i).name().c_str()));
                    }
                    else if(j == 2) {
                        model->setItem(i, j, new QStandardItem(QString::number(item.itemattr_balance(i).value())));
                    }
                    else if(j == 3) {
                        model->setItem(i, j, new QStandardItem(item.itemattr_balance(i).introduce().c_str()));
                    }
                }
            }
            finBetteryData.close();
            finBetteryData.clear();
        }
    }
    else if(lan == 1)
    {
        BatteryConfig::Item item;
        std::ifstream finBetteryData("battery.data", std::ios::binary);
        if(!item.ParseFromIstream(&finBetteryData)) {
            qDebug() << __FUNCTION__ << __LINE__ << "proto parse failed";
            finBetteryData.close();
            finBetteryData.clear();
        }
        else {
            for(int i = 0; i< item.itemattr_balance_size(); i++)
            {
                for(int j = 0; j < 4; j++) {
                    if(j == 1) {
                        model->setItem(i, j, new QStandardItem(item.itemattr_balance(i).name().c_str()));
                    }
                    else if(j == 2) {
                        model->setItem(i, j, new QStandardItem(QString::number(item.itemattr_balance(i).value())));
                    }
                    else if(j == 3) {
                        model->setItem(i, j, new QStandardItem(item.itemattr_balance(i).introduce().c_str()));
                    }
                }
            }
            finBetteryData.close();
            finBetteryData.clear();
        }
    }
}

void MainWindow::pageParaSetInit_SOX_setting()
{
    // ui->tabWidget_paraset->setStyleSheet("background-color: #FFFFFF;");
    // ui->pageParaSet->setStyleSheet("background-color: #FFFFFF;");
    /*设置默认行高*/
    ui->tableView_SOX_setting->verticalHeader()->setDefaultSectionSize(26);
    /*设置交替行颜色--允许交替行颜色*/
    ui->tableView_SOX_setting->setAlternatingRowColors(true);
    /*设置水平/垂直滚动模式--一次滚动一个项目*/
    ui->tableView_SOX_setting->setHorizontalScrollMode(QAbstractItemView::ScrollPerItem);
    ui->tableView_SOX_setting->setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
    /*设置选择行为--每次选择只有一整行*/
    ui->tableView_SOX_setting->setSelectionBehavior(QAbstractItemView::SelectRows);
    /*设置拖放行为--不允许拖放*/
    ui->tableView_SOX_setting->setDragDropMode(QAbstractItemView::NoDragDrop);
    /*设置选择模式--只能选择一个项目*/
    ui->tableView_SOX_setting->setSelectionMode(QAbstractItemView::SingleSelection);
    /*设置Tab导航键--允许使用Tab键导航，shift+tab反向导航*/
    ui->tableView_SOX_setting->setTabKeyNavigation(true);
    /*设置是否自动换行--取消自动换行*/
    ui->tableView_SOX_setting->setWordWrap(false);
    /*设置文本省略模式--省略号不会出现在文本中*/
    ui->tableView_SOX_setting->setTextElideMode(Qt::ElideNone);
    /*设置左上角全选按钮--禁用*/
    ui->tableView_SOX_setting->setCornerButtonEnabled(false);
    /*设置是否支持表头排序--应该和表头是否可以单击保持一致*/
    ui->tableView_SOX_setting->setSortingEnabled(false);
    /*设置是否显示网格线*/
    ui->tableView_SOX_setting->setShowGrid(true);
    /*设置垂直表头是否可见*/
    ui->tableView_SOX_setting->verticalHeader()->setVisible(true);
    /*设置选中一行表头是否加粗--不加粗*/
    ui->tableView_SOX_setting->horizontalHeader()->setHighlightSections(true);
    /*设置最后一行是否拉伸填充*/
    ui->tableView_SOX_setting->horizontalHeader()->setStretchLastSection(true);
    /*设置行标题最小宽度尺寸*/
    ui->tableView_SOX_setting->horizontalHeader()->setMinimumSectionSize(0);
    /*设置行标题最小高度*/
    ui->tableView_SOX_setting->horizontalHeader()->setFixedHeight(35);
    /*设置表头是否可以单击--不可单击*/
    ui->tableView_SOX_setting->horizontalHeader()->setSectionsClickable(false);
    ui->tableView_SOX_setting->verticalHeader()->setHidden(false);
    /*是否可编辑*/
    if(true)
    {
        ui->tableView_SOX_setting->setEditTriggers(QAbstractItemView::CurrentChanged|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
    }
    else
    {
        ui->tableView_SOX_setting->setEditTriggers(QAbstractItemView::NoEditTriggers);
    }

    QStringList columnNames;
    QList<int> columnWidths;
    columnNames << "check" << "name" << "value" << "introduce";
    columnWidths << 60 << 420 << 120 << 120;

    model = new QStandardItemModel;
    model->setHorizontalHeaderLabels(columnNames);
    ui->tableView_SOX_setting->setModel(model);
    int count = columnNames.count();
    for(int i = 0; i< count;i++)
    {
        ui->tableView_SOX_setting->setColumnWidth(i, columnWidths.at(i));
    }


    Delegate *checkDelegate = new Delegate;
    checkDelegate->setDelegateType("QCheckBox");
    checkDelegate->setDelegateColumn(0);
    ui->tableView_SOX_setting->setItemDelegateForColumn(0, checkDelegate);

    Delegate *labelDelegate = new Delegate;
    labelDelegate->setDelegateType("QLabel");
    ui->tableView_SOX_setting->setItemDelegateForColumn(1,labelDelegate);
    Delegate * lineEidtDelegate1 = new Delegate;
    lineEidtDelegate1->setDelegateType("QLineEdit");
    ui->tableView_SOX_setting->setItemDelegateForColumn(2, lineEidtDelegate1);

    Delegate *labelDelegate1 = new Delegate;
    labelDelegate1->setDelegateType("QLabel");
    ui->tableView_SOX_setting->setItemDelegateForColumn(3,labelDelegate1);

    if(lan == 0)
    {
        BatteryConfig_English::Item item;
        std::ifstream finBetteryData("battery_english.data", std::ios::binary);
        if(!item.ParseFromIstream(&finBetteryData)) {
            qDebug() << __FUNCTION__ << __LINE__ << "proto parse failed";
            finBetteryData.close();
            finBetteryData.clear();
        }
        else {
            for (int i=0; i < item.itemattr_sox_size(); i++)
            {
                for(int j = 0; j < 4; j++) {
                    if(j == 1) {
                        model->setItem(i, j, new QStandardItem(item.itemattr_sox(i).name().c_str()));
                    }
                    else if(j == 2) {
                        model->setItem(i, j, new QStandardItem(QString::number(item.itemattr_sox(i).value())));
                    }
                    else if(j == 3) {
                        model->setItem(i, j, new QStandardItem(item.itemattr_sox(i).introduce().c_str()));
                    }
                }
            }
            finBetteryData.close();
            finBetteryData.clear();
        }
    }
    else if(lan == 1)
    {
        BatteryConfig::Item item;
        std::ifstream finBetteryData("battery.data", std::ios::binary);
        if(!item.ParseFromIstream(&finBetteryData)) {
            qDebug() << __FUNCTION__ << __LINE__ << "proto parse failed";
            finBetteryData.close();
            finBetteryData.clear();
        }
        else {
            for (int i=0; i < item.itemattr_sox_size(); i++)
            {
                for(int j = 0; j < 4; j++) {
                    if(j == 1) {
                        model->setItem(i, j, new QStandardItem(item.itemattr_sox(i).name().c_str()));
                    }
                    else if(j == 2) {
                        model->setItem(i, j, new QStandardItem(QString::number(item.itemattr_sox(i).value())));
                    }
                    else if(j == 3) {
                        model->setItem(i, j, new QStandardItem(item.itemattr_sox(i).introduce().c_str()));
                    }
                }
            }
            finBetteryData.close();
            finBetteryData.clear();
        }
    }
}

void MainWindow::pageParaSetInit_other_setting()
{
    // ui->tabWidget_paraset->setStyleSheet("background-color: #FFFFFF;");
    // ui->pageParaSet->setStyleSheet("background-color: #FFFFFF;");
    /*设置默认行高*/
    ui->tableView_other_setting->verticalHeader()->setDefaultSectionSize(26);
    /*设置交替行颜色--允许交替行颜色*/
    ui->tableView_other_setting->setAlternatingRowColors(true);
    /*设置水平/垂直滚动模式--一次滚动一个项目*/
    ui->tableView_other_setting->setHorizontalScrollMode(QAbstractItemView::ScrollPerItem);
    ui->tableView_other_setting->setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
    /*设置选择行为--每次选择只有一整行*/
    ui->tableView_other_setting->setSelectionBehavior(QAbstractItemView::SelectRows);
    /*设置拖放行为--不允许拖放*/
    ui->tableView_other_setting->setDragDropMode(QAbstractItemView::NoDragDrop);
    /*设置选择模式--只能选择一个项目*/
    ui->tableView_other_setting->setSelectionMode(QAbstractItemView::SingleSelection);
    /*设置Tab导航键--允许使用Tab键导航，shift+tab反向导航*/
    ui->tableView_other_setting->setTabKeyNavigation(true);
    /*设置是否自动换行--取消自动换行*/
    ui->tableView_other_setting->setWordWrap(false);
    /*设置文本省略模式--省略号不会出现在文本中*/
    ui->tableView_other_setting->setTextElideMode(Qt::ElideNone);
    /*设置左上角全选按钮--禁用*/
    ui->tableView_other_setting->setCornerButtonEnabled(false);
    /*设置是否支持表头排序--应该和表头是否可以单击保持一致*/
    ui->tableView_other_setting->setSortingEnabled(false);
    /*设置是否显示网格线*/
    ui->tableView_other_setting->setShowGrid(true);
    /*设置垂直表头是否可见*/
    ui->tableView_other_setting->verticalHeader()->setVisible(true);
    /*设置选中一行表头是否加粗--不加粗*/
    ui->tableView_other_setting->horizontalHeader()->setHighlightSections(true);
    /*设置最后一行是否拉伸填充*/
    ui->tableView_other_setting->horizontalHeader()->setStretchLastSection(true);
    /*设置行标题最小宽度尺寸*/
    ui->tableView_other_setting->horizontalHeader()->setMinimumSectionSize(0);
    /*设置行标题最小高度*/
    ui->tableView_other_setting->horizontalHeader()->setFixedHeight(35);
    /*设置表头是否可以单击--不可单击*/
    ui->tableView_other_setting->horizontalHeader()->setSectionsClickable(false);
    ui->tableView_other_setting->verticalHeader()->setHidden(false);
    /*是否可编辑*/
    if(true)
    {
        ui->tableView_other_setting->setEditTriggers(QAbstractItemView::CurrentChanged|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
    }
    else
    {
        ui->tableView_other_setting->setEditTriggers(QAbstractItemView::NoEditTriggers);
    }

    QStringList columnNames;
    QList<int> columnWidths;
    columnNames << "check" << "name" << "value" << "introduce";
    columnWidths << 60 << 420 << 120 << 120;

    model = new QStandardItemModel;
    model->setHorizontalHeaderLabels(columnNames);
    ui->tableView_other_setting->setModel(model);
    int count = columnNames.count();
    for(int i = 0; i< count;i++)
    {
        ui->tableView_other_setting->setColumnWidth(i, columnWidths.at(i));
    }


    Delegate *checkDelegate = new Delegate;
    checkDelegate->setDelegateType("QCheckBox");
    checkDelegate->setDelegateColumn(0);
    ui->tableView_other_setting->setItemDelegateForColumn(0, checkDelegate);

    Delegate *labelDelegate = new Delegate;
    labelDelegate->setDelegateType("QLabel");
    ui->tableView_other_setting->setItemDelegateForColumn(1,labelDelegate);
    Delegate * lineEidtDelegate1 = new Delegate;
    lineEidtDelegate1->setDelegateType("QLineEdit");
    ui->tableView_other_setting->setItemDelegateForColumn(2, lineEidtDelegate1);

    Delegate *labelDelegate1 = new Delegate;
    labelDelegate1->setDelegateType("QLabel");
    ui->tableView_other_setting->setItemDelegateForColumn(3, labelDelegate1);

    if(lan == 0)
    {
        BatteryConfig_English::Item item;
        std::ifstream finBetteryData("battery_english.data", std::ios::binary);
        if(!item.ParseFromIstream(&finBetteryData)) {
            qDebug() << __FUNCTION__ << __LINE__ << "proto parse failed";
            finBetteryData.close();
            finBetteryData.clear();
        }
        else {
            for(int i = 0; i < item.itemattr_other_size(); i++) {
                for(int j = 0; j < 4; j++) {
                    if(j == 1) {
                        model->setItem(i, j, new QStandardItem(item.itemattr_other(i).name().c_str()));
                    }
                    else if(j == 2) {
                        model->setItem(i, j, new QStandardItem(QString::number(item.itemattr_other(i).value())));
                    }
                    else if(j == 3) {
                        model->setItem(i, j, new QStandardItem(item.itemattr_other(i).introduce().c_str()));
                    }
                }
            }
            finBetteryData.close();
            finBetteryData.clear();
        }
    }
    else if(lan == 1)
    {
        BatteryConfig::Item item;
        std::ifstream finBetteryData("battery.data", std::ios::binary);
        if(!item.ParseFromIstream(&finBetteryData)) {
            qDebug() << __FUNCTION__ << __LINE__ << "proto parse failed";
            finBetteryData.close();
            finBetteryData.clear();
        }
        else {
            for(int i = 0; i < item.itemattr_other_size(); i++) {
                for(int j = 0; j < 4; j++) {
                    if(j == 1) {
                        model->setItem(i, j, new QStandardItem(item.itemattr_other(i).name().c_str()));
                    }
                    else if(j == 2) {
                        model->setItem(i, j, new QStandardItem(QString::number(item.itemattr_other(i).value())));
                    }
                    else if(j == 3) {
                        model->setItem(i, j, new QStandardItem(item.itemattr_other(i).introduce().c_str()));
                    }
                }
            }
            finBetteryData.close();
            finBetteryData.clear();
        }
    }
}

// void MainWindow::setNum(QString value)
// {
//     qDebug("###1");
//     QModelIndex currentIndex = ui->pageParaSetTableView->currentIndex();
//     if(currentIndex.column() == 3)
//     {
//         model->setData(model->index(currentIndex.row(), 10), value.toFloat());
//     }
// }

void MainWindow::slot_getBcuNumberFromDialoglogin(int number)
{
    Q_UNUSED(number);
    // QTreeView treeView;
    // 创建模型
    modelBCU = new QStandardItemModel(ui->treeViewBCUbmu);
    // QMap<QModelIndex, int> indexTopPageMap;

    //创建一级目录项数为可变的
    // QStringList bcuNames;

    // qDebug() << "number: " << number;
    // for (int i = 1; i <= number; ++i) {
    //     QString bcuName = QString("BCU%1").arg(i);
    //     bcuNames.append(bcuName);
    // }

    // qDebug() << "BCUNames" << bcuNames;


    // 创建一级目录项

    rootItem = new QStandardItem("BCU01");
    // 设置一级目录项的字体为加粗
    QFont boldFont = rootItem->font();
    boldFont.setBold(true);
    rootItem->setFont(boldFont);
    modelBCU->appendRow(rootItem);

    for (int i = 1; i <= 26; ++i)
    {
        QString bmuName = QString("BMU%1").arg(i);
        QStandardItem *bmuItem = new QStandardItem(bmuName);
        rootItem->appendRow(bmuItem);
    }


    ui->tabWidgetBCU->setCurrentIndex(0);
    ui->tabWidgetBMU->setCurrentIndex(0);

    connect(ui->treeViewBCUbmu, &QTreeView::clicked, [=](const QModelIndex index){
        if(index.parent().isValid())
        {
            // qDebug() << "index" << index;
            qDebug() << "BMU: the row of the List" <<  index.row();
            int rowIndex = index.row();
            emit row_of_bmus_index(rowIndex);
            ui->pageBatteryStackWidget->setCurrentIndex(1);
        }
        else
        {
            // qDebug() << "index" << index;
            qDebug() << "BCU" << index.row();
            // int topLeveIndex = index.row();
            ui->pageBatteryStackWidget->setCurrentIndex(0);
        }
    });

    ui->treeViewBCUbmu->setModel(modelBCU);
    ui->treeViewBCUbmu->setHeaderHidden(true);
    ui->treeViewBCUbmu->setAnimated(true);
    ui->treeViewBCUbmu->expandAll();
    ui->treeViewBCUbmu->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->treeViewBCUbmu->show();
}



void MainWindow::on_pageParaSetCheck_stateChanged(int arg1)
{
    QWidget *currentWidget = ui->tabWidget_paraset->currentWidget();
    if (currentWidget) {
        QTableView *tableView = currentWidget->findChild<QTableView *>();
        if (tableView) {
            QStandardItemModel *model = qobject_cast<QStandardItemModel *>(tableView->model());
            if (model) {
                if(arg1 == Qt::CheckState::Checked) {
                    for(int i = 0; i < model->rowCount(); i++) {
                        model->setItem(i, 0, new QStandardItem("true"));
                    }
                }
                else {
                    for(int i = 0; i < model->rowCount(); i++) {
                        model->setItem(i, 0, new QStandardItem("false"));
                    }
                }
            }
        }
    }
}

void MainWindow::on_pageParaSetRead_clicked()
{
    BatteryConfig::Item item;
    std::ifstream finBetteryData("battery.data", std::ios::binary);
    if(!item.ParseFromIstream(&finBetteryData)) {
        qDebug() << __FUNCTION__ << __LINE__ << "proto parse failed";
        finBetteryData.close();
        finBetteryData.clear();
    }
    else {
        QList<int> checkRow_read;
        QList<int> checkAddress_read;

        QWidget *currentWidget = ui->tabWidget_paraset->currentWidget();
        if (currentWidget)
        {
            QTableView *tableView = currentWidget->findChild<QTableView *>();
            if (tableView)
            {
                QStandardItemModel *model = qobject_cast<QStandardItemModel *>(tableView->model());
                if (model)
                {
                    switch (tabWidget_paraset_index)
                    {
                    case 0:
                        qDebug() << "the tabWidget_paraset_index is :  " << tabWidget_paraset_index;
                        for(int row = 0; row < model->rowCount(); row++)
                        {
                            for(int column = 0; column < model->columnCount(); column++)
                            {
                                if(column == 0)
                                {
                                    QModelIndex index = model->index(row, column);
                                    QString data = model->data(index).toString();
                                    if(data == "true") {
                                        index = model->index(row, 2);
                                        // uint16_t data = model->data(index).toUInt();
                                        // item.mutable_itemattr(row)->set_value(data);
                                        int tempAddress = item.mutable_itemattr(row)->addr();
                                        checkRow_read.append(row);
                                        checkAddress_read.append(tempAddress);
                                    }
                                }
                            }
                        }
                        break;
                    case 1:
                        qDebug() << "the tabWidget_paraset_index is :  " << tabWidget_paraset_index;
                        for(int row = 0; row < model->rowCount(); row++)
                        {
                            for(int column = 0; column < model->columnCount(); column++)
                            {
                                if(column == 0)
                                {
                                    QModelIndex index = model->index(row, column);
                                    QString data = model->data(index).toString();
                                    if(data == "true") {
                                        index = model->index(row, 2);
                                        uint16_t data = model->data(index).toUInt();
                                        // item.mutable_itemattr_balance(row)->set_value(data);
                                        int tempAddress = item.mutable_itemattr_balance(row)->addr();
                                        checkRow_read.append(row);
                                        checkAddress_read.append(tempAddress);
                                    }
                                }
                            }
                        }
                        break;
                    case 2:
                        qDebug() << "the tabWidget_paraset_index is :  " << tabWidget_paraset_index;
                        for(int row = 0; row < model->rowCount(); row++)
                        {
                            for(int column = 0; column < model->columnCount(); column++)
                            {
                                if(column == 0)
                                {
                                    QModelIndex index = model->index(row, column);
                                    QString data = model->data(index).toString();
                                    if(data == "true") {
                                        index = model->index(row, 2);
                                        uint16_t data = model->data(index).toUInt();
                                        // item.mutable_itemattr_sox(row)->set_value(data);
                                        int tempAddress = item.mutable_itemattr_sox(row)->addr();
                                        checkRow_read.append(row);
                                        checkAddress_read.append(tempAddress);
                                    }
                                }
                            }
                        }
                        break;
                    case 3:
                        qDebug() << "the tabWidget_paraset_index is :  " << tabWidget_paraset_index;
                        for(int row = 0; row < model->rowCount(); row++)
                        {
                            for(int column = 0; column < model->columnCount(); column++)
                            {
                                if(column == 0)
                                {
                                    QModelIndex index = model->index(row, column);
                                    QString data = model->data(index).toString();
                                    if(data == "true") {
                                        index = model->index(row, 2);
                                        uint16_t data = model->data(index).toUInt();
                                        // item.mutable_itemattr_dido(row)->set_value(data);
                                        int tempAddress = item.mutable_itemattr_dido(row)->addr();
                                        // qDebug() << "the address:" << item.mutable_itemattr(row)->addr()  << "  , the value is :" <<data;
                                        checkRow_read.append(row);
                                        checkAddress_read.append(tempAddress);
                                    }
                                }
                            }
                        }
                        break;
                    case 4:
                        qDebug() << "the tabWidget_paraset_index is :  " << tabWidget_paraset_index;
                        for(int row = 0; row < model->rowCount(); row++)
                        {
                            for(int column = 0; column < model->columnCount(); column++)
                            {
                                if(column == 0)
                                {
                                    QModelIndex index = model->index(row, column);
                                    QString data = model->data(index).toString();
                                    if(data == "true") {
                                        index = model->index(row, 2);
                                        uint16_t data = model->data(index).toUInt();
                                        // item.mutable_itemattr_alert_value(row)->set_value(data);
                                        int tempAddress = item.mutable_itemattr_alert_value(row)->addr();
                                        checkRow_read.append(row);
                                        checkAddress_read.append(tempAddress);
                                    }
                                }
                            }
                        }
                        break;
                    case 5:
                        qDebug() << "the tabWidget_paraset_index is :  " << tabWidget_paraset_index;
                        for(int row = 0; row < model->rowCount(); row++)
                        {
                            for(int column = 0; column < model->columnCount(); column++)
                            {
                                if(column == 0)
                                {
                                    QModelIndex index = model->index(row, column);
                                    QString data = model->data(index).toString();
                                    if(data == "true") {
                                        index = model->index(row, 2);
                                        uint16_t data = model->data(index).toUInt();
                                        // item.mutable_itemattr_alert_delay(row)->set_value(data);
                                        int tempAddress = item.mutable_itemattr_alert_delay(row)->addr();
                                        checkRow_read.append(row);
                                        checkAddress_read.append(tempAddress);
                                    }
                                }
                            }
                        }
                        break;
                    case 6:
                        qDebug() << "the tabWidget_paraset_index is :  " << tabWidget_paraset_index;
                        for(int row = 0; row < model->rowCount(); row++)
                        {
                            for(int column = 0; column < model->columnCount(); column++)
                            {
                                if(column == 0)
                                {
                                    QModelIndex index = model->index(row, column);
                                    QString data = model->data(index).toString();
                                    if(data == "true") {
                                        index = model->index(row, 2);
                                        uint16_t data = model->data(index).toUInt();
                                        // item.mutable_itemattr_alert_release_value(row)->set_value(data);
                                        int tempAddress = item.mutable_itemattr_alert_release_value(row)->addr();
                                        checkRow_read.append(row);
                                        checkAddress_read.append(tempAddress);
                                    }
                                }
                            }
                        }
                        break;
                    case 7:
                        qDebug() << "the tabWidget_paraset_index is :  " << tabWidget_paraset_index;
                        for(int row = 0; row < model->rowCount(); row++)
                        {
                            for(int column = 0; column < model->columnCount(); column++)
                            {
                                if(column == 0)
                                {
                                    QModelIndex index = model->index(row, column);
                                    QString data = model->data(index).toString();
                                    if(data == "true") {
                                        index = model->index(row, 2);
                                        uint16_t data = model->data(index).toUInt();
                                        // item.mutable_itemattr_alert_release_delay(row)->set_value(data);
                                        int tempAddress = item.mutable_itemattr_alert_release_delay(row)->addr();
                                        checkRow_read.append(row);
                                        checkAddress_read.append(tempAddress);
                                    }
                                }
                            }
                        }
                        break;
                    case 8:
                        qDebug() << "the tabWidget_paraset_index is :  " << tabWidget_paraset_index;
                        for(int row = 0; row < model->rowCount(); row++)
                        {
                            for(int column = 0; column < model->columnCount(); column++)
                            {
                                if(column == 0)
                                {
                                    QModelIndex index = model->index(row, column);
                                    QString data = model->data(index).toString();
                                    if(data == "true") {
                                        index = model->index(row, 2);
                                        uint16_t data = model->data(index).toUInt();
                                        // item.mutable_itemattr_alert_dropcurr_rate(row)->set_value(data);
                                        int tempAddress = item.mutable_itemattr_alert_dropcurr_rate(row)->addr();
                                        checkRow_read.append(row);
                                        checkAddress_read.append(tempAddress);
                                    }
                                }
                            }
                        }
                        break;
                    case 9:
                        qDebug() << "the tabWidget_paraset_index is :  " << tabWidget_paraset_index;
                        for(int row = 0; row < model->rowCount(); row++)
                        {
                            for(int column = 0; column < model->columnCount(); column++)
                            {
                                if(column == 0)
                                {
                                    QModelIndex index = model->index(row, column);
                                    QString data = model->data(index).toString();
                                    if(data == "true") {
                                        index = model->index(row, 2);
                                        uint16_t data = model->data(index).toUInt();
                                        // item.mutable_itemattr_alert_solve_measure(row)->set_value(data);
                                        int tempAddress = item.mutable_itemattr_alert_solve_measure(row)->addr();
                                        checkRow_read.append(row);
                                        checkAddress_read.append(tempAddress);
                                    }
                                }
                            }
                        }
                        break;
                    case 10:
                        qDebug() << "the tabWidget_paraset_index is :  " << tabWidget_paraset_index;
                        for(int row = 0; row < model->rowCount(); row++)
                        {
                            for(int column = 0; column < model->columnCount(); column++)
                            {
                                if(column == 0)
                                {
                                    QModelIndex index = model->index(row, column);
                                    QString data = model->data(index).toString();
                                    if(data == "true") {
                                        index = model->index(row, 2);
                                        uint16_t data = model->data(index).toUInt();
                                        // item.mutable_itemattr_other(row)->set_value(data);
                                        int tempAddress = item.mutable_itemattr_other(row)->addr();
                                        checkRow_read.append(row);
                                        checkAddress_read.append(tempAddress);
                                    }
                                }
                            }
                        }
                        break;
                    }
                }
            }
        }

        if (checkRow_read.isEmpty())
        {
            QMessageBox::warning(nullptr, "警告", "勾选框无勾选，请勾选后再操作");
        }
        else{
            int startAddress = -1;
            int consecutiveCount = 0;
            QList<QPair<int, int>> pairs_addr;//addr, the number of the continuous
            int row_index_i = 0;  // 防止勾选框不间断时，checkRow_read与checkAddress_read，值与索引不匹配的问题
            for (int row : checkRow_read)
            {
                int address = checkAddress_read[row_index_i];
                if (startAddress == -1)
                {
                    startAddress = address;
                    consecutiveCount = 1;
                }
                else if (address == startAddress + consecutiveCount)
                {
                    consecutiveCount++;
                }
                else
                {
                    if (consecutiveCount > 1)
                    {
                        pairs_addr.append(qMakePair(startAddress, consecutiveCount));
                    }
                    else
                    {
                        pairs_addr.append(qMakePair(startAddress, 1));
                    }
                    startAddress = address;
                    consecutiveCount = 1;
                }
                row_index_i++;
            }

            if (consecutiveCount > 1)
            {
                pairs_addr.append(qMakePair(startAddress, consecutiveCount));

            }
            else
            {
                pairs_addr.append(qMakePair(startAddress, 1));
            }

            emit closeThread();
            QThread::msleep(700);
            int rowStart = 0;
            QList<QPair<int, int>>::iterator it;
            for (it = pairs_addr.begin(); it!= pairs_addr.end(); ++it) {
                qDebug() << "First element read: " << it->first << ", Second element  read: " << it->second;
                uint16_t result[it->second];
                int tempIndex = checkRow_read[rowStart];
                emit read_regs_signals(it->first, it->second, result, tempIndex);
                QThread::msleep(80);
                rowStart += it->second;
            }
            emit openThread();
            rowStart = 0;
            qDebug() << "read of the row" << checkRow_read;
            qDebug() << "read of the address" << checkAddress_read;
        }
        finBetteryData.close();
        finBetteryData.clear();
    }
}

void MainWindow::slot_testData(uint16_t *data)
{
    // qDebug("#####slot_testData data[0]:[%x] [1]:[%x] [2]:[%x] [3]:[%x] [4]:[%x] [5]:[%x] [6]:[%x] [7]:[%x] [8]:[%x] [9]:[%x] ",
    //        data[0], data[1], data[2], data[3], data[4],
    //        data[5], data[6], data[7], data[8], data[9]);
}

void MainWindow::slot_pageParaSetShow(int row, int nb, uint16_t *data)
{
    // qDebug() << "mainwindow:" << data[0] << data[1] << data[2] << data[3] << data[4];
    int i = 0;
    for(;i < nb; row++, i++)
    {
        QWidget *currentWidget = ui->tabWidget_paraset->currentWidget();
        if (currentWidget)
        {
            QTableView *tableView = currentWidget->findChild<QTableView *>();
            if (tableView)
            {
                QStandardItemModel *model = qobject_cast<QStandardItemModel *>(tableView->model());
                if (model)
                {
                    qDebug() << "1111111111111111111";
                    QModelIndex index = model->index(row, 2);
                    model->setData(index, data[i]);
                    qDebug() << "第" << i << "个元素："<< "row " << row << "  result: " << data[i];
                }
            }
        }
    }
    i = 0;
}

void MainWindow::trubleListInit()
{
    for (int i = 1; i <= 56; ++i)
    {
        QString labelName = QString("label_trouble_%1").arg(i);
        QList<QWidget*> allWidgets = findChildren<QWidget*>();
        for (QWidget* widget : allWidgets)
        {
            QLabel* label = qobject_cast<QLabel*>(widget);
            if (label!= nullptr && label->objectName() == labelName)
            {
                trouble_list.append(label);
                break;   // 找到后就可以跳出内层循环
            }
        }
    }
}

void MainWindow::slot_pageHomeFault(QByteArray byteArray, int dataType, uint16_t *data)
{
    /*    ui->color_trouble_1->setStyleSheet("background-image: url(:/Image/trouble-background-1.png);");
    ui->color_trouble_2->setStyleSheet("background-image: url(:/Image/trouble-background-2.png);");
    ui->color_trouble_3->setStyleSheet("background-image: url(:/Image/trouble-background-3.png);");
    ui->color_trouble_normal->setStyleSheet("background-image: url(:/Image/trouble-background-normal.png);");
    */
    if(dataType == TypeRecvData)
    {
        QList<QString> list;
        QList<QString> list_result;
        for (int i=0; i <= 6;i++)
        {
            QString temp = QString::number(data[i], 2);
            while (temp.size() < 16)
            {
                temp = "0" + temp;
            }
            list.append(temp);
        }

        for(const QString &binary : list)
        {
            for (int i = 0; i < 16; i+=2)
            {
                list_result << binary.mid(i, 2);
            }
        }

        // qDebug() << "data:" << data[0] << data[1] << data[2] << data[3] << data[4] << data[5] << data[6] << data[7];
        // qDebug() << "test_list: " << list;
        // qDebug() << "list_reslut:" <<list_result.size();
        // qDebug() << "trouble:" << trouble_list.size();


        for (int i = 0; i < 56; i++)
        {
            if (list_result[i] == "00")
            {
                trouble_list[i]->setStyleSheet("background-image: url(:/Image/trouble-background-normal.png);");
            }
            else if (list_result[i] == "01")
            {
                trouble_list[i]->setStyleSheet("background-image: url(:/Image/trouble-background-1.png);");
                QString timeStr = QString(QDateTime::currentDateTime().toString("[yyyy-MM-dd hh:mm:ss.zzz] "));
                model_history_alarm->setItem(count_history_alarm, 0, new QStandardItem(timeStr));
                model_history_alarm->setItem(count_history_alarm, 1, new QStandardItem(trouble_list[i]->text()));
                model_history_alarm->setItem(count_history_alarm, 2, new QStandardItem(currentBCU));
                if (lan == 0)
                {
                    model_history_alarm->setItem(count_history_alarm, 3, new QStandardItem("Level 1 Alarm"));
                }
                else if (lan == 1)
                {
                    model_history_alarm->setItem(count_history_alarm, 3, new QStandardItem("一级报警"));
                }
                count_history_alarm++;
            }
            else if (list_result[i] == "10")
            {
                trouble_list[i]->setStyleSheet("background-image: url(:/Image/trouble-background-2.png);");
                QString timeStr = QString(QDateTime::currentDateTime().toString("[yyyy-MM-dd hh:mm:ss.zzz] "));
                model_history_alarm->setItem(count_history_alarm, 0, new QStandardItem(timeStr));
                model_history_alarm->setItem(count_history_alarm, 1, new QStandardItem(trouble_list[i]->text()));
                model_history_alarm->setItem(count_history_alarm, 2, new QStandardItem(currentBCU));
                if (lan == 0)
                {
                    model_history_alarm->setItem(count_history_alarm, 3, new QStandardItem("Level 2 Alarm"));
                }
                else if (lan == 1)
                {
                    model_history_alarm->setItem(count_history_alarm, 3, new QStandardItem("二级报警"));
                }
                count_history_alarm++;
            }
            else if (list_result[i] == "11")
            {
                trouble_list[i]->setStyleSheet("background-image: url(:/Image/trouble-background-3.png);");
                QString timeStr = QString(QDateTime::currentDateTime().toString("[yyyy-MM-dd hh:mm:ss.zzz] "));
                model_history_alarm->setItem(count_history_alarm, 0, new QStandardItem(timeStr));
                model_history_alarm->setItem(count_history_alarm, 1, new QStandardItem(trouble_list[i]->text()));
                model_history_alarm->setItem(count_history_alarm, 2, new QStandardItem(currentBCU));
                if (lan == 0)
                {
                    model_history_alarm->setItem(count_history_alarm, 3, new QStandardItem("Level 3 Alarm"));
                }
                else if (lan == 1)
                {
                    model_history_alarm->setItem(count_history_alarm, 3, new QStandardItem("三级报警"));
                }
                count_history_alarm++;
            }
            else
            {
                trouble_list[i]->setStyleSheet("background-image: url(:/Image/trouble-background-default.png);");
                qDebug() << "Can not analysis the right address!!!";
            }
        }

        //设置每次界面刷新数据时，表格始终停留在最新的数据上
        int curIndex = model_history_alarm->rowCount();
        if (curIndex > 0)
        {
            ui->tableView_history_alarm->scrollToBottom();
        }
    }
}

void MainWindow::closeEvent(QCloseEvent *e)
{
    emit quitThread();

    QWidget::closeEvent(e);
}

void MainWindow::on_pageParaSetWrite_clicked()
{
    BatteryConfig::Item item;

    // 从磁盘读取 protobuf 文件
    std::ifstream finBetteryData("battery.data", std::ios::in | std::ios::binary);
    if (!finBetteryData.is_open()) {

    }

    // 获取文件大小
    finBetteryData.seekg(0, std::ios::end);
    size_t size = finBetteryData.tellg();
    finBetteryData.seekg(0, std::ios::beg);

    // 读取文件内容到字符串
    std::string serialized_data(size, '\0');
    if (!finBetteryData.read(&serialized_data[0], size)) {

    }
    finBetteryData.close();

    // 反序列化 protobuf 数据
    if (!item.ParseFromString(serialized_data)) {
    }

    QList<int> checkRow_write;//存放被勾选的勾选框的索引值
    QVector<uint16_t> originVector;//存放被勾选的勾选框的value

    QWidget *currentWidget = ui->tabWidget_paraset->currentWidget();
    if (currentWidget)
    {
        QTableView *tableView = currentWidget->findChild<QTableView *>();
        if (tableView)
        {
            QStandardItemModel *model = qobject_cast<QStandardItemModel *>(tableView->model());
            if (model)
            {
                switch (tabWidget_paraset_index) {
                case 0:
                    //仅需地址和值
                    qDebug() << "the tabWidget_paraset_index is :  " << tabWidget_paraset_index;
                    for(int row = 0; row < model->rowCount(); row++)
                    {
                        for(int column = 0; column < model->columnCount(); column++)
                        {
                            if(column == 0)
                            {
                                QModelIndex index = model->index(row, column);
                                QString data = model->data(index).toString();
                                if(data == "true") {
                                    index = model->index(row, 2);
                                    // int tempAddress = item.mutable_itemattr(row)->addr();
                                    // int resultAddress = tempAddress < 4000 ? tempAddress - 3000 : tempAddress -4000 + 162;
                                    uint16_t data = model->data(index).toUInt();
                                    item.mutable_itemattr(row)->set_value(data);
                                    int tempAddress = item.mutable_itemattr(row)->addr();
                                    // qDebug() << "the address:" << item.mutable_itemattr(row)->addr()  << "  , the value is :" <<data;
                                    checkRow_write.append(tempAddress);
                                    originVector.append(item.mutable_itemattr(row)->value());
                                }
                            }
                        }
                    }
                    break;
                case 1:
                    qDebug() << "the tabWidget_paraset_index is :  " << tabWidget_paraset_index;
                    for(int row = 0; row < model->rowCount(); row++)
                    {
                        for(int column = 0; column < model->columnCount(); column++)
                        {
                            if(column == 0)
                            {
                                QModelIndex index = model->index(row, column);
                                QString data = model->data(index).toString();
                                if(data == "true") {
                                    index = model->index(row, 2);
                                    // int tempAddress = item.mutable_itemattr(row)->addr();
                                    // int resultAddress = tempAddress < 4000 ? tempAddress - 3000 : tempAddress -4000 + 162;
                                    uint16_t data = model->data(index).toUInt();
                                    item.mutable_itemattr_balance(row)->set_value(data);
                                    int tempAddress = item.mutable_itemattr_balance(row)->addr();
                                    // qDebug() << "the address:" << item.mutable_itemattr(row)->addr()  << "  , the value is :" <<data;
                                    checkRow_write.append(tempAddress);
                                    originVector.append(item.mutable_itemattr_balance(row)->value());
                                }
                            }
                        }
                    }
                    break;
                case 2:
                    qDebug() << "the tabWidget_paraset_index is :  " << tabWidget_paraset_index;
                    for(int row = 0; row < model->rowCount(); row++)
                    {
                        for(int column = 0; column < model->columnCount(); column++)
                        {
                            if(column == 0)
                            {
                                QModelIndex index = model->index(row, column);
                                QString data = model->data(index).toString();
                                if(data == "true") {
                                    index = model->index(row, 2);
                                    // int tempAddress = item.mutable_itemattr(row)->addr();
                                    // int resultAddress = tempAddress < 4000 ? tempAddress - 3000 : tempAddress -4000 + 162;
                                    uint16_t data = model->data(index).toUInt();
                                    item.mutable_itemattr_sox(row)->set_value(data);
                                    int tempAddress = item.mutable_itemattr_sox(row)->addr();
                                    // qDebug() << "the address:" << item.mutable_itemattr(row)->addr()  << "  , the value is :" <<data;
                                    checkRow_write.append(tempAddress);
                                    originVector.append(item.mutable_itemattr_sox(row)->value());
                                }
                            }
                        }
                    }
                    break;
                case 3:
                    qDebug() << "the tabWidget_paraset_index is :  " << tabWidget_paraset_index;
                    for(int row = 0; row < model->rowCount(); row++)
                    {
                        for(int column = 0; column < model->columnCount(); column++)
                        {
                            if(column == 0)
                            {
                                QModelIndex index = model->index(row, column);
                                QString data = model->data(index).toString();
                                if(data == "true") {
                                    index = model->index(row, 2);
                                    // int tempAddress = item.mutable_itemattr(row)->addr();
                                    // int resultAddress = tempAddress < 4000 ? tempAddress - 3000 : tempAddress -4000 + 162;
                                    uint16_t data = model->data(index).toUInt();
                                    item.mutable_itemattr_dido(row)->set_value(data);
                                    int tempAddress = item.mutable_itemattr_dido(row)->addr();
                                    // qDebug() << "the address:" << item.mutable_itemattr(row)->addr()  << "  , the value is :" <<data;
                                    checkRow_write.append(tempAddress);
                                    originVector.append(item.mutable_itemattr_dido(row)->value());
                                }
                            }
                        }
                    }
                    break;
                case 4:
                    qDebug() << "the tabWidget_paraset_index is :  " << tabWidget_paraset_index;
                    for(int row = 0; row < model->rowCount(); row++)
                    {
                        for(int column = 0; column < model->columnCount(); column++)
                        {
                            if(column == 0)
                            {
                                QModelIndex index = model->index(row, column);
                                QString data = model->data(index).toString();
                                if(data == "true") {
                                    index = model->index(row, 2);
                                    // int tempAddress = item.mutable_itemattr(row)->addr();
                                    // int resultAddress = tempAddress < 4000 ? tempAddress - 3000 : tempAddress -4000 + 162;
                                    uint16_t data = model->data(index).toUInt();
                                    item.mutable_itemattr_alert_value(row)->set_value(data);
                                    int tempAddress = item.mutable_itemattr_alert_value(row)->addr();
                                    // qDebug() << "the address:" << item.mutable_itemattr(row)->addr()  << "  , the value is :" <<data;
                                    checkRow_write.append(tempAddress);
                                    originVector.append(item.mutable_itemattr_alert_value(row)->value());
                                }
                            }
                        }
                    }
                    break;
                case 5:
                    qDebug() << "the tabWidget_paraset_index is :  " << tabWidget_paraset_index;
                    for(int row = 0; row < model->rowCount(); row++)
                    {
                        for(int column = 0; column < model->columnCount(); column++)
                        {
                            if(column == 0)
                            {
                                QModelIndex index = model->index(row, column);
                                QString data = model->data(index).toString();
                                if(data == "true") {
                                    index = model->index(row, 2);
                                    // int tempAddress = item.mutable_itemattr(row)->addr();
                                    // int resultAddress = tempAddress < 4000 ? tempAddress - 3000 : tempAddress -4000 + 162;
                                    uint16_t data = model->data(index).toUInt();
                                    item.mutable_itemattr_alert_delay(row)->set_value(data);
                                    int tempAddress = item.mutable_itemattr_alert_delay(row)->addr();
                                    // qDebug() << "the address:" << item.mutable_itemattr(row)->addr()  << "  , the value is :" <<data;
                                    checkRow_write.append(tempAddress);
                                    originVector.append(item.mutable_itemattr_alert_delay(row)->value());
                                }
                            }
                        }
                    }
                    break;
                case 6:
                    qDebug() << "the tabWidget_paraset_index is :  " << tabWidget_paraset_index;
                    for(int row = 0; row < model->rowCount(); row++)
                    {
                        for(int column = 0; column < model->columnCount(); column++)
                        {
                            if(column == 0)
                            {
                                QModelIndex index = model->index(row, column);
                                QString data = model->data(index).toString();
                                if(data == "true") {
                                    index = model->index(row, 2);
                                    // int tempAddress = item.mutable_itemattr(row)->addr();
                                    // int resultAddress = tempAddress < 4000 ? tempAddress - 3000 : tempAddress -4000 + 162;
                                    uint16_t data = model->data(index).toUInt();
                                    item.mutable_itemattr_alert_release_value(row)->set_value(data);
                                    int tempAddress = item.mutable_itemattr_alert_release_value(row)->addr();
                                    // qDebug() << "the address:" << item.mutable_itemattr(row)->addr()  << "  , the value is :" <<data;
                                    checkRow_write.append(tempAddress);
                                    originVector.append(item.mutable_itemattr_alert_release_value(row)->value());
                                }
                            }
                        }
                    }
                    break;
                case 7:
                    qDebug() << "the tabWidget_paraset_index is :  " << tabWidget_paraset_index;
                    for(int row = 0; row < model->rowCount(); row++)
                    {
                        for(int column = 0; column < model->columnCount(); column++)
                        {
                            if(column == 0)
                            {
                                QModelIndex index = model->index(row, column);
                                QString data = model->data(index).toString();
                                if(data == "true") {
                                    index = model->index(row, 2);
                                    // int tempAddress = item.mutable_itemattr(row)->addr();
                                    // int resultAddress = tempAddress < 4000 ? tempAddress - 3000 : tempAddress -4000 + 162;
                                    uint16_t data = model->data(index).toUInt();
                                    item.mutable_itemattr_alert_release_delay(row)->set_value(data);
                                    int tempAddress = item.mutable_itemattr_alert_release_delay(row)->addr();
                                    // qDebug() << "the address:" << item.mutable_itemattr(row)->addr()  << "  , the value is :" <<data;
                                    checkRow_write.append(tempAddress);
                                    originVector.append(item.mutable_itemattr_alert_release_delay(row)->value());
                                }
                            }
                        }
                    }
                    break;
                case 8:
                    qDebug() << "the tabWidget_paraset_index is :  " << tabWidget_paraset_index;
                    for(int row = 0; row < model->rowCount(); row++)
                    {
                        for(int column = 0; column < model->columnCount(); column++)
                        {
                            if(column == 0)
                            {
                                QModelIndex index = model->index(row, column);
                                QString data = model->data(index).toString();
                                if(data == "true") {
                                    index = model->index(row, 2);
                                    // int tempAddress = item.mutable_itemattr(row)->addr();
                                    // int resultAddress = tempAddress < 4000 ? tempAddress - 3000 : tempAddress -4000 + 162;
                                    uint16_t data = model->data(index).toUInt();
                                    item.mutable_itemattr_alert_dropcurr_rate(row)->set_value(data);
                                    int tempAddress = item.mutable_itemattr_alert_dropcurr_rate(row)->addr();
                                    // qDebug() << "the address:" << item.mutable_itemattr(row)->addr()  << "  , the value is :" <<data;
                                    checkRow_write.append(tempAddress);
                                    originVector.append(item.mutable_itemattr_alert_dropcurr_rate(row)->value());
                                }
                            }
                        }
                    }
                    break;
                case 9:
                    qDebug() << "the tabWidget_paraset_index is :  " << tabWidget_paraset_index;
                    for(int row = 0; row < model->rowCount(); row++)
                    {
                        for(int column = 0; column < model->columnCount(); column++)
                        {
                            if(column == 0)
                            {
                                QModelIndex index = model->index(row, column);
                                QString data = model->data(index).toString();
                                if(data == "true") {
                                    index = model->index(row, 2);
                                    // int tempAddress = item.mutable_itemattr(row)->addr();
                                    // int resultAddress = tempAddress < 4000 ? tempAddress - 3000 : tempAddress -4000 + 162;
                                    uint16_t data = model->data(index).toUInt();
                                    item.mutable_itemattr_alert_solve_measure(row)->set_value(data);
                                    int tempAddress = item.mutable_itemattr_alert_solve_measure(row)->addr();
                                    // qDebug() << "the address:" << item.mutable_itemattr(row)->addr()  << "  , the value is :" <<data;
                                    checkRow_write.append(tempAddress);
                                    originVector.append(item.mutable_itemattr_alert_solve_measure(row)->value());
                                }
                            }
                        }
                    }
                    break;
                case 10:
                    qDebug() << "the tabWidget_paraset_index is :  " << tabWidget_paraset_index;
                    for(int row = 0; row < model->rowCount(); row++)
                    {
                        for(int column = 0; column < model->columnCount(); column++)
                        {
                            if(column == 0)
                            {
                                QModelIndex index = model->index(row, column);
                                QString data = model->data(index).toString();
                                if(data == "true") {
                                    index = model->index(row, 2);
                                    // int tempAddress = item.mutable_itemattr(row)->addr();
                                    // int resultAddress = tempAddress < 4000 ? tempAddress - 3000 : tempAddress -4000 + 162;
                                    uint16_t data = model->data(index).toUInt();
                                    item.mutable_itemattr_other(row)->set_value(data);
                                    int tempAddress = item.mutable_itemattr_other(row)->addr();
                                    // qDebug() << "the address:" << item.mutable_itemattr(row)->addr()  << "  , the value is :" <<data;
                                    checkRow_write.append(tempAddress);
                                    originVector.append(item.mutable_itemattr_other(row)->value());
                                }
                            }
                        }
                    }
                    break;
                }
            }
        }
    }

    // for(int row = 0; row < model->rowCount(); row++)
    // {
    //     for(int column = 0; column < model->columnCount(); column++)
    //     {
    //         if(column == 0)
    //         {
    //             QModelIndex index = model->index(row, column);
    //             QString data = model->data(index).toString();
    //             if(data == "true") {
    //                 index = model->index(row, 2);
    //                 // int tempAddress = item.mutable_itemattr(row)->addr();
    //                 // int resultAddress = tempAddress < 4000 ? tempAddress - 3000 : tempAddress -4000 + 162;
    //                 uint16_t data = model->data(index).toUInt();
    //                 item.mutable_itemattr(row)->set_value(data);
    //                 // qDebug() << "the address:" << item.mutable_itemattr(row)->addr()  << "  , the value is :" <<data;
    //                 checkRow_write.append(row);
    //                 originVector.append(item.mutable_itemattr(row)->value());
    //             }
    //         }
    //     }
    // }

    // for(int row = 0; row < model->rowCount(); row++) {
    //     for(int column = 0; column < model->columnCount(); column++) {
    //         if(column == 0) {
    //             QModelIndex index = model->index(row, column);
    //             QString data = model->data(index).toString();
    //             if(data == "true") {
    //                 index = model->index(row, 2);
    //                 uint16_t data = model->data(index).toUInt();
    //                 item.mutable_itemattr(row)->set_value(data);
    //                 // qDebug() << "the address:" << item.mutable_itemattr(row)->addr()  << "  , the value is :" <<data;
    //                 checkRow_write.append(row);
    //                 originVector.append(item.mutable_itemattr(row)->value());
    //             }
    //         }
    //     }
    // }

        qDebug() << "write of the row" << checkRow_write;
        qDebug() << "originalLIst of the value" << originVector;

    if (checkRow_write.isEmpty())
    {
        QMessageBox::warning(nullptr, "警告", "勾选框无勾选，请勾选后再操作");
    }
    else
    {
        emit closeThread();
        QThread::msleep(700);
        for (int i=0; i<checkRow_write.size();i++)
        {
            emit write_regs_signals(checkRow_write[i], originVector[i]);
        }
        emit openThread();
    }
    // 序列化消息对象
    std::string new_serialized_data;
    if (!item.SerializeToString(&new_serialized_data)) {

    }

    // 将序列化后的数据写回磁盘
    std::ofstream foutBetteryData("battery.data", std::ios::out | std::ios::binary | std::ios::trunc);
    if (!foutBetteryData.is_open()) {

    }

    // 写入文件
    if (!foutBetteryData.write(new_serialized_data.c_str(), new_serialized_data.size())) {

    }
    foutBetteryData.close();
    // qDebug() << item.mutable_itemattr(0)->value();
    // qDebug() << "update";

}

void MainWindow::on_tabChanged(int index)
{
    tabWidget_paraset_index = index;
    ui->pageParaSetCheck->setCheckState(Qt::Unchecked);
}

void MainWindow::on_comBoxBCUSelect(int index)
{
    QString BCUText = ui->comboBoxBCUSelect->currentText();
    QString statusBarBCULabel = "Current BCU:  ";

    statusBarBcu->setText(statusBarBCULabel + BCUText);
    rootItem->setText(BCUText);

    //当改变BCU选择时，改变当前BCU读取的地址
    currentBCU = BCUText;
}

void MainWindow::on_btn_close_pos_clicked()
{
    //强闭总正

}


void MainWindow::on_btn_open_pos_clicked()
{
    //强断总正

}

void MainWindow::on_btn_close_neg_clicked()
{
    //强闭总负

}

void MainWindow::on_btn_open_neg_clicked()
{
    //强断总负

}

void MainWindow::on_btn_close_prechg_clicked()
{
    //强闭预充

}

void MainWindow::on_btn_open_prechg_clicked()
{
    //强断预充

}

void MainWindow::on_btnImport_clicked()
{
    QString filePath = QFileDialog::getOpenFileName(this, "请选择需要升级的固件", "", "所有文件 (*)");
        if (!filePath.isEmpty()) {
            // 可以在这里对选择的文件路径进行处理
            qDebug() << "选择的文件路径：" << filePath;
            ui->label_pageFlash_filepath->setText(filePath);
        }
}

