select_service_dialog.h
Go to the documentation of this file.
00001 // *****************************************************************************
00002 //
00003 // Copyright (c) 2015, Southwest Research Institute® (SwRI®)
00004 // All rights reserved.
00005 //
00006 // Redistribution and use in source and binary forms, with or without
00007 // modification, are permitted provided that the following conditions are met:
00008 //     * Redistributions of source code must retain the above copyright
00009 //       notice, this list of conditions and the following disclaimer.
00010 //     * Redistributions in binary form must reproduce the above copyright
00011 //       notice, this list of conditions and the following disclaimer in the
00012 //       documentation and/or other materials provided with the distribution.
00013 //     * Neither the name of Southwest Research Institute® (SwRI®) nor the
00014 //       names of its contributors may be used to endorse or promote products
00015 //       derived from this software without specific prior written permission.
00016 //
00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020 // ARE DISCLAIMED. IN NO EVENT SHALL Southwest Research Institute® BE LIABLE 
00021 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
00022 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
00023 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
00024 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
00025 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
00026 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00027 // DAMAGE.
00028 //
00029 // *****************************************************************************
00030 
00031 #ifndef MAPVIZ_SELECT_SERVICE_DIALOG_H
00032 #define MAPVIZ_SELECT_SERVICE_DIALOG_H
00033 
00034 #include <set>
00035 #include <vector>
00036 
00037 #include <boost/shared_ptr.hpp>
00038 
00039 #include <QDialog>
00040 #include <QMetaType>
00041 #include <QThread>
00042 
00043 #include <ros/ros.h>
00044 
00045 QT_BEGIN_NAMESPACE
00046 class QLineEdit;
00047 class QListWidget;
00048 class QPushButton;
00049 QT_END_NAMESPACE
00050 
00051 // This is ugly, but necessary in order to be able to send a std::vector<std::string>
00052 // via a queued signal/slot connection.
00053 typedef std::vector<std::string> ServiceStringVector;
00054 Q_DECLARE_METATYPE(ServiceStringVector);
00055 
00056 namespace mapviz
00057 {
00062   class ServiceUpdaterThread : public QThread
00063   {
00064     Q_OBJECT
00065   public:
00066     ServiceUpdaterThread(ros::NodeHandle& nh, const std::string& allowed_datatype, QObject* parent) :
00067       QThread(parent),
00068       nh_(nh),
00069       allowed_datatype_(allowed_datatype)
00070     {
00071     }
00072     void run();
00073 
00074   Q_SIGNALS:
00075     void servicesFetched(ServiceStringVector services);
00076     void fetchingFailed(const QString error_msg);
00077 
00078   private:
00079     ros::NodeHandle& nh_;
00080     const std::string& allowed_datatype_;
00081   };
00082 
00087   class SelectServiceDialog : public QDialog
00088   {
00089     Q_OBJECT
00090   public:
00100     static std::string selectService(const std::string& datatype, QWidget* parent=0);
00101 
00109     SelectServiceDialog(const std::string& datatype = "", QWidget* parent=0);
00110     virtual ~SelectServiceDialog();
00111 
00118     void setDatatypeFilter(const std::string& datatype);
00119 
00125     std::string selectedService() const;
00126 
00127   private Q_SLOTS:
00132     void fetchServices();
00137     void updateDisplayedServices();
00141     void updateKnownServices(ServiceStringVector services);
00146     void displayUpdateError(const QString);
00147 
00148   private:
00149     std::vector<std::string> filterServices();
00150     void timerEvent(QTimerEvent *);
00151     void closeEvent(QCloseEvent *);
00152 
00153     ros::NodeHandle nh_;
00154 
00155     std::string allowed_datatype_;
00156     std::vector<std::string> displayed_services_;
00157     std::vector<std::string> known_services_;
00158 
00159     int fetch_services_timer_id_;
00160 
00161     QPushButton *cancel_button_;
00162     QListWidget *list_widget_;
00163     QLineEdit *name_filter_;
00164     QPushButton *ok_button_;
00165 
00166     boost::shared_ptr<ServiceUpdaterThread> worker_thread_;
00167   };
00168 }
00169 
00170 #endif //MAPVIZ_SELECT_SERVICE_DIALOG_H


mapviz
Author(s): Marc Alban
autogenerated on Thu Jun 6 2019 18:50:58