35 #include <rosgraph_msgs/Log.h>
45 #include <QColorDialog>
47 #include <QApplication>
50 #include <QFileDialog>
70 QObject::connect(
ui.action_NewWindow, SIGNAL(triggered(
bool)),
73 QObject::connect(
ui.action_Copy, SIGNAL(triggered()),
76 QObject::connect(
ui.action_CopyExtended, SIGNAL(triggered()),
79 QObject::connect(
ui.action_SelectAll, SIGNAL(triggered()),
82 QObject::connect(
ui.action_ReadBagFile, SIGNAL(triggered(
bool)),
85 QObject::connect(
ui.action_ReadLogFile, SIGNAL(triggered(
bool)),
88 QObject::connect(
ui.action_ReadLogDirectory, SIGNAL(triggered(
bool)),
91 QObject::connect(
ui.action_SaveLogs, SIGNAL(triggered(
bool)),
94 QObject::connect(
ui.action_AbsoluteTimestamps, SIGNAL(toggled(
bool)),
97 QObject::connect(
ui.action_Use_human_readable_time, SIGNAL(toggled(
bool)),
98 db_proxy_, SLOT(setHumanReadableTime(
bool)));
100 QObject::connect(
ui.action_ShowTimestamps, SIGNAL(toggled(
bool)),
103 QObject::connect(
ui.action_ShowLoggerName, SIGNAL(toggled(
bool)),
104 db_proxy_, SLOT(setDisplayLogger(
bool)));
106 QObject::connect(
ui.action_ShowFunctionName, SIGNAL(toggled(
bool)),
107 db_proxy_, SLOT(setDisplayFunction(
bool)));
109 QObject::connect(
ui.action_RegularExpressions, SIGNAL(toggled(
bool)),
110 db_proxy_, SLOT(setUseRegularExpressions(
bool)));
112 QObject::connect(
ui.action_RegularExpressions, SIGNAL(toggled(
bool)),
115 QObject::connect(
ui.action_RegularExpressions, SIGNAL(toggled(
bool)),
118 QObject::connect(
ui.action_SelectFont, SIGNAL(triggered(
bool)),
121 QObject::connect(
ui.action_ColorizeLogs, SIGNAL(toggled(
bool)),
124 QObject::connect(
ui.debugColorWidget, SIGNAL(clicked(
bool)),
126 QObject::connect(
ui.infoColorWidget, SIGNAL(clicked(
bool)),
128 QObject::connect(
ui.warnColorWidget, SIGNAL(clicked(
bool)),
130 QObject::connect(
ui.errorColorWidget, SIGNAL(clicked(
bool)),
132 QObject::connect(
ui.fatalColorWidget, SIGNAL(clicked(
bool)),
137 ui.messageList->setUniformItemSizes(
true);
140 ui.nodeList->selectionModel(),
141 SIGNAL(selectionChanged(
const QItemSelection &,
142 const QItemSelection &)),
149 ui.checkDebug, SIGNAL(toggled(
bool)),
152 ui.checkInfo, SIGNAL(toggled(
bool)),
155 ui.checkWarn, SIGNAL(toggled(
bool)),
158 ui.checkError, SIGNAL(toggled(
bool)),
161 ui.checkFatal, SIGNAL(toggled(
bool)),
166 QObject::connect(
ui.checkFollowNewest, SIGNAL(toggled(
bool)),
170 QObject::connect(
ui.messageList, SIGNAL(customContextMenuRequested(
const QPoint&)),
173 QObject::connect(
ui.clearAllButton, SIGNAL(clicked()),
175 QObject::connect(
ui.clearMessagesButton, SIGNAL(clicked()),
179 ui.messageList->verticalScrollBar(), SIGNAL(valueChanged(
int)),
183 ui.includeText, SIGNAL(textChanged(
const QString &)),
187 ui.excludeText, SIGNAL(textChanged(
const QString &)),
192 ui.searchText, SIGNAL(textChanged(
const QString &)),
195 QObject::connect(
ui.pushPrev, SIGNAL(clicked()),
198 QObject::connect(
ui.pushNext, SIGNAL(clicked()),
205 ui.splitter->setSizes(sizes);
230 QString defaultname = QDateTime::currentDateTime().toString(Qt::ISODate) +
".bag";
231 QString filename = QFileDialog::getSaveFileName(
this,
233 QDir::homePath() + QDir::separator() + defaultname,
234 tr(
"Bag Files (*.bag);;Text Files (*.txt)"));
235 if (filename != NULL && !filename.isEmpty()) {
245 statusBar()->showMessage(
"Connected to ROS Master. URL: "+currentUrl);
247 statusBar()->showMessage(
"Disconnected from ROS Master.");
253 QMainWindow::closeEvent(event);
259 QModelIndexList selection =
ui.nodeList->selectionModel()->selectedIndexes();
260 std::set<std::string> nodes;
261 QStringList node_names;
263 for (
int i = 0; i < selection.size(); i++) {
266 node_names.append(name.c_str());
271 for (
int i = 0; i < node_names.size(); i++) {
272 node_names[i] = node_names[i].split(
"/", QString::SkipEmptyParts).last();
275 setWindowTitle(QString(
"SWRI Console (") + node_names.join(
", ") +
")");
282 if (
ui.checkDebug->isChecked()) {
283 mask |= rosgraph_msgs::Log::DEBUG;
285 if (
ui.checkInfo->isChecked()) {
286 mask |= rosgraph_msgs::Log::INFO;
288 if (
ui.checkWarn->isChecked()) {
289 mask |= rosgraph_msgs::Log::WARN;
291 if (
ui.checkError->isChecked()) {
292 mask |= rosgraph_msgs::Log::ERROR;
294 if (
ui.checkFatal->isChecked()) {
295 mask |= rosgraph_msgs::Log::FATAL;
311 if (
ui.checkFollowNewest->isChecked()) {
312 ui.messageList->scrollToBottom();
319 QMenu contextMenu(tr(
"Context menu"),
ui.messageList);
321 QAction select_all(tr(
"Select All"),
ui.messageList);
322 connect(&select_all, SIGNAL(triggered()),
this, SLOT(
selectAllLogs()));
324 QAction copy(tr(
"Copy"),
ui.messageList);
325 connect(©, SIGNAL(triggered()),
this, SLOT(
copyLogs()));
327 QAction copy_extended(tr(
"Copy Extended"),
ui.messageList);
328 connect(©_extended, SIGNAL(triggered()),
this, SLOT(
copyExtendedLogs()));
330 QAction alternate_row_colors(tr(
"Alternate Row Colors"),
ui.messageList);
331 alternate_row_colors.setCheckable(
true);
332 alternate_row_colors.setChecked(
ui.messageList->alternatingRowColors());
333 connect(&alternate_row_colors, SIGNAL(toggled(
bool)),
336 contextMenu.addAction(&select_all);
337 contextMenu.addAction(©);
338 contextMenu.addAction(©_extended);
339 contextMenu.addAction(&alternate_row_colors);
341 contextMenu.exec(
ui.messageList->mapToGlobal(point));
346 if (value !=
ui.messageList->verticalScrollBar()->maximum()) {
347 ui.checkFollowNewest->setChecked(
false);
349 ui.checkFollowNewest->setChecked(
true);
356 if (
ui.nodeList->hasFocus()) {
357 ui.nodeList->selectAll();
359 ui.messageList->selectAll();
366 foreach(
const QModelIndex &index,
ui.messageList->selectionModel()->selectedIndexes())
368 buffer <<
db_proxy_->
data(index, Qt::DisplayRole).toString();
370 QApplication::clipboard()->setText(buffer.join(tr(
"\n")));
376 foreach(
const QModelIndex &index,
ui.messageList->selectionModel()->selectedIndexes())
380 QApplication::clipboard()->setText(buffer.join(tr(
"\n\n")));
391 QStringList items = text.split(
";", QString::SkipEmptyParts);
392 QStringList filtered;
394 for (
int i = 0; i < items.size(); i++) {
395 QString x = items[i].trimmed();
409 QStringList items = text.split(
";", QString::SkipEmptyParts);
410 QStringList filtered;
412 for (
int i = 0; i < items.size(); i++) {
413 QString x = items[i].trimmed();
448 int rowSearchStart =
ui.messageList->currentIndex().row();
450 QString searchText =
ui.searchText->text();
451 searchText = searchText.toUpper().trimmed();
464 if (rowSearchStart==-1){
471 printf(
"Invalid string passed to ConsoleWindow::nextIndex");
476 ui.messageList->clearSelection();
477 if(newRowIndex == -1)
482 QModelIndex index =
ui.messageList->model()->index(newRowIndex,0);
483 ui.messageList->setCurrentIndex(index);
484 ui.checkFollowNewest->setChecked(
false);
493 ui.includeLabel->setText(
"Include");
495 ui.includeLabel->setText(
"<font color='red'>Include</font>");
502 ui.excludeLabel->setText(
"Exclude");
504 ui.excludeLabel->setText(
"<font color='red'>Exclude</font>");
510 ui.messageList->setFont(font);
511 ui.nodeList->setFont(font);
542 QColor color = QColorDialog::getColor(old_color,
this);
543 if (color.isValid()) {
550 QString ss = button->styleSheet();
551 QRegExp re(
"background: (#\\w*);");
553 if (re.indexIn(ss) >= 0) {
554 old_color = QColor(re.cap(1));
561 QString
s(
"background: #"
562 + QString(color.red() < 16?
"0" :
"") + QString::number(color.red(),16)
563 + QString(color.green() < 16?
"0" :
"") + QString::number(color.green(),16)
564 + QString(color.blue() < 16?
"0" :
"") + QString::number(color.blue(),16) +
";");
565 widget->setStyleSheet(
s);
568 if (widget ==
ui.debugColorWidget) {
571 else if (widget ==
ui.infoColorWidget) {
574 else if (widget ==
ui.warnColorWidget) {
577 else if (widget ==
ui.errorColorWidget) {
580 else if (widget ==
ui.fatalColorWidget) {
584 qWarning(
"Unexpected widget passed to ConsoleWindow::updateButtonColor.");
594 if (button ==
ui.debugColorWidget) {
595 defaultColor = Qt::gray;
597 else if (button ==
ui.infoColorWidget) {
598 defaultColor = Qt::black;
600 else if (button ==
ui.warnColorWidget) {
601 defaultColor = QColor(255, 127, 0);
603 else if (button ==
ui.errorColorWidget) {
604 defaultColor = Qt::red;
606 else if (button ==
ui.fatalColorWidget) {
607 defaultColor = Qt::magenta;
609 QColor color = settings.value(key, defaultColor).value<QColor>();
615 ui.messageList->setAlternatingRowColors(checked);
634 ui.action_Use_human_readable_time->setEnabled(displayTimestamp);
643 ui.checkDebug->setChecked(showDebug);
644 ui.checkInfo->setChecked(showInfo);
645 ui.checkWarn->setChecked(showWarn);
646 ui.checkError->setChecked(showError);
647 ui.checkFatal->setChecked(showFatal);
659 ui.includeText->setText(includeFilter);
661 ui.excludeText->setText(excludeFilter);
664 ui.messageList->setAlternatingRowColors(alternate_row_colors);