37 #include <QVBoxLayout>
40 #include <QContextMenuEvent>
53 #include <QTableWidget>
55 #include <QHeaderView>
56 #include <QStackedLayout>
57 #include <QApplication>
60 #include <QPushButton>
101 if (event->key() == Qt::Key_C && (
event->modifiers() & Qt::ControlModifier))
103 QModelIndexList cells = selectedIndexes();
108 foreach (
const QModelIndex& cell, cells) {
109 if (text.length() == 0) {
111 }
else if (cell.row() != currentRow) {
118 currentRow = cell.row();
119 text += cell.data().toString();
122 QApplication::clipboard()->setText(text);
129 QTableWidget::keyPressEvent(event);
137 mScrollToBottomEnabled(true)
140 QVBoxLayout* layout =
new QVBoxLayout(
this);
141 layout->setMargin(0);
142 this->setLayout(layout);
143 layout->addWidget(
mTable);
145 mTable->setShowGrid(
false);
146 mTable->setTextElideMode(Qt::ElideLeft);
147 mTable->setWordWrap(
false);
149 mTable->setColumnCount(6);
151 mTable->setHorizontalHeaderLabels(QStringList() <<
"time" <<
"source" <<
"function" <<
"thread" <<
"level" <<
"description");
152 mTable->setSelectionBehavior(QAbstractItemView::SelectRows);
153 mTable->verticalHeader()->hide();
155 QFontMetrics metric(this->font());
156 mTable->setColumnWidth(0, metric.width(
"00:00:00.000xx"));
157 mTable->setColumnWidth(1, metric.width(
"cxSourceFile.cpp:333xx"));
158 mTable->setColumnWidth(2, metric.width(
"function()xx"));
159 mTable->setColumnWidth(3, metric.width(
"mainxx"));
160 mTable->setColumnWidth(4, metric.width(
"WARNINGxx"));
161 mTable->horizontalHeader()->setStretchLastSection(
true);
163 for (
int i=0; i<
mTable->horizontalHeader()->count(); ++i)
166 int value = headerItem.
readValue(
"-1").toInt();
169 mTable->setColumnWidth(i, value);
172 int textLineHeight = metric.lineSpacing();
173 mTable->verticalHeader()->setDefaultSectionSize(textLineHeight);
178 for (
int i=0; i<
mTable->horizontalHeader()->count(); ++i)
192 mTable->horizontalScrollBar()->setValue(
mTable->horizontalScrollBar()->minimum());
197 int row =
mTable->rowCount();
200 QString timestamp = message.
getTimeStamp().toString(
"hh:mm:ss.zzz");
201 this->
addItem(0, timestamp, message);
206 this->
addItem(1, source, message);
209 this->
addItem(2,
function, message);
211 QString thread = message.
mThread;
212 this->
addItem(3, thread, message);
215 this->
addItem(4, level, message);
217 QString desc = message.
getText();
218 this->
addItem(5, desc, message);
231 mTable->horizontalHeader()->setVisible(on);
242 int row =
mTable->rowCount();
244 QTableWidgetItem* item =
new QTableWidgetItem(text);
245 item->setStatusTip(text);
246 item->setToolTip(text);
248 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
249 mTable->setItem(row-1, column, item);
259 mScrollToBottomEnabled(true)
263 mBrowser->setLineWrapMode(QTextEdit::NoWrap);
264 QVBoxLayout* layout =
new QVBoxLayout(
this);
265 layout->setMargin(0);
266 this->setLayout(layout);
268 this->scrollToBottom();
274 this->scrollToBottom();
279 mBrowser->horizontalScrollBar()->setValue(
mBrowser->horizontalScrollBar()->minimum());
288 this->scrollToBottom();
293 mScrollToBottomEnabled = on;
294 this->scrollToBottom();
297 void SimpleLogMessageDisplayWidget::scrollToBottom()
299 if (mScrollToBottomEnabled)
300 mBrowser->verticalScrollBar()->setValue(
mBrowser->verticalScrollBar()->maximum());
306 return message.
mText;
309 retval= QString(
"[%1] %2")
329 mSeverityAction(NULL),
330 mMessagesWidget(NULL),
331 mMessagesLayout(NULL),
343 mSeverityAction(NULL),
344 mMessagesWidget(NULL),
345 mMessagesLayout(NULL),
348 mOptions =
profile()->getXmlSettings().descend(this->objectName());
357 if (!mMessagesLayout)
364 void ConsoleWidget::createUI()
366 mSeverityAction = NULL;
367 mMessagesWidget = NULL;
369 this->setToolTip(
"Display system information, warnings and errors.");
371 QVBoxLayout* layout =
new QVBoxLayout;
372 layout->setMargin(0);
373 layout->setSpacing(0);
374 this->setLayout(layout);
378 layout->addWidget(mPopupWidget);
379 this->createButtonWidget(mPopupWidget->
getToolbar());
381 mMessagesLayout =
new QVBoxLayout;
382 mMessagesLayout->setMargin(0);
383 layout->addLayout(mMessagesLayout);
387 mMessageListener->installFilter(mMessageFilter);
391 QString defVal = enum2string<LOG_SEVERITY>(
msINFO);
392 LOG_SEVERITY value = string2enum<LOG_SEVERITY>(this->option(
"showLevel").
readValue(defVal));
393 mMessageFilter->setLowestSeverity(value);
395 mMessageFilter->setActiveChannel(mChannelSelector->getValue());
396 mMessageListener->installFilter(mMessageFilter);
401 void ConsoleWidget::createButtonWidget(QWidget* widget)
403 QHBoxLayout* buttonLayout =
new QHBoxLayout(widget);
404 buttonLayout->setMargin(0);
405 buttonLayout->setSpacing(0);
407 this->addSeverityButtons(buttonLayout);
408 buttonLayout->addSpacing(8);
409 this->addDetailsButton(buttonLayout);
411 this->createChannelSelector();
413 LabeledComboBoxWidget* channelSelectorWidget =
new LabeledComboBoxWidget(
this, mChannelSelector);
414 channelSelectorWidget->showLabel(
false);
415 buttonLayout->addSpacing(8);
416 buttonLayout->addWidget(channelSelectorWidget);
417 buttonLayout->setStretch(buttonLayout->count()-1, 0);
419 buttonLayout->addStretch(1);
422 void ConsoleWidget::updateShowHeader()
429 XmlOptionItem ConsoleWidget::option(QString name)
431 return XmlOptionItem(name, mOptions.
getElement());
439 QString levelString = enum2string<LOG_SEVERITY>(mMessageFilter->getLowestSeverity());
440 this->option(
"showLevel").
writeValue(levelString);
441 this->option(
"showDetails").
writeVariant(mDetailsAction->isChecked());
448 mDetailsAction->setChecked(on);
457 void ConsoleWidget::addSeverityButtons(QBoxLayout* buttonLayout)
460 QIcon(
":/icons/open_icon_library/zoom-in-3.png"),
461 "More",
"More detailed log output",
462 SLOT(onSeverityDown()),
465 this->addSeverityIndicator(buttonLayout);
468 QIcon(
":/icons/open_icon_library/zoom-out-3.png"),
469 "Less ",
"Less detailed log output",
470 SLOT(onSeverityUp()),
474 void ConsoleWidget::addSeverityIndicator(QBoxLayout* buttonLayout)
476 QAction* action =
new QAction(QIcon(
""),
"Severity",
this);
477 mSeverityAction = action;
478 QString help =
"Lowest displayed log severity";
479 action->setStatusTip(help);
480 action->setWhatsThis(help);
481 action->setToolTip(help);
483 button->setDefaultAction(action);
484 buttonLayout->addWidget(button);
487 void ConsoleWidget::updateSeverityIndicator()
489 LOG_SEVERITY severity = mMessageFilter->getLowestSeverity();
494 this->updateSeverityIndicator(
"window-close-3.png",
"error");
497 this->updateSeverityIndicator(
"dialog-warning-panel.png",
"warning");
500 this->updateSeverityIndicator(
"dialog-information-4.png",
"info");
503 this->updateSeverityIndicator(
"script-error.png",
"debug");
506 this->updateSeverityIndicator(
"script-error.png",
"");
511 void ConsoleWidget::updateSeverityIndicator(QString iconname, QString help)
513 QIcon icon(QString(
":/icons/message_levels/%1").arg(iconname));
514 mSeverityAction->setIcon(icon);
516 help = QString(
"Current log level is %1").arg(help);
517 mSeverityAction->setStatusTip(help);
518 mSeverityAction->setToolTip(help);
521 void ConsoleWidget::onSeverityUp()
523 this->onSeverityChange(-1);
526 void ConsoleWidget::onSeverityDown()
528 this->onSeverityChange(+1);
531 void ConsoleWidget::onSeverityChange(
int delta)
533 LOG_SEVERITY severity = mMessageFilter->getLowestSeverity();
534 int val = (int)severity + delta;
536 severity =
static_cast<LOG_SEVERITY
>(val);
538 mMessageFilter->setLowestSeverity(severity);
539 mMessageListener->installFilter(mMessageFilter);
543 void ConsoleWidget::createChannelSelector()
545 QString defval =
"console";
551 "",
"Log Channel to display",
554 mChannelSelector = retval;
557 void ConsoleWidget::addDetailsButton(QBoxLayout* buttonLayout)
559 QIcon icon(
":/icons/open_icon_library/system-run-5.png");
562 "Details",
"Show detailed info on each log entry",
565 action->setCheckable(
true);
567 bool value = this->option(
"showDetails").
readVariant(
false).toBool();
568 action->blockSignals(
true);
569 action->setChecked(value);
570 action->blockSignals(
false);
572 mDetailsAction = action;
575 void ConsoleWidget::updateUI()
577 this->updateSeverityIndicator();
579 this->setWindowTitle(
"Console: " + mChannelSelector->getValue());
580 this->selectMessagesWidget();
581 this->updateShowHeader();
585 QTimer::singleShot(0,
this, SLOT(clearTable()));
587 mMessageListener->restart();
590 void ConsoleWidget::selectMessagesWidget()
592 if (mMessagesWidget && (mMessagesWidget->
getType()==this->getDetailTypeFromButton()))
598 mMessagesLayout->takeAt(0);
599 delete mMessagesWidget;
602 if (this->getDetailTypeFromButton()==
"detail")
604 mMessagesWidget =
new DetailedLogMessageDisplayWidget(
this, mOptions);
608 mMessagesWidget =
new SimpleLogMessageDisplayWidget(
this);
611 mMessagesLayout->addWidget(mMessagesWidget);
614 QString ConsoleWidget::getDetailTypeFromButton()
const
616 if (mDetailsAction->isChecked())
622 void ConsoleWidget::clearTable()
625 mMessagesWidget->
clear();
628 void ConsoleWidget::onLoggingFolderChanged()
632 mMessageListener->installFilter(mMessageFilter);
636 void ConsoleWidget::onChannelSelectorChanged()
638 mChannelSelector->blockSignals(
true);
640 mMessageFilter->setActiveChannel(mChannelSelector->getValue());
641 mMessageListener->installFilter(mMessageFilter);
644 mChannelSelector->blockSignals(
false);
662 void ConsoleWidget::receivedChannel(QString channel)
664 if (!mChannels.count(channel))
666 mChannels.append(channel);
667 mChannelSelector->setValueRange(mChannels);
671 void ConsoleWidget::receivedMessage(
Message message)
673 this->receivedChannel(message.
mChannel);
680 this->printMessage(message);
683 void ConsoleWidget::printMessage(
const Message& message)
686 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