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