libyui  3.3.3
YMultiProgressMeter.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YMultiProgressMeter.cc
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #define YUILogComponent "ui"
27 #include "YUILog.h"
28 
29 #include "YUISymbols.h"
30 #include "YMultiProgressMeter.h"
31 
32 
34 {
35  YMultiProgressMeterPrivate( YUIDimension dim,
36  const std::vector<float> & maxValues )
37  : dim( dim )
38  , maxValues( maxValues )
39  {
40  // Make currentValues as large as maxValues
41  // and initialize each element with 0
42  currentValues = std::vector<float>( maxValues.size(), 0.0 );
43  }
44 
45 
46  YUIDimension dim;
47  std::vector<float> maxValues;
48  std::vector<float> currentValues;
49 };
50 
51 
52 
53 
55  YUIDimension dim,
56  const std::vector<float> & maxValues )
57  : YWidget( parent )
58  , priv( new YMultiProgressMeterPrivate( dim, maxValues ) )
59 {
60  YUI_CHECK_NEW( priv );
61 
62  setDefaultStretchable( YD_HORIZ, dim == YD_HORIZ );
63  setDefaultStretchable( YD_VERT, dim == YD_VERT );
64 }
65 
66 
68 {
69  // NOP
70 }
71 
72 
73 YUIDimension
75 {
76  return priv->dim;
77 }
78 
79 
81 {
82  return priv->dim == YD_HORIZ;
83 }
84 
85 
87 {
88  return priv->dim == YD_VERT;
89 }
90 
91 
93 {
94  return (int) priv->maxValues.size();
95 }
96 
97 
98 float YMultiProgressMeter::maxValue( int segment ) const
99 {
100  YUI_CHECK_INDEX( segment, 0, (int) priv->maxValues.size() );
101 
102  return priv->maxValues[ segment ];
103 }
104 
105 
106 float YMultiProgressMeter::currentValue( int segment ) const
107 {
108  YUI_CHECK_INDEX( segment, 0, (int) priv->currentValues.size() );
109 
110  return priv->currentValues[ segment ];
111 }
112 
113 
114 void YMultiProgressMeter::setCurrentValue( int segment, float value )
115 {
116  YUI_CHECK_INDEX( segment, 0, (int) priv->currentValues.size() );
117 
118  if ( value < 0.0 ) // Allow -1 etc. as marker values
119  value = 0.0;
120 
121  if ( value > maxValue( segment ) ) // Don't complain (beware of rounding errors)
122  value = maxValue( segment );
123 
124  priv->currentValues[ segment ] = value;
125 }
126 
127 
128 void YMultiProgressMeter::setCurrentValues( const std::vector<float> & values )
129 {
130  for ( int i=0; i < (int) values.size(); i++ )
131  {
132  setCurrentValue( i, values[i] );
133  }
134 
135  doUpdate();
136 }
137 
138 
139 const YPropertySet &
141 {
142  static YPropertySet propSet;
143 
144  if ( propSet.isEmpty() )
145  {
146  /*
147  * @property list<integer> Values the current values for all segments
148  */
149  propSet.add( YProperty( YUIProperty_Values, YOtherProperty ) );
150  propSet.add( YWidget::propertySet() );
151  }
152 
153  return propSet;
154 }
155 
156 
157 bool
158 YMultiProgressMeter::setProperty( const std::string & propertyName, const YPropertyValue & val )
159 {
160  propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
161 
162  if ( propertyName == YUIProperty_Values ) return false; // need special processing
163  else
164  {
165  YWidget::setProperty( propertyName, val );
166  }
167 
168  return true; // success -- no special handling necessary
169 }
170 
171 
173 YMultiProgressMeter::getProperty( const std::string & propertyName )
174 {
175  propertySet().check( propertyName ); // throws exceptions if not found
176 
177  if ( propertyName == YUIProperty_Values ) return YPropertyValue( YOtherProperty );
178  else
179  {
180  return YWidget::getProperty( propertyName );
181  }
182 }
YPropertySet::add
void add(const YProperty &prop)
Add a property to this property set.
Definition: YProperty.cc:145
YWidget
Abstract base class of all UI widgets.
Definition: YWidget.h:54
YMultiProgressMeter::getProperty
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YMultiProgressMeter.cc:173
YMultiProgressMeterPrivate
Definition: YMultiProgressMeter.cc:33
YMultiProgressMeter::vertical
bool vertical() const
Return 'true' if the orientation is vertical.
Definition: YMultiProgressMeter.cc:86
YMultiProgressMeter::~YMultiProgressMeter
virtual ~YMultiProgressMeter()
Destructor.
Definition: YMultiProgressMeter.cc:67
YPropertySet
A set of properties to check names and types against.
Definition: YProperty.h:197
YPropertySet::isEmpty
bool isEmpty() const
Returns 'true' if this property set does not contain anything.
Definition: YProperty.h:263
YMultiProgressMeter::setProperty
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YMultiProgressMeter.cc:158
YMultiProgressMeter::maxValue
float maxValue(int segment) const
Return the maximum value for the specified segment (counting from 0).
Definition: YMultiProgressMeter.cc:98
YPropertyValue::type
YPropertyType type() const
Returns the type of this property value.
Definition: YProperty.h:169
YWidget::getProperty
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YWidget.cc:453
YMultiProgressMeter::segments
int segments() const
Return the number of segments.
Definition: YMultiProgressMeter.cc:92
YProperty
Class for widget properties.
Definition: YProperty.h:51
YMultiProgressMeter::currentValue
float currentValue(int segment) const
Return the current value for the specified segment (counting from 0).
Definition: YMultiProgressMeter.cc:106
YMultiProgressMeter::setCurrentValue
void setCurrentValue(int segment, float value)
Set the current value for the specified segment.
Definition: YMultiProgressMeter.cc:114
YPropertySet::check
void check(const std::string &propertyName) const
Check if a property 'propertyName' exists in this property set.
Definition: YProperty.cc:87
YMultiProgressMeter::propertySet
virtual const YPropertySet & propertySet()
Return this class's property set.
Definition: YMultiProgressMeter.cc:140
YMultiProgressMeter::dimension
YUIDimension dimension() const
Return the orientation of the MultiProgressBar.
Definition: YMultiProgressMeter.cc:74
YPropertyValue
Transport class for the value of simple properties.
Definition: YProperty.h:104
YWidget::setDefaultStretchable
void setDefaultStretchable(YUIDimension dim, bool newStretch)
Set the stretchable state to "newStretch".
Definition: YWidget.cc:561
YMultiProgressMeter::horizontal
bool horizontal() const
Return 'true' if the orientation is horizontal.
Definition: YMultiProgressMeter.cc:80
YMultiProgressMeter::setCurrentValues
void setCurrentValues(const std::vector< float > &values)
Set all current values and call doUpdate().
Definition: YMultiProgressMeter.cc:128
YMultiProgressMeter::doUpdate
virtual void doUpdate()=0
Notification that values have been updated and the widget needs to be redisplayed.
YMultiProgressMeter::YMultiProgressMeter
YMultiProgressMeter(YWidget *parent, YUIDimension dim, const std::vector< float > &maxValues)
Constructor.
Definition: YMultiProgressMeter.cc:54
YWidget::setProperty
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YWidget.cc:428
YWidget::propertySet
virtual const YPropertySet & propertySet()
Return this class's property set.
Definition: YWidget.cc:393