diff --git a/CounterRealTime/CounterChannel.cpp b/CounterRealTime/CounterChannel.cpp index 54ec842..978b969 100644 --- a/CounterRealTime/CounterChannel.cpp +++ b/CounterRealTime/CounterChannel.cpp @@ -6,6 +6,10 @@ } +bool CounterChannel::isActive() +{ + return active; +} QString CounterChannel::getDeviceId() { return deviceId; @@ -26,6 +30,10 @@ { return delays; } +void CounterChannel::setActive(bool active) +{ + this->active = active; +} void CounterChannel::setDeviceId(QString deviceId) { this->deviceId = deviceId; diff --git a/CounterRealTime/CounterChannel.cpp b/CounterRealTime/CounterChannel.cpp index 54ec842..978b969 100644 --- a/CounterRealTime/CounterChannel.cpp +++ b/CounterRealTime/CounterChannel.cpp @@ -6,6 +6,10 @@ } +bool CounterChannel::isActive() +{ + return active; +} QString CounterChannel::getDeviceId() { return deviceId; @@ -26,6 +30,10 @@ { return delays; } +void CounterChannel::setActive(bool active) +{ + this->active = active; +} void CounterChannel::setDeviceId(QString deviceId) { this->deviceId = deviceId; diff --git a/CounterRealTime/CounterChannel.h b/CounterRealTime/CounterChannel.h index 2cb8317..afc5dc2 100644 --- a/CounterRealTime/CounterChannel.h +++ b/CounterRealTime/CounterChannel.h @@ -9,11 +9,13 @@ public: explicit CounterChannel(QObject *parent = nullptr); + bool isActive(); QString getDeviceId(); QString getChannelId(); QString getChannelCode(); QString getChannelNo(); QString getDelays(); + void setActive(bool active); void setDeviceId(QString deviceId); void setChannelId(QString channelId); void setChannelCode(QString channelCode); @@ -27,6 +29,7 @@ void appendHisData(QString timestampStr, QString valueStr); private: + bool active = true; QString deviceId; QString channelId; QString channelCode; diff --git a/CounterRealTime/CounterChannel.cpp b/CounterRealTime/CounterChannel.cpp index 54ec842..978b969 100644 --- a/CounterRealTime/CounterChannel.cpp +++ b/CounterRealTime/CounterChannel.cpp @@ -6,6 +6,10 @@ } +bool CounterChannel::isActive() +{ + return active; +} QString CounterChannel::getDeviceId() { return deviceId; @@ -26,6 +30,10 @@ { return delays; } +void CounterChannel::setActive(bool active) +{ + this->active = active; +} void CounterChannel::setDeviceId(QString deviceId) { this->deviceId = deviceId; diff --git a/CounterRealTime/CounterChannel.h b/CounterRealTime/CounterChannel.h index 2cb8317..afc5dc2 100644 --- a/CounterRealTime/CounterChannel.h +++ b/CounterRealTime/CounterChannel.h @@ -9,11 +9,13 @@ public: explicit CounterChannel(QObject *parent = nullptr); + bool isActive(); QString getDeviceId(); QString getChannelId(); QString getChannelCode(); QString getChannelNo(); QString getDelays(); + void setActive(bool active); void setDeviceId(QString deviceId); void setChannelId(QString channelId); void setChannelCode(QString channelCode); @@ -27,6 +29,7 @@ void appendHisData(QString timestampStr, QString valueStr); private: + bool active = true; QString deviceId; QString channelId; QString channelCode; diff --git a/CounterRealTime/CounterDevice.cpp b/CounterRealTime/CounterDevice.cpp index 3c9d626..63200bb 100644 --- a/CounterRealTime/CounterDevice.cpp +++ b/CounterRealTime/CounterDevice.cpp @@ -162,20 +162,20 @@ QLogUtil::writeChannelDataLogByDate(date, chFilename, channelDataStr); - QJsonObject jsonObj = counterData->toJSON(i - 1); - jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - jsonObj.insert("master", SettingConfig::getInstance().MASTER); - jsonObj.insert("deviceId", deviceId); - messageArray.append(jsonObj); - // append data into hisDataList CounterChannel * channelPtr = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i)); - if (channelPtr != nullptr) + if (channelPtr != nullptr && channelPtr->isActive() == true) { // 通道时延值 并计算 减去时延值的测量值 double delay = channelPtr->getDelays().isEmpty() == false ? channelPtr->getDelays().toDouble() : 0.0; double valueMinusDelay = counterData->channelDataArray.at(i-1).toDouble() - delay * 1E-9; channelPtr->appendHisData(QString::number(counterData->milisecond), QString::number(valueMinusDelay, 'f', 12)); + + QJsonObject jsonObj = counterData->toJSON(i - 1); + jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); + jsonObj.insert("master", SettingConfig::getInstance().MASTER); + jsonObj.insert("deviceId", deviceId); + messageArray.append(jsonObj); } } } @@ -192,7 +192,7 @@ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact))); } - qDebug() << counterData->rawFrame; +// qDebug() << counterData->rawFrame; qDebug() << messageArray; // 4. 在界面上简单显示相差数据结果 diff --git a/CounterRealTime/CounterChannel.cpp b/CounterRealTime/CounterChannel.cpp index 54ec842..978b969 100644 --- a/CounterRealTime/CounterChannel.cpp +++ b/CounterRealTime/CounterChannel.cpp @@ -6,6 +6,10 @@ } +bool CounterChannel::isActive() +{ + return active; +} QString CounterChannel::getDeviceId() { return deviceId; @@ -26,6 +30,10 @@ { return delays; } +void CounterChannel::setActive(bool active) +{ + this->active = active; +} void CounterChannel::setDeviceId(QString deviceId) { this->deviceId = deviceId; diff --git a/CounterRealTime/CounterChannel.h b/CounterRealTime/CounterChannel.h index 2cb8317..afc5dc2 100644 --- a/CounterRealTime/CounterChannel.h +++ b/CounterRealTime/CounterChannel.h @@ -9,11 +9,13 @@ public: explicit CounterChannel(QObject *parent = nullptr); + bool isActive(); QString getDeviceId(); QString getChannelId(); QString getChannelCode(); QString getChannelNo(); QString getDelays(); + void setActive(bool active); void setDeviceId(QString deviceId); void setChannelId(QString channelId); void setChannelCode(QString channelCode); @@ -27,6 +29,7 @@ void appendHisData(QString timestampStr, QString valueStr); private: + bool active = true; QString deviceId; QString channelId; QString channelCode; diff --git a/CounterRealTime/CounterDevice.cpp b/CounterRealTime/CounterDevice.cpp index 3c9d626..63200bb 100644 --- a/CounterRealTime/CounterDevice.cpp +++ b/CounterRealTime/CounterDevice.cpp @@ -162,20 +162,20 @@ QLogUtil::writeChannelDataLogByDate(date, chFilename, channelDataStr); - QJsonObject jsonObj = counterData->toJSON(i - 1); - jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - jsonObj.insert("master", SettingConfig::getInstance().MASTER); - jsonObj.insert("deviceId", deviceId); - messageArray.append(jsonObj); - // append data into hisDataList CounterChannel * channelPtr = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i)); - if (channelPtr != nullptr) + if (channelPtr != nullptr && channelPtr->isActive() == true) { // 通道时延值 并计算 减去时延值的测量值 double delay = channelPtr->getDelays().isEmpty() == false ? channelPtr->getDelays().toDouble() : 0.0; double valueMinusDelay = counterData->channelDataArray.at(i-1).toDouble() - delay * 1E-9; channelPtr->appendHisData(QString::number(counterData->milisecond), QString::number(valueMinusDelay, 'f', 12)); + + QJsonObject jsonObj = counterData->toJSON(i - 1); + jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); + jsonObj.insert("master", SettingConfig::getInstance().MASTER); + jsonObj.insert("deviceId", deviceId); + messageArray.append(jsonObj); } } } @@ -192,7 +192,7 @@ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact))); } - qDebug() << counterData->rawFrame; +// qDebug() << counterData->rawFrame; qDebug() << messageArray; // 4. 在界面上简单显示相差数据结果 diff --git a/CounterRealTime/CounterSettingForm.cpp b/CounterRealTime/CounterSettingForm.cpp index e74a11e..c095523 100644 --- a/CounterRealTime/CounterSettingForm.cpp +++ b/CounterRealTime/CounterSettingForm.cpp @@ -16,6 +16,9 @@ ui->btnSetDialog->button(QDialogButtonBox::Ok)->setText("确定"); ui->btnSetDialog->button(QDialogButtonBox::Cancel)->setText("取消"); + ui->btnChanelSetDialog->button(QDialogButtonBox::Ok)->setText("确定"); + ui->btnChanelSetDialog->button(QDialogButtonBox::Cancel)->setText("取消"); + flagGroup = new QButtonGroup(); flagGroup->addButton(ui->radioDispA, 1); flagGroup->addButton(ui->radioDispB, 0); @@ -27,6 +30,7 @@ this->initDefaultSettings(); this->initChannelSettingTable(); + this->clearChannelSettingValue(); } CounterSettingForm::~CounterSettingForm() @@ -84,14 +88,14 @@ headerLeftClock->setProperty("table", "header"); headerLeftDelay->setProperty("table", "header"); + headerLeftActive->setMaximumSize(100, 50); + headerLeftActive->setMinimumSize(100, 50); 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); + headerLeftClock->setMinimumSize(100, 50); + headerLeftClock->setMaximumSize(100, 50); + headerLeftDelay->setMinimumSize(160, 50); + headerLeftDelay->setMaximumSize(160, 50); headerLeftNo->setAlignment(Qt::AlignCenter); headerLeftActive->setAlignment(Qt::AlignCenter); @@ -115,14 +119,14 @@ headerRightClock->setProperty("table", "header"); headerRightDelay->setProperty("table", "header"); + headerRightActive->setMaximumSize(100, 50); + headerRightActive->setMinimumSize(100, 50); 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); + headerRightClock->setMinimumSize(100, 50); + headerRightClock->setMaximumSize(100, 50); + headerRightDelay->setMinimumSize(160, 50); + headerRightDelay->setMaximumSize(160, 50); headerRightNo->setAlignment(Qt::AlignCenter); headerRightActive->setAlignment(Qt::AlignCenter); @@ -136,6 +140,26 @@ for ( int i = 0; i < 8; i++ ) { + QCheckBox * tdLeftActive = new QCheckBox(ui->widgetChannel); + QCheckBox * tdRightActive = new QCheckBox(ui->widgetChannel); + tdLeftActive->setText("启用"); + tdLeftActive->setMinimumSize(100, 40); + tdLeftActive->setMaximumSize(100, 40); + tdRightActive->setText("启用"); + tdRightActive->setMinimumSize(100, 40); + tdRightActive->setMaximumSize(100, 40); + leftLayout->addWidget(tdLeftActive, i + 1, 0); + rightLayout->addWidget(tdRightActive, i + 1 , 0); + + tdLeftActive->setProperty("channelIndex", QString::number(i)); + tdRightActive->setProperty("channelIndex", QString::number(i + 8)); + + connect(tdLeftActive, &QCheckBox::stateChanged, this, &CounterSettingForm::onActiveStateChanged); + connect(tdRightActive, &QCheckBox::stateChanged, this, &CounterSettingForm::onActiveStateChanged); + + activeListLeft.append(tdLeftActive); + activeListRight.append(tdRightActive); + QLabel * tdLeftNo = new QLabel(ui->widgetChannel); QLabel * tdRightNo = new QLabel(ui->widgetChannel); tdLeftNo->setText(QString("CH%1").arg(i + 1)); @@ -145,47 +169,36 @@ 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); + tdLeftClock->setMinimumSize(100, 40); + tdLeftClock->setMaximumSize(100, 40); + tdRightClock->setMinimumSize(100, 40); + tdRightClock->setMaximumSize(100, 40); leftLayout->addWidget(tdLeftClock, i + 1, 2); rightLayout->addWidget(tdRightClock, i + 1 , 2); + clockListLeft.append(tdLeftClock); + clockListRight.append(tdRightClock); + 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); + tdLeftDelay->setMinimumSize(160, 40); + tdLeftDelay->setMaximumSize(160, 40); tdRightDelay->setRange(-1E9, 1E9); tdRightDelay->setSingleStep(0.001); tdRightDelay->setDecimals(3); - tdRightDelay->setMinimumSize(120, 40); - tdRightDelay->setMaximumSize(120, 40); + tdRightDelay->setMinimumSize(160, 40); + tdRightDelay->setMaximumSize(160, 40); leftLayout->addWidget(tdLeftDelay, i + 1, 3); rightLayout->addWidget(tdRightDelay, i + 1 , 3); + delayListLeft.append(tdLeftDelay); + delayListRight.append(tdRightDelay); + if (i % 2 == 0) { tdLeftNo->setProperty("table", "trOdd"); @@ -209,6 +222,28 @@ } } +void CounterSettingForm::clearChannelSettingValue() +{ + for (int i = 0; i < 8; i++) + { + activeListLeft.at(i)->setCheckable(false); + activeListLeft.at(i)->setChecked(false); + activeListLeft.at(i)->setText("未启用"); + clockListLeft.at(i)->setText("-"); + clockListLeft.at(i)->setReadOnly(true); + delayListLeft.at(i)->setValue(0.000); + delayListLeft.at(i)->setReadOnly(true); + + activeListRight.at(i)->setCheckable(false); + activeListRight.at(i)->setChecked(false); + activeListRight.at(i)->setText("未启用"); + clockListRight.at(i)->setText("-"); + clockListRight.at(i)->setReadOnly(true); + delayListRight.at(i)->setValue(0.000); + delayListRight.at(i)->setReadOnly(true); + } +} + void CounterSettingForm::on_btnSettingClose_clicked() { this->close(); @@ -244,6 +279,57 @@ this->close(); } +void CounterSettingForm::on_btnChanelSetDialog_accepted() +{ + QString deviceId = ui->selectCounter->currentData().toString(); + + for (int i = 0; i < 8; i++) + { + CounterChannel * channelPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1)); + if (channelPrt != nullptr) + { + QString channelCode = clockListLeft.at(i)->text(); // 通道钟号 + double delay = delayListLeft.at(i)->value(); // 通道时延值 + + channelPrt->setChannelCode(channelCode); + channelPrt->setDelays(QString::number(delay)); + channelPrt->setActive(activeListLeft.at(i)->isChecked()); + } else if (activeListLeft.at(i)->isChecked() == true) { + CounterChannel * newChannel = new CounterChannel(); + newChannel->setActive(true); + newChannel->setChannelCode(clockListLeft.at(i)->text()); + newChannel->setDelays(QString::number(delayListLeft.at(i)->value())); + + ConstCache::getInstance().channelMap.insert(QString("%1-%2").arg(deviceId).arg(i+1), newChannel); + } + + CounterChannel * channelRightPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1+8)); + if (channelRightPrt != nullptr) + { + QString channelCode = clockListRight.at(i)->text(); // 通道钟号 + double delay = delayListRight.at(i)->value(); // 通道时延值 + + channelRightPrt->setChannelCode(channelCode); + channelRightPrt->setDelays(QString::number(delay)); + channelRightPrt->setActive(activeListRight.at(i)->isChecked()); + } else if (activeListRight.at(i)->isChecked() == true) { + CounterChannel * newChannel = new CounterChannel(); + newChannel->setActive(true); + newChannel->setChannelCode(clockListRight.at(i)->text()); + newChannel->setDelays(QString::number(delayListRight.at(i)->value())); + + ConstCache::getInstance().channelMap.insert(QString("%1-%2").arg(deviceId).arg(i+1+8), newChannel); + } + } + + this->close(); +} + +void CounterSettingForm::on_btnChanelSetDialog_rejected() +{ + this->close(); +} + void CounterSettingForm::on_btnSelectDir_clicked() { QString selectDir = QFileDialog::getExistingDirectory(this, "选择日志保存根目录", QDir::currentPath(), QFileDialog::ShowDirsOnly); @@ -255,11 +341,85 @@ void CounterSettingForm::on_selectCounter_currentIndexChanged(int index) { - if (index == -1) + if (index == 0) { - + clearChannelSettingValue(); } else { QString deviceId = ui->selectCounter->currentData().toString(); - std::cout << deviceId.toStdString() << std::endl; + + for (int i = 0; i < 8; i++) + { + activeListLeft.at(i)->setCheckable(true); + activeListRight.at(i)->setCheckable(true); + + CounterChannel * channelPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1)); + if (channelPrt != nullptr && channelPrt->isActive() == true) + { + QString channelCode = channelPrt->getChannelCode(); // 通道钟号 + QString delays = channelPrt->getDelays(); // 通道时延值 + + activeListLeft.at(i)->setChecked(true); + activeListLeft.at(i)->setText("启用"); + clockListLeft.at(i)->setText(channelCode); + clockListLeft.at(i)->setReadOnly(false); + delayListLeft.at(i)->setValue(delays.toDouble()); + delayListLeft.at(i)->setReadOnly(false); + } else { + activeListLeft.at(i)->setChecked(false); + activeListLeft.at(i)->setText("未启用"); + clockListLeft.at(i)->setText("-"); + clockListLeft.at(i)->setReadOnly(true); + delayListLeft.at(i)->setValue(0.000); + delayListLeft.at(i)->setReadOnly(true); + } + + CounterChannel * channelRightPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1+8)); + if (channelRightPrt != nullptr && channelRightPrt->isActive() == true) + { + QString channelCode = channelRightPrt->getChannelCode(); // 通道钟号 + QString delays = channelRightPrt->getDelays(); // 通道时延值 + + activeListRight.at(i)->setChecked(true); + activeListRight.at(i)->setText("启用"); + clockListRight.at(i)->setText(channelCode); + clockListRight.at(i)->setReadOnly(false); + delayListRight.at(i)->setValue(delays.toDouble()); + delayListRight.at(i)->setReadOnly(false); + } else { + activeListRight.at(i)->setChecked(false); + activeListRight.at(i)->setText("未启用"); + clockListRight.at(i)->setText("-"); + clockListRight.at(i)->setReadOnly(true); + delayListRight.at(i)->setValue(0.000); + delayListRight.at(i)->setReadOnly(true); + } + } + } +} + +void CounterSettingForm::onActiveStateChanged() +{ + QCheckBox * obj = (QCheckBox *) sender(); + + QString channelIndex = obj->property("channelIndex").toString(); + + if (obj->isChecked() == true) { + obj->setText("启用"); + enableChannel(channelIndex.toInt(), true); + } else { + obj->setText("未启用"); + enableChannel(channelIndex.toInt(), false); + } +} + +void CounterSettingForm::enableChannel(int index, bool enable) +{ + if (index < 8) + { + clockListLeft.at(index)->setReadOnly(!enable); + delayListLeft.at(index)->setReadOnly(!enable); + } else if (index >= 8 && index < 16) { + clockListRight.at(index - 8)->setReadOnly(!enable); + delayListRight.at(index - 8)->setReadOnly(!enable); } } diff --git a/CounterRealTime/CounterChannel.cpp b/CounterRealTime/CounterChannel.cpp index 54ec842..978b969 100644 --- a/CounterRealTime/CounterChannel.cpp +++ b/CounterRealTime/CounterChannel.cpp @@ -6,6 +6,10 @@ } +bool CounterChannel::isActive() +{ + return active; +} QString CounterChannel::getDeviceId() { return deviceId; @@ -26,6 +30,10 @@ { return delays; } +void CounterChannel::setActive(bool active) +{ + this->active = active; +} void CounterChannel::setDeviceId(QString deviceId) { this->deviceId = deviceId; diff --git a/CounterRealTime/CounterChannel.h b/CounterRealTime/CounterChannel.h index 2cb8317..afc5dc2 100644 --- a/CounterRealTime/CounterChannel.h +++ b/CounterRealTime/CounterChannel.h @@ -9,11 +9,13 @@ public: explicit CounterChannel(QObject *parent = nullptr); + bool isActive(); QString getDeviceId(); QString getChannelId(); QString getChannelCode(); QString getChannelNo(); QString getDelays(); + void setActive(bool active); void setDeviceId(QString deviceId); void setChannelId(QString channelId); void setChannelCode(QString channelCode); @@ -27,6 +29,7 @@ void appendHisData(QString timestampStr, QString valueStr); private: + bool active = true; QString deviceId; QString channelId; QString channelCode; diff --git a/CounterRealTime/CounterDevice.cpp b/CounterRealTime/CounterDevice.cpp index 3c9d626..63200bb 100644 --- a/CounterRealTime/CounterDevice.cpp +++ b/CounterRealTime/CounterDevice.cpp @@ -162,20 +162,20 @@ QLogUtil::writeChannelDataLogByDate(date, chFilename, channelDataStr); - QJsonObject jsonObj = counterData->toJSON(i - 1); - jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - jsonObj.insert("master", SettingConfig::getInstance().MASTER); - jsonObj.insert("deviceId", deviceId); - messageArray.append(jsonObj); - // append data into hisDataList CounterChannel * channelPtr = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i)); - if (channelPtr != nullptr) + if (channelPtr != nullptr && channelPtr->isActive() == true) { // 通道时延值 并计算 减去时延值的测量值 double delay = channelPtr->getDelays().isEmpty() == false ? channelPtr->getDelays().toDouble() : 0.0; double valueMinusDelay = counterData->channelDataArray.at(i-1).toDouble() - delay * 1E-9; channelPtr->appendHisData(QString::number(counterData->milisecond), QString::number(valueMinusDelay, 'f', 12)); + + QJsonObject jsonObj = counterData->toJSON(i - 1); + jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); + jsonObj.insert("master", SettingConfig::getInstance().MASTER); + jsonObj.insert("deviceId", deviceId); + messageArray.append(jsonObj); } } } @@ -192,7 +192,7 @@ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact))); } - qDebug() << counterData->rawFrame; +// qDebug() << counterData->rawFrame; qDebug() << messageArray; // 4. 在界面上简单显示相差数据结果 diff --git a/CounterRealTime/CounterSettingForm.cpp b/CounterRealTime/CounterSettingForm.cpp index e74a11e..c095523 100644 --- a/CounterRealTime/CounterSettingForm.cpp +++ b/CounterRealTime/CounterSettingForm.cpp @@ -16,6 +16,9 @@ ui->btnSetDialog->button(QDialogButtonBox::Ok)->setText("确定"); ui->btnSetDialog->button(QDialogButtonBox::Cancel)->setText("取消"); + ui->btnChanelSetDialog->button(QDialogButtonBox::Ok)->setText("确定"); + ui->btnChanelSetDialog->button(QDialogButtonBox::Cancel)->setText("取消"); + flagGroup = new QButtonGroup(); flagGroup->addButton(ui->radioDispA, 1); flagGroup->addButton(ui->radioDispB, 0); @@ -27,6 +30,7 @@ this->initDefaultSettings(); this->initChannelSettingTable(); + this->clearChannelSettingValue(); } CounterSettingForm::~CounterSettingForm() @@ -84,14 +88,14 @@ headerLeftClock->setProperty("table", "header"); headerLeftDelay->setProperty("table", "header"); + headerLeftActive->setMaximumSize(100, 50); + headerLeftActive->setMinimumSize(100, 50); 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); + headerLeftClock->setMinimumSize(100, 50); + headerLeftClock->setMaximumSize(100, 50); + headerLeftDelay->setMinimumSize(160, 50); + headerLeftDelay->setMaximumSize(160, 50); headerLeftNo->setAlignment(Qt::AlignCenter); headerLeftActive->setAlignment(Qt::AlignCenter); @@ -115,14 +119,14 @@ headerRightClock->setProperty("table", "header"); headerRightDelay->setProperty("table", "header"); + headerRightActive->setMaximumSize(100, 50); + headerRightActive->setMinimumSize(100, 50); 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); + headerRightClock->setMinimumSize(100, 50); + headerRightClock->setMaximumSize(100, 50); + headerRightDelay->setMinimumSize(160, 50); + headerRightDelay->setMaximumSize(160, 50); headerRightNo->setAlignment(Qt::AlignCenter); headerRightActive->setAlignment(Qt::AlignCenter); @@ -136,6 +140,26 @@ for ( int i = 0; i < 8; i++ ) { + QCheckBox * tdLeftActive = new QCheckBox(ui->widgetChannel); + QCheckBox * tdRightActive = new QCheckBox(ui->widgetChannel); + tdLeftActive->setText("启用"); + tdLeftActive->setMinimumSize(100, 40); + tdLeftActive->setMaximumSize(100, 40); + tdRightActive->setText("启用"); + tdRightActive->setMinimumSize(100, 40); + tdRightActive->setMaximumSize(100, 40); + leftLayout->addWidget(tdLeftActive, i + 1, 0); + rightLayout->addWidget(tdRightActive, i + 1 , 0); + + tdLeftActive->setProperty("channelIndex", QString::number(i)); + tdRightActive->setProperty("channelIndex", QString::number(i + 8)); + + connect(tdLeftActive, &QCheckBox::stateChanged, this, &CounterSettingForm::onActiveStateChanged); + connect(tdRightActive, &QCheckBox::stateChanged, this, &CounterSettingForm::onActiveStateChanged); + + activeListLeft.append(tdLeftActive); + activeListRight.append(tdRightActive); + QLabel * tdLeftNo = new QLabel(ui->widgetChannel); QLabel * tdRightNo = new QLabel(ui->widgetChannel); tdLeftNo->setText(QString("CH%1").arg(i + 1)); @@ -145,47 +169,36 @@ 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); + tdLeftClock->setMinimumSize(100, 40); + tdLeftClock->setMaximumSize(100, 40); + tdRightClock->setMinimumSize(100, 40); + tdRightClock->setMaximumSize(100, 40); leftLayout->addWidget(tdLeftClock, i + 1, 2); rightLayout->addWidget(tdRightClock, i + 1 , 2); + clockListLeft.append(tdLeftClock); + clockListRight.append(tdRightClock); + 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); + tdLeftDelay->setMinimumSize(160, 40); + tdLeftDelay->setMaximumSize(160, 40); tdRightDelay->setRange(-1E9, 1E9); tdRightDelay->setSingleStep(0.001); tdRightDelay->setDecimals(3); - tdRightDelay->setMinimumSize(120, 40); - tdRightDelay->setMaximumSize(120, 40); + tdRightDelay->setMinimumSize(160, 40); + tdRightDelay->setMaximumSize(160, 40); leftLayout->addWidget(tdLeftDelay, i + 1, 3); rightLayout->addWidget(tdRightDelay, i + 1 , 3); + delayListLeft.append(tdLeftDelay); + delayListRight.append(tdRightDelay); + if (i % 2 == 0) { tdLeftNo->setProperty("table", "trOdd"); @@ -209,6 +222,28 @@ } } +void CounterSettingForm::clearChannelSettingValue() +{ + for (int i = 0; i < 8; i++) + { + activeListLeft.at(i)->setCheckable(false); + activeListLeft.at(i)->setChecked(false); + activeListLeft.at(i)->setText("未启用"); + clockListLeft.at(i)->setText("-"); + clockListLeft.at(i)->setReadOnly(true); + delayListLeft.at(i)->setValue(0.000); + delayListLeft.at(i)->setReadOnly(true); + + activeListRight.at(i)->setCheckable(false); + activeListRight.at(i)->setChecked(false); + activeListRight.at(i)->setText("未启用"); + clockListRight.at(i)->setText("-"); + clockListRight.at(i)->setReadOnly(true); + delayListRight.at(i)->setValue(0.000); + delayListRight.at(i)->setReadOnly(true); + } +} + void CounterSettingForm::on_btnSettingClose_clicked() { this->close(); @@ -244,6 +279,57 @@ this->close(); } +void CounterSettingForm::on_btnChanelSetDialog_accepted() +{ + QString deviceId = ui->selectCounter->currentData().toString(); + + for (int i = 0; i < 8; i++) + { + CounterChannel * channelPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1)); + if (channelPrt != nullptr) + { + QString channelCode = clockListLeft.at(i)->text(); // 通道钟号 + double delay = delayListLeft.at(i)->value(); // 通道时延值 + + channelPrt->setChannelCode(channelCode); + channelPrt->setDelays(QString::number(delay)); + channelPrt->setActive(activeListLeft.at(i)->isChecked()); + } else if (activeListLeft.at(i)->isChecked() == true) { + CounterChannel * newChannel = new CounterChannel(); + newChannel->setActive(true); + newChannel->setChannelCode(clockListLeft.at(i)->text()); + newChannel->setDelays(QString::number(delayListLeft.at(i)->value())); + + ConstCache::getInstance().channelMap.insert(QString("%1-%2").arg(deviceId).arg(i+1), newChannel); + } + + CounterChannel * channelRightPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1+8)); + if (channelRightPrt != nullptr) + { + QString channelCode = clockListRight.at(i)->text(); // 通道钟号 + double delay = delayListRight.at(i)->value(); // 通道时延值 + + channelRightPrt->setChannelCode(channelCode); + channelRightPrt->setDelays(QString::number(delay)); + channelRightPrt->setActive(activeListRight.at(i)->isChecked()); + } else if (activeListRight.at(i)->isChecked() == true) { + CounterChannel * newChannel = new CounterChannel(); + newChannel->setActive(true); + newChannel->setChannelCode(clockListRight.at(i)->text()); + newChannel->setDelays(QString::number(delayListRight.at(i)->value())); + + ConstCache::getInstance().channelMap.insert(QString("%1-%2").arg(deviceId).arg(i+1+8), newChannel); + } + } + + this->close(); +} + +void CounterSettingForm::on_btnChanelSetDialog_rejected() +{ + this->close(); +} + void CounterSettingForm::on_btnSelectDir_clicked() { QString selectDir = QFileDialog::getExistingDirectory(this, "选择日志保存根目录", QDir::currentPath(), QFileDialog::ShowDirsOnly); @@ -255,11 +341,85 @@ void CounterSettingForm::on_selectCounter_currentIndexChanged(int index) { - if (index == -1) + if (index == 0) { - + clearChannelSettingValue(); } else { QString deviceId = ui->selectCounter->currentData().toString(); - std::cout << deviceId.toStdString() << std::endl; + + for (int i = 0; i < 8; i++) + { + activeListLeft.at(i)->setCheckable(true); + activeListRight.at(i)->setCheckable(true); + + CounterChannel * channelPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1)); + if (channelPrt != nullptr && channelPrt->isActive() == true) + { + QString channelCode = channelPrt->getChannelCode(); // 通道钟号 + QString delays = channelPrt->getDelays(); // 通道时延值 + + activeListLeft.at(i)->setChecked(true); + activeListLeft.at(i)->setText("启用"); + clockListLeft.at(i)->setText(channelCode); + clockListLeft.at(i)->setReadOnly(false); + delayListLeft.at(i)->setValue(delays.toDouble()); + delayListLeft.at(i)->setReadOnly(false); + } else { + activeListLeft.at(i)->setChecked(false); + activeListLeft.at(i)->setText("未启用"); + clockListLeft.at(i)->setText("-"); + clockListLeft.at(i)->setReadOnly(true); + delayListLeft.at(i)->setValue(0.000); + delayListLeft.at(i)->setReadOnly(true); + } + + CounterChannel * channelRightPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1+8)); + if (channelRightPrt != nullptr && channelRightPrt->isActive() == true) + { + QString channelCode = channelRightPrt->getChannelCode(); // 通道钟号 + QString delays = channelRightPrt->getDelays(); // 通道时延值 + + activeListRight.at(i)->setChecked(true); + activeListRight.at(i)->setText("启用"); + clockListRight.at(i)->setText(channelCode); + clockListRight.at(i)->setReadOnly(false); + delayListRight.at(i)->setValue(delays.toDouble()); + delayListRight.at(i)->setReadOnly(false); + } else { + activeListRight.at(i)->setChecked(false); + activeListRight.at(i)->setText("未启用"); + clockListRight.at(i)->setText("-"); + clockListRight.at(i)->setReadOnly(true); + delayListRight.at(i)->setValue(0.000); + delayListRight.at(i)->setReadOnly(true); + } + } + } +} + +void CounterSettingForm::onActiveStateChanged() +{ + QCheckBox * obj = (QCheckBox *) sender(); + + QString channelIndex = obj->property("channelIndex").toString(); + + if (obj->isChecked() == true) { + obj->setText("启用"); + enableChannel(channelIndex.toInt(), true); + } else { + obj->setText("未启用"); + enableChannel(channelIndex.toInt(), false); + } +} + +void CounterSettingForm::enableChannel(int index, bool enable) +{ + if (index < 8) + { + clockListLeft.at(index)->setReadOnly(!enable); + delayListLeft.at(index)->setReadOnly(!enable); + } else if (index >= 8 && index < 16) { + clockListRight.at(index - 8)->setReadOnly(!enable); + delayListRight.at(index - 8)->setReadOnly(!enable); } } diff --git a/CounterRealTime/CounterSettingForm.h b/CounterRealTime/CounterSettingForm.h index 2c42cc0..b4949fb 100644 --- a/CounterRealTime/CounterSettingForm.h +++ b/CounterRealTime/CounterSettingForm.h @@ -31,6 +31,11 @@ void on_btnSelectDir_clicked(); void on_selectCounter_currentIndexChanged(int index); + void onActiveStateChanged(); + + void on_btnChanelSetDialog_accepted(); + + void on_btnChanelSetDialog_rejected(); private: Ui::CounterSettingForm *ui; @@ -38,8 +43,18 @@ QButtonGroup * flagGroup; QButtonGroup * countGroup; + QVector activeListLeft; + QVector activeListRight; + QVector clockListLeft; + QVector clockListRight; + QVector delayListLeft; + QVector delayListRight; + void initDefaultSettings(); void initChannelSettingTable(); + void clearChannelSettingValue(); + + void enableChannel(int index, bool enable); signals: void swiftDisplayLoop(); diff --git a/CounterRealTime/CounterChannel.cpp b/CounterRealTime/CounterChannel.cpp index 54ec842..978b969 100644 --- a/CounterRealTime/CounterChannel.cpp +++ b/CounterRealTime/CounterChannel.cpp @@ -6,6 +6,10 @@ } +bool CounterChannel::isActive() +{ + return active; +} QString CounterChannel::getDeviceId() { return deviceId; @@ -26,6 +30,10 @@ { return delays; } +void CounterChannel::setActive(bool active) +{ + this->active = active; +} void CounterChannel::setDeviceId(QString deviceId) { this->deviceId = deviceId; diff --git a/CounterRealTime/CounterChannel.h b/CounterRealTime/CounterChannel.h index 2cb8317..afc5dc2 100644 --- a/CounterRealTime/CounterChannel.h +++ b/CounterRealTime/CounterChannel.h @@ -9,11 +9,13 @@ public: explicit CounterChannel(QObject *parent = nullptr); + bool isActive(); QString getDeviceId(); QString getChannelId(); QString getChannelCode(); QString getChannelNo(); QString getDelays(); + void setActive(bool active); void setDeviceId(QString deviceId); void setChannelId(QString channelId); void setChannelCode(QString channelCode); @@ -27,6 +29,7 @@ void appendHisData(QString timestampStr, QString valueStr); private: + bool active = true; QString deviceId; QString channelId; QString channelCode; diff --git a/CounterRealTime/CounterDevice.cpp b/CounterRealTime/CounterDevice.cpp index 3c9d626..63200bb 100644 --- a/CounterRealTime/CounterDevice.cpp +++ b/CounterRealTime/CounterDevice.cpp @@ -162,20 +162,20 @@ QLogUtil::writeChannelDataLogByDate(date, chFilename, channelDataStr); - QJsonObject jsonObj = counterData->toJSON(i - 1); - jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - jsonObj.insert("master", SettingConfig::getInstance().MASTER); - jsonObj.insert("deviceId", deviceId); - messageArray.append(jsonObj); - // append data into hisDataList CounterChannel * channelPtr = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i)); - if (channelPtr != nullptr) + if (channelPtr != nullptr && channelPtr->isActive() == true) { // 通道时延值 并计算 减去时延值的测量值 double delay = channelPtr->getDelays().isEmpty() == false ? channelPtr->getDelays().toDouble() : 0.0; double valueMinusDelay = counterData->channelDataArray.at(i-1).toDouble() - delay * 1E-9; channelPtr->appendHisData(QString::number(counterData->milisecond), QString::number(valueMinusDelay, 'f', 12)); + + QJsonObject jsonObj = counterData->toJSON(i - 1); + jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); + jsonObj.insert("master", SettingConfig::getInstance().MASTER); + jsonObj.insert("deviceId", deviceId); + messageArray.append(jsonObj); } } } @@ -192,7 +192,7 @@ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact))); } - qDebug() << counterData->rawFrame; +// qDebug() << counterData->rawFrame; qDebug() << messageArray; // 4. 在界面上简单显示相差数据结果 diff --git a/CounterRealTime/CounterSettingForm.cpp b/CounterRealTime/CounterSettingForm.cpp index e74a11e..c095523 100644 --- a/CounterRealTime/CounterSettingForm.cpp +++ b/CounterRealTime/CounterSettingForm.cpp @@ -16,6 +16,9 @@ ui->btnSetDialog->button(QDialogButtonBox::Ok)->setText("确定"); ui->btnSetDialog->button(QDialogButtonBox::Cancel)->setText("取消"); + ui->btnChanelSetDialog->button(QDialogButtonBox::Ok)->setText("确定"); + ui->btnChanelSetDialog->button(QDialogButtonBox::Cancel)->setText("取消"); + flagGroup = new QButtonGroup(); flagGroup->addButton(ui->radioDispA, 1); flagGroup->addButton(ui->radioDispB, 0); @@ -27,6 +30,7 @@ this->initDefaultSettings(); this->initChannelSettingTable(); + this->clearChannelSettingValue(); } CounterSettingForm::~CounterSettingForm() @@ -84,14 +88,14 @@ headerLeftClock->setProperty("table", "header"); headerLeftDelay->setProperty("table", "header"); + headerLeftActive->setMaximumSize(100, 50); + headerLeftActive->setMinimumSize(100, 50); 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); + headerLeftClock->setMinimumSize(100, 50); + headerLeftClock->setMaximumSize(100, 50); + headerLeftDelay->setMinimumSize(160, 50); + headerLeftDelay->setMaximumSize(160, 50); headerLeftNo->setAlignment(Qt::AlignCenter); headerLeftActive->setAlignment(Qt::AlignCenter); @@ -115,14 +119,14 @@ headerRightClock->setProperty("table", "header"); headerRightDelay->setProperty("table", "header"); + headerRightActive->setMaximumSize(100, 50); + headerRightActive->setMinimumSize(100, 50); 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); + headerRightClock->setMinimumSize(100, 50); + headerRightClock->setMaximumSize(100, 50); + headerRightDelay->setMinimumSize(160, 50); + headerRightDelay->setMaximumSize(160, 50); headerRightNo->setAlignment(Qt::AlignCenter); headerRightActive->setAlignment(Qt::AlignCenter); @@ -136,6 +140,26 @@ for ( int i = 0; i < 8; i++ ) { + QCheckBox * tdLeftActive = new QCheckBox(ui->widgetChannel); + QCheckBox * tdRightActive = new QCheckBox(ui->widgetChannel); + tdLeftActive->setText("启用"); + tdLeftActive->setMinimumSize(100, 40); + tdLeftActive->setMaximumSize(100, 40); + tdRightActive->setText("启用"); + tdRightActive->setMinimumSize(100, 40); + tdRightActive->setMaximumSize(100, 40); + leftLayout->addWidget(tdLeftActive, i + 1, 0); + rightLayout->addWidget(tdRightActive, i + 1 , 0); + + tdLeftActive->setProperty("channelIndex", QString::number(i)); + tdRightActive->setProperty("channelIndex", QString::number(i + 8)); + + connect(tdLeftActive, &QCheckBox::stateChanged, this, &CounterSettingForm::onActiveStateChanged); + connect(tdRightActive, &QCheckBox::stateChanged, this, &CounterSettingForm::onActiveStateChanged); + + activeListLeft.append(tdLeftActive); + activeListRight.append(tdRightActive); + QLabel * tdLeftNo = new QLabel(ui->widgetChannel); QLabel * tdRightNo = new QLabel(ui->widgetChannel); tdLeftNo->setText(QString("CH%1").arg(i + 1)); @@ -145,47 +169,36 @@ 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); + tdLeftClock->setMinimumSize(100, 40); + tdLeftClock->setMaximumSize(100, 40); + tdRightClock->setMinimumSize(100, 40); + tdRightClock->setMaximumSize(100, 40); leftLayout->addWidget(tdLeftClock, i + 1, 2); rightLayout->addWidget(tdRightClock, i + 1 , 2); + clockListLeft.append(tdLeftClock); + clockListRight.append(tdRightClock); + 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); + tdLeftDelay->setMinimumSize(160, 40); + tdLeftDelay->setMaximumSize(160, 40); tdRightDelay->setRange(-1E9, 1E9); tdRightDelay->setSingleStep(0.001); tdRightDelay->setDecimals(3); - tdRightDelay->setMinimumSize(120, 40); - tdRightDelay->setMaximumSize(120, 40); + tdRightDelay->setMinimumSize(160, 40); + tdRightDelay->setMaximumSize(160, 40); leftLayout->addWidget(tdLeftDelay, i + 1, 3); rightLayout->addWidget(tdRightDelay, i + 1 , 3); + delayListLeft.append(tdLeftDelay); + delayListRight.append(tdRightDelay); + if (i % 2 == 0) { tdLeftNo->setProperty("table", "trOdd"); @@ -209,6 +222,28 @@ } } +void CounterSettingForm::clearChannelSettingValue() +{ + for (int i = 0; i < 8; i++) + { + activeListLeft.at(i)->setCheckable(false); + activeListLeft.at(i)->setChecked(false); + activeListLeft.at(i)->setText("未启用"); + clockListLeft.at(i)->setText("-"); + clockListLeft.at(i)->setReadOnly(true); + delayListLeft.at(i)->setValue(0.000); + delayListLeft.at(i)->setReadOnly(true); + + activeListRight.at(i)->setCheckable(false); + activeListRight.at(i)->setChecked(false); + activeListRight.at(i)->setText("未启用"); + clockListRight.at(i)->setText("-"); + clockListRight.at(i)->setReadOnly(true); + delayListRight.at(i)->setValue(0.000); + delayListRight.at(i)->setReadOnly(true); + } +} + void CounterSettingForm::on_btnSettingClose_clicked() { this->close(); @@ -244,6 +279,57 @@ this->close(); } +void CounterSettingForm::on_btnChanelSetDialog_accepted() +{ + QString deviceId = ui->selectCounter->currentData().toString(); + + for (int i = 0; i < 8; i++) + { + CounterChannel * channelPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1)); + if (channelPrt != nullptr) + { + QString channelCode = clockListLeft.at(i)->text(); // 通道钟号 + double delay = delayListLeft.at(i)->value(); // 通道时延值 + + channelPrt->setChannelCode(channelCode); + channelPrt->setDelays(QString::number(delay)); + channelPrt->setActive(activeListLeft.at(i)->isChecked()); + } else if (activeListLeft.at(i)->isChecked() == true) { + CounterChannel * newChannel = new CounterChannel(); + newChannel->setActive(true); + newChannel->setChannelCode(clockListLeft.at(i)->text()); + newChannel->setDelays(QString::number(delayListLeft.at(i)->value())); + + ConstCache::getInstance().channelMap.insert(QString("%1-%2").arg(deviceId).arg(i+1), newChannel); + } + + CounterChannel * channelRightPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1+8)); + if (channelRightPrt != nullptr) + { + QString channelCode = clockListRight.at(i)->text(); // 通道钟号 + double delay = delayListRight.at(i)->value(); // 通道时延值 + + channelRightPrt->setChannelCode(channelCode); + channelRightPrt->setDelays(QString::number(delay)); + channelRightPrt->setActive(activeListRight.at(i)->isChecked()); + } else if (activeListRight.at(i)->isChecked() == true) { + CounterChannel * newChannel = new CounterChannel(); + newChannel->setActive(true); + newChannel->setChannelCode(clockListRight.at(i)->text()); + newChannel->setDelays(QString::number(delayListRight.at(i)->value())); + + ConstCache::getInstance().channelMap.insert(QString("%1-%2").arg(deviceId).arg(i+1+8), newChannel); + } + } + + this->close(); +} + +void CounterSettingForm::on_btnChanelSetDialog_rejected() +{ + this->close(); +} + void CounterSettingForm::on_btnSelectDir_clicked() { QString selectDir = QFileDialog::getExistingDirectory(this, "选择日志保存根目录", QDir::currentPath(), QFileDialog::ShowDirsOnly); @@ -255,11 +341,85 @@ void CounterSettingForm::on_selectCounter_currentIndexChanged(int index) { - if (index == -1) + if (index == 0) { - + clearChannelSettingValue(); } else { QString deviceId = ui->selectCounter->currentData().toString(); - std::cout << deviceId.toStdString() << std::endl; + + for (int i = 0; i < 8; i++) + { + activeListLeft.at(i)->setCheckable(true); + activeListRight.at(i)->setCheckable(true); + + CounterChannel * channelPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1)); + if (channelPrt != nullptr && channelPrt->isActive() == true) + { + QString channelCode = channelPrt->getChannelCode(); // 通道钟号 + QString delays = channelPrt->getDelays(); // 通道时延值 + + activeListLeft.at(i)->setChecked(true); + activeListLeft.at(i)->setText("启用"); + clockListLeft.at(i)->setText(channelCode); + clockListLeft.at(i)->setReadOnly(false); + delayListLeft.at(i)->setValue(delays.toDouble()); + delayListLeft.at(i)->setReadOnly(false); + } else { + activeListLeft.at(i)->setChecked(false); + activeListLeft.at(i)->setText("未启用"); + clockListLeft.at(i)->setText("-"); + clockListLeft.at(i)->setReadOnly(true); + delayListLeft.at(i)->setValue(0.000); + delayListLeft.at(i)->setReadOnly(true); + } + + CounterChannel * channelRightPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1+8)); + if (channelRightPrt != nullptr && channelRightPrt->isActive() == true) + { + QString channelCode = channelRightPrt->getChannelCode(); // 通道钟号 + QString delays = channelRightPrt->getDelays(); // 通道时延值 + + activeListRight.at(i)->setChecked(true); + activeListRight.at(i)->setText("启用"); + clockListRight.at(i)->setText(channelCode); + clockListRight.at(i)->setReadOnly(false); + delayListRight.at(i)->setValue(delays.toDouble()); + delayListRight.at(i)->setReadOnly(false); + } else { + activeListRight.at(i)->setChecked(false); + activeListRight.at(i)->setText("未启用"); + clockListRight.at(i)->setText("-"); + clockListRight.at(i)->setReadOnly(true); + delayListRight.at(i)->setValue(0.000); + delayListRight.at(i)->setReadOnly(true); + } + } + } +} + +void CounterSettingForm::onActiveStateChanged() +{ + QCheckBox * obj = (QCheckBox *) sender(); + + QString channelIndex = obj->property("channelIndex").toString(); + + if (obj->isChecked() == true) { + obj->setText("启用"); + enableChannel(channelIndex.toInt(), true); + } else { + obj->setText("未启用"); + enableChannel(channelIndex.toInt(), false); + } +} + +void CounterSettingForm::enableChannel(int index, bool enable) +{ + if (index < 8) + { + clockListLeft.at(index)->setReadOnly(!enable); + delayListLeft.at(index)->setReadOnly(!enable); + } else if (index >= 8 && index < 16) { + clockListRight.at(index - 8)->setReadOnly(!enable); + delayListRight.at(index - 8)->setReadOnly(!enable); } } diff --git a/CounterRealTime/CounterSettingForm.h b/CounterRealTime/CounterSettingForm.h index 2c42cc0..b4949fb 100644 --- a/CounterRealTime/CounterSettingForm.h +++ b/CounterRealTime/CounterSettingForm.h @@ -31,6 +31,11 @@ void on_btnSelectDir_clicked(); void on_selectCounter_currentIndexChanged(int index); + void onActiveStateChanged(); + + void on_btnChanelSetDialog_accepted(); + + void on_btnChanelSetDialog_rejected(); private: Ui::CounterSettingForm *ui; @@ -38,8 +43,18 @@ QButtonGroup * flagGroup; QButtonGroup * countGroup; + QVector activeListLeft; + QVector activeListRight; + QVector clockListLeft; + QVector clockListRight; + QVector delayListLeft; + QVector delayListRight; + void initDefaultSettings(); void initChannelSettingTable(); + void clearChannelSettingValue(); + + void enableChannel(int index, bool enable); signals: void swiftDisplayLoop(); diff --git a/CounterRealTime/CounterSettingForm.ui b/CounterRealTime/CounterSettingForm.ui index 740ce4e..6c7fffc 100644 --- a/CounterRealTime/CounterSettingForm.ui +++ b/CounterRealTime/CounterSettingForm.ui @@ -95,7 +95,7 @@ - 1 + 0 @@ -326,6 +326,9 @@ 40 + + true + @@ -346,6 +349,31 @@ 重新选择 + + + + 0 + 480 + 960 + 64 + + + + + 0 + 64 + + + + + 16777215 + 64 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + @@ -402,28 +430,34 @@ + + + + 0 + 480 + 960 + 64 + + + + + 0 + 64 + + + + + 16777215 + 64 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + - - - - - 0 - 64 - - - - - 16777215 - 64 - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - diff --git a/CounterRealTime/CounterChannel.cpp b/CounterRealTime/CounterChannel.cpp index 54ec842..978b969 100644 --- a/CounterRealTime/CounterChannel.cpp +++ b/CounterRealTime/CounterChannel.cpp @@ -6,6 +6,10 @@ } +bool CounterChannel::isActive() +{ + return active; +} QString CounterChannel::getDeviceId() { return deviceId; @@ -26,6 +30,10 @@ { return delays; } +void CounterChannel::setActive(bool active) +{ + this->active = active; +} void CounterChannel::setDeviceId(QString deviceId) { this->deviceId = deviceId; diff --git a/CounterRealTime/CounterChannel.h b/CounterRealTime/CounterChannel.h index 2cb8317..afc5dc2 100644 --- a/CounterRealTime/CounterChannel.h +++ b/CounterRealTime/CounterChannel.h @@ -9,11 +9,13 @@ public: explicit CounterChannel(QObject *parent = nullptr); + bool isActive(); QString getDeviceId(); QString getChannelId(); QString getChannelCode(); QString getChannelNo(); QString getDelays(); + void setActive(bool active); void setDeviceId(QString deviceId); void setChannelId(QString channelId); void setChannelCode(QString channelCode); @@ -27,6 +29,7 @@ void appendHisData(QString timestampStr, QString valueStr); private: + bool active = true; QString deviceId; QString channelId; QString channelCode; diff --git a/CounterRealTime/CounterDevice.cpp b/CounterRealTime/CounterDevice.cpp index 3c9d626..63200bb 100644 --- a/CounterRealTime/CounterDevice.cpp +++ b/CounterRealTime/CounterDevice.cpp @@ -162,20 +162,20 @@ QLogUtil::writeChannelDataLogByDate(date, chFilename, channelDataStr); - QJsonObject jsonObj = counterData->toJSON(i - 1); - jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - jsonObj.insert("master", SettingConfig::getInstance().MASTER); - jsonObj.insert("deviceId", deviceId); - messageArray.append(jsonObj); - // append data into hisDataList CounterChannel * channelPtr = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i)); - if (channelPtr != nullptr) + if (channelPtr != nullptr && channelPtr->isActive() == true) { // 通道时延值 并计算 减去时延值的测量值 double delay = channelPtr->getDelays().isEmpty() == false ? channelPtr->getDelays().toDouble() : 0.0; double valueMinusDelay = counterData->channelDataArray.at(i-1).toDouble() - delay * 1E-9; channelPtr->appendHisData(QString::number(counterData->milisecond), QString::number(valueMinusDelay, 'f', 12)); + + QJsonObject jsonObj = counterData->toJSON(i - 1); + jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); + jsonObj.insert("master", SettingConfig::getInstance().MASTER); + jsonObj.insert("deviceId", deviceId); + messageArray.append(jsonObj); } } } @@ -192,7 +192,7 @@ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact))); } - qDebug() << counterData->rawFrame; +// qDebug() << counterData->rawFrame; qDebug() << messageArray; // 4. 在界面上简单显示相差数据结果 diff --git a/CounterRealTime/CounterSettingForm.cpp b/CounterRealTime/CounterSettingForm.cpp index e74a11e..c095523 100644 --- a/CounterRealTime/CounterSettingForm.cpp +++ b/CounterRealTime/CounterSettingForm.cpp @@ -16,6 +16,9 @@ ui->btnSetDialog->button(QDialogButtonBox::Ok)->setText("确定"); ui->btnSetDialog->button(QDialogButtonBox::Cancel)->setText("取消"); + ui->btnChanelSetDialog->button(QDialogButtonBox::Ok)->setText("确定"); + ui->btnChanelSetDialog->button(QDialogButtonBox::Cancel)->setText("取消"); + flagGroup = new QButtonGroup(); flagGroup->addButton(ui->radioDispA, 1); flagGroup->addButton(ui->radioDispB, 0); @@ -27,6 +30,7 @@ this->initDefaultSettings(); this->initChannelSettingTable(); + this->clearChannelSettingValue(); } CounterSettingForm::~CounterSettingForm() @@ -84,14 +88,14 @@ headerLeftClock->setProperty("table", "header"); headerLeftDelay->setProperty("table", "header"); + headerLeftActive->setMaximumSize(100, 50); + headerLeftActive->setMinimumSize(100, 50); 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); + headerLeftClock->setMinimumSize(100, 50); + headerLeftClock->setMaximumSize(100, 50); + headerLeftDelay->setMinimumSize(160, 50); + headerLeftDelay->setMaximumSize(160, 50); headerLeftNo->setAlignment(Qt::AlignCenter); headerLeftActive->setAlignment(Qt::AlignCenter); @@ -115,14 +119,14 @@ headerRightClock->setProperty("table", "header"); headerRightDelay->setProperty("table", "header"); + headerRightActive->setMaximumSize(100, 50); + headerRightActive->setMinimumSize(100, 50); 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); + headerRightClock->setMinimumSize(100, 50); + headerRightClock->setMaximumSize(100, 50); + headerRightDelay->setMinimumSize(160, 50); + headerRightDelay->setMaximumSize(160, 50); headerRightNo->setAlignment(Qt::AlignCenter); headerRightActive->setAlignment(Qt::AlignCenter); @@ -136,6 +140,26 @@ for ( int i = 0; i < 8; i++ ) { + QCheckBox * tdLeftActive = new QCheckBox(ui->widgetChannel); + QCheckBox * tdRightActive = new QCheckBox(ui->widgetChannel); + tdLeftActive->setText("启用"); + tdLeftActive->setMinimumSize(100, 40); + tdLeftActive->setMaximumSize(100, 40); + tdRightActive->setText("启用"); + tdRightActive->setMinimumSize(100, 40); + tdRightActive->setMaximumSize(100, 40); + leftLayout->addWidget(tdLeftActive, i + 1, 0); + rightLayout->addWidget(tdRightActive, i + 1 , 0); + + tdLeftActive->setProperty("channelIndex", QString::number(i)); + tdRightActive->setProperty("channelIndex", QString::number(i + 8)); + + connect(tdLeftActive, &QCheckBox::stateChanged, this, &CounterSettingForm::onActiveStateChanged); + connect(tdRightActive, &QCheckBox::stateChanged, this, &CounterSettingForm::onActiveStateChanged); + + activeListLeft.append(tdLeftActive); + activeListRight.append(tdRightActive); + QLabel * tdLeftNo = new QLabel(ui->widgetChannel); QLabel * tdRightNo = new QLabel(ui->widgetChannel); tdLeftNo->setText(QString("CH%1").arg(i + 1)); @@ -145,47 +169,36 @@ 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); + tdLeftClock->setMinimumSize(100, 40); + tdLeftClock->setMaximumSize(100, 40); + tdRightClock->setMinimumSize(100, 40); + tdRightClock->setMaximumSize(100, 40); leftLayout->addWidget(tdLeftClock, i + 1, 2); rightLayout->addWidget(tdRightClock, i + 1 , 2); + clockListLeft.append(tdLeftClock); + clockListRight.append(tdRightClock); + 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); + tdLeftDelay->setMinimumSize(160, 40); + tdLeftDelay->setMaximumSize(160, 40); tdRightDelay->setRange(-1E9, 1E9); tdRightDelay->setSingleStep(0.001); tdRightDelay->setDecimals(3); - tdRightDelay->setMinimumSize(120, 40); - tdRightDelay->setMaximumSize(120, 40); + tdRightDelay->setMinimumSize(160, 40); + tdRightDelay->setMaximumSize(160, 40); leftLayout->addWidget(tdLeftDelay, i + 1, 3); rightLayout->addWidget(tdRightDelay, i + 1 , 3); + delayListLeft.append(tdLeftDelay); + delayListRight.append(tdRightDelay); + if (i % 2 == 0) { tdLeftNo->setProperty("table", "trOdd"); @@ -209,6 +222,28 @@ } } +void CounterSettingForm::clearChannelSettingValue() +{ + for (int i = 0; i < 8; i++) + { + activeListLeft.at(i)->setCheckable(false); + activeListLeft.at(i)->setChecked(false); + activeListLeft.at(i)->setText("未启用"); + clockListLeft.at(i)->setText("-"); + clockListLeft.at(i)->setReadOnly(true); + delayListLeft.at(i)->setValue(0.000); + delayListLeft.at(i)->setReadOnly(true); + + activeListRight.at(i)->setCheckable(false); + activeListRight.at(i)->setChecked(false); + activeListRight.at(i)->setText("未启用"); + clockListRight.at(i)->setText("-"); + clockListRight.at(i)->setReadOnly(true); + delayListRight.at(i)->setValue(0.000); + delayListRight.at(i)->setReadOnly(true); + } +} + void CounterSettingForm::on_btnSettingClose_clicked() { this->close(); @@ -244,6 +279,57 @@ this->close(); } +void CounterSettingForm::on_btnChanelSetDialog_accepted() +{ + QString deviceId = ui->selectCounter->currentData().toString(); + + for (int i = 0; i < 8; i++) + { + CounterChannel * channelPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1)); + if (channelPrt != nullptr) + { + QString channelCode = clockListLeft.at(i)->text(); // 通道钟号 + double delay = delayListLeft.at(i)->value(); // 通道时延值 + + channelPrt->setChannelCode(channelCode); + channelPrt->setDelays(QString::number(delay)); + channelPrt->setActive(activeListLeft.at(i)->isChecked()); + } else if (activeListLeft.at(i)->isChecked() == true) { + CounterChannel * newChannel = new CounterChannel(); + newChannel->setActive(true); + newChannel->setChannelCode(clockListLeft.at(i)->text()); + newChannel->setDelays(QString::number(delayListLeft.at(i)->value())); + + ConstCache::getInstance().channelMap.insert(QString("%1-%2").arg(deviceId).arg(i+1), newChannel); + } + + CounterChannel * channelRightPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1+8)); + if (channelRightPrt != nullptr) + { + QString channelCode = clockListRight.at(i)->text(); // 通道钟号 + double delay = delayListRight.at(i)->value(); // 通道时延值 + + channelRightPrt->setChannelCode(channelCode); + channelRightPrt->setDelays(QString::number(delay)); + channelRightPrt->setActive(activeListRight.at(i)->isChecked()); + } else if (activeListRight.at(i)->isChecked() == true) { + CounterChannel * newChannel = new CounterChannel(); + newChannel->setActive(true); + newChannel->setChannelCode(clockListRight.at(i)->text()); + newChannel->setDelays(QString::number(delayListRight.at(i)->value())); + + ConstCache::getInstance().channelMap.insert(QString("%1-%2").arg(deviceId).arg(i+1+8), newChannel); + } + } + + this->close(); +} + +void CounterSettingForm::on_btnChanelSetDialog_rejected() +{ + this->close(); +} + void CounterSettingForm::on_btnSelectDir_clicked() { QString selectDir = QFileDialog::getExistingDirectory(this, "选择日志保存根目录", QDir::currentPath(), QFileDialog::ShowDirsOnly); @@ -255,11 +341,85 @@ void CounterSettingForm::on_selectCounter_currentIndexChanged(int index) { - if (index == -1) + if (index == 0) { - + clearChannelSettingValue(); } else { QString deviceId = ui->selectCounter->currentData().toString(); - std::cout << deviceId.toStdString() << std::endl; + + for (int i = 0; i < 8; i++) + { + activeListLeft.at(i)->setCheckable(true); + activeListRight.at(i)->setCheckable(true); + + CounterChannel * channelPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1)); + if (channelPrt != nullptr && channelPrt->isActive() == true) + { + QString channelCode = channelPrt->getChannelCode(); // 通道钟号 + QString delays = channelPrt->getDelays(); // 通道时延值 + + activeListLeft.at(i)->setChecked(true); + activeListLeft.at(i)->setText("启用"); + clockListLeft.at(i)->setText(channelCode); + clockListLeft.at(i)->setReadOnly(false); + delayListLeft.at(i)->setValue(delays.toDouble()); + delayListLeft.at(i)->setReadOnly(false); + } else { + activeListLeft.at(i)->setChecked(false); + activeListLeft.at(i)->setText("未启用"); + clockListLeft.at(i)->setText("-"); + clockListLeft.at(i)->setReadOnly(true); + delayListLeft.at(i)->setValue(0.000); + delayListLeft.at(i)->setReadOnly(true); + } + + CounterChannel * channelRightPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1+8)); + if (channelRightPrt != nullptr && channelRightPrt->isActive() == true) + { + QString channelCode = channelRightPrt->getChannelCode(); // 通道钟号 + QString delays = channelRightPrt->getDelays(); // 通道时延值 + + activeListRight.at(i)->setChecked(true); + activeListRight.at(i)->setText("启用"); + clockListRight.at(i)->setText(channelCode); + clockListRight.at(i)->setReadOnly(false); + delayListRight.at(i)->setValue(delays.toDouble()); + delayListRight.at(i)->setReadOnly(false); + } else { + activeListRight.at(i)->setChecked(false); + activeListRight.at(i)->setText("未启用"); + clockListRight.at(i)->setText("-"); + clockListRight.at(i)->setReadOnly(true); + delayListRight.at(i)->setValue(0.000); + delayListRight.at(i)->setReadOnly(true); + } + } + } +} + +void CounterSettingForm::onActiveStateChanged() +{ + QCheckBox * obj = (QCheckBox *) sender(); + + QString channelIndex = obj->property("channelIndex").toString(); + + if (obj->isChecked() == true) { + obj->setText("启用"); + enableChannel(channelIndex.toInt(), true); + } else { + obj->setText("未启用"); + enableChannel(channelIndex.toInt(), false); + } +} + +void CounterSettingForm::enableChannel(int index, bool enable) +{ + if (index < 8) + { + clockListLeft.at(index)->setReadOnly(!enable); + delayListLeft.at(index)->setReadOnly(!enable); + } else if (index >= 8 && index < 16) { + clockListRight.at(index - 8)->setReadOnly(!enable); + delayListRight.at(index - 8)->setReadOnly(!enable); } } diff --git a/CounterRealTime/CounterSettingForm.h b/CounterRealTime/CounterSettingForm.h index 2c42cc0..b4949fb 100644 --- a/CounterRealTime/CounterSettingForm.h +++ b/CounterRealTime/CounterSettingForm.h @@ -31,6 +31,11 @@ void on_btnSelectDir_clicked(); void on_selectCounter_currentIndexChanged(int index); + void onActiveStateChanged(); + + void on_btnChanelSetDialog_accepted(); + + void on_btnChanelSetDialog_rejected(); private: Ui::CounterSettingForm *ui; @@ -38,8 +43,18 @@ QButtonGroup * flagGroup; QButtonGroup * countGroup; + QVector activeListLeft; + QVector activeListRight; + QVector clockListLeft; + QVector clockListRight; + QVector delayListLeft; + QVector delayListRight; + void initDefaultSettings(); void initChannelSettingTable(); + void clearChannelSettingValue(); + + void enableChannel(int index, bool enable); signals: void swiftDisplayLoop(); diff --git a/CounterRealTime/CounterSettingForm.ui b/CounterRealTime/CounterSettingForm.ui index 740ce4e..6c7fffc 100644 --- a/CounterRealTime/CounterSettingForm.ui +++ b/CounterRealTime/CounterSettingForm.ui @@ -95,7 +95,7 @@ - 1 + 0 @@ -326,6 +326,9 @@ 40 + + true + @@ -346,6 +349,31 @@ 重新选择 + + + + 0 + 480 + 960 + 64 + + + + + 0 + 64 + + + + + 16777215 + 64 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + @@ -402,28 +430,34 @@ + + + + 0 + 480 + 960 + 64 + + + + + 0 + 64 + + + + + 16777215 + 64 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + - - - - - 0 - 64 - - - - - 16777215 - 64 - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - diff --git a/CounterRealTime/CounterWindowRT.cpp b/CounterRealTime/CounterWindowRT.cpp index 1304727..55db2ed 100644 --- a/CounterRealTime/CounterWindowRT.cpp +++ b/CounterRealTime/CounterWindowRT.cpp @@ -47,7 +47,7 @@ // 初始化设备和通道 getDeviceList(); - QThread::msleep(1000 * 3); +// QThread::msleep(1000 * 3); for (int i = 0; i < ConstCache::getInstance().deviceIdLoopA.size(); i++) { CounterDevice * devicePtr = ConstCache::getInstance().deviceMap.value(ConstCache::getInstance().deviceIdLoopA.at(i)); @@ -224,13 +224,13 @@ QLabel * labChannelValue = new QLabel(widgetDev); // 通道测量值 // 默认显示内容 - labChannelName->setText(QString("CH%1").arg(i+1)); + labChannelName->setText(QString("CH%1").arg(i+1, 2, 10, QLatin1Char('0'))); labChannelValue->setText("0.000000000000"); // css不支持的样式用代码实现 labChannelName->setMargin(10); labChannelValue->setMargin(10); - labChannelValue->setAlignment(Qt::AlignCenter); + labChannelValue->setAlignment(Qt::AlignRight | Qt::AlignVCenter); // 奇偶显示不同的背景色 if (i % 2 == 0) @@ -278,7 +278,7 @@ if (devIdx < devRefList.size()) { // 参考通道的显示 QString refText = devRefList.at(devIdx)->text(); - channelNameList.at(devIdx * 16 + refChNo - 1)->setText(QString("CH%1:%2").arg(refChNo).arg(refText.right(refText.length() - 4))); + channelNameList.at(devIdx * 16 + refChNo - 1)->setText(QString("CH%1:%2").arg(refChNo, 2, 10, QLatin1Char('0')).arg(refText.right(refText.length() - 4))); } QMap channelDataJsonMap; @@ -293,6 +293,7 @@ for (int i = 0; i < 16; i++) { QString channelNo = QString::number(i + 1); + QString channelNoStr = QString("%1").arg(i + 1, 2, 10, QLatin1Char('0')); if (i + 1 == refChNo) { @@ -307,23 +308,26 @@ // 通道Label的序号 int chanelIdx = devIdx * 16 + channelDataItem.find("channelNo")->toInt() - 1; - if (channel != nullptr) + if (channel != nullptr && channel->isActive() == true) { // 通道时延值 并计算 减去时延值的测量值 double delay = channel->getDelays().isEmpty() == false ? channel->getDelays().toDouble() : 0.0; double valueMinusDelay = channelDataItem.find("data")->toObject().find("dataValue")->toString().toDouble() - delay * 1E-9; // 设置通道名和测量值的QLabel - channelNameList.at(chanelIdx)->setText(QString("CH%1:%2").arg(channelNo).arg(channel->getChannelCode())); + channelNameList.at(chanelIdx)->setText(QString("CH%1:%2").arg(channelNoStr).arg(channel->getChannelCode())); channelValueList.at(chanelIdx)->setText(QString::number(valueMinusDelay, 'f', 12)); channelNameList.at(chanelIdx)->setProperty("channelId", channel->getChannelId()); channelNameList.at(chanelIdx)->setProperty("deviceId", deviceId); channelNameList.at(chanelIdx)->setProperty("channelNo", channelNo); + } else { + channelNameList.at(chanelIdx)->setText(QString("CH%1:%2").arg(channelNoStr).arg("-")); + channelValueList.at(chanelIdx)->setText(""); } } else { // 没有测量值的通道清空 - channelNameList.at(devIdx * 16 + i)->setText(QString("CH%1:%2").arg(i + 1).arg("-")); + channelNameList.at(devIdx * 16 + i)->setText(QString("CH%1:%2").arg(channelNoStr).arg("-")); channelValueList.at(devIdx * 16 + i)->setText(""); } } @@ -354,7 +358,7 @@ CounterDevice * device = new CounterDevice(this); device->setDeviceId(deviceId); device->setComName(devItem.find("linkComName")->toString()); - device->setBaudRate(115200); + device->setBaudRate(SettingConfig::getInstance().BAUD_RATE); device->setDevCode(devItem.find("deviceNo")->toString()); device->setDeviceName(devName); device->setIsUse(isUse.toInt()); @@ -401,6 +405,7 @@ channel->setChannelId(channelId); channel->setChannelCode(channelCode); channel->setChannelNo(channelNo); + channel->setDelays(delays); // 添加到通道的集合中 key=deviceId-channelNo ConstCache::getInstance().channelMap.insert(deviceId + "-" + channelNo, channel); diff --git a/CounterRealTime/CounterChannel.cpp b/CounterRealTime/CounterChannel.cpp index 54ec842..978b969 100644 --- a/CounterRealTime/CounterChannel.cpp +++ b/CounterRealTime/CounterChannel.cpp @@ -6,6 +6,10 @@ } +bool CounterChannel::isActive() +{ + return active; +} QString CounterChannel::getDeviceId() { return deviceId; @@ -26,6 +30,10 @@ { return delays; } +void CounterChannel::setActive(bool active) +{ + this->active = active; +} void CounterChannel::setDeviceId(QString deviceId) { this->deviceId = deviceId; diff --git a/CounterRealTime/CounterChannel.h b/CounterRealTime/CounterChannel.h index 2cb8317..afc5dc2 100644 --- a/CounterRealTime/CounterChannel.h +++ b/CounterRealTime/CounterChannel.h @@ -9,11 +9,13 @@ public: explicit CounterChannel(QObject *parent = nullptr); + bool isActive(); QString getDeviceId(); QString getChannelId(); QString getChannelCode(); QString getChannelNo(); QString getDelays(); + void setActive(bool active); void setDeviceId(QString deviceId); void setChannelId(QString channelId); void setChannelCode(QString channelCode); @@ -27,6 +29,7 @@ void appendHisData(QString timestampStr, QString valueStr); private: + bool active = true; QString deviceId; QString channelId; QString channelCode; diff --git a/CounterRealTime/CounterDevice.cpp b/CounterRealTime/CounterDevice.cpp index 3c9d626..63200bb 100644 --- a/CounterRealTime/CounterDevice.cpp +++ b/CounterRealTime/CounterDevice.cpp @@ -162,20 +162,20 @@ QLogUtil::writeChannelDataLogByDate(date, chFilename, channelDataStr); - QJsonObject jsonObj = counterData->toJSON(i - 1); - jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - jsonObj.insert("master", SettingConfig::getInstance().MASTER); - jsonObj.insert("deviceId", deviceId); - messageArray.append(jsonObj); - // append data into hisDataList CounterChannel * channelPtr = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i)); - if (channelPtr != nullptr) + if (channelPtr != nullptr && channelPtr->isActive() == true) { // 通道时延值 并计算 减去时延值的测量值 double delay = channelPtr->getDelays().isEmpty() == false ? channelPtr->getDelays().toDouble() : 0.0; double valueMinusDelay = counterData->channelDataArray.at(i-1).toDouble() - delay * 1E-9; channelPtr->appendHisData(QString::number(counterData->milisecond), QString::number(valueMinusDelay, 'f', 12)); + + QJsonObject jsonObj = counterData->toJSON(i - 1); + jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); + jsonObj.insert("master", SettingConfig::getInstance().MASTER); + jsonObj.insert("deviceId", deviceId); + messageArray.append(jsonObj); } } } @@ -192,7 +192,7 @@ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact))); } - qDebug() << counterData->rawFrame; +// qDebug() << counterData->rawFrame; qDebug() << messageArray; // 4. 在界面上简单显示相差数据结果 diff --git a/CounterRealTime/CounterSettingForm.cpp b/CounterRealTime/CounterSettingForm.cpp index e74a11e..c095523 100644 --- a/CounterRealTime/CounterSettingForm.cpp +++ b/CounterRealTime/CounterSettingForm.cpp @@ -16,6 +16,9 @@ ui->btnSetDialog->button(QDialogButtonBox::Ok)->setText("确定"); ui->btnSetDialog->button(QDialogButtonBox::Cancel)->setText("取消"); + ui->btnChanelSetDialog->button(QDialogButtonBox::Ok)->setText("确定"); + ui->btnChanelSetDialog->button(QDialogButtonBox::Cancel)->setText("取消"); + flagGroup = new QButtonGroup(); flagGroup->addButton(ui->radioDispA, 1); flagGroup->addButton(ui->radioDispB, 0); @@ -27,6 +30,7 @@ this->initDefaultSettings(); this->initChannelSettingTable(); + this->clearChannelSettingValue(); } CounterSettingForm::~CounterSettingForm() @@ -84,14 +88,14 @@ headerLeftClock->setProperty("table", "header"); headerLeftDelay->setProperty("table", "header"); + headerLeftActive->setMaximumSize(100, 50); + headerLeftActive->setMinimumSize(100, 50); 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); + headerLeftClock->setMinimumSize(100, 50); + headerLeftClock->setMaximumSize(100, 50); + headerLeftDelay->setMinimumSize(160, 50); + headerLeftDelay->setMaximumSize(160, 50); headerLeftNo->setAlignment(Qt::AlignCenter); headerLeftActive->setAlignment(Qt::AlignCenter); @@ -115,14 +119,14 @@ headerRightClock->setProperty("table", "header"); headerRightDelay->setProperty("table", "header"); + headerRightActive->setMaximumSize(100, 50); + headerRightActive->setMinimumSize(100, 50); 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); + headerRightClock->setMinimumSize(100, 50); + headerRightClock->setMaximumSize(100, 50); + headerRightDelay->setMinimumSize(160, 50); + headerRightDelay->setMaximumSize(160, 50); headerRightNo->setAlignment(Qt::AlignCenter); headerRightActive->setAlignment(Qt::AlignCenter); @@ -136,6 +140,26 @@ for ( int i = 0; i < 8; i++ ) { + QCheckBox * tdLeftActive = new QCheckBox(ui->widgetChannel); + QCheckBox * tdRightActive = new QCheckBox(ui->widgetChannel); + tdLeftActive->setText("启用"); + tdLeftActive->setMinimumSize(100, 40); + tdLeftActive->setMaximumSize(100, 40); + tdRightActive->setText("启用"); + tdRightActive->setMinimumSize(100, 40); + tdRightActive->setMaximumSize(100, 40); + leftLayout->addWidget(tdLeftActive, i + 1, 0); + rightLayout->addWidget(tdRightActive, i + 1 , 0); + + tdLeftActive->setProperty("channelIndex", QString::number(i)); + tdRightActive->setProperty("channelIndex", QString::number(i + 8)); + + connect(tdLeftActive, &QCheckBox::stateChanged, this, &CounterSettingForm::onActiveStateChanged); + connect(tdRightActive, &QCheckBox::stateChanged, this, &CounterSettingForm::onActiveStateChanged); + + activeListLeft.append(tdLeftActive); + activeListRight.append(tdRightActive); + QLabel * tdLeftNo = new QLabel(ui->widgetChannel); QLabel * tdRightNo = new QLabel(ui->widgetChannel); tdLeftNo->setText(QString("CH%1").arg(i + 1)); @@ -145,47 +169,36 @@ 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); + tdLeftClock->setMinimumSize(100, 40); + tdLeftClock->setMaximumSize(100, 40); + tdRightClock->setMinimumSize(100, 40); + tdRightClock->setMaximumSize(100, 40); leftLayout->addWidget(tdLeftClock, i + 1, 2); rightLayout->addWidget(tdRightClock, i + 1 , 2); + clockListLeft.append(tdLeftClock); + clockListRight.append(tdRightClock); + 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); + tdLeftDelay->setMinimumSize(160, 40); + tdLeftDelay->setMaximumSize(160, 40); tdRightDelay->setRange(-1E9, 1E9); tdRightDelay->setSingleStep(0.001); tdRightDelay->setDecimals(3); - tdRightDelay->setMinimumSize(120, 40); - tdRightDelay->setMaximumSize(120, 40); + tdRightDelay->setMinimumSize(160, 40); + tdRightDelay->setMaximumSize(160, 40); leftLayout->addWidget(tdLeftDelay, i + 1, 3); rightLayout->addWidget(tdRightDelay, i + 1 , 3); + delayListLeft.append(tdLeftDelay); + delayListRight.append(tdRightDelay); + if (i % 2 == 0) { tdLeftNo->setProperty("table", "trOdd"); @@ -209,6 +222,28 @@ } } +void CounterSettingForm::clearChannelSettingValue() +{ + for (int i = 0; i < 8; i++) + { + activeListLeft.at(i)->setCheckable(false); + activeListLeft.at(i)->setChecked(false); + activeListLeft.at(i)->setText("未启用"); + clockListLeft.at(i)->setText("-"); + clockListLeft.at(i)->setReadOnly(true); + delayListLeft.at(i)->setValue(0.000); + delayListLeft.at(i)->setReadOnly(true); + + activeListRight.at(i)->setCheckable(false); + activeListRight.at(i)->setChecked(false); + activeListRight.at(i)->setText("未启用"); + clockListRight.at(i)->setText("-"); + clockListRight.at(i)->setReadOnly(true); + delayListRight.at(i)->setValue(0.000); + delayListRight.at(i)->setReadOnly(true); + } +} + void CounterSettingForm::on_btnSettingClose_clicked() { this->close(); @@ -244,6 +279,57 @@ this->close(); } +void CounterSettingForm::on_btnChanelSetDialog_accepted() +{ + QString deviceId = ui->selectCounter->currentData().toString(); + + for (int i = 0; i < 8; i++) + { + CounterChannel * channelPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1)); + if (channelPrt != nullptr) + { + QString channelCode = clockListLeft.at(i)->text(); // 通道钟号 + double delay = delayListLeft.at(i)->value(); // 通道时延值 + + channelPrt->setChannelCode(channelCode); + channelPrt->setDelays(QString::number(delay)); + channelPrt->setActive(activeListLeft.at(i)->isChecked()); + } else if (activeListLeft.at(i)->isChecked() == true) { + CounterChannel * newChannel = new CounterChannel(); + newChannel->setActive(true); + newChannel->setChannelCode(clockListLeft.at(i)->text()); + newChannel->setDelays(QString::number(delayListLeft.at(i)->value())); + + ConstCache::getInstance().channelMap.insert(QString("%1-%2").arg(deviceId).arg(i+1), newChannel); + } + + CounterChannel * channelRightPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1+8)); + if (channelRightPrt != nullptr) + { + QString channelCode = clockListRight.at(i)->text(); // 通道钟号 + double delay = delayListRight.at(i)->value(); // 通道时延值 + + channelRightPrt->setChannelCode(channelCode); + channelRightPrt->setDelays(QString::number(delay)); + channelRightPrt->setActive(activeListRight.at(i)->isChecked()); + } else if (activeListRight.at(i)->isChecked() == true) { + CounterChannel * newChannel = new CounterChannel(); + newChannel->setActive(true); + newChannel->setChannelCode(clockListRight.at(i)->text()); + newChannel->setDelays(QString::number(delayListRight.at(i)->value())); + + ConstCache::getInstance().channelMap.insert(QString("%1-%2").arg(deviceId).arg(i+1+8), newChannel); + } + } + + this->close(); +} + +void CounterSettingForm::on_btnChanelSetDialog_rejected() +{ + this->close(); +} + void CounterSettingForm::on_btnSelectDir_clicked() { QString selectDir = QFileDialog::getExistingDirectory(this, "选择日志保存根目录", QDir::currentPath(), QFileDialog::ShowDirsOnly); @@ -255,11 +341,85 @@ void CounterSettingForm::on_selectCounter_currentIndexChanged(int index) { - if (index == -1) + if (index == 0) { - + clearChannelSettingValue(); } else { QString deviceId = ui->selectCounter->currentData().toString(); - std::cout << deviceId.toStdString() << std::endl; + + for (int i = 0; i < 8; i++) + { + activeListLeft.at(i)->setCheckable(true); + activeListRight.at(i)->setCheckable(true); + + CounterChannel * channelPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1)); + if (channelPrt != nullptr && channelPrt->isActive() == true) + { + QString channelCode = channelPrt->getChannelCode(); // 通道钟号 + QString delays = channelPrt->getDelays(); // 通道时延值 + + activeListLeft.at(i)->setChecked(true); + activeListLeft.at(i)->setText("启用"); + clockListLeft.at(i)->setText(channelCode); + clockListLeft.at(i)->setReadOnly(false); + delayListLeft.at(i)->setValue(delays.toDouble()); + delayListLeft.at(i)->setReadOnly(false); + } else { + activeListLeft.at(i)->setChecked(false); + activeListLeft.at(i)->setText("未启用"); + clockListLeft.at(i)->setText("-"); + clockListLeft.at(i)->setReadOnly(true); + delayListLeft.at(i)->setValue(0.000); + delayListLeft.at(i)->setReadOnly(true); + } + + CounterChannel * channelRightPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1+8)); + if (channelRightPrt != nullptr && channelRightPrt->isActive() == true) + { + QString channelCode = channelRightPrt->getChannelCode(); // 通道钟号 + QString delays = channelRightPrt->getDelays(); // 通道时延值 + + activeListRight.at(i)->setChecked(true); + activeListRight.at(i)->setText("启用"); + clockListRight.at(i)->setText(channelCode); + clockListRight.at(i)->setReadOnly(false); + delayListRight.at(i)->setValue(delays.toDouble()); + delayListRight.at(i)->setReadOnly(false); + } else { + activeListRight.at(i)->setChecked(false); + activeListRight.at(i)->setText("未启用"); + clockListRight.at(i)->setText("-"); + clockListRight.at(i)->setReadOnly(true); + delayListRight.at(i)->setValue(0.000); + delayListRight.at(i)->setReadOnly(true); + } + } + } +} + +void CounterSettingForm::onActiveStateChanged() +{ + QCheckBox * obj = (QCheckBox *) sender(); + + QString channelIndex = obj->property("channelIndex").toString(); + + if (obj->isChecked() == true) { + obj->setText("启用"); + enableChannel(channelIndex.toInt(), true); + } else { + obj->setText("未启用"); + enableChannel(channelIndex.toInt(), false); + } +} + +void CounterSettingForm::enableChannel(int index, bool enable) +{ + if (index < 8) + { + clockListLeft.at(index)->setReadOnly(!enable); + delayListLeft.at(index)->setReadOnly(!enable); + } else if (index >= 8 && index < 16) { + clockListRight.at(index - 8)->setReadOnly(!enable); + delayListRight.at(index - 8)->setReadOnly(!enable); } } diff --git a/CounterRealTime/CounterSettingForm.h b/CounterRealTime/CounterSettingForm.h index 2c42cc0..b4949fb 100644 --- a/CounterRealTime/CounterSettingForm.h +++ b/CounterRealTime/CounterSettingForm.h @@ -31,6 +31,11 @@ void on_btnSelectDir_clicked(); void on_selectCounter_currentIndexChanged(int index); + void onActiveStateChanged(); + + void on_btnChanelSetDialog_accepted(); + + void on_btnChanelSetDialog_rejected(); private: Ui::CounterSettingForm *ui; @@ -38,8 +43,18 @@ QButtonGroup * flagGroup; QButtonGroup * countGroup; + QVector activeListLeft; + QVector activeListRight; + QVector clockListLeft; + QVector clockListRight; + QVector delayListLeft; + QVector delayListRight; + void initDefaultSettings(); void initChannelSettingTable(); + void clearChannelSettingValue(); + + void enableChannel(int index, bool enable); signals: void swiftDisplayLoop(); diff --git a/CounterRealTime/CounterSettingForm.ui b/CounterRealTime/CounterSettingForm.ui index 740ce4e..6c7fffc 100644 --- a/CounterRealTime/CounterSettingForm.ui +++ b/CounterRealTime/CounterSettingForm.ui @@ -95,7 +95,7 @@ - 1 + 0 @@ -326,6 +326,9 @@ 40 + + true + @@ -346,6 +349,31 @@ 重新选择 + + + + 0 + 480 + 960 + 64 + + + + + 0 + 64 + + + + + 16777215 + 64 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + @@ -402,28 +430,34 @@ + + + + 0 + 480 + 960 + 64 + + + + + 0 + 64 + + + + + 16777215 + 64 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + - - - - - 0 - 64 - - - - - 16777215 - 64 - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - diff --git a/CounterRealTime/CounterWindowRT.cpp b/CounterRealTime/CounterWindowRT.cpp index 1304727..55db2ed 100644 --- a/CounterRealTime/CounterWindowRT.cpp +++ b/CounterRealTime/CounterWindowRT.cpp @@ -47,7 +47,7 @@ // 初始化设备和通道 getDeviceList(); - QThread::msleep(1000 * 3); +// QThread::msleep(1000 * 3); for (int i = 0; i < ConstCache::getInstance().deviceIdLoopA.size(); i++) { CounterDevice * devicePtr = ConstCache::getInstance().deviceMap.value(ConstCache::getInstance().deviceIdLoopA.at(i)); @@ -224,13 +224,13 @@ QLabel * labChannelValue = new QLabel(widgetDev); // 通道测量值 // 默认显示内容 - labChannelName->setText(QString("CH%1").arg(i+1)); + labChannelName->setText(QString("CH%1").arg(i+1, 2, 10, QLatin1Char('0'))); labChannelValue->setText("0.000000000000"); // css不支持的样式用代码实现 labChannelName->setMargin(10); labChannelValue->setMargin(10); - labChannelValue->setAlignment(Qt::AlignCenter); + labChannelValue->setAlignment(Qt::AlignRight | Qt::AlignVCenter); // 奇偶显示不同的背景色 if (i % 2 == 0) @@ -278,7 +278,7 @@ if (devIdx < devRefList.size()) { // 参考通道的显示 QString refText = devRefList.at(devIdx)->text(); - channelNameList.at(devIdx * 16 + refChNo - 1)->setText(QString("CH%1:%2").arg(refChNo).arg(refText.right(refText.length() - 4))); + channelNameList.at(devIdx * 16 + refChNo - 1)->setText(QString("CH%1:%2").arg(refChNo, 2, 10, QLatin1Char('0')).arg(refText.right(refText.length() - 4))); } QMap channelDataJsonMap; @@ -293,6 +293,7 @@ for (int i = 0; i < 16; i++) { QString channelNo = QString::number(i + 1); + QString channelNoStr = QString("%1").arg(i + 1, 2, 10, QLatin1Char('0')); if (i + 1 == refChNo) { @@ -307,23 +308,26 @@ // 通道Label的序号 int chanelIdx = devIdx * 16 + channelDataItem.find("channelNo")->toInt() - 1; - if (channel != nullptr) + if (channel != nullptr && channel->isActive() == true) { // 通道时延值 并计算 减去时延值的测量值 double delay = channel->getDelays().isEmpty() == false ? channel->getDelays().toDouble() : 0.0; double valueMinusDelay = channelDataItem.find("data")->toObject().find("dataValue")->toString().toDouble() - delay * 1E-9; // 设置通道名和测量值的QLabel - channelNameList.at(chanelIdx)->setText(QString("CH%1:%2").arg(channelNo).arg(channel->getChannelCode())); + channelNameList.at(chanelIdx)->setText(QString("CH%1:%2").arg(channelNoStr).arg(channel->getChannelCode())); channelValueList.at(chanelIdx)->setText(QString::number(valueMinusDelay, 'f', 12)); channelNameList.at(chanelIdx)->setProperty("channelId", channel->getChannelId()); channelNameList.at(chanelIdx)->setProperty("deviceId", deviceId); channelNameList.at(chanelIdx)->setProperty("channelNo", channelNo); + } else { + channelNameList.at(chanelIdx)->setText(QString("CH%1:%2").arg(channelNoStr).arg("-")); + channelValueList.at(chanelIdx)->setText(""); } } else { // 没有测量值的通道清空 - channelNameList.at(devIdx * 16 + i)->setText(QString("CH%1:%2").arg(i + 1).arg("-")); + channelNameList.at(devIdx * 16 + i)->setText(QString("CH%1:%2").arg(channelNoStr).arg("-")); channelValueList.at(devIdx * 16 + i)->setText(""); } } @@ -354,7 +358,7 @@ CounterDevice * device = new CounterDevice(this); device->setDeviceId(deviceId); device->setComName(devItem.find("linkComName")->toString()); - device->setBaudRate(115200); + device->setBaudRate(SettingConfig::getInstance().BAUD_RATE); device->setDevCode(devItem.find("deviceNo")->toString()); device->setDeviceName(devName); device->setIsUse(isUse.toInt()); @@ -401,6 +405,7 @@ channel->setChannelId(channelId); channel->setChannelCode(channelCode); channel->setChannelNo(channelNo); + channel->setDelays(delays); // 添加到通道的集合中 key=deviceId-channelNo ConstCache::getInstance().channelMap.insert(deviceId + "-" + channelNo, channel); diff --git a/CounterRealTime/common/utils/QSerialPortUtil.cpp b/CounterRealTime/common/utils/QSerialPortUtil.cpp index 2441c20..7c7cf55 100644 --- a/CounterRealTime/common/utils/QSerialPortUtil.cpp +++ b/CounterRealTime/common/utils/QSerialPortUtil.cpp @@ -21,10 +21,10 @@ serial.setPortName(portName); // 串口名 serial.setBaudRate(baudRate); // 波特率 - open = serial.open(QIODevice::ReadWrite); - if (SettingConfig::getInstance().WORK_TYPE == "mock") { + std::cout << portName.toStdString() << QString(" - %1 - mock").arg(baudRate).toStdString() << std::endl; + // mock data received per second QTimer * timer = new QTimer(this); connect(timer, &QTimer::timeout, @@ -32,7 +32,8 @@ timer->start(1000); } else { - std::cout << portName.toStdString() << QString(" - %1").arg(baudRate).toStdString(); + open = serial.open(QIODevice::ReadWrite); + std::cout << portName.toStdString() << QString(" - %1").arg(baudRate).toStdString() << std::endl; if (open == true) { // 绑定信号与槽 diff --git a/CounterRealTime/CounterChannel.cpp b/CounterRealTime/CounterChannel.cpp index 54ec842..978b969 100644 --- a/CounterRealTime/CounterChannel.cpp +++ b/CounterRealTime/CounterChannel.cpp @@ -6,6 +6,10 @@ } +bool CounterChannel::isActive() +{ + return active; +} QString CounterChannel::getDeviceId() { return deviceId; @@ -26,6 +30,10 @@ { return delays; } +void CounterChannel::setActive(bool active) +{ + this->active = active; +} void CounterChannel::setDeviceId(QString deviceId) { this->deviceId = deviceId; diff --git a/CounterRealTime/CounterChannel.h b/CounterRealTime/CounterChannel.h index 2cb8317..afc5dc2 100644 --- a/CounterRealTime/CounterChannel.h +++ b/CounterRealTime/CounterChannel.h @@ -9,11 +9,13 @@ public: explicit CounterChannel(QObject *parent = nullptr); + bool isActive(); QString getDeviceId(); QString getChannelId(); QString getChannelCode(); QString getChannelNo(); QString getDelays(); + void setActive(bool active); void setDeviceId(QString deviceId); void setChannelId(QString channelId); void setChannelCode(QString channelCode); @@ -27,6 +29,7 @@ void appendHisData(QString timestampStr, QString valueStr); private: + bool active = true; QString deviceId; QString channelId; QString channelCode; diff --git a/CounterRealTime/CounterDevice.cpp b/CounterRealTime/CounterDevice.cpp index 3c9d626..63200bb 100644 --- a/CounterRealTime/CounterDevice.cpp +++ b/CounterRealTime/CounterDevice.cpp @@ -162,20 +162,20 @@ QLogUtil::writeChannelDataLogByDate(date, chFilename, channelDataStr); - QJsonObject jsonObj = counterData->toJSON(i - 1); - jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - jsonObj.insert("master", SettingConfig::getInstance().MASTER); - jsonObj.insert("deviceId", deviceId); - messageArray.append(jsonObj); - // append data into hisDataList CounterChannel * channelPtr = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i)); - if (channelPtr != nullptr) + if (channelPtr != nullptr && channelPtr->isActive() == true) { // 通道时延值 并计算 减去时延值的测量值 double delay = channelPtr->getDelays().isEmpty() == false ? channelPtr->getDelays().toDouble() : 0.0; double valueMinusDelay = counterData->channelDataArray.at(i-1).toDouble() - delay * 1E-9; channelPtr->appendHisData(QString::number(counterData->milisecond), QString::number(valueMinusDelay, 'f', 12)); + + QJsonObject jsonObj = counterData->toJSON(i - 1); + jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); + jsonObj.insert("master", SettingConfig::getInstance().MASTER); + jsonObj.insert("deviceId", deviceId); + messageArray.append(jsonObj); } } } @@ -192,7 +192,7 @@ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact))); } - qDebug() << counterData->rawFrame; +// qDebug() << counterData->rawFrame; qDebug() << messageArray; // 4. 在界面上简单显示相差数据结果 diff --git a/CounterRealTime/CounterSettingForm.cpp b/CounterRealTime/CounterSettingForm.cpp index e74a11e..c095523 100644 --- a/CounterRealTime/CounterSettingForm.cpp +++ b/CounterRealTime/CounterSettingForm.cpp @@ -16,6 +16,9 @@ ui->btnSetDialog->button(QDialogButtonBox::Ok)->setText("确定"); ui->btnSetDialog->button(QDialogButtonBox::Cancel)->setText("取消"); + ui->btnChanelSetDialog->button(QDialogButtonBox::Ok)->setText("确定"); + ui->btnChanelSetDialog->button(QDialogButtonBox::Cancel)->setText("取消"); + flagGroup = new QButtonGroup(); flagGroup->addButton(ui->radioDispA, 1); flagGroup->addButton(ui->radioDispB, 0); @@ -27,6 +30,7 @@ this->initDefaultSettings(); this->initChannelSettingTable(); + this->clearChannelSettingValue(); } CounterSettingForm::~CounterSettingForm() @@ -84,14 +88,14 @@ headerLeftClock->setProperty("table", "header"); headerLeftDelay->setProperty("table", "header"); + headerLeftActive->setMaximumSize(100, 50); + headerLeftActive->setMinimumSize(100, 50); 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); + headerLeftClock->setMinimumSize(100, 50); + headerLeftClock->setMaximumSize(100, 50); + headerLeftDelay->setMinimumSize(160, 50); + headerLeftDelay->setMaximumSize(160, 50); headerLeftNo->setAlignment(Qt::AlignCenter); headerLeftActive->setAlignment(Qt::AlignCenter); @@ -115,14 +119,14 @@ headerRightClock->setProperty("table", "header"); headerRightDelay->setProperty("table", "header"); + headerRightActive->setMaximumSize(100, 50); + headerRightActive->setMinimumSize(100, 50); 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); + headerRightClock->setMinimumSize(100, 50); + headerRightClock->setMaximumSize(100, 50); + headerRightDelay->setMinimumSize(160, 50); + headerRightDelay->setMaximumSize(160, 50); headerRightNo->setAlignment(Qt::AlignCenter); headerRightActive->setAlignment(Qt::AlignCenter); @@ -136,6 +140,26 @@ for ( int i = 0; i < 8; i++ ) { + QCheckBox * tdLeftActive = new QCheckBox(ui->widgetChannel); + QCheckBox * tdRightActive = new QCheckBox(ui->widgetChannel); + tdLeftActive->setText("启用"); + tdLeftActive->setMinimumSize(100, 40); + tdLeftActive->setMaximumSize(100, 40); + tdRightActive->setText("启用"); + tdRightActive->setMinimumSize(100, 40); + tdRightActive->setMaximumSize(100, 40); + leftLayout->addWidget(tdLeftActive, i + 1, 0); + rightLayout->addWidget(tdRightActive, i + 1 , 0); + + tdLeftActive->setProperty("channelIndex", QString::number(i)); + tdRightActive->setProperty("channelIndex", QString::number(i + 8)); + + connect(tdLeftActive, &QCheckBox::stateChanged, this, &CounterSettingForm::onActiveStateChanged); + connect(tdRightActive, &QCheckBox::stateChanged, this, &CounterSettingForm::onActiveStateChanged); + + activeListLeft.append(tdLeftActive); + activeListRight.append(tdRightActive); + QLabel * tdLeftNo = new QLabel(ui->widgetChannel); QLabel * tdRightNo = new QLabel(ui->widgetChannel); tdLeftNo->setText(QString("CH%1").arg(i + 1)); @@ -145,47 +169,36 @@ 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); + tdLeftClock->setMinimumSize(100, 40); + tdLeftClock->setMaximumSize(100, 40); + tdRightClock->setMinimumSize(100, 40); + tdRightClock->setMaximumSize(100, 40); leftLayout->addWidget(tdLeftClock, i + 1, 2); rightLayout->addWidget(tdRightClock, i + 1 , 2); + clockListLeft.append(tdLeftClock); + clockListRight.append(tdRightClock); + 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); + tdLeftDelay->setMinimumSize(160, 40); + tdLeftDelay->setMaximumSize(160, 40); tdRightDelay->setRange(-1E9, 1E9); tdRightDelay->setSingleStep(0.001); tdRightDelay->setDecimals(3); - tdRightDelay->setMinimumSize(120, 40); - tdRightDelay->setMaximumSize(120, 40); + tdRightDelay->setMinimumSize(160, 40); + tdRightDelay->setMaximumSize(160, 40); leftLayout->addWidget(tdLeftDelay, i + 1, 3); rightLayout->addWidget(tdRightDelay, i + 1 , 3); + delayListLeft.append(tdLeftDelay); + delayListRight.append(tdRightDelay); + if (i % 2 == 0) { tdLeftNo->setProperty("table", "trOdd"); @@ -209,6 +222,28 @@ } } +void CounterSettingForm::clearChannelSettingValue() +{ + for (int i = 0; i < 8; i++) + { + activeListLeft.at(i)->setCheckable(false); + activeListLeft.at(i)->setChecked(false); + activeListLeft.at(i)->setText("未启用"); + clockListLeft.at(i)->setText("-"); + clockListLeft.at(i)->setReadOnly(true); + delayListLeft.at(i)->setValue(0.000); + delayListLeft.at(i)->setReadOnly(true); + + activeListRight.at(i)->setCheckable(false); + activeListRight.at(i)->setChecked(false); + activeListRight.at(i)->setText("未启用"); + clockListRight.at(i)->setText("-"); + clockListRight.at(i)->setReadOnly(true); + delayListRight.at(i)->setValue(0.000); + delayListRight.at(i)->setReadOnly(true); + } +} + void CounterSettingForm::on_btnSettingClose_clicked() { this->close(); @@ -244,6 +279,57 @@ this->close(); } +void CounterSettingForm::on_btnChanelSetDialog_accepted() +{ + QString deviceId = ui->selectCounter->currentData().toString(); + + for (int i = 0; i < 8; i++) + { + CounterChannel * channelPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1)); + if (channelPrt != nullptr) + { + QString channelCode = clockListLeft.at(i)->text(); // 通道钟号 + double delay = delayListLeft.at(i)->value(); // 通道时延值 + + channelPrt->setChannelCode(channelCode); + channelPrt->setDelays(QString::number(delay)); + channelPrt->setActive(activeListLeft.at(i)->isChecked()); + } else if (activeListLeft.at(i)->isChecked() == true) { + CounterChannel * newChannel = new CounterChannel(); + newChannel->setActive(true); + newChannel->setChannelCode(clockListLeft.at(i)->text()); + newChannel->setDelays(QString::number(delayListLeft.at(i)->value())); + + ConstCache::getInstance().channelMap.insert(QString("%1-%2").arg(deviceId).arg(i+1), newChannel); + } + + CounterChannel * channelRightPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1+8)); + if (channelRightPrt != nullptr) + { + QString channelCode = clockListRight.at(i)->text(); // 通道钟号 + double delay = delayListRight.at(i)->value(); // 通道时延值 + + channelRightPrt->setChannelCode(channelCode); + channelRightPrt->setDelays(QString::number(delay)); + channelRightPrt->setActive(activeListRight.at(i)->isChecked()); + } else if (activeListRight.at(i)->isChecked() == true) { + CounterChannel * newChannel = new CounterChannel(); + newChannel->setActive(true); + newChannel->setChannelCode(clockListRight.at(i)->text()); + newChannel->setDelays(QString::number(delayListRight.at(i)->value())); + + ConstCache::getInstance().channelMap.insert(QString("%1-%2").arg(deviceId).arg(i+1+8), newChannel); + } + } + + this->close(); +} + +void CounterSettingForm::on_btnChanelSetDialog_rejected() +{ + this->close(); +} + void CounterSettingForm::on_btnSelectDir_clicked() { QString selectDir = QFileDialog::getExistingDirectory(this, "选择日志保存根目录", QDir::currentPath(), QFileDialog::ShowDirsOnly); @@ -255,11 +341,85 @@ void CounterSettingForm::on_selectCounter_currentIndexChanged(int index) { - if (index == -1) + if (index == 0) { - + clearChannelSettingValue(); } else { QString deviceId = ui->selectCounter->currentData().toString(); - std::cout << deviceId.toStdString() << std::endl; + + for (int i = 0; i < 8; i++) + { + activeListLeft.at(i)->setCheckable(true); + activeListRight.at(i)->setCheckable(true); + + CounterChannel * channelPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1)); + if (channelPrt != nullptr && channelPrt->isActive() == true) + { + QString channelCode = channelPrt->getChannelCode(); // 通道钟号 + QString delays = channelPrt->getDelays(); // 通道时延值 + + activeListLeft.at(i)->setChecked(true); + activeListLeft.at(i)->setText("启用"); + clockListLeft.at(i)->setText(channelCode); + clockListLeft.at(i)->setReadOnly(false); + delayListLeft.at(i)->setValue(delays.toDouble()); + delayListLeft.at(i)->setReadOnly(false); + } else { + activeListLeft.at(i)->setChecked(false); + activeListLeft.at(i)->setText("未启用"); + clockListLeft.at(i)->setText("-"); + clockListLeft.at(i)->setReadOnly(true); + delayListLeft.at(i)->setValue(0.000); + delayListLeft.at(i)->setReadOnly(true); + } + + CounterChannel * channelRightPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1+8)); + if (channelRightPrt != nullptr && channelRightPrt->isActive() == true) + { + QString channelCode = channelRightPrt->getChannelCode(); // 通道钟号 + QString delays = channelRightPrt->getDelays(); // 通道时延值 + + activeListRight.at(i)->setChecked(true); + activeListRight.at(i)->setText("启用"); + clockListRight.at(i)->setText(channelCode); + clockListRight.at(i)->setReadOnly(false); + delayListRight.at(i)->setValue(delays.toDouble()); + delayListRight.at(i)->setReadOnly(false); + } else { + activeListRight.at(i)->setChecked(false); + activeListRight.at(i)->setText("未启用"); + clockListRight.at(i)->setText("-"); + clockListRight.at(i)->setReadOnly(true); + delayListRight.at(i)->setValue(0.000); + delayListRight.at(i)->setReadOnly(true); + } + } + } +} + +void CounterSettingForm::onActiveStateChanged() +{ + QCheckBox * obj = (QCheckBox *) sender(); + + QString channelIndex = obj->property("channelIndex").toString(); + + if (obj->isChecked() == true) { + obj->setText("启用"); + enableChannel(channelIndex.toInt(), true); + } else { + obj->setText("未启用"); + enableChannel(channelIndex.toInt(), false); + } +} + +void CounterSettingForm::enableChannel(int index, bool enable) +{ + if (index < 8) + { + clockListLeft.at(index)->setReadOnly(!enable); + delayListLeft.at(index)->setReadOnly(!enable); + } else if (index >= 8 && index < 16) { + clockListRight.at(index - 8)->setReadOnly(!enable); + delayListRight.at(index - 8)->setReadOnly(!enable); } } diff --git a/CounterRealTime/CounterSettingForm.h b/CounterRealTime/CounterSettingForm.h index 2c42cc0..b4949fb 100644 --- a/CounterRealTime/CounterSettingForm.h +++ b/CounterRealTime/CounterSettingForm.h @@ -31,6 +31,11 @@ void on_btnSelectDir_clicked(); void on_selectCounter_currentIndexChanged(int index); + void onActiveStateChanged(); + + void on_btnChanelSetDialog_accepted(); + + void on_btnChanelSetDialog_rejected(); private: Ui::CounterSettingForm *ui; @@ -38,8 +43,18 @@ QButtonGroup * flagGroup; QButtonGroup * countGroup; + QVector activeListLeft; + QVector activeListRight; + QVector clockListLeft; + QVector clockListRight; + QVector delayListLeft; + QVector delayListRight; + void initDefaultSettings(); void initChannelSettingTable(); + void clearChannelSettingValue(); + + void enableChannel(int index, bool enable); signals: void swiftDisplayLoop(); diff --git a/CounterRealTime/CounterSettingForm.ui b/CounterRealTime/CounterSettingForm.ui index 740ce4e..6c7fffc 100644 --- a/CounterRealTime/CounterSettingForm.ui +++ b/CounterRealTime/CounterSettingForm.ui @@ -95,7 +95,7 @@ - 1 + 0 @@ -326,6 +326,9 @@ 40 + + true + @@ -346,6 +349,31 @@ 重新选择 + + + + 0 + 480 + 960 + 64 + + + + + 0 + 64 + + + + + 16777215 + 64 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + @@ -402,28 +430,34 @@ + + + + 0 + 480 + 960 + 64 + + + + + 0 + 64 + + + + + 16777215 + 64 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + - - - - - 0 - 64 - - - - - 16777215 - 64 - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - diff --git a/CounterRealTime/CounterWindowRT.cpp b/CounterRealTime/CounterWindowRT.cpp index 1304727..55db2ed 100644 --- a/CounterRealTime/CounterWindowRT.cpp +++ b/CounterRealTime/CounterWindowRT.cpp @@ -47,7 +47,7 @@ // 初始化设备和通道 getDeviceList(); - QThread::msleep(1000 * 3); +// QThread::msleep(1000 * 3); for (int i = 0; i < ConstCache::getInstance().deviceIdLoopA.size(); i++) { CounterDevice * devicePtr = ConstCache::getInstance().deviceMap.value(ConstCache::getInstance().deviceIdLoopA.at(i)); @@ -224,13 +224,13 @@ QLabel * labChannelValue = new QLabel(widgetDev); // 通道测量值 // 默认显示内容 - labChannelName->setText(QString("CH%1").arg(i+1)); + labChannelName->setText(QString("CH%1").arg(i+1, 2, 10, QLatin1Char('0'))); labChannelValue->setText("0.000000000000"); // css不支持的样式用代码实现 labChannelName->setMargin(10); labChannelValue->setMargin(10); - labChannelValue->setAlignment(Qt::AlignCenter); + labChannelValue->setAlignment(Qt::AlignRight | Qt::AlignVCenter); // 奇偶显示不同的背景色 if (i % 2 == 0) @@ -278,7 +278,7 @@ if (devIdx < devRefList.size()) { // 参考通道的显示 QString refText = devRefList.at(devIdx)->text(); - channelNameList.at(devIdx * 16 + refChNo - 1)->setText(QString("CH%1:%2").arg(refChNo).arg(refText.right(refText.length() - 4))); + channelNameList.at(devIdx * 16 + refChNo - 1)->setText(QString("CH%1:%2").arg(refChNo, 2, 10, QLatin1Char('0')).arg(refText.right(refText.length() - 4))); } QMap channelDataJsonMap; @@ -293,6 +293,7 @@ for (int i = 0; i < 16; i++) { QString channelNo = QString::number(i + 1); + QString channelNoStr = QString("%1").arg(i + 1, 2, 10, QLatin1Char('0')); if (i + 1 == refChNo) { @@ -307,23 +308,26 @@ // 通道Label的序号 int chanelIdx = devIdx * 16 + channelDataItem.find("channelNo")->toInt() - 1; - if (channel != nullptr) + if (channel != nullptr && channel->isActive() == true) { // 通道时延值 并计算 减去时延值的测量值 double delay = channel->getDelays().isEmpty() == false ? channel->getDelays().toDouble() : 0.0; double valueMinusDelay = channelDataItem.find("data")->toObject().find("dataValue")->toString().toDouble() - delay * 1E-9; // 设置通道名和测量值的QLabel - channelNameList.at(chanelIdx)->setText(QString("CH%1:%2").arg(channelNo).arg(channel->getChannelCode())); + channelNameList.at(chanelIdx)->setText(QString("CH%1:%2").arg(channelNoStr).arg(channel->getChannelCode())); channelValueList.at(chanelIdx)->setText(QString::number(valueMinusDelay, 'f', 12)); channelNameList.at(chanelIdx)->setProperty("channelId", channel->getChannelId()); channelNameList.at(chanelIdx)->setProperty("deviceId", deviceId); channelNameList.at(chanelIdx)->setProperty("channelNo", channelNo); + } else { + channelNameList.at(chanelIdx)->setText(QString("CH%1:%2").arg(channelNoStr).arg("-")); + channelValueList.at(chanelIdx)->setText(""); } } else { // 没有测量值的通道清空 - channelNameList.at(devIdx * 16 + i)->setText(QString("CH%1:%2").arg(i + 1).arg("-")); + channelNameList.at(devIdx * 16 + i)->setText(QString("CH%1:%2").arg(channelNoStr).arg("-")); channelValueList.at(devIdx * 16 + i)->setText(""); } } @@ -354,7 +358,7 @@ CounterDevice * device = new CounterDevice(this); device->setDeviceId(deviceId); device->setComName(devItem.find("linkComName")->toString()); - device->setBaudRate(115200); + device->setBaudRate(SettingConfig::getInstance().BAUD_RATE); device->setDevCode(devItem.find("deviceNo")->toString()); device->setDeviceName(devName); device->setIsUse(isUse.toInt()); @@ -401,6 +405,7 @@ channel->setChannelId(channelId); channel->setChannelCode(channelCode); channel->setChannelNo(channelNo); + channel->setDelays(delays); // 添加到通道的集合中 key=deviceId-channelNo ConstCache::getInstance().channelMap.insert(deviceId + "-" + channelNo, channel); diff --git a/CounterRealTime/common/utils/QSerialPortUtil.cpp b/CounterRealTime/common/utils/QSerialPortUtil.cpp index 2441c20..7c7cf55 100644 --- a/CounterRealTime/common/utils/QSerialPortUtil.cpp +++ b/CounterRealTime/common/utils/QSerialPortUtil.cpp @@ -21,10 +21,10 @@ serial.setPortName(portName); // 串口名 serial.setBaudRate(baudRate); // 波特率 - open = serial.open(QIODevice::ReadWrite); - if (SettingConfig::getInstance().WORK_TYPE == "mock") { + std::cout << portName.toStdString() << QString(" - %1 - mock").arg(baudRate).toStdString() << std::endl; + // mock data received per second QTimer * timer = new QTimer(this); connect(timer, &QTimer::timeout, @@ -32,7 +32,8 @@ timer->start(1000); } else { - std::cout << portName.toStdString() << QString(" - %1").arg(baudRate).toStdString(); + open = serial.open(QIODevice::ReadWrite); + std::cout << portName.toStdString() << QString(" - %1").arg(baudRate).toStdString() << std::endl; if (open == true) { // 绑定信号与槽 diff --git a/CounterRealTime/common/utils/SettingConfig.h b/CounterRealTime/common/utils/SettingConfig.h index 72448a5..0ed91ea 100644 --- a/CounterRealTime/common/utils/SettingConfig.h +++ b/CounterRealTime/common/utils/SettingConfig.h @@ -29,7 +29,7 @@ void init(); /******** 以下为需要的各类参数 ********/ - qint16 BAUD_RATE; + qint32 BAUD_RATE; qint16 WINDOW_WIDTH; qint16 WINDOW_HEIGHT; diff --git a/CounterRealTime/CounterChannel.cpp b/CounterRealTime/CounterChannel.cpp index 54ec842..978b969 100644 --- a/CounterRealTime/CounterChannel.cpp +++ b/CounterRealTime/CounterChannel.cpp @@ -6,6 +6,10 @@ } +bool CounterChannel::isActive() +{ + return active; +} QString CounterChannel::getDeviceId() { return deviceId; @@ -26,6 +30,10 @@ { return delays; } +void CounterChannel::setActive(bool active) +{ + this->active = active; +} void CounterChannel::setDeviceId(QString deviceId) { this->deviceId = deviceId; diff --git a/CounterRealTime/CounterChannel.h b/CounterRealTime/CounterChannel.h index 2cb8317..afc5dc2 100644 --- a/CounterRealTime/CounterChannel.h +++ b/CounterRealTime/CounterChannel.h @@ -9,11 +9,13 @@ public: explicit CounterChannel(QObject *parent = nullptr); + bool isActive(); QString getDeviceId(); QString getChannelId(); QString getChannelCode(); QString getChannelNo(); QString getDelays(); + void setActive(bool active); void setDeviceId(QString deviceId); void setChannelId(QString channelId); void setChannelCode(QString channelCode); @@ -27,6 +29,7 @@ void appendHisData(QString timestampStr, QString valueStr); private: + bool active = true; QString deviceId; QString channelId; QString channelCode; diff --git a/CounterRealTime/CounterDevice.cpp b/CounterRealTime/CounterDevice.cpp index 3c9d626..63200bb 100644 --- a/CounterRealTime/CounterDevice.cpp +++ b/CounterRealTime/CounterDevice.cpp @@ -162,20 +162,20 @@ QLogUtil::writeChannelDataLogByDate(date, chFilename, channelDataStr); - QJsonObject jsonObj = counterData->toJSON(i - 1); - jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - jsonObj.insert("master", SettingConfig::getInstance().MASTER); - jsonObj.insert("deviceId", deviceId); - messageArray.append(jsonObj); - // append data into hisDataList CounterChannel * channelPtr = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i)); - if (channelPtr != nullptr) + if (channelPtr != nullptr && channelPtr->isActive() == true) { // 通道时延值 并计算 减去时延值的测量值 double delay = channelPtr->getDelays().isEmpty() == false ? channelPtr->getDelays().toDouble() : 0.0; double valueMinusDelay = counterData->channelDataArray.at(i-1).toDouble() - delay * 1E-9; channelPtr->appendHisData(QString::number(counterData->milisecond), QString::number(valueMinusDelay, 'f', 12)); + + QJsonObject jsonObj = counterData->toJSON(i - 1); + jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); + jsonObj.insert("master", SettingConfig::getInstance().MASTER); + jsonObj.insert("deviceId", deviceId); + messageArray.append(jsonObj); } } } @@ -192,7 +192,7 @@ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact))); } - qDebug() << counterData->rawFrame; +// qDebug() << counterData->rawFrame; qDebug() << messageArray; // 4. 在界面上简单显示相差数据结果 diff --git a/CounterRealTime/CounterSettingForm.cpp b/CounterRealTime/CounterSettingForm.cpp index e74a11e..c095523 100644 --- a/CounterRealTime/CounterSettingForm.cpp +++ b/CounterRealTime/CounterSettingForm.cpp @@ -16,6 +16,9 @@ ui->btnSetDialog->button(QDialogButtonBox::Ok)->setText("确定"); ui->btnSetDialog->button(QDialogButtonBox::Cancel)->setText("取消"); + ui->btnChanelSetDialog->button(QDialogButtonBox::Ok)->setText("确定"); + ui->btnChanelSetDialog->button(QDialogButtonBox::Cancel)->setText("取消"); + flagGroup = new QButtonGroup(); flagGroup->addButton(ui->radioDispA, 1); flagGroup->addButton(ui->radioDispB, 0); @@ -27,6 +30,7 @@ this->initDefaultSettings(); this->initChannelSettingTable(); + this->clearChannelSettingValue(); } CounterSettingForm::~CounterSettingForm() @@ -84,14 +88,14 @@ headerLeftClock->setProperty("table", "header"); headerLeftDelay->setProperty("table", "header"); + headerLeftActive->setMaximumSize(100, 50); + headerLeftActive->setMinimumSize(100, 50); 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); + headerLeftClock->setMinimumSize(100, 50); + headerLeftClock->setMaximumSize(100, 50); + headerLeftDelay->setMinimumSize(160, 50); + headerLeftDelay->setMaximumSize(160, 50); headerLeftNo->setAlignment(Qt::AlignCenter); headerLeftActive->setAlignment(Qt::AlignCenter); @@ -115,14 +119,14 @@ headerRightClock->setProperty("table", "header"); headerRightDelay->setProperty("table", "header"); + headerRightActive->setMaximumSize(100, 50); + headerRightActive->setMinimumSize(100, 50); 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); + headerRightClock->setMinimumSize(100, 50); + headerRightClock->setMaximumSize(100, 50); + headerRightDelay->setMinimumSize(160, 50); + headerRightDelay->setMaximumSize(160, 50); headerRightNo->setAlignment(Qt::AlignCenter); headerRightActive->setAlignment(Qt::AlignCenter); @@ -136,6 +140,26 @@ for ( int i = 0; i < 8; i++ ) { + QCheckBox * tdLeftActive = new QCheckBox(ui->widgetChannel); + QCheckBox * tdRightActive = new QCheckBox(ui->widgetChannel); + tdLeftActive->setText("启用"); + tdLeftActive->setMinimumSize(100, 40); + tdLeftActive->setMaximumSize(100, 40); + tdRightActive->setText("启用"); + tdRightActive->setMinimumSize(100, 40); + tdRightActive->setMaximumSize(100, 40); + leftLayout->addWidget(tdLeftActive, i + 1, 0); + rightLayout->addWidget(tdRightActive, i + 1 , 0); + + tdLeftActive->setProperty("channelIndex", QString::number(i)); + tdRightActive->setProperty("channelIndex", QString::number(i + 8)); + + connect(tdLeftActive, &QCheckBox::stateChanged, this, &CounterSettingForm::onActiveStateChanged); + connect(tdRightActive, &QCheckBox::stateChanged, this, &CounterSettingForm::onActiveStateChanged); + + activeListLeft.append(tdLeftActive); + activeListRight.append(tdRightActive); + QLabel * tdLeftNo = new QLabel(ui->widgetChannel); QLabel * tdRightNo = new QLabel(ui->widgetChannel); tdLeftNo->setText(QString("CH%1").arg(i + 1)); @@ -145,47 +169,36 @@ 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); + tdLeftClock->setMinimumSize(100, 40); + tdLeftClock->setMaximumSize(100, 40); + tdRightClock->setMinimumSize(100, 40); + tdRightClock->setMaximumSize(100, 40); leftLayout->addWidget(tdLeftClock, i + 1, 2); rightLayout->addWidget(tdRightClock, i + 1 , 2); + clockListLeft.append(tdLeftClock); + clockListRight.append(tdRightClock); + 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); + tdLeftDelay->setMinimumSize(160, 40); + tdLeftDelay->setMaximumSize(160, 40); tdRightDelay->setRange(-1E9, 1E9); tdRightDelay->setSingleStep(0.001); tdRightDelay->setDecimals(3); - tdRightDelay->setMinimumSize(120, 40); - tdRightDelay->setMaximumSize(120, 40); + tdRightDelay->setMinimumSize(160, 40); + tdRightDelay->setMaximumSize(160, 40); leftLayout->addWidget(tdLeftDelay, i + 1, 3); rightLayout->addWidget(tdRightDelay, i + 1 , 3); + delayListLeft.append(tdLeftDelay); + delayListRight.append(tdRightDelay); + if (i % 2 == 0) { tdLeftNo->setProperty("table", "trOdd"); @@ -209,6 +222,28 @@ } } +void CounterSettingForm::clearChannelSettingValue() +{ + for (int i = 0; i < 8; i++) + { + activeListLeft.at(i)->setCheckable(false); + activeListLeft.at(i)->setChecked(false); + activeListLeft.at(i)->setText("未启用"); + clockListLeft.at(i)->setText("-"); + clockListLeft.at(i)->setReadOnly(true); + delayListLeft.at(i)->setValue(0.000); + delayListLeft.at(i)->setReadOnly(true); + + activeListRight.at(i)->setCheckable(false); + activeListRight.at(i)->setChecked(false); + activeListRight.at(i)->setText("未启用"); + clockListRight.at(i)->setText("-"); + clockListRight.at(i)->setReadOnly(true); + delayListRight.at(i)->setValue(0.000); + delayListRight.at(i)->setReadOnly(true); + } +} + void CounterSettingForm::on_btnSettingClose_clicked() { this->close(); @@ -244,6 +279,57 @@ this->close(); } +void CounterSettingForm::on_btnChanelSetDialog_accepted() +{ + QString deviceId = ui->selectCounter->currentData().toString(); + + for (int i = 0; i < 8; i++) + { + CounterChannel * channelPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1)); + if (channelPrt != nullptr) + { + QString channelCode = clockListLeft.at(i)->text(); // 通道钟号 + double delay = delayListLeft.at(i)->value(); // 通道时延值 + + channelPrt->setChannelCode(channelCode); + channelPrt->setDelays(QString::number(delay)); + channelPrt->setActive(activeListLeft.at(i)->isChecked()); + } else if (activeListLeft.at(i)->isChecked() == true) { + CounterChannel * newChannel = new CounterChannel(); + newChannel->setActive(true); + newChannel->setChannelCode(clockListLeft.at(i)->text()); + newChannel->setDelays(QString::number(delayListLeft.at(i)->value())); + + ConstCache::getInstance().channelMap.insert(QString("%1-%2").arg(deviceId).arg(i+1), newChannel); + } + + CounterChannel * channelRightPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1+8)); + if (channelRightPrt != nullptr) + { + QString channelCode = clockListRight.at(i)->text(); // 通道钟号 + double delay = delayListRight.at(i)->value(); // 通道时延值 + + channelRightPrt->setChannelCode(channelCode); + channelRightPrt->setDelays(QString::number(delay)); + channelRightPrt->setActive(activeListRight.at(i)->isChecked()); + } else if (activeListRight.at(i)->isChecked() == true) { + CounterChannel * newChannel = new CounterChannel(); + newChannel->setActive(true); + newChannel->setChannelCode(clockListRight.at(i)->text()); + newChannel->setDelays(QString::number(delayListRight.at(i)->value())); + + ConstCache::getInstance().channelMap.insert(QString("%1-%2").arg(deviceId).arg(i+1+8), newChannel); + } + } + + this->close(); +} + +void CounterSettingForm::on_btnChanelSetDialog_rejected() +{ + this->close(); +} + void CounterSettingForm::on_btnSelectDir_clicked() { QString selectDir = QFileDialog::getExistingDirectory(this, "选择日志保存根目录", QDir::currentPath(), QFileDialog::ShowDirsOnly); @@ -255,11 +341,85 @@ void CounterSettingForm::on_selectCounter_currentIndexChanged(int index) { - if (index == -1) + if (index == 0) { - + clearChannelSettingValue(); } else { QString deviceId = ui->selectCounter->currentData().toString(); - std::cout << deviceId.toStdString() << std::endl; + + for (int i = 0; i < 8; i++) + { + activeListLeft.at(i)->setCheckable(true); + activeListRight.at(i)->setCheckable(true); + + CounterChannel * channelPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1)); + if (channelPrt != nullptr && channelPrt->isActive() == true) + { + QString channelCode = channelPrt->getChannelCode(); // 通道钟号 + QString delays = channelPrt->getDelays(); // 通道时延值 + + activeListLeft.at(i)->setChecked(true); + activeListLeft.at(i)->setText("启用"); + clockListLeft.at(i)->setText(channelCode); + clockListLeft.at(i)->setReadOnly(false); + delayListLeft.at(i)->setValue(delays.toDouble()); + delayListLeft.at(i)->setReadOnly(false); + } else { + activeListLeft.at(i)->setChecked(false); + activeListLeft.at(i)->setText("未启用"); + clockListLeft.at(i)->setText("-"); + clockListLeft.at(i)->setReadOnly(true); + delayListLeft.at(i)->setValue(0.000); + delayListLeft.at(i)->setReadOnly(true); + } + + CounterChannel * channelRightPrt = ConstCache::getInstance().channelMap.value(QString("%1-%2").arg(deviceId).arg(i+1+8)); + if (channelRightPrt != nullptr && channelRightPrt->isActive() == true) + { + QString channelCode = channelRightPrt->getChannelCode(); // 通道钟号 + QString delays = channelRightPrt->getDelays(); // 通道时延值 + + activeListRight.at(i)->setChecked(true); + activeListRight.at(i)->setText("启用"); + clockListRight.at(i)->setText(channelCode); + clockListRight.at(i)->setReadOnly(false); + delayListRight.at(i)->setValue(delays.toDouble()); + delayListRight.at(i)->setReadOnly(false); + } else { + activeListRight.at(i)->setChecked(false); + activeListRight.at(i)->setText("未启用"); + clockListRight.at(i)->setText("-"); + clockListRight.at(i)->setReadOnly(true); + delayListRight.at(i)->setValue(0.000); + delayListRight.at(i)->setReadOnly(true); + } + } + } +} + +void CounterSettingForm::onActiveStateChanged() +{ + QCheckBox * obj = (QCheckBox *) sender(); + + QString channelIndex = obj->property("channelIndex").toString(); + + if (obj->isChecked() == true) { + obj->setText("启用"); + enableChannel(channelIndex.toInt(), true); + } else { + obj->setText("未启用"); + enableChannel(channelIndex.toInt(), false); + } +} + +void CounterSettingForm::enableChannel(int index, bool enable) +{ + if (index < 8) + { + clockListLeft.at(index)->setReadOnly(!enable); + delayListLeft.at(index)->setReadOnly(!enable); + } else if (index >= 8 && index < 16) { + clockListRight.at(index - 8)->setReadOnly(!enable); + delayListRight.at(index - 8)->setReadOnly(!enable); } } diff --git a/CounterRealTime/CounterSettingForm.h b/CounterRealTime/CounterSettingForm.h index 2c42cc0..b4949fb 100644 --- a/CounterRealTime/CounterSettingForm.h +++ b/CounterRealTime/CounterSettingForm.h @@ -31,6 +31,11 @@ void on_btnSelectDir_clicked(); void on_selectCounter_currentIndexChanged(int index); + void onActiveStateChanged(); + + void on_btnChanelSetDialog_accepted(); + + void on_btnChanelSetDialog_rejected(); private: Ui::CounterSettingForm *ui; @@ -38,8 +43,18 @@ QButtonGroup * flagGroup; QButtonGroup * countGroup; + QVector activeListLeft; + QVector activeListRight; + QVector clockListLeft; + QVector clockListRight; + QVector delayListLeft; + QVector delayListRight; + void initDefaultSettings(); void initChannelSettingTable(); + void clearChannelSettingValue(); + + void enableChannel(int index, bool enable); signals: void swiftDisplayLoop(); diff --git a/CounterRealTime/CounterSettingForm.ui b/CounterRealTime/CounterSettingForm.ui index 740ce4e..6c7fffc 100644 --- a/CounterRealTime/CounterSettingForm.ui +++ b/CounterRealTime/CounterSettingForm.ui @@ -95,7 +95,7 @@ - 1 + 0 @@ -326,6 +326,9 @@ 40 + + true + @@ -346,6 +349,31 @@ 重新选择 + + + + 0 + 480 + 960 + 64 + + + + + 0 + 64 + + + + + 16777215 + 64 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + @@ -402,28 +430,34 @@ + + + + 0 + 480 + 960 + 64 + + + + + 0 + 64 + + + + + 16777215 + 64 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + - - - - - 0 - 64 - - - - - 16777215 - 64 - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - diff --git a/CounterRealTime/CounterWindowRT.cpp b/CounterRealTime/CounterWindowRT.cpp index 1304727..55db2ed 100644 --- a/CounterRealTime/CounterWindowRT.cpp +++ b/CounterRealTime/CounterWindowRT.cpp @@ -47,7 +47,7 @@ // 初始化设备和通道 getDeviceList(); - QThread::msleep(1000 * 3); +// QThread::msleep(1000 * 3); for (int i = 0; i < ConstCache::getInstance().deviceIdLoopA.size(); i++) { CounterDevice * devicePtr = ConstCache::getInstance().deviceMap.value(ConstCache::getInstance().deviceIdLoopA.at(i)); @@ -224,13 +224,13 @@ QLabel * labChannelValue = new QLabel(widgetDev); // 通道测量值 // 默认显示内容 - labChannelName->setText(QString("CH%1").arg(i+1)); + labChannelName->setText(QString("CH%1").arg(i+1, 2, 10, QLatin1Char('0'))); labChannelValue->setText("0.000000000000"); // css不支持的样式用代码实现 labChannelName->setMargin(10); labChannelValue->setMargin(10); - labChannelValue->setAlignment(Qt::AlignCenter); + labChannelValue->setAlignment(Qt::AlignRight | Qt::AlignVCenter); // 奇偶显示不同的背景色 if (i % 2 == 0) @@ -278,7 +278,7 @@ if (devIdx < devRefList.size()) { // 参考通道的显示 QString refText = devRefList.at(devIdx)->text(); - channelNameList.at(devIdx * 16 + refChNo - 1)->setText(QString("CH%1:%2").arg(refChNo).arg(refText.right(refText.length() - 4))); + channelNameList.at(devIdx * 16 + refChNo - 1)->setText(QString("CH%1:%2").arg(refChNo, 2, 10, QLatin1Char('0')).arg(refText.right(refText.length() - 4))); } QMap channelDataJsonMap; @@ -293,6 +293,7 @@ for (int i = 0; i < 16; i++) { QString channelNo = QString::number(i + 1); + QString channelNoStr = QString("%1").arg(i + 1, 2, 10, QLatin1Char('0')); if (i + 1 == refChNo) { @@ -307,23 +308,26 @@ // 通道Label的序号 int chanelIdx = devIdx * 16 + channelDataItem.find("channelNo")->toInt() - 1; - if (channel != nullptr) + if (channel != nullptr && channel->isActive() == true) { // 通道时延值 并计算 减去时延值的测量值 double delay = channel->getDelays().isEmpty() == false ? channel->getDelays().toDouble() : 0.0; double valueMinusDelay = channelDataItem.find("data")->toObject().find("dataValue")->toString().toDouble() - delay * 1E-9; // 设置通道名和测量值的QLabel - channelNameList.at(chanelIdx)->setText(QString("CH%1:%2").arg(channelNo).arg(channel->getChannelCode())); + channelNameList.at(chanelIdx)->setText(QString("CH%1:%2").arg(channelNoStr).arg(channel->getChannelCode())); channelValueList.at(chanelIdx)->setText(QString::number(valueMinusDelay, 'f', 12)); channelNameList.at(chanelIdx)->setProperty("channelId", channel->getChannelId()); channelNameList.at(chanelIdx)->setProperty("deviceId", deviceId); channelNameList.at(chanelIdx)->setProperty("channelNo", channelNo); + } else { + channelNameList.at(chanelIdx)->setText(QString("CH%1:%2").arg(channelNoStr).arg("-")); + channelValueList.at(chanelIdx)->setText(""); } } else { // 没有测量值的通道清空 - channelNameList.at(devIdx * 16 + i)->setText(QString("CH%1:%2").arg(i + 1).arg("-")); + channelNameList.at(devIdx * 16 + i)->setText(QString("CH%1:%2").arg(channelNoStr).arg("-")); channelValueList.at(devIdx * 16 + i)->setText(""); } } @@ -354,7 +358,7 @@ CounterDevice * device = new CounterDevice(this); device->setDeviceId(deviceId); device->setComName(devItem.find("linkComName")->toString()); - device->setBaudRate(115200); + device->setBaudRate(SettingConfig::getInstance().BAUD_RATE); device->setDevCode(devItem.find("deviceNo")->toString()); device->setDeviceName(devName); device->setIsUse(isUse.toInt()); @@ -401,6 +405,7 @@ channel->setChannelId(channelId); channel->setChannelCode(channelCode); channel->setChannelNo(channelNo); + channel->setDelays(delays); // 添加到通道的集合中 key=deviceId-channelNo ConstCache::getInstance().channelMap.insert(deviceId + "-" + channelNo, channel); diff --git a/CounterRealTime/common/utils/QSerialPortUtil.cpp b/CounterRealTime/common/utils/QSerialPortUtil.cpp index 2441c20..7c7cf55 100644 --- a/CounterRealTime/common/utils/QSerialPortUtil.cpp +++ b/CounterRealTime/common/utils/QSerialPortUtil.cpp @@ -21,10 +21,10 @@ serial.setPortName(portName); // 串口名 serial.setBaudRate(baudRate); // 波特率 - open = serial.open(QIODevice::ReadWrite); - if (SettingConfig::getInstance().WORK_TYPE == "mock") { + std::cout << portName.toStdString() << QString(" - %1 - mock").arg(baudRate).toStdString() << std::endl; + // mock data received per second QTimer * timer = new QTimer(this); connect(timer, &QTimer::timeout, @@ -32,7 +32,8 @@ timer->start(1000); } else { - std::cout << portName.toStdString() << QString(" - %1").arg(baudRate).toStdString(); + open = serial.open(QIODevice::ReadWrite); + std::cout << portName.toStdString() << QString(" - %1").arg(baudRate).toStdString() << std::endl; if (open == true) { // 绑定信号与槽 diff --git a/CounterRealTime/common/utils/SettingConfig.h b/CounterRealTime/common/utils/SettingConfig.h index 72448a5..0ed91ea 100644 --- a/CounterRealTime/common/utils/SettingConfig.h +++ b/CounterRealTime/common/utils/SettingConfig.h @@ -29,7 +29,7 @@ void init(); /******** 以下为需要的各类参数 ********/ - qint16 BAUD_RATE; + qint32 BAUD_RATE; qint16 WINDOW_WIDTH; qint16 WINDOW_HEIGHT; diff --git a/CounterRealTime/qss/mainClock.css b/CounterRealTime/qss/mainClock.css index 330aed6..a8ce530 100644 --- a/CounterRealTime/qss/mainClock.css +++ b/CounterRealTime/qss/mainClock.css @@ -3,6 +3,7 @@ /* widgetTitle */ QWidget#widgetTitle QLabel { font-family: "Microsoft Yahei"; + font-weight: bold; color: #FFFFFF; } QWidget#widgetTitle QLabel#labTitle { @@ -51,7 +52,7 @@ QWidget#widgetContent QLabel { font-weight: bold; - font-family: "Micorsoft Yahei"; +/* font-family: "Microsoft Yahei";*/ } QLabel[labType='devTitle4'] { font-size: 28px; @@ -314,25 +315,25 @@ } QWidget#widgetChannel QLabel { - color: #62D8FF; + color: #FFFFFF; font-family: "Microsoft YaHei"; font-size: 16px; } QWidget#widgetChannel QLineEdit { - color: #62D8FF; + color: #FFFFFF; font-family: "Microsoft YaHei"; font-size: 16px; } QWidget#widgetChannel QDoubleSpinBox { - color: #62D8FF; + color: #FFFFFF; font-family: "Microsoft YaHei"; font-size: 16px; } QWidget#widgetChannel QCheckBox { - color: #62D8FF; + color: #FFFFFF; font-family: "Microsoft YaHei"; font-size: 16px; - padding-left: 30px; + padding-left: 15px; } QWidget#widgetChannel QCheckBox::indicator { width: 10px; @@ -350,6 +351,7 @@ QWidget#widgetChannel QLabel[table="header"] { background-color: #1E5A7C; + color: #62D8FF; } QWidget#widgetChannel QLabel[table="trEven"] { background-color: #194B6C;