select_service_dialog.h
Go to the documentation of this file.
1 // *****************************************************************************
2 //
3 // Copyright (c) 2015, Southwest Research Institute® (SwRI®)
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of Southwest Research Institute® (SwRI®) nor the
14 // names of its contributors may be used to endorse or promote products
15 // derived from this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL Southwest Research Institute® BE LIABLE
21 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27 // DAMAGE.
28 //
29 // *****************************************************************************
30 
31 #ifndef MAPVIZ_SELECT_SERVICE_DIALOG_H
32 #define MAPVIZ_SELECT_SERVICE_DIALOG_H
33 
34 #include <set>
35 #include <vector>
36 
37 #include <boost/shared_ptr.hpp>
38 
39 #include <QDialog>
40 #include <QMetaType>
41 #include <QThread>
42 
43 #include <ros/ros.h>
44 
45 QT_BEGIN_NAMESPACE
46 class QLineEdit;
47 class QListWidget;
48 class QPushButton;
49 QT_END_NAMESPACE
50 
51 // This is ugly, but necessary in order to be able to send a std::vector<std::string>
52 // via a queued signal/slot connection.
53 typedef std::vector<std::string> ServiceStringVector;
55 
56 namespace mapviz
57 {
62  class ServiceUpdaterThread : public QThread
63  {
64  Q_OBJECT
65  public:
66  ServiceUpdaterThread(ros::NodeHandle& nh, const std::string& allowed_datatype, QObject* parent) :
67  QThread(parent),
68  nh_(nh),
69  allowed_datatype_(allowed_datatype)
70  {
71  }
72  void run();
73 
74  Q_SIGNALS:
75  void servicesFetched(ServiceStringVector services);
76  void fetchingFailed(const QString error_msg);
77 
78  private:
80  const std::string& allowed_datatype_;
81  };
82 
87  class SelectServiceDialog : public QDialog
88  {
89  Q_OBJECT
90  public:
100  static std::string selectService(const std::string& datatype, QWidget* parent=0);
101 
109  SelectServiceDialog(const std::string& datatype = "", QWidget* parent=0);
110  virtual ~SelectServiceDialog();
111 
118  void setDatatypeFilter(const std::string& datatype);
119 
125  std::string selectedService() const;
126 
127  private Q_SLOTS:
132  void fetchServices();
146  void displayUpdateError(const QString);
147 
148  private:
149  std::vector<std::string> filterServices();
150  void timerEvent(QTimerEvent *);
151  void closeEvent(QCloseEvent *);
152 
154 
155  std::string allowed_datatype_;
156  std::vector<std::string> displayed_services_;
157  std::vector<std::string> known_services_;
158 
160 
161  QPushButton *cancel_button_;
162  QListWidget *list_widget_;
163  QLineEdit *name_filter_;
164  QPushButton *ok_button_;
166  };
167 }
168 
169 #endif //MAPVIZ_SELECT_SERVICE_DIALOG_H
mapviz::SelectServiceDialog::selectService
static std::string selectService(const std::string &datatype, QWidget *parent=0)
Definition: select_service_dialog.cpp:98
mapviz::SelectServiceDialog::ok_button_
QPushButton * ok_button_
Definition: select_service_dialog.h:164
mapviz::SelectServiceDialog::worker_thread_
boost::shared_ptr< ServiceUpdaterThread > worker_thread_
Definition: select_service_dialog.h:165
mapviz::SelectServiceDialog
Definition: select_service_dialog.h:87
mapviz
Definition: color_button.h:36
mapviz::SelectServiceDialog::setDatatypeFilter
void setDatatypeFilter(const std::string &datatype)
Definition: select_service_dialog.cpp:276
boost::shared_ptr
mapviz::SelectServiceDialog::SelectServiceDialog
SelectServiceDialog(const std::string &datatype="", QWidget *parent=0)
Definition: select_service_dialog.cpp:109
mapviz::ServiceUpdaterThread::nh_
ros::NodeHandle & nh_
Definition: select_service_dialog.h:79
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(ServiceStringVector)
ros.h
mapviz::SelectServiceDialog::timerEvent
void timerEvent(QTimerEvent *)
Definition: select_service_dialog.cpp:296
mapviz::ServiceUpdaterThread::run
void run()
Definition: select_service_dialog.cpp:48
mapviz::ServiceUpdaterThread::servicesFetched
void servicesFetched(ServiceStringVector services)
mapviz::SelectServiceDialog::updateKnownServices
void updateKnownServices(ServiceStringVector services)
Definition: select_service_dialog.cpp:188
mapviz::SelectServiceDialog::list_widget_
QListWidget * list_widget_
Definition: select_service_dialog.h:162
mapviz::ServiceUpdaterThread::ServiceUpdaterThread
ServiceUpdaterThread(ros::NodeHandle &nh, const std::string &allowed_datatype, QObject *parent)
Definition: select_service_dialog.h:66
mapviz::SelectServiceDialog::nh_
ros::NodeHandle nh_
Definition: select_service_dialog.h:153
mapviz::SelectServiceDialog::selectedService
std::string selectedService() const
Definition: select_service_dialog.cpp:282
mapviz::ServiceUpdaterThread::fetchingFailed
void fetchingFailed(const QString error_msg)
mapviz::SelectServiceDialog::filterServices
std::vector< std::string > filterServices()
Definition: select_service_dialog.cpp:203
mapviz::SelectServiceDialog::name_filter_
QLineEdit * name_filter_
Definition: select_service_dialog.h:163
mapviz::ServiceUpdaterThread
Definition: select_service_dialog.h:62
mapviz::SelectServiceDialog::allowed_datatype_
std::string allowed_datatype_
Definition: select_service_dialog.h:155
mapviz::SelectServiceDialog::closeEvent
void closeEvent(QCloseEvent *)
Definition: select_service_dialog.cpp:303
mapviz::ServiceUpdaterThread::allowed_datatype_
const std::string & allowed_datatype_
Definition: select_service_dialog.h:80
mapviz::SelectServiceDialog::displayUpdateError
void displayUpdateError(const QString)
Definition: select_service_dialog.cpp:194
mapviz::SelectServiceDialog::updateDisplayedServices
void updateDisplayedServices()
Definition: select_service_dialog.cpp:220
mapviz::SelectServiceDialog::fetchServices
void fetchServices()
Definition: select_service_dialog.cpp:169
mapviz::SelectServiceDialog::~SelectServiceDialog
virtual ~SelectServiceDialog()
Definition: select_service_dialog.cpp:152
datatype
const char * datatype()
mapviz::SelectServiceDialog::fetch_services_timer_id_
int fetch_services_timer_id_
Definition: select_service_dialog.h:159
mapviz::SelectServiceDialog::displayed_services_
std::vector< std::string > displayed_services_
Definition: select_service_dialog.h:156
mapviz::SelectServiceDialog::cancel_button_
QPushButton * cancel_button_
Definition: select_service_dialog.h:161
ServiceStringVector
QT_END_NAMESPACE typedef std::vector< std::string > ServiceStringVector
Definition: select_service_dialog.h:48
ros::NodeHandle
mapviz::SelectServiceDialog::known_services_
std::vector< std::string > known_services_
Definition: select_service_dialog.h:157


mapviz
Author(s): Marc Alban
autogenerated on Wed Jan 17 2024 03:27:46