ch_widget.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include "ch_widget.h"
  2. #include "ui_ch_widget.h"
  3. #include <QDebug>
  4. #define RunStatus "#ch_Widget{border: 2px solid #00FF00;background-color: #FFFFFF;border-radius: 15px;}QLabel { color: #00FF00; }"
  5. #define StopStatus "#ch_Widget{border: 2px solid #000000;background-color: #FFFFFF;border-radius: 15px;}QLabel { color: #000000; }"
  6. #define WarningStatus "#ch_Widget{border: 2px solid #0000FF;background-color: #FFFFFF;border-radius: 15px;}QLabel { color: #0000FF; }"
  7. ch_Widget::ch_Widget(QWidget *parent) :
  8. QWidget(parent),
  9. ui(new Ui::ch_Widget),
  10. m_pCHData(nullptr),
  11. m_pChWarning(nullptr)
  12. {
  13. ui->setupUi(this);
  14. }
  15. ch_Widget::~ch_Widget()
  16. {
  17. delete ui;
  18. }
  19. void ch_Widget::setDataCHP(int nIndex, PowerInfo *pdata,PowerWarningInfo* pWarn)
  20. {
  21. if(pdata&&pWarn)
  22. {
  23. m_nIndex=nIndex;
  24. m_pCHData=pdata;
  25. m_pChWarning=pWarn;
  26. UpdateData();
  27. }
  28. }
  29. void ch_Widget::UpdateData()
  30. {
  31. if(m_pCHData)
  32. {
  33. ui->label_CH->setText("CH"+QString::number(m_nIndex));
  34. ui->label_V->setText(QString::number(m_pCHData->voltage, 'f', 2));
  35. ui->label_I->setText(QString::number(m_pCHData->current, 'f', 2));
  36. ui->label_P->setText(QString::number(m_pCHData->power,'f', 2));
  37. ui->label_W->setText(QString::number(m_pCHData->consumption, 'f', 2));
  38. //if(m_pCHData->status!=nStatus)
  39. {
  40. nStatus=m_pCHData->status;
  41. if(nStatus==1)
  42. {
  43. if(m_pChWarning&&(m_pChWarning->w_voltage_up||m_pChWarning->w_voltage_down||m_pChWarning->w_current||m_pChWarning->w_power||m_pChWarning->w_consumption))
  44. {
  45. this->setStyleSheet(WarningStatus);
  46. }else
  47. {
  48. this->setStyleSheet(RunStatus);
  49. }
  50. /*
  51. if(m_pChWarning)
  52. {
  53. if(m_pChWarning->w_voltage_up) {qDebug()<<"HaveWarning "<< m_nIndex<<" V_up";}
  54. if(m_pChWarning->w_voltage_down){qDebug()<<"HaveWarning "<< m_nIndex<<" V_down";}
  55. if(m_pChWarning->w_current) {qDebug()<<"HaveWarning "<< m_nIndex<<" I_up";}
  56. if(m_pChWarning->w_power) {qDebug()<<"HaveWarning "<< m_nIndex<<" P_up";}
  57. if(m_pChWarning->w_consumption) {qDebug()<<"HaveWarning "<< m_nIndex<<" SUM_up";}
  58. }else
  59. {
  60. qDebug()<<"No Warning Load CH"<<m_nIndex;
  61. }*/
  62. }else
  63. {
  64. this->setStyleSheet(StopStatus);
  65. }
  66. }
  67. }
  68. }
  69. bool ch_Widget::event(QEvent *event)
  70. {
  71. if (event->type() == QEvent::TouchBegin ||
  72. event->type() == QEvent::TouchUpdate ||
  73. event->type() == QEvent::TouchEnd) {
  74. // 不处理触摸事件,交给父级(QScrollArea 的视口)处理
  75. return false;
  76. }
  77. return QWidget::event(event);
  78. }