ctkErrorLogStatusMessageHandler.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // Qt includes
  15. #include <QApplication>
  16. #include <QDateTime>
  17. #include <QDebug>
  18. #include <QMainWindow>
  19. #include <QStatusBar>
  20. #include <QThread>
  21. // CTK includes
  22. #include "ctkErrorLogStatusMessageHandler.h"
  23. #include "ctkUtils.h"
  24. // --------------------------------------------------------------------------
  25. QString ctkErrorLogStatusMessageHandler::HandlerName = QLatin1String("Status");
  26. // --------------------------------------------------------------------------
  27. ctkErrorLogStatusMessageHandler::ctkErrorLogStatusMessageHandler(QMainWindow * mainWindow) :
  28. ctkErrorLogAbstractMessageHandler()
  29. {
  30. this->MainWindow = QPointer<QMainWindow>(mainWindow);
  31. }
  32. // --------------------------------------------------------------------------
  33. QString ctkErrorLogStatusMessageHandler::handlerName()const
  34. {
  35. return ctkErrorLogStatusMessageHandler::HandlerName;
  36. }
  37. // --------------------------------------------------------------------------
  38. void ctkErrorLogStatusMessageHandler::setEnabledInternal(bool value)
  39. {
  40. if (value)
  41. {
  42. if (this->MainWindow.isNull())
  43. {
  44. qCritical() << "ctkErrorLogStatusMessageHandler - "
  45. " Failed to enable ctkErrorLogStatusMessageHandler - "
  46. "QMainWindow passed to the constructor is Null !";
  47. return;
  48. }
  49. if (!this->MainWindow->statusBar())
  50. {
  51. qCritical() << "ctkErrorLogStatusMessageHandler - Failed to enable the message handler: "
  52. "There is no StatusBar associated with QMainWindow" << this->MainWindow;
  53. return;
  54. }
  55. connect(this->MainWindow->statusBar(), SIGNAL(messageChanged(QString)),
  56. this, SLOT(statusBarMessageChanged(QString)));
  57. }
  58. else
  59. {
  60. if (!this->MainWindow.isNull())
  61. {
  62. disconnect(this->MainWindow->statusBar(), SIGNAL(messageChanged(QString)),
  63. this, SLOT(statusBarMessageChanged(QString)));
  64. }
  65. }
  66. }
  67. //------------------------------------------------------------------------------
  68. void ctkErrorLogStatusMessageHandler::statusBarMessageChanged(const QString& text)
  69. {
  70. if (text.isEmpty())
  71. {
  72. return;
  73. }
  74. this->handleMessage(
  75. ctk::qtHandleToString(QThread::currentThreadId()),
  76. ctkErrorLogLevel::Status, this->handlerPrettyName(), text);
  77. }