ctkErrorLogModel.h 5.2 KB

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