CustusX  15.3.3-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxConsoleWidget.cpp
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 #include "cxConsoleWidget.h"
35 
36 #include <iostream>
37 #include <QVBoxLayout>
38 #include <QMenu>
39 #include <QScrollBar>
40 #include <QContextMenuEvent>
41 #include "cxTypeConversions.h"
42 #include "cxEnumConverter.h"
43 #include "cxDefinitionStrings.h"
44 #include "cxSettings.h"
45 #include "cxStringProperty.h"
46 #include "cxHelperWidgets.h"
48 #include "cxMessageListener.h"
49 #include "cxEnumConverter.h"
50 #include "cxUtilHelpers.h"
51 #include <QTimer>
52 #include <QThread>
53 #include <QTableWidget>
54 #include "cxLogMessageFilter.h"
55 #include <QHeaderView>
56 #include <QStackedLayout>
57 #include <QApplication>
58 #include <QClipboard>
59 #include "cxNullDeleter.h"
60 #include <QPushButton>
61 #include "cxProfile.h"
62 #include "cxTime.h"
63 
64 namespace cx
65 {
66 
68 {
69  this->createTextCharFormats();
70 }
71 
73 {
74  mFormat[mlINFO].setForeground(Qt::black);
75  mFormat[mlSUCCESS].setForeground(QColor(60, 179, 113)); // medium sea green
76  mFormat[mlWARNING].setForeground(QColor(255, 140, 0)); //dark orange
77  mFormat[mlERROR].setForeground(Qt::red);
78  mFormat[mlDEBUG].setForeground(QColor(135, 206, 250)); //sky blue
79  mFormat[mlCERR].setForeground(Qt::red);
80  mFormat[mlCOUT].setForeground(Qt::darkGray);
81 }
82 
86 
87 class MyTableWidget : public QTableWidget
88 {
89 public:
90  MyTableWidget(QWidget* parent=NULL) : QTableWidget(parent) {}
91  virtual ~MyTableWidget() {}
92  virtual void keyPressEvent(QKeyEvent* event);
93 };
94 
95 //source: http://stackoverflow.com/questions/3135737/copying-part-of-qtableview
96 void MyTableWidget::keyPressEvent(QKeyEvent* event)
97 {
98  // If Ctrl-C typed
99  // Or use event->matches(QKeySequence::Copy)
100  if (event->key() == Qt::Key_C && (event->modifiers() & Qt::ControlModifier))
101  {
102  QModelIndexList cells = selectedIndexes();
103  qSort(cells); // Necessary, otherwise they are in column order
104 
105  QString text;
106  int currentRow = 0; // To determine when to insert newlines
107  foreach (const QModelIndex& cell, cells) {
108  if (text.length() == 0) {
109  // First item
110  } else if (cell.row() != currentRow) {
111  // New row
112  text += '\n';
113  } else {
114  // Next cell
115  text += '\t';
116  }
117  currentRow = cell.row();
118  text += cell.data().toString();
119  }
120 
121  QApplication::clipboard()->setText(text);
122  }
123  else
124  {
125  event->ignore();
126  }
127 
128  QTableWidget::keyPressEvent(event);
129 }
130 
132 
134  LogMessageDisplayWidget(parent),
135  mOptions(options),
136  mScrollToBottomEnabled(true)
137 {
138  mTable = new MyTableWidget(this);
139  QVBoxLayout* layout = new QVBoxLayout(this);
140  layout->setMargin(0);
141  this->setLayout(layout);
142  layout->addWidget(mTable);
143 
144  mTable->setShowGrid(false);
145  mTable->setTextElideMode(Qt::ElideLeft);
146  mTable->setWordWrap(false);
147 
148  mTable->setColumnCount(6);
149  mTable->setRowCount(0);
150  mTable->setHorizontalHeaderLabels(QStringList() << "time" << "source" << "function" << "thread" << "level" << "description");
151  mTable->setSelectionBehavior(QAbstractItemView::SelectRows);
152  mTable->verticalHeader()->hide();
153 
154  QFontMetrics metric(this->font());
155  mTable->setColumnWidth(0, metric.width("00:00:00.000xx"));
156  mTable->setColumnWidth(1, metric.width("cxSourceFile.cpp:333xx"));
157  mTable->setColumnWidth(2, metric.width("function()xx"));
158  mTable->setColumnWidth(3, metric.width("mainxx"));
159  mTable->setColumnWidth(4, metric.width("WARNINGxx"));
160  mTable->horizontalHeader()->setStretchLastSection(true);
161 
162  for (int i=0; i<mTable->horizontalHeader()->count(); ++i)
163  {
164  XmlOptionItem headerItem("headerwidth_"+QString::number(i), mOptions.getElement());
165  int value = headerItem.readValue("-1").toInt();
166  if (value<0)
167  continue;
168  mTable->setColumnWidth(i, value);
169  }
170 
171  int textLineHeight = metric.lineSpacing();
172  mTable->verticalHeader()->setDefaultSectionSize(textLineHeight);
173 }
174 
176 {
177  for (int i=0; i<mTable->horizontalHeader()->count(); ++i)
178  {
179  XmlOptionItem headerItem("headerwidth_"+QString::number(i), mOptions.getElement());
180  headerItem.writeValue(QString::number(mTable->columnWidth(i)));
181  }
182 }
183 
185 {
186  mTable->setRowCount(0);
187 }
188 
190 {
191  mTable->horizontalScrollBar()->setValue(mTable->horizontalScrollBar()->minimum());
192 }
193 
195 {
196  int row = mTable->rowCount();
197  mTable->insertRow(row);
198 
199  QTableWidgetItem* item = NULL;
200 
201  QString timestamp = message.getTimeStamp().toString("hh:mm:ss.zzz");
202  item = this->addItem(0, timestamp, message);
203 
204  QString source;
205  if (!message.mSourceFile.isEmpty())
206  source = QString("%1:%2").arg(message.mSourceFile).arg(message.mSourceLine);
207  item = this->addItem(1, source, message);
208 // item->setTextAlignment(Qt::AlignRight);
209 
210  QString function = message.mSourceFunction;
211  item = this->addItem(2, function, message);
212 
213  QString thread = message.mThread;
214  item = this->addItem(3, thread, message);
215 
216  QString level = enum2string(message.getMessageLevel());
217  item = this->addItem(4, level, message);
218 
219  QString desc = message.getText();
220  item = this->addItem(5, desc, message);
221 
222  this->scrollToBottom();
223 }
224 
226 {
228  this->scrollToBottom();
229 }
230 
232 {
233  mTable->horizontalHeader()->setVisible(on);
234 }
235 
237 {
239  QTimer::singleShot(0, mTable, SLOT(scrollToBottom()));
240 }
241 
242 QTableWidgetItem* DetailedLogMessageDisplayWidget::addItem(int column, QString text, const Message& message)
243 {
244  int row = mTable->rowCount();
245 
246  QTableWidgetItem* item = new QTableWidgetItem(text);
247  item->setStatusTip(text);
248  item->setToolTip(text);
249  item->setForeground(mFormat[message.getMessageLevel()].foreground());
250  item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
251  mTable->setItem(row-1, column, item);
252  return item;
253 }
254 
258 
260  LogMessageDisplayWidget(parent),
261  mScrollToBottomEnabled(true)
262 {
263  mBrowser = new QTextBrowser(this);
264  mBrowser->setReadOnly(true);
265  mBrowser->setLineWrapMode(QTextEdit::NoWrap);
266  QVBoxLayout* layout = new QVBoxLayout(this);
267  layout->setMargin(0);
268  this->setLayout(layout);
269  layout->addWidget(mBrowser);
270  this->scrollToBottom();
271 }
272 
274 {
275  mBrowser->clear();
276  this->scrollToBottom();
277 }
278 
280 {
281  mBrowser->horizontalScrollBar()->setValue(mBrowser->horizontalScrollBar()->minimum());
282 }
283 
285 {
286  this->format(message);
287 
288  mBrowser->append(this->getCompactMessage(message));
289 
290  this->scrollToBottom();
291 }
292 
294 {
295  mScrollToBottomEnabled = on;
296  this->scrollToBottom();
297 }
298 
299 void SimpleLogMessageDisplayWidget::scrollToBottom()
300 {
301  if (mScrollToBottomEnabled)
302  mBrowser->verticalScrollBar()->setValue(mBrowser->verticalScrollBar()->maximum());
303 }
304 
306 {
307  if(message.mMessageLevel == mlRAW)
308  return message.mText;
309 
310  QString retval;
311  retval= QString("[%1] %2")
312 // .arg(message.mTimeStamp.toString(timestampSecondsFormatNice()))
313  .arg(message.mTimeStamp.toString("hh:mm"))
314  .arg(message.mText);
315  return retval;
316 }
317 
319 {
320  if (!mFormat.count(message.getMessageLevel()))
321  return;
322  mBrowser->setCurrentCharFormat(mFormat[message.getMessageLevel()]);
323 }
324 
328 
329 //class MyExpandButton : public ctkExpandButton
330 //{
331 //public:
332 // MyExpandButton(QWidget* parent) : ctkExpandButton(parent) {}
333 // virtual QSize sizeHint() const
334 // {
335 // int ext = this->style()->pixelMetric(QStyle::PM_ToolBarExtensionExtent);
336 // std::cout << "ext: " << ext << std::endl;
338 // return QSize(ext, ext * 2 / 3);
339 // }
340 //};
341 
345 
346 PopupButton::PopupButton(QWidget* parent)
347 {
348 // this->setMouseTracking(true);
349  // this->setFrameStyle(QFrame::Box);
350 
351  QVBoxLayout* layout = new QVBoxLayout(this);
352  layout->setMargin(0);
353  this->setLayout(layout);
354 
355  // QToolButton* expandButton = new QToolButton(this);
356  QToolButton* expandButton = new CXSmallToolButton(this);
357  mShowHeaderButton = expandButton;
358  this->setFixedSize(expandButton->sizeHint());
359 
360  QAction* action = new QAction(QIcon(":icons/open_icon_library/layer-lower-3.png"), "Controls", this);
361  QString tip = "Show Controls";
362  action->setStatusTip(tip);
363  action->setWhatsThis(tip);
364  action->setToolTip(tip);
365  connect(action, SIGNAL(triggered()), this, SLOT(onTriggered()));
366  mAction = action;
367 
368  mShowHeaderButton->setDefaultAction(action);
369  layout->addWidget(mShowHeaderButton);
370 
371  action->setCheckable(true);
372 }
373 
374 //void PopupButton::mouseMoveEvent(QMouseEvent* event)
375 //{
376 // std::cout << "mouse move" << std::endl;
377 //}
378 
380 {
381  return mShowHeaderButton->isChecked();
382 }
383 
384 void PopupButton::onTriggered()
385 {
386  if (this->getShowPopup())
387  mAction->setIcon(QIcon(":icons/open_icon_library/layer-raise-3.png"));
388  else
389  mAction->setIcon(QIcon(":icons/open_icon_library/layer-lower-3.png"));
390 
391  emit popup(this->getShowPopup());
392 }
393 
394 
398 
399 ConsoleWidget::ConsoleWidget(QWidget* parent, QString uid, QString name, XmlOptionFile options, LogPtr log) :
400  BaseWidget(parent, uid, name),
401  mSeverityAction(NULL),
402  mMessagesWidget(NULL),
403  mMessagesLayout(NULL),
404  mDetailsAction(NULL)
405 {
406  mOptions = options;
407  mLog = log;
408  connect(mLog.get(), &Log::loggingFolderChanged, this, &ConsoleWidget::onLoggingFolderChanged);
409 
410  this->setModified();
411 }
412 
413 ConsoleWidget::ConsoleWidget(QWidget* parent, QString uid, QString name) :
414  BaseWidget(parent, uid, name),
415  mSeverityAction(NULL),
416  mMessagesWidget(NULL),
417  mMessagesLayout(NULL),
418  mDetailsAction(NULL)
419 {
420  mOptions = profile()->getXmlSettings().descend(this->objectName());
421  mLog = reporter();
422  connect(mLog.get(), &Log::loggingFolderChanged, this, &ConsoleWidget::onLoggingFolderChanged);
423 
424  this->setModified();
425 }
426 
428 {
429  if (!mMessagesLayout)
430  {
431  this->createUI();
432  }
433 
434 }
435 
436 void ConsoleWidget::createUI()
437 {
438  mSeverityAction = NULL;
439  mMessagesWidget = NULL;
440 
441  this->setWhatsThis(this->defaultWhatsThis());
442 
443  QVBoxLayout* layout = new QVBoxLayout;
444  layout->setMargin(0);
445  layout->setSpacing(0);
446  this->setLayout(layout);
447 
448  mControlLayout = new QHBoxLayout;
449  mControlLayout->setMargin(0);
450  layout->addLayout(mControlLayout);
451 
452  mShowControlsButton = new PopupButton(this);
453  mControlLayout->addWidget(mShowControlsButton);
454  connect(mShowControlsButton, &PopupButton::popup, this, &ConsoleWidget::updateShowHeader);
455 
456  this->createButtonWidget();
457 
458  mControlLayout->addStretch(1);
459 
460  mMessagesLayout = new QVBoxLayout;
461  mMessagesLayout->setMargin(0);
462  layout->addLayout(mMessagesLayout);
463 
464  mMessageListener = MessageListener::create(mLog);
465  mMessageFilter.reset(new MessageFilterConsole);
466  mMessageListener->installFilter(mMessageFilter);
467  connect(mMessageListener.get(), &MessageListener::newMessage, this, &ConsoleWidget::receivedMessage);
468  connect(mMessageListener.get(), &MessageListener::newChannel, this, &ConsoleWidget::receivedChannel);
469 
470  QString defVal = enum2string<LOG_SEVERITY>(msINFO);
471  LOG_SEVERITY value = string2enum<LOG_SEVERITY>(this->option("showLevel").readValue(defVal));
472  mMessageFilter->setLowestSeverity(value);
473 
474  mMessageFilter->setActiveChannel(mChannelSelector->getValue());
475  mMessageListener->installFilter(mMessageFilter);
476 
477  this->updateUI();
478 }
479 
480 void ConsoleWidget::createButtonWidget()
481 {
482  mButtonWidget = new QWidget(this);
483  mControlLayout->addWidget(mButtonWidget);
484 
485  QHBoxLayout* buttonLayout = new QHBoxLayout;
486  buttonLayout->setMargin(0);
487  buttonLayout->setSpacing(0);
488 
489  mButtonWidget->setLayout(buttonLayout);
490 
491  this->addSeverityButtons(buttonLayout);
492  buttonLayout->addSpacing(8);
493  this->addDetailsButton(buttonLayout);
494 
495  this->createChannelSelector();
496 
497  LabeledComboBoxWidget* channelSelectorWidget = new LabeledComboBoxWidget(this, mChannelSelector);
498  channelSelectorWidget->showLabel(false);
499  buttonLayout->addSpacing(8);
500  buttonLayout->addWidget(channelSelectorWidget);
501  buttonLayout->setStretch(buttonLayout->count()-1, 0);
502 
503  buttonLayout->addStretch(1);
504 }
505 
506 void ConsoleWidget::updateShowHeader()
507 {
508  bool show = mShowControlsButton->getShowPopup();
509 
510  mMessagesWidget->showHeader(show);
511  mButtonWidget->setVisible(show);
512 
513  if (show)
514  {
515  mControlLayout->insertWidget(0, mShowControlsButton);
516  }
517  else
518  {
519  // remove from layout, add to top of this
520  mControlLayout->removeWidget(mShowControlsButton);
521  mShowControlsButton->setParent(NULL);
522  mShowControlsButton->setParent(this);
523  mShowControlsButton->setVisible(true);
524 
525  }
526 }
527 
528 
529 XmlOptionItem ConsoleWidget::option(QString name)
530 {
531  return XmlOptionItem(name, mOptions.getElement());
532 }
533 
535 {
536  if (!mMessageFilter)
537  return;
538 
539  QString levelString = enum2string<LOG_SEVERITY>(mMessageFilter->getLowestSeverity());
540  this->option("showLevel").writeValue(levelString);
541  this->option("showDetails").writeVariant(mDetailsAction->isChecked());
542 }
543 
545 {
546  return "<html>"
547  "<h3>CustusX console.</h3>"
548  "<p>Display device for system administration messages.</p>"
549  "<p><i>Right click for addition options.</i></p>"
550  "</html>";
551 }
552 
554 {
555  if (mDetailsAction)
556  {
557  mDetailsAction->setChecked(on);
558  this->updateUI();
559  }
560  else
561  {
562  this->option("showDetails").writeVariant(on);
563  }
564 }
565 
566 void ConsoleWidget::addSeverityButtons(QBoxLayout* buttonLayout)
567 {
568  QAction* actionUp = this->createAction(this,
569  QIcon(":/icons/open_icon_library/zoom-in-3.png"),
570  "More", "More detailed log output",
571  SLOT(onSeverityDown()),
572  buttonLayout, new CXSmallToolButton());
573 
574  this->addSeverityIndicator(buttonLayout);
575 
576  QAction* actionDown = this->createAction(this,
577  QIcon(":/icons/open_icon_library/zoom-out-3.png"),
578  "Less ", "Less detailed log output",
579  SLOT(onSeverityUp()),
580  buttonLayout, new CXSmallToolButton());
581 }
582 
583 void ConsoleWidget::addSeverityIndicator(QBoxLayout* buttonLayout)
584 {
585  QAction* action = new QAction(QIcon(""), "Severity", this);
586  mSeverityAction = action;
587  QString help = "Lowest displayed log severity";
588  action->setStatusTip(help);
589  action->setWhatsThis(help);
590  action->setToolTip(help);
591  QToolButton* button = new CXSmallToolButton();
592  button->setDefaultAction(action);
593  buttonLayout->addWidget(button);
594 }
595 
596 void ConsoleWidget::updateSeverityIndicator()
597 {
598  LOG_SEVERITY severity = mMessageFilter->getLowestSeverity();
599 
600  switch (severity)
601  {
602  case msERROR:
603  this->updateSeverityIndicator("window-close-3.png", "error");
604  break;
605  case msWARNING:
606  this->updateSeverityIndicator("dialog-warning-panel.png", "warning");
607  break;
608  case msINFO:
609  this->updateSeverityIndicator("dialog-information-4.png", "info");
610  break;
611  case msDEBUG:
612  this->updateSeverityIndicator("script-error.png", "debug");
613  break;
614  default:
615  this->updateSeverityIndicator("script-error.png", "");
616  break;
617  }
618 }
619 
620 void ConsoleWidget::updateSeverityIndicator(QString iconname, QString help)
621 {
622  QIcon icon(QString(":/icons/message_levels/%1").arg(iconname));
623  mSeverityAction->setIcon(icon);
624 
625  help = QString("Current log level is %1").arg(help);
626  mSeverityAction->setStatusTip(help);
627  mSeverityAction->setToolTip(help);
628 }
629 
630 void ConsoleWidget::onSeverityUp()
631 {
632  this->onSeverityChange(-1);
633 }
634 
635 void ConsoleWidget::onSeverityDown()
636 {
637  this->onSeverityChange(+1);
638 }
639 
640 void ConsoleWidget::onSeverityChange(int delta)
641 {
642  LOG_SEVERITY severity = mMessageFilter->getLowestSeverity();
643  int val = (int)severity + delta;
644  val = constrainValue(val, 0, int(msCOUNT)-1);
645  severity = static_cast<LOG_SEVERITY>(val);
646 
647  mMessageFilter->setLowestSeverity(severity);
648  mMessageListener->installFilter(mMessageFilter);
649  this->updateUI();
650 }
651 
652 void ConsoleWidget::createChannelSelector()
653 {
654  QString defval = "console";
655  mChannels << "all";
656  mChannels << defval;
657 
658  StringPropertyPtr retval;
659  retval = StringProperty::initialize("ChannelSelector",
660  "", "Log Channel to display",
661  defval, mChannels, mOptions.getElement());
662  connect(retval.get(), &StringPropertyBase::changed, this, &ConsoleWidget::onChannelSelectorChanged);
663  mChannelSelector = retval;
664 }
665 
666 void ConsoleWidget::addDetailsButton(QBoxLayout* buttonLayout)
667 {
668  QIcon icon(":/icons/open_icon_library/system-run-5.png");
669  QAction* action = this->createAction(this,
670  icon,
671  "Details", "Show detailed info on each log entry",
672  SLOT(updateUI()),
673  buttonLayout, new CXSmallToolButton());
674  action->setCheckable(true);
675 
676  bool value = this->option("showDetails").readVariant(false).toBool();
677  action->blockSignals(true);
678  action->setChecked(value);
679  action->blockSignals(false);
680 
681  mDetailsAction = action;
682 }
683 
684 void ConsoleWidget::updateUI()
685 {
686  this->updateSeverityIndicator();
687 
688  this->setWindowTitle("Console: " + mChannelSelector->getValue());
689  this->selectMessagesWidget();
690  this->updateShowHeader();
691 
692  // reset content of browser
693  QTimer::singleShot(0, this, SLOT(clearTable())); // let the messages recently emitted be processed before clearing
694 
695  mMessageListener->restart();
696 }
697 
698 void ConsoleWidget::selectMessagesWidget()
699 {
700  if (mMessagesWidget && (mMessagesWidget->getType()==this->getDetailTypeFromButton()))
701  return;
702 
703  if (mMessagesWidget)
704  {
705  // remove
706  mMessagesLayout->takeAt(0);
707  delete mMessagesWidget;
708  }
709 
710  if (this->getDetailTypeFromButton()=="detail")
711  {
712  mMessagesWidget = new DetailedLogMessageDisplayWidget(this, mOptions);
713  }
714  else
715  {
716  mMessagesWidget = new SimpleLogMessageDisplayWidget(this);
717  }
718 
719  mMessagesLayout->addWidget(mMessagesWidget);
720 }
721 
722 QString ConsoleWidget::getDetailTypeFromButton() const
723 {
724  if (mDetailsAction->isChecked())
725  return "detail";
726  else
727  return "simple";
728 }
729 
730 void ConsoleWidget::clearTable()
731 {
732  if (mMessagesWidget)
733  mMessagesWidget->clear();
734 }
735 
736 void ConsoleWidget::onLoggingFolderChanged()
737 {
738  if (!mMessageFilter)
739  return;
740  mMessageListener->installFilter(mMessageFilter);
741  this->updateUI();
742 }
743 
744 void ConsoleWidget::onChannelSelectorChanged()
745 {
746  mChannelSelector->blockSignals(true);
747 
748  mMessageFilter->setActiveChannel(mChannelSelector->getValue());
749  mMessageListener->installFilter(mMessageFilter);
750  this->updateUI();
751 
752  mChannelSelector->blockSignals(false);
753 }
754 
755 void ConsoleWidget::contextMenuEvent(QContextMenuEvent* event)
756 {
757 // QMenu *menu = mBrowser->createStandardContextMenu();
758 // menu->addSeparator();
759 // menu->addAction(mLineWrappingAction);
760 // menu->exec(event->globalPos());
761 // delete menu;
762 }
763 
764 void ConsoleWidget::showEvent(QShowEvent* event)
765 {
766  if (mMessagesWidget)
767  mMessagesWidget->normalize();
768 }
769 
770 void ConsoleWidget::receivedChannel(QString channel)
771 {
772  if (!mChannels.count(channel))
773  {
774  mChannels.append(channel);
775  mChannelSelector->setValueRange(mChannels);
776  }
777 }
778 
779 void ConsoleWidget::receivedMessage(Message message)
780 {
781  this->receivedChannel(message.mChannel);
782 // if (!mChannels.count(message.mChannel))
783 // {
784 // mChannels.append(message.mChannel);
785 // mChannelSelector->setValueRange(mChannels);
786 // }
787 
788  this->printMessage(message);
789 }
790 
791 void ConsoleWidget::printMessage(const Message& message)
792 {
793  if (mMessagesWidget)
794  mMessagesWidget->add(message);
795 }
796 
797 //void ConsoleWidget::lineWrappingSlot(bool checked)
798 //{
800 //}
801 
802 }//namespace cx
static MessageListenerPtr create(LogPtr log=LogPtr())
mlSUCCESS
Definition: cxDefinitions.h:80
cxResource_EXPORT ProfilePtr profile()
Definition: cxProfile.cpp:142
QString getCompactMessage(Message message)
SimpleLogMessageDisplayWidget(QWidget *parent=NULL)
virtual void showHeader(bool on)=0
mlRAW
Definition: cxDefinitions.h:80
QString mSourceFile
Definition: cxLogMessage.h:98
DetailedLogMessageDisplayWidget(QWidget *parent, XmlOptionFile options)
PopupButton(QWidget *parent=NULL)
MyTableWidget(QWidget *parent=NULL)
virtual void keyPressEvent(QKeyEvent *event)
ReporterPtr reporter()
Definition: cxReporter.cpp:59
void newChannel(QString channel)
msDEBUG
Definition: cxDefinitions.h:94
void writeVariant(const QVariant &val)
void format(const Message &message)
formats the text to suit the message level
void loggingFolderChanged()
mlCERR
Definition: cxDefinitions.h:80
virtual QString getType() const =0
QString getText() const
The raw message.
msINFO
Definition: cxDefinitions.h:94
virtual void setScrollToBottom(bool on)
QString mThread
Definition: cxLogMessage.h:96
QDomElement getElement()
return the current element
mlDEBUG
Definition: cxDefinitions.h:80
QDateTime getTimeStamp() const
The time at which the message was created.
MESSAGE_LEVEL mMessageLevel
Definition: cxLogMessage.h:90
QAction * createAction(QObject *parent, QIcon iconName, QString text, QString tip, T slot, QLayout *layout=NULL, QToolButton *button=new QToolButton())
Definition: cxBaseWidget.h:130
void popup(bool show)
Helper class for storing one string value in an xml document.
boost::shared_ptr< class StringProperty > StringPropertyPtr
QString mChannel
Definition: cxLogMessage.h:95
msERROR
Definition: cxDefinitions.h:94
boost::shared_ptr< class Log > LogPtr
Definition: cxLog.h:68
std::map< MESSAGE_LEVEL, QTextCharFormat > mFormat
double constrainValue(double val, double min, double max)
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 showEvent(QShowEvent *event)
updates internal info before showing the widget
void changed()
emit when the underlying data value is changed: The user interface will be updated.
static StringPropertyPtr initialize(const QString &uid, QString name, QString help, QString value, QStringList range, QDomNode root=QDomNode())
void writeValue(const QString &val)
QDateTime mTimeStamp
Definition: cxLogMessage.h:92
virtual void add(const Message &message)=0
mlINFO
Definition: cxDefinitions.h:80
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:108
QString mSourceFunction
Definition: cxLogMessage.h:99
void contextMenuEvent(QContextMenuEvent *event)
void setDetails(bool on)
virtual void add(const Message &message)
ConsoleWidget(QWidget *parent, QString uid="ConsoleWidget", QString name="Console")
QVariant readVariant(const QVariant &defval=QVariant()) const
mlCOUT
Definition: cxDefinitions.h:80
virtual QString defaultWhatsThis() const
Returns a short description of what this widget will do for you.
QString mText
Definition: cxLogMessage.h:89
LogMessageDisplayWidget(QWidget *parent)
msWARNING
Definition: cxDefinitions.h:94
virtual void normalize()=0
mlWARNING
Definition: cxDefinitions.h:80
virtual void prePaintEvent()
void newMessage(Message message)
virtual void add(const Message &message)
MESSAGE_LEVEL getMessageLevel() const
The category of the message.
mlERROR
Definition: cxDefinitions.h:80
QString enum2string(const ENUM &val)
Helper class for xml files used to store ssc/cx data.
QString readValue(const QString &defval) const