00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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 }
00044
00045 void StatusList::setName( const QString& name )
00046 {
00047 name_prefix_ = name;
00048 updateLabel();
00049 }
00050
00051 void StatusList::setStatus( Level level, const QString& name, const QString& text )
00052 {
00053 QHash<QString, StatusProperty*>::iterator child_iter = status_children_.find( name );
00054 StatusProperty* child;
00055 if( child_iter == status_children_.end() )
00056 {
00057 child = new StatusProperty( name, text, level, this );
00058 status_children_.insert( name, child );
00059 }
00060 else
00061 {
00062 child = child_iter.value();
00063 child->setLevel( level );
00064 child->setValue( text );
00065 }
00066 if( level > level_ )
00067 {
00068 setLevel( level );
00069 }
00070 else if( level < level_ )
00071 {
00072 updateLevel();
00073 }
00074 }
00075
00076 void StatusList::deleteStatus( const QString& name )
00077 {
00078 StatusProperty* child = status_children_.take( name );
00079 if( child )
00080 {
00081 delete child;
00082 updateLevel();
00083 }
00084 }
00085
00086 void StatusList::clear()
00087 {
00088 int num_rows = numChildren();
00089 if( num_rows > 0 )
00090 {
00091 QHash<QString, StatusProperty*>::iterator iter;
00092 for( iter = status_children_.begin(); iter != status_children_.end(); iter++ )
00093 {
00094 delete iter.value();
00095 }
00096 status_children_.clear();
00097 }
00098 setLevel( Ok );
00099 }
00100
00101 void StatusList::updateLevel()
00102 {
00103 Level new_level = Ok;
00104
00105 QHash<QString, StatusProperty*>::iterator iter;
00106 for( iter = status_children_.begin(); iter != status_children_.end(); iter++ )
00107 {
00108 Level child_level = iter.value()->getLevel();
00109 if( child_level > new_level )
00110 {
00111 new_level = child_level;
00112 }
00113 }
00114 setLevel( new_level );
00115 }
00116
00117 void StatusList::setLevel( Level new_level )
00118 {
00119 StatusProperty::setLevel( new_level );
00120 updateLabel();
00121 }
00122
00123 void StatusList::updateLabel()
00124 {
00125 StatusProperty::setName( name_prefix_ + ": " + statusWord( getLevel() ));
00126 }
00127
00128 }