property_tree_with_help.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <QTextBrowser>
31 
34 
36 
37 namespace rviz
38 {
39 
41  : QSplitter( parent )
42 {
43  setOrientation( Qt::Vertical );
44 
46 
47  help_ = new QTextBrowser;
48  help_->setOpenExternalLinks( true );
49 
50  addWidget( property_tree_ );
51  addWidget( help_ );
52 
53  setStretchFactor( 0, 1000 );
54  setCollapsible( 0, false );
55 
56  QList<int> _sizes;
57  _sizes.push_back( 1000 );
58  _sizes.push_back( 1 );
59  setSizes( _sizes );
60 
61  connect( property_tree_, SIGNAL( currentPropertyChanged( const Property* )),
62  this, SLOT( showHelpForProperty( const Property* )));
63 }
64 
66 {
67  if( property )
68  {
69  QString body_text = property->getDescription();
70  QString heading = property->getName();
71  QString html = "<html><body bgcolor=\"#EFEBE7\"><strong>" + heading + "</strong><br>" + body_text + "</body></html>";
72  help_->setHtml( html );
73  }
74  else
75  {
76  help_->setHtml( "" );
77  }
78 }
79 
80 void PropertyTreeWithHelp::save( Config config ) const
81 {
82  property_tree_->save( config.mapMakeChild( "Property Tree Widget" ));
83 
84  QList<int> _sizes = sizes();
85  config.mapSetValue( "Tree Height", _sizes.at( 0 ));
86  config.mapSetValue( "Help Height", _sizes.at( 1 ));
87 }
88 
89 void PropertyTreeWithHelp::load( const Config& config )
90 {
91  property_tree_->load( config.mapGetChild( "Property Tree Widget" ));
92 
93  int tree_height;
94  int help_height;
95  if( config.mapGetInt( "Tree Height", &tree_height ) &&
96  config.mapGetInt( "Help Height", &help_height ))
97  {
98  QList<int> _sizes;
99  _sizes.push_back( tree_height );
100  _sizes.push_back( help_height );
101  setSizes( _sizes );
102  }
103 }
104 
105 } // end namespace rviz
A single element of a property tree, with a name, value, description, and possibly children...
Definition: property.h:100
void mapSetValue(const QString &key, QVariant value)
Set a named child to the given value.
Definition: config.cpp:185
Configuration data storage class.
Definition: config.h:125
PropertyTreeWidget * property_tree_
void save(Config config) const
Write state to the given Config.
void load(const Config &config)
Read state from the given Config.
void showHelpForProperty(const Property *property)
Config mapMakeChild(const QString &key)
Create a child node stored with the given key, and return the child.
Definition: config.cpp:190
void save(Config config) const
Write state to the given Config.
bool mapGetInt(const QString &key, int *value_out) const
Convenience function for looking up a named integer.
Definition: config.cpp:229
void load(const Config &config)
Read state from the given Config.
Config mapGetChild(const QString &key) const
If the referenced Node is a Map and it has a child with the given key, return a reference to the chil...
Definition: config.cpp:201


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Wed Aug 28 2019 04:01:51