libyui  3.10.0
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 using std::string;
33 using std::vector;
34 
35 
37 {
38  YMultiProgressMeterPrivate( YUIDimension dim,
39  const vector<float> & maxValues )
40  : dim( dim )
41  , maxValues( maxValues )
42  {
43  // Make currentValues as large as maxValues
44  // and initialize each element with 0
45  currentValues = vector<float>( maxValues.size(), 0.0 );
46  }
47 
48 
49  YUIDimension dim;
50  vector<float> maxValues;
51  vector<float> currentValues;
52 };
53 
54 
55 
56 
58  YUIDimension dim,
59  const vector<float> & maxValues )
60  : YWidget( parent )
61  , priv( new YMultiProgressMeterPrivate( dim, maxValues ) )
62 {
63  YUI_CHECK_NEW( priv );
64 
65  setDefaultStretchable( YD_HORIZ, dim == YD_HORIZ );
66  setDefaultStretchable( YD_VERT, dim == YD_VERT );
67 }
68 
69 
71 {
72  // NOP
73 }
74 
75 
76 YUIDimension
78 {
79  return priv->dim;
80 }
81 
82 
84 {
85  return priv->dim == YD_HORIZ;
86 }
87 
88 
90 {
91  return priv->dim == YD_VERT;
92 }
93 
94 
96 {
97  return (int) priv->maxValues.size();
98 }
99 
100 
101 float YMultiProgressMeter::maxValue( int segment ) const
102 {
103  YUI_CHECK_INDEX( segment, 0, (int) priv->maxValues.size() );
104 
105  return priv->maxValues[ segment ];
106 }
107 
108 
109 float YMultiProgressMeter::currentValue( int segment ) const
110 {
111  YUI_CHECK_INDEX( segment, 0, (int) priv->currentValues.size() );
112 
113  return priv->currentValues[ segment ];
114 }
115 
116 
117 void YMultiProgressMeter::setCurrentValue( int segment, float value )
118 {
119  YUI_CHECK_INDEX( segment, 0, (int) priv->currentValues.size() );
120 
121  if ( value < 0.0 ) // Allow -1 etc. as marker values
122  value = 0.0;
123 
124  if ( value > maxValue( segment ) ) // Don't complain (beware of rounding errors)
125  value = maxValue( segment );
126 
127  priv->currentValues[ segment ] = value;
128 }
129 
130 
131 void YMultiProgressMeter::setCurrentValues( const vector<float> & values )
132 {
133  for ( int i=0; i < (int) values.size(); i++ )
134  {
135  setCurrentValue( i, values[i] );
136  }
137 
138  doUpdate();
139 }
140 
141 
142 const YPropertySet &
144 {
145  static YPropertySet propSet;
146 
147  if ( propSet.isEmpty() )
148  {
149  /*
150  * @property list<integer> Values the current values for all segments
151  */
152  propSet.add( YProperty( YUIProperty_Values, YOtherProperty ) );
153  propSet.add( YWidget::propertySet() );
154  }
155 
156  return propSet;
157 }
158 
159 
160 bool
161 YMultiProgressMeter::setProperty( const string & propertyName, const YPropertyValue & val )
162 {
163  propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
164 
165  if ( propertyName == YUIProperty_Values ) return false; // need special processing
166  else
167  {
168  YWidget::setProperty( propertyName, val );
169  }
170 
171  return true; // success -- no special handling necessary
172 }
173 
174 
176 YMultiProgressMeter::getProperty( const string & propertyName )
177 {
178  propertySet().check( propertyName ); // throws exceptions if not found
179 
180  if ( propertyName == YUIProperty_Values ) return YPropertyValue( YOtherProperty );
181  else
182  {
183  return YWidget::getProperty( propertyName );
184  }
185 }
float currentValue(int segment) const
Return the current value for the specified segment (counting from 0).
bool vertical() const
Return 'true' if the orientation is vertical.
int segments() const
Return the number of segments.
void setCurrentValues(const std::vector< float > &values)
Set all current values and call doUpdate().
bool horizontal() const
Return 'true' if the orientation is horizontal.
void setCurrentValue(int segment, float value)
Set the current value for the specified segment.
YUIDimension dimension() const
Return the orientation of the MultiProgressBar.
float maxValue(int segment) const
Return the maximum value for the specified segment (counting from 0).
virtual const YPropertySet & propertySet()
Return this class's property set.
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
virtual ~YMultiProgressMeter()
Destructor.
virtual void doUpdate()=0
Notification that values have been updated and the widget needs to be redisplayed.
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
YMultiProgressMeter(YWidget *parent, YUIDimension dim, const std::vector< float > &maxValues)
Constructor.
A set of properties to check names and types against.
Definition: YProperty.h:198
void check(const std::string &propertyName) const
Check if a property 'propertyName' exists in this property set.
Definition: YProperty.cc:88
bool isEmpty() const
Returns 'true' if this property set does not contain anything.
Definition: YProperty.h:263
void add(const YProperty &prop)
Add a property to this property set.
Definition: YProperty.cc:146
Transport class for the value of simple properties.
Definition: YProperty.h:105
YPropertyType type() const
Returns the type of this property value.
Definition: YProperty.h:169
Class for widget properties.
Definition: YProperty.h:52
Abstract base class of all UI widgets.
Definition: YWidget.h:55
virtual const YPropertySet & propertySet()
Return this class's property set.
Definition: YWidget.cc:395
void setDefaultStretchable(YUIDimension dim, bool newStretch)
Set the stretchable state to "newStretch".
Definition: YWidget.cc:566
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YWidget.cc:432
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YWidget.cc:457