status_list.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2012, 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 <stdio.h>
00031 
00032 #include "rviz/properties/property_tree_model.h"
00033 
00034 #include "rviz/properties/status_list.h"
00035 
00036 namespace rviz
00037 {
00038 
00039 StatusList::StatusList( const QString& name, Property* parent )
00040   : StatusProperty( "", "", Ok, parent )
00041 { 
00042   setName( name );
00043   setShouldBeSaved( false );
00044 }
00045 
00046 void StatusList::setName( const QString& name )
00047 {
00048   name_prefix_ = name;
00049   updateLabel();
00050 }
00051 
00052 void StatusList::setStatus( Level level, const QString& name, const QString& text )
00053 {
00054   QHash<QString, StatusProperty*>::iterator child_iter = status_children_.find( name );
00055   StatusProperty* child;
00056   if( child_iter == status_children_.end() )
00057   {
00058     child = new StatusProperty( name, text, level, this );
00059     status_children_.insert( name, child );
00060   }
00061   else
00062   {
00063     child = child_iter.value();
00064     child->setLevel( level );
00065     child->setValue( text );
00066   }
00067   if( level > level_ )
00068   {
00069     setLevel( level );
00070   }
00071   else if( level < level_ )
00072   {
00073     updateLevel();
00074   }
00075 }
00076 
00077 void StatusList::deleteStatus( const QString& name )
00078 {
00079   StatusProperty* child = status_children_.take( name );
00080   if( child )
00081   {
00082     delete child;
00083     updateLevel();
00084   }
00085 }
00086 
00087 void StatusList::clear()
00088 {
00089   int num_rows = numChildren();
00090   if( num_rows > 0 )
00091   {
00092     QList<StatusProperty*> to_be_deleted = status_children_.values();
00093 
00094     status_children_.clear();
00095 
00096     // It is important here to clear the status_children_ list before
00097     // deleting its contents.  On Macs the deletion can indirectly
00098     // trigger a call to setStatus(), and status_children_ should not
00099     // contain any pointers to deleted memory at that time.
00100     for( int i = 0; i < to_be_deleted.size(); i++ )
00101     {
00102       delete to_be_deleted[ i ];
00103     }
00104   }
00105   setLevel( Ok );
00106 }
00107 
00108 void StatusList::updateLevel()
00109 {
00110   Level new_level = Ok;
00111 
00112   QHash<QString, StatusProperty*>::iterator iter;
00113   for( iter = status_children_.begin(); iter != status_children_.end(); iter++ )
00114   {
00115     Level child_level = iter.value()->getLevel();
00116     if( child_level > new_level )
00117     {
00118       new_level = child_level;
00119     }
00120   }
00121   setLevel( new_level );
00122 }
00123 
00124 void StatusList::setLevel( Level new_level )
00125 {
00126   StatusProperty::setLevel( new_level );
00127   updateLabel();
00128 }
00129 
00130 void StatusList::updateLabel()
00131 {
00132   StatusProperty::setName( name_prefix_ + ": " + statusWord( getLevel() ));
00133 }
00134 
00135 } // end namespace rviz


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Tue Oct 3 2017 03:19:31