Tuxi_Test_Qt/src/lightstripmanager.h
zzh 5445380824 修复清空全部sn未生效的问题
修复label匹配值错误的问题
增加版本显示
2025-09-12 10:54:37 +08:00

194 lines
5.7 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef LIGHTSTRIPMANAGER_H
#define LIGHTSTRIPMANAGER_H
#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGroupBox>
#include <QScrollArea>
#include <QCheckBox>
#include <QLabel>
#include <QPushButton>
#include <QLineEdit>
#include <QSpinBox>
#include <QComboBox>
#include <QSettings>
#include <QSet>
#include <QList>
#include <QMessageBox>
#include <QScreen>
#include <QGuiApplication>
#include <QTimer>
#include <QGridLayout>
#include <QSplitter>
#include <QResizeEvent>
// 新增身份信息绑定需要的头文件
#include <QDateTime>
#include <QJsonObject>
#include <QJsonDocument>
class MainWindow; // 前向声明
class LightStripManager : public QWidget
{
Q_OBJECT
public:
explicit LightStripManager(QWidget *parent = nullptr);
~LightStripManager();
// 公共接口
void addSnToList(const QString &sn);
void syncSnListFromMainWindow(const QStringList &snList); // 新增批量同步方法
QStringList getSelectedSns() const;
QStringList getAllSns() const;
int getSnCount() const;
void clearSnList();
// 新增:设置主窗口引用
void setMainWindow(MainWindow *mainWindow);
signals:
void snSelectionChanged(const QStringList &selectedSns);
void lightControlRequested(const QStringList &sns, const QString &color, bool flash, int interval, int duration, bool sound);
void clearAllRequested();
void snCountChanged(int count);
// 新增:身份信息绑定信号
void identityBindingRequested(const QString &sn, const QString &label1, const QString &label2, const QString &label3);
// 修改分组点亮信号添加sound和flashInterval参数
void groupLightRequested(const QString &label1, const QString &label2, const QString &label3,
int rule1, int rule2, int rule3,
const QString &color, int blink, int duration, bool sound, int flashInterval);
private slots:
void onClearSnListClicked();
void onSelectAllClicked();
void onDeselectAllClicked();
void onDeleteSelectedClicked();
void onAddSnManuallyClicked();
void onSearchTextChanged(const QString &text);
void onSendLightSelectedClicked();
void onSendLightAllClicked();
void onCheckBoxStateChanged();
void onRefreshClicked();
// 新增:身份信息绑定相关槽函数
void onBindIdentitySelectedClicked();
void onBindIdentityAllClicked();
void onLabel1Changed(const QString &text);
void onLabel2Changed(const QString &text);
void onLabel3Changed(const QString &text);
// 新增:分组点亮槽函数
void onGroupLightClicked();
private:
void setupUI();
void setupControlPanel();
void setupSnDisplayArea();
void setupLightControlArea();
// 新增:身份信息绑定区域
void setupIdentityBindingArea();
void saveSnList();
void loadSnList();
void updateSnCount();
void updateControlButtons();
void filterSnDisplay(const QString &searchText);
QWidget* createSnWidget(const QString &sn);
void applyResponsiveLayout();
// 新增MQTT发送功能
void sendLightControlMessage(const QStringList &sns);
// 新增:身份信息绑定相关私有函数
void sendIdentityBindingMessage(const QString &sn);
QString generateMessageId() const;
void saveIdentitySettings();
void loadIdentitySettings();
protected:
void resizeEvent(QResizeEvent *event) override;
private:
// UI组件
QVBoxLayout *mainLayout;
QSplitter *mainSplitter;
// 控制面板
QGroupBox *controlGroup;
QHBoxLayout *controlLayout;
QPushButton *selectAllBtn;
QPushButton *deselectAllBtn;
QPushButton *deleteSelectedBtn;
QPushButton *clearAllBtn;
QPushButton *refreshBtn;
QLineEdit *searchEdit;
QLineEdit *manualSnEdit;
QPushButton *addSnBtn;
QLabel *snCountLabel;
// SN显示区域
QGroupBox *snDisplayGroup;
QScrollArea *snScrollArea;
QWidget *snContainerWidget;
QGridLayout *snGridLayout;
// 点亮控制区域
QGroupBox *lightControlGroup;
QComboBox *colorCombo;
QComboBox *flashCombo;
QSpinBox *flashIntervalSpin;
QSpinBox *lightDurationSpin;
QComboBox *soundCombo;
QPushButton *sendLightSelectedBtn;
QPushButton *sendLightAllBtn;
// 新增:分组点亮按钮
QPushButton *groupLightBtn;
// 新增:身份信息绑定区域
QGroupBox *identityBindingGroup;
QLineEdit *label1Edit;
QLineEdit *label2Edit;
QLineEdit *label3Edit;
QComboBox *rule1ComboBox; // label1的匹配规则
QComboBox *rule2ComboBox; // label2的匹配规则
QComboBox *rule3ComboBox; // label3的匹配规则
QPushButton *bindIdentitySelectedBtn;
QPushButton *bindIdentityAllBtn;
QLabel *bindingStatusLabel;
// 数据存储
QSettings *settings;
QSet<QString> snSet;
// 新增:主窗口引用
MainWindow *m_mainWindow;
// 新增:缺失的成员变量
QTimer *resizeTimer;
QSet<QString> uniqueSnSet;
QList<QWidget*> lightStripWidgets;
QList<QCheckBox*> lightStripCheckBoxes;
int columnsPerRow;
// 新增:身份信息绑定相关数据
QString currentLabel1;
QString currentLabel2;
QString currentLabel3;
public:
enum MatchRule {
EQUAL = 0, // = (00)
GREATER = 1, // > (01)
LESS = 2, // < (02)
NOT_EQUAL = 3, // ≠ (03)
NO_MATCH = 4 // ∅ (04) 不参与匹配
};
public slots:
//void onClearSnListClicked();
public:
// 添加公有的清空方法
void clearAllData();
};
#endif // LIGHTSTRIPMANAGER_H