YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
mainwindow.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6#include "mainwindow.h"
7#include "ui_mainwindow.h"
8#include "advanced_dialog.h"
9#include "logtab.h"
10#include "ui_logtab.h"
11#include <QString>
12#include <QMenu>
13#include <QTextStream>
14#include <ctime>
16#include <QAbstractItemModel>
17#include <QStandardItemModel>
18#include <QDesktopServices>
19#include <QUrl>
20#include <QSignalMapper>
21#include <QFileDialog>
22#include <QDateTime>
23#include <QMimeData>
24
25void MainWindow::updateMain()
26{
27 //model_yarprunports->clear();
28 std::list<yarp::yarpLogger::LogEntryInfo> infos;
29 this->theLogger->get_infos (infos);
30 std::list<yarp::yarpLogger::LogEntryInfo>::iterator it;
31
32 QStandardItem *itemsRoot = model_yarprunports->invisibleRootItem();
33 for (it=infos.begin(); it!=infos.end(); it++)
34 {
35 const size_t string_size= 50;
36 char time_text[string_size];
37 if (it->last_update!=-1)
38 {
39 std::tm* tm = localtime(&it->last_update);
40 sprintf(time_text, "%02d:%02d:%02d %02d/%02d/%02d", tm->tm_hour, tm->tm_min, tm->tm_sec, tm->tm_mday, tm->tm_mon, tm->tm_year+1900);
41 } else {
42 sprintf(time_text, "no data received yet");
43 }
44
45 char logsize_text[10];
46 sprintf (logsize_text, "%d", it->logsize);
47
48 char logerrors_text[10];
49 sprintf (logerrors_text, "%d", it->get_number_of_errors());
50
51 char logwarnings_text[10];
52 sprintf (logwarnings_text, "%d", it->get_number_of_warnings());
53
54//#define TREE_MODEL 1
55#define IN_ROW_MODEL 1
56#if IN_ROW_MODEL
57 bool existing = false;
58 int i=0;
59 for (i=0; i<model_yarprunports->rowCount(); i++)
60 {
61 QStandardItem *item = model_yarprunports->item(i,1);
62 if (item && item->text()==it->port_complete.c_str())
63 {
64 model_yarprunports->item(i,2)->setText(time_text);
65 model_yarprunports->item(i,3)->setText(logsize_text);
66 model_yarprunports->item(i,4)->setText(logerrors_text);
67 model_yarprunports->item(i,5)->setText(logwarnings_text);
68
69 QColor rowcolor = QColor(Qt::white);
70 yarp::yarpLogger::LogLevel last_error = it->getLastError();
71
72 bool log_enabled = this->theLogger->get_log_enable_by_port_complete(it->port_complete);
73 if (log_enabled)
74 {
75 if (last_error == yarp::yarpLogger::LOGLEVEL_ERROR) {
76 rowcolor = QColor("#FF7070");
77 } else if (last_error == yarp::yarpLogger::LOGLEVEL_WARNING) {
78 rowcolor = QColor("#FFFF70");
79 }
80 for (int j = 0; j < model_yarprunports->columnCount(); j++) {
81 model_yarprunports->item(i, j)->setBackground(rowcolor);
82 }
83 }
84
85 existing = true;
86 if (it->last_update==-1 && !ui->actionShow_Mute_Ports->isChecked()) {model_yarprunports->removeRow(i);}
87 break;
88 }
89 }
90 if (existing == false)
91 {
92 QList<QStandardItem *> rowItems;
93 rowItems << new QStandardItem(it->ip_address.c_str())
94 << new QStandardItem(it->port_complete.c_str())
95 << new QStandardItem(time_text)
96 << new QStandardItem(logsize_text)
97 << new QStandardItem(logerrors_text)
98 << new QStandardItem (logwarnings_text);
99 if (ui->actionShow_Mute_Ports->isChecked() || it->last_update!=-1)
100 {
101 itemsRoot->appendRow(rowItems);
102 }
103 }
104
105#elif TREE_MODEL
106 bool level1_exists = false;
107 bool level2_exists = false;
108 for (int i=0; i<model_yarprunports->rowCount(); i++)
109 {
110 QStandardItem *item_level1 = model_yarprunports->item(i,0);
111 if (item_level1 && item_level1->text() == it->port_prefix.c_str())
112 {
113 level1_exists = true;
114 for (int j=0; j<item_level1->rowCount(); j++)
115 {
116 QStandardItem *item_level2 = item_level1->child(j,0);
117 if (item_level2 && item_level1->child(j,1)->text() == it->port_complete.c_str())
118 {
119 level2_exists = true;
120 item_level1->child(j,2)->text() = time_text;
121 break;
122 }
123 }
124 if (level2_exists == false)
125 {
126 QList<QStandardItem *> rowItems;
127 rowItems << new QStandardItem(it->port_prefix.c_str())
128 << new QStandardItem(it->port_complete.c_str())
129 << new QStandardItem(time_text);
130 item_level1->appendRow(rowItems);
131 break;
132 }
133 }
134 }
135 if (level1_exists == false)
136 {
137 /*QList<QStandardItem *> rowItems_l1;
138 QList<QStandardItem *> rowItems_l2;
139 rowItems_l1 << new QStandardItem(it->port_prefix.c_str());
140 rowItems_l2 << new QStandardItem(it->port_prefix.c_str()) << new QStandardItem(it->port_complete.c_str()) << new QStandardItem(time_text);
141 rowItems_l1->appendRow(rowItems_l2);
142 itemsRoot->appendRow(rowItems_l1);*/
143 QList<QStandardItem *> rowItems_l1;
144 rowItems_l1 << new QStandardItem(it->port_prefix.c_str());
145 itemsRoot->appendRow(rowItems_l1);
146 }
147 /*if (existing == false)
148 {
149 QList<QStandardItem *> rowItems;
150 rowItems << new QStandardItem(it->port_prefix.c_str()) << new QStandardItem(it->port_complete.c_str()) << new QStandardItem(time_text);
151 itemsRoot->appendRow(rowItems);
152 }
153 bool rowfound = false;
154 for (int i=0; i<model_yarprunports->rowCount(); i++)
155 {
156 QStandardItem *rowParent = model_yarprunports->item(i,0);
157 if (rowParent && rowParent->text()==it->port_prefix.c_str())
158 {
159 rowParent->appendRow(rowItems);
160 rowfound = true;
161 }
162 }
163 if (rowfound==false)
164 {
165 itemsRoot->appendRow(rowItems);
166 }*/
167#endif
168 }
169}
170
171void MainWindow::on_enableLogTab(int model_row)
172{
173 std::string logname = model_yarprunports->item(model_row,1)->text().toStdString();
174 bool log_enabled = theLogger->get_log_enable_by_port_complete(logname);
175
176 if (log_enabled)
177 {
178 theLogger->set_log_enable_by_port_complete(logname,false);
179 for (int j = 0; j < model_yarprunports->columnCount(); j++) {
180 model_yarprunports->item(model_row, j)->setBackground(QColor("#808080"));
181 }
182 QString message = logname.c_str() + QString(" log disabled");
183 system_message->addMessage(message);
184 }
185 else
186 {
187 theLogger->set_log_enable_by_port_complete(logname,true);
188 for (int j = 0; j < model_yarprunports->columnCount(); j++) {
189 model_yarprunports->item(model_row, j)->setBackground(QColor(Qt::white));
190 }
191 QString message = logname.c_str() + QString(" log enabled");
192 system_message->addMessage(message);
193 }
194}
195
196void MainWindow::on_enableLogTab_action()
197{
198 QModelIndex pre_index = ui->yarprunTreeView->selectionModel()->currentIndex();
199 QModelIndex index = proxyModel->mapToSource(pre_index);
200 int model_row=index.row();
201 if (model_row==-1)
202 {
203 system_message->addMessage("on_clearLogTab_action error", MESSAGE_LEVEL_ERROR);
204 return;
205 }
206 on_enableLogTab(model_row);
207}
208
209void MainWindow::on_clearLogTab(int model_row)
210{
211 QString logname = model_yarprunports->item(model_row,1)->text();
212 theLogger->clear_messages_by_port_complete(logname.toStdString());
213 for (int i=0; i<ui->logtabs->count(); i++)
214 {
215 if (ui->logtabs->tabText(i) == logname)
216 {
217 auto* l = ui->logtabs->widget(i)->findChild<LogTab*>("logtab");
218 if (l) {
219 l->clearLogModel();
220 }
221 break;
222 }
223 }
224 QString message = logname + QString(" log cleared");
225 system_message->addMessage(message);
226}
227
228void MainWindow::on_clearLogTab_action()
229{
230 QModelIndex pre_index = ui->yarprunTreeView->selectionModel()->currentIndex();
231 QModelIndex index = proxyModel->mapToSource(pre_index);
232 int model_row=index.row();
233 if (model_row==-1)
234 {
235 system_message->addMessage("on_clearLogTab_action error",MESSAGE_LEVEL_ERROR);
236 return;
237 }
238 on_clearLogTab(model_row);
239}
240
241void MainWindow::on_resetCountersLogTab(int model_row)
242{
243 std::string logname = model_yarprunports->item(model_row,1)->text().toStdString();
244 system_message->addMessage(QString("Counters reset for log ") + QString(logname.c_str()));
245}
246
247void MainWindow::on_saveLogTab(int model_row)
248{
249 std::string logname = model_yarprunports->item(model_row,1)->text().toStdString();
250 std::string preferred_filename=logname;
251 std::replace(preferred_filename.begin(), preferred_filename.end(), '/', '_');
252 preferred_filename.erase(0,1);
253 QString fileName = QFileDialog::getSaveFileName(this, tr("Export log to text file"),preferred_filename.c_str(), tr("Text Files (*.txt)"));
254 if (fileName.size()!=0)
255 {
256 if (theLogger->export_log_to_text_file(fileName.toStdString(), logname)) {
257 system_message->addMessage(QString("Current log successfully exported to file: ") + fileName);
258 }
259 }
260}
261
262void MainWindow::on_saveLogTab_action()
263{
264 QModelIndex pre_index = ui->yarprunTreeView->selectionModel()->currentIndex();
265 QModelIndex index = proxyModel->mapToSource(pre_index);
266 int model_row=index.row();
267 if (model_row==-1)
268 {
269 system_message->addMessage("on_saveLogTab_action error",MESSAGE_LEVEL_ERROR);
270 return;
271 }
272 on_saveLogTab(model_row);
273}
274
275void MainWindow::on_resetCountersLogTab_action()
276{
277 QModelIndex pre_index = ui->yarprunTreeView->selectionModel()->currentIndex();
278 QModelIndex index = proxyModel->mapToSource(pre_index);
279 int model_row=index.row();
280 if (model_row==-1)
281 {
282 system_message->addMessage("on_resetCountersLogTab_action error",MESSAGE_LEVEL_ERROR);
283 return;
284 }
285 on_resetCountersLogTab(model_row);
286}
287
288void MainWindow::ctxMenu(const QPoint &pos)
289{
290 QModelIndex pre_index = ui->yarprunTreeView->selectionModel()->currentIndex();
291 QModelIndex index = proxyModel->mapToSource(pre_index);
292 int model_row=index.row();
293 if (model_row==-1)
294 {
295 system_message->addMessage("ctxMenu error",MESSAGE_LEVEL_ERROR);
296 return;
297 }
298 std::string logname = model_yarprunports->item(model_row,1)->text().toStdString();
299 bool log_enabled = theLogger->get_log_enable_by_port_complete(logname);
300
301 auto* menu = new QMenu;
302 menu->addAction(tr("Clear current log"), this, SLOT(on_clearLogTab_action()));
303 menu->addAction(tr("Export current log to text file"), this, SLOT(on_saveLogTab_action()));
304 menu->addAction(log_enabled ? tr("Disable current log") : tr("Enable current log"), this, SLOT(on_enableLogTab_action()));
305 menu->addAction(tr("Reset errors/warning counters"), this, SLOT(on_resetCountersLogTab_action()));
306 menu->exec(ui->yarprunTreeView->mapToGlobal(pos));
307}
308
309MainWindow::MainWindow(QWidget *parent) :
310 QMainWindow(parent),
311 ui(new Ui::MainWindow)
312{
314
315 std::string loggername = rf.check("name",yarp::os::Value("/yarplogger")).asString();
316 theLogger = new yarp::yarpLogger::LoggerEngine(loggername);
317
318 ui->setupUi(this);
319
320 system_message = ui->tab->findChild<MessageWidget*>("system_message");
321 system_message->addMessage("Application Started");
322
323 model_yarprunports = new QStandardItemModel(this);
324
325 proxyModel = new YarprunPortsSortFilterProxyModel(this);
326 proxyModel->setSourceModel(model_yarprunports);
327
328 mainTimer = new QTimer(this);
329 connect(mainTimer, SIGNAL(timeout()), this, SLOT(updateMain()));
330 mainTimer->start(500);
331
332 ui->yarprunTreeView->setModel(proxyModel);
333 ui->yarprunTreeView->expandAll();
334 selection_yarprunports=ui->yarprunTreeView->selectionModel();
335
336 connect(ui->yarprunTreeView, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(ctxMenu(const QPoint &)));
337
338 bool autostart = rf.check("start");
339 if (autostart)
340 {
341 system_message->addMessage("start option found");
342 on_actionStart_Logger_triggered();
343 }
344
345 bool unlimited = rf.check("unlimited_size");
346 if (unlimited)
347 {
348 system_message->addMessage("unlimited_size option found");
349 theLogger->set_log_lines_max_size(false, 1000000);
350 theLogger->set_log_list_max_size(false, 1000000);
351 }
352
353 //set headers
354 resetMainWindowHeaders();
355
356 setAcceptDrops(true);
357}
358
360{
361 this->theLogger->stop_logging();
362 if (mainTimer) {delete mainTimer; mainTimer=nullptr;}
363 if (ui) {delete ui; ui=nullptr;}
364}
365
366void MainWindow::loadTextFile()
367{
368 /*
369 QFile inputFile("c:\\ptcsetup.log");
370 inputFile.open(QIODevice::ReadOnly);
371
372 QTextStream in(&inputFile);
373 QString line = in.readAll();
374 inputFile.close();
375
376 ui->textEdit->setPlainText(line);
377 QTextCursor cursor = ui->textEdit->textCursor();
378 cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1);
379 */
380}
381
382void MainWindow::on_filterLineEdit_textChanged(const QString &text)
383{
384#if USE_FILTERS
385 QString filter = "*";
386 filter.append(text);
387 filter.append("*");
388 QRegExp regExp(filter, Qt::CaseInsensitive, QRegExp::Wildcard);
389
390 auto* logtab = ui->logtabs->currentWidget()->findChild<LogTab*>("logtab");
391 if (logtab) {
392 logtab->proxyModelSearch->setFilterRegExp(regExp);
393 }
394#endif
395}
396
397void MainWindow::on_logtabs_tabCloseRequested(int index)
398{
399 delete ui->logtabs->widget(index);
400}
401
402void MainWindow::on_yarprunTreeView_doubleClicked(const QModelIndex &pre_index)
403{
404 QModelIndex index = proxyModel->mapToSource(pre_index);
405 int model_row=index.row();
406 if (model_row==-1)
407 {
408 system_message->addMessage("Invalid log selected",MESSAGE_LEVEL_ERROR);
409 return;
410 }
411 QString tabname = model_yarprunports->item(model_row,1)->text();
412
413 int exists = -1;
414 for (int i = 0; i < ui->logtabs->count(); i++) {
415 if (ui->logtabs->tabText(i) == tabname) {
416 exists = i;
417 }
418 }
419
420 if (exists>=0)
421 {
422 ui->logtabs->setCurrentIndex(exists);
423 }
424 else
425 {
426 auto* tab = new QTabWidget(this);
427 auto* l = new QVBoxLayout(tab);
428 l->setContentsMargins(0, 0, 0, 0);
429 l->setSpacing(0);
430 LogTab* tmpLogTab = new LogTab(theLogger, system_message, tabname.toStdString(), this);
431 tmpLogTab->displayYarprunTimestamp(ui->actionShow_YarprunTimestamps->isChecked());
432 tmpLogTab->displayLocalTimestamp(ui->actionShow_LocalTimestamps->isChecked());
433 tmpLogTab->displaySystemTime(ui->actionShow_System_Time->isChecked());
434 tmpLogTab->displayNetworkTime(ui->actionShow_Network_Time->isChecked());
435 tmpLogTab->displayExternalTime(ui->actionShow_Custom_Time->isChecked());
436 tmpLogTab->displayLogLevel(ui->actionShow_Log_Level->isChecked());
437 tmpLogTab->displayFilename(ui->actionShow_Filename->isChecked());
438 tmpLogTab->displayLine(ui->actionShow_Line_Number->isChecked());
439 tmpLogTab->displayFunction(ui->actionShow_Function->isChecked());
440 tmpLogTab->displayHostname(ui->actionShow_Hostname->isChecked());
441 tmpLogTab->displayPid(ui->actionShow_Pid->isChecked());
442 tmpLogTab->displayCmd(ui->actionShow_Cmd->isChecked());
443 tmpLogTab->displayArgs(ui->actionShow_Args->isChecked());
444 tmpLogTab->displayThreadId(ui->actionShow_Thread_Id->isChecked());
445 tmpLogTab->displayComponent(ui->actionShow_Component->isChecked());
446 tmpLogTab->displayId(ui->actionShow_Id->isChecked());
447 tmpLogTab->displayGrid(ui->actionShow_Grid->isChecked());
448 tmpLogTab->displayColors(ui->actionShow_Colors->isChecked());
449 l->addWidget(tmpLogTab);
450 tmpLogTab->setObjectName("logtab");
451
452 int newtab_index = ui->logtabs->addTab(tab, tabname);
453 ui->logtabs->setCurrentIndex(newtab_index);
454 }
455 apply_button_filters(); //@@@@NOT WORKING HERE
456}
457
458QString MainWindow::recomputeFilters()
459{
460 QString filter;
461 bool e_trace = this->ui->DisplayTraceEnable->isChecked();
462 bool e_debug = this->ui->DisplayDebugEnable->isChecked();
463 bool e_info = this->ui->DisplayInfoEnable->isChecked();
464 bool e_warning = this->ui->DisplayWarningEnable->isChecked();
465 bool e_error = this->ui->DisplayErrorEnable->isChecked();
466 bool e_all = this->ui->DisplayUnformattedEnable->isChecked();
467 int f = 0;
468 if (e_trace) {filter = filter + "^TRACE$"; f++;}
469 if (e_debug) {
470 if (f > 0) {
471 filter = filter + "|";
472 }
473 filter = filter + "^DEBUG$";
474 f++;
475 }
476 if (e_info) {
477 if (f > 0) {
478 filter = filter + "|";
479 }
480 filter = filter + "^INFO$";
481 f++;
482 }
483 if (e_warning) {
484 if (f > 0) {
485 filter = filter + "|";
486 }
487 filter = filter + "^WARNING$";
488 f++;
489 }
490 if (e_error) {
491 if (f > 0) {
492 filter = filter + "|";
493 }
494 filter = filter + "^ERROR$";
495 f++;
496 }
497 if (e_all) {
498 if (f > 0) {
499 filter = filter + "|";
500 }
501 filter = filter + "^$";
502 f++;
503 }
504 if (true) {
505 if (f > 0) {
506 filter = filter + "|";
507 }
508 filter = filter + "^FATAL$";
509 f++;
510 }
511 std::string debug = filter.toStdString();
512 return filter;
513}
514
515void MainWindow::apply_button_filters()
516{
517#if USE_FILTERS
518 QRegExp regExp ("*", Qt::CaseInsensitive, QRegExp::RegExp);
519 regExp.setPattern(recomputeFilters());
520 for (int i=0; i<ui->logtabs->count(); i++)
521 {
522 auto* logtab = ui->logtabs->widget(i)->findChild<LogTab*>("logtab");
523 if (logtab) {
524 logtab->proxyModelButtons->setFilterRegExp(regExp);
525 logtab->proxyModelButtons->setFilterKeyColumn(LogModel::LOGLEVEL_COLUMN);
526 }
527 }
528#endif
529}
530
531void MainWindow::on_DisplayErrorEnable_toggled(bool checked)
532{
533 apply_button_filters();
534}
535
536void MainWindow::on_DisplayWarningEnable_toggled(bool checked)
537{
538 apply_button_filters();
539}
540
541void MainWindow::on_DisplayDebugEnable_toggled(bool checked)
542{
543 apply_button_filters();
544}
545
546void MainWindow::on_DisplayInfoEnable_toggled(bool checked)
547{
548 apply_button_filters();
549}
550
551void MainWindow::on_DisplayTraceEnable_toggled(bool checked)
552{
553 apply_button_filters();
554}
555
556void MainWindow::on_DisplayUnformattedEnable_toggled(bool checked)
557{
558 apply_button_filters();
559}
560
561void MainWindow::on_actionShow_YarprunTimestamps_toggled(bool checked)
562{
563 for (int i=0; i<ui->logtabs->count(); i++)
564 {
565 auto* logtab = ui->logtabs->widget(i)->findChild<LogTab*>("logtab");
566 if (logtab)
567 {
568 logtab->displayYarprunTimestamp(checked);
569 }
570 }
571}
572
573void MainWindow::on_actionShow_LocalTimestamps_toggled(bool checked)
574{
575 for (int i=0; i<ui->logtabs->count(); i++)
576 {
577 auto* logtab = ui->logtabs->widget(i)->findChild<LogTab*>("logtab");
578 if (logtab)
579 {
580 logtab->displayLocalTimestamp(checked);
581 }
582 }
583}
584
585void MainWindow::on_actionShow_System_Time_toggled(bool checked)
586{
587 for (int i=0; i<ui->logtabs->count(); i++)
588 {
589 auto* logtab = ui->logtabs->widget(i)->findChild<LogTab*>("logtab");
590 if (logtab)
591 {
592 logtab->displaySystemTime(checked);
593 }
594 }
595}
596
597void MainWindow::on_actionShow_Network_Time_toggled(bool checked)
598{
599 for (int i=0; i<ui->logtabs->count(); i++)
600 {
601 auto* logtab = ui->logtabs->widget(i)->findChild<LogTab*>("logtab");
602 if (logtab)
603 {
604 logtab->displayNetworkTime(checked);
605 }
606 }
607}
608
609void MainWindow::on_actionShow_Custom_Time_toggled(bool checked)
610{
611 for (int i=0; i<ui->logtabs->count(); i++)
612 {
613 auto* logtab = ui->logtabs->widget(i)->findChild<LogTab*>("logtab");
614 if (logtab)
615 {
616 logtab->displayExternalTime(checked);
617 }
618 }
619}
620
621void MainWindow::on_actionShow_Log_Level_toggled(bool checked)
622{
623 for (int i=0; i<ui->logtabs->count(); i++)
624 {
625 auto* logtab = ui->logtabs->widget(i)->findChild<LogTab*>("logtab");
626 if (logtab)
627 {
628 logtab->displayLogLevel(checked);
629 }
630 }
631}
632
633void MainWindow::on_actionShow_Filename_toggled(bool checked)
634{
635 for (int i=0; i<ui->logtabs->count(); i++)
636 {
637 auto* logtab = ui->logtabs->widget(i)->findChild<LogTab*>("logtab");
638 if (logtab)
639 {
640 logtab->displayFilename(checked);
641 }
642 }
643}
644
645void MainWindow::on_actionShow_Line_Number_toggled(bool checked)
646{
647 for (int i=0; i<ui->logtabs->count(); i++)
648 {
649 auto* logtab = ui->logtabs->widget(i)->findChild<LogTab*>("logtab");
650 if (logtab)
651 {
652 logtab->displayLine(checked);
653 }
654 }
655}
656
657void MainWindow::on_actionShow_Function_toggled(bool checked)
658{
659 for (int i=0; i<ui->logtabs->count(); i++)
660 {
661 auto* logtab = ui->logtabs->widget(i)->findChild<LogTab*>("logtab");
662 if (logtab)
663 {
664 logtab->displayFunction(checked);
665 }
666 }
667}
668
669void MainWindow::on_actionShow_Hostname_toggled(bool checked)
670{
671 for (int i=0; i<ui->logtabs->count(); i++)
672 {
673 auto* logtab = ui->logtabs->widget(i)->findChild<LogTab*>("logtab");
674 if (logtab)
675 {
676 logtab->displayHostname(checked);
677 }
678 }
679}
680
681void MainWindow::on_actionShow_Pid_toggled(bool checked)
682{
683 for (int i=0; i<ui->logtabs->count(); i++)
684 {
685 auto* logtab = ui->logtabs->widget(i)->findChild<LogTab*>("logtab");
686 if (logtab)
687 {
688 logtab->displayPid(checked);
689 }
690 }
691}
692
693void MainWindow::on_actionShow_Cmd_toggled(bool checked)
694{
695 for (int i=0; i<ui->logtabs->count(); i++)
696 {
697 auto* logtab = ui->logtabs->widget(i)->findChild<LogTab*>("logtab");
698 if (logtab)
699 {
700 logtab->displayCmd(checked);
701 }
702 }
703}
704
705void MainWindow::on_actionShow_Args_toggled(bool checked)
706{
707 for (int i=0; i<ui->logtabs->count(); i++)
708 {
709 auto* logtab = ui->logtabs->widget(i)->findChild<LogTab*>("logtab");
710 if (logtab)
711 {
712 logtab->displayArgs(checked);
713 }
714 }
715}
716
717void MainWindow::on_actionShow_Thread_Id_toggled(bool checked)
718{
719 for (int i=0; i<ui->logtabs->count(); i++)
720 {
721 auto* logtab = ui->logtabs->widget(i)->findChild<LogTab*>("logtab");
722 if (logtab)
723 {
724 logtab->displayThreadId(checked);
725 }
726 }
727}
728
729void MainWindow::on_actionShow_Component_toggled(bool checked)
730{
731 for (int i=0; i<ui->logtabs->count(); i++)
732 {
733 auto* logtab = ui->logtabs->widget(i)->findChild<LogTab*>("logtab");
734 if (logtab)
735 {
736 logtab->displayComponent(checked);
737 }
738 }
739}
740
741void MainWindow::on_actionShow_Id_toggled(bool checked)
742{
743 for (int i=0; i<ui->logtabs->count(); i++)
744 {
745 auto* logtab = ui->logtabs->widget(i)->findChild<LogTab*>("logtab");
746 if (logtab)
747 {
748 logtab->displayId(checked);
749 }
750 }
751}
752
753void MainWindow::on_actionShow_Grid_toggled(bool checked)
754{
755 for (int i=0; i<ui->logtabs->count(); i++)
756 {
757 auto* logtab = ui->logtabs->widget(i)->findChild<LogTab*>("logtab");
758 if (logtab)
759 {
760 logtab->displayGrid(checked);
761 }
762 }
763}
764
765void MainWindow::on_actionShow_Colors_toggled(bool checked)
766{
767 for (int i=0; i<ui->logtabs->count(); i++)
768 {
769 auto* logtab = ui->logtabs->widget(i)->findChild<LogTab*>("logtab");
770 if (logtab)
771 {
772 logtab->displayColors(checked);
773 }
774 }
775}
776
777void MainWindow::on_actionShow_Mute_Ports_toggled(bool checked)
778{
779 // FIXME Do something?
780}
781
782void MainWindow::on_actionAbout_QtYarpLogger_triggered()
783{
784 QDesktopServices::openUrl(QUrl("https://www.yarp.it/latest/yarp_logging.html"));
785}
786
787void MainWindow::on_actionSave_Log_triggered(bool checked)
788{
789 QString dateformat = "dd_MM_yyyy_hh_mm_ss";
790 QDateTime currDate = QDateTime::currentDateTime();
791 QString preferred_filename = "yarprunlog_" + currDate.toString(dateformat) + ".log";
792 QString fileName = QFileDialog::getSaveFileName(this, tr("Save to log file"),preferred_filename, tr("Log Files (*.log)"));
793 if (fileName.size()!=0)
794 {
795 if (theLogger->save_all_logs_to_file(fileName.toStdString())) {
796 system_message->addMessage(QString("Log saved to file: ") + fileName);
797 } else {
798 system_message->addMessage(QString("Unable to save file: ") + fileName, MESSAGE_LEVEL_ERROR);
799 }
800 }
801}
802
803void MainWindow::on_actionLoad_Log_triggered()
804{
805 QString fileName = QFileDialog::getOpenFileName(this, tr("Load log file"),"./", tr("Log Files (*.log)"));
806 if (fileName.size()!=0)
807 {
808 on_actionStop_Logger_triggered();
809 on_actionClear_triggered();
810 if (theLogger->load_all_logs_from_file(fileName.toStdString())) {
811 system_message->addMessage(QString("Log loaded from file: ") + fileName);
812 } else {
813 system_message->addMessage(QString("Unable to load file: ") + fileName, MESSAGE_LEVEL_ERROR);
814 }
815 }
816}
817
818void MainWindow::on_actionAdvanced_triggered()
819{
820 QDialog* advanced = new advanced_dialog(theLogger, this);
821 advanced->show();
822}
823
824void MainWindow::on_actionStart_Logger_triggered()
825{
826 if (this->theLogger->start_logging())
827 {
828 ui->actionStart_Logger->setEnabled(false);
829 ui->actionStop_Logger->setEnabled(true);
830 ui->actionRefresh->setEnabled(true);
831 system_message->addMessage("Logger started");
832 }
833 else
834 {
835 system_message->addMessage("Unable to start: maybe logger port is conflicting with another running process?\nOnly one logger can be executed on the same network.", MESSAGE_LEVEL_ERROR);
836 }
837}
838
839void MainWindow::on_actionStop_Logger_triggered()
840{
841 if (this->theLogger->stop_logging())
842 {
843 ui->actionStart_Logger->setEnabled(true);
844 ui->actionStop_Logger->setEnabled(false);
845 ui->actionRefresh->setEnabled(false);
846 system_message->addMessage("Logger stopped");
847 }
848 else
849 {
850 system_message->addMessage("Unable to stop: logger is not currently running",MESSAGE_LEVEL_ERROR);
851 }
852}
853
854void MainWindow::on_actionRefresh_triggered()
855{
856 system_message->addMessage("Searching for yarprun ports");
857 std::list<std::string> ports;
858 theLogger->discover(ports);
859 updateMain();
860 theLogger->connect(ports);
861 char text [100];
862 sprintf (text,"found %zd ports, logger running", ports.size());
863 system_message->addMessage(text);
864}
865
866void MainWindow::resetMainWindowHeaders()
867{
868 model_yarprunports->setHorizontalHeaderItem(0, new QStandardItem("ip"));
869 model_yarprunports->setHorizontalHeaderItem(1, new QStandardItem("process"));
870 model_yarprunports->setHorizontalHeaderItem(2, new QStandardItem("last heard"));
871 model_yarprunports->setHorizontalHeaderItem(3, new QStandardItem("log size"));
872 model_yarprunports->setHorizontalHeaderItem(4, new QStandardItem("errors"));
873 model_yarprunports->setHorizontalHeaderItem(5, new QStandardItem("warnings"));
874 ui->yarprunTreeView->setColumnWidth(0, 100);
875 ui->yarprunTreeView->setColumnWidth(1, 200);
876 ui->yarprunTreeView->setColumnWidth(2, 150);
877 ui->yarprunTreeView->setColumnWidth(3, 80);
878 ui->yarprunTreeView->setColumnWidth(4, 60);
879 ui->yarprunTreeView->setColumnWidth(5, 60);
880}
881
882void MainWindow::on_actionClear_triggered()
883{
884 if (theLogger->clear())
885 {
886 if (model_yarprunports)
887 {
888 model_yarprunports->clear();
889 resetMainWindowHeaders();
890 }
891 if (ui->logtabs) {
892 ui->logtabs->clear();
893 }
894
895 system_message->addMessage("Log cleared");
896 }
897}
898
899void MainWindow::on_actionClear_current_log_triggered()
900{
901 QModelIndex pre_index = ui->yarprunTreeView->selectionModel()->currentIndex();
902 QModelIndex index = proxyModel->mapToSource(pre_index);
903 int model_row=index.row();
904 if (model_row==-1)
905 {
906 system_message->addMessage("Invalid log selected",MESSAGE_LEVEL_ERROR);
907 return;
908 }
909 on_clearLogTab(model_row);
910}
911
912void MainWindow::on_actionExport_current_log_to_text_file_triggered()
913{
914 QModelIndex pre_index = ui->yarprunTreeView->selectionModel()->currentIndex();
915 QModelIndex index = proxyModel->mapToSource(pre_index);
916 int model_row=index.row();
917 if (model_row==-1)
918 {
919 system_message->addMessage("Invalid log selected",MESSAGE_LEVEL_ERROR);
920 return;
921 }
922 on_saveLogTab(model_row);
923}
924
925void MainWindow::on_actionDisable_current_log_triggered()
926{
927 QModelIndex pre_index = ui->yarprunTreeView->selectionModel()->currentIndex();
928 QModelIndex index = proxyModel->mapToSource(pre_index);
929 int model_row=index.row();
930 if (model_row==-1)
931 {
932 system_message->addMessage("Invalid log selected",MESSAGE_LEVEL_ERROR);
933 return;
934 }
935 on_enableLogTab(model_row);
936}
937
938void MainWindow::on_actionReset_current_log_error_warning_counters_triggered()
939{
940 QModelIndex pre_index = ui->yarprunTreeView->selectionModel()->currentIndex();
941 QModelIndex index = proxyModel->mapToSource(pre_index);
942 int model_row=index.row();
943 if (model_row==-1)
944 {
945 system_message->addMessage("Invalid log selected",MESSAGE_LEVEL_ERROR);
946 return;
947 }
948 on_resetCountersLogTab(model_row);
949}
950
951void MainWindow::dragEnterEvent(QDragEnterEvent *e)
952{
953 if (e->mimeData()->hasUrls()) {
954 e->acceptProposedAction();
955 }
956}
957
958void MainWindow::dropEvent(QDropEvent *e)
959{
960 const QUrl url = e->mimeData()->urls().first();
961
962 QString fileName = url.toLocalFile();
963
964 on_actionStop_Logger_triggered();
965 on_actionClear_triggered();
966
967 if (theLogger->load_all_logs_from_file(fileName.toStdString())) {
968 system_message->addMessage(QString("Log loaded from file: ") + fileName);
969 } else {
970 system_message->addMessage(QString("Unable to load file: ") + fileName, MESSAGE_LEVEL_ERROR);
971 }
972}
int SIGNAL(int pid, int signum)
static constexpr int LOGLEVEL_COLUMN
Definition logmodel.h:54
void displayGrid(bool enabled)
Definition logtab.cpp:317
void displayPid(bool enabled)
Definition logtab.cpp:287
void displayLocalTimestamp(bool enabled)
Definition logtab.cpp:211
void displaySystemTime(bool enabled)
Definition logtab.cpp:217
void displayExternalTime(bool enabled)
Definition logtab.cpp:229
void displayLine(bool enabled)
Definition logtab.cpp:251
void displayYarprunTimestamp(bool enabled)
Definition logtab.cpp:205
void displayFunction(bool enabled)
Definition logtab.cpp:257
void displayLogLevel(bool enabled)
Definition logtab.cpp:236
LogSortFilterProxyModel * proxyModelButtons
Definition logtab.h:74
void displayId(bool enabled)
Definition logtab.cpp:305
void displayHostname(bool enabled)
Definition logtab.cpp:266
void displayColors(bool enabled)
Definition logtab.cpp:311
void displayFilename(bool enabled)
Definition logtab.cpp:242
LogSortFilterProxyModel * proxyModelSearch
Definition logtab.h:75
void displayCmd(bool enabled)
Definition logtab.cpp:272
void displayArgs(bool enabled)
Definition logtab.cpp:278
void displayThreadId(bool enabled)
Definition logtab.cpp:293
void clearLogModel()
Definition logtab.cpp:170
void displayNetworkTime(bool enabled)
Definition logtab.cpp:223
void displayComponent(bool enabled)
Definition logtab.cpp:299
MainWindow class.
Definition display.h:22
MainWindow(const yarp::os::ResourceFinder &rf, yarp::dev::IBattery *ibat, QWidget *parent=0, double refresh_period=10.0)
Definition display.cpp:186
void addMessage(QString text, int level=0)
Helper class for finding config files and other external resources.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
static ResourceFinder & getResourceFinderSingleton()
Access a ResourceFinder singleton whose lifetime will match that of the YARP library.
A single value (typically within a Bottle).
Definition Value.h:43
void set_log_list_max_size(bool enabled, int new_size)
void connect(const std::list< std::string > &ports)
bool get_log_enable_by_port_complete(std::string port)
void clear_messages_by_port_complete(std::string port)
void set_log_lines_max_size(bool enabled, int new_size)
void discover(std::list< std::string > &ports)
bool load_all_logs_from_file(std::string filename)
bool save_all_logs_to_file(std::string filename)
bool export_log_to_text_file(std::string filename, std::string portname)
void get_infos(std::list< LogEntryInfo > &infos)
void set_log_enable_by_port_complete(std::string port, bool enable)
@ MESSAGE_LEVEL_ERROR
Definition aboutdlg.h:11