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
virtual void setLevel(Level level)
PropertyTreeModel * model_
Pointer to the PropertyTreeModel managing this property tree.
Definition: property.h:499
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
A single element of a property tree, with a name, value, description, and possibly children...
Definition: property.h:100
bool setValue(const QVariant &new_value) override
Set the status text. Overridden from Property.
QIcon statusIcon(Level level) const
virtual void setDescription(const QString &description)
Set the description.
Definition: property.cpp:169
QVariant getViewData(int column, int role) const override
Return data appropriate for the given column (0 or 1) and role for this StatusProperty.
static QString status_words_[3]
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
virtual Qt::ItemFlags getViewFlags(int column) const
Return item flags appropriate for the given column (0 or 1) for this Property.
Definition: property.cpp:289
static QColor statusColor(Level level)
Return the color appropriate for the given status level.
void setShouldBeSaved(bool save)
If save is true and getReadOnly() is false, shouldBeSaved will return true; otherwise false...
Definition: property.h:388
static QString statusWord(Level level)
Return the word appropriate for the given status level: "Ok", "Warn", or "Error". ...
void emitDataChanged(Property *property)
static QColor status_colors_[3]
StatusProperty(const QString &name, const QString &text, Level level, Property *parent)
QPixmap loadPixmap(QString url, bool fill_cache)
Qt::ItemFlags getViewFlags(int column) const override
Return item flags appropriate for the given column (0 or 1) for this StatusProperty.


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