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 PropertyTreeWithHelp::PropertyTreeWithHelp(QWidget* parent) : QSplitter(parent)
40 {
41  setOrientation(Qt::Vertical);
42 
44 
45  help_ = new QTextBrowser;
46  help_->setOpenExternalLinks(true);
47 
48  addWidget(property_tree_);
49  addWidget(help_);
50 
51  setStretchFactor(0, 1000);
52  setCollapsible(0, false);
53 
54  QList<int> _sizes;
55  _sizes.push_back(1000);
56  _sizes.push_back(1);
57  setSizes(_sizes);
58 
59  connect(property_tree_, SIGNAL(currentPropertyChanged(const Property*)), this,
60  SLOT(showHelpForProperty(const Property*)));
61 }
62 
64 {
65  if (property)
66  {
67  QString body_text = property->getDescription();
68  QString heading = property->getName();
69  body_text.replace("\n", "<br>");
70  QString html = "<html><body><strong>" + heading + "</strong><br>" + body_text + "</body></html>";
71  help_->setHtml(html);
72  }
73  else
74  {
75  help_->setHtml("");
76  }
77 }
78 
80 {
81  property_tree_->save(config.mapMakeChild("Property Tree Widget"));
82 
83  QList<int> _sizes = sizes();
84  config.mapSetValue("Tree Height", _sizes.at(0));
85  config.mapSetValue("Help Height", _sizes.at(1));
86 }
87 
89 {
90  property_tree_->load(config.mapGetChild("Property Tree Widget"));
91 
92  int tree_height;
93  int help_height;
94  if (config.mapGetInt("Tree Height", &tree_height) && config.mapGetInt("Help Height", &help_height))
95  {
96  QList<int> _sizes;
97  _sizes.push_back(tree_height);
98  _sizes.push_back(help_height);
99  setSizes(_sizes);
100  }
101 }
102 
103 } // end namespace rviz
A single element of a property tree, with a name, value, description, and possibly children...
Definition: property.h:100
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:212
void mapSetValue(const QString &key, QVariant value)
Set a named child to the given value.
Definition: config.cpp:196
void save(Config config) const
Write state to the given Config.
Configuration data storage class.
Definition: config.h:124
PropertyTreeWidget * property_tree_
PropertyTreeWithHelp(QWidget *parent=nullptr)
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:201
void load(const Config &config)
Read state from the given Config.
bool mapGetInt(const QString &key, int *value_out) const
Convenience function for looking up a named integer.
Definition: config.cpp:240
void save(Config config) const
Write state to the given Config.


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat May 27 2023 02:06:25