scriptable_monitor_rqt.cpp
Go to the documentation of this file.
00001 /*
00002  * scriptable_monitor_rqt.cpp
00003  *
00004  *  Created on: Oct 31, 2013
00005  *      Author: blackpc
00006  */
00007 
00008 #include <scriptable_monitor_rqt/scriptable_monitor_rqt.h>
00009 
00010 namespace scriptable_monitor {
00011 
00012 ScriptableMonitorRqt::ScriptableMonitorRqt()
00013         : rqt_gui_cpp::Plugin(), widget_(NULL), _nodeHandle(NULL), _newScriptDialog(NULL)
00014 {
00015 
00016 }
00017 
00018 ScriptableMonitorRqt::~ScriptableMonitorRqt()
00019 {
00020         delete _nodeHandle;
00021 }
00022 
00023 void ScriptableMonitorRqt::initPlugin(
00024                 qt_gui_cpp::PluginContext& context)
00025 {
00026 
00027         QStringList argv = context.argv();
00028 
00029         _nodeHandle = new ros::NodeHandle("~");
00030         _getScriptsClient = _nodeHandle->serviceClient<scriptable_monitor::GetScripts>("/scriptable_monitor/get_scripts", true);
00031         _addScriptClient = _nodeHandle->serviceClient<scriptable_monitor::AddScript>("/scriptable_monitor/add_script", true);
00032 
00033         _newScriptDialog = new QDialog(0, 0);
00034         widget_ = new QWidget();
00035 
00036         _scriptsUi.setupUi(widget_);
00037         _newScriptUi.setupUi(_newScriptDialog);
00038 
00039         context.addWidget(widget_);
00040 
00041         connectEvents();
00042         refreshScripts();
00043 }
00044 
00045 void ScriptableMonitorRqt::shutdownPlugin()
00046 {
00047 
00048 }
00049 
00050 void ScriptableMonitorRqt::saveSettings(
00051                 qt_gui_cpp::Settings& plugin_settings,
00052                 qt_gui_cpp::Settings& instance_settings) const
00053 {
00054 
00055 }
00056 
00057 void ScriptableMonitorRqt::connectEvents()
00058 {
00059         // Main window
00060         connect(_scriptsUi.refreshButton, SIGNAL(clicked()), this, SLOT(refreshClicked()));
00061         connect(_scriptsUi.addScriptButton, SIGNAL(clicked()), this, SLOT(newScriptWindowClicked()));
00062 
00063         // Add script window
00064         connect(_newScriptUi.addButton, SIGNAL(clicked()), this, SLOT(addScriptClicked()));
00065 }
00066 
00067 void ScriptableMonitorRqt::restoreSettings(
00068                 const qt_gui_cpp::Settings& plugin_settings,
00069                 const qt_gui_cpp::Settings& instance_settings)
00070 {
00071 
00072 }
00073 
00074 void ScriptableMonitorRqt::refreshScripts() {
00075 
00076         scriptable_monitor::GetScripts getScriptsService;
00077         _getScriptsClient.call(getScriptsService);
00078         vector<Script>& scripts = getScriptsService.response.scripts;
00079 
00080         if (_scriptsUi.scriptsTableView->model() != NULL)
00081                 _scriptsUi.scriptsTableView->model()->deleteLater();
00082 
00083         QStandardItemModel* model = new QStandardItemModel(scripts.size(), 3);
00084 
00085         int row = 0;
00086         foreach(Script script, scripts) {
00087 
00088                 model->setItem(row, 0, new QStandardItem(QString(script.name.c_str())));
00089                 model->setItem(row, 1, new QStandardItem(QString("%1s").arg(script.interval)));
00090                 model->setItem(row, 2, new QStandardItem(QString("")));
00091                 row++;
00092         }
00093 
00094         model->setHeaderData(0, Qt::Horizontal, "Script name");
00095         model->setHeaderData(1, Qt::Horizontal, "Interval");
00096         model->setHeaderData(2, Qt::Horizontal, "Last execution");
00097 
00098         _scriptsUi.scriptsTableView->header()->setDefaultSectionSize(200);
00099         _scriptsUi.scriptsTableView->setModel(model);
00100 }
00101 
00102 }
00103 
00104 PLUGINLIB_EXPORT_CLASS(scriptable_monitor::ScriptableMonitorRqt, rqt_gui_cpp::Plugin)


scriptable_monitor_rqt
Author(s):
autogenerated on Wed Aug 26 2015 16:21:35