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 
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 
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 
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:
147 
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
virtual ~ctkErrorLogModel()
QStringList msgHandlerEnabled() const
Return names of the enabled message handlers.
void setFileLoggingPattern(const QString &value)
QScopedPointer< ctkErrorLogModelPrivate > d_ptr
void setFilePath(const QString &filePath)
void disableAllMsgHandler()
ctkErrorLogModel Self
Q_INVOKABLE int logEntryCount() const
QSortFilterProxyModel Superclass
bool msgHandlerEnabled(const QString &handlerName) const
Return True if the handler identified by handlerName is enabled.
void setMsgHandlerEnabled(const QStringList &handlerNames)
Enable handler identified by their names.
void entryAdded(ctkErrorLogLevel::LogLevel logLevel)
void addEntry(const QDateTime &currentDateTime, const QString &threadId, ctkErrorLogLevel::LogLevel logLevel, const QString &origin, const ctkErrorLogContext &context, const QString &text)
QString filePath() const
QString fileLoggingPattern() const
bool logEntryGrouping() const
QVariant logEntryData(int row, int column=ctkErrorLogModel::DescriptionColumn, int role=Qt::DisplayRole) const
void setNumberOfFilesToKeep(int value)
ctkErrorLogLevel::LogLevels logLevelFilter() const
void logLevelFilterChanged()
int numberOfFilesToKeep() const
ctkErrorLogTerminalOutput::TerminalOutputs terminalOutputs() const
void setFileLoggingEnabled(bool value)
bool registerMsgHandler(ctkErrorLogAbstractMessageHandler *msgHandler)
Register a message handler.
void setMsgHandlerEnabled(const QString &handlerName, bool enabled)
Enable a specific handler given its name.
void setLogEntryGrouping(bool value)
void setAsynchronousLogging(bool value)
bool fileLoggingEnabled() const
QStringList msgHandlerNames() const
Q_INVOKABLE QString logEntryDescription(int row) const
void enableAllMsgHandler()
void clear()
Remove all log entries from model.
bool asynchronousLogging() const
ctkErrorLogModel(QObject *parentObject=0)
void setAllMsgHandlerEnabled(bool enabled)
void setTerminalOutputs(const ctkErrorLogTerminalOutput::TerminalOutputs &terminalOutput)
void filterEntry(const ctkErrorLogLevel::LogLevels &logLevel=ctkErrorLogLevel::Unknown, bool disableFilter=false)