3 #include <QProgressDialog>
7 #include "cetlib/filepath_maker.h"
8 #include "fhiclcpp/ParameterSet.h"
9 #include "fhiclcpp/make_ParameterSet.h"
11 #include "mfextensions/Binaries/mvdlg.hh"
13 #if GCC_VERSION >= 701000 || defined(__clang__)
14 #pragma GCC diagnostic push
15 #pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
18 #define TRACE_NAME "MessageViewer"
21 #if GCC_VERSION >= 701000 || defined(__clang__)
22 #pragma GCC diagnostic pop
29 static void process_fname(std::string& fname) {
30 size_t sub_start = fname.find(
"${");
31 size_t sub_end = fname.find(
"}");
33 const size_t npos = std::string::npos;
35 if ((sub_start == npos && sub_end != npos) || (sub_start != npos && sub_end == npos) || (sub_start > sub_end)) {
36 throw std::runtime_error(
"Unrecognized configuration file. Use default configuration instead.");
39 if (sub_start == npos)
return;
41 std::string env = std::string(getenv(fname.substr(sub_start + 2, sub_end - sub_start - 2).c_str()));
42 fname.replace(sub_start, sub_end - sub_start + 1, env);
47 static fhicl::ParameterSet readConf(std::string
const& fname) {
48 if (fname.empty())
return fhicl::ParameterSet();
50 std::string filename = fname;
51 process_fname(filename);
53 std::string env(
"FHICL_FILE_PATH=");
55 if (filename[0] ==
'/') {
61 char* mfe_path = getenv(
"MFEXTENSIONS_DIR");
62 if (mfe_path) env.append(
":").append(mfe_path).append(
"/config");
64 putenv((
char*)env.c_str());
68 cet::filepath_lookup policy(
"FHICL_FILE_PATH");
71 fhicl::ParameterSet pset;
72 fhicl::make_ParameterSet(filename, policy, pset);
92 sup_menu(new QMenu(this)),
93 thr_menu(new QMenu(this)),
94 receivers_(readConf(conf).get<fhicl::ParameterSet>(
"receivers", fhicl::ParameterSet())) {
101 fhicl::ParameterSet pset = readConf(conf);
107 btnSuppression->setMenu(sup_menu);
108 btnThrottling->setMenu(thr_menu);
111 connect(btnPause, SIGNAL(clicked()),
this, SLOT(
pause()));
112 connect(btnScrollToBottom, SIGNAL(clicked()),
this, SLOT(scrollToBottom()));
113 connect(btnExit, SIGNAL(clicked()),
this, SLOT(
exit()));
114 connect(btnClear, SIGNAL(clicked()),
this, SLOT(
clear()));
116 connect(btnRMode, SIGNAL(clicked()),
this, SLOT(renderMode()));
117 connect(btnDisplayMode, SIGNAL(clicked()),
this, SLOT(
shortMode()));
119 connect(btnSearch, SIGNAL(clicked()),
this, SLOT(searchMsg()));
120 connect(btnSearchClear, SIGNAL(clicked()),
this, SLOT(searchClear()));
122 connect(btnFilter, SIGNAL(clicked()),
this, SLOT(setFilter()));
124 connect(btnError, SIGNAL(clicked()),
this, SLOT(setSevError()));
125 connect(btnWarning, SIGNAL(clicked()),
this, SLOT(setSevWarning()));
126 connect(btnInfo, SIGNAL(clicked()),
this, SLOT(setSevInfo()));
127 connect(btnDebug, SIGNAL(clicked()),
this, SLOT(setSevDebug()));
129 connect(sup_menu, SIGNAL(triggered(QAction*)),
this, SLOT(setSuppression(QAction*)));
131 connect(thr_menu, SIGNAL(triggered(QAction*)),
this, SLOT(setThrottling(QAction*)));
133 connect(vsSeverity, SIGNAL(valueChanged(
int)),
this, SLOT(
changeSeverity(
int)));
135 connect(&receivers_, SIGNAL(newMessage(
qt_mf_msg const&)),
this, SLOT(onNewMsg(
qt_mf_msg const&)));
137 connect(tabWidget, SIGNAL(currentChanged(
int)),
this, SLOT(tabWidgetCurrentChanged(
int)));
138 connect(tabWidget, SIGNAL(tabCloseRequested(
int)),
this, SLOT(tabCloseRequested(
int)));
139 MsgFilterDisplay allMessages;
140 allMessages.txtDisplay = txtMessages;
141 allMessages.nDisplayMsgs = 0;
142 allMessages.nDisplayedDeletedMsgs = 0;
143 allMessages.sevThresh = SINFO;
144 msgFilters_.push_back(allMessages);
147 QTabBar* tabBar = tabWidget->findChild<QTabBar*>();
148 tabBar->setTabButton(0, QTabBar::RightSide, 0);
149 tabBar->setTabButton(0, QTabBar::LeftSide, 0);
152 btnRMode->setChecked(
true);
154 btnRMode->setChecked(
false);
156 btnRMode->setEnabled(
false);
160 QTextDocument* doc =
new QTextDocument(txtMessages);
161 txtMessages->setDocument(doc);
166 msgViewerDlg::~msgViewerDlg() {
171 static void str_to_suppress(std::vector<std::string>
const& vs, std::vector<suppress>& s, QMenu* menu) {
175 act = menu->addAction(
"None");
176 act->setEnabled(
false);
180 s.reserve(vs.size());
182 for (
size_t i = 0; i < vs.size(); ++i) {
184 act = menu->addAction(QString(vs[i].c_str()));
185 act->setCheckable(
true);
186 act->setChecked(
true);
187 QVariant v = qVariantFromValue((
void*)&s[i]);
192 static void pset_to_throttle(std::vector<fhicl::ParameterSet>
const& ps, std::vector<throttle>& t, QMenu* menu) {
196 act = menu->addAction(
"None");
197 act->setEnabled(
false);
201 t.reserve(ps.size());
203 for (
size_t i = 0; i < ps.size(); ++i) {
204 std::string name = ps[i].get<std::string>(
"name");
205 t.push_back(
throttle(name, ps[i].get<int>(
"limit", -1), ps[i].get<long>(
"timespan", -1)));
206 act = menu->addAction(QString(name.c_str()));
207 act->setCheckable(
true);
208 act->setChecked(
true);
209 QVariant v = qVariantFromValue((
void*)&t[i]);
214 void msgViewerDlg::parseConf(fhicl::ParameterSet
const& conf) {
215 fhicl::ParameterSet nulp;
219 fhicl::ParameterSet sup = conf.get<fhicl::ParameterSet>(
"suppress", nulp);
221 auto sup_host = sup.get<std::vector<std::string>>(
"hosts", std::vector<std::string>());
222 auto sup_app = sup.get<std::vector<std::string>>(
"applications", std::vector<std::string>());
223 auto sup_cat = sup.get<std::vector<std::string>>(
"categories", std::vector<std::string>());
225 str_to_suppress(sup_host, e_sup_host, sup_menu);
226 sup_menu->addSeparator();
228 str_to_suppress(sup_app, e_sup_app, sup_menu);
229 sup_menu->addSeparator();
231 str_to_suppress(sup_cat, e_sup_cat, sup_menu);
234 auto thr = conf.get<fhicl::ParameterSet>(
"throttle", nulp);
236 auto thr_host = thr.get<std::vector<fhicl::ParameterSet>>(
"hosts", std::vector<fhicl::ParameterSet>());
237 auto thr_app = thr.get<std::vector<fhicl::ParameterSet>>(
"applications", std::vector<fhicl::ParameterSet>());
238 auto thr_cat = thr.get<std::vector<fhicl::ParameterSet>>(
"categories", std::vector<fhicl::ParameterSet>());
240 pset_to_throttle(thr_host, e_thr_host, thr_menu);
241 thr_menu->addSeparator();
243 pset_to_throttle(thr_app, e_thr_app, thr_menu);
244 thr_menu->addSeparator();
246 pset_to_throttle(thr_cat, e_thr_cat, thr_menu);
248 maxMsgs = conf.get<
size_t>(
"max_message_buffer_size", 100000);
249 maxDeletedMsgs = conf.get<
size_t>(
"max_displayed_deleted_messages", 100000);
252 bool msgViewerDlg::msg_throttled(
qt_mf_msg const& mfmsg) {
257 for (
size_t i = 0; i < e_sup_host.size(); ++i)
258 if (e_sup_host[i].match(mfmsg.
host().toStdString()))
return true;
260 for (
size_t i = 0; i < e_sup_app.size(); ++i)
261 if (e_sup_app[i].match(mfmsg.
app().toStdString()))
return true;
263 for (
size_t i = 0; i < e_sup_cat.size(); ++i)
264 if (e_sup_cat[i].match(mfmsg.
cat().toStdString()))
return true;
272 for (
size_t i = 0; i < e_thr_host.size(); ++i)
273 if (e_thr_host[i].reach_limit(mfmsg.
host().toStdString(), mfmsg.
time()))
return true;
275 for (
size_t i = 0; i < e_thr_app.size(); ++i)
276 if (e_thr_app[i].reach_limit(mfmsg.
app().toStdString(), mfmsg.
time()))
return true;
278 for (
size_t i = 0; i < e_thr_cat.size(); ++i)
279 if (e_thr_cat[i].reach_limit(mfmsg.
cat().toStdString(), mfmsg.
time()))
return true;
286 void msgViewerDlg::writeSettings() {
287 QSettings settings(
"ARTDAQ",
"MsgViewer");
289 settings.beginGroup(
"MainWindow");
290 settings.setValue(
"size", size());
291 settings.setValue(
"pos", pos());
295 void msgViewerDlg::readSettings() {
296 QSettings settings(
"ARTDAQ",
"MsgViewer");
298 settings.beginGroup(
"MainWindow");
299 QPoint pos = settings.value(
"pos", QPoint(100, 100)).toPoint();
300 QSize size = settings.value(
"size", QSize(660, 760)).toSize();
306 void msgViewerDlg::onNewMsg(
qt_mf_msg const& mfmsg) {
312 lcdMsgs->display(nMsgs);
315 if (msg_throttled(mfmsg)) {
316 lcdSuppressionCount->display(nSupMsgs);
317 lcdThrottlingCount->display(nThrMsgs);
322 msg_pool_.emplace_back(mfmsg);
324 while (maxMsgs > 0 && msg_pool_.size() > maxMsgs) {
325 removeMsg(msg_pool_.begin());
328 msgs_t::iterator it = --msg_pool_.end();
331 unsigned int flag = update_index(it);
334 if (flag & LIST_APP) updateList<msg_iters_map_t>(lwApplication, app_msgs_);
335 if (flag & LIST_CAT) updateList<msg_iters_map_t>(lwCategory, cat_msgs_);
336 if (flag & LIST_HOST) updateList<msg_iters_map_t>(lwHost, host_msgs_);
338 for (
size_t d = 0; d < msgFilters_.size(); ++d) {
340 msgFilters_[d].hostFilter.contains(it->host(), Qt::CaseInsensitive) || msgFilters_[d].hostFilter.size() == 0;
342 msgFilters_[d].appFilter.contains(it->app(), Qt::CaseInsensitive) || msgFilters_[d].appFilter.size() == 0;
344 msgFilters_[d].catFilter.contains(it->cat(), Qt::CaseInsensitive) || msgFilters_[d].catFilter.size() == 0;
347 if (hostMatch && appMatch && catMatch) {
348 msgFilters_[d].msgs.push_back(it);
354 void msgViewerDlg::removeMsg(msgs_t::iterator it) {
355 std::unique_lock<std::mutex> lk(updating_mutex_);
356 QString
const& app = it->app();
357 QString
const& cat = it->cat();
358 QString
const& host = it->host();
360 auto catIter = std::find(cat_msgs_[cat].begin(), cat_msgs_[cat].end(), it);
361 auto hostIter = std::find(host_msgs_[host].begin(), host_msgs_[host].end(), it);
362 auto appIter = std::find(app_msgs_[app].begin(), app_msgs_[app].end(), it);
363 if (catIter != cat_msgs_[cat].end()) cat_msgs_[cat].erase(catIter);
364 if (hostIter != host_msgs_[host].end()) host_msgs_[host].erase(hostIter);
365 if (appIter != app_msgs_[app].end()) app_msgs_[app].erase(appIter);
367 if (app_msgs_[app].size() == 0) {
368 app_msgs_.erase(app);
369 updateList<msg_iters_map_t>(lwApplication, app_msgs_);
371 if (cat_msgs_[cat].size() == 0) {
372 cat_msgs_.erase(cat);
373 updateList<msg_iters_map_t>(lwCategory, cat_msgs_);
375 if (host_msgs_[host].size() == 0) {
376 host_msgs_.erase(host);
377 updateList<msg_iters_map_t>(lwHost, host_msgs_);
380 for (
size_t d = 0; d < msgFilters_.size(); ++d) {
382 msgFilters_[d].hostFilter.contains(it->host(), Qt::CaseInsensitive) || msgFilters_[d].hostFilter.size() == 0;
384 msgFilters_[d].appFilter.contains(it->app(), Qt::CaseInsensitive) || msgFilters_[d].appFilter.size() == 0;
386 msgFilters_[d].catFilter.contains(it->cat(), Qt::CaseInsensitive) || msgFilters_[d].catFilter.size() == 0;
387 bool sevMatch = it->sev() >= msgFilters_[d].sevThresh;
390 if (hostMatch && appMatch && catMatch) {
391 auto filterIt = std::find(msgFilters_[d].msgs.begin(), msgFilters_[d].msgs.end(), it);
392 if (filterIt != msgFilters_[d].msgs.end()) msgFilters_[d].msgs.erase(filterIt);
395 if (++msgFilters_[d].nDisplayedDeletedMsgs > static_cast<int>(maxDeletedMsgs) && maxDeletedMsgs > 0) {
401 if ((
int)d == tabWidget->currentIndex()) {
402 lcdDisplayedDeleted->display(msgFilters_[d].nDisplayedDeletedMsgs);
408 lcdDeletedCount->display(nDeleted);
411 unsigned int msgViewerDlg::update_index(msgs_t::iterator it) {
412 std::unique_lock<std::mutex> lk(updating_mutex_);
413 QString
const& app = it->app();
414 QString
const& cat = it->cat();
415 QString
const& host = it->host();
417 unsigned int update = 0x0;
419 if (cat_msgs_.find(cat) == cat_msgs_.end()) update |= LIST_CAT;
420 if (host_msgs_.find(host) == host_msgs_.end()) update |= LIST_HOST;
421 if (app_msgs_.find(app) == app_msgs_.end()) update |= LIST_APP;
423 cat_msgs_[cat].push_back(it);
424 host_msgs_[host].push_back(it);
425 app_msgs_[app].push_back(it);
430 void msgViewerDlg::displayMsg(msgs_t::const_iterator it,
int display) {
431 if (it->sev() < msgFilters_[display].sevThresh)
return;
432 std::unique_lock<std::mutex> lk(updating_mutex_);
434 msgFilters_[display].nDisplayMsgs++;
435 if (display == tabWidget->currentIndex()) {
436 lcdDisplayedMsgs->display(msgFilters_[display].nDisplayMsgs);
439 auto txt = it->text(shortMode_);
440 UpdateTextAreaDisplay(txt, msgFilters_[display].txtDisplay);
443 void msgViewerDlg::displayMsg(
int display) {
444 std::unique_lock<std::mutex> lk(updating_mutex_);
446 msgFilters_[display].txtDisplay->clear();
447 msgFilters_[display].nDisplayMsgs = 0;
448 msgFilters_[display].nDisplayedDeletedMsgs = 0;
450 msg_iters_t::const_iterator it;
452 n = msgFilters_[display].msgs.size();
453 it = msgFilters_[display].msgs.begin();
454 QProgressDialog progress(
"Fetching data...",
"Cancel", 0, n / 1000,
this);
456 progress.setWindowModality(Qt::WindowModal);
457 progress.setMinimumDuration(2000);
462 for (; it != msgFilters_[display].msgs.end(); ++it, ++i) {
463 if (it->get()->sev() >= msgFilters_[display].sevThresh) {
464 txt += it->get()->text(shortMode_);
465 ++msgFilters_[display].nDisplayMsgs;
471 progress.setValue(prog);
474 UpdateTextAreaDisplay(txt, msgFilters_[display].txtDisplay);
479 if (progress.wasCanceled())
break;
482 if (display == tabWidget->currentIndex()) {
483 lcdDisplayedMsgs->display(msgFilters_[display].nDisplayMsgs);
486 UpdateTextAreaDisplay(txt, msgFilters_[display].txtDisplay);
490 void msgViewerDlg::UpdateTextAreaDisplay(QString text, QTextEdit* widget) {
491 const QTextCursor old_cursor = widget->textCursor();
492 const int old_scrollbar_value = widget->verticalScrollBar()->value();
493 const bool is_scrolled_down =
494 old_scrollbar_value >= widget->verticalScrollBar()->maximum() * 0.95;
496 if (!paused && !is_scrolled_down) {
501 widget->append(text);
503 if (old_cursor.hasSelection() || paused) {
505 widget->setTextCursor(old_cursor);
506 widget->verticalScrollBar()->setValue(old_scrollbar_value);
509 widget->moveCursor(QTextCursor::End);
510 widget->verticalScrollBar()->setValue(widget->verticalScrollBar()->maximum());
511 widget->horizontalScrollBar()->setValue(0);
515 void msgViewerDlg::scrollToBottom() {
516 int display = tabWidget->currentIndex();
517 msgFilters_[display].txtDisplay->moveCursor(QTextCursor::End);
518 msgFilters_[display].txtDisplay->verticalScrollBar()->setValue(
519 msgFilters_[display].txtDisplay->verticalScrollBar()->maximum());
520 msgFilters_[display].txtDisplay->horizontalScrollBar()->setValue(0);
523 void msgViewerDlg::updateDisplays() {
524 for (
size_t ii = 0; ii < msgFilters_.size(); ++ii) {
529 template <
typename M>
530 bool msgViewerDlg::updateList(QListWidget* lw, M
const& map) {
531 bool nonSelectedBefore = (lw->currentRow() == -1);
532 bool nonSelectedAfter =
true;
534 QString item = nonSelectedBefore ?
"" : lw->currentItem()->text();
538 typename M::const_iterator it = map.begin();
540 while (it != map.end()) {
541 lw->addItem(it->first);
542 if (!nonSelectedBefore && nonSelectedAfter) {
543 if (item == it->first) {
544 lw->setCurrentRow(row);
545 nonSelectedAfter =
false;
552 if (!nonSelectedBefore && nonSelectedAfter)
return true;
557 msg_iters_t msgViewerDlg::list_intersect(msg_iters_t
const& l1, msg_iters_t
const& l2) {
559 msg_iters_t::const_iterator it1 = l1.begin();
560 msg_iters_t::const_iterator it2 = l2.begin();
562 while (it1 != l1.end() && it2 != l2.end()) {
565 }
else if (*it2 < *it1) {
568 output.push_back(*it1);
574 TLOG(10) <<
"list_intersect: output list has " << output.size() <<
" entries";
578 std::string sev_to_string(sev_code_t s) {
592 void msgViewerDlg::setFilter() {
593 auto hostFilter = toQStringList(lwHost->selectedItems());
594 auto appFilter = toQStringList(lwApplication->selectedItems());
595 auto catFilter = toQStringList(lwCategory->selectedItems());
597 lwHost->setCurrentRow(-1, QItemSelectionModel::Clear);
598 lwApplication->setCurrentRow(-1, QItemSelectionModel::Clear);
599 lwCategory->setCurrentRow(-1, QItemSelectionModel::Clear);
601 if (hostFilter.isEmpty() && appFilter.isEmpty() && catFilter.isEmpty()) {
606 QString catFilterExpression =
"";
607 QString hostFilterExpression =
"";
608 QString appFilterExpression =
"";
611 for (
auto app = 0; app < appFilter.size(); ++app) {
612 msg_iters_map_t::const_iterator it = app_msgs_.find(appFilter[app]);
613 appFilterExpression += QString(first ?
"" :
" || ") + appFilter[app];
615 if (it != app_msgs_.end()) {
616 msg_iters_t temp(it->second);
617 TLOG(10) <<
"setFilter: app " << appFilter[app].toStdString() <<
" has " << temp.size() <<
" messages";
621 TLOG(10) <<
"setFilter: result contains %zu messages", result.size();
624 if (!hostFilter.isEmpty()) {
625 msg_iters_t hostResult;
626 for (
auto host = 0; host < hostFilter.size(); ++host) {
627 hostFilterExpression += QString(first ?
"" :
" || ") + hostFilter[host];
629 msg_iters_map_t::const_iterator it = host_msgs_.find(hostFilter[host]);
630 if (it != host_msgs_.end()) {
631 msg_iters_t temp(it->second);
632 TLOG(10) <<
"setFilter: host " << hostFilter[host].toStdString() <<
" has " << temp.size() <<
" messages";
633 hostResult.merge(temp);
636 if (result.empty()) {
639 result = list_intersect(result, hostResult);
641 TLOG(10) <<
"setFilter: result contains " << result.size() <<
" messages";
645 if (!catFilter.isEmpty()) {
646 msg_iters_t catResult;
647 for (
auto cat = 0; cat < catFilter.size(); ++cat) {
648 catFilterExpression += QString(first ?
"" :
" || ") + catFilter[cat];
650 msg_iters_map_t::const_iterator it = cat_msgs_.find(catFilter[cat]);
651 if (it != cat_msgs_.end()) {
652 msg_iters_t temp(it->second);
653 TLOG(10) <<
"setFilter: cat " << catFilter[cat].toStdString() <<
" has " << temp.size() <<
" messages";
654 catResult.merge(temp);
657 if (result.empty()) {
660 result = list_intersect(result, catResult);
662 TLOG(10) <<
"setFilter: result contains " << result.size() <<
" messages";
666 auto nFilterExpressions =
667 (appFilterExpression !=
"" ? 1 : 0) + (hostFilterExpression !=
"" ? 1 : 0) + (catFilterExpression !=
"" ? 1 : 0);
668 QString filterExpression =
"";
669 if (nFilterExpressions == 1) {
670 filterExpression = catFilterExpression + hostFilterExpression + appFilterExpression;
672 filterExpression =
"(" + (catFilterExpression !=
"" ? catFilterExpression +
") && (" :
"") + hostFilterExpression +
673 (hostFilterExpression !=
"" && appFilterExpression !=
"" ?
") && (" :
"") + appFilterExpression +
679 auto newTabTitle = QString(
"Filter ") + QString::number(++nFilters);
680 QWidget* newTab =
new QWidget();
682 QTextEdit* txtDisplay =
new QTextEdit(newTab);
683 QTextDocument* doc =
new QTextDocument(txtDisplay);
684 txtDisplay->setDocument(doc);
686 QVBoxLayout* layout =
new QVBoxLayout();
687 layout->addWidget(txtDisplay);
688 layout->setContentsMargins(0, 0, 0, 0);
689 newTab->setLayout(layout);
691 MsgFilterDisplay filteredMessages;
692 filteredMessages.msgs = result;
693 filteredMessages.hostFilter = hostFilter;
694 filteredMessages.appFilter = appFilter;
695 filteredMessages.catFilter = catFilter;
696 filteredMessages.txtDisplay = txtDisplay;
697 filteredMessages.nDisplayMsgs = result.size();
698 filteredMessages.nDisplayedDeletedMsgs = 0;
699 filteredMessages.sevThresh = SINFO;
700 msgFilters_.push_back(filteredMessages);
702 tabWidget->addTab(newTab, newTabTitle);
703 tabWidget->setTabToolTip(tabWidget->count() - 1, filterExpression);
704 tabWidget->setCurrentIndex(tabWidget->count() - 1);
706 displayMsg(msgFilters_.size() - 1);
712 btnPause->setText(
"Resume Scrolling");
716 btnPause->setText(
"Pause Scrolling");
725 QMessageBox::question(
this, tr(
"Message Viewer"), tr(
"Are you sure you want to clear all received messages?"),
726 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
727 std::unique_lock<std::mutex> lk(updating_mutex_);
729 case QMessageBox::Yes:
738 updateList<msg_iters_map_t>(lwApplication, app_msgs_);
739 updateList<msg_iters_map_t>(lwCategory, cat_msgs_);
740 updateList<msg_iters_map_t>(lwHost, host_msgs_);
741 for (
auto& display : msgFilters_) {
742 display.txtDisplay->clear();
743 display.msgs.clear();
744 display.nDisplayMsgs = 0;
745 display.nDisplayedDeletedMsgs = 0;
748 lcdMsgs->display(nMsgs);
749 lcdDisplayedMsgs->display(0);
751 case QMessageBox::No:
760 btnDisplayMode->setText(
"Long View");
763 btnDisplayMode->setText(
"Compact View");
769 auto display = tabWidget->currentIndex();
790 void msgViewerDlg::setSevError() {
791 auto display = tabWidget->currentIndex();
792 msgFilters_[display].sevThresh = SERROR;
793 btnError->setChecked(
true);
794 btnWarning->setChecked(
false);
795 btnInfo->setChecked(
false);
796 btnDebug->setChecked(
false);
797 vsSeverity->setValue(SERROR);
800 void msgViewerDlg::setSevWarning() {
801 auto display = tabWidget->currentIndex();
802 msgFilters_[display].sevThresh = SWARNING;
803 btnError->setChecked(
false);
804 btnWarning->setChecked(
true);
805 btnInfo->setChecked(
false);
806 btnDebug->setChecked(
false);
807 vsSeverity->setValue(SWARNING);
810 void msgViewerDlg::setSevInfo() {
811 auto display = tabWidget->currentIndex();
812 msgFilters_[display].sevThresh = SINFO;
813 btnError->setChecked(
false);
814 btnWarning->setChecked(
false);
815 btnInfo->setChecked(
true);
816 btnDebug->setChecked(
false);
817 vsSeverity->setValue(SINFO);
820 void msgViewerDlg::setSevDebug() {
821 auto display = tabWidget->currentIndex();
822 msgFilters_[display].sevThresh = SDEBUG;
823 btnError->setChecked(
false);
824 btnWarning->setChecked(
false);
825 btnInfo->setChecked(
false);
826 btnDebug->setChecked(
true);
827 vsSeverity->setValue(SDEBUG);
830 void msgViewerDlg::renderMode() {
831 simpleRender = !simpleRender;
834 btnRMode->setChecked(
true);
835 for (
auto display : msgFilters_) {
836 display.txtDisplay->setPlainText(display.txtDisplay->toPlainText());
839 btnRMode->setChecked(
false);
844 void msgViewerDlg::searchMsg() {
845 QString search = editSearch->text();
847 if (search.isEmpty())
return;
849 auto display = tabWidget->currentIndex();
850 if (search != searchStr) {
851 msgFilters_[display].txtDisplay->moveCursor(QTextCursor::Start);
852 if (!msgFilters_[display].txtDisplay->find(search)) {
853 msgFilters_[display].txtDisplay->moveCursor(QTextCursor::End);
858 if (!msgFilters_[display].txtDisplay->find(search)) {
859 msgFilters_[display].txtDisplay->moveCursor(QTextCursor::Start);
860 if (!msgFilters_[display].txtDisplay->find(search)) {
861 msgFilters_[display].txtDisplay->moveCursor(QTextCursor::End);
868 void msgViewerDlg::searchClear() {
869 auto display = tabWidget->currentIndex();
870 editSearch->setText(
"");
872 msgFilters_[display].txtDisplay->find(
"");
873 msgFilters_[display].txtDisplay->moveCursor(QTextCursor::End);
876 void msgViewerDlg::setSuppression(QAction* act) {
877 bool status = act->isChecked();
882 void msgViewerDlg::setThrottling(QAction* act) {
883 bool status = act->isChecked();
888 void msgViewerDlg::tabWidgetCurrentChanged(
int newTab) {
889 lcdDisplayedMsgs->display(msgFilters_[newTab].nDisplayMsgs);
891 lwHost->setCurrentRow(-1, QItemSelectionModel::Clear);
892 lwApplication->setCurrentRow(-1, QItemSelectionModel::Clear);
893 lwCategory->setCurrentRow(-1, QItemSelectionModel::Clear);
895 for (
auto host : msgFilters_[newTab].hostFilter) {
896 auto items = lwHost->findItems(host, Qt::MatchExactly);
897 if (items.size() > 0) {
898 items[0]->setSelected(
true);
901 for (
auto app : msgFilters_[newTab].appFilter) {
902 auto items = lwApplication->findItems(app, Qt::MatchExactly);
903 if (items.size() > 0) {
904 items[0]->setSelected(
true);
907 for (
auto cat : msgFilters_[newTab].catFilter) {
908 auto items = lwCategory->findItems(cat, Qt::MatchExactly);
909 if (items.size() > 0) {
910 items[0]->setSelected(
true);
914 switch (msgFilters_[newTab].sevThresh) {
930 void msgViewerDlg::tabCloseRequested(
int tabIndex) {
931 if (tabIndex == 0 || static_cast<size_t>(tabIndex) >= msgFilters_.size())
return;
933 auto widget = tabWidget->widget(tabIndex);
934 tabWidget->removeTab(tabIndex);
937 msgFilters_.erase(msgFilters_.begin() + tabIndex);
942 QStringList msgViewerDlg::toQStringList(QList<QListWidgetItem*> in) {
945 for (
auto i = 0; i < in.size(); ++i) {
946 out << in[i]->text();
QString const & app() const
Get the application of the message
void use(bool flag)
Enable or disable this throttle
timeval time() const
Get the message timestamp
void exit()
Exit the program.
void start()
Start all receivers
Qt wrapper around MessageFacility message
Suppress messages based on a regular expression
void clear()
Clear the message buffer.
QString const & host() const
Get the host from which the message came
void use(bool flag)
Set whether the suppression is active
Throttle messages based on name and time limits. Separate from MessageFacility limiting.
void stop()
Stop all receivers
void pause()
Pause message receiving.
void changeSeverity(int sev)
Change the severity threshold.
QString const & cat() const
Get the category of the message
void shortMode()
Switch to/from Short message mode.
void closeEvent(QCloseEvent *event)
Perform actions on window close.
msgViewerDlg(std::string const &conf, QDialog *parent=0)
Message Viewer Dialog Constructor.