Newer
Older
ZXSSCJ / CounterRealTime / CounterSettingForm.cpp
#include "CounterSettingForm.h"
#include "ui_CounterSettingForm.h"

#include <iostream>

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

    this->setWindowFlags(Qt::FramelessWindowHint);
    resize(1020, 680);
    this->move(450, 200);

    ui->btnSetDialog->button(QDialogButtonBox::Ok)->setText("确定");
    ui->btnSetDialog->button(QDialogButtonBox::Cancel)->setText("取消");

    flagGroup = new QButtonGroup();
    flagGroup->addButton(ui->radioDispA, 1);
    flagGroup->addButton(ui->radioDispB, 0);

    countGroup = new QButtonGroup();
    countGroup->addButton(ui->radioDispFour, 4);
    countGroup->addButton(ui->radioDispSix, 6);
    countGroup->addButton(ui->radioDispEight, 8);

    this->initDefaultSettings();
    this->initChannelSettingTable();
}

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

void CounterSettingForm::initCounterSelect()
{
    ui->selectCounter->clear();
    ui->selectCounter->addItem("== 请选择 ==", "-1");
    QList<QString> devIds = SettingConfig::getInstance().MASTER == 1 ? ConstCache::getInstance().deviceIdLoopA : ConstCache::getInstance().deviceIdLoopB;
    for (int i = 0; i < devIds.size(); i++)
    {
        ui->selectCounter->addItem(ConstCache::getInstance().deviceMap.value(devIds.at(i))->getDeviceName(), devIds.at(i));
    }
}

void CounterSettingForm::initDefaultSettings()
{
    ui->iptApiUrl->setText(SettingConfig::getInstance().BASE_URL);
    ui->iptLogPath->setText(SettingConfig::getInstance().BASE_LOG_PATH);

    if (flagGroup->button(SettingConfig::getInstance().MASTER) != nullptr)
    {
        flagGroup->button(SettingConfig::getInstance().MASTER)->setChecked(true);
    }
    if (countGroup->button(SettingConfig::getInstance().DISPLAY_COUNT) != nullptr)
    {
        countGroup->button(SettingConfig::getInstance().DISPLAY_COUNT)->setChecked(true);
    }
}

void CounterSettingForm::initChannelSettingTable()
{
    QGridLayout * leftLayout = new QGridLayout();
    QGridLayout * rightLayout = new QGridLayout();
    QHBoxLayout * channelTableLayout = new QHBoxLayout(ui->widgetChannel);
    ui->widgetChannel->setLayout(channelTableLayout);
    channelTableLayout->addLayout(leftLayout);
    channelTableLayout->addLayout(rightLayout);
    leftLayout->setSpacing(0);
    rightLayout->setSpacing(0);

    QLabel * headerLeftNo = new QLabel(ui->widgetChannel);
    QLabel * headerLeftActive = new QLabel(ui->widgetChannel);
    QLabel * headerLeftClock = new QLabel(ui->widgetChannel);
    QLabel * headerLeftDelay = new QLabel(ui->widgetChannel);
    headerLeftNo->setText("通道号");
    headerLeftActive->setText("是否启用");
    headerLeftClock->setText("钟编号");
    headerLeftDelay->setText("时延(ns)");
    headerLeftNo->setProperty("table", "header");
    headerLeftActive->setProperty("table", "header");
    headerLeftClock->setProperty("table", "header");
    headerLeftDelay->setProperty("table", "header");

    headerLeftNo->setMaximumSize(100, 50);
    headerLeftNo->setMinimumSize(100, 50);
    headerLeftActive->setMaximumSize(120, 50);
    headerLeftActive->setMinimumSize(120, 50);
    headerLeftClock->setMinimumSize(120, 50);
    headerLeftClock->setMaximumSize(120, 50);
    headerLeftDelay->setMinimumSize(120, 50);
    headerLeftDelay->setMaximumSize(120, 50);

    headerLeftNo->setAlignment(Qt::AlignCenter);
    headerLeftActive->setAlignment(Qt::AlignCenter);
    headerLeftClock->setAlignment(Qt::AlignCenter);
    headerLeftDelay->setAlignment(Qt::AlignCenter);
    leftLayout->addWidget(headerLeftActive, 0, 0);
    leftLayout->addWidget(headerLeftNo, 0, 1);
    leftLayout->addWidget(headerLeftClock, 0, 2);
    leftLayout->addWidget(headerLeftDelay, 0, 3);

    QLabel * headerRightNo = new QLabel(ui->widgetChannel);
    QLabel * headerRightActive = new QLabel(ui->widgetChannel);
    QLabel * headerRightClock = new QLabel(ui->widgetChannel);
    QLabel * headerRightDelay = new QLabel(ui->widgetChannel);
    headerRightNo->setText("通道号");
    headerRightActive->setText("是否启用");
    headerRightClock->setText("钟编号");
    headerRightDelay->setText("时延(ns)");
    headerRightNo->setProperty("table", "header");
    headerRightActive->setProperty("table", "header");
    headerRightClock->setProperty("table", "header");
    headerRightDelay->setProperty("table", "header");

    headerRightNo->setMaximumSize(100, 50);
    headerRightNo->setMinimumSize(100, 50);
    headerRightActive->setMaximumSize(120, 50);
    headerRightActive->setMinimumSize(120, 50);
    headerRightClock->setMinimumSize(120, 50);
    headerRightClock->setMaximumSize(120, 50);
    headerRightDelay->setMinimumSize(120, 50);
    headerRightDelay->setMaximumSize(120, 50);

    headerRightNo->setAlignment(Qt::AlignCenter);
    headerRightActive->setAlignment(Qt::AlignCenter);
    headerRightClock->setAlignment(Qt::AlignCenter);
    headerRightDelay->setAlignment(Qt::AlignCenter);

    rightLayout->addWidget(headerRightActive, 0, 0);
    rightLayout->addWidget(headerRightNo, 0, 1);
    rightLayout->addWidget(headerRightClock, 0, 2);
    rightLayout->addWidget(headerRightDelay, 0, 3);

    for ( int i = 0; i < 8; i++ )
    {
        QLabel * tdLeftNo = new QLabel(ui->widgetChannel);
        QLabel * tdRightNo = new QLabel(ui->widgetChannel);
        tdLeftNo->setText(QString("CH%1").arg(i + 1));
        tdLeftNo->setAlignment(Qt::AlignCenter);
        tdRightNo->setText(QString("CH%1").arg(i + 8 + 1));
        tdRightNo->setAlignment(Qt::AlignCenter);
        leftLayout->addWidget(tdLeftNo, i + 1, 1);
        rightLayout->addWidget(tdRightNo, i + 1 , 1);

        QCheckBox * tdLeftActive = new QCheckBox(ui->widgetChannel);
        QCheckBox * tdRightActive = new QCheckBox(ui->widgetChannel);
        tdLeftActive->setText("启用");
//        tdLeftActive->setStyleSheet("padding-left: 30px;");
        tdLeftActive->setMinimumSize(120, 40);
        tdLeftActive->setMaximumSize(120, 40);
        tdRightActive->setText("启用");
//        tdRightActive->setStyleSheet("padding-left: 30px;");
        tdRightActive->setMinimumSize(120, 40);
        tdRightActive->setMaximumSize(120, 40);
        leftLayout->addWidget(tdLeftActive, i + 1, 0);
        rightLayout->addWidget(tdRightActive, i + 1 , 0);

        QLineEdit * tdLeftClock = new QLineEdit(ui->widgetChannel);
        QLineEdit * tdRightClock = new QLineEdit(ui->widgetChannel);
        tdLeftClock->setText("1000");
        tdLeftClock->setMinimumSize(120, 40);
        tdLeftClock->setMaximumSize(120, 40);
        tdRightClock->setText("1000");
        tdRightClock->setMinimumSize(120, 40);
        tdRightClock->setMaximumSize(120, 40);
        leftLayout->addWidget(tdLeftClock, i + 1, 2);
        rightLayout->addWidget(tdRightClock, i + 1 , 2);

        QDoubleSpinBox * tdLeftDelay = new QDoubleSpinBox(ui->widgetChannel);
        QDoubleSpinBox * tdRightDelay = new QDoubleSpinBox(ui->widgetChannel);
        tdLeftDelay->setValue(0.000);
        tdLeftDelay->setRange(-1E9, 1E9);
        tdLeftDelay->setSingleStep(0.001);
        tdLeftDelay->setDecimals(3);
        tdLeftDelay->setMinimumSize(120, 40);
        tdLeftDelay->setMaximumSize(120, 40);
        tdRightDelay->setValue(0.000);
        tdRightDelay->setRange(-1E9, 1E9);
        tdRightDelay->setSingleStep(0.001);
        tdRightDelay->setDecimals(3);
        tdRightDelay->setMinimumSize(120, 40);
        tdRightDelay->setMaximumSize(120, 40);
        leftLayout->addWidget(tdLeftDelay, i + 1, 3);
        rightLayout->addWidget(tdRightDelay, i + 1 , 3);

        if (i % 2 == 0)
        {
            tdLeftNo->setProperty("table", "trOdd");
            tdRightNo->setProperty("table", "trOdd");
            tdLeftClock->setProperty("table", "trOdd");
            tdRightClock->setProperty("table", "trOdd");
            tdLeftDelay->setProperty("table", "trOdd");
            tdRightDelay->setProperty("table", "trOdd");
            tdLeftActive->setProperty("table", "trOdd");
            tdRightActive->setProperty("table", "trOdd");
        } else {
            tdLeftNo->setProperty("table", "trEven");
            tdRightNo->setProperty("table", "trEven");
            tdLeftClock->setProperty("table", "trEven");
            tdRightClock->setProperty("table", "trEven");
            tdLeftDelay->setProperty("table", "trEven");
            tdRightDelay->setProperty("table", "trEven");
            tdLeftActive->setProperty("table", "trEven");
            tdRightActive->setProperty("table", "trEven");
        }
    }
}

void CounterSettingForm::on_btnSettingClose_clicked()
{
    this->close();
}

void CounterSettingForm::on_btnSetDialog_accepted()
{
    if (SettingConfig::getInstance().MASTER != flagGroup->checkedId())
    {
        SettingConfig::getInstance().MASTER = flagGroup->checkedId();
        emit swiftDisplayLoop();
    }

    if (SettingConfig::getInstance().DISPLAY_COUNT != countGroup->checkedId())
    {
        SettingConfig::getInstance().DISPLAY_COUNT = countGroup->checkedId();
        SettingConfig::getInstance().setProperty("client", "displayCount", QString::number(countGroup->checkedId()));
        emit swiftDisplayCount();
        emit swiftDisplayLoop();
    }

    SettingConfig::getInstance().BASE_URL = ui->iptApiUrl->text();
    SettingConfig::getInstance().BASE_LOG_PATH = ui->iptLogPath->text();

    SettingConfig::getInstance().setProperty("http", "baseUrl", ui->iptApiUrl->text());
    SettingConfig::getInstance().setProperty("log", "basePath", ui->iptLogPath->text());

    this->close();
}

void CounterSettingForm::on_btnSetDialog_rejected()
{
    this->close();
}

void CounterSettingForm::on_btnSelectDir_clicked()
{
    QString selectDir = QFileDialog::getExistingDirectory(this, "选择日志保存根目录", QDir::currentPath(), QFileDialog::ShowDirsOnly);
    if (selectDir.isEmpty() == false)
    {
        ui->iptLogPath->setText(selectDir + "/");
    }
}

void CounterSettingForm::on_selectCounter_currentIndexChanged(int index)
{
    if (index == -1)
    {

    } else {
        QString deviceId = ui->selectCounter->currentData().toString();
        std::cout << deviceId.toStdString() << std::endl;
    }
}