LogViewer.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarX::
17 * @author Mirko Waechter ( mirko.waechter at kit dot edu)
18 * @date 2012
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #include "LogViewer.h"
24 
25 #include "LogTableModel.h"
26 #include "LogTable.h"
27 #include "FilterDialog.h"
28 #include <ArmarXCore/interface/core/ManagedIceObjectDefinitions.h>
29 #include <ArmarXGui/gui-plugins/LoggingPlugin/ui_FilterDialog.h>
30 
31 // C++ includes
32 #include <sstream>
33 
34 // Qt includes
35 #include <QToolBar>
36 #include <QScrollBar>
37 #include <QTimer>
38 #include <QInputDialog>
39 #include <QStatusBar>
40 #include <QMainWindow>
41 
42 #include <boost/algorithm/string/regex.hpp>
43 
44 
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"
50 
51 namespace armarx
52 {
54  logTable(NULL),
55  loggingPaused(false),
56  customToolbar(0)
57 
58  {
59  qRegisterMetaType<Qt::Orientation>("Qt::Orientation");
60  qRegisterMetaType<std::string>("std::string");
61  ui.setupUi(getWidget());
62 
63  for (int i = 0; i < eLogLevelCount; i++)
64  {
65  ui.cbVerbosityLevel->addItem(LogSender::levelToString((MessageTypeT)i).c_str());
66  }
67 
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);
75 
76  connect(pendingEntriesTimer, SIGNAL(timeout()), this, SLOT(insertPendingEntries()));
77  connect(this, SIGNAL(componentConnected()), pendingEntriesTimer, SLOT(start()));
78 
79 
80  QList<int> sizes;
81  sizes.push_back(80);
82  sizes.push_back(400);
83  ui.splitter->setSizes(sizes);
84  addFilter("Warning+", "Warning+", "", "", "", eWARN, "", "", ""); // add additional filters after splitter->setSizes-> otherwise they have a width of NULL
85 
86 
87 
88  qRegisterMetaType<LogMessage>("LogMessage");
89 
90  // SIGNALS AND SLOTS CONNECTIONS
91  connect(this, SIGNAL(newEntry(LogMessage)), this, SLOT(addNewEntry(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()));
95  connect(ui.btnRemoveFilter, SIGNAL(clicked()), this, SLOT(removeSelectedFilter()));
96  connect(ui.btnPause, SIGNAL(toggled(bool)), this, SLOT(pauseLogging(bool)));
97  connect(ui.btnClearLog, SIGNAL(clicked()), this, SLOT(clearSelectedLog()));
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)));
102  connect(this, SIGNAL(updateFilterListSignal()), this, SLOT(updateFilterList()));
103  connect(ui.btnNextItem, SIGNAL(clicked()), this, SLOT(selectNextSearchResult()));
104  connect(ui.btnPreviousItem, SIGNAL(clicked()), this, SLOT(selectPreviousSearchResult()));
105 
106  ui.edtLiveFilter->hide();
107  ui.edtLiveSearch->setFocus();
108 
109 
110  }
111 
113  {
114  // ARMARX_VERBOSE << "~LogViewer";
115  }
116 
117 
118 
119  void armarx::LogViewer::loadSettings(QSettings* settings)
120  {
121  ui.cbVerbosityLevel->setCurrentIndex(settings->value("verbosityLevel", 2).toInt());
122  ui.cbAutoComponentFilters->setChecked(settings->value("autoFilterAdding", true).toBool());
123  }
124 
125  void armarx::LogViewer:: saveSettings(QSettings* settings)
126  {
127 
128  settings->setValue("verbosityLevel", ui.cbVerbosityLevel->currentIndex());
129 
130  settings->setValue("autoFilterAdding", ui.cbAutoComponentFilters->isChecked());
131 
132 
133  // // saving filters
134 
135  // QString filterName = ui.lvFilters->items()->data(USERROLE_LOGTABLEID).toString();
136  // for(unsigned int i= 0; i< logTable->getModel()->getFilters().size(); i++)
137  // {
138  // std::string columnName = logTable->getModel()->getFilters()[i].first;
139  // std::string filter = logTable->getModel()->getFilters()[i].second;
140  // if(columnName == ARMARX_LOG_COMPONENTSTR)
141  // filterDialog.ui->editComponent->setText(filter.c_str());
142  // else if(columnName == ARMARX_LOG_TAGSTR)
143  // filterDialog.ui->edtTag->setText(filter.c_str());
144  // else if(columnName == ARMARX_LOG_VERBOSITYSTR){
145 
146  // filterDialog.ui->cbVerbosity->setCurrentIndex(QString(filter.c_str()).toInt());
147  // }
148  // else if(columnName == ARMARX_LOG_MESSAGESTR)
149  // filterDialog.ui->edtMessage->setText(filter.c_str());
150  // else if(columnName == ARMARX_LOG_FILESTR)
151  // filterDialog.ui->edtFile->setText(filter.c_str());
152  // else if(columnName == ARMARX_LOG_FUNCTIONSTR)
153  // filterDialog.ui->edtFunction->setText(filter.c_str());
154  // }
155 
156 
157  }
158 
159 
160 
161 
163  {
164  usingTopic("Log");
165  }
166 
168  {
169  emit componentConnected();
170  }
171 
173  {
174  // QInputDialog dialog;
175  // if(dialog.exec() == QDialog::Rejected)
176  // return false;
177 
179  }
180 
181  QString LogViewer::loggingGroupNameToFilterName(const QString& loggingGroupName) const
182  {
183  return loggingGroupName.isEmpty() ? "" : ("_" + loggingGroupName);
184  }
185 
187  {
188  }
189 
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&)
191  {
192  LogMessage msg;
193  msg.who = who;
194  msg.time = time;
195  msg.tag = tag;
196  msg.type = severity;
197  msg.what = message;
198  msg.file = file;
199  msg.line = line;
200  msg.function = function;
201 
202  writeLog(msg);
203  }
204 
205  void LogViewer::writeLog(const LogMessage& msg, const Ice::Current&)
206  {
207  if (loggingPaused)
208  {
209  return;
210  }
211 
212  if (ui.cbVerbosityLevel->currentIndex() <= msg.type)
213  {
214  std::unique_lock lock(pendingEntriesMutex);
215  pendingEntries.push_back(msg);
216  }
217  }
218 
219 
220  void LogViewer::setRow(const LogMessage& msg, int rowIndex)
221  {
222  }
223 
224  void LogViewer::addNewEntry(const LogMessage& msg)
225  {
226  }
227 
228  void LogViewer::performLiveFilter(QString filterStr, int startRow)
229  {
230  // if((IceUtil::Time::now() - lastLiveSearchEditChangeTime).toSeconds() < 1)
231  // return;
232  if (filterStr.length() == 0)
233  {
235  }
236  else if (filterStr.length() < 3)
237  {
238  return;
239  }
240 
241  // LogSearch search(logTable);
242  // search.search(searchStr);
243  logTable->liveFilter(filterStr, startRow);
244  lastLiveSearchEditChangeTime = IceUtil::Time::now();
245  }
246 
247  void LogViewer::performLiveSearch(QString searchStr)
248  {
249  if (searchStr.length() == 0)
250  {
252  ui.btnNextItem->setEnabled(false);
253  ui.btnPreviousItem->setEnabled(false);
254  }
255  // else if(searchStr.length() < 3)
256  // return;
257  else
258  {
259  if (!logTable->liveSearch(searchStr))
260  {
261  getMainWindow()->statusBar()->showMessage("Could not find '" + logTable->getModel()->getCurrentSearchStr() + "' in the log!", 5000);
262  ui.btnNextItem->setEnabled(false);
263  ui.btnPreviousItem->setEnabled(false);
264  }
265  else
266  {
267  ui.btnNextItem->setEnabled(true);
268  ui.btnPreviousItem->setEnabled(true);
269  }
270 
271  }
272  }
273 
275  {
276  if (logTable)
277  {
279  }
280  }
281 
283  {
284  std::map<QString, LogTable*>::iterator it = filterMap.begin();
285 
286  for (; it != filterMap.end() ; it++)
287  {
288  it->second->getModel()->clearData();
289  }
290 
291  emit updateFilterListSignal();
292  }
293 
294 
295 
296 
297  void LogViewer::pauseLogging(bool pause)
298  {
299  loggingPaused = pause;
300  }
301 
302 
304  {
305  LogTable* newLogTable = new LogTable();
306  // newLogTable->setColumns(standardColumns);
307  QTreeWidgetItem* item = new QTreeWidgetItem(ui.lvFilters);
308  QString standardFilterStr = ALL_MESSAGES_FILTER;
309  item->setText(0, standardFilterStr);
310  item->setData(0, USERROLE_LOGTABLEID, standardFilterStr);
311  item->setData(0, USERROLE_BASENAME, standardFilterStr);
312  // item->setData(USERROLE_LOGTABLEPTR, qVariantFromValue((void*)newLogTable));
313  // ui.lvFilters->addItem(item);
314  filterMap[standardFilterStr] = newLogTable;
315  ui.splitter->addWidget(newLogTable);
316 
317  return newLogTable;
318  }
319 
320  LogTable* LogViewer::addFilter(QString filterId, QString filterName, QString loggingGroup, QString componentFilter, QString tagFilter, MessageType minimumVerbosity, QString messageFilter, QString fileFilter, QString functionFilter)
321  {
322 
323  if (filterMap.find(filterId) != filterMap.end())
324  {
325  QString msg = "A filter with the id " + filterId + " exists already";
326  showMessageBox(msg);
327  return NULL;
328  }
329 
330  LogTable* newLogTable = new LogTable();
331  newLogTable->hide();
332 
333  if (loggingGroup.length())
334  {
335  newLogTable->getModel()->addFilter(ARMARX_LOG_LOGGINGGROUPSTR, loggingGroup.toStdString());
336  }
337 
338  // newLogTable->setColumns(standardColumns);
339  if (componentFilter.length())
340  {
341  newLogTable->getModel()->addFilter(ARMARX_LOG_COMPONENTSTR, componentFilter.toStdString());
342  }
343 
344  if (tagFilter.length())
345  {
346  newLogTable->getModel()->addFilter(ARMARX_LOG_TAGSTR, tagFilter.toStdString());
347  }
348 
349  if (messageFilter.length())
350  {
351  newLogTable->getModel()->addFilter(ARMARX_LOG_MESSAGESTR, messageFilter.toStdString());
352  }
353 
354  if (fileFilter.length())
355  {
356  newLogTable->getModel()->addFilter(ARMARX_LOG_FILESTR, fileFilter.toStdString());
357  }
358 
359  if (functionFilter.length())
360  {
361  newLogTable->getModel()->addFilter(ARMARX_LOG_FUNCTIONSTR, functionFilter.toStdString());
362  }
363 
364  newLogTable->getModel()->addFilter(ARMARX_LOG_VERBOSITYSTR, QString::number(minimumVerbosity).toStdString());
365 
366  QTreeWidgetItem* item = new QTreeWidgetItem();
367  item->setText(0, filterName);
368  // item->setData(USERROLE_LOGTABLEPTR, qVariantFromValue((void*)newLogTable));
369  item->setData(0, USERROLE_LOGTABLEID, filterId);
370  item->setData(0, USERROLE_BASENAME, filterName);
371  filterMap[filterId] = newLogTable;
372  Ice::StringSeq children;
373  for (int i = 0; i < ui.lvFilters->invisibleRootItem()->childCount(); i++)
374  {
375  children.push_back(ui.lvFilters->invisibleRootItem()->child(i)->text(0).toStdString());
376  }
377 
378  QTreeWidgetItem* grpItem = NULL;
379  auto grpFilterId = loggingGroupNameToFilterName(loggingGroup);
380  for (int i = 0; i < ui.lvFilters->invisibleRootItem()->childCount(); i++)
381  {
382  if (ui.lvFilters->invisibleRootItem()->child(i)->data(0, USERROLE_BASENAME).toString() == grpFilterId)
383  {
384  grpItem = ui.lvFilters->invisibleRootItem()->child(i);
385  break;
386  }
387  }
388  if (grpItem)
389  {
390  grpItem->addChild(item);
391  // items.at(0)->sortChildren(0, Qt::AscendingOrder);
392  }
393  else
394  {
395  // ARMARX_INFO << loggingGroup.toStdString() << " group not found - adding " << filterId.toStdString() << " as toplevel\n" << children;
396  ui.lvFilters->insertTopLevelItem(0, item);
397  // ui.lvFilters->invisibleRootItem()->sortChildren(0, Qt::AscendingOrder);
398  }
399 
400  ui.splitter->addWidget(newLogTable);
401  return newLogTable;
402  }
403 
404  bool LogViewer::checkAndAddNewFilter(const QString& loggingGroupName, const QString& componentName)
405  {
406  if (componentName.length() == 0 && loggingGroupName.length() == 0)
407  {
408  return false;
409  }
410 
411  if (!ui.cbAutoComponentFilters->isChecked())
412  {
413  return false;
414  }
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);
419  ARMARX_CHECK_EXPRESSION(!filterName.isEmpty());
420  if (filterMap.count(filterId))
421  {
422  return false;
423  }
424 
425  addFilter(filterId, filterName, loggingGroupName, componentName, "", eDEBUG, "", "", "");
426  return true;
427  }
428 
429 
430 
432  {
433  FilterDialog filterDialog;
434 
435  if (!filterDialog.exec())
436  {
437  return;
438  }
439 
440  QString filterName = filterDialog.ui->edtFilterName->text();
441 
442  if (filterMap.find(filterName) != filterMap.end())
443  {
444  QString msg = "A filter with this name already exists";
445  showMessageBox(msg);
446  return;
447  }
448 
449  LogTable* newLogTable = new LogTable();
450  newLogTable->hide();
451 
452  // newLogTable->setColumns(standardColumns);
453  if (filterDialog.ui->editComponent->text().length())
454  {
455  newLogTable->getModel()->addFilter(ARMARX_LOG_COMPONENTSTR, filterDialog.ui->editComponent->text().toStdString());
456  }
457 
458  if (filterDialog.ui->edtTag->text().length())
459  {
460  newLogTable->getModel()->addFilter(ARMARX_LOG_TAGSTR, filterDialog.ui->edtTag->text().toStdString());
461  }
462 
463  if (filterDialog.ui->edtMessage->text().length())
464  {
465  newLogTable->getModel()->addFilter(ARMARX_LOG_MESSAGESTR, filterDialog.ui->edtMessage->text().toStdString());
466  }
467 
468  if (filterDialog.ui->edtFile->text().length())
469  {
470  newLogTable->getModel()->addFilter(ARMARX_LOG_FILESTR, filterDialog.ui->edtFile->text().toStdString());
471  }
472 
473  if (filterDialog.ui->edtFunction->text().length())
474  {
475  newLogTable->getModel()->addFilter(ARMARX_LOG_FUNCTIONSTR, filterDialog.ui->edtFunction->text().toStdString());
476  }
477 
478  if (filterDialog.ui->cbVerbosity->currentIndex() != -1)
479  {
480  newLogTable->getModel()->addFilter(ARMARX_LOG_VERBOSITYSTR, QString::number(filterDialog.ui->cbVerbosity->currentIndex()).toStdString());
481  }
482 
483  QTreeWidgetItem* item = new QTreeWidgetItem();
484  item->setText(0, filterName);
485  // item->setData(USERROLE_LOGTABLEPTR, qVariantFromValue((void*)newLogTable));
486  item->setData(0, USERROLE_LOGTABLEID, filterName);
487  item->setData(0, USERROLE_BASENAME, filterName);
488  filterMap[filterName] = newLogTable;
489  ui.lvFilters->insertTopLevelItem(ui.lvFilters->invisibleRootItem()->childCount(), item);
490  // ui.lvFilters->invisibleRootItem()->sortChildren(0, Qt::AscendingOrder);
491  ui.splitter->addWidget(newLogTable);
492  }
493 
494  void LogViewer::editFilter(QTreeWidgetItem* item, int column)
495  {
496  QString filterId = item->data(0, USERROLE_LOGTABLEID).toString();
497  FilterDialog filterDialog;
498  filterDialog.ui->edtFilterName->setText(item->data(0, USERROLE_BASENAME).toString());
499 
500  if (filterMap.find(filterId) == filterMap.end())
501  {
502  ARMARX_WARNING << "filter " << filterId.toStdString() << " does not exist" << flush;
503  return;
504  }
505 
506  LogTable* logTable = filterMap.find(filterId)->second;
507 
508  if (!logTable)
509  {
510  ARMARX_WARNING << "logtable ptr is NULL " << flush;
511  return;
512  }
513 
514  for (unsigned int i = 0; i < logTable->getModel()->getFilters().size(); i++)
515  {
516  std::string columnName = logTable->getModel()->getFilters()[i].first;
517  std::string filter = logTable->getModel()->getFilters()[i].second;
518 
519  if (columnName == ARMARX_LOG_COMPONENTSTR)
520  {
521  filterDialog.ui->editComponent->setText(filter.c_str());
522  }
523  else if (columnName == ARMARX_LOG_TAGSTR)
524  {
525  filterDialog.ui->edtTag->setText(filter.c_str());
526  }
527  else if (columnName == ARMARX_LOG_VERBOSITYSTR)
528  {
529 
530  filterDialog.ui->cbVerbosity->setCurrentIndex(QString(filter.c_str()).toInt());
531  }
532  else if (columnName == ARMARX_LOG_MESSAGESTR)
533  {
534  filterDialog.ui->edtMessage->setText(filter.c_str());
535  }
536  else if (columnName == ARMARX_LOG_FILESTR)
537  {
538  filterDialog.ui->edtFile->setText(filter.c_str());
539  }
540  else if (columnName == ARMARX_LOG_FUNCTIONSTR)
541  {
542  filterDialog.ui->edtFunction->setText(filter.c_str());
543  }
544  }
545 
546 
547  if (!filterDialog.exec())
548  {
549  return;
550  }
551  item->setText(0, filterDialog.ui->edtFilterName->text());
552  item->setData(0, USERROLE_BASENAME, filterDialog.ui->edtFilterName->text());
554 
555  if (filterDialog.ui->editComponent->text().length())
556  {
557  logTable->getModel()->addFilter(ARMARX_LOG_COMPONENTSTR, filterDialog.ui->editComponent->text().toStdString());
558  }
559 
560  if (filterDialog.ui->edtTag->text().length())
561  {
562  logTable->getModel()->addFilter(ARMARX_LOG_TAGSTR, filterDialog.ui->edtTag->text().toStdString());
563  }
564 
565  if (filterDialog.ui->edtMessage->text().length())
566  {
567  logTable->getModel()->addFilter(ARMARX_LOG_MESSAGESTR, filterDialog.ui->edtMessage->text().toStdString());
568  }
569 
570  if (filterDialog.ui->edtFile->text().length())
571  {
572  logTable->getModel()->addFilter(ARMARX_LOG_FILESTR, filterDialog.ui->edtFile->text().toStdString());
573  }
574 
575  if (filterDialog.ui->edtFunction->text().length())
576  {
577  logTable->getModel()->addFilter(ARMARX_LOG_FUNCTIONSTR, filterDialog.ui->edtFunction->text().toStdString());
578  }
579 
580  if (filterDialog.ui->cbVerbosity->currentIndex() != -1)
581  {
582  logTable->getModel()->addFilter(ARMARX_LOG_VERBOSITYSTR, QString::number(filterDialog.ui->cbVerbosity->currentIndex()).toStdString());
583  }
584 
586  logTable->update();
587 
588  }
589 
591  {
592  if (ui.lvFilters->invisibleRootItem()->childCount() == 1)
593  {
594  return;
595  }
596 
597  auto item = ui.lvFilters->currentItem();
598  removeFilter(item);
599 
600  }
601 
602  void LogViewer::removeFilter(QTreeWidgetItem* item)
603  {
604  if (!item)
605  {
606  return;
607  }
608 
609  std::map<QString, LogTable*>::iterator it = filterMap.find(item->data(0, USERROLE_LOGTABLEID).toString());
610 
611  if (it == filterMap.end())
612  {
613  return;
614  }
615  QList<QTreeWidgetItem*> itemsToDelete, iterationList({item});
616  while (!iterationList.isEmpty())
617  {
618  auto curItem = iterationList.front();
619  itemsToDelete << curItem;
620  iterationList.pop_front();
621  iterationList << curItem->takeChildren();
622  }
623  ui.lvFilters->setCurrentItem(ui.lvFilters->invisibleRootItem()->child(0));
624  for (auto& item : itemsToDelete)
625  {
626  auto parent = item->parent();
627  if (parent)
628  {
629  parent->removeChild(item);
630  }
631  else
632  {
633  ui.lvFilters->invisibleRootItem()->removeChild(item);
634  }
635  std::map<QString, LogTable*>::iterator it = filterMap.find(item->data(0, USERROLE_LOGTABLEID).toString());
636  delete item;
637 
638  if (it == filterMap.end())
639  {
640  continue;
641  }
642  LogTable* logTable = it->second;
643  delete logTable;
644  filterMap.erase(it);
645  }
646  }
647 
648 
649  void LogViewer::filterSelectionChanged(QTreeWidgetItem* item, QTreeWidgetItem* previous)
650  {
651  if (!item)
652  {
653  return;
654  }
655  LogTable* oldLogTable = logTable;
656  QString filterId = item->data(0, USERROLE_LOGTABLEID).toString();
657  // item->setText(0, filterId); Why?
658  QFont font;
659  font.setBold(false);
660  item->setFont(0, font);
661 
662  if (filterMap.find(filterId) == filterMap.end())
663  {
664  showMessageBox("Filtername " + filterId + " not found.");
665  return;
666  }
667 
668  logTable = filterMap[filterId];
669 
670  if (!logTable)
671  {
672  ARMARX_ERROR << "logTable ptr is NULL" << flush;
673  return;
674  }
675 
676 
677 
678  if (oldLogTable)
679  {
680  oldLogTable->hide();
681  }
682 
683  logTable->show();
684  ui.edtLiveFilter->setText(logTable->getLiveFilterStr());
685  ui.edtLiveSearch->setText(logTable->getModel()->getCurrentSearchStr());
686  }
687 
689  {
690  static QFont font;
691  QList<QTreeWidgetItem*> itemsToUpdate, iterationList({ui.lvFilters->invisibleRootItem()});
692  while (!iterationList.isEmpty())
693  {
694  auto curItem = iterationList.front();
695  itemsToUpdate << curItem;
696  iterationList.pop_front();
697  for (int i = 0; i < curItem->childCount(); ++i)
698  {
699  iterationList << curItem->child(i);
700  }
701  }
702  // Update new message count in filter list box
703  for (auto item : itemsToUpdate)
704  {
705  auto filterId = item->data(0, USERROLE_LOGTABLEID).toString();
706  LogTable* curLogtable = filterMap.find(filterId)->second;
707  if (!curLogtable)
708  {
709  continue;
710  }
711  QString newContent;
712 
713  if (curLogtable == logTable || curLogtable->getNewMessageCount() == 0)
714  {
715  font.setBold(false);
716  item->setFont(0, font);
717  newContent = item->data(0, USERROLE_BASENAME).toString();
718  item->setBackgroundColor(0, ui.lvFilters->palette().base().color());
719  }
720  else
721  {
722  font.setBold(true);
723  item->setFont(0, font);
724  newContent = item->data(0, USERROLE_BASENAME).toString() + "(" + QString::number(curLogtable->getNewMessageCount()) + ")";
725 
726  if (curLogtable->getMaxNewLogLevelType() == eWARN)
727  {
728  item->setBackgroundColor(0, QColor(216, 120, 50));
729  }
730  else if (curLogtable->getMaxNewLogLevelType() == eERROR)
731  {
732  item->setBackgroundColor(0, QColor(255, 90, 80));
733  }
734  else if (curLogtable->getMaxNewLogLevelType() == eFATAL)
735  {
736  item->setBackgroundColor(0, QColor(255, 60, 50));
737  }
738  else
739  {
740  item->setBackgroundColor(0, ui.lvFilters->palette().base().color());
741  }
742  }
743 
744  item->setText(0, newContent);
745  item->setToolTip(0, newContent);
746  }
747  }
748 
750  {
751  throw LocalException() << "Not yet implemented";
752  }
753 
755  {
756 
757  if (getState() >= eManagedIceObjectExiting)
758  {
759  return;
760  }
761 
762  std::vector <LogMessage> pendingEntriesTemp;
763  {
764  std::unique_lock lock(pendingEntriesMutex);
765  pendingEntriesTemp.swap(pendingEntries);
766  }
767 
768 
769 
770  unsigned int size = pendingEntriesTemp.size();
771  boost::regex re(REGEX_COLORS);
772  // check for new components, that are sending log messages and perform auto scroll
773  for (unsigned int i = 0; i < size; i++)
774  {
775  LogMessage& msg = pendingEntriesTemp[i];
776  msg.what = boost::regex_replace(msg.what, re, "");
777 
778  if (!getWidget() || ui.cbVerbosityLevel->currentIndex() > msg.type)
779  {
780  continue;
781  }
782  checkAndAddNewFilter(msg.group.c_str(), "");
783  checkAndAddNewFilter(msg.group.c_str(), msg.who.c_str());
784 
785  std::map<QString, LogTable*>::iterator it = filterMap.begin();
786 
787  for (; it != filterMap.end(); ++it)
788  {
789  LogTable* log = it->second;
790 
791  if (!log)
792  {
793  std::cerr << "log ptr is NULL" << std::endl;
794  return;
795  }
796 
797  //setRow(msg, currentRow);
798  bool autoScroll = false;
799 
800  if (log->verticalScrollBar()->value() == log->verticalScrollBar()->maximum())
801  {
802  autoScroll = true;
803  }
804 
805  //int row = log->addEntry(msg);
806 
807  if (autoScroll)
808  {
809  log->scrollToBottom();
810  }
811 
812  //dynamic_cast<LogTableModel*> (logTable->model())->updateView();
813  }
814 
815  }
816 
817  bool autoScroll = false;
818 
819  if (logTable->verticalScrollBar()->value() == logTable->verticalScrollBar()->maximum())
820  {
821  autoScroll = true;
822  }
823 
824  std::map<QString, LogTable*>::iterator it = filterMap.begin();
825 
826  for (; it != filterMap.end(); ++it)
827  {
828  LogTable* log = it->second;
829  int row = log->getModel()->rowCount();
830  int rowsAdded = log->getModel()->addEntries(pendingEntriesTemp, log->getCurrentLiveFilter());
831  if (rowsAdded > 0)
832  {
833  int count = log->getModel()->rowCount();
834  int r;
835  for (r = row; r < count; r++)
836  {
837  log->liveFilterRow(log->getCurrentLiveFilter(), r);
838  }
839  }
840  bool autoScroll = false;
841 
842  if (log->verticalScrollBar()->value() == log->verticalScrollBar()->maximum())
843  {
844  autoScroll = true;
845  }
846 
847 
848 
849  if (autoScroll)
850  {
851  log->scrollToBottom();
852  }
853 
854  }
855 
856 
857 
858  if (autoScroll)
859  {
860  logTable->scrollToBottom();
861  }
862 
864 
865 
866 
867 
868  }
869 
871  {
872  if (index == 0)
873  {
874  ui.edtLiveSearch->show();
875  ui.btnPreviousItem->show();
876  ui.btnNextItem->show();
877  ui.edtLiveFilter->hide();
878  }
879  else
880  {
881  ui.edtLiveSearch->hide();
882  ui.btnPreviousItem->hide();
883  ui.btnNextItem->hide();
884  ui.edtLiveFilter->show();
885  }
886  }
887 
889  {
890 
891  if (logTable)
892  {
893  if (!logTable->selectNextSearchResult(false))
894  {
895  getMainWindow()->statusBar()->showMessage("Could not find '" + logTable->getModel()->getCurrentSearchStr() + "' in the log!", 5000);
896  }
897  }
898  }
899 
901  {
902  if (logTable)
903  if (!logTable->selectNextSearchResult(true))
904  {
905  getMainWindow()->statusBar()->showMessage("Could not find '" + logTable->getModel()->getCurrentSearchStr() + "' in the log!", 5000);
906  }
907  }
908 
909 
910 
911  QPointer<QWidget> LogViewer::getCustomTitlebarWidget(QWidget* parent)
912  {
913  if (customToolbar)
914  {
915  if (parent != customToolbar->parent())
916  {
917  customToolbar->setParent(parent);
918  }
919 
920  return customToolbar;
921  }
922 
923  customToolbar = new QToolBar(parent);
924  customToolbar->setIconSize(QSize(16, 16));
925  customToolbar->addAction(QIcon(":/icons/configure-3.png"), "Configure", this, SLOT(OpenConfigureDialog()));
926 
927  return customToolbar;
928  }
929 }
armarx::LogTable::selectNextSearchResult
bool selectNextSearchResult(bool backwards=true, bool keepSelectionIfPossible=false)
Definition: LogTable.cpp:360
armarx::LogTableModel::addEntries
int addEntries(const std::vector< LogMessage > &entryList, const QString &filterStr)
Definition: LogTableModel.cpp:637
armarx::LogViewer::performLiveFilter
void performLiveFilter(QString searchStr, int startRow=0)
Definition: LogViewer.cpp:228
armarx::LogTable
Definition: LogTable.h:56
USERROLE_LOGTABLEID
#define USERROLE_LOGTABLEID
Definition: LogViewer.cpp:45
armarx::LogViewer::updateFilterList
void updateFilterList()
Definition: LogViewer.cpp:688
armarx::MessageTypeT
MessageTypeT
Definition: LogSender.h:45
armarx::LogTableModel::getFilters
const std::vector< std::pair< std::string, std::string > > & getFilters() const
Definition: LogTableModel.h:77
armarx::LogViewer::write
void 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 &=Ice::emptyCurrent)
Definition: LogViewer.cpp:190
armarx::LogViewer::addEmptyFilter
LogTable * addEmptyFilter()
Definition: LogViewer.cpp:303
armarx::LogViewer::saveSettings
void saveSettings(QSettings *settings) override
Implement to save the settings as part of the GUI configuration.
Definition: LogViewer.cpp:125
armarx::LogTableModel::resetFilters
void resetFilters()
Definition: LogTableModel.cpp:592
armarx::LogViewer::~LogViewer
~LogViewer() override
Definition: LogViewer.cpp:112
armarx::LogViewer::editFilter
void editFilter(QTreeWidgetItem *item, int column)
Definition: LogViewer.cpp:494
armarx::LogTable::getMaxNewLogLevelType
MessageType getMaxNewLogLevelType()
Definition: LogTable.h:76
armarx::FilterDialog::ui
Ui::FilterDialog * ui
Definition: FilterDialog.h:45
armarx::LogViewer::selectPreviousSearchResult
void selectPreviousSearchResult()
Definition: LogViewer.cpp:900
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::LogTableModel::getCurrentSearchStr
QString getCurrentSearchStr()
Definition: LogTableModel.h:65
LogTableModel.h
REGEX_COLORS
#define REGEX_COLORS
Definition: LogViewer.cpp:48
armarx::LogViewer::getCustomTitlebarWidget
QPointer< QWidget > getCustomTitlebarWidget(QWidget *parent) override
getTitleToolbar returns a pointer to the a toolbar widget of this controller.
Definition: LogViewer.cpp:911
armarx::LogViewer::insertPendingEntries
void insertPendingEntries()
Definition: LogViewer.cpp:754
armarx::LogTable::getModel
LogTableModel * getModel()
Definition: LogTable.cpp:234
armarx::LogViewer::OpenConfigureDialog
void OpenConfigureDialog()
Definition: LogViewer.cpp:749
armarx::LogTable::liveFilterRow
void liveFilterRow(const QString &filterStr, int row)
Definition: LogTable.cpp:121
armarx::ManagedIceObject::getState
int getState() const
Retrieve current state of the ManagedIceObject.
Definition: ManagedIceObject.cpp:725
armarx::LogViewer::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: LogViewer.cpp:162
armarx::LogViewer::filterSelectionChanged
void filterSelectionChanged(QTreeWidgetItem *item, QTreeWidgetItem *previous)
Definition: LogViewer.cpp:649
ARMARX_LOG_FILESTR
#define ARMARX_LOG_FILESTR
Definition: LogTable.h:44
message
message(STATUS "Boost-Library-Dir: " "${Boost_LIBRARY_DIRS}") message(STATUS "Boost-LIBRARIES
Definition: CMakeLists.txt:8
armarx::LogViewer::logTable
LogTable * logTable
Definition: LogViewer.h:123
FilterDialog.h
armarx::LogTableModel::addFilter
void addFilter(const std::string &columnName, const std::string &filter)
Definition: LogTableModel.cpp:559
armarx::LogViewer::componentConnected
void componentConnected()
armarx::LogTableModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: LogTableModel.cpp:37
ARMARX_LOG_FUNCTIONSTR
#define ARMARX_LOG_FUNCTIONSTR
Definition: LogTable.h:45
armarx::LogViewer::clearAllLogs
void clearAllLogs()
Definition: LogViewer.cpp:282
armarx::LogViewer::ui
Ui_LogViewer ui
Definition: LogViewer.h:122
armarx::ArmarXWidgetController::getMainWindow
virtual QMainWindow * getMainWindow()
Returns the ArmarX MainWindow.
Definition: ArmarXWidgetController.cpp:125
armarx::LogViewer::performLiveSearch
void performLiveSearch(QString searchStr)
Definition: LogViewer.cpp:247
armarx::LogViewer::checkAndAddNewFilter
bool checkAndAddNewFilter(const QString &loggingGroupName, const QString &componentName)
This function checks, if there are new components in the log and if so, it creates new filters for th...
Definition: LogViewer.cpp:404
armarx::LogViewer::removeSelectedFilter
void removeSelectedFilter()
Definition: LogViewer.cpp:590
armarx::FilterDialog
Definition: FilterDialog.h:36
armarx::LogViewer::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: LogViewer.cpp:167
armarx::LogTable::liveSearch
bool liveSearch(const QString &search)
Definition: LogTable.cpp:209
armarx::LogViewer::searchTypeChanged
void searchTypeChanged(int index)
Definition: LogViewer.cpp:870
ARMARX_LOG_MESSAGESTR
#define ARMARX_LOG_MESSAGESTR
Definition: LogTable.h:43
armarx::LogViewer::selectNextSearchResult
void selectNextSearchResult()
Definition: LogViewer.cpp:888
armarx::LogTable::getNewMessageCount
int getNewMessageCount()
Definition: LogTable.h:72
ALL_MESSAGES_FILTER
#define ALL_MESSAGES_FILTER
Definition: LogViewer.cpp:49
LogTable.h
armarx::flush
const LogSender::manipulator flush
Definition: LogSender.h:251
armarx::LogTable::resetLiveFilter
void resetLiveFilter()
Definition: LogTable.cpp:218
armarx::LogViewer::writeLog
void writeLog(const LogMessage &msg, const Ice::Current &=Ice::emptyCurrent) override
Definition: LogViewer.cpp:205
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:917
ARMARX_LOG_LOGGINGGROUPSTR
#define ARMARX_LOG_LOGGINGGROUPSTR
Definition: LogTable.h:46
armarx::LogViewer::loadSettings
void loadSettings(QSettings *settings) override
Implement to load the settings that are part of the GUI configuration.
Definition: LogViewer.cpp:119
ARMARX_LOG_TAGSTR
#define ARMARX_LOG_TAGSTR
Definition: LogTable.h:41
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
armarx::LogTable::resetLiveSearch
void resetLiveSearch()
Definition: LogTable.cpp:227
armarx::LogViewer::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: LogViewer.cpp:186
armarx::LogViewer::onClose
bool onClose() override
onClose is called before the DockWidget is closed.
Definition: LogViewer.cpp:172
armarx::LogViewer::LogViewer
LogViewer()
Definition: LogViewer.cpp:53
ARMARX_LOG_VERBOSITYSTR
#define ARMARX_LOG_VERBOSITYSTR
Definition: LogTable.h:42
armarx::ArmarXWidgetController::showMessageBox
static int showMessageBox(const QString &msg)
Definition: ArmarXWidgetController.cpp:166
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
armarx::LogViewer::clearSelectedLog
void clearSelectedLog()
Definition: LogViewer.cpp:274
armarx::LogTable::getCurrentLiveFilter
QString getCurrentLiveFilter() const
Definition: LogTable.cpp:115
armarx::LogViewer::addNewEntry
void addNewEntry(const LogMessage &msg)
Definition: LogViewer.cpp:224
armarx::LogTable::getLiveFilterStr
QString getLiveFilterStr()
Definition: LogTable.h:85
armarx::Logging::tag
LogTag tag
Definition: Logging.h:271
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:916
LogViewer.h
armarx::LogTableModel::clearData
int clearData()
Definition: LogTableModel.cpp:686
armarx::ArmarXWidgetController::getWidget
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
Definition: ArmarXWidgetController.cpp:54
USERROLE_BASENAME
#define USERROLE_BASENAME
Definition: LogViewer.cpp:47
armarx::LogViewer::removeFilter
void removeFilter(QTreeWidgetItem *item)
Definition: LogViewer.cpp:602
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::LogViewer::addFilter
void addFilter()
Definition: LogViewer.cpp:431
ARMARX_LOG_COMPONENTSTR
#define ARMARX_LOG_COMPONENTSTR
Definition: LogTable.h:40
armarx::LogViewer::pauseLogging
void pauseLogging(bool pause=false)
Definition: LogViewer.cpp:297
armarx::LogViewer::setRow
void setRow(const LogMessage &msg, int rowIndex)
Definition: LogViewer.cpp:220
armarx::LogViewer::updateFilterListSignal
void updateFilterListSignal()
armarx::LogTable::liveFilter
void liveFilter(const QString &search, int startRow=0)
Definition: LogTable.cpp:136
armarx::LogViewer::newEntry
void newEntry(const LogMessage &msg)
armarx::LogTableModel::reapplyAllFilters
void reapplyAllFilters()
Definition: LogTableModel.cpp:564
armarx::ArmarXComponentWidgetController::onClose
bool onClose() override
If you overwrite this method, make sure to call this implementation at the end of your implementation...
Definition: ArmarXComponentWidgetController.cpp:42
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::LogSender::levelToString
static std::string levelToString(MessageTypeT type)
Definition: LogSender.cpp:611