#ifndef SIGNALMEASUREMENTWIDGET_H #define SIGNALMEASUREMENTWIDGET_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "../hardware/channelmanager.h" #include "channelstatuswidget.h" /** * @brief 信号测量功能模块基类 * 提供统一的工业风格UI框架 */ class MeasurementModuleBase : public QWidget { Q_OBJECT public: explicit MeasurementModuleBase(const QString &title, QWidget *parent = nullptr); protected: // 创建标准样式的输入控件 QLineEdit *createStyledInput(const QString &placeholder = "", int width = 120); QDoubleSpinBox *createStyledSpinBox(double min, double max, int decimals = 2, int width = 120); QComboBox *createStyledComboBox(const QStringList &items, int width = 150); QPushButton *createPrimaryButton(const QString &text, int width = 120); QPushButton *createSecondaryButton(const QString &text, int width = 100); QLabel *createValueDisplay(const QString &value = "---", int width = 180); QGroupBox *createStyledGroupBox(const QString &title); // 添加带标签的输入行 QHBoxLayout *createLabeledRow(const QString &label, QWidget *widget, const QString &unit = ""); // 统一样式常量 static const QString CARD_STYLE; static const QString INPUT_STYLE; static const QString PRIMARY_BTN_STYLE; static const QString SECONDARY_BTN_STYLE; static const QString VALUE_DISPLAY_STYLE; static const QString LABEL_STYLE; static const QString GROUPBOX_STYLE; QVBoxLayout *m_mainLayout; QString m_title; }; /** * @brief 热电阻测量模块 * 支持2/3/4线热电阻测量和PT100输出 * 整合ChannelManager进行通道管理 */ class RTDMeasurementWidget : public MeasurementModuleBase { Q_OBJECT public: enum RTDType { PT100, PT1000, CU50, CU100 }; enum MeasurementMode { TWO_WIRE_MODE, THREE_WIRE_MODE, FOUR_WIRE_MODE }; explicit RTDMeasurementWidget(QWidget *parent = nullptr); ~RTDMeasurementWidget(); signals: void measurementDataReady(double resistance, double temperature); protected: bool eventFilter(QObject *obj, QEvent *event) override; private slots: void onMeasureClicked(); void onStopClicked(); void onWireTypeChanged(int index); void onChannelSelected(ChannelManager::ChannelId channelId); void updateMeasurement(); private: void setupUI(); void setupChannelSelection(); void updateChannelSelection(); void updateConnectionModeVisibility(); void generateSimulatedData(); double convertResistanceToTemperature(double resistance); bool validateChannelForMode(); // 通道管理 ChannelManager *m_channelManager; QMap m_channelWidgets; ChannelManager::ChannelId m_selectedChannel; ChannelManager::ChannelId m_currentChannel; QTimer *m_measurementTimer; // 测量状态 bool m_isMeasuring; MeasurementMode m_currentMode; RTDType m_currentRTDType; double m_currentResistance; double m_currentTemperature; // UI控件 QWidget *m_channelSelectionWidget; QComboBox *m_wireTypeCombo; QComboBox *m_rtdTypeCombo; QLabel *m_resistanceDisplay; QLabel *m_temperatureDisplay; QLabel *m_lineResDisplay; QLabel *m_channelStatusLabel; QLabel *m_wiringDiagramLabel; QPushButton *m_measureBtn; QPushButton *m_stopBtn; }; /** * @brief PT100输出模块 - 双通道 * 支持两个通道的PT100温度输出 */ class RTDOutputWidget : public MeasurementModuleBase { Q_OBJECT public: explicit RTDOutputWidget(QWidget *parent = nullptr); ~RTDOutputWidget(); private slots: void onChannel1OutputClicked(); void onChannel1StopClicked(); void onChannel2OutputClicked(); void onChannel2StopClicked(); void onChannel1TempChanged(double value); void onChannel2TempChanged(double value); private: void setupUI(); double convertTemperatureToResistance(double temperature); // 输出状态 bool m_isChannel1Outputting; bool m_isChannel2Outputting; // 通道1控件 QDoubleSpinBox *m_channel1TempSpin; QLabel *m_channel1ResDisplay; QPushButton *m_channel1OutputBtn; QPushButton *m_channel1StopBtn; // 通道2控件 QDoubleSpinBox *m_channel2TempSpin; QLabel *m_channel2ResDisplay; QPushButton *m_channel2OutputBtn; QPushButton *m_channel2StopBtn; }; /** * @brief 热电偶测量模块 * 支持热电偶电压测量和毫伏输出 */ class ThermocoupleMeasurementWidget : public MeasurementModuleBase { Q_OBJECT public: explicit ThermocoupleMeasurementWidget(QWidget *parent = nullptr); private slots: void onMeasureClicked(); void onOutputClicked(); private: void setupUI(); QComboBox *m_tcTypeCombo; // K/J/T/E/S/R/B型选择 QLabel *m_voltageDisplay; // 电压显示(mV) QLabel *m_temperatureDisplay; // 温度显示 QDoubleSpinBox *m_outputTempSpin; // 输出温度设置 QLabel *m_outputVoltageDisplay; // 输出电压显示 QPushButton *m_measureBtn; QPushButton *m_outputBtn; }; /** * @brief 绝缘电阻测量模块 * 支持50V/100V绝缘电阻测量 */ class InsulationMeasurementWidget : public MeasurementModuleBase { Q_OBJECT public: explicit InsulationMeasurementWidget(QWidget *parent = nullptr); private slots: void onMeasureClicked(); void onAutoTestToggled(bool enabled); private: void setupUI(); QRadioButton *m_50vRadio; QRadioButton *m_100vRadio; QCheckBox *m_autoTestCheck; // 自动测试 QLabel *m_insulationDisplay; // 绝缘电阻显示 QLabel *m_statusDisplay; // 状态显示 QProgressBar *m_dischargeProgress; // 放电进度 QPushButton *m_measureBtn; }; /** * @brief 直流电流信号模块 * 支持0-20mA电流输出/测量 */ class DCCurrentWidget : public MeasurementModuleBase { Q_OBJECT public: explicit DCCurrentWidget(QWidget *parent = nullptr); private slots: void onMeasureClicked(); void onOutputClicked(); private: void setupUI(); QRadioButton *m_activeRadio; // 有源模式 QRadioButton *m_passiveRadio; // 无源模式 QLabel *m_currentDisplay; // 电流显示 QLabel *m_maxDisplay; // 最大值 QLabel *m_minDisplay; // 最小值 QLabel *m_avgDisplay; // 平均值 QDoubleSpinBox *m_outputSpin; // 输出设置 QPushButton *m_measureBtn; QPushButton *m_outputBtn; }; /** * @brief 直流电压信号模块 * 支持0-20V电压输出/测量 */ class DCVoltageWidget : public MeasurementModuleBase { Q_OBJECT public: explicit DCVoltageWidget(QWidget *parent = nullptr); private slots: void onMeasureClicked(); void onOutputClicked(); private: void setupUI(); QLabel *m_voltageDisplay; QLabel *m_maxDisplay; QLabel *m_minDisplay; QLabel *m_avgDisplay; QDoubleSpinBox *m_outputSpin; QPushButton *m_measureBtn; QPushButton *m_outputBtn; }; /** * @brief 频率信号模块 * 支持频率测量和方波/正弦波输出 */ class FrequencyWidget : public MeasurementModuleBase { Q_OBJECT public: explicit FrequencyWidget(QWidget *parent = nullptr); private slots: void onMeasureClicked(); void onOutputClicked(); void onWaveTypeChanged(int index); private: void setupUI(); QLabel *m_frequencyDisplay; QComboBox *m_waveTypeCombo; // 方波/正弦波 QDoubleSpinBox *m_freqSpin; // 频率设置 QDoubleSpinBox *m_amplitudeSpin; // 幅值设置 QPushButton *m_measureBtn; QPushButton *m_outputBtn; }; /** * @brief 220VAC测量模块 */ class ACVoltageWidget : public MeasurementModuleBase { Q_OBJECT public: explicit ACVoltageWidget(QWidget *parent = nullptr); private slots: void onMeasureClicked(); private: void setupUI(); QLabel *m_voltageDisplay; QLabel *m_frequencyDisplay; QPushButton *m_measureBtn; }; /** * @brief 开关量检测模块 */ class SwitchDetectionWidget : public MeasurementModuleBase { Q_OBJECT public: explicit SwitchDetectionWidget(QWidget *parent = nullptr); private slots: void onDetectClicked(); private: void setupUI(); QRadioButton *m_resistanceMode; // 电阻通断模式 QRadioButton *m_voltageMode; // 电压模式 QLabel *m_statusDisplay; // 通断状态 QLabel *m_valueDisplay; // 测量值 QPushButton *m_detectBtn; }; /** * @brief 信号采集记录模块 */ class SignalAcquisitionWidget : public MeasurementModuleBase { Q_OBJECT public: explicit SignalAcquisitionWidget(QWidget *parent = nullptr); private slots: void onStartClicked(); void onStopClicked(); void onExportClicked(); private: void setupUI(); QComboBox *m_channel1Type; // 通道1类型 QComboBox *m_channel2Type; // 通道2类型 QDoubleSpinBox *m_rateSpin; // 采集速率 QTableWidget *m_dataTable; // 数据表格 QPushButton *m_startBtn; QPushButton *m_stopBtn; QPushButton *m_exportBtn; QTimer *m_acquisitionTimer; }; /** * @brief 斜波信号输出模块 */ class RampSignalWidget : public MeasurementModuleBase { Q_OBJECT public: explicit RampSignalWidget(QWidget *parent = nullptr); private slots: void onStartClicked(); void onStopClicked(); private: void setupUI(); QComboBox *m_signalType; // 电压/电流 QDoubleSpinBox *m_startValue; // 起始值 QDoubleSpinBox *m_endValue; // 结束值 QDoubleSpinBox *m_rampRate; // 斜波速率 QLabel *m_currentValueDisplay; // 当前值 QProgressBar *m_rampProgress; QPushButton *m_startBtn; QPushButton *m_stopBtn; }; /** * @brief 电源纹波检测模块 */ class RippleDetectionWidget : public MeasurementModuleBase { Q_OBJECT public: explicit RippleDetectionWidget(QWidget *parent = nullptr); private slots: void onDetectClicked(); void onDiagnoseClicked(); private: void setupUI(); QLabel *m_rippleDisplay; // 纹波值 QLabel *m_diagnosisDisplay; // 诊断结果 QLabel *m_confidenceDisplay; // 置信度 QPushButton *m_detectBtn; QPushButton *m_diagnoseBtn; }; /** * @brief 信号测量主页面 * 包含所有测量功能模块的导航 */ class SignalMeasurementWidget : public QWidget { Q_OBJECT public: explicit SignalMeasurementWidget(QWidget *parent = nullptr); void setModule(int moduleIndex); signals: void backRequested(); private slots: void onBackClicked(); void onModuleSelected(int index); private: void setupUI(); void setupContentArea(); QStackedWidget *m_contentStack; QLabel *m_titleLabel; int m_currentModuleIndex; // 各功能模块 RTDMeasurementWidget *m_rtdWidget; RTDOutputWidget *m_rtdOutputWidget; ThermocoupleMeasurementWidget *m_tcWidget; InsulationMeasurementWidget *m_insulationWidget; DCCurrentWidget *m_dcCurrentWidget; DCVoltageWidget *m_dcVoltageWidget; FrequencyWidget *m_frequencyWidget; ACVoltageWidget *m_acVoltageWidget; SwitchDetectionWidget *m_switchWidget; SignalAcquisitionWidget *m_acquisitionWidget; RampSignalWidget *m_rampWidget; RippleDetectionWidget *m_rippleWidget; }; #endif // SIGNALMEASUREMENTWIDGET_H