1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 CEA
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
23 // File : SMESHGUI_CreateHypothesesDlg.cxx
24 // Author : Julia DOROVSKIKH
28 #include "SMESHGUI_CreateHypothesesDlg.h"
30 #include "SUIT_Desktop.h"
31 #include "SUIT_ResourceMgr.h"
33 #include "SALOME_ListIteratorOfListIO.hxx"
35 #include "utilities.h"
38 #include <qbuttongroup.h>
39 #include <qgroupbox.h>
40 #include <qpushbutton.h>
42 #include <qlistview.h>
47 * \param theIsAlgo - If TRUE when operator is used for creation of gypotheses
49 * Constructor does nothing
51 SMESHGUI_CreateHypothesesDlg::SMESHGUI_CreateHypothesesDlg ( bool isAlgo )
52 : SMESHGUI_Dialog( 0, false, true, Apply | Cancel ),
55 setCaption( isAlgo ? tr( "SMESH_CREATE_ALGORITHMS" ) : tr( "SMESH_CREATE_HYPOTHESES" ) );
56 setSizeGripEnabled( TRUE );
58 QGridLayout* SMESHGUI_CreateHypothesesDlgLayout = new QGridLayout( mainFrame() );
59 SMESHGUI_CreateHypothesesDlgLayout->setSpacing( 6 );
60 SMESHGUI_CreateHypothesesDlgLayout->setMargin( 11 );
62 /***************************************************************/
63 QGroupBox* GroupAlgorithms = new QGroupBox( mainFrame(), "GroupAlgorithms" );
64 GroupAlgorithms->setTitle( isAlgo ? tr( "SMESH_AVAILABLE_ALGORITHMS" ) : tr( "SMESH_AVAILABLE_HYPOTHESES" ) );
65 GroupAlgorithms->setColumnLayout( 0, Qt::Vertical );
66 GroupAlgorithms->layout()->setSpacing( 0 );
67 GroupAlgorithms->layout()->setMargin( 0 );
69 QGridLayout* hypLayout = new QGridLayout( GroupAlgorithms->layout() );
70 hypLayout->setGeometry( QRect( 12, 18, 139, 250 ) );
71 hypLayout->setAlignment( Qt::AlignTop );
72 hypLayout->setSpacing( 6 );
73 hypLayout->setMargin( 11 );
75 myList = new QListView( GroupAlgorithms, "myList" );
76 myList->setMinimumSize( 400, 200 );
77 myList->addColumn( "" );
78 myList->header()->hide();
79 myList->setSelectionMode( QListView::Single );
80 myList->setResizeMode( QListView::AllColumns );
81 myList->setRootIsDecorated( true );
83 hypLayout->addWidget( myList, 0, 0 );
84 SMESHGUI_CreateHypothesesDlgLayout->addWidget( GroupAlgorithms, 0, 0 );
86 setButtonText( Apply, tr( "SMESH_BUT_CREATE" ) );
88 // connect signals and slots
89 connect( myList, SIGNAL( selectionChanged() ), SLOT( onHypSelected() ) );
90 connect( myList, SIGNAL( doubleClicked( QListViewItem* ) ), SLOT( onDoubleClicked( QListViewItem* ) ) );
92 // update button state
99 SMESHGUI_CreateHypothesesDlg::~SMESHGUI_CreateHypothesesDlg()
104 * \brief Get Name of hypotheses or algorithm
105 * \return Name of hypotheses or algorithm
107 QString SMESHGUI_CreateHypothesesDlg::hypName() const
109 QListViewItem* item = myList->selectedItem();
110 return item ? item->text( 1 ) : "";
114 * \brief Enable/Disable "Apply" button
116 * Private slot called when selection in list box changed enables/disables "Apply" button
118 void SMESHGUI_CreateHypothesesDlg::onHypSelected()
120 QListViewItem* item = myList->selectedItem();
121 setButtonEnabled( item && item->depth() > 0, Apply );
125 * \brief Emits dlgApply signal
126 * \param i - clicked item
128 * Private slot called when item of list box is double clicked emits dlgApply signal
130 void SMESHGUI_CreateHypothesesDlg::onDoubleClicked ( QListViewItem* i )
132 if ( i && i->depth() > 0 )
137 * \brief Initialize dialog
138 * \param theHypList - List of hypotheses
139 * \param theHypList - Plugin names
140 * \param theHypList - Labels
141 * \param theHypList - Icons' identifiers
143 * Initializes dialog with parameters. This method is called by operation before showing
146 void SMESHGUI_CreateHypothesesDlg::init( const QStringList& theHypList,
147 const QStringList& thePluginNames,
148 const QStringList& theLabels,
149 const QStringList& theIconIds )
152 for ( int i = 0; i < theHypList.count(); ++i )
154 QListViewItem* parentItem = 0;
155 QListViewItem* childItem = myList->firstChild();
158 if ( childItem->text( 0 ) == thePluginNames[ i ] )
160 parentItem = childItem;
163 childItem = childItem->nextSibling();
167 parentItem = new QListViewItem( myList, thePluginNames[ i ] );
168 parentItem->setOpen( true );
169 QListViewItem* aItem =
170 new QListViewItem( parentItem, theLabels[ i ], theHypList[ i ] );
171 QPixmap aPixMap( resMgr()->loadPixmap( "SMESH", tr( theIconIds[ i ] ) ) );
172 if ( !aPixMap.isNull() )
173 aItem->setPixmap( 0, aPixMap );