优化代码

This commit is contained in:
zhangsheng 2025-04-23 17:13:05 +08:00
parent 2c42a9eaa7
commit 46a0a87da9
15 changed files with 77 additions and 464 deletions

View File

@ -995,31 +995,11 @@
<string>1倍频幅值</string>
</property>
</item>
<item>
<property name="text">
<string>带回滞1倍频相位</string>
</property>
</item>
<item>
<property name="text">
<string>不带回滞1倍频相位</string>
</property>
</item>
<item>
<property name="text">
<string>2倍频幅值</string>
</property>
</item>
<item>
<property name="text">
<string>带回滞2倍频相位</string>
</property>
</item>
<item>
<property name="text">
<string>不带回滞2倍频相位</string>
</property>
</item>
</widget>
<widget class="QCheckBox" name="checkBox_two_ma_clamp">
<property name="geometry">
@ -1100,31 +1080,11 @@
<string>1倍频幅值</string>
</property>
</item>
<item>
<property name="text">
<string>带回滞1倍频相位</string>
</property>
</item>
<item>
<property name="text">
<string>不带回滞1倍频相位</string>
</property>
</item>
<item>
<property name="text">
<string>2倍频幅值</string>
</property>
</item>
<item>
<property name="text">
<string>带回滞2倍频相位</string>
</property>
</item>
<item>
<property name="text">
<string>不带回滞2倍频相位</string>
</property>
</item>
</widget>
<widget class="QLabel" name="label_7">
<property name="geometry">

View File

@ -40,11 +40,7 @@ typedef enum {
kAccRecorderOutNone = 0,
kAccRecorderOutDirectAmpl = 1,
kAccRecorderOut1XAmpl = 2,
kAccRecorderOut1XPhaseLagWithHysteresis = 3,
kAccRecorderOut1XPhaseLagWithoutHysteresis = 4,
kAccRecorderOut2XAmpl = 5,
kAccRecorderOut2XPhaseLagWithHysteresis = 6,
kAccRecorderOut2XPhaseLagWithoutHysteresis = 7,
kAccRecorderOut2XAmpl = 3,
} AccRecorderOut;
#endif // ACCELERATION_DS_H

View File

@ -118,8 +118,6 @@ void ConfigMgr::Save(QString & file_path) {
QJsonObject x2;
QJsonObject recorder_out;
QJsonObject delay;
QJsonObject not1x;
QJsonObject smax;
QJsonArray latching;
direct["full_scale_range"] = radial_ptr->direct_.full_scale_range;
direct["clamp_value"] = radial_ptr->direct_.clamp_value;
@ -147,16 +145,6 @@ void ConfigMgr::Save(QString & file_path) {
delay["danger"] = radial_ptr->delay_.danger;
delay["active_100ms"] = radial_ptr->delay_.active_100ms;
variables["delay"] = delay;
not1x["checked"] = radial_ptr->not1x_.checked;
not1x["full_scale_range"] = radial_ptr->not1x_.full_scale_range;
not1x["clamp_value"] = radial_ptr->not1x_.clamp_value;
not1x["custom"] = radial_ptr->not1x_.custom;
variables["not1x"] = not1x;
smax["checked"] = radial_ptr->smax_.checked;
smax["full_scale_range"] = radial_ptr->smax_.full_scale_range;
smax["clamp_value"] = radial_ptr->smax_.clamp_value;
smax["custom"] = radial_ptr->smax_.custom;
variables["smax"] = smax;
latching.append(radial_ptr->alert_latching_);
latching.append(radial_ptr->danger_latching_);
variables["latching"] = latching;
@ -450,16 +438,6 @@ void ConfigMgr::Load(QString filename) {
variable->delay_.alert = delay["alert"].toInt();
variable->delay_.danger = delay["danger"].toDouble();
variable->delay_.active_100ms = delay["active_100ms"].toBool();
QJsonObject not1x = tmp_variable["not1x"].toObject();
variable->not1x_.checked = not1x["checked"].toBool();
variable->not1x_.full_scale_range = not1x["full_scale_range"].toInt();
variable->not1x_.clamp_value = not1x["clamp_value"].toDouble();
variable->not1x_.custom = not1x["custom"].toDouble();
QJsonObject smax = tmp_variable["smax"].toObject();
variable->smax_.checked = smax["checked"].toBool();
variable->smax_.full_scale_range = smax["full_scale_range"].toInt();
variable->smax_.clamp_value = smax["clamp_value"].toDouble();
variable->smax_.custom = smax["custom"].toDouble();
QJsonObject latching = tmp_variable["latching"].toObject();
variable->alert_latching_ = latching["alert"].toBool();
variable->danger_latching_ = latching["danger"].toBool();

View File

@ -22,8 +22,16 @@ protected:
QMimeData *mimeData = new QMimeData;
QString customData = item->data(Qt::UserRole).toString();
mimeData->setData("application/x-custom", customData.toUtf8());
// 获取显示文本和 UserRole 数据
QString visibleText = item->text();
QString userData = item->data(Qt::UserRole).toString();
// 使用 QDataStream 打包数据
QByteArray data;
QDataStream stream(&data, QIODevice::WriteOnly);
stream << visibleText << userData; // 包含显示文本和 UserRole 数据
mimeData->setData("application/x-custom", data); // 设置自定义 MIME 数据
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);

View File

@ -14,15 +14,8 @@ typedef enum {
typedef enum {
kDisRecorderOutNone = 0,
kDisRecorderOutDirectAmpl = 1,
kDisRecorderOutGap = 2,
kDisRecorderOut1XAmpl = 3,
kDisRecorderOut1XPhaseLagWithHysteresis = 4,
kDisRecorderOut1XPhaseLagWithoutHysteresis = 5,
kDisRecorderOut2XAmpl = 6,
kDisRecorderOut2XPhaseLagWithHysteresis = 7,
kDisRecorderOut2XPhaseLagWithoutHysteresis = 8,
kDisRecorderOutNot1XAmpl = 9,
kDisRecorderOutSmaxAmpl = 10
kDisRecorderOut1XAmpl = 2,
kDisRecorderOut2XAmpl = 3
} DisRecorderOut;
#endif // DISPLACEMENT_DS_H

View File

@ -290,8 +290,9 @@ void MainWindow::onMenuActionTriggered() {
ConfigMgr::Instance()->card_type_[button_id + 1] != kCardNone)) {
QMessageBox::information(this, QStringLiteral("提示"), "不要重叠三冗余板卡配置,请在创建新配置之前移除现有的配置!");
return;
} else if (card_type == kCardRelayTMRPrimary && map_slot_config[button_id + 1].slot_type == "" \
&& map_slot_config[button_id + 2].slot_type == "") {
} else if (card_type == kCardRelayTMRPrimary && ConfigMgr::Instance()->card_type_[button_id - 1] == kCardNone \
&& ConfigMgr::Instance()->card_type_[button_id] == kCardNone &&
ConfigMgr::Instance()->card_type_[button_id + 1] == kCardNone) {
map_slot_config[button_id].slot_type = slot_type;
map_slot_config[button_id].slot_btn->setText(chan_display);
map_slot_config[button_id + 1].slot_type = slot_type;
@ -309,7 +310,7 @@ void MainWindow::onMenuActionTriggered() {
ConfigMgr::Instance()->card_type_[button_id] != kCardNone)) {
QMessageBox::information(this, QStringLiteral("提示"), "不要重叠两板卡配置,请在创建新配置之前移除现有的配置!");
return;
} else if (rack_type == "两板卡" && ConfigMgr::Instance()->card_type_[button_id - 1] != kCardNone) {
} else if (rack_type == "两板卡" && ConfigMgr::Instance()->card_type_[button_id - 1] == kCardNone) {
map_slot_config[button_id].slot_type = slot_type;
map_slot_config[button_id].slot_btn->setText(chan_display);
map_slot_config[button_id + 1].slot_type = slot_type;
@ -317,7 +318,7 @@ void MainWindow::onMenuActionTriggered() {
}
if ((card_type == kCardVibSingle || card_type == kCardSpeedSingle ||
card_type == kCardKeyphaseSingle || card_type == kCardRelaySingle ||
card_type == kCardRelaySingleNOK) && ConfigMgr::Instance()->card_type_[button_id - 1] != kCardNone) {
card_type == kCardRelaySingleNOK) && ConfigMgr::Instance()->card_type_[button_id - 1] == kCardNone) {
map_slot_config[button_id].slot_type = slot_type;
button->setText(chan_display);
ConfigMgr::Instance()->card_type_[button_id - 1] = card_type;
@ -470,6 +471,8 @@ void MainWindow::OnButtonGroup(QAbstractButton *slot_btn) {
QString object_name = slot_btn->objectName();
int button_id = object_name.right(object_name.length() - 15).toInt();
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(button_id);
if(base_ptr == nullptr)
return;
switch(base_ptr->card_type_){
case kCardVibSingle:{
QString object_name = slot_btn->objectName();
@ -492,6 +495,9 @@ void MainWindow::OnButtonGroup(QAbstractButton *slot_btn) {
if(slot_btn != NULL && ui->pushButton_point_name->isChecked()){
QString object_name = slot_btn->objectName();
int button_id = object_name.right(object_name.length() - 15).toInt();
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(button_id);
if(base_ptr == nullptr)
return;
PointName *point_name = new PointName(button_id,ConfigMgr::Instance()->card_type_[button_id - 1]);
point_name->setWindowModality(Qt::ApplicationModal);
point_name->show();

View File

@ -60,26 +60,6 @@ void Radial::on_checkBox_2x_ampl_toggled(bool checked) {
ui->doubleSpinBox_2x_phase_lag_clamp->setEnabled(false);
}
void Radial::on_checkBox_not_1x_ampl_toggled(bool checked) {
if (checked) {
ui->comboBox_not_1x_ampl->setEnabled(true);
ui->doubleSpinBox_not_1x_ampl_clamp->setEnabled(true);
return;
}
ui->comboBox_not_1x_ampl->setEnabled(false);
ui->doubleSpinBox_not_1x_ampl_clamp->setEnabled(false);
}
void Radial::on_checkBox_smax_ampl_toggled(bool checked) {
if (checked) {
ui->comboBox_smax_range->setEnabled(true);
ui->doubleSpinBox_smax_clamp->setEnabled(true);
return;
}
ui->comboBox_smax_range->setEnabled(false);
ui->doubleSpinBox_smax_clamp->setEnabled(false);
}
void Radial::Init() {
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no);
if (base_ptr == nullptr) {
@ -119,14 +99,6 @@ void Radial::Init() {
ui->comboBox_2x_value_range->setCurrentIndex(variable_ptr->x2_.full_scale_range);
ui->doubleSpinBox_2x_ampl_clamp->setValue(variable_ptr->x2_.clamp_value);
ui->doubleSpinBox_2x_phase_lag_clamp->setValue(variable_ptr->x2_.phase_lag);
ui->checkBox_not_1x_ampl->setChecked(variable_ptr->not1x_.checked);
ui->comboBox_not_1x_ampl->setCurrentIndex(variable_ptr->not1x_.full_scale_range);
ui->doubleSpinBox_not_1x_ampl_clamp->setValue(variable_ptr->not1x_.clamp_value);
// ui->doubleSpinBox_2x_phase_lag_clamp->setValue(variable_ptr->not1x_.custom);
ui->checkBox_smax_ampl->setChecked(variable_ptr->smax_.checked);
ui->comboBox_smax_range->setCurrentIndex(variable_ptr->smax_.full_scale_range);
ui->doubleSpinBox_smax_clamp->setValue(variable_ptr->smax_.clamp_value);
// ui->doubleSpinBox_2x_phase_lag_clamp->setValue(variable_ptr->smax_.custom);
ui->spinBox_alert->setValue(variable_ptr->delay_.alert);
ui->doubleSpinBox_danger->setValue(variable_ptr->delay_.danger);
ui->checkBox_100ms->setChecked(variable_ptr->delay_.active_100ms);
@ -184,14 +156,6 @@ void Radial::on_pushButton_confirm_clicked() {
variable->recorder_out_.trip_multiply = ui->doubleSpinBox_trip_multiply->value();
variable->recorder_out_.comparision = ui->comboBox_comparision->currentIndex();
variable->recorder_out_.percentage = ui->spinBox_comparision_percentage->value();
variable->not1x_.checked = ui->checkBox_not_1x_ampl->isChecked();
variable->not1x_.full_scale_range = ui->comboBox_not_1x_ampl->currentIndex();
variable->not1x_.clamp_value = ui->doubleSpinBox_1x_ampl_clamp->value();
variable->not1x_.custom = 0; // TODO:
variable->smax_.checked = ui->checkBox_smax_ampl->isChecked();
variable->smax_.full_scale_range = ui->comboBox_smax_range->currentIndex();
variable->smax_.clamp_value = ui->doubleSpinBox_smax_clamp->value();
variable->smax_.custom = 0; // TODO:
variable->delay_.alert = ui->spinBox_alert->value();
variable->delay_.danger = ui->doubleSpinBox_danger->value();
variable->delay_.active_100ms = ui->checkBox_100ms->isChecked();
@ -229,14 +193,6 @@ void Radial::on_pushButton_confirm_clicked() {
variable->recorder_out_.trip_multiply = ui->doubleSpinBox_trip_multiply->value();
variable->recorder_out_.comparision = ui->comboBox_comparision->currentIndex();
variable->recorder_out_.percentage = ui->spinBox_comparision_percentage->value();
variable->not1x_.checked = ui->checkBox_not_1x_ampl->isChecked();
variable->not1x_.full_scale_range = ui->comboBox_not_1x_ampl->currentIndex();
variable->not1x_.clamp_value = ui->doubleSpinBox_1x_ampl_clamp->value();
variable->not1x_.custom = 0; // TODO:
variable->smax_.checked = ui->checkBox_smax_ampl->isChecked();
variable->smax_.full_scale_range = ui->comboBox_smax_range->currentIndex();
variable->smax_.clamp_value = ui->doubleSpinBox_smax_clamp->value();
variable->smax_.custom = 0; // TODO:
variable->delay_.alert = ui->spinBox_alert->value();
variable->delay_.danger = ui->doubleSpinBox_danger->value();
variable->delay_.active_100ms = ui->checkBox_100ms->isChecked();

View File

@ -678,162 +678,6 @@
</property>
</item>
</widget>
<widget class="QCheckBox" name="checkBox_not_1x_ampl">
<property name="geometry">
<rect>
<x>20</x>
<y>240</y>
<width>91</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>非1倍频幅值</string>
</property>
</widget>
<widget class="QComboBox" name="comboBox_not_1x_ampl">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>130</x>
<y>240</y>
<width>111</width>
<height>22</height>
</rect>
</property>
<property name="currentIndex">
<number>4</number>
</property>
<item>
<property name="text">
<string>0-100 um</string>
</property>
</item>
<item>
<property name="text">
<string>0-150 um</string>
</property>
</item>
<item>
<property name="text">
<string>0-200 um</string>
</property>
</item>
<item>
<property name="text">
<string>0-400 um</string>
</property>
</item>
<item>
<property name="text">
<string>0-500 um</string>
</property>
</item>
<item>
<property name="text">
<string>自定义</string>
</property>
</item>
</widget>
<widget class="QDoubleSpinBox" name="doubleSpinBox_not_1x_ampl_clamp">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>260</x>
<y>240</y>
<width>62</width>
<height>22</height>
</rect>
</property>
<property name="decimals">
<number>0</number>
</property>
<property name="maximum">
<double>1000.000000000000000</double>
</property>
</widget>
<widget class="QComboBox" name="comboBox_smax_range">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>130</x>
<y>270</y>
<width>111</width>
<height>22</height>
</rect>
</property>
<property name="currentIndex">
<number>4</number>
</property>
<item>
<property name="text">
<string>0-100 um</string>
</property>
</item>
<item>
<property name="text">
<string>0-150 um</string>
</property>
</item>
<item>
<property name="text">
<string>0-200 um</string>
</property>
</item>
<item>
<property name="text">
<string>0-400 um</string>
</property>
</item>
<item>
<property name="text">
<string>0-500 um</string>
</property>
</item>
<item>
<property name="text">
<string>自定义</string>
</property>
</item>
</widget>
<widget class="QCheckBox" name="checkBox_smax_ampl">
<property name="geometry">
<rect>
<x>20</x>
<y>270</y>
<width>91</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string> Smax 幅值</string>
</property>
</widget>
<widget class="QDoubleSpinBox" name="doubleSpinBox_smax_clamp">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>260</x>
<y>270</y>
<width>62</width>
<height>22</height>
</rect>
</property>
<property name="decimals">
<number>0</number>
</property>
<property name="maximum">
<double>1000.000000000000000</double>
</property>
</widget>
<widget class="QGroupBox" name="groupBox_12">
<property name="geometry">
<rect>
@ -1042,51 +886,16 @@
<string>直接幅值</string>
</property>
</item>
<item>
<property name="text">
<string>间隙</string>
</property>
</item>
<item>
<property name="text">
<string>1倍频幅值</string>
</property>
</item>
<item>
<property name="text">
<string>带回滞1倍频相位</string>
</property>
</item>
<item>
<property name="text">
<string>不带回滞1倍频相位</string>
</property>
</item>
<item>
<property name="text">
<string>2倍频幅值</string>
</property>
</item>
<item>
<property name="text">
<string>带回滞2倍频相位</string>
</property>
</item>
<item>
<property name="text">
<string>不带回滞2倍频相位</string>
</property>
</item>
<item>
<property name="text">
<string>非1倍频幅值</string>
</property>
</item>
<item>
<property name="text">
<string>Smax幅值</string>
</property>
</item>
</widget>
<widget class="QCheckBox" name="checkBox_two_ma_clamp">
<property name="geometry">
@ -1152,51 +961,16 @@
<string>直接幅值</string>
</property>
</item>
<item>
<property name="text">
<string>间隙</string>
</property>
</item>
<item>
<property name="text">
<string>1倍频幅值</string>
</property>
</item>
<item>
<property name="text">
<string>带回滞1倍频相位</string>
</property>
</item>
<item>
<property name="text">
<string>不带回滞1倍频相位</string>
</property>
</item>
<item>
<property name="text">
<string>2倍频幅值</string>
</property>
</item>
<item>
<property name="text">
<string>带回滞2倍频相位</string>
</property>
</item>
<item>
<property name="text">
<string>不带回滞2倍频相位</string>
</property>
</item>
<item>
<property name="text">
<string>非1倍频幅值</string>
</property>
</item>
<item>
<property name="text">
<string>Smax幅值</string>
</property>
</item>
</widget>
<widget class="QSpinBox" name="spinBox_comparision_percentage">
<property name="enabled">

View File

@ -12,10 +12,12 @@ SingleRelay::SingleRelay(int slot,int cardtype,QWidget *parent)
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
QVBoxLayout *layout_relay = new QVBoxLayout(ui->widget_relay);
textEdit_relay = new DropTextEdit;
textEdit_relay->setAcceptDrops(true);
layout_relay->addWidget(textEdit_relay);
QVBoxLayout *layout_available = new QVBoxLayout(ui->widget_available);
list_widget_available = new DraggableListWidget;
list_widget_available = new DraggableListWidget();
layout_available->addWidget(list_widget_available);
list_widget_available->setDragEnabled(true);
btnGroup_slot = new QButtonGroup(this);
btnGroup_slot->addButton(ui->pushButton_slot1);
@ -36,13 +38,15 @@ SingleRelay::SingleRelay(int slot,int cardtype,QWidget *parent)
btnGroup_slot->addButton(ui->pushButton_slot16);
connect(btnGroup_slot, SIGNAL(buttonClicked(QAbstractButton *)), this, SLOT(OnButtonGroup(QAbstractButton *)));
connect(ui->pushButton_backspace, &QPushButton::clicked, textEdit_relay, &DropTextEdit::removeLastElement);
//connect(ui->pushButton_backspace, &QPushButton::clicked, textEdit_relay, &DropTextEdit::removeLastElement);
connect(ui->comboBox_relay_ch, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &SingleRelay::onComboBoxIndexChanged);
Init();
current_index = ui->comboBox_relay_ch->currentIndex();
if(single_relay_nok_data->single_relay_nok[current_index].logic_expression != "")
textEdit_relay->setPlainText(single_relay_nok_data->single_relay_nok[current_index].logic_expression);
if(single_relay_nok_data->single_relay_nok[current_index].logic_expression != ""){
QString channel_name = channelNameMap[single_relay_nok_data->single_relay_nok[current_index].logic_expression];
textEdit_relay->setPlainText(channel_name);
}
}
SingleRelay::~SingleRelay() {
@ -88,7 +92,22 @@ void SingleRelay::Init(){
return;
}
single_relay_nok_data = std::dynamic_pointer_cast<SingleRelayDataNOK>(base_ptr);
for(int i = 0 ; i < SLOT_NUM ; i++){
std::shared_ptr<CardBase> cardbase_ptr = ConfigMgr::Instance()->GetSlotPtr(i + 1);
if(cardbase_ptr != nullptr &&
cardbase_ptr->card_type_ == kCardVibSingle){
std::shared_ptr<VibrationData> ptr = std::dynamic_pointer_cast<VibrationData>(cardbase_ptr);
for (int var = 0; var < CHANNEL_COUNT; ++var) {
QString item_data,item_str;
item_str = QString("%1 (槽位 %2 通道 %3 非OK)").arg(ptr->base_config_[var].point_name).arg(ptr->base_config_[var].chan_id.mid(1,2)).arg(ptr->base_config_[var].chan_id.mid(4,2));
item_data = QString("%1P##NO").arg(ptr->base_config_[var].chan_id);
channelNameMap[item_data] = item_str;
}
}else if(cardbase_ptr != nullptr &&
cardbase_ptr->card_type_ == kCardSpeedSingle){
}
}
}
void SingleRelay::on_pushButton_cancel_clicked() {
this->close();
@ -105,7 +124,7 @@ void SingleRelay::OnButtonGroup(QAbstractButton *slot_btn) {
std::shared_ptr<VibrationData> vib_data = std::dynamic_pointer_cast<VibrationData>(base_ptr);
if((vib_data->base_config_[var].standby && vib_data->base_config_[var + 1].standby && !(var % 2)))
continue;
QString item_str = QString("%1 (Slot %2 Channel %3 Not OK)").arg(vib_data->base_config_[var].point_name).arg(button_id).arg(var+1);
QString item_str = QString("%1 (槽位 %2 通道 %3 非OK)").arg(vib_data->base_config_[var].point_name).arg(button_id).arg(var+1);
QListWidgetItem *item = new QListWidgetItem(item_str);
QString item_data = QString("S%1C%2P##NO").arg(QString::number(button_id, 10).rightJustified(2, '0')).arg(QString::number(var+1, 10).rightJustified(2, '0'));
item->setData(Qt::UserRole, item_data);
@ -147,7 +166,19 @@ void SingleRelay::on_pushButton_confirm_clicked()
void SingleRelay::onComboBoxIndexChanged(int index){
qDebug()<< "[SingleRelay]:index " << index;
single_relay_nok_data->single_relay_nok[current_index].logic_expression = textEdit_relay->toPlainText();
QString html = textEdit_relay->toHtml();
qDebug() << html ;
QRegularExpression spanRegex(R"(<span[^>]*data-key='([^']+)'[^>]*>([^<]+)</span>)");
QRegularExpressionMatchIterator i = spanRegex.globalMatch(html);
QString userData = "",visibleText = "";
while (i.hasNext()) {
QRegularExpressionMatch match = i.next();
userData = match.captured(1);
visibleText = match.captured(2);
}
qDebug() << "Extracted data-key:" << userData << ", text:" << visibleText;
single_relay_nok_data->single_relay_nok[current_index].logic_expression = userData;
current_index = index;
textEdit_relay->setPlainText(single_relay_nok_data->single_relay_nok[index].logic_expression);
}

View File

@ -20,52 +20,7 @@ public:
setAcceptDrops(true);
}
public slots:
void removeLastElement() {
QString html = this->toHtml();
// 匹配 <span>元素</span>
QRegularExpression spanRe(R"(<span[^>]*>[^<]*</span>)");
QRegularExpressionMatchIterator spanIt = spanRe.globalMatch(html);
// 匹配符号元素(注意符号两边可能有空格)
QRegularExpression symbolRe(R"((\s?[+*()]\s?))");
QRegularExpressionMatchIterator symbolIt = symbolRe.globalMatch(html);
// 保存所有匹配结果:位置 + 匹配内容
struct Match {
int start;
int length;
};
QList<Match> matches;
while (spanIt.hasNext()) {
auto m = spanIt.next();
matches.append({ m.capturedStart(), m.capturedLength() });
}
while (symbolIt.hasNext()) {
auto m = symbolIt.next();
matches.append({ m.capturedStart(), m.capturedLength() });
}
if (matches.isEmpty())
return;
// 找出最后出现的元素
std::sort(matches.begin(), matches.end(), [](const Match &a, const Match &b) {
return a.start < b.start;
});
// 删除最后一个匹配
Match last = matches.last();
html.remove(last.start, last.length);
this->setHtml(html);
// 保持光标在末尾
QTextCursor cursor = this->textCursor();
cursor.movePosition(QTextCursor::End);
this->setTextCursor(cursor);
}
protected:
void dragEnterEvent(QDragEnterEvent *event) override {
if (event->mimeData()->hasFormat("application/x-custom")) {
@ -90,22 +45,17 @@ protected:
}
if (event->mimeData()->hasFormat("application/x-custom")) {
QByteArray data = event->mimeData()->data("application/x-custom");
QDataStream stream(&data, QIODevice::ReadOnly);
QString visibleText, userData;
stream >> visibleText >> userData; // 解析显示文本和 UserRole 数据
qDebug() << visibleText << userData;
QString text = QString::fromUtf8(data);
QTextCursor cursor = this->textCursor();
this->setTextCursor(cursor);
QString html = QString(
"<span style='"
"background:#ddd;"
"padding:2px 6px;"
"border-radius:4px;"
"border:1px solid #aaa;"
"outline: none;"
"box-shadow: none;"
"text-shadow: none;"
"display:inline-block;'>%1</span>"
).arg(text);
QString html = QString("<span data-key='%1' style='color:black;'>%2</span>&nbsp;")
.arg(userData.toHtmlEscaped(), visibleText.toHtmlEscaped());
cursor.insertHtml(html);
event->acceptProposedAction();
} else {
@ -143,6 +93,8 @@ private:
DropTextEdit *textEdit_relay = nullptr;
std::shared_ptr<SingleRelayDataNOK> single_relay_nok_data = nullptr;
int current_index;
QMap<QString, QString> channelNameMap;
void Init();
};

View File

@ -139,7 +139,7 @@ void TMRRelayAssociation::Init(){
channelNameMap[item_data] = item_str;
}
}else if(cardbase_ptr != nullptr &&
(cardbase_ptr->card_type_ == kCardSpeedSingle)){
cardbase_ptr->card_type_ == kCardSpeedSingle){
}
}
@ -148,6 +148,7 @@ void TMRRelayAssociation::Init(){
setExpressionToTreeView(treeView_relay, relay_data->tmr_relay[current_index].logic_expression);
}
}
ExprNode* TMRRelayAssociation::parseExpression(const QString& expr, int& pos) {
auto skipSpaces = [&]() {
while (pos < expr.length() && expr[pos].isSpace()) pos++;
@ -375,7 +376,6 @@ ExprValidationResult TMRRelayAssociation::validateLogicExpression(const QString&
}
void TMRRelayAssociation::buildTreeFromExpression(QTreeView *treeView, const QString &expr) {
QStandardItemModel* model = new QStandardItemModel();
QStandardItem* rootItem = parseExpression(expr);
if (rootItem) {
@ -404,6 +404,8 @@ void TMRRelayAssociation::OnButtonGroup(QAbstractButton *slot_btn) {
list_widget_available->addItem(item_or);
for(int var = 0; var < CHANNEL_COUNT ; ++var){
QString item_data;
if(ptr->base_config_[var].standby && ptr->base_config_[var + 1].standby && (var % 2))
continue;
if(ptr->alert_danger[var].direct_enable ||
ptr->alert_danger[var].x1_ampl_enable ||
ptr->alert_danger[var].x2_ampl_enable){

View File

@ -9,6 +9,7 @@
#include <QStandardItemModel> //数据模型类
#include <QTreeView>
#include "tmrrelayassociation_data.h"
#include <QListWidget>
namespace Ui {
class TMRRelayAssociation;

View File

@ -973,7 +973,7 @@
<x>130</x>
<y>20</y>
<width>54</width>
<height>12</height>
<height>21</height>
</rect>
</property>
<property name="text">
@ -996,7 +996,7 @@
<x>610</x>
<y>80</y>
<width>251</width>
<height>421</height>
<height>441</height>
</rect>
</property>
</widget>

View File

@ -859,31 +859,11 @@
<string>1倍频幅值</string>
</property>
</item>
<item>
<property name="text">
<string>带回滞1倍频相位</string>
</property>
</item>
<item>
<property name="text">
<string>不带回滞1倍频相位</string>
</property>
</item>
<item>
<property name="text">
<string>2倍频幅值</string>
</property>
</item>
<item>
<property name="text">
<string>带回滞2倍频相位</string>
</property>
</item>
<item>
<property name="text">
<string>不带回滞2倍频相位</string>
</property>
</item>
</widget>
<widget class="QCheckBox" name="checkBox_two_ma_clamp">
<property name="geometry">
@ -954,31 +934,11 @@
<string>1倍频幅值</string>
</property>
</item>
<item>
<property name="text">
<string>带回滞1倍频相位</string>
</property>
</item>
<item>
<property name="text">
<string>不带回滞1倍频相位</string>
</property>
</item>
<item>
<property name="text">
<string>2倍频幅值</string>
</property>
</item>
<item>
<property name="text">
<string>带回滞2倍频相位</string>
</property>
</item>
<item>
<property name="text">
<string>不带回滞2倍频相位</string>
</property>
</item>
</widget>
<widget class="QSpinBox" name="spinBox_comparision_percentage">
<property name="enabled">

View File

@ -30,11 +30,7 @@ typedef enum {
kVelRecorderOutNone = 0,
kVelRecorderOutDirectAmpl = 1,
kVelRecorderOut1XAmpl = 2,
kVelRecorderOut1XPhaseLagWithHysteresis = 3,
kVelRecorderOut1XPhaseLagWithoutHysteresis = 4,
kVelRecorderOut2XAmpl = 5,
kVelRecorderOut2XPhaseLagWithHysteresis = 6,
kVelRecorderOut2XPhaseLagWithoutHysteresis = 7,
kVelRecorderOut2XAmpl = 3
} VelRecorderOut;
#endif // VELOCITY_DS_H