property_manager.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
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 the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       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 THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #ifndef RVIZ_PROPERTY_MANAGER_H
00031 #define RVIZ_PROPERTY_MANAGER_H
00032 
00033 #include <QObject>
00034 
00035 #include "forwards.h"
00036 #include "ros/assert.h"
00037 
00038 #include <boost/bind.hpp>
00039 #include <boost/thread/mutex.hpp>
00040 
00041 #include <map>
00042 #include <set>
00043 
00044 namespace rviz
00045 {
00046 
00047 class Config;
00048 class PropertyTreeWidget;
00049 class PropertyBase;
00050 class CategoryProperty;
00051 
00057 class PropertyManager: public QObject
00058 {
00059 Q_OBJECT
00060 public:
00065   PropertyManager();
00069   ~PropertyManager();
00070 
00081   template<typename T, typename G, typename S>
00082   boost::weak_ptr<T> createProperty(const std::string& name, const std::string& prefix, const G& getter, const S& setter, const CategoryPropertyWPtr& parent, void* user_data = NULL)
00083   {
00084     boost::shared_ptr<T> property(new T( name, prefix, parent, getter, setter ));
00085     addProperty(property, name, prefix, user_data);
00086 
00087     return boost::weak_ptr<T>(property);
00088   }
00089 
00090   void addProperty(const PropertyBasePtr& property, const std::string& name, const std::string& prefix, void* user_data);
00091 
00098   CategoryPropertyWPtr createCategory(const std::string& name, const std::string& prefix, const CategoryPropertyWPtr& parent = CategoryPropertyWPtr(), void* user_data = NULL);
00099 
00100   CategoryPropertyWPtr createCheckboxCategory(const std::string& label, const std::string& name, const std::string& prefix, const boost::function<bool(void)>& getter,
00101                                               const boost::function<void(bool)>& setter, const CategoryPropertyWPtr& parent = CategoryPropertyWPtr(), void* user_data = NULL);
00102 
00103   StatusPropertyWPtr createStatus(const std::string& name, const std::string& prefix, const CategoryPropertyWPtr& parent = CategoryPropertyWPtr(), void* user_data = NULL);
00104 
00105   bool hasProperty(const std::string& name, const std::string& prefix) { return properties_.find(std::make_pair(prefix, name)) != properties_.end(); }
00106 
00111   void deleteProperty( const PropertyBasePtr& property );
00117   void deleteProperty( const std::string& name, const std::string& prefix );
00122   void deleteByUserData( void* user_data );
00127   void deleteChildren( const PropertyBasePtr& property );
00128 
00133   void propertySet( const PropertyBasePtr& property );
00134 
00139   void save(const boost::shared_ptr<Config>& config);
00144   void load(const boost::shared_ptr<Config>& config, const StatusCallback& cb = StatusCallback());
00145 
00150   PropertyTreeWidget* getPropertyTreeWidget() { return grid_; }
00151 
00155   void changePrefix(const std::string& old_prefix, const std::string& new_prefix);
00156 
00157   void setPropertyTreeWidget(PropertyTreeWidget* grid);
00158 
00159   void setDefaultUserData(void* data) { default_user_data_ = data; }
00160 
00161   void refreshAll();
00162   void clear();
00163   void update();
00164 
00166   void emitConfigChanged();
00167 
00168 Q_SIGNALS:
00170   void configChanged();
00171 
00172 protected:
00173   PropertyTreeWidget* grid_;        //< The property grid associated with our properties
00174 
00175   typedef std::map< std::pair<std::string, std::string>, PropertyBasePtr > M_Property;
00176   M_Property properties_;       //< The properties, mapped by name + prefix
00177 
00178   boost::mutex changed_mutex_;
00179   typedef std::set<PropertyBaseWPtr> S_PropertyBaseWPtr;
00180   S_PropertyBaseWPtr changed_properties_;
00181 
00182   void* default_user_data_;
00183 
00184   boost::shared_ptr<Config> config_;
00185 };
00186 
00187 } // namespace rviz
00188 
00189 #endif


rviz
Author(s): Dave Hershberger, Josh Faust
autogenerated on Mon Jan 6 2014 11:54:32