CustusX  15.3.4-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 
34 #ifndef CXCONSOLEWIDGET_H_
35 #define CXCONSOLEWIDGET_H_
36 
37 #include "cxResourceWidgetsExport.h"
38 
39 #include "cxBaseWidget.h"
40 #include "cxReporter.h"
41 #include <QTextBrowser>
42 #include <QTextCharFormat>
43 #include "cxStringProperty.h"
44 class QTableWidget;
45 class QTableWidgetItem;
46 
47 
48 class QContextMenuEvent;
49 class QAction;
50 class QStackedLayout;
51 
52 namespace cx
53 {
54 typedef boost::shared_ptr<class MessageListener> MessageListenerPtr;
55 
56 class LogMessageDisplayWidget : public QWidget
57 {
58 public:
59  LogMessageDisplayWidget(QWidget *parent);
61  virtual void clear() = 0;
62  virtual void add(const Message& message) = 0;
63  virtual void normalize() = 0;
64  virtual QString getType() const = 0;
65  virtual void setScrollToBottom(bool on) = 0;
66  virtual void showHeader(bool on) = 0;
67 protected:
68  void createTextCharFormats();
69  std::map<MESSAGE_LEVEL, QTextCharFormat> mFormat;
70 };
71 
73 {
74 public:
75  DetailedLogMessageDisplayWidget(QWidget* parent, XmlOptionFile options);
77  virtual void clear();
78  virtual void add(const Message& message);
79  virtual void normalize();
80  virtual QString getType() const { return "detail";}
81  virtual void setScrollToBottom(bool on);
82  virtual void showHeader(bool on);
83 
84 protected:
86  QTableWidget* mTable;
87  QTableWidgetItem *addItem(int column, QString text, const Message& message);
88  void scrollToBottom();
90 };
91 
93 {
94 public:
95  SimpleLogMessageDisplayWidget(QWidget* parent=NULL);
97  virtual void clear();
98  virtual void add(const Message& message);
99  virtual void normalize();
100  virtual QString getType() const { return "simple";}
101  virtual void setScrollToBottom(bool on);
102  virtual void showHeader(bool on) {}
103 
104  QTextBrowser* mBrowser;
105  void format(const Message &message);
106  QString getCompactMessage(Message message);
107 private:
108  void scrollToBottom();
109  bool mScrollToBottomEnabled;
110 };
111 
112 class PopupButton : public QFrame
113 {
114  Q_OBJECT
115 public:
116  PopupButton(QWidget *parent = NULL);
117  bool getShowPopup() const;
118 
119 signals:
120  void popup(bool show);
121 private slots:
122  void onTriggered();
123 protected:
124 // void mouseMoveEvent(QMouseEvent* event);
125 private:
126  QAction* mAction;
127  QToolButton* mShowHeaderButton;
128 
129 };
130 
138 class cxResourceWidgets_EXPORT ConsoleWidget: public BaseWidget
139 {
140 Q_OBJECT
141 
142 public:
143  ConsoleWidget(QWidget* parent, QString uid="ConsoleWidget", QString name="Console");
144  ConsoleWidget(QWidget* parent, QString uid, QString name, XmlOptionFile options, LogPtr log);
145  ~ConsoleWidget();
146  virtual QString defaultWhatsThis() const;
147 
148  void setDetails(bool on);
149 
150 protected slots:
151  void contextMenuEvent(QContextMenuEvent* event);
152  virtual void showEvent(QShowEvent* event);
153 
154 protected:
155  virtual void prePaintEvent();
156 
157 private slots:
158  void onChannelSelectorChanged();
159  void onLoggingFolderChanged();
160  void receivedMessage(Message message);
161  void receivedChannel(QString channel);
162 
163  void onSeverityUp();
164  void onSeverityDown();
165  void onSeverityChange(int delta);
166  void updateUI();
167  void clearTable();
168  void updateShowHeader();
169 
170 private:
171  XmlOptionItem option(QString name);
172  void createUI();
173  void printMessage(const Message& message);
174  void addSeverityButtons(QBoxLayout* buttonLayout);
175  void addDetailsButton(QBoxLayout* buttonLayout);
176  void createChannelSelector();
177  void updateSeverityIndicator(QString iconname, QString help);
178  void addSeverityIndicator(QBoxLayout* buttonLayout);
179  void updateSeverityIndicator();
180  QString getDetailTypeFromButton() const;
181  void selectMessagesWidget();
182  void createButtonWidget();
183 
184 // QAction* mLineWrappingAction;
185  QAction* mSeverityAction;
186  LogMessageDisplayWidget* mMessagesWidget;
187  QVBoxLayout* mMessagesLayout;
188 
189  QAction* mDetailsAction;
190  StringPropertyPtr mChannelSelector;
191  QStringList mChannels;
192  MessageListenerPtr mMessageListener;
193  boost::shared_ptr<class MessageFilterConsole> mMessageFilter;
194  XmlOptionFile mOptions;
195  QWidget* mButtonWidget;
196  QHBoxLayout* mControlLayout;
197  PopupButton* mShowControlsButton;
198 
199 
200  LogPtr mLog;
201 };
202 } // namespace cx
203 #endif /* CXCONSOLEWIDGET_H_ */
QString getCompactMessage(Message message)
SimpleLogMessageDisplayWidget(QWidget *parent=NULL)
virtual void showHeader(bool on)=0
virtual QString getType() const
DetailedLogMessageDisplayWidget(QWidget *parent, XmlOptionFile options)
PopupButton(QWidget *parent=NULL)
void format(const Message &message)
formats the text to suit the message level
Widget for displaying status messages.
virtual QString getType() const =0
virtual void setScrollToBottom(bool on)
virtual void showHeader(bool on)
void popup(bool show)
Helper class for storing one string value in an xml document.
boost::shared_ptr< class StringProperty > StringPropertyPtr
boost::shared_ptr< class Log > LogPtr
Definition: cxLog.h:68
std::map< MESSAGE_LEVEL, QTextCharFormat > mFormat
QTableWidgetItem * addItem(int column, QString text, const Message &message)
void createTextCharFormats()
sets up the formating rules for the message levels
bool getShowPopup() const
virtual void add(const Message &message)=0
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:108
virtual void add(const Message &message)
virtual QString getType() const
LogMessageDisplayWidget(QWidget *parent)
virtual void normalize()=0
virtual void add(const Message &message)
virtual void setScrollToBottom(bool on)=0
Helper class for xml files used to store ssc/cx data.
boost::shared_ptr< class MessageListener > MessageListenerPtr
Definition: cxLog.h:66