compareitemdialog.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. #include "compareitemdialog.h"
  2. #include "GlobalVariable.h"
  3. #include "ui_compareitemwidget.h"
  4. #include "UIStyleManager.h"
  5. #include "SoundCardData.h"
  6. #include "tipwidget.h"
  7. #include "commonFunc.h"
  8. #include <QIntValidator>
  9. CompareItemDialog::CompareItemDialog(QWidget *parent)
  10. : DialogBase(parent)
  11. , ui(new Ui::CompareItemWidget)
  12. {
  13. QWidget *widgetContent = new QWidget(this);
  14. ui->setupUi(widgetContent);
  15. /* 设置内容 */
  16. setContentWidget(widgetContent);
  17. /* 设置标题 */
  18. setTitle("对比项信息", QSize(120, 18));
  19. /* 对输入做一些限制 */
  20. setDetectParamInputOnlyNumber();
  21. /* 限制对比项名称长度 */
  22. ui->lineEdit_compareItmName->setMaxLength(15);
  23. /* 设置默认开启 */
  24. ui->checkBoxMute->setChecked(true);
  25. ui->checkBoxOverload->setChecked(true);
  26. ui->checkBoxPhase->setChecked(true);
  27. /* 设置可选的声卡通道信息 */
  28. setSoundCardRoadList(SoundCards.getCurrentSoundCardInfo());
  29. /* 连接信号和槽 */
  30. connect(ui->pBtn_add, &QPushButton::clicked, this, &CompareItemDialog::do_pBtn_add_clicked);
  31. /* 连接静音、过载、反相三个按钮的开关 */
  32. connect(ui->checkBoxMute, &QCheckBox::clicked, this, &CompareItemDialog::do_checkBox_MOP_clicked);
  33. connect(ui->checkBoxOverload, &QCheckBox::clicked, this, &CompareItemDialog::do_checkBox_MOP_clicked);
  34. connect(ui->checkBoxPhase, &QCheckBox::clicked, this, &CompareItemDialog::do_checkBox_MOP_clicked);
  35. /* 连接通道的选择信号 */
  36. connect(ui->widget_mainRoad, &SingleCompareRoadWidget::signal_selectRecordRoad, this, &CompareItemDialog::do_selectOneRecordRoad);
  37. connect(ui->widget_secondRoad, &SingleCompareRoadWidget::signal_selectRecordRoad, this, &CompareItemDialog::do_selectOneRecordRoad);
  38. /* 设置样式 */
  39. setQSS();
  40. }
  41. CompareItemDialog::~CompareItemDialog()
  42. {
  43. delete ui;
  44. }
  45. /* 设置可选的声卡通道信息 */
  46. void CompareItemDialog::setSoundCardRoadList(const SoundCardPCMInfo_t& soundCardInfo)
  47. {
  48. m_soundCardInfo = soundCardInfo;
  49. /* 设置已有两个通道的可选录音通道 */
  50. ui->widget_mainRoad->setSoundCardRoadList(m_soundCardInfo);
  51. ui->widget_secondRoad->setSoundCardRoadList(m_soundCardInfo);
  52. }
  53. /* 设置默认的参数 */
  54. void CompareItemDialog::setDefaultParams(const CompareItemInfo_t& item)
  55. {
  56. m_compareItemInfo = item; // 保存对比项信息
  57. /* 设置对比项名称 */
  58. ui->lineEdit_compareItmName->setText(item.strName);
  59. /* 设置对比项状态 */
  60. ui->checkBox_enable->setChecked(item.isEnable);
  61. /* 设置静音检测参数,设置文本需要取绝对值 */
  62. ui->checkBoxMute->setChecked(item.paramMute.isEnable);
  63. ui->lineEditMuteLen->setText(QString::number(item.paramMute.nLen));
  64. ui->lineEditMuteSensibility->setText(QString::number(item.paramMute.nSensitivity));
  65. ui->lineEditMuteThreshold->setText(QString::number(std::abs(item.paramMute.threshold.nThreshold)));
  66. /* 设置过载检测参数 */
  67. ui->checkBoxOverload->setChecked(item.paramOverload.isEnable);
  68. ui->lineEditOverloadLen->setText(QString::number(item.paramOverload.nLen));
  69. ui->lineEditOverloadSensibility->setText(QString::number(item.paramOverload.nSensitivity));
  70. ui->lineEditOverloadThreshold->setText(QString::number(std::abs(item.paramOverload.threshold.nThreshold)));
  71. /* 设置反相检测参数 */
  72. ui->checkBoxPhase->setChecked(item.paramPhase.isEnable);
  73. ui->lineEditPhaseLen->setText(QString::number(item.paramPhase.nLen));
  74. ui->lineEditPhaseSensibility->setText(QString::number(item.paramPhase.nSensitivity));
  75. ui->lineEditPhaseThreshold->setText(QString::number(std::abs(item.paramPhase.threshold.dThreshold)));
  76. /* 先设置主通道和第二通道 */
  77. for(const auto& road : item.mapRoad)
  78. {
  79. if(road.nCompareRoadNum == 1) // 主通道
  80. {
  81. /* 阻塞这个comBoBox发送信号 */
  82. ui->widget_mainRoad->blockSignals(true);
  83. ui->widget_mainRoad->setSoundCardRoadList(m_soundCardInfo);
  84. ui->widget_mainRoad->blockSignals(false);
  85. ui->widget_mainRoad->setDefaultParams(road);
  86. }
  87. else if(road.nCompareRoadNum == 2) // 第二通道
  88. {
  89. ui->widget_secondRoad->blockSignals(true);
  90. ui->widget_secondRoad->setSoundCardRoadList(m_soundCardInfo);
  91. ui->widget_secondRoad->blockSignals(false);
  92. ui->widget_secondRoad->setDefaultParams(road);
  93. }
  94. }
  95. /* 设置其他通道 */
  96. for(const auto& road : item.mapRoad)
  97. {
  98. if(road.nCompareRoadNum > 2) // 其他通道
  99. {
  100. auto pWgt = addOneRoadWidget(road.nCompareRoadNum, true);
  101. /* 设置默认参数 */
  102. pWgt->setDefaultParams(road);
  103. }
  104. }
  105. }
  106. /* 获取生成的对比项信息 */
  107. CompareItemInfo_t& CompareItemDialog::getCompareItemInfo()
  108. {
  109. return m_compareItemInfo;
  110. }
  111. /* 新增通道 */
  112. void CompareItemDialog::do_pBtn_add_clicked()
  113. {
  114. /* 从3开始编号,1是主通道,2是第二通道 */
  115. int index = m_listOtherRoadWgt.size() + 3;
  116. addOneRoadWidget(index, true);
  117. }
  118. /* 删除通道 */
  119. void CompareItemDialog::do_CompareRoadWgtDeleted(int nIndex)
  120. {
  121. int nRealIndex = nIndex - 3;
  122. if(nRealIndex < m_listOtherRoadWgt.size())
  123. {
  124. SingleCompareRoadWidget *pWgt = m_listOtherRoadWgt.at(nRealIndex);
  125. m_listOtherRoadWgt.removeOne(pWgt);
  126. delete pWgt;
  127. pWgt = nullptr;
  128. }
  129. for(int i = nRealIndex; i < m_listOtherRoadWgt.size(); i++)
  130. {
  131. m_listOtherRoadWgt.at(i)->setIndex(i + 3);
  132. }
  133. }
  134. /* 静音、过载、反相检测条件开关 */
  135. void CompareItemDialog::do_checkBox_MOP_clicked(bool checked)
  136. {
  137. /* 获取信号发送者 */
  138. QCheckBox *checkBox = qobject_cast<QCheckBox*>(sender());
  139. checkBox->setText(checked ? "开启" : "关闭");
  140. if(checkBox == ui->checkBoxMute)
  141. {
  142. setMOPEditable(EDBType::DBType_Mute, checked);
  143. }
  144. else if(checkBox == ui->checkBoxOverload)
  145. {
  146. setMOPEditable(EDBType::DBType_Overload, checked);
  147. }
  148. else if(checkBox == ui->checkBoxPhase)
  149. {
  150. setMOPEditable(EDBType::DBType_Phase, checked);
  151. }
  152. }
  153. /* 选择了一个录音通道,判断有没有重复的,有则去掉重复的 */
  154. void CompareItemDialog::do_selectOneRecordRoad(QString strPCMName)
  155. {
  156. auto sender = qobject_cast<SingleCompareRoadWidget*>(QObject::sender());
  157. /* 只在release模式下生效,debug可以设置重复的,方便测试 */
  158. #if C_RELEASE
  159. /* 判断是否重复 */
  160. if(sender != ui->widget_mainRoad)
  161. {
  162. if(ui->widget_mainRoad->getCurrentPCMName() == strPCMName)
  163. {
  164. // 如果重复,则去掉重复的
  165. ui->widget_mainRoad->clearCurrentSelectRecordName();
  166. }
  167. }
  168. if(sender != ui->widget_secondRoad)
  169. {
  170. if(ui->widget_secondRoad->getCurrentPCMName() == strPCMName)
  171. {
  172. // 如果重复,则去掉重复的
  173. ui->widget_secondRoad->clearCurrentSelectRecordName();
  174. }
  175. }
  176. for(auto& it : m_listOtherRoadWgt)
  177. {
  178. if(it == sender)
  179. {
  180. continue;
  181. }
  182. if(it->getCurrentPCMName() == strPCMName)
  183. {
  184. it->clearCurrentSelectRecordName();
  185. }
  186. }
  187. #endif
  188. }
  189. /* 设置样式表 */
  190. void CompareItemDialog::setQSS()
  191. {
  192. QString qssPath = UIStyle.getQSSPath() + "/compareitemwidget.qss";
  193. QFile file(qssPath);
  194. if(file.open(QFile::ReadOnly))
  195. {
  196. QString qss = file.readAll();
  197. file.close();
  198. /* 这里设置的是内容容器样式表,this是最外层的 */
  199. getContentWidget()->setStyleSheet(qss);
  200. ui->scrollArea->setStyleSheet(qss);
  201. ui->scrollAreaWidgetContents->setStyleSheet(qss);
  202. } else
  203. {
  204. SPDLOG_LOGGER_ERROR(m_logger, "打开QSS文件失败: {}", qssPath.toStdString());
  205. SPDLOG_LOGGER_ERROR(m_logger, "错误信息: {}", file.errorString().toStdString());
  206. }
  207. /* 打开对比项通道的qss */
  208. file.setFileName(UIStyle.getQSSPath() + "/singlecompareroadwidget.qss");
  209. if(file.open(QFile::ReadOnly))
  210. {
  211. m_qssRecordRoad = file.readAll();
  212. file.close();
  213. } else
  214. {
  215. SPDLOG_LOGGER_ERROR(m_logger, "打开QSS文件失败: {}", file.fileName().toStdString());
  216. SPDLOG_LOGGER_ERROR(m_logger, "错误信息: {}", file.errorString().toStdString());
  217. }
  218. ui->widget_mainRoad->setQSS(m_qssRecordRoad);
  219. ui->widget_secondRoad->setQSS(m_qssRecordRoad);
  220. }
  221. /* 设置静音过载反相可编辑 */
  222. void CompareItemDialog::setMOPEditable(EDBType type, bool editable)
  223. {
  224. if(type == EDBType::DBType_Mute)
  225. {
  226. if(editable)
  227. {
  228. ui->lineEditMuteLen->setEnabled(true);
  229. ui->lineEditMuteSensibility->setEnabled(true);
  230. ui->lineEditMuteThreshold->setEnabled(true);
  231. }else {
  232. ui->lineEditMuteLen->setEnabled(false);
  233. ui->lineEditMuteSensibility->setEnabled(false);
  234. ui->lineEditMuteThreshold->setEnabled(false);
  235. }
  236. }
  237. else if(type == EDBType::DBType_Overload)
  238. {
  239. if(editable)
  240. {
  241. ui->lineEditOverloadLen->setEnabled(true);
  242. ui->lineEditOverloadSensibility->setEnabled(true);
  243. ui->lineEditOverloadThreshold->setEnabled(true);
  244. }else {
  245. ui->lineEditOverloadLen->setEnabled(false);
  246. ui->lineEditOverloadSensibility->setEnabled(false);
  247. ui->lineEditOverloadThreshold->setEnabled(false);
  248. }
  249. }
  250. else if(type == EDBType::DBType_Phase)
  251. {
  252. if(editable)
  253. {
  254. ui->lineEditPhaseLen->setEnabled(true);
  255. ui->lineEditPhaseSensibility->setEnabled(true);
  256. ui->lineEditPhaseThreshold->setEnabled(true);
  257. }else {
  258. ui->lineEditPhaseLen->setEnabled(false);
  259. ui->lineEditPhaseSensibility->setEnabled(false);
  260. ui->lineEditPhaseThreshold->setEnabled(false);
  261. }
  262. }
  263. }
  264. /* 设置检测参数输入栏只能输入数字 */
  265. void CompareItemDialog::setDetectParamInputOnlyNumber()
  266. {
  267. // 静音参数,只允许输入1~1000的整数
  268. // QRegularExpression rx1("-[4-8][0-9]");
  269. // ui->lineEditMuteThreshold->setValidator(new QRegularExpressionValidator(rx1, this));
  270. ui->lineEditMuteThreshold->setValidator(new QIntValidator(40, 84, this));
  271. ui->lineEditMuteLen->setValidator(new QIntValidator(2, 90, this));
  272. ui->lineEditMuteSensibility->setValidator(new QIntValidator(22, 100, this));
  273. // 过载参数
  274. ui->lineEditOverloadThreshold->setValidator(new QIntValidator(0, 40, this));
  275. ui->lineEditOverloadLen->setValidator(new QIntValidator(2, 90, this));
  276. ui->lineEditOverloadSensibility->setValidator(new QIntValidator(22, 100, this));
  277. // 反相参数,阈值为浮点数,范围0.0~0.99
  278. ui->lineEditPhaseThreshold->setValidator(new StrictDoubleValidator(0.0, 0.99, 3, this));
  279. ui->lineEditPhaseLen->setValidator(new QIntValidator(10, 90, this));
  280. ui->lineEditPhaseSensibility->setValidator(new QIntValidator(20, 99, this));
  281. }
  282. /* 新增一个通道 */
  283. SingleCompareRoadWidget* CompareItemDialog::addOneRoadWidget(int nIndex, bool bDelBtnVisible)
  284. {
  285. QVBoxLayout* pLayout = qobject_cast<QVBoxLayout*>(ui->scrollAreaWidgetContents->layout());
  286. if(pLayout == nullptr)
  287. {
  288. SPDLOG_LOGGER_ERROR(m_logger, "滚动区域内容布局未设置,无法添加通道");
  289. return nullptr;
  290. }
  291. SingleCompareRoadWidget *pWgt = new SingleCompareRoadWidget(this);
  292. pWgt->setIndex(nIndex);
  293. pWgt->setDelBtnVisible(bDelBtnVisible);
  294. /* 设置可选通道列表 */
  295. pWgt->setSoundCardRoadList(m_soundCardInfo);
  296. pWgt->setQSS(m_qssRecordRoad);
  297. pLayout->insertWidget(m_listOtherRoadWgt.size(), pWgt);
  298. connect(pWgt, &SingleCompareRoadWidget::deleted, this, &CompareItemDialog::do_CompareRoadWgtDeleted);
  299. connect(pWgt, &SingleCompareRoadWidget::signal_selectRecordRoad, this, &CompareItemDialog::do_selectOneRecordRoad);
  300. m_listOtherRoadWgt.append(pWgt);
  301. return pWgt;
  302. }
  303. /* 重载按下关闭按钮之前的操作 */
  304. bool CompareItemDialog::isOKClicked()
  305. {
  306. /* 先取消所有的报警 */
  307. cancelAllWarn();
  308. /* 获取对比项的信息 */
  309. if(!getCompareItemBaseInfo(m_compareItemInfo))
  310. {
  311. return false;
  312. }
  313. /* 获取录音通道信息 */
  314. if(!getCompareRoadInfo(m_compareItemInfo))
  315. {
  316. return false;
  317. }
  318. /* 获取音频检测信息 */
  319. if(!getAudioDetectInfo(m_compareItemInfo))
  320. {
  321. return false;
  322. }
  323. return true;
  324. }
  325. /* 获取对比项的基础信息 */
  326. bool CompareItemDialog::getCompareItemBaseInfo(CompareItemInfo_t& compareItemInfo)
  327. {
  328. if(ui->lineEdit_compareItmName->text().isEmpty())
  329. {
  330. setWarn(ui->lineEdit_compareItmName, true);
  331. TipWidget::display(TipWidget::OPERATOR_WARN, "对比项名称不能为空", this);
  332. return false;
  333. }
  334. compareItemInfo.strName = ui->lineEdit_compareItmName->text();
  335. compareItemInfo.isEnable = ui->checkBox_enable->isChecked();
  336. return true;
  337. }
  338. /* 获取各个通道信息 */
  339. bool CompareItemDialog::getCompareRoadInfo(CompareItemInfo_t& compareItemInfo)
  340. {
  341. compareItemInfo.mapRoad.clear();
  342. /* 获取主通道信息 */
  343. CompareItemRoadInfo_t mainRoadInfo;
  344. mainRoadInfo.strCompareRoadName = ui->widget_mainRoad->getRoadName();
  345. mainRoadInfo.nCompareRoadNum = ui->widget_mainRoad->getIndex();
  346. mainRoadInfo.isEnableRecord = ui->widget_mainRoad->isRecordEnabled();
  347. mainRoadInfo.scRoadInfo = ui->widget_mainRoad->getSoundCardRoadInfo();
  348. if(mainRoadInfo.strCompareRoadName.isEmpty())
  349. {
  350. ui->widget_mainRoad->setRoadNameWarn(true);
  351. TipWidget::display(TipWidget::OPERATOR_WARN, "主通道名称不能为空", this);
  352. return false;
  353. }
  354. compareItemInfo.mapRoad.insert(mainRoadInfo.nCompareRoadNum, mainRoadInfo);
  355. /* 获取第二通道信息 */
  356. CompareItemRoadInfo_t secondRoadInfo;
  357. secondRoadInfo.strCompareRoadName = ui->widget_secondRoad->getRoadName();
  358. secondRoadInfo.nCompareRoadNum = ui->widget_secondRoad->getIndex();
  359. secondRoadInfo.isEnableRecord = ui->widget_secondRoad->isRecordEnabled();
  360. secondRoadInfo.scRoadInfo = ui->widget_secondRoad->getSoundCardRoadInfo();
  361. if(secondRoadInfo.strCompareRoadName.isEmpty())
  362. {
  363. ui->widget_secondRoad->setRoadNameWarn(true);
  364. TipWidget::display(TipWidget::OPERATOR_WARN, "第二通道名称不能为空", this);
  365. return false;
  366. }
  367. compareItemInfo.mapRoad.insert(secondRoadInfo.nCompareRoadNum, secondRoadInfo);
  368. /* 获取其他通道信息 */
  369. for(SingleCompareRoadWidget* roadWgt : m_listOtherRoadWgt)
  370. {
  371. CompareItemRoadInfo_t otherRoadInfo;
  372. otherRoadInfo.strCompareRoadName = roadWgt->getRoadName();
  373. otherRoadInfo.nCompareRoadNum = roadWgt->getIndex();
  374. otherRoadInfo.isEnableRecord = roadWgt->isRecordEnabled();
  375. otherRoadInfo.scRoadInfo = roadWgt->getSoundCardRoadInfo();
  376. if(otherRoadInfo.strCompareRoadName.isEmpty())
  377. {
  378. roadWgt->setRoadNameWarn(true);
  379. TipWidget::display(TipWidget::OPERATOR_WARN, QString("第%1通道名称不能为空").arg(otherRoadInfo.nCompareRoadNum), this);
  380. return false;
  381. }
  382. compareItemInfo.mapRoad.insert(otherRoadInfo.nCompareRoadNum, otherRoadInfo);
  383. }
  384. return true;
  385. }
  386. /* 获取音频检测信息 */
  387. bool CompareItemDialog::getAudioDetectInfo(CompareItemInfo_t& compareItemInfo)
  388. {
  389. /* 静音检测,注意阈值是负数,在输入框中是正数,这里需要转换一下 */
  390. compareItemInfo.paramMute.isEnable = ui->checkBoxMute->isChecked();
  391. compareItemInfo.paramMute.threshold.nThreshold = -ui->lineEditMuteThreshold->text().toULongLong();
  392. compareItemInfo.paramMute.nLen = ui->lineEditMuteLen->text().toInt();
  393. compareItemInfo.paramMute.nSensitivity = ui->lineEditMuteSensibility->text().toInt();
  394. /* 过载检测 */
  395. compareItemInfo.paramOverload.isEnable = ui->checkBoxOverload->isChecked();
  396. compareItemInfo.paramOverload.threshold.nThreshold = -ui->lineEditOverloadThreshold->text().toULongLong();
  397. compareItemInfo.paramOverload.nLen = ui->lineEditOverloadLen->text().toInt();
  398. compareItemInfo.paramOverload.nSensitivity = ui->lineEditOverloadSensibility->text().toInt();
  399. /* 反相检测 */
  400. compareItemInfo.paramPhase.isEnable = ui->checkBoxPhase->isChecked();
  401. compareItemInfo.paramPhase.threshold.dThreshold = -ui->lineEditPhaseThreshold->text().toDouble();
  402. compareItemInfo.paramPhase.nLen = ui->lineEditPhaseLen->text().toInt();
  403. compareItemInfo.paramPhase.nSensitivity = ui->lineEditPhaseSensibility->text().toInt();
  404. return true;
  405. }
  406. /* 取消所有的报警 */
  407. void CompareItemDialog::cancelAllWarn()
  408. {
  409. setWarn(ui->lineEdit_compareItmName, false);
  410. ui->widget_mainRoad->setRoadNameWarn(false);
  411. ui->widget_secondRoad->setRoadNameWarn(false);
  412. for(SingleCompareRoadWidget* roadWgt : m_listOtherRoadWgt)
  413. {
  414. roadWgt->setRoadNameWarn(false);
  415. }
  416. }