1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 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
24 // File : SMESHGUI_aParameter.h
28 #ifndef SMESHGUI_aParameter_H
29 #define SMESHGUI_aParameter_H
31 #include <boost/shared_ptr.hpp>
32 #include <qstringlist.h>
36 #include <SALOMEconfig.h>
37 #include CORBA_SERVER_HEADER(SMESH_Mesh)
40 class SMESHGUI_aParameter;
42 typedef boost::shared_ptr<SMESHGUI_aParameter> SMESHGUI_aParameterPtr;
45 * \brief This class is the base class of all parameters
47 class SMESHGUI_aParameter
50 typedef bool (*VALIDATION_FUNC)( SMESHGUI_aParameter* );
52 SMESHGUI_aParameter(const QString& label, const bool = false );
53 virtual ~SMESHGUI_aParameter();
55 enum Type { INT, DOUBLE, STRING, ENUM, BOOL, TABLE };
56 virtual Type GetType() const = 0;
57 virtual bool GetNewInt( int & Value ) const = 0;
58 virtual bool GetNewDouble( double & Value ) const = 0;
59 virtual bool GetNewText( QString & Value ) const = 0;
60 virtual void TakeValue( QWidget* ) = 0;
61 virtual QWidget* CreateWidget( QWidget* ) const = 0;
62 virtual void InitializeWidget( QWidget* ) const = 0;
64 bool needPreview() const;
67 * \brief Returns string representation of signal emitted when value in corrsponding widget is changed
69 virtual QString sigValueChanged() const;
79 * \brief This class provides parameter with integer value
81 class SMESHGUI_intParameter: public SMESHGUI_aParameter
84 SMESHGUI_intParameter(const int initValue = 0,
85 const QString& label = QString::null,
89 int & InitValue() { return _initValue; }
90 int & Top() { return _top; }
91 int & Bottom() { return _bottom; }
92 virtual Type GetType() const;
93 virtual bool GetNewInt( int & Value ) const;
94 virtual bool GetNewDouble( double & Value ) const;
95 virtual bool GetNewText( QString & Value ) const;
96 virtual void TakeValue( QWidget* );
97 virtual QWidget* CreateWidget( QWidget* ) const;
98 virtual void InitializeWidget( QWidget* ) const;
100 virtual QString sigValueChanged() const;
104 int _initValue, _newValue;
108 * \brief This class provides parameter with double value
110 class SMESHGUI_doubleParameter: public SMESHGUI_aParameter
113 SMESHGUI_doubleParameter(const double initValue = 0.0,
114 const QString& label = QString::null,
115 const double bottom = -1E6,
116 const double top = +1E6,
117 const double step = 1.0,
118 const int decimals = 3,
120 double & InitValue() { return _initValue; }
121 double & Top() { return _top; }
122 double & Bottom() { return _bottom; }
123 double & Step() { return _step; }
124 int & Decimals() { return _decimals; }
125 virtual Type GetType() const;
126 virtual bool GetNewInt( int & Value ) const;
127 virtual bool GetNewDouble( double & Value ) const;
128 virtual bool GetNewText( QString & Value ) const;
129 virtual QWidget* CreateWidget( QWidget* ) const;
130 virtual void InitializeWidget( QWidget* ) const;
131 virtual void TakeValue( QWidget* );
133 virtual QString sigValueChanged() const;
136 double _top, _bottom, _step;
137 double _initValue, _newValue;
142 * \brief This class provides parameter with string value
144 class SMESHGUI_strParameter: public SMESHGUI_aParameter
147 SMESHGUI_strParameter( const QString& initValue = "",
148 const QString& label = QString::null,
149 const bool = false );
150 QString& InitValue() { return _initValue; }
151 virtual Type GetType() const;
152 virtual bool GetNewInt( int & Value ) const;
153 virtual bool GetNewDouble( double & Value ) const;
154 virtual bool GetNewText( QString & Value ) const;
155 virtual QWidget* CreateWidget( QWidget* ) const;
156 virtual void InitializeWidget( QWidget* ) const;
157 virtual void TakeValue( QWidget* );
159 virtual QString sigValueChanged() const;
162 QString _initValue, _newValue;
167 * \brief This class represents the base parameter which contains dependency of
168 * shown state of other parameters on value of current
170 class SMESHGUI_dependParameter: public SMESHGUI_aParameter
174 * \brief This map describes what parameters must be shown when this parameter has value as key
175 * The list contains some indices of parameters (for example, order in some list)
176 * Value is integer based 0. If map is empty, it means that there is no dependencies.
178 typedef QValueList< int > IntList;
179 typedef QMap< int, IntList > ShownMap;
182 SMESHGUI_dependParameter( const QString& = QString::null, const bool = false );
184 const ShownMap& shownMap() const;
185 ShownMap& shownMap();
192 * \brief This class represents parameter which can have value from fixed set
194 class SMESHGUI_enumParameter: public SMESHGUI_dependParameter
198 * \brief Creates parameter with set of values 'values', default value 'init' and title 'label'
199 * Every value can be described both by integer based 0 or by string value
201 SMESHGUI_enumParameter( const QStringList& values,
203 const QString& label = QString::null,
204 const bool = false );
205 virtual ~SMESHGUI_enumParameter();
208 * \brief Returns count of possible values
212 int& InitValue() { return myInitValue; }
213 virtual Type GetType() const;
214 virtual bool GetNewInt( int& ) const;
215 virtual bool GetNewDouble( double& ) const;
216 virtual bool GetNewText( QString& ) const;
217 virtual QWidget* CreateWidget( QWidget* ) const;
218 virtual void InitializeWidget( QWidget* ) const;
219 virtual void TakeValue( QWidget* );
221 virtual QString sigValueChanged() const;
224 int myInitValue, myValue;
225 QStringList myValues;
230 * \brief This class represents parameter which can have value true or false
232 class SMESHGUI_boolParameter: public SMESHGUI_dependParameter
235 SMESHGUI_boolParameter( const bool = false,
236 const QString& = QString::null,
237 const bool = false );
238 virtual ~SMESHGUI_boolParameter();
240 bool& InitValue() { return myInitValue; }
241 virtual Type GetType() const;
242 virtual bool GetNewInt( int& ) const;
243 virtual bool GetNewDouble( double& ) const;
244 virtual bool GetNewText( QString& ) const;
245 virtual QWidget* CreateWidget( QWidget* ) const;
246 virtual void InitializeWidget( QWidget* ) const;
247 virtual void TakeValue( QWidget* );
249 virtual QString sigValueChanged() const;
252 bool myInitValue, myValue;
257 class SMESHGUI_tableParameter;
261 * \brief This class represents custom table. It has only double values and
262 editor for every cell has validator
264 class SMESHGUI_Table : public QTable
269 SMESHGUI_Table( const SMESHGUI_tableParameter*, int numRows, int numCols, QWidget* = 0, const char* = 0 );
270 virtual ~SMESHGUI_Table();
273 * \brief Hides current editor of cell
277 virtual QSize sizeHint() const;
280 * \brief Returns parameters of double validator corresponding to cell (row,col)
282 void validator( const int row, const int col, double&, double&, int& );
285 * \brief Sets the double validator parameters to every cell in row range [rmin,rmax]
286 * and column range [cmin,cmax].
287 * If rmin=-1 then rmin is set to 0, if rmax=-1 then rmax = last row.
288 * Analogically cmin and cmax are set
290 void setValidator( const double, const double, const int,
291 const int rmin = -1, const int rmax = -1,
292 const int cmin = -1, const int cmax = -1 );
295 virtual void keyPressEvent( QKeyEvent* );
296 virtual bool eventFilter( QObject*, QEvent* );
297 virtual QWidget* createEditor( int, int, bool ) const;
300 SMESHGUI_tableParameter* myParam;
305 * \brief This class represents frame for table and buttons
307 class SMESHGUI_TableFrame : public QFrame
313 * \brief Values corresponding to buttons for table resize
315 typedef enum { ADD_COLUMN, REMOVE_COLUMN, ADD_ROW, REMOVE_ROW } Button;
318 SMESHGUI_TableFrame( const SMESHGUI_tableParameter*, QWidget* );
319 ~SMESHGUI_TableFrame();
321 SMESHGUI_Table* table() const;
324 * \brief Changes shown state of some button for table resize
326 void setShown( const Button, const bool );
329 * \brief Returns shown state of some button for table resize
331 bool isShown( const Button ) const;
334 QButton* button( const Button ) const;
337 void onButtonClicked();
341 * \brief This signal is emitted if some of button for table resize is clicked
342 * Second parameter is current column for ADD_COLUMN, REMOVE_COLUMN buttons
343 * and current row for ADD_ROW, REMOVE_ROW buttons. Take into account that
344 * this object resize table ( returned by table() ) automatically
346 void toEdit( SMESHGUI_TableFrame::Button, int );
347 void valueChanged( int, int );
350 QButton *myAddColumn, *myRemoveColumn, *myAddRow, *myRemoveRow;
351 SMESHGUI_Table* myTable;
356 * \brief This class represents parameter which can have two-dimensional array of values
358 class SMESHGUI_tableParameter: public QObject, public SMESHGUI_aParameter
364 * \brief Creates table parameter with default value 'init' and title 'label'.
365 * The default value means that by default the table is filled with default value
366 * and if new column or row is added then it is filled with default value
368 SMESHGUI_tableParameter( const double init = 0.0,
369 const QString& label = QString::null,
370 const bool preview = false );
371 virtual ~SMESHGUI_tableParameter();
373 virtual Type GetType() const;
374 virtual bool GetNewInt( int& ) const;
375 virtual bool GetNewDouble( double& ) const;
376 virtual bool GetNewText( QString& ) const;
377 virtual QWidget* CreateWidget( QWidget* ) const;
378 virtual void InitializeWidget( QWidget* ) const;
379 virtual void TakeValue( QWidget* );
381 static void sortData( SMESH::double_array& );
384 * \brief Updates look of widget in accordance with all parameters of this object
386 void update( QWidget* ) const;
389 * \brief Returns data taken from widget. Please don't forget to call TakeValue before.
391 void data( SMESH::double_array& ) const;
394 * \brief Sets data. The InitializeWidget must be called in order to change values in widget
396 void setData( const SMESH::double_array& );
399 * \brief Sets count of columns and updates widget
401 void setColCount( const int, QWidget* = 0 );
404 * \brief Sets count of rows and updates widget
406 void setRowCount( const int, QWidget* = 0 );
409 * \brief Binds count of columns to some parameter and updates widget. Take into account that
410 * if this parameter is changed, the update() must be called to resize table
412 void setColCount( const SMESHGUI_aParameterPtr, QWidget* = 0 );
415 * \brief Binds count of rows to some parameter and updates widget. Take into account that
416 * if this parameter is changed, the update() must be called to resize table
418 void setRowCount( const SMESHGUI_aParameterPtr, QWidget* = 0 );
421 * \brief Enables or disables to change count of columns by buttons
423 void setEditCols( const bool );
426 * \brief Enables or disables to change count of rows by buttons
428 void setEditRows( const bool );
430 virtual QString sigValueChanged() const;
432 void setValidator( const int col, const double, const double, const int );
433 void validator( const int col, double&, double&, int& ) const;
436 * \brief These methods allow to read and change name of column
438 void setColName( const int, const QString& );
439 QString colName( const int ) const;
442 void onEdit( SMESHGUI_TableFrame::Button, int );
443 void onEdit( SMESHGUI_Table*, SMESHGUI_TableFrame::Button, int );
446 void setItems( QWidget*, int = -1, int = -1, int = -1, int = -1 ) const;
455 typedef QMap<int, ValidatorInfo> ValidatorsMap;
458 int myColsInt, myRowsInt;
459 SMESHGUI_aParameterPtr myCols, myRows;
461 SMESH::double_array myData;
462 ValidatorsMap myValidators;
463 bool myEditCols, myEditRows;
464 QMap< int, QString > myColNames;
466 friend class SMESHGUI_Table;
469 #endif // SMESHGUI_aParameter.h