WindowAppLogView.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #include "WindowAppLogView.h"
  2. #include "DebugManager.h"
  3. #include "Preferences.h"
  4. WindowAppLogView::WindowAppLogView(const QString& strTitle, QWidget* parent)
  5. : QWidget(parent)
  6. , m_strTitle(strTitle)
  7. {
  8. ui.setupUi(this);
  9. ui.textEdit->setStyleSheet("background-color:#464646;");
  10. //关联Debug信息,显示到文本框
  11. //注意,如果槽函数为lambda或者其他没有接收者的情况,需要保证槽函数中的变量有效性
  12. //因为static变量的生命周期更长,可能槽函数所在模块已经释放资源,最好connect加上接收者
  13. connect(DebugManager::getInstance(), &DebugManager::newDebug,
  14. this, [this](int msgType, const QString& log)
  15. {
  16. Q_UNUSED(msgType);
  17. ui.textEdit->append(log);
  18. ui.textEdit->moveCursor(QTextCursor::End);
  19. });
  20. //关联信号和槽
  21. QObject::connect(ui.logMode, SIGNAL(currentIndexChanged(int)), this, SLOT(ChangeShowMode(int)));
  22. ChangeShowMode(0);
  23. // 窗口禁止软键盘输入
  24. ui.textEdit->setProperty("noinput", true);
  25. }
  26. WindowAppLogView::~WindowAppLogView()
  27. {
  28. }
  29. void WindowAppLogView::ChangeShowMode(int index)
  30. {
  31. ui.textEdit->clear();
  32. for (int i = 0; i < DebugManager::getInstance()->m_AllDebugMsg.size(); i++)
  33. {
  34. DEBUGMSG msg = DebugManager::getInstance()->m_AllDebugMsg[i];
  35. if (msg.msgType == QtDebugMsg && index == 1)
  36. {
  37. ui.textEdit->append(msg.strMsg);
  38. ui.textEdit->moveCursor(QTextCursor::End);
  39. }
  40. if (msg.msgType == QtInfoMsg && index == 2)
  41. {
  42. ui.textEdit->append(msg.strMsg);
  43. ui.textEdit->moveCursor(QTextCursor::End);
  44. }
  45. if (msg.msgType == QtWarningMsg && index == 3)
  46. {
  47. ui.textEdit->append(msg.strMsg);
  48. ui.textEdit->moveCursor(QTextCursor::End);
  49. }
  50. if (msg.msgType == QtCriticalMsg && index == 4)
  51. {
  52. ui.textEdit->append(msg.strMsg);
  53. ui.textEdit->moveCursor(QTextCursor::End);
  54. }
  55. if (msg.msgType == QtFatalMsg && index == 5)
  56. {
  57. ui.textEdit->append(msg.strMsg);
  58. ui.textEdit->moveCursor(QTextCursor::End);
  59. }
  60. if (index == 0)
  61. {
  62. ui.textEdit->append(msg.strMsg);
  63. ui.textEdit->moveCursor(QTextCursor::End);
  64. }
  65. }
  66. }
  67. /// <summary>
  68. /// 调整大小的消息中改变表格栏的宽度
  69. /// </summary>
  70. /// <param name="event"></param>
  71. void WindowAppLogView::resizeEvent(QResizeEvent* event)
  72. {
  73. Q_UNUSED(event);
  74. //ui.textEdit->resize(this->frameGeometry().size());
  75. ui.textEdit->resize(this->frameGeometry().size());
  76. }