35 #include <roscpp/GetLoggers.h>
36 #include <roscpp/SetLoggerLevel.h>
38 #include <QMessageBox>
39 #include <QTextStream>
49 QContextMenuEvent* context_event;
52 switch (event->type()) {
53 case QEvent::ContextMenu:
54 context_event =
static_cast<QContextMenuEvent*
>(event);
57 list =
static_cast<QListView*
>(obj);
65 return QObject::eventFilter(obj, event);
71 QModelIndexList index_list = list->selectionModel()->selectedIndexes();
72 if (index_list.isEmpty()) {
90 ROS_WARN(
"Timed out while waiting for service at %s.", service_name.c_str());
91 QMessageBox::warning(list,
"Error Getting Loggers",
"Timed out waiting for get_loggers service.");
95 roscpp::GetLoggers srv;
98 QAction* label = menu.addAction(QString::fromStdString(
node_name_ +
" loggers:"));
99 label->setDisabled(
true);
105 Q_FOREACH(
const roscpp::Logger& logger, srv.response.loggers) {
106 ROS_DEBUG(
"Log level for %s is %s", logger.name.c_str(), logger.level.c_str());
108 QString logger_name = QString::fromStdString(logger.name);
110 menu.addMenu(
createMenu(logger_name, QString::fromStdString(logger.level)));
114 std::string error =
"Service call to get_loggers failed.";
116 QMessageBox::warning(list,
"Service Call Failed", error.c_str());
119 menu.exec(event->globalPos());
126 QString action_label;
127 QTextStream stream(&action_label);
128 stream << logger_name;
129 if (!current_level.isEmpty()) {
130 stream <<
" (" << current_level.toUpper() <<
")";
133 QMenu* nodeMenu =
new QMenu(action_label);
135 const QString levels[] = {
"DEBUG",
"INFO",
"WARN",
"ERROR",
"FATAL"};
137 for (
int i = 0; i < 5; i++) {
138 QAction* action = nodeMenu->addAction(levels[i],
this, SLOT(
logLevelClicked()));
139 action->setData(logger_name);
147 QAction* action =
static_cast<QAction*
>(sender());
149 std::string logger = action->data().toString().toStdString();
150 std::string level = action->text().toStdString();
151 ROS_DEBUG(
"Setting log level for %s/%s to %s",
node_name_.c_str(), logger.c_str(), level.c_str());
157 ROS_WARN(
"Timed out while waiting for service at %s.", service_name.c_str());
158 QMessageBox::warning(NULL,
"Error Getting Loggers",
"Timed out waiting for set_logger_level service.");
162 std::vector<std::string> target_loggers;
167 target_loggers.push_back(logger);
170 Q_FOREACH (
const std::string& logger_name, target_loggers) {
171 roscpp::SetLoggerLevel srv;
172 srv.request.level = level;
173 srv.request.logger = logger_name;
178 ROS_WARN(
"Service call to %s failed.", service_name.c_str());
179 QMessageBox::warning(NULL,
"Error Setting Log Level",
"Failed to set logger level.");