property_widget_item.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011, 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 #include <float.h>
00031 
00032 #include "rviz/properties/property_widget_item.h"
00033 #include "rviz/properties/property_tree_widget.h"
00034 #include "rviz/properties/property.h"
00035 #include "rviz/properties/topic_info_variant.h"
00036 
00037 namespace rviz
00038 {
00039 
00040 PropertyWidgetItem::PropertyWidgetItem( PropertyBase* property,
00041                                         const std::string& label,
00042                                         bool editable,
00043                                         bool needs_check_box,
00044                                         bool first_column_spans )
00045   : max_( FLT_MAX )
00046   , min_( -FLT_MAX )
00047   , property_( property )
00048   , first_column_spans_( first_column_spans )
00049 {
00050   Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
00051 
00052   if( needs_check_box && editable )
00053   {
00054     flags |= Qt::ItemIsUserCheckable;
00055   }
00056 
00057   // "ItemIsEditable" for a checkbox means ability to edit a text
00058   // label adjacent to it.  Not what we want.
00059   if( !needs_check_box && editable )
00060   {
00061     flags |= Qt::ItemIsEditable;
00062   }
00063 
00064   setFlags( flags );
00065 
00066   setLeftText( label ); // Set the label in the left column.
00067 
00068   // Setting flags, name, etc (above) must come before adding this as
00069   // a child of parent with addToParent().  Otherwise those
00070   // flag-settings etc trigger the itemChanged() signal and the empty
00071   // data from this item gets written to the Property.
00072 }
00073 
00074 void PropertyWidgetItem::addToParent( PropertyWidgetItem* parent_item )
00075 {
00076   if( parent_item )
00077   {
00078     parent_item->addChild( this );
00079   }
00080   else
00081   {
00082     CategoryPropertyPtr parent = property_->getParent().lock();
00083     if( parent )
00084     {
00085       parent->getWidgetItem()->addChild( this );
00086     }
00087     else
00088     {
00089       property_->getPropertyTreeWidget()->addTopLevelItem( this );
00090     }
00091   }
00092 
00093   // Column-spanning must be done after adding this item to a parent.
00094   // It does not seem to trigger itemChanged().
00095   setFirstColumnSpanned( first_column_spans_ );
00096 }
00097 
00098 void PropertyWidgetItem::setLeftText( const std::string& text )
00099 {
00100   bool ign = property_->getPropertyTreeWidget()->setIgnoreChanges( true );
00101 
00102   setText( 0, QString::fromStdString( text ));
00103 
00104   property_->getPropertyTreeWidget()->setIgnoreChanges( ign );
00105 }
00106 
00107 void PropertyWidgetItem::setRightText( const QString& text )
00108 {
00109   bool ign = property_->getPropertyTreeWidget()->setIgnoreChanges( true );
00110 
00111   setText( 1, text );
00112 
00113   property_->getPropertyTreeWidget()->setIgnoreChanges( ign );
00114 }
00115 
00116 void PropertyWidgetItem::setRightText( const std::string& text )
00117 {
00118   setRightText( QString::fromStdString( text ));
00119 }
00120 
00121 void PropertyWidgetItem::setUserData( QVariant _data )
00122 {
00123   bool ign = property_->getPropertyTreeWidget()->setIgnoreChanges( true );
00124 
00125   setData( 1, Qt::UserRole, _data );
00126 
00127   if( _data.canConvert<ros::master::TopicInfo>() )
00128   {
00129     ros::master::TopicInfo topic = _data.value<ros::master::TopicInfo>();
00130     setText( 1, QString::fromStdString( topic.name ));
00131   }
00132   else
00133   {
00134     setText( 1, _data.toString() );
00135   }
00136 
00137   property_->getPropertyTreeWidget()->setIgnoreChanges( ign );
00138 }
00139 
00140 QVariant PropertyWidgetItem::userData() const
00141 {
00142   return data( 1, Qt::UserRole );
00143 }
00144 
00145 } // end namespace rviz
00146 


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