libyui  3.3.2
YIntField.h
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: YIntField.h
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 #ifndef YIntField_h
26 #define YIntField_h
27 
28 #include "YWidget.h"
29 
30 class YIntFieldPrivate;
31 
32 
33 
34 /**
35  * IntField: Input field for integer values. Enforces input range between a
36  * specified minimum and maximum value.
37  **/
38 class YIntField : public YWidget
39 {
40 protected:
41  /**
42  * Constructor.
43  *
44  * Create an IntField with 'label' as the caption, and the specified minimum
45  * and maximum values.
46  *
47  * Note that YWidgetFactory::createIntField() also has an 'initialValue'
48  * parameter that is not used here (because the current value is not stored
49  * in this base class, but in the derived class).
50  **/
52  const std::string & label,
53  int minValue,
54  int maxValue );
55 
56 public:
57  /**
58  * Destructor.
59  **/
60  virtual ~YIntField();
61 
62  /**
63  * Return a descriptive name of this widget class for logging,
64  * debugging etc.
65  **/
66  virtual const char * widgetClass() const { return "YIntField"; }
67 
68  /**
69  * Get the current value (the number entered by the user or set from the
70  * outside) of this IntField.
71  *
72  * Derived classes are required to implement this.
73  **/
74  virtual int value() = 0;
75 
76  /**
77  * Set the current value (the number entered by the user or set from the
78  * outside) of this IntField. This method enforces 'val to be between
79  * minValue and maxValue.
80  **/
81  void setValue( int val ) { setValueInternal( enforceRange( val ) ); }
82 
83 protected:
84 
85  /**
86  * Set the current value (the number entered by the user or set from the
87  * outside) of this IntField. 'val' is guaranteed to be between minValue
88  * and maxValue; no further checks are required.
89  *
90  * Derived classes are required to implement this method.
91  **/
92  virtual void setValueInternal( int val ) = 0;
93 
94  /**
95  * Enforce 'val' to be between minValue and maxValue.
96  * Return a value that is in range. This does not change the internally
97  * stored value of this IntField in any way.
98  **/
99  int enforceRange( int val ) const;
100 
101 public:
102 
103  /**
104  * Return the minimum value.
105  **/
106  int minValue() const;
107 
108  /**
109  * Set a new minimum value. If the current value is less than that, it will
110  * be set to the new minimum.
111  **/
112  void setMinValue( int val );
113 
114  /**
115  * Return the maximum value.
116  **/
117  int maxValue() const;
118 
119  /**
120  * Set a new maximum value. If the current value is greater than that, it
121  * will be set to the new maximum.
122  **/
123  void setMaxValue( int val );
124 
125  /**
126  * Get the label (the caption above the input field).
127  **/
128  std::string label() const;
129 
130  /**
131  * Set the label (the caption above the input field).
132  *
133  * Derived classes are free to reimplement this, but they should call this
134  * base class method at the end of the overloaded function.
135  **/
136  virtual void setLabel( const std::string & label );
137 
138  /**
139  * Set a property.
140  * Reimplemented from YWidget.
141  *
142  * This function may throw YUIPropertyExceptions.
143  *
144  * This function returns 'true' if the value was successfully set and
145  * 'false' if that value requires special handling (not in error cases:
146  * those are covered by exceptions).
147  **/
148  virtual bool setProperty( const std::string & propertyName,
149  const YPropertyValue & val );
150 
151  /**
152  * Get a property.
153  * Reimplemented from YWidget.
154  *
155  * This method may throw YUIPropertyExceptions.
156  **/
157  virtual YPropertyValue getProperty( const std::string & propertyName );
158 
159  /**
160  * Return this class's property set.
161  * This also initializes the property upon the first call.
162  *
163  * Reimplemented from YWidget.
164  **/
165  virtual const YPropertySet & propertySet();
166 
167  /**
168  * Get the string of this widget that holds the keyboard shortcut.
169  *
170  * Reimplemented from YWidget.
171  **/
172  virtual std::string shortcutString() const { return label(); }
173 
174  /**
175  * Set the string of this widget that holds the keyboard shortcut.
176  *
177  * Reimplemented from YWidget.
178  **/
179  virtual void setShortcutString( const std::string & str )
180  { setLabel( str ); }
181 
182  /**
183  * The name of the widget property that will return user input.
184  * Inherited from YWidget.
185  **/
186  const char * userInputProperty() { return YUIProperty_Value; }
187 
188 
189 private:
190 
192 };
193 
194 
195 #endif // YIntField_h
virtual void setValueInternal(int val)=0
Set the current value (the number entered by the user or set from the outside) of this IntField...
virtual const char * widgetClass() const
Return a descriptive name of this widget class for logging, debugging etc.
Definition: YIntField.h:66
YIntField(YWidget *parent, const std::string &label, int minValue, int maxValue)
Constructor.
Definition: YIntField.cc:50
Transport class for the value of simple properties.
Definition: YProperty.h:104
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
Definition: YIntField.cc:139
A set of properties to check names and types against.
Definition: YProperty.h:197
virtual void setShortcutString(const std::string &str)
Set the string of this widget that holds the keyboard shortcut.
Definition: YIntField.h:179
int maxValue() const
Return the maximum value.
Definition: YIntField.cc:104
YWidget * parent() const
Return this widget&#39;s parent or 0 if it doesn&#39;t have a parent.
Definition: YWidget.cc:269
int minValue() const
Return the minimum value.
Definition: YIntField.cc:84
void setMaxValue(int val)
Set a new maximum value.
Definition: YIntField.cc:111
virtual void setLabel(const std::string &label)
Set the label (the caption above the input field).
Definition: YIntField.cc:131
virtual ~YIntField()
Destructor.
Definition: YIntField.cc:64
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YIntField.cc:163
virtual std::string shortcutString() const
Get the string of this widget that holds the keyboard shortcut.
Definition: YIntField.h:172
int enforceRange(int val) const
Enforce &#39;val&#39; to be between minValue and maxValue.
Definition: YIntField.cc:71
std::string label() const
Get the label (the caption above the input field).
Definition: YIntField.cc:124
const char * userInputProperty()
The name of the widget property that will return user input.
Definition: YIntField.h:186
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YIntField.cc:181
virtual int value()=0
Get the current value (the number entered by the user or set from the outside) of this IntField...
IntField: Input field for integer values.
Definition: YIntField.h:38
void setMinValue(int val)
Set a new minimum value.
Definition: YIntField.cc:91
void setValue(int val)
Set the current value (the number entered by the user or set from the outside) of this IntField...
Definition: YIntField.h:81
Abstract base class of all UI widgets.
Definition: YWidget.h:54