1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_aParameter.h
27 #ifndef SMESHGUI_aParameter_H
28 #define SMESHGUI_aParameter_H
30 #include <boost/shared_ptr.hpp>
31 #include <qstringlist.h>
35 #include <SALOMEconfig.h>
36 #include CORBA_SERVER_HEADER(SMESH_Mesh)
39 class SMESHGUI_aParameter;
41 typedef boost::shared_ptr<SMESHGUI_aParameter> SMESHGUI_aParameterPtr;
44 * \brief This class is the base class of all parameters
46 class SMESHGUI_aParameter
49 typedef bool (*VALIDATION_FUNC)( SMESHGUI_aParameter* );
51 SMESHGUI_aParameter(const QString& label, const bool = false );
52 virtual ~SMESHGUI_aParameter();
54 enum Type { INT, DOUBLE, STRING, ENUM, BOOL, TABLE };
55 virtual Type GetType() const = 0;
56 virtual bool GetNewInt( int & Value ) const = 0;
57 virtual bool GetNewDouble( double & Value ) const = 0;
58 virtual bool GetNewText( QString & Value ) const = 0;
59 virtual void TakeValue( QWidget* ) = 0;
60 virtual QWidget* CreateWidget( QWidget* ) const = 0;
61 virtual void InitializeWidget( QWidget* ) const = 0;
63 bool needPreview() const;
66 * \brief Returns string representation of signal emitted when value in corrsponding widget is changed
68 virtual QString sigValueChanged() const;
78 * \brief This class provides parameter with integer value
80 class SMESHGUI_intParameter: public SMESHGUI_aParameter
83 SMESHGUI_intParameter(const int initValue = 0,
84 const QString& label = QString::null,
88 int & InitValue() { return _initValue; }
89 int & Top() { return _top; }
90 int & Bottom() { return _bottom; }
91 virtual Type GetType() const;
92 virtual bool GetNewInt( int & Value ) const;
93 virtual bool GetNewDouble( double & Value ) const;
94 virtual bool GetNewText( QString & Value ) const;
95 virtual void TakeValue( QWidget* );
96 virtual QWidget* CreateWidget( QWidget* ) const;
97 virtual void InitializeWidget( QWidget* ) const;
99 virtual QString sigValueChanged() const;
103 int _initValue, _newValue;
107 * \brief This class provides parameter with double value
109 class SMESHGUI_doubleParameter: public SMESHGUI_aParameter
112 SMESHGUI_doubleParameter(const double initValue = 0.0,
113 const QString& label = QString::null,
114 const double bottom = -1E6,
115 const double top = +1E6,
116 const double step = 1.0,
117 const int decimals = 3,
119 double & InitValue() { return _initValue; }
120 double & Top() { return _top; }
121 double & Bottom() { return _bottom; }
122 double & Step() { return _step; }
123 int & Decimals() { return _decimals; }
124 virtual Type GetType() const;
125 virtual bool GetNewInt( int & Value ) const;
126 virtual bool GetNewDouble( double & Value ) const;
127 virtual bool GetNewText( QString & Value ) const;
128 virtual QWidget* CreateWidget( QWidget* ) const;
129 virtual void InitializeWidget( QWidget* ) const;
130 virtual void TakeValue( QWidget* );
132 virtual QString sigValueChanged() const;
135 double _top, _bottom, _step;
136 double _initValue, _newValue;
141 * \brief This class provides parameter with string value
143 class SMESHGUI_strParameter: public SMESHGUI_aParameter
146 SMESHGUI_strParameter( const QString& initValue = "",
147 const QString& label = QString::null,
148 const bool = false );
149 QString& InitValue() { return _initValue; }
150 virtual Type GetType() const;
151 virtual bool GetNewInt( int & Value ) const;
152 virtual bool GetNewDouble( double & Value ) const;
153 virtual bool GetNewText( QString & Value ) const;
154 virtual QWidget* CreateWidget( QWidget* ) const;
155 virtual void InitializeWidget( QWidget* ) const;
156 virtual void TakeValue( QWidget* );
158 virtual QString sigValueChanged() const;
161 QString _initValue, _newValue;
166 * \brief This class represents the base parameter which contains dependency of
167 * shown state of other parameters on value of current
169 class SMESHGUI_dependParameter: public SMESHGUI_aParameter
173 * \brief This map describes what parameters must be shown when this parameter has value as key
174 * The list contains some indices of parameters (for example, order in some list)
175 * Value is integer based 0. If map is empty, it means that there is no dependencies.
177 typedef QValueList< int > IntList;
178 typedef QMap< int, IntList > ShownMap;
181 SMESHGUI_dependParameter( const QString& = QString::null, const bool = false );
183 const ShownMap& shownMap() const;
184 ShownMap& shownMap();
191 * \brief This class represents parameter which can have value from fixed set
193 class SMESHGUI_enumParameter: public SMESHGUI_dependParameter
197 * \brief Creates parameter with set of values 'values', default value 'init' and title 'label'
198 * Every value can be described both by integer based 0 or by string value
200 SMESHGUI_enumParameter( const QStringList& values,
202 const QString& label = QString::null,
203 const bool = false );
204 virtual ~SMESHGUI_enumParameter();
207 * \brief Returns count of possible values
211 int& InitValue() { return myInitValue; }
212 virtual Type GetType() const;
213 virtual bool GetNewInt( int& ) const;
214 virtual bool GetNewDouble( double& ) const;
215 virtual bool GetNewText( QString& ) const;
216 virtual QWidget* CreateWidget( QWidget* ) const;
217 virtual void InitializeWidget( QWidget* ) const;
218 virtual void TakeValue( QWidget* );
220 virtual QString sigValueChanged() const;
223 int myInitValue, myValue;
224 QStringList myValues;
229 * \brief This class represents parameter which can have value true or false
231 class SMESHGUI_boolParameter: public SMESHGUI_dependParameter
234 SMESHGUI_boolParameter( const bool = false,
235 const QString& = QString::null,
236 const bool = false );
237 virtual ~SMESHGUI_boolParameter();
239 bool& InitValue() { return myInitValue; }
240 virtual Type GetType() const;
241 virtual bool GetNewInt( int& ) const;
242 virtual bool GetNewDouble( double& ) const;
243 virtual bool GetNewText( QString& ) const;
244 virtual QWidget* CreateWidget( QWidget* ) const;
245 virtual void InitializeWidget( QWidget* ) const;
246 virtual void TakeValue( QWidget* );
248 virtual QString sigValueChanged() const;
251 bool myInitValue, myValue;
256 class SMESHGUI_tableParameter;
260 * \brief This class represents custom table. It has only double values and
261 editor for every cell has validator
263 class SMESHGUI_Table : public QTable
268 SMESHGUI_Table( const SMESHGUI_tableParameter*, int numRows, int numCols, QWidget* = 0, const char* = 0 );
269 virtual ~SMESHGUI_Table();
272 * \brief Hides current editor of cell
276 virtual QSize sizeHint() const;
279 * \brief Returns parameters of double validator corresponding to cell (row,col)
281 void validator( const int row, const int col, double&, double&, int& );
284 * \brief Sets the double validator parameters to every cell in row range [rmin,rmax]
285 * and column range [cmin,cmax].
286 * If rmin=-1 then rmin is set to 0, if rmax=-1 then rmax = last row.
287 * Analogically cmin and cmax are set
289 void setValidator( const double, const double, const int,
290 const int rmin = -1, const int rmax = -1,
291 const int cmin = -1, const int cmax = -1 );
294 virtual void keyPressEvent( QKeyEvent* );
295 virtual bool eventFilter( QObject*, QEvent* );
296 virtual QWidget* createEditor( int, int, bool ) const;
299 SMESHGUI_tableParameter* myParam;
304 * \brief This class represents frame for table and buttons
306 class SMESHGUI_TableFrame : public QFrame
312 * \brief Values corresponding to buttons for table resize
314 typedef enum { ADD_COLUMN, REMOVE_COLUMN, ADD_ROW, REMOVE_ROW } Button;
317 SMESHGUI_TableFrame( const SMESHGUI_tableParameter*, QWidget* );
318 ~SMESHGUI_TableFrame();
320 SMESHGUI_Table* table() const;
323 * \brief Changes shown state of some button for table resize
325 void setShown( const Button, const bool );
328 * \brief Returns shown state of some button for table resize
330 bool isShown( const Button ) const;
333 QButton* button( const Button ) const;
336 void onButtonClicked();
340 * \brief This signal is emitted if some of button for table resize is clicked
341 * Second parameter is current column for ADD_COLUMN, REMOVE_COLUMN buttons
342 * and current row for ADD_ROW, REMOVE_ROW buttons. Take into account that
343 * this object resize table ( returned by table() ) automatically
345 void toEdit( SMESHGUI_TableFrame::Button, int );
346 void valueChanged( int, int );
349 QButton *myAddColumn, *myRemoveColumn, *myAddRow, *myRemoveRow;
350 SMESHGUI_Table* myTable;
355 * \brief This class represents parameter which can have two-dimensional array of values
357 class SMESHGUI_tableParameter: public QObject, public SMESHGUI_aParameter
363 * \brief Creates table parameter with default value 'init' and title 'label'.
364 * The default value means that by default the table is filled with default value
365 * and if new column or row is added then it is filled with default value
367 SMESHGUI_tableParameter( const double init = 0.0,
368 const QString& label = QString::null,
369 const bool preview = false );
370 virtual ~SMESHGUI_tableParameter();
372 virtual Type GetType() const;
373 virtual bool GetNewInt( int& ) const;
374 virtual bool GetNewDouble( double& ) const;
375 virtual bool GetNewText( QString& ) const;
376 virtual QWidget* CreateWidget( QWidget* ) const;
377 virtual void InitializeWidget( QWidget* ) const;
378 virtual void TakeValue( QWidget* );
380 static void sortData( SMESH::double_array& );
383 * \brief Updates look of widget in accordance with all parameters of this object
385 void update( QWidget* ) const;
388 * \brief Returns data taken from widget. Please don't forget to call TakeValue before.
390 void data( SMESH::double_array& ) const;
393 * \brief Sets data. The InitializeWidget must be called in order to change values in widget
395 void setData( const SMESH::double_array& );
398 * \brief Sets count of columns and updates widget
400 void setColCount( const int, QWidget* = 0 );
403 * \brief Sets count of rows and updates widget
405 void setRowCount( const int, QWidget* = 0 );
408 * \brief Binds count of columns to some parameter and updates widget. Take into account that
409 * if this parameter is changed, the update() must be called to resize table
411 void setColCount( const SMESHGUI_aParameterPtr, QWidget* = 0 );
414 * \brief Binds count of rows to some parameter and updates widget. Take into account that
415 * if this parameter is changed, the update() must be called to resize table
417 void setRowCount( const SMESHGUI_aParameterPtr, QWidget* = 0 );
420 * \brief Enables or disables to change count of columns by buttons
422 void setEditCols( const bool );
425 * \brief Enables or disables to change count of rows by buttons
427 void setEditRows( const bool );
429 virtual QString sigValueChanged() const;
431 void setValidator( const int col, const double, const double, const int );
432 void validator( const int col, double&, double&, int& ) const;
435 * \brief These methods allow to read and change name of column
437 void setColName( const int, const QString& );
438 QString colName( const int ) const;
441 void onEdit( SMESHGUI_TableFrame::Button, int );
442 void onEdit( SMESHGUI_Table*, SMESHGUI_TableFrame::Button, int );
445 void setItems( QWidget*, int = -1, int = -1, int = -1, int = -1 ) const;
454 typedef QMap<int, ValidatorInfo> ValidatorsMap;
457 int myColsInt, myRowsInt;
458 SMESHGUI_aParameterPtr myCols, myRows;
460 SMESH::double_array myData;
461 ValidatorsMap myValidators;
462 bool myEditCols, myEditRows;
463 QMap< int, QString > myColNames;
465 friend class SMESHGUI_Table;
468 #endif // SMESHGUI_aParameter.h