libyui  3.10.0
YRadioButtonGroup.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: YRadioButtonGroup.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 "YRadioButton.h"
31 #include "YRadioButtonGroup.h"
32 
33 using std::string;
34 
35 
37 {
39  {}
40 
41 
42  YRadioButtonList buttonList;
43 };
44 
45 
46 
47 
49  : YSingleChildContainerWidget( parent )
50  , priv( new YRadioButtonGroupPrivate() )
51 {
52  YUI_CHECK_NEW( priv );
53 }
54 
55 
57 {
58 }
59 
60 
61 YRadioButtonListConstIterator
63 {
64  return priv->buttonList.begin();
65 }
66 
67 
68 YRadioButtonListConstIterator
70 {
71  return priv->buttonList.end();
72 }
73 
74 
75 int
77 {
78  return priv->buttonList.size();
79 }
80 
81 
82 void
84 {
85  priv->buttonList.push_back( button );
86 }
87 
88 
89 void
91 {
92  priv->buttonList.remove( button );
93 }
94 
95 
96 void
98 {
99  for ( YRadioButtonListConstIterator it = radioButtonsBegin();
100  it != radioButtonsEnd();
101  ++it )
102  {
103  if ( *it != selectedRadioButton )
104  (*it)->setValue( false );
105  }
106 }
107 
108 
109 YRadioButton *
111 {
112  for ( YRadioButtonListConstIterator it = radioButtonsBegin();
113  it != radioButtonsEnd();
114  ++it )
115  {
116  if ( (*it)->value() )
117  return *it;
118  }
119 
120  return 0;
121 }
122 
123 
124 const YPropertySet &
126 {
127  static YPropertySet propSet;
128 
129  if ( propSet.isEmpty() )
130  {
131  /*
132  * @property any CurrentButton widget ID of the currently selected RadioButton of this group
133  * @property any Value Alias for CurrentButton
134  */
135  propSet.add( YProperty( YUIProperty_Value, YOtherProperty ) );
136  propSet.add( YProperty( YUIProperty_CurrentButton, YOtherProperty ) );
137  propSet.add( YWidget::propertySet() );
138  }
139 
140  return propSet;
141 }
142 
143 
144 bool
145 YRadioButtonGroup::setProperty( const string & propertyName, const YPropertyValue & val )
146 {
147  propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
148 
149  if ( propertyName == YUIProperty_CurrentButton ||
150  propertyName == YUIProperty_Value ) return false; // Needs special handling
151  else
152  {
153  return YWidget::setProperty( propertyName, val );
154  }
155 
156  return true; // success -- no special processing necessary
157 }
158 
159 
161 YRadioButtonGroup::getProperty( const string & propertyName )
162 {
163  propertySet().check( propertyName ); // throws exceptions if not found
164 
165  if ( propertyName == YUIProperty_CurrentButton ||
166  propertyName == YUIProperty_Value ) return YPropertyValue( YOtherProperty );
167  else
168  {
169  return YWidget::getProperty( propertyName );
170  }
171 }
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
YRadioButtonGroup(YWidget *parent)
Constructor.
virtual ~YRadioButtonGroup()
Destructor.
virtual void removeRadioButton(YRadioButton *radioButton)
Remove a RadioButton from this button group.
YRadioButtonListConstIterator radioButtonsEnd() const
Return an iterator that points behind the last RadioButton of this button group.
YRadioButtonListConstIterator radioButtonsBegin() const
Return an iterator that points to the first RadioButton of this button group.
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
int radioButtonsCount() const
Return the number of RadioButtons in this button group.
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
YRadioButton * currentButton() const
Find the currently selected button.
virtual const YPropertySet & propertySet()
Return this class's property set.
virtual void addRadioButton(YRadioButton *radioButton)
Add a RadioButton to this button group.
void uncheckOtherButtons(YRadioButton *radioButton)
Unchecks all radio buttons except one.
RadioButton: Widget for one-out-of-many selection.
Definition: YRadioButton.h:52
Container widget class that manages one child.
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
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