Salome HOME
Update copyrights 2014.
[modules/smesh.git] / src / StdMeshersGUI / StdMeshersGUI_RadioButtonsGrpWdg.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #include "StdMeshersGUI_RadioButtonsGrpWdg.h"
20
21 #include <QVBoxLayout>
22 #include <QRadioButton>
23 #include <QButtonGroup>
24 #include <QStringList>
25
26 #define SPACING 6
27 #define MARGIN  11
28
29 //================================================================================
30 /*!
31  * \brief Creates a QGroupBox with a given title
32  */
33 //================================================================================
34
35 StdMeshersGUI_RadioButtonsGrpWdg::StdMeshersGUI_RadioButtonsGrpWdg( const QString& title )
36   : QGroupBox( title )
37 {
38   myButtonGrp = new QButtonGroup( this );
39 }
40
41 //================================================================================
42 /*!
43  * \brief Creates a given nubmer of button labels with given labels (QString's)
44  */
45 //================================================================================
46
47 void StdMeshersGUI_RadioButtonsGrpWdg::setButtonLabels( const QStringList& buttonLabels )
48 {
49   QVBoxLayout* layout = new QVBoxLayout( this );
50   layout->setSpacing(SPACING);
51   layout->setMargin(MARGIN);
52
53   for ( int id = 0; id < buttonLabels.size(); ++id )
54   {
55     QRadioButton* button = new QRadioButton( buttonLabels.at(id), this );
56     layout->addWidget( button );
57     myButtonGrp->addButton( button, id );
58   }
59 }
60
61 //================================================================================
62 /*!
63  * \brief Set checked a radio button with a give id.
64  */
65 //================================================================================
66
67 void StdMeshersGUI_RadioButtonsGrpWdg::setChecked(int id)
68 {
69   if ( QAbstractButton* but = myButtonGrp->button( id ))
70     but->setChecked( true );
71 }
72
73 //================================================================================
74 /*!
75  * \brief Return id (zero based) of a checked radio button
76  */
77 //================================================================================
78
79 int StdMeshersGUI_RadioButtonsGrpWdg::checkedId () const
80 {
81   return myButtonGrp->checkedId();
82 }