Fraxinus  16.5.0-fx-rc4
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 class PopupToolbarWidget;
55 typedef boost::shared_ptr<class MessageListener> MessageListenerPtr;
56 
57 class LogMessageDisplayWidget : public QWidget
58 {
59 public:
60  LogMessageDisplayWidget(QWidget *parent);
62  virtual void clear() = 0;
63  virtual void add(const Message& message) = 0;
64  virtual void normalize() = 0;
65  virtual QString getType() const = 0;
66  virtual void setScrollToBottom(bool on) = 0;
67  virtual void showHeader(bool on) = 0;
68 protected:
69  void createTextCharFormats();
70  std::map<MESSAGE_LEVEL, QTextCharFormat> mFormat;
71 };
72 
74 {
75 public:
76  DetailedLogMessageDisplayWidget(QWidget* parent, XmlOptionFile options);
78  virtual void clear();
79  virtual void add(const Message& message);
80  virtual void normalize();
81  virtual QString getType() const { return "detail";}
82  virtual void setScrollToBottom(bool on);
83  virtual void showHeader(bool on);
84 
85 protected:
87  QTableWidget* mTable;
88  QTableWidgetItem *addItem(int column, QString text, const Message& message);
89  void scrollToBottom();
91 };
92 
94 {
95 public:
96  SimpleLogMessageDisplayWidget(QWidget* parent=NULL);
98  virtual void clear();
99  virtual void add(const Message& message);
100  virtual void normalize();
101  virtual QString getType() const { return "simple";}
102  virtual void setScrollToBottom(bool on);
103  virtual void showHeader(bool on) {}
104 
105  QTextBrowser* mBrowser;
106  void format(const Message &message);
107  QString getCompactMessage(Message message);
108 private:
109  void scrollToBottom();
110  bool mScrollToBottomEnabled;
111 };
112 
113 
121 class cxResourceWidgets_EXPORT ConsoleWidget: public BaseWidget
122 {
123 Q_OBJECT
124 
125 public:
126  ConsoleWidget(QWidget* parent, QString uid="ConsoleWidget", QString name="Console");
127  ConsoleWidget(QWidget* parent, QString uid, QString name, XmlOptionFile options, LogPtr log);
128  ~ConsoleWidget();
129 
130  void setDetails(bool on);
131 
132 protected slots:
133  void contextMenuEvent(QContextMenuEvent* event);
134  virtual void showEvent(QShowEvent* event);
135 
136 protected:
137  virtual void prePaintEvent();
138 
139 private slots:
140  void onChannelSelectorChanged();
141  void onLoggingFolderChanged();
142  void receivedMessage(Message message);
143  void receivedChannel(QString channel);
144 
145  void onSeverityUp();
146  void onSeverityDown();
147  void onSeverityChange(int delta);
148  void updateUI();
149  void clearTable();
150  void updateShowHeader();
151 
152 private:
153  XmlOptionItem option(QString name);
154  void createUI();
155  void printMessage(const Message& message);
156  void addSeverityButtons(QBoxLayout* buttonLayout);
157  void addDetailsButton(QBoxLayout* buttonLayout);
158  void createChannelSelector();
159  void updateSeverityIndicator(QString iconname, QString help);
160  void addSeverityIndicator(QBoxLayout* buttonLayout);
161  void updateSeverityIndicator();
162  QString getDetailTypeFromButton() const;
163  void selectMessagesWidget();
164  void createButtonWidget(QWidget *widget);
165 
166 // QAction* mLineWrappingAction;
167  QAction* mSeverityAction;
168  LogMessageDisplayWidget* mMessagesWidget;
169  QVBoxLayout* mMessagesLayout;
170 
171  QAction* mDetailsAction;
172  StringPropertyPtr mChannelSelector;
173  QStringList mChannels;
174  MessageListenerPtr mMessageListener;
175  boost::shared_ptr<class MessageFilterConsole> mMessageFilter;
176  XmlOptionFile mOptions;
177  PopupToolbarWidget* mPopupWidget;
178 
179  LogPtr mLog;
180 };
181 } // namespace cx
182 #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)
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)
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
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