修复清空全部sn未生效的问题
修复label匹配值错误的问题 增加版本显示
This commit is contained in:
parent
e098025c47
commit
5445380824
@ -1,10 +1,11 @@
|
||||
#include "lightstripmanager.h"
|
||||
#include <QThread>
|
||||
#include <QStandardPaths>
|
||||
// 如果不再需要可以删除: #include <QRandomGenerator>
|
||||
|
||||
LightStripManager::LightStripManager(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, settings(new QSettings("LightStripManager", "Config", this))
|
||||
, settings(new QSettings("TuxiApp", "LightStripSN", this))
|
||||
, columnsPerRow(4)
|
||||
, resizeTimer(new QTimer(this))
|
||||
{
|
||||
@ -1130,9 +1131,28 @@ int LightStripManager::getSnCount() const
|
||||
|
||||
void LightStripManager::saveSnList()
|
||||
{
|
||||
QStringList snList = uniqueSnSet.values();
|
||||
settings->setValue("lightStripSnList", snList);
|
||||
if (uniqueSnSet.isEmpty()) {
|
||||
// 如果集合为空,删除配置项而不是保存空列表
|
||||
settings->remove("lightStripSnList");
|
||||
qDebug() << "已删除lightStripSnList配置项";
|
||||
} else {
|
||||
// 如果有数据,正常保存
|
||||
QStringList snList = uniqueSnSet.values();
|
||||
settings->setValue("lightStripSnList", snList);
|
||||
qDebug() << "已保存" << snList.size() << "个SN到lightStripSnList";
|
||||
}
|
||||
|
||||
// 强制同步到磁盘
|
||||
settings->sync();
|
||||
|
||||
// 检查同步状态
|
||||
QSettings::Status status = settings->status();
|
||||
if (status != QSettings::NoError) {
|
||||
qDebug() << "保存配置文件时出错,状态码:" << status;
|
||||
qDebug() << "配置文件路径:" << settings->fileName();
|
||||
} else {
|
||||
qDebug() << "配置保存成功,路径:" << settings->fileName();
|
||||
}
|
||||
}
|
||||
|
||||
void LightStripManager::loadSnList()
|
||||
@ -1429,10 +1449,10 @@ void LightStripManager::onGroupLightClicked()
|
||||
bool sound = soundCombo->currentIndex() == 1; // 正确获取sound值
|
||||
int flashInterval = flashIntervalSpin->value(); // 正确获取flashInterval值
|
||||
|
||||
// 获取各label的匹配规则(转换为int)
|
||||
int rule1 = rule1ComboBox->currentText().split("-")[0].toInt();
|
||||
int rule2 = rule2ComboBox->currentText().split("-")[0].toInt();
|
||||
int rule3 = rule3ComboBox->currentText().split("-")[0].toInt();
|
||||
// 获取各label的匹配规则(使用currentData获取正确的数值)
|
||||
int rule1 = rule1ComboBox->currentData().toInt();
|
||||
int rule2 = rule2ComboBox->currentData().toInt();
|
||||
int rule3 = rule3ComboBox->currentData().toInt();
|
||||
|
||||
// 发射分组点亮信号(添加sound和flashInterval参数)
|
||||
emit groupLightRequested(label1Edit->text(), label2Edit->text(), label3Edit->text(),
|
||||
@ -1442,6 +1462,40 @@ void LightStripManager::onGroupLightClicked()
|
||||
bindingStatusLabel->setText("分组点亮指令已发送");
|
||||
bindingStatusLabel->setStyleSheet("QLabel { color: green; }");
|
||||
}
|
||||
|
||||
void LightStripManager::clearAllData()
|
||||
{
|
||||
// 调用私有的清空方法
|
||||
onClearSnListClicked();
|
||||
}
|
||||
|
||||
void LightStripManager::syncSnListFromMainWindow(const QStringList &snList)
|
||||
{
|
||||
// 清空现有数据但不保存
|
||||
for (QWidget *widget : lightStripWidgets) {
|
||||
delete widget;
|
||||
}
|
||||
lightStripWidgets.clear();
|
||||
lightStripCheckBoxes.clear();
|
||||
uniqueSnSet.clear();
|
||||
|
||||
// 批量添加但不保存
|
||||
for (const QString &sn : snList) {
|
||||
if (!uniqueSnSet.contains(sn)) {
|
||||
uniqueSnSet.insert(sn);
|
||||
QWidget *lightStripWidget = createSnWidget(sn);
|
||||
lightStripWidgets.append(lightStripWidget);
|
||||
}
|
||||
}
|
||||
|
||||
// 统一更新界面
|
||||
applyResponsiveLayout();
|
||||
updateSnCount();
|
||||
updateControlButtons();
|
||||
|
||||
// 不调用saveSnList(),避免重新生成配置
|
||||
}
|
||||
|
||||
void LightStripManager::setupIdentityBindingArea()
|
||||
{
|
||||
identityBindingGroup = new QGroupBox("身份信息绑定", this);
|
||||
@ -1496,11 +1550,11 @@ void LightStripManager::setupIdentityBindingArea()
|
||||
label1Layout->addWidget(label1Edit);
|
||||
|
||||
rule1ComboBox = new QComboBox();
|
||||
rule1ComboBox->addItem("= (等于)", 1);
|
||||
rule1ComboBox->addItem("> (大于)", 2);
|
||||
rule1ComboBox->addItem("< (小于)", 3);
|
||||
rule1ComboBox->addItem("≠ (不等于)", 4);
|
||||
rule1ComboBox->addItem("∅ (不参与匹配)", 0);
|
||||
rule1ComboBox->addItem("= (等于)", 0);
|
||||
rule1ComboBox->addItem("> (大于)", 1);
|
||||
rule1ComboBox->addItem("< (小于)", 2);
|
||||
rule1ComboBox->addItem("≠ (不等于)", 3);
|
||||
rule1ComboBox->addItem("∅ (不参与匹配)", 4);
|
||||
rule1ComboBox->setMinimumWidth(120);
|
||||
rule1ComboBox->setStyleSheet(
|
||||
"QComboBox { "
|
||||
@ -1549,11 +1603,11 @@ void LightStripManager::setupIdentityBindingArea()
|
||||
label2Layout->addWidget(label2Edit);
|
||||
|
||||
rule2ComboBox = new QComboBox();
|
||||
rule2ComboBox->addItem("= (等于)", 1);
|
||||
rule2ComboBox->addItem("> (大于)", 2);
|
||||
rule2ComboBox->addItem("< (小于)", 3);
|
||||
rule2ComboBox->addItem("≠ (不等于)", 4);
|
||||
rule2ComboBox->addItem("∅ (不参与匹配)", 0);
|
||||
rule2ComboBox->addItem("= (等于)", 0);
|
||||
rule2ComboBox->addItem("> (大于)", 1);
|
||||
rule2ComboBox->addItem("< (小于)", 2);
|
||||
rule2ComboBox->addItem("≠ (不等于)", 3);
|
||||
rule2ComboBox->addItem("∅ (不参与匹配)", 4);
|
||||
rule2ComboBox->setMinimumWidth(120);
|
||||
rule2ComboBox->setStyleSheet(
|
||||
"QComboBox { "
|
||||
@ -1602,11 +1656,11 @@ void LightStripManager::setupIdentityBindingArea()
|
||||
label3Layout->addWidget(label3Edit);
|
||||
|
||||
rule3ComboBox = new QComboBox();
|
||||
rule3ComboBox->addItem("= (等于)", 1);
|
||||
rule3ComboBox->addItem("> (大于)", 2);
|
||||
rule3ComboBox->addItem("< (小于)", 3);
|
||||
rule3ComboBox->addItem("≠ (不等于)", 4);
|
||||
rule3ComboBox->addItem("∅ (不参与匹配)", 0);
|
||||
rule3ComboBox->addItem("= (等于)", 0);
|
||||
rule3ComboBox->addItem("> (大于)", 1);
|
||||
rule3ComboBox->addItem("< (小于)", 2);
|
||||
rule3ComboBox->addItem("≠ (不等于)", 3);
|
||||
rule3ComboBox->addItem("∅ (不参与匹配)", 4);
|
||||
rule3ComboBox->setMinimumWidth(120);
|
||||
rule3ComboBox->setStyleSheet(
|
||||
"QComboBox { "
|
||||
|
||||
@ -39,6 +39,7 @@ public:
|
||||
|
||||
// 公共接口
|
||||
void addSnToList(const QString &sn);
|
||||
void syncSnListFromMainWindow(const QStringList &snList); // 新增批量同步方法
|
||||
QStringList getSelectedSns() const;
|
||||
QStringList getAllSns() const;
|
||||
int getSnCount() const;
|
||||
@ -182,6 +183,12 @@ private:
|
||||
NOT_EQUAL = 3, // ≠ (03)
|
||||
NO_MATCH = 4 // ∅ (04) 不参与匹配
|
||||
};
|
||||
public slots:
|
||||
//void onClearSnListClicked();
|
||||
|
||||
public:
|
||||
// 添加公有的清空方法
|
||||
void clearAllData();
|
||||
};
|
||||
|
||||
#endif // LIGHTSTRIPMANAGER_H
|
||||
@ -59,7 +59,7 @@ MainWindow::~MainWindow()
|
||||
}
|
||||
|
||||
void MainWindow::setupUI() {
|
||||
setWindowTitle("兔喜Test Author:Zhangzhenghao Email:zzh9953477@gmail.com");
|
||||
setWindowTitle("兔喜Test1.2 Author:Zhangzhenghao Email:zzh9953477@gmail.com");
|
||||
|
||||
// 参考qt_bak的合理尺寸设置,增加竖向高度
|
||||
setMinimumSize(850, 720); // 增加最小高度
|
||||
@ -1020,11 +1020,13 @@ void MainWindow::onClearSnListClicked()
|
||||
// 更新计数显示
|
||||
snCountLabel->setText("已发现灯条: 0 个");
|
||||
|
||||
// 移除对lightStripManager的直接调用
|
||||
// 让灯条管理器独立管理自己的数据
|
||||
// 不再调用saveSnList(),让LightStripManager管理数据
|
||||
// saveSnList(); // 删除这行
|
||||
|
||||
// 保存设置
|
||||
saveSnList();
|
||||
// 如果LightStripManager存在,调用公有的清空方法
|
||||
if (lightStripManager) {
|
||||
lightStripManager->clearAllData();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::openLightStripManager()
|
||||
@ -1289,9 +1291,8 @@ void MainWindow::openLightStripManager()
|
||||
this, &MainWindow::onLightStripManagerClosed);
|
||||
|
||||
// 同步当前的SN列表到管理器
|
||||
for (const QString &sn : uniqueSnSet) {
|
||||
lightStripManager->addSnToList(sn);
|
||||
}
|
||||
QStringList snList = uniqueSnSet.values();
|
||||
lightStripManager->syncSnListFromMainWindow(snList);
|
||||
}
|
||||
|
||||
lightStripManager->show();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user