16 #include <QVBoxLayout> 19 #include <QContextMenuEvent> 32 #include <QTableWidget> 34 #include <QHeaderView> 35 #include <QStackedLayout> 36 #include <QApplication> 39 #include <QPushButton> 72 virtual void keyPressEvent(QKeyEvent* event);
80 if (event->key() == Qt::Key_C && (
event->modifiers() & Qt::ControlModifier))
82 QModelIndexList cells = selectedIndexes();
87 foreach (
const QModelIndex& cell, cells) {
88 if (text.length() == 0) {
90 }
else if (cell.row() != currentRow) {
97 currentRow = cell.row();
98 text += cell.data().toString();
101 QApplication::clipboard()->setText(text);
108 QTableWidget::keyPressEvent(event);
116 mScrollToBottomEnabled(true)
119 QVBoxLayout* layout =
new QVBoxLayout(
this);
120 layout->setMargin(0);
121 this->setLayout(layout);
122 layout->addWidget(
mTable);
124 mTable->setShowGrid(
false);
125 mTable->setTextElideMode(Qt::ElideLeft);
126 mTable->setWordWrap(
false);
128 mTable->setColumnCount(6);
130 mTable->setHorizontalHeaderLabels(QStringList() <<
"time" <<
"source" <<
"function" <<
"thread" <<
"level" <<
"description");
131 mTable->setSelectionBehavior(QAbstractItemView::SelectRows);
132 mTable->verticalHeader()->hide();
134 QFontMetrics metric(this->font());
135 mTable->setColumnWidth(0, metric.width(
"00:00:00.000xx"));
136 mTable->setColumnWidth(1, metric.width(
"cxSourceFile.cpp:333xx"));
137 mTable->setColumnWidth(2, metric.width(
"function()xx"));
138 mTable->setColumnWidth(3, metric.width(
"mainxx"));
139 mTable->setColumnWidth(4, metric.width(
"WARNINGxx"));
140 mTable->horizontalHeader()->setStretchLastSection(
true);
142 for (
int i=0; i<
mTable->horizontalHeader()->count(); ++i)
145 int value = headerItem.
readValue(
"-1").toInt();
148 mTable->setColumnWidth(i, value);
151 int textLineHeight = metric.lineSpacing();
152 mTable->verticalHeader()->setDefaultSectionSize(textLineHeight);
157 for (
int i=0; i<
mTable->horizontalHeader()->count(); ++i)
171 mTable->horizontalScrollBar()->setValue(
mTable->horizontalScrollBar()->minimum());
176 int row =
mTable->rowCount();
179 QString timestamp = message.
getTimeStamp().toString(
"hh:mm:ss.zzz");
180 this->
addItem(0, timestamp, message);
185 this->
addItem(1, source, message);
188 this->
addItem(2,
function, message);
190 QString thread = message.
mThread;
191 this->
addItem(3, thread, message);
194 this->
addItem(4, level, message);
196 QString desc = message.
getText();
197 this->
addItem(5, desc, message);
210 mTable->horizontalHeader()->setVisible(on);
221 int row =
mTable->rowCount();
223 QTableWidgetItem* item =
new QTableWidgetItem(text);
224 item->setStatusTip(text);
225 item->setToolTip(text);
227 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
228 mTable->setItem(row-1, column, item);
242 mBrowser->setLineWrapMode(QTextEdit::NoWrap);
243 QVBoxLayout* layout =
new QVBoxLayout(
this);
244 layout->setMargin(0);
245 this->setLayout(layout);
247 this->scrollToBottom();
253 this->scrollToBottom();
258 mBrowser->horizontalScrollBar()->setValue(
mBrowser->horizontalScrollBar()->minimum());
267 this->scrollToBottom();
272 mScrollToBottomEnabled = on;
273 this->scrollToBottom();
276 void SimpleLogMessageDisplayWidget::scrollToBottom()
278 if (mScrollToBottomEnabled)
279 mBrowser->verticalScrollBar()->setValue(
mBrowser->verticalScrollBar()->maximum());
285 return message.
mText;
288 retval= QString(
"[%1] %2")
308 mSeverityAction(NULL),
309 mMessagesWidget(NULL),
310 mMessagesLayout(NULL),
322 mSeverityAction(NULL),
323 mMessagesWidget(NULL),
324 mMessagesLayout(NULL),
327 mOptions =
profile()->getXmlSettings().descend(this->objectName());
336 if (!mMessagesLayout)
343 void ConsoleWidget::createUI()
345 mSeverityAction = NULL;
346 mMessagesWidget = NULL;
348 this->setToolTip(
"Display system information, warnings and errors.");
350 QVBoxLayout* layout =
new QVBoxLayout;
351 layout->setMargin(0);
352 layout->setSpacing(0);
353 this->setLayout(layout);
357 layout->addWidget(mPopupWidget);
358 this->createButtonWidget(mPopupWidget->
getToolbar());
360 mMessagesLayout =
new QVBoxLayout;
361 mMessagesLayout->setMargin(0);
362 layout->addLayout(mMessagesLayout);
366 mMessageListener->installFilter(mMessageFilter);
370 QString defVal = enum2string<LOG_SEVERITY>(
msINFO);
371 LOG_SEVERITY value = string2enum<LOG_SEVERITY>(this->option(
"showLevel").
readValue(defVal));
372 mMessageFilter->setLowestSeverity(value);
374 mMessageFilter->setActiveChannel(mChannelSelector->getValue());
375 mMessageListener->installFilter(mMessageFilter);
380 void ConsoleWidget::createButtonWidget(QWidget* widget)
382 QHBoxLayout* buttonLayout =
new QHBoxLayout(widget);
383 buttonLayout->setMargin(0);
384 buttonLayout->setSpacing(0);
386 this->addSeverityButtons(buttonLayout);
387 buttonLayout->addSpacing(8);
388 this->addDetailsButton(buttonLayout);
390 this->createChannelSelector();
394 buttonLayout->addSpacing(8);
395 buttonLayout->addWidget(channelSelectorWidget);
396 buttonLayout->setStretch(buttonLayout->count()-1, 0);
398 buttonLayout->addStretch(1);
401 void ConsoleWidget::updateShowHeader()
418 QString levelString = enum2string<LOG_SEVERITY>(mMessageFilter->getLowestSeverity());
419 this->option(
"showLevel").
writeValue(levelString);
420 this->option(
"showDetails").
writeVariant(mDetailsAction->isChecked());
427 mDetailsAction->setChecked(on);
436 void ConsoleWidget::addSeverityButtons(QBoxLayout* buttonLayout)
439 QIcon(
":/icons/open_icon_library/zoom-in-3.png"),
440 "More",
"More detailed log output",
441 SLOT(onSeverityDown()),
444 this->addSeverityIndicator(buttonLayout);
447 QIcon(
":/icons/open_icon_library/zoom-out-3.png"),
448 "Less ",
"Less detailed log output",
449 SLOT(onSeverityUp()),
453 void ConsoleWidget::addSeverityIndicator(QBoxLayout* buttonLayout)
455 QAction* action =
new QAction(QIcon(
""),
"Severity",
this);
456 mSeverityAction = action;
457 QString help =
"Lowest displayed log severity";
458 action->setStatusTip(help);
459 action->setWhatsThis(help);
460 action->setToolTip(help);
462 button->setDefaultAction(action);
463 buttonLayout->addWidget(button);
466 void ConsoleWidget::updateSeverityIndicator()
468 LOG_SEVERITY severity = mMessageFilter->getLowestSeverity();
473 this->updateSeverityIndicator(
"window-close-3.png",
"error");
476 this->updateSeverityIndicator(
"dialog-warning-panel.png",
"warning");
479 this->updateSeverityIndicator(
"dialog-information-4.png",
"info");
482 this->updateSeverityIndicator(
"script-error.png",
"debug");
485 this->updateSeverityIndicator(
"script-error.png",
"");
490 void ConsoleWidget::updateSeverityIndicator(QString iconname, QString help)
492 QIcon icon(QString(
":/icons/message_levels/%1").arg(iconname));
493 mSeverityAction->setIcon(icon);
495 help = QString(
"Current log level is %1").arg(help);
496 mSeverityAction->setStatusTip(help);
497 mSeverityAction->setToolTip(help);
500 void ConsoleWidget::onSeverityUp()
502 this->onSeverityChange(-1);
505 void ConsoleWidget::onSeverityDown()
507 this->onSeverityChange(+1);
510 void ConsoleWidget::onSeverityChange(
int delta)
512 LOG_SEVERITY severity = mMessageFilter->getLowestSeverity();
513 int val = (int)severity + delta;
515 severity =
static_cast<LOG_SEVERITY
>(val);
517 mMessageFilter->setLowestSeverity(severity);
518 mMessageListener->installFilter(mMessageFilter);
522 void ConsoleWidget::createChannelSelector()
524 QString defval =
"console";
530 "",
"Log Channel to display",
533 mChannelSelector = retval;
536 void ConsoleWidget::addDetailsButton(QBoxLayout* buttonLayout)
538 QIcon icon(
":/icons/open_icon_library/system-run-5.png");
541 "Details",
"Show detailed info on each log entry",
544 action->setCheckable(
true);
546 bool value = this->option(
"showDetails").
readVariant(
false).toBool();
547 action->blockSignals(
true);
548 action->setChecked(value);
549 action->blockSignals(
false);
551 mDetailsAction = action;
554 void ConsoleWidget::updateUI()
556 this->updateSeverityIndicator();
558 this->setWindowTitle(
"Console: " + mChannelSelector->getValue());
559 this->selectMessagesWidget();
560 this->updateShowHeader();
564 QTimer::singleShot(0,
this, SLOT(clearTable()));
566 mMessageListener->restart();
569 void ConsoleWidget::selectMessagesWidget()
571 if (mMessagesWidget && (mMessagesWidget->
getType()==this->getDetailTypeFromButton()))
577 mMessagesLayout->takeAt(0);
578 delete mMessagesWidget;
581 if (this->getDetailTypeFromButton()==
"detail")
590 mMessagesLayout->addWidget(mMessagesWidget);
593 QString ConsoleWidget::getDetailTypeFromButton()
const 595 if (mDetailsAction->isChecked())
601 void ConsoleWidget::clearTable()
604 mMessagesWidget->
clear();
607 void ConsoleWidget::onLoggingFolderChanged()
611 mMessageListener->installFilter(mMessageFilter);
615 void ConsoleWidget::onChannelSelectorChanged()
617 mChannelSelector->blockSignals(
true);
619 mMessageFilter->setActiveChannel(mChannelSelector->getValue());
620 mMessageListener->installFilter(mMessageFilter);
623 mChannelSelector->blockSignals(
false);
641 void ConsoleWidget::receivedChannel(QString channel)
643 if (!mChannels.count(channel))
645 mChannels.append(channel);
646 mChannelSelector->setValueRange(mChannels);
650 void ConsoleWidget::receivedMessage(
Message message)
652 this->receivedChannel(message.
mChannel);
659 this->printMessage(message);
662 void ConsoleWidget::printMessage(
const Message& message)
665 mMessagesWidget->
add(message);
static MessageListenerPtr create(LogPtr log=LogPtr())
cxResource_EXPORT ProfilePtr profile()
void newChannel(QString channel)
void writeVariant(const QVariant &val)
void loggingFolderChanged()
QString getText() const
The raw message.
QDomElement getElement()
return the current element
QDateTime getTimeStamp() const
The time at which the message was created.
MESSAGE_LEVEL mMessageLevel
Helper class for storing one string value in an xml document.
boost::shared_ptr< class StringProperty > StringPropertyPtr
boost::shared_ptr< class Log > LogPtr
double constrainValue(double val, double min, double max)
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)
QVariant readVariant(const QVariant &defval=QVariant()) const
void newMessage(Message message)
MESSAGE_LEVEL getMessageLevel() const
The category of the message.
QString enum2string(const ENUM &val)
Helper class for xml files used to store ssc/cx data.
QString readValue(const QString &defval) const
Namespace for all CustusX production code.