16 #include <QVBoxLayout>
19 #include <QContextMenuEvent>
28 #include <QTableWidget>
30 #include <QHeaderView>
31 #include <QStackedLayout>
32 #include <QApplication>
35 #include <QPushButton>
77 if (event->key() == Qt::Key_C && (event->modifiers() & Qt::ControlModifier))
79 QModelIndexList cells = selectedIndexes();
84 foreach (
const QModelIndex& cell, cells) {
85 if (text.length() == 0) {
87 }
else if (cell.row() != currentRow) {
94 currentRow = cell.row();
95 text += cell.data().toString();
98 QApplication::clipboard()->setText(text);
105 QTableWidget::keyPressEvent(event);
113 mScrollToBottomEnabled(true)
116 QVBoxLayout* layout =
new QVBoxLayout(
this);
117 layout->setMargin(0);
118 this->setLayout(layout);
119 layout->addWidget(
mTable);
121 mTable->setShowGrid(
false);
122 mTable->setTextElideMode(Qt::ElideLeft);
123 mTable->setWordWrap(
false);
125 mTable->setColumnCount(6);
127 mTable->setHorizontalHeaderLabels(QStringList() <<
"time" <<
"source" <<
"function" <<
"thread" <<
"level" <<
"description");
128 mTable->setSelectionBehavior(QAbstractItemView::SelectRows);
129 mTable->verticalHeader()->hide();
131 QFontMetrics metric(this->font());
132 mTable->setColumnWidth(0, metric.width(
"00:00:00.000xx"));
133 mTable->setColumnWidth(1, metric.width(
"cxSourceFile.cpp:333xx"));
134 mTable->setColumnWidth(2, metric.width(
"function()xx"));
135 mTable->setColumnWidth(3, metric.width(
"mainxx"));
136 mTable->setColumnWidth(4, metric.width(
"WARNINGxx"));
137 mTable->horizontalHeader()->setStretchLastSection(
true);
139 for (
int i=0; i<
mTable->horizontalHeader()->count(); ++i)
142 int value = headerItem.
readValue(
"-1").toInt();
145 mTable->setColumnWidth(i, value);
148 int textLineHeight = metric.lineSpacing();
149 mTable->verticalHeader()->setDefaultSectionSize(textLineHeight);
154 for (
int i=0; i<
mTable->horizontalHeader()->count(); ++i)
168 mTable->horizontalScrollBar()->setValue(
mTable->horizontalScrollBar()->minimum());
173 int row =
mTable->rowCount();
176 QString timestamp = message.
getTimeStamp().toString(
"hh:mm:ss.zzz");
177 this->
addItem(0, timestamp, message);
182 this->
addItem(1, source, message);
185 this->
addItem(2,
function, message);
187 QString thread = message.
mThread;
188 this->
addItem(3, thread, message);
191 this->
addItem(4, level, message);
193 QString desc = message.
getText();
194 this->
addItem(5, desc, message);
207 mTable->horizontalHeader()->setVisible(on);
218 int row =
mTable->rowCount();
220 QTableWidgetItem* item =
new QTableWidgetItem(text);
221 item->setStatusTip(text);
222 item->setToolTip(text);
224 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
225 mTable->setItem(row-1, column, item);
235 mScrollToBottomEnabled(true)
239 mBrowser->setLineWrapMode(QTextEdit::NoWrap);
240 QVBoxLayout* layout =
new QVBoxLayout(
this);
241 layout->setMargin(0);
242 this->setLayout(layout);
244 this->scrollToBottom();
250 this->scrollToBottom();
255 mBrowser->horizontalScrollBar()->setValue(
mBrowser->horizontalScrollBar()->minimum());
264 this->scrollToBottom();
269 mScrollToBottomEnabled = on;
270 this->scrollToBottom();
273 void SimpleLogMessageDisplayWidget::scrollToBottom()
275 if (mScrollToBottomEnabled)
276 mBrowser->verticalScrollBar()->setValue(
mBrowser->verticalScrollBar()->maximum());
282 return message.
mText;
285 retval= QString(
"[%1] %2")
305 mSeverityAction(NULL),
306 mMessagesWidget(NULL),
307 mMessagesLayout(NULL),
319 mSeverityAction(NULL),
320 mMessagesWidget(NULL),
321 mMessagesLayout(NULL),
324 mOptions =
profile()->getXmlSettings().descend(this->objectName());
333 if (!mMessagesLayout)
340 void ConsoleWidget::createUI()
342 mSeverityAction = NULL;
343 mMessagesWidget = NULL;
345 this->setToolTip(
"Display system information, warnings and errors.");
347 QVBoxLayout* layout =
new QVBoxLayout;
348 layout->setMargin(0);
349 layout->setSpacing(0);
350 this->setLayout(layout);
354 layout->addWidget(mPopupWidget);
355 this->createButtonWidget(mPopupWidget->
getToolbar());
357 mMessagesLayout =
new QVBoxLayout;
358 mMessagesLayout->setMargin(0);
359 layout->addLayout(mMessagesLayout);
363 mMessageListener->installFilter(mMessageFilter);
367 QString defVal = enum2string<LOG_SEVERITY>(
msINFO);
368 LOG_SEVERITY value = string2enum<LOG_SEVERITY>(this->option(
"showLevel").readValue(defVal));
369 mMessageFilter->setLowestSeverity(value);
371 mMessageFilter->setActiveChannel(mChannelSelector->getValue());
372 mMessageListener->installFilter(mMessageFilter);
377 void ConsoleWidget::createButtonWidget(QWidget* widget)
379 QHBoxLayout* buttonLayout =
new QHBoxLayout(widget);
380 buttonLayout->setMargin(0);
381 buttonLayout->setSpacing(0);
383 this->addSeverityButtons(buttonLayout);
384 buttonLayout->addSpacing(8);
385 this->addDetailsButton(buttonLayout);
387 this->createChannelSelector();
389 LabeledComboBoxWidget* channelSelectorWidget =
new LabeledComboBoxWidget(
this, mChannelSelector);
390 channelSelectorWidget->showLabel(
false);
391 buttonLayout->addSpacing(8);
392 buttonLayout->addWidget(channelSelectorWidget);
393 buttonLayout->setStretch(buttonLayout->count()-1, 0);
395 buttonLayout->addStretch(1);
398 void ConsoleWidget::updateShowHeader()
405 XmlOptionItem ConsoleWidget::option(QString name)
407 return XmlOptionItem(name, mOptions.
getElement());
415 QString levelString = enum2string<LOG_SEVERITY>(mMessageFilter->getLowestSeverity());
416 this->option(
"showLevel").
writeValue(levelString);
417 this->option(
"showDetails").
writeVariant(mDetailsAction->isChecked());
424 mDetailsAction->setChecked(on);
433 void ConsoleWidget::addSeverityButtons(QBoxLayout* buttonLayout)
436 QIcon(
":/icons/open_icon_library/zoom-in-3.png"),
437 "More",
"More detailed log output",
438 SLOT(onSeverityDown()),
441 this->addSeverityIndicator(buttonLayout);
444 QIcon(
":/icons/open_icon_library/zoom-out-3.png"),
445 "Less ",
"Less detailed log output",
446 SLOT(onSeverityUp()),
450 void ConsoleWidget::addSeverityIndicator(QBoxLayout* buttonLayout)
452 QAction* action =
new QAction(QIcon(
""),
"Severity",
this);
453 mSeverityAction = action;
454 QString help =
"Lowest displayed log severity";
455 action->setStatusTip(help);
456 action->setWhatsThis(help);
457 action->setToolTip(help);
459 button->setDefaultAction(action);
460 buttonLayout->addWidget(button);
463 void ConsoleWidget::updateSeverityIndicator()
465 LOG_SEVERITY severity = mMessageFilter->getLowestSeverity();
470 this->updateSeverityIndicator(
"window-close-3.png",
"error");
473 this->updateSeverityIndicator(
"dialog-warning-panel.png",
"warning");
476 this->updateSeverityIndicator(
"dialog-information-4.png",
"info");
479 this->updateSeverityIndicator(
"script-error.png",
"debug");
482 this->updateSeverityIndicator(
"script-error.png",
"");
487 void ConsoleWidget::updateSeverityIndicator(QString iconname, QString help)
489 QIcon icon(QString(
":/icons/message_levels/%1").arg(iconname));
490 mSeverityAction->setIcon(icon);
492 help = QString(
"Current log level is %1").arg(help);
493 mSeverityAction->setStatusTip(help);
494 mSeverityAction->setToolTip(help);
497 void ConsoleWidget::onSeverityUp()
499 this->onSeverityChange(-1);
502 void ConsoleWidget::onSeverityDown()
504 this->onSeverityChange(+1);
507 void ConsoleWidget::onSeverityChange(
int delta)
509 LOG_SEVERITY severity = mMessageFilter->getLowestSeverity();
510 int val = (int)severity + delta;
512 severity =
static_cast<LOG_SEVERITY
>(val);
514 mMessageFilter->setLowestSeverity(severity);
515 mMessageListener->installFilter(mMessageFilter);
519 void ConsoleWidget::createChannelSelector()
521 QString defval =
"console";
527 "",
"Log Channel to display",
530 mChannelSelector = retval;
533 void ConsoleWidget::addDetailsButton(QBoxLayout* buttonLayout)
535 QIcon icon(
":/icons/open_icon_library/system-run-5.png");
538 "Details",
"Show detailed info on each log entry",
541 action->setCheckable(
true);
543 bool value = this->option(
"showDetails").
readVariant(
false).toBool();
544 action->blockSignals(
true);
545 action->setChecked(value);
546 action->blockSignals(
false);
548 mDetailsAction = action;
551 void ConsoleWidget::updateUI()
553 this->updateSeverityIndicator();
555 this->setWindowTitle(
"Console: " + mChannelSelector->getValue());
556 this->selectMessagesWidget();
557 this->updateShowHeader();
561 QTimer::singleShot(0,
this, SLOT(clearTable()));
563 mMessageListener->restart();
566 void ConsoleWidget::selectMessagesWidget()
568 if (mMessagesWidget && (mMessagesWidget->
getType()==this->getDetailTypeFromButton()))
574 mMessagesLayout->takeAt(0);
575 delete mMessagesWidget;
578 if (this->getDetailTypeFromButton()==
"detail")
580 mMessagesWidget =
new DetailedLogMessageDisplayWidget(
this, mOptions);
584 mMessagesWidget =
new SimpleLogMessageDisplayWidget(
this);
587 mMessagesLayout->addWidget(mMessagesWidget);
590 QString ConsoleWidget::getDetailTypeFromButton()
const
592 if (mDetailsAction->isChecked())
598 void ConsoleWidget::clearTable()
601 mMessagesWidget->
clear();
604 void ConsoleWidget::onLoggingFolderChanged()
608 mMessageListener->installFilter(mMessageFilter);
612 void ConsoleWidget::onChannelSelectorChanged()
614 mChannelSelector->blockSignals(
true);
616 mMessageFilter->setActiveChannel(mChannelSelector->getValue());
617 mMessageListener->installFilter(mMessageFilter);
620 mChannelSelector->blockSignals(
false);
638 void ConsoleWidget::receivedChannel(QString channel)
640 if (!mChannels.count(channel))
642 mChannels.append(channel);
643 mChannelSelector->setValueRange(mChannels);
647 void ConsoleWidget::receivedMessage(
Message message)
649 this->receivedChannel(message.
mChannel);
656 this->printMessage(message);
659 void ConsoleWidget::printMessage(
const Message& message)
662 mMessagesWidget->
add(message);