setinfowidget.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #include "setinfowidget.h"
  2. #include "CompareItemData.h"
  3. #include "ui_setinfowidget.h"
  4. #include "UIStyleManager.h"
  5. #include "tipwidget.h"
  6. #include "GLobalInfo.h"
  7. SetInfoWidget::SetInfoWidget(QWidget *parent) :
  8. QWidget(parent),
  9. ui(new Ui::SetInfoWidget)
  10. {
  11. ui->setupUi(this);
  12. /* 连接信号和槽 */
  13. connect(ui->pBtn_save, &QPushButton::clicked, this, &SetInfoWidget::do_pBtn_save_clicked);
  14. connect(ui->pBtn_cancel, &QPushButton::clicked, this, &SetInfoWidget::do_pBtn_cancel_clicked);
  15. connect(ui->tabWidget, &QTabWidget::currentChanged, this, &SetInfoWidget::do_tabWidget_currentChanged);
  16. /* 设置样式表 */
  17. UIStyle.registerWidget(this);
  18. }
  19. SetInfoWidget::~SetInfoWidget()
  20. {
  21. /* 注销样式表 */
  22. UIStyle.unregisterWidget(this);
  23. delete ui;
  24. }
  25. /* 设置WebAPI */
  26. void SetInfoWidget::setWebAPI(FromWebAPI* api)
  27. {
  28. m_fromWebAPI = api;
  29. /* 设置BasicWidget的WebAPI */
  30. BasicWidget* basicWidget = qobject_cast<BasicWidget*>(ui->tabWidget->widget(0));
  31. if(basicWidget)
  32. {
  33. basicWidget->setWebAPI(m_fromWebAPI);
  34. }
  35. /* 设置ai对比项的webapi指针 */
  36. AICompareWidget* aiCompareWidget = qobject_cast<AICompareWidget*>(ui->tabWidget->widget(1));
  37. if(aiCompareWidget)
  38. {
  39. aiCompareWidget->setWebAPI(m_fromWebAPI);
  40. }
  41. /* 设置噪音检测的webapi */
  42. NoiseWidget* noiseWidget = qobject_cast<NoiseWidget*>(ui->tabWidget->widget(2));
  43. if(noiseWidget)
  44. {
  45. noiseWidget->setWebAPI(m_fromWebAPI);
  46. }
  47. /* 设置数据库配置的WebAPI */
  48. DatabaseWidget* databaseWidget = qobject_cast<DatabaseWidget*>(ui->tabWidget->widget(3));
  49. if(databaseWidget)
  50. {
  51. databaseWidget->setWebAPI(m_fromWebAPI);
  52. }
  53. }
  54. /* 保存按钮 */
  55. void SetInfoWidget::do_pBtn_save_clicked()
  56. {
  57. saveData();
  58. }
  59. /* 取消按钮 */
  60. void SetInfoWidget::do_pBtn_cancel_clicked()
  61. {
  62. }
  63. /* 切换了页面 */
  64. void SetInfoWidget::do_tabWidget_currentChanged(int index)
  65. {
  66. /* 获取当前页的编号 */
  67. QWidget* currentWidget = ui->tabWidget->currentWidget();
  68. if(currentWidget == nullptr)
  69. {
  70. return;
  71. }
  72. /* 根据当前页的编号执行不同的操作 */
  73. switch(index)
  74. {
  75. case 0: // 基础信息
  76. break;
  77. case 1: // 对比项
  78. break;
  79. case 2: // 噪音检测
  80. break;
  81. case 3: // 数据库
  82. break;
  83. case 4: // 检测时段
  84. {
  85. /* 设置对比项到可选列表中 */
  86. CheckPeriodWidget* checkPeriodWidget = qobject_cast<CheckPeriodWidget*>(currentWidget);
  87. if(checkPeriodWidget)
  88. {
  89. checkPeriodWidget->updateCompareItemList(CIData.getCompareItemList());
  90. }
  91. }
  92. break;
  93. default:
  94. break;
  95. }
  96. }
  97. /* 保存数据 */
  98. void SetInfoWidget::saveData()
  99. {
  100. /* 获取当前页的编号 */
  101. int currentIndex = ui->tabWidget->currentIndex();
  102. QWidget* currentWidget = ui->tabWidget->currentWidget();
  103. bool isSuccess = false;
  104. switch(currentIndex)
  105. {
  106. case 0: /* 基础信息 */
  107. {
  108. BasicWidget* widget = qobject_cast<BasicWidget*>(currentWidget);
  109. if(widget)
  110. {
  111. /* 保存基础信息 */
  112. isSuccess = widget->saveBasicInfo();
  113. }
  114. }
  115. break;
  116. case 1: /* 对比项 */
  117. {
  118. AICompareWidget* widget = qobject_cast<AICompareWidget*>(currentWidget);
  119. if(widget)
  120. {
  121. /* 保存对比项信息 */
  122. isSuccess = widget->saveConfig();
  123. }
  124. }
  125. break;
  126. case 2: /* 噪音检测 */
  127. {
  128. NoiseWidget* widget = qobject_cast<NoiseWidget*>(currentWidget);
  129. if(widget)
  130. {
  131. /* 保存噪音检测信息 */
  132. isSuccess = widget->saveConfig();
  133. }
  134. }
  135. break;
  136. case 3: /* 数据库 */
  137. {
  138. DatabaseWidget* widget = qobject_cast<DatabaseWidget*>(currentWidget);
  139. if(widget)
  140. {
  141. /* 保存数据库信息 */
  142. isSuccess = widget->saveParams();
  143. }
  144. }
  145. break;
  146. case 4: /* 检测时段 */
  147. break;
  148. default:
  149. break;
  150. }
  151. if(isSuccess)
  152. {
  153. /* 保存成功 */
  154. TipWidget::display(TipWidget::OPERATOR_OK, "设置保存成功", GInfo.getTopWindow());
  155. }else {
  156. /* 保存失败 */
  157. TipWidget::display(TipWidget::OPERATOR_FAIL, "设置保存失败", GInfo.getTopWindow());
  158. }
  159. }