ctkErrorLogModel.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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.commontk.org/LICENSE
  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. #ifndef __ctkErrorLogModel_h
  15. #define __ctkErrorLogModel_h
  16. // Qt includes
  17. #include <QPointer>
  18. #include <QSortFilterProxyModel>
  19. // CTK includes
  20. #include "ctkCoreExport.h"
  21. class ctkErrorLogModel;
  22. class ctkErrorLogModelPrivate;
  23. class QStandardItemModel;
  24. #include <iostream>
  25. //------------------------------------------------------------------------------
  26. class CTK_CORE_EXPORT ctkErrorLogAbstractMessageHandler
  27. {
  28. public:
  29. ctkErrorLogAbstractMessageHandler():Enabled(false){}
  30. virtual ~ctkErrorLogAbstractMessageHandler(){}
  31. ctkErrorLogModel * errorLogModel()const;
  32. void setErrorLogModel(ctkErrorLogModel * newErrorLogModel);
  33. virtual QString handlerName()const = 0;
  34. QString handlerPrettyName()const;
  35. bool enabled()const;
  36. void setEnabled(bool value);
  37. protected:
  38. void setHandlerPrettyName(const QString& newHandlerPrettyName);
  39. virtual void setEnabledInternal(bool value) = 0;
  40. private:
  41. QPointer<ctkErrorLogModel> ErrorLogModel;
  42. bool Enabled;
  43. QString HandlerPrettyName;
  44. };
  45. //------------------------------------------------------------------------------
  46. class CTK_CORE_EXPORT ctkErrorLogModel : public QSortFilterProxyModel
  47. {
  48. Q_OBJECT
  49. Q_FLAGS(LogLevel)
  50. Q_PROPERTY(bool logEntryGrouping READ logEntryGrouping WRITE setLogEntryGrouping)
  51. public:
  52. typedef QSortFilterProxyModel Superclass;
  53. typedef ctkErrorLogModel Self;
  54. explicit ctkErrorLogModel(QObject* parentObject = 0);
  55. virtual ~ctkErrorLogModel();
  56. enum LogLevel
  57. {
  58. None = 0x0,
  59. Unknown = 0x1,
  60. Status = 0x2,
  61. Trace = 0x4,
  62. Debug = 0x8,
  63. Info = 0x10,
  64. Warning = 0x20,
  65. Error = 0x40,
  66. Critical = 0x80,
  67. Fatal = 0x100
  68. };
  69. Q_DECLARE_FLAGS(LogLevels, LogLevel)
  70. enum ColumnsIds
  71. {
  72. TimeColumn = 0,
  73. LogLevelColumn,
  74. OriginColumn,
  75. DescriptionColumn
  76. };
  77. enum ItemDataRole{
  78. DescriptionTextRole = Qt::UserRole + 1
  79. };
  80. bool registerMsgHandler(ctkErrorLogAbstractMessageHandler * msgHandler);
  81. QStringList msgHandlerNames()const;
  82. bool msgHandlerEnabled(const QString& handlerName) const;
  83. void setMsgHandlerEnabled(const QString& handlerName, bool enabled);
  84. void disableAllMsgHandler();
  85. QString logLevelAsString(LogLevel logLevel)const;
  86. void addEntry(LogLevel logLevel, const QString& origin, const char* text);
  87. void clear();
  88. void filterEntry(const LogLevels& logLevel = Unknown, bool disableFilter = false);
  89. LogLevels logLevelFilter()const;
  90. bool logEntryGrouping()const;
  91. void setLogEntryGrouping(bool value);
  92. signals:
  93. void logLevelFilterChanged();
  94. protected:
  95. QScopedPointer<ctkErrorLogModelPrivate> d_ptr;
  96. private:
  97. Q_DECLARE_PRIVATE(ctkErrorLogModel);
  98. Q_DISABLE_COPY(ctkErrorLogModel);
  99. };
  100. Q_DECLARE_OPERATORS_FOR_FLAGS(ctkErrorLogModel::LogLevels)
  101. #endif