Files
env-monitor-qt/mainwindow.h
T

82 lines
1.7 KiB
C++

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
// 添加GLIBC兼容性支持
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
// 限制GLIBC版本兼容性到2.31
#if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
# if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 31)
# define GLIBC_MAX_VERSION "2.31"
# endif
#endif
#include <QMainWindow>
#include <QMap>
class QLabel;
class QPushButton;
class QLineEdit;
class QTcpSocket;
class QTimer;
class QSpinBox;
class QCheckBox;
class QComboBox;
class QListWidget;
class QListWidgetItem;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void connectToServer();
void onConnected();
void onDisconnected();
void onReadyRead();
void pollData();
void onReconnectTimeout();
void onReconnectIntervalChanged(int value);
void onDeviceSelectionChanged();
void refreshDevicesList();
void sendControlCommand();
private:
void updateDisplayFromJson(const QJsonObject &obj);
private:
QLineEdit *m_ipEdit;
QLineEdit *m_portEdit;
QPushButton *m_connectBtn;
// 设备列表和选择
QComboBox *m_deviceCombo;
QPushButton *m_refreshBtn;
QLabel *m_currentDeviceLabel;
QLabel *m_tempLabel;
QLabel *m_humLabel;
QLabel *m_buzzerLabel;
QLabel *m_ledLabels[3];
QTcpSocket *m_socket;
QTimer *m_pollTimer;
QTimer *m_reconnectTimer;
QSpinBox *m_pollSpin;
QSpinBox *m_reconnectSpin;
// 控制面板
QCheckBox *m_buzzerChk;
QCheckBox *m_ledChk[3];
QPushButton *m_sendControlBtn;
// 设备数据管理
QString m_currentDeviceId;
QMap<QString, QString> m_deviceData; // device_id -> latest data
};
#endif // MAINWINDOW_H