CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkErrorLogModel.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Library: CTK
4 
5  Copyright (c) Kitware Inc.
6 
7  Licensed under the Apache License, Version 2.0 (the "License");
8  you may not use this file except in compliance with the License.
9  You may obtain a copy of the License at
10 
11  http://www.apache.org/licenses/LICENSE-2.0.txt
12 
13  Unless required by applicable law or agreed to in writing, software
14  distributed under the License is distributed on an "AS IS" BASIS,
15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  See the License for the specific language governing permissions and
17  limitations under the License.
18 
19 =========================================================================*/
20 
21 #ifndef __ctkErrorLogModel_h
22 #define __ctkErrorLogModel_h
23 
24 // Qt includes
25 #include <QSortFilterProxyModel>
26 
27 // CTK includes
28 #include "ctkWidgetsExport.h"
29 #include "ctkErrorLogLevel.h"
31 
32 //------------------------------------------------------------------------------
34 class ctkErrorLogModelPrivate;
35 struct ctkErrorLogContext;
36 
37 //------------------------------------------------------------------------------
39 class CTK_WIDGETS_EXPORT ctkErrorLogModel : public QSortFilterProxyModel
40 {
41  Q_OBJECT
42  Q_PROPERTY(bool logEntryGrouping READ logEntryGrouping WRITE setLogEntryGrouping)
43  Q_PROPERTY(ctkErrorLogTerminalOutput::TerminalOutputs terminalOutputs READ terminalOutputs WRITE setTerminalOutputs)
44  Q_PROPERTY(bool asynchronousLogging READ asynchronousLogging WRITE setAsynchronousLogging)
45  Q_PROPERTY(QString filePath READ filePath WRITE setFilePath)
46  Q_PROPERTY(int numberOfFilesToKeep READ numberOfFilesToKeep WRITE setNumberOfFilesToKeep)
47  Q_PROPERTY(bool fileLoggingEnabled READ fileLoggingEnabled WRITE setFileLoggingEnabled)
48  Q_PROPERTY(QString fileLoggingPattern READ fileLoggingPattern WRITE setFileLoggingPattern)
49 public:
50  typedef QSortFilterProxyModel Superclass;
52  explicit ctkErrorLogModel(QObject* parentObject = 0);
53  virtual ~ctkErrorLogModel();
54 
56  {
57  TimeColumn = 0,
62  MaxColumn = DescriptionColumn
63  };
64 
66  DescriptionTextRole = Qt::UserRole + 1
67  };
68 
70  bool registerMsgHandler(ctkErrorLogAbstractMessageHandler * msgHandler);
71 
72  QStringList msgHandlerNames()const;
73 
75  bool msgHandlerEnabled(const QString& handlerName) const;
76 
78  void setMsgHandlerEnabled(const QString& handlerName, bool enabled);
79 
81  QStringList msgHandlerEnabled()const;
82 
84  void setMsgHandlerEnabled(const QStringList& handlerNames);
85 
86  void enableAllMsgHandler();
87  void disableAllMsgHandler();
88  void setAllMsgHandlerEnabled(bool enabled);
89 
92  ctkErrorLogTerminalOutput::TerminalOutputs terminalOutputs()const;
93 
97  void setTerminalOutputs(const ctkErrorLogTerminalOutput::TerminalOutputs& terminalOutput);
98 
99  ctkErrorLogLevel::LogLevels logLevelFilter()const;
100 
101  void filterEntry(const ctkErrorLogLevel::LogLevels& logLevel = ctkErrorLogLevel::Unknown, bool disableFilter = false);
102 
103  bool logEntryGrouping()const;
104  void setLogEntryGrouping(bool value);
105 
106  bool asynchronousLogging()const;
107  void setAsynchronousLogging(bool value);
108 
109  QString filePath()const;
110  void setFilePath(const QString& filePath);
111 
112  int numberOfFilesToKeep()const;
113  void setNumberOfFilesToKeep(int value);
114 
115  bool fileLoggingEnabled()const;
116  void setFileLoggingEnabled(bool value);
117 
118  QString fileLoggingPattern()const;
119  void setFileLoggingPattern(const QString& value);
120 
123  QVariant logEntryData(int row,
125  int role = Qt::DisplayRole) const;
126 
129  Q_INVOKABLE QString logEntryDescription(int row) const;
130 
133  Q_INVOKABLE int logEntryCount() const;
134 
135 public Q_SLOTS:
136 
138  void clear();
139 
141  void addEntry(const QDateTime& currentDateTime, const QString& threadId,
142  ctkErrorLogLevel::LogLevel logLevel, const QString& origin,
143  const ctkErrorLogContext &context, const QString& text);
144 
145 Q_SIGNALS:
146  void logLevelFilterChanged();
147 
149  void entryAdded(ctkErrorLogLevel::LogLevel logLevel);
150 
151 protected:
152  QScopedPointer<ctkErrorLogModelPrivate> d_ptr;
153 
154 private:
155  Q_DECLARE_PRIVATE(ctkErrorLogModel)
156  Q_DISABLE_COPY(ctkErrorLogModel)
157 };
158 
159 #endif
ctkErrorLogLevel::LogLevel
LogLevel
Definition: ctkErrorLogLevel.h:39
ctkErrorLogModel::d_ptr
QScopedPointer< ctkErrorLogModelPrivate > d_ptr
Definition: ctkErrorLogModel.h:152
ctkErrorLogModel::ColumnsIds
ColumnsIds
Definition: ctkErrorLogModel.h:55
ctkErrorLogModel
Definition: ctkErrorLogModel.h:39
ctkErrorLogAbstractMessageHandler
Definition: ctkErrorLogAbstractMessageHandler.h:39
ctkErrorLogLevel.h
ctkErrorLogTerminalOutput
Definition: ctkErrorLogTerminalOutput.h:36
ctkErrorLogModel::ThreadIdColumn
@ ThreadIdColumn
Definition: ctkErrorLogModel.h:58
ctkErrorLogContext
Definition: ctkErrorLogContext.h:32
ctkErrorLogModel::ItemDataRole
ItemDataRole
Definition: ctkErrorLogModel.h:65
ctkErrorLogModel::LogLevelColumn
@ LogLevelColumn
Definition: ctkErrorLogModel.h:59
ctkErrorLogLevel::Unknown
@ Unknown
Definition: ctkErrorLogLevel.h:42
ctkErrorLogModel::Superclass
QSortFilterProxyModel Superclass
Definition: ctkErrorLogModel.h:50
ctkErrorLogModel::DescriptionColumn
@ DescriptionColumn
Definition: ctkErrorLogModel.h:61
ctkErrorLogTerminalOutput.h
ctkErrorLogModel::OriginColumn
@ OriginColumn
Definition: ctkErrorLogModel.h:60