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 <QColor>
31 
33 
35 #include "rviz/load_resource.h"
36 
37 namespace rviz
38 {
39 
40 QColor StatusProperty::status_colors_[3] = { QColor(), QColor( 192, 128, 0 ), QColor( 192, 32, 32 ) };
41 QString StatusProperty::status_words_[3] = { "Ok", "Warn", "Error" };
42 
43 StatusProperty::StatusProperty( const QString& name, const QString& text, Level level, Property* parent )
44  : Property( name, text, text, parent )
45  , 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 
53 bool StatusProperty::setValue( const QVariant& new_value )
54 {
55  setDescription( new_value.toString() );
56  return Property::setValue( new_value );
57 }
58 
59 QVariant StatusProperty::getViewData( int column, int role ) const
60 {
61  if ( (getViewFlags(column) & Qt::ItemIsEnabled) && column == 0 && role == Qt::ForegroundRole )
62  {
63  return statusColor( level_ );
64  }
65  if( column == 0 && role == Qt::DecorationRole )
66  {
67  return statusIcon( level_ );
68  }
69  return Property::getViewData( column, role );
70 }
71 
72 Qt::ItemFlags StatusProperty::getViewFlags( int column ) const
73 {
74  return Property::getViewFlags( column );
75 }
76 
77 // static function
79 {
80  return status_colors_[ (int) level ];
81 }
82 
83 // static function
84 QIcon StatusProperty::statusIcon( Level level ) const
85 {
86  return status_icons_[ level ];
87 }
88 
91 // static function
93 {
94  return status_words_[ (int) level ];
95 }
96 
97 
99 {
100  if( level_ != level )
101  {
102  level_ = level;
103  if( model_ )
104  model_->emitDataChanged( this );
105  }
106 }
107 
108 } // end namespace rviz
virtual void setLevel(Level level)
PropertyTreeModel * model_
Pointer to the PropertyTreeModel managing this property tree.
Definition: property.h:454
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:130
A single element of a property tree, with a name, value, description, and possibly children...
Definition: property.h:100
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:236
virtual void setDescription(const QString &description)
Set the description.
Definition: property.cpp:164
virtual Qt::ItemFlags getViewFlags(int column) const
Return item flags appropriate for the given column (0 or 1) for this StatusProperty.
static QString status_words_[3]
static QColor statusColor(Level level)
Return the color appropriate for the given status level.
QIcon statusIcon(Level level) const
void setShouldBeSaved(bool save)
If save is true and getReadOnly() is false, shouldBeSaved will return true; otherwise false...
Definition: property.h:361
virtual QVariant getViewData(int column, int role) const
Return data appropriate for the given column (0 or 1) and role for this StatusProperty.
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)
virtual bool setValue(const QVariant &new_value)
Set the status text. Overridden from Property.
virtual Qt::ItemFlags getViewFlags(int column) const
Return item flags appropriate for the given column (0 or 1) for this Property.
Definition: property.cpp:285


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat Apr 27 2019 02:33:42