status_property.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, 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 <QApplication>
31 #include <QColor>
32 #include <QPalette>
33 
35 
37 #include <rviz/load_resource.h>
38 
39 namespace rviz
40 {
41 QColor StatusProperty::status_colors_[3] = {QColor(), QColor(192, 128, 0), QColor(192, 32, 32)};
42 QString StatusProperty::status_words_[3] = {"Ok", "Warn", "Error"};
43 
44 StatusProperty::StatusProperty(const QString& name, const QString& text, Level level, Property* parent)
45  : Property(name, text, text, parent), level_(level)
46 {
47  setShouldBeSaved(false);
48  status_icons_[0] = loadPixmap("package://rviz/icons/ok.png");
49  status_icons_[1] = loadPixmap("package://rviz/icons/warning.png");
50  status_icons_[2] = loadPixmap("package://rviz/icons/error.png");
51 
52  if (!status_colors_[0].isValid()) // initialize default text color once
53  status_colors_[0] = QApplication::palette().color(QPalette::Text);
54 }
55 
56 bool StatusProperty::setValue(const QVariant& new_value)
57 {
58  setDescription(new_value.toString());
59  return Property::setValue(new_value);
60 }
61 
62 QVariant StatusProperty::getViewData(int column, int role) const
63 {
64  if ((getViewFlags(column) & Qt::ItemIsEnabled) && column == 0 && role == Qt::ForegroundRole)
65  {
66  return statusColor(level_);
67  }
68  if (column == 0 && role == Qt::DecorationRole)
69  {
70  return statusIcon(level_);
71  }
72  return Property::getViewData(column, role);
73 }
74 
75 Qt::ItemFlags StatusProperty::getViewFlags(int column) const
76 {
77  return Property::getViewFlags(column);
78 }
79 
80 // static function
82 {
83  return status_colors_[(int)level];
84 }
85 
86 // static function
88 {
89  return status_icons_[level];
90 }
91 
94 // static function
96 {
97  return status_words_[(int)level];
98 }
99 
100 
102 {
103  if (level_ != level)
104  {
105  level_ = level;
106  if (model_)
107  model_->emitDataChanged(this);
108  }
109 }
110 
111 } // end namespace rviz
rviz::Property::getViewData
virtual QVariant getViewData(int column, int role) const
Return data appropriate for the given column (0 or 1) and role for this Property.
Definition: property.cpp:241
rviz::StatusProperty::Level
Level
Definition: status_property.h:42
status_property.h
rviz::StatusProperty::status_words_
static QString status_words_[3]
Definition: status_property.h:83
rviz::StatusProperty::StatusProperty
StatusProperty(const QString &name, const QString &text, Level level, Property *parent)
Definition: status_property.cpp:44
rviz::loadPixmap
QPixmap loadPixmap(const QString &url, bool fill_cache)
Definition: load_resource.cpp:65
rviz::StatusProperty::setValue
bool setValue(const QVariant &new_value) override
Set the status text. Overridden from Property.
Definition: status_property.cpp:56
rviz::Property
A single element of a property tree, with a name, value, description, and possibly children.
Definition: property.h:100
rviz::StatusProperty::statusColor
static QColor statusColor(Level level)
Return the color appropriate for the given status level.
Definition: status_property.cpp:81
rviz::Property::setShouldBeSaved
void setShouldBeSaved(bool save)
If save is false, neither the property nor its children will get saved. If true (the default),...
Definition: property.h:449
rviz::PropertyTreeModel::emitDataChanged
void emitDataChanged(Property *property, bool emit_config_changed=true)
Definition: property_tree_model.cpp:294
rviz::StatusProperty::level_
Level level_
Definition: status_property.h:79
rviz::Property::setValue
virtual bool setValue(const QVariant &new_value)
Set the new value for this property. Returns true if the new value is different from the old value,...
Definition: property.cpp:134
rviz
Definition: add_display_dialog.cpp:54
rviz::StatusProperty::getViewData
QVariant getViewData(int column, int role) const override
Return data appropriate for the given column (0 or 1) and role for this StatusProperty.
Definition: status_property.cpp:62
rviz::Property::model_
PropertyTreeModel * model_
Pointer to the PropertyTreeModel managing this property tree.
Definition: property.h:560
rviz::StatusProperty::status_icons_
QIcon status_icons_[3]
Definition: status_property.h:84
property_tree_model.h
rviz::Property::setDescription
virtual void setDescription(const QString &description)
Set the description.
Definition: property.cpp:169
rviz::Property::getViewFlags
virtual Qt::ItemFlags getViewFlags(int column) const
Return item flags appropriate for the given column (0 or 1) for this Property.
Definition: property.cpp:290
rviz::StatusProperty::setLevel
virtual void setLevel(Level level)
Definition: status_property.cpp:101
rviz::StatusProperty::status_colors_
static QColor status_colors_[3]
Definition: status_property.h:82
load_resource.h
rviz::StatusProperty::statusWord
static QString statusWord(Level level)
Return the word appropriate for the given status level: "Ok", "Warn", or "Error".
Definition: status_property.cpp:95
rviz::StatusProperty::getViewFlags
Qt::ItemFlags getViewFlags(int column) const override
Return item flags appropriate for the given column (0 or 1) for this StatusProperty.
Definition: status_property.cpp:75
rviz::StatusProperty::statusIcon
QIcon statusIcon(Level level) const
Definition: status_property.cpp:87


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Fri Dec 13 2024 03:31:03