NorMIT-nav  22.09
An IGT application
cxConsoleWidget.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 
13 #ifndef CXCONSOLEWIDGET_H_
14 #define CXCONSOLEWIDGET_H_
15 
16 #include "cxResourceWidgetsExport.h"
17 
18 #include "cxBaseWidget.h"
19 #include "cxReporter.h"
20 #include <QTextBrowser>
21 #include <QTextCharFormat>
22 #include "cxStringProperty.h"
23 class QTableWidget;
24 class QTableWidgetItem;
25 
26 
27 class QContextMenuEvent;
28 class QAction;
29 class QStackedLayout;
30 
31 namespace cx
32 {
33 class PopupToolbarWidget;
34 typedef boost::shared_ptr<class MessageListener> MessageListenerPtr;
35 
36 class LogMessageDisplayWidget : public QWidget
37 {
38 public:
39  LogMessageDisplayWidget(QWidget *parent);
41  virtual void clear() = 0;
42  virtual void add(const Message& message) = 0;
43  virtual void normalize() = 0;
44  virtual QString getType() const = 0;
45  virtual void setScrollToBottom(bool on) = 0;
46  virtual void showHeader(bool on) = 0;
47 protected:
48  void createTextCharFormats();
49  std::map<MESSAGE_LEVEL, QTextCharFormat> mFormat;
50 };
51 
53 {
54 public:
55  DetailedLogMessageDisplayWidget(QWidget* parent, XmlOptionFile options);
57  virtual void clear();
58  virtual void add(const Message& message);
59  virtual void normalize();
60  virtual QString getType() const { return "detail";}
61  virtual void setScrollToBottom(bool on);
62  virtual void showHeader(bool on);
63 
64 protected:
66  QTableWidget* mTable;
67  QTableWidgetItem *addItem(int column, QString text, const Message& message);
68  void scrollToBottom();
70 };
71 
73 {
74 public:
75  SimpleLogMessageDisplayWidget(QWidget* parent=NULL);
77  virtual void clear();
78  virtual void add(const Message& message);
79  virtual void normalize();
80  virtual QString getType() const { return "simple";}
81  virtual void setScrollToBottom(bool on);
82  virtual void showHeader(bool on) {}
83 
84  QTextBrowser* mBrowser;
85  void format(const Message &message);
86  QString getCompactMessage(Message message);
87 private:
88  void scrollToBottom();
89  bool mScrollToBottomEnabled;
90 };
91 
92 
100 class cxResourceWidgets_EXPORT ConsoleWidget: public BaseWidget
101 {
102 Q_OBJECT
103 
104 public:
105  ConsoleWidget(QWidget* parent, QString uid="console_widget", QString name="Console");
106  ConsoleWidget(QWidget* parent, QString uid, QString name, XmlOptionFile options, LogPtr log);
107  ~ConsoleWidget();
108 
109  void setDetails(bool on);
110 
111 protected slots:
112  void contextMenuEvent(QContextMenuEvent* event);
113  virtual void showEvent(QShowEvent* event);
114 
115 protected:
116  virtual void prePaintEvent();
117 
118 private slots:
119  void onChannelSelectorChanged();
120  void onLoggingFolderChanged();
121  void receivedMessage(Message message);
122  void receivedChannel(QString channel);
123 
124  void onSeverityUp();
125  void onSeverityDown();
126  void onSeverityChange(int delta);
127  void updateUI();
128  void clearTable();
129  void updateShowHeader();
130 
131 private:
132  XmlOptionItem option(QString name);
133  void createUI();
134  void printMessage(const Message& message);
135  void addSeverityButtons(QBoxLayout* buttonLayout);
136  void addDetailsButton(QBoxLayout* buttonLayout);
137  void createChannelSelector();
138  void updateSeverityIndicator(QString iconname, QString help);
139  void addSeverityIndicator(QBoxLayout* buttonLayout);
140  void updateSeverityIndicator();
141  QString getDetailTypeFromButton() const;
142  void selectMessagesWidget();
143  void createButtonWidget(QWidget *widget);
144 
145 // QAction* mLineWrappingAction;
146  QAction* mSeverityAction;
147  LogMessageDisplayWidget* mMessagesWidget;
148  QVBoxLayout* mMessagesLayout;
149 
150  QAction* mDetailsAction;
151  StringPropertyPtr mChannelSelector;
152  QStringList mChannels;
153  MessageListenerPtr mMessageListener;
154  boost::shared_ptr<class MessageFilterConsole> mMessageFilter;
155  XmlOptionFile mOptions;
156  PopupToolbarWidget* mPopupWidget;
157 
158  LogPtr mLog;
159 };
160 } // namespace cx
161 #endif /* CXCONSOLEWIDGET_H_ */
cx::LogMessageDisplayWidget::getType
virtual QString getType() const =0
cx::XmlOptionFile
Helper class for xml files used to store ssc/cx data.
Definition: cxXmlOptionItem.h:78
cx::SimpleLogMessageDisplayWidget::setScrollToBottom
virtual void setScrollToBottom(bool on)
Definition: cxConsoleWidget.cpp:267
cx::SimpleLogMessageDisplayWidget::getCompactMessage
QString getCompactMessage(Message message)
Definition: cxConsoleWidget.cpp:279
cx::DetailedLogMessageDisplayWidget::getType
virtual QString getType() const
Definition: cxConsoleWidget.h:60
cx::SimpleLogMessageDisplayWidget::~SimpleLogMessageDisplayWidget
virtual ~SimpleLogMessageDisplayWidget()
Definition: cxConsoleWidget.h:76
cx::DetailedLogMessageDisplayWidget::showHeader
virtual void showHeader(bool on)
Definition: cxConsoleWidget.cpp:205
cx::Message
Definition: cxLogMessage.h:54
cx::SimpleLogMessageDisplayWidget::add
virtual void add(const Message &message)
Definition: cxConsoleWidget.cpp:258
cxBaseWidget.h
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::LogMessageDisplayWidget::normalize
virtual void normalize()=0
cx::BaseWidget
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
cx::DetailedLogMessageDisplayWidget::scrollToBottom
void scrollToBottom()
Definition: cxConsoleWidget.cpp:210
cx::LogMessageDisplayWidget::add
virtual void add(const Message &message)=0
cx::SimpleLogMessageDisplayWidget::getType
virtual QString getType() const
Definition: cxConsoleWidget.h:80
cx::DetailedLogMessageDisplayWidget::mTable
QTableWidget * mTable
Definition: cxConsoleWidget.h:66
cx::LogMessageDisplayWidget::setScrollToBottom
virtual void setScrollToBottom(bool on)=0
cx::StringPropertyPtr
boost::shared_ptr< class StringProperty > StringPropertyPtr
Definition: cxVideoConnectionWidget.h:42
cx::SimpleLogMessageDisplayWidget
Definition: cxConsoleWidget.h:72
cxReporter.h
cx::LogMessageDisplayWidget::LogMessageDisplayWidget
LogMessageDisplayWidget(QWidget *parent)
Definition: cxConsoleWidget.cpp:44
cx::LogMessageDisplayWidget::clear
virtual void clear()=0
cx::DetailedLogMessageDisplayWidget::addItem
QTableWidgetItem * addItem(int column, QString text, const Message &message)
Definition: cxConsoleWidget.cpp:216
cx::LogMessageDisplayWidget::showHeader
virtual void showHeader(bool on)=0
cx::LogMessageDisplayWidget::mFormat
std::map< MESSAGE_LEVEL, QTextCharFormat > mFormat
Definition: cxConsoleWidget.h:49
cx::SimpleLogMessageDisplayWidget::SimpleLogMessageDisplayWidget
SimpleLogMessageDisplayWidget(QWidget *parent=NULL)
Definition: cxConsoleWidget.cpp:233
cx::PopupToolbarWidget
Definition: cxPopupToolbarWidget.h:51
cx::MessageListenerPtr
boost::shared_ptr< class MessageListener > MessageListenerPtr
Definition: cxLog.h:45
cx::DetailedLogMessageDisplayWidget::DetailedLogMessageDisplayWidget
DetailedLogMessageDisplayWidget(QWidget *parent, XmlOptionFile options)
Definition: cxConsoleWidget.cpp:110
cx::XmlOptionItem
Helper class for storing one string value in an xml document.
Definition: cxXmlOptionItem.h:38
cx::DetailedLogMessageDisplayWidget::setScrollToBottom
virtual void setScrollToBottom(bool on)
Definition: cxConsoleWidget.cpp:199
cx::LogMessageDisplayWidget
Definition: cxConsoleWidget.h:36
cx::LogMessageDisplayWidget::~LogMessageDisplayWidget
virtual ~LogMessageDisplayWidget()
Definition: cxConsoleWidget.h:40
cx::DetailedLogMessageDisplayWidget::mScrollToBottomEnabled
bool mScrollToBottomEnabled
Definition: cxConsoleWidget.h:69
cx::DetailedLogMessageDisplayWidget::normalize
virtual void normalize()
Definition: cxConsoleWidget.cpp:166
cx::DetailedLogMessageDisplayWidget::add
virtual void add(const Message &message)
Definition: cxConsoleWidget.cpp:171
cx::LogMessageDisplayWidget::createTextCharFormats
void createTextCharFormats()
sets up the formating rules for the message levels
Definition: cxConsoleWidget.cpp:49
cx::SimpleLogMessageDisplayWidget::normalize
virtual void normalize()
Definition: cxConsoleWidget.cpp:253
cx::SimpleLogMessageDisplayWidget::format
void format(const Message &message)
formats the text to suit the message level
Definition: cxConsoleWidget.cpp:292
cx::LogPtr
boost::shared_ptr< class Log > LogPtr
Definition: cxLog.h:47
cx::DetailedLogMessageDisplayWidget::clear
virtual void clear()
Definition: cxConsoleWidget.cpp:161
cx::SimpleLogMessageDisplayWidget::mBrowser
QTextBrowser * mBrowser
Definition: cxConsoleWidget.h:84
cxStringProperty.h
cx::SimpleLogMessageDisplayWidget::showHeader
virtual void showHeader(bool on)
Definition: cxConsoleWidget.h:82
cx::DetailedLogMessageDisplayWidget
Definition: cxConsoleWidget.h:52
cx::DetailedLogMessageDisplayWidget::mOptions
XmlOptionFile mOptions
Definition: cxConsoleWidget.h:65
cx::ConsoleWidget
Widget for displaying status messages.
Definition: cxConsoleWidget.h:100
cx::SimpleLogMessageDisplayWidget::clear
virtual void clear()
Definition: cxConsoleWidget.cpp:247
cx::DetailedLogMessageDisplayWidget::~DetailedLogMessageDisplayWidget
virtual ~DetailedLogMessageDisplayWidget()
Definition: cxConsoleWidget.cpp:152