28 #include <ArmarXCore/interface/core/ManagedIceObjectDefinitions.h>
29 #include <ArmarXGui/gui-plugins/LoggingPlugin/ui_FilterDialog.h>
38 #include <QInputDialog>
40 #include <QMainWindow>
42 #include <boost/algorithm/string/regex.hpp>
45 #define USERROLE_LOGTABLEID Qt::UserRole+1
46 #define USERROLE_LOGTABLEPTR Qt::UserRole+2
47 #define USERROLE_BASENAME Qt::UserRole+3
48 #define REGEX_COLORS "\033\\[(\\d|\\w?)[;]?(\\d+)m"
49 #define ALL_MESSAGES_FILTER "All Messages"
59 qRegisterMetaType<Qt::Orientation>(
"Qt::Orientation");
60 qRegisterMetaType<std::string>(
"std::string");
63 for (
int i = 0; i < eLogLevelCount; i++)
68 ui.cbVerbosityLevel->setCurrentIndex(1);
70 ui.lvFilters->setCurrentItem(
ui.lvFilters->invisibleRootItem()->child(0));
71 ui.lvFilters->setSortingEnabled(
true);
72 ui.lvFilters->sortByColumn(0, Qt::AscendingOrder);
73 pendingEntriesTimer =
new QTimer(
getWidget());
74 pendingEntriesTimer->setInterval(50);
83 ui.splitter->setSizes(sizes);
84 addFilter(
"Warning+",
"Warning+",
"",
"",
"", eWARN,
"",
"",
"");
88 qRegisterMetaType<LogMessage>(
"LogMessage");
92 connect(
ui.edtLiveFilter, SIGNAL(textChanged(QString)),
this, SLOT(
performLiveFilter(QString)));
93 connect(
ui.edtLiveSearch, SIGNAL(textChanged(QString)),
this, SLOT(
performLiveSearch(QString)));
94 connect(
ui.btnAddFilter, SIGNAL(clicked()),
this, SLOT(
addFilter()));
96 connect(
ui.btnPause, SIGNAL(toggled(
bool)),
this, SLOT(
pauseLogging(
bool)));
98 connect(
ui.btnClearAllLogs, SIGNAL(clicked()),
this, SLOT(
clearAllLogs()));
99 connect(
ui.lvFilters, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
this, SLOT(
filterSelectionChanged(QTreeWidgetItem*, QTreeWidgetItem*)));
100 connect(
ui.lvFilters, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,
int)),
this, SLOT(
editFilter(QTreeWidgetItem*,
int)));
101 connect(
ui.cbSearchType, SIGNAL(currentIndexChanged(
int)),
this, SLOT(
searchTypeChanged(
int)));
106 ui.edtLiveFilter->hide();
107 ui.edtLiveSearch->setFocus();
121 ui.cbVerbosityLevel->setCurrentIndex(settings->value(
"verbosityLevel", 2).toInt());
122 ui.cbAutoComponentFilters->setChecked(settings->value(
"autoFilterAdding",
true).toBool());
128 settings->setValue(
"verbosityLevel", ui.cbVerbosityLevel->currentIndex());
130 settings->setValue(
"autoFilterAdding", ui.cbAutoComponentFilters->isChecked());
169 emit componentConnected();
181 QString LogViewer::loggingGroupNameToFilterName(
const QString& loggingGroupName)
const
183 return loggingGroupName.isEmpty() ?
"" : (
"_" + loggingGroupName);
190 void LogViewer::write(
const std::string& who,
Ice::Long time,
const std::string& tag, MessageType severity,
const std::string&
message,
const std::string& file,
Ice::Int line,
const std::string&
function,
const Ice::Current&)
200 msg.function =
function;
212 if (
ui.cbVerbosityLevel->currentIndex() <= msg.type)
214 std::unique_lock lock(pendingEntriesMutex);
215 pendingEntries.push_back(msg);
232 if (filterStr.length() == 0)
236 else if (filterStr.length() < 3)
244 lastLiveSearchEditChangeTime = IceUtil::Time::now();
249 if (searchStr.length() == 0)
252 ui.btnNextItem->setEnabled(
false);
253 ui.btnPreviousItem->setEnabled(
false);
262 ui.btnNextItem->setEnabled(
false);
263 ui.btnPreviousItem->setEnabled(
false);
267 ui.btnNextItem->setEnabled(
true);
268 ui.btnPreviousItem->setEnabled(
true);
284 std::map<QString, LogTable*>::iterator it = filterMap.begin();
286 for (; it != filterMap.end() ; it++)
288 it->second->getModel()->clearData();
299 loggingPaused = pause;
307 QTreeWidgetItem* item =
new QTreeWidgetItem(
ui.lvFilters);
309 item->setText(0, standardFilterStr);
314 filterMap[standardFilterStr] = newLogTable;
315 ui.splitter->addWidget(newLogTable);
320 LogTable*
LogViewer::addFilter(QString filterId, QString filterName, QString loggingGroup, QString componentFilter, QString tagFilter, MessageType minimumVerbosity, QString messageFilter, QString fileFilter, QString functionFilter)
323 if (filterMap.find(filterId) != filterMap.end())
325 QString msg =
"A filter with the id " + filterId +
" exists already";
333 if (loggingGroup.length())
339 if (componentFilter.length())
344 if (tagFilter.length())
349 if (messageFilter.length())
354 if (fileFilter.length())
359 if (functionFilter.length())
366 QTreeWidgetItem* item =
new QTreeWidgetItem();
367 item->setText(0, filterName);
371 filterMap[filterId] = newLogTable;
372 Ice::StringSeq children;
373 for (
int i = 0; i <
ui.lvFilters->invisibleRootItem()->childCount(); i++)
375 children.push_back(
ui.lvFilters->invisibleRootItem()->child(i)->text(0).toStdString());
378 QTreeWidgetItem* grpItem = NULL;
379 auto grpFilterId = loggingGroupNameToFilterName(loggingGroup);
380 for (
int i = 0; i <
ui.lvFilters->invisibleRootItem()->childCount(); i++)
382 if (
ui.lvFilters->invisibleRootItem()->child(i)->data(0,
USERROLE_BASENAME).toString() == grpFilterId)
384 grpItem =
ui.lvFilters->invisibleRootItem()->child(i);
390 grpItem->addChild(item);
396 ui.lvFilters->insertTopLevelItem(0, item);
400 ui.splitter->addWidget(newLogTable);
406 if (componentName.length() == 0 && loggingGroupName.length() == 0)
411 if (!
ui.cbAutoComponentFilters->isChecked())
415 QString filler = (loggingGroupName.length() > 0 && componentName.length() > 0) ?
"_" :
"";
416 auto filterId = loggingGroupNameToFilterName(loggingGroupName) +
417 filler + componentName;
418 auto filterName = componentName.length() > 0 ? componentName : loggingGroupNameToFilterName(loggingGroupName);
420 if (filterMap.count(filterId))
425 addFilter(filterId, filterName, loggingGroupName, componentName,
"", eDEBUG,
"",
"",
"");
435 if (!filterDialog.exec())
440 QString filterName = filterDialog.
ui->edtFilterName->text();
442 if (filterMap.find(filterName) != filterMap.end())
444 QString msg =
"A filter with this name already exists";
453 if (filterDialog.
ui->editComponent->text().length())
458 if (filterDialog.
ui->edtTag->text().length())
463 if (filterDialog.
ui->edtMessage->text().length())
468 if (filterDialog.
ui->edtFile->text().length())
473 if (filterDialog.
ui->edtFunction->text().length())
478 if (filterDialog.
ui->cbVerbosity->currentIndex() != -1)
483 QTreeWidgetItem* item =
new QTreeWidgetItem();
484 item->setText(0, filterName);
488 filterMap[filterName] = newLogTable;
489 ui.lvFilters->insertTopLevelItem(
ui.lvFilters->invisibleRootItem()->childCount(), item);
491 ui.splitter->addWidget(newLogTable);
500 if (filterMap.find(filterId) == filterMap.end())
514 for (
unsigned int i = 0; i <
logTable->
getModel()->getFilters().size(); i++)
521 filterDialog.
ui->editComponent->setText(filter.c_str());
525 filterDialog.
ui->edtTag->setText(filter.c_str());
530 filterDialog.
ui->cbVerbosity->setCurrentIndex(QString(filter.c_str()).toInt());
534 filterDialog.
ui->edtMessage->setText(filter.c_str());
538 filterDialog.
ui->edtFile->setText(filter.c_str());
542 filterDialog.
ui->edtFunction->setText(filter.c_str());
547 if (!filterDialog.exec())
551 item->setText(0, filterDialog.
ui->edtFilterName->text());
555 if (filterDialog.
ui->editComponent->text().length())
560 if (filterDialog.
ui->edtTag->text().length())
565 if (filterDialog.
ui->edtMessage->text().length())
570 if (filterDialog.
ui->edtFile->text().length())
575 if (filterDialog.
ui->edtFunction->text().length())
580 if (filterDialog.
ui->cbVerbosity->currentIndex() != -1)
592 if (
ui.lvFilters->invisibleRootItem()->childCount() == 1)
597 auto item =
ui.lvFilters->currentItem();
609 std::map<QString, LogTable*>::iterator it = filterMap.find(item->data(0,
USERROLE_LOGTABLEID).toString());
611 if (it == filterMap.end())
615 QList<QTreeWidgetItem*> itemsToDelete, iterationList({item});
616 while (!iterationList.isEmpty())
618 auto curItem = iterationList.front();
619 itemsToDelete << curItem;
620 iterationList.pop_front();
621 iterationList << curItem->takeChildren();
623 ui.lvFilters->setCurrentItem(
ui.lvFilters->invisibleRootItem()->child(0));
624 for (
auto& item : itemsToDelete)
626 auto parent = item->parent();
629 parent->removeChild(item);
633 ui.lvFilters->invisibleRootItem()->removeChild(item);
635 std::map<QString, LogTable*>::iterator it = filterMap.find(item->data(0,
USERROLE_LOGTABLEID).toString());
638 if (it == filterMap.end())
660 item->setFont(0, font);
662 if (filterMap.find(filterId) == filterMap.end())
691 QList<QTreeWidgetItem*> itemsToUpdate, iterationList({
ui.lvFilters->invisibleRootItem()});
692 while (!iterationList.isEmpty())
694 auto curItem = iterationList.front();
695 itemsToUpdate << curItem;
696 iterationList.pop_front();
697 for (
int i = 0; i < curItem->childCount(); ++i)
699 iterationList << curItem->child(i);
703 for (
auto item : itemsToUpdate)
706 LogTable* curLogtable = filterMap.find(filterId)->second;
716 item->setFont(0, font);
718 item->setBackgroundColor(0,
ui.lvFilters->palette().base().color());
723 item->setFont(0, font);
728 item->setBackgroundColor(0, QColor(216, 120, 50));
732 item->setBackgroundColor(0, QColor(255, 90, 80));
736 item->setBackgroundColor(0, QColor(255, 60, 50));
740 item->setBackgroundColor(0,
ui.lvFilters->palette().base().color());
744 item->setText(0, newContent);
745 item->setToolTip(0, newContent);
751 throw LocalException() <<
"Not yet implemented";
757 if (
getState() >= eManagedIceObjectExiting)
762 std::vector <LogMessage> pendingEntriesTemp;
764 std::unique_lock lock(pendingEntriesMutex);
765 pendingEntriesTemp.swap(pendingEntries);
770 unsigned int size = pendingEntriesTemp.size();
773 for (
unsigned int i = 0; i < size; i++)
775 LogMessage& msg = pendingEntriesTemp[i];
776 msg.what = boost::regex_replace(msg.what, re,
"");
778 if (!
getWidget() ||
ui.cbVerbosityLevel->currentIndex() > msg.type)
785 std::map<QString, LogTable*>::iterator it = filterMap.begin();
787 for (; it != filterMap.end(); ++it)
793 std::cerr <<
"log ptr is NULL" << std::endl;
798 bool autoScroll =
false;
800 if (log->verticalScrollBar()->value() == log->verticalScrollBar()->maximum())
809 log->scrollToBottom();
817 bool autoScroll =
false;
819 if (
logTable->verticalScrollBar()->value() ==
logTable->verticalScrollBar()->maximum())
824 std::map<QString, LogTable*>::iterator it = filterMap.begin();
826 for (; it != filterMap.end(); ++it)
835 for (r = row; r < count; r++)
840 bool autoScroll =
false;
842 if (log->verticalScrollBar()->value() == log->verticalScrollBar()->maximum())
851 log->scrollToBottom();
874 ui.edtLiveSearch->show();
875 ui.btnPreviousItem->show();
876 ui.btnNextItem->show();
877 ui.edtLiveFilter->hide();
881 ui.edtLiveSearch->hide();
882 ui.btnPreviousItem->hide();
883 ui.btnNextItem->hide();
884 ui.edtLiveFilter->show();
915 if (parent != customToolbar->parent())
917 customToolbar->setParent(parent);
920 return customToolbar;
923 customToolbar =
new QToolBar(parent);
924 customToolbar->setIconSize(QSize(16, 16));
925 customToolbar->addAction(QIcon(
":/icons/configure-3.png"),
"Configure",
this, SLOT(
OpenConfigureDialog()));
927 return customToolbar;