ctkErrorLogModel.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. #ifndef __ctkErrorLogModel_h
  15. #define __ctkErrorLogModel_h
  16. // Qt includes
  17. #include <QSortFilterProxyModel>
  18. // CTK includes
  19. #include "ctkWidgetsExport.h"
  20. #include "ctkErrorLogLevel.h"
  21. #include "ctkErrorLogTerminalOutput.h"
  22. //------------------------------------------------------------------------------
  23. class ctkErrorLogAbstractMessageHandler;
  24. class ctkErrorLogModelPrivate;
  25. //------------------------------------------------------------------------------
  26. /// \ingroup Widgets
  27. class CTK_WIDGETS_EXPORT ctkErrorLogModel : public QSortFilterProxyModel
  28. {
  29. Q_OBJECT
  30. Q_PROPERTY(bool logEntryGrouping READ logEntryGrouping WRITE setLogEntryGrouping)
  31. Q_PROPERTY(ctkErrorLogTerminalOutput::TerminalOutputs terminalOutputs READ terminalOutputs WRITE setTerminalOutputs)
  32. Q_PROPERTY(bool asynchronousLogging READ asynchronousLogging WRITE setAsynchronousLogging)
  33. public:
  34. typedef QSortFilterProxyModel Superclass;
  35. typedef ctkErrorLogModel Self;
  36. explicit ctkErrorLogModel(QObject* parentObject = 0);
  37. virtual ~ctkErrorLogModel();
  38. enum ColumnsIds
  39. {
  40. TimeColumn = 0,
  41. ThreadIdColumn,
  42. LogLevelColumn,
  43. OriginColumn,
  44. DescriptionColumn,
  45. MaxColumn = DescriptionColumn
  46. };
  47. enum ItemDataRole{
  48. DescriptionTextRole = Qt::UserRole + 1
  49. };
  50. /// Register a message handler.
  51. bool registerMsgHandler(ctkErrorLogAbstractMessageHandler * msgHandler);
  52. QStringList msgHandlerNames()const;
  53. /// Return True if the handler identified by \a handlerName is enabled
  54. bool msgHandlerEnabled(const QString& handlerName) const;
  55. /// Enable a specific handler given its name
  56. void setMsgHandlerEnabled(const QString& handlerName, bool enabled);
  57. /// Return names of the enabled message handlers
  58. QStringList msgHandlerEnabled()const;
  59. /// Enable handler identified by their names
  60. void setMsgHandlerEnabled(const QStringList& handlerNames);
  61. void enableAllMsgHandler();
  62. void disableAllMsgHandler();
  63. void setAllMsgHandlerEnabled(bool enabled);
  64. /// Return if messages are both printed into the terminal and added to ctkErrorLogModel.
  65. /// \note If TerminalOutput::None is returned, message will only be added to the model.
  66. ctkErrorLogTerminalOutput::TerminalOutputs terminalOutputs()const;
  67. /// Set terminal output mode
  68. /// \sa terminalOutputs()
  69. /// \sa TerminalOutput
  70. void setTerminalOutputs(const ctkErrorLogTerminalOutput::TerminalOutputs& terminalOutput);
  71. ctkErrorLogLevel::LogLevels logLevelFilter()const;
  72. void filterEntry(const ctkErrorLogLevel::LogLevels& logLevel = ctkErrorLogLevel::Unknown, bool disableFilter = false);
  73. bool logEntryGrouping()const;
  74. void setLogEntryGrouping(bool value);
  75. bool asynchronousLogging()const;
  76. void setAsynchronousLogging(bool value);
  77. /// Return log entry information associated with \a row and \a column.
  78. /// \internal
  79. QVariant logEntryData(int row,
  80. int column = ctkErrorLogModel::DescriptionColumn,
  81. int role = Qt::DisplayRole) const;
  82. /// Return log entry information associated with Description column.
  83. /// \sa ctkErrorLogModel::DescriptionColumn, logEntryData()
  84. Q_INVOKABLE QString logEntryDescription(int row) const;
  85. /// Return current number of log entries.
  86. /// \sa clear()
  87. Q_INVOKABLE int logEntryCount() const;
  88. public Q_SLOTS:
  89. /// Remove all log entries from model
  90. void clear();
  91. /// \sa logEntryGrouping(), asynchronousLogging()
  92. void addEntry(const QDateTime& currentDateTime, const QString& threadId,
  93. ctkErrorLogLevel::LogLevel logLevel, const QString& origin, const QString& text);
  94. Q_SIGNALS:
  95. void logLevelFilterChanged();
  96. /// \sa addEntry()
  97. void entryAdded(ctkErrorLogLevel::LogLevel logLevel);
  98. protected:
  99. QScopedPointer<ctkErrorLogModelPrivate> d_ptr;
  100. private:
  101. Q_DECLARE_PRIVATE(ctkErrorLogModel)
  102. Q_DISABLE_COPY(ctkErrorLogModel)
  103. };
  104. #endif