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