X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESHGUI%2FSMESHGUI_aParameter.h;h=8613b50dd1a8a2ef1b7a6891e566d56bcb73aa7a;hp=a4360b5fd83096b28cad8000d918436e69f8da4d;hb=81a502af8470190be359d6491a20796dbad5bb97;hpb=3036ecaa2577a1fb892f75e20ba11e91cbe42b37 diff --git a/src/SMESHGUI/SMESHGUI_aParameter.h b/src/SMESHGUI/SMESHGUI_aParameter.h index a4360b5fd..8613b50dd 100644 --- a/src/SMESHGUI/SMESHGUI_aParameter.h +++ b/src/SMESHGUI/SMESHGUI_aParameter.h @@ -29,41 +29,50 @@ #define SMESHGUI_aParameter_H #include -#include +#include +#include +#include + +#include +#include CORBA_SERVER_HEADER(SMESH_Mesh) class QWidget; class SMESHGUI_aParameter; typedef boost::shared_ptr SMESHGUI_aParameterPtr; -//================================================================================= -// class : SMESHGUI_aParameter -// purpose : -//================================================================================= +/*! + * \brief This class is the base class of all parameters + */ class SMESHGUI_aParameter { public: SMESHGUI_aParameter(const QString& label):_label(label) {} virtual ~SMESHGUI_aParameter(); - enum Type { INT, DOUBLE, TEXT }; + enum Type { INT, DOUBLE, STRING, ENUM, BOOL, TABLE }; virtual Type GetType() const = 0; virtual bool GetNewInt( int & Value ) const = 0; virtual bool GetNewDouble( double & Value ) const = 0; virtual bool GetNewText( QString & Value ) const = 0; - virtual void InitializeWidget( QWidget* ) const = 0; virtual void TakeValue( QWidget* ) = 0; + virtual QWidget* CreateWidget( QWidget* ) const = 0; + virtual void InitializeWidget( QWidget* ) const = 0; - QString & Label() { return _label; } + /*! + * \brief Returns string representation of signal emitted when value in corrsponding widget is changed + */ + virtual QString sigValueChanged() const; - private: + QString & Label() { return _label; } + +private: QString _label; }; -//================================================================================= -// class : SMESHGUI_intParameter -// purpose : -//================================================================================= +/*! + * \brief This class provides parameter with integer value + */ class SMESHGUI_intParameter: public SMESHGUI_aParameter { public: @@ -78,18 +87,20 @@ public: virtual bool GetNewInt( int & Value ) const; virtual bool GetNewDouble( double & Value ) const; virtual bool GetNewText( QString & Value ) const; - virtual void InitializeWidget( QWidget* ) const; virtual void TakeValue( QWidget* ); + virtual QWidget* CreateWidget( QWidget* ) const; + virtual void InitializeWidget( QWidget* ) const; - private: + virtual QString sigValueChanged() const; + +private: int _top, _bottom; int _initValue, _newValue; }; -//================================================================================= -// class : SMESHGUI_doubleParameter -// purpose : -//================================================================================= +/*! + * \brief This class provides parameter with double value + */ class SMESHGUI_doubleParameter: public SMESHGUI_aParameter { public: @@ -108,35 +119,324 @@ public: virtual bool GetNewInt( int & Value ) const; virtual bool GetNewDouble( double & Value ) const; virtual bool GetNewText( QString & Value ) const; + virtual QWidget* CreateWidget( QWidget* ) const; virtual void InitializeWidget( QWidget* ) const; virtual void TakeValue( QWidget* ); - private: + virtual QString sigValueChanged() const; + +private: double _top, _bottom, _step; double _initValue, _newValue; int _decimals; }; - -//================================================================================= -// class : SMESHGUI_strParameter -// purpose : -//================================================================================= +/*! + * \brief This class provides parameter with string value + */ class SMESHGUI_strParameter: public SMESHGUI_aParameter { public: - SMESHGUI_strParameter(const QString& initValue = "", - const QString& label = QString::null); - QString InitValue() { return _initValue; } + SMESHGUI_strParameter( const QString& initValue = "", + const QString& label = QString::null); + QString& InitValue() { return _initValue; } virtual Type GetType() const; virtual bool GetNewInt( int & Value ) const; virtual bool GetNewDouble( double & Value ) const; virtual bool GetNewText( QString & Value ) const; + virtual QWidget* CreateWidget( QWidget* ) const; virtual void InitializeWidget( QWidget* ) const; virtual void TakeValue( QWidget* ); - private: + virtual QString sigValueChanged() const; + +private: QString _initValue, _newValue; }; + +/*! + * \brief This class represents the base parameter which contains dependency of + * shown state of other parameters on value of current + */ +class SMESHGUI_dependParameter: public SMESHGUI_aParameter +{ +public: + /*! + * \brief This map describes what parameters must be shown when this parameter has value as key + * The list contains some indices of parameters (for example, order in some list) + * Value is integer based 0. If map is empty, it means that there is no dependencies. + */ + typedef QValueList< int > IntList; + typedef QMap< int, IntList > ShownMap; + +public: + SMESHGUI_dependParameter( const QString& = QString::null ); + + const ShownMap& shownMap() const; + ShownMap& shownMap(); + +private: + ShownMap myShownMap; +}; + +/*! + * \brief This class represents parameter which can have value from fixed set + */ +class SMESHGUI_enumParameter: public SMESHGUI_dependParameter +{ +public: + /*! + * \brief Creates parameter with set of values 'values', default value 'init' and title 'label' + * Every value can be described both by integer based 0 or by string value + */ + SMESHGUI_enumParameter( const QStringList& values, + const int init = 0, + const QString& label = QString::null ); + virtual ~SMESHGUI_enumParameter(); + + /*! + * \brief Returns count of possible values + */ + int Count() const; + + int& InitValue() { return myInitValue; } + virtual Type GetType() const; + virtual bool GetNewInt( int& ) const; + virtual bool GetNewDouble( double& ) const; + virtual bool GetNewText( QString& ) const; + virtual QWidget* CreateWidget( QWidget* ) const; + virtual void InitializeWidget( QWidget* ) const; + virtual void TakeValue( QWidget* ); + + virtual QString sigValueChanged() const; + +private: + int myInitValue, myValue; + QStringList myValues; +}; + + +/*! + * \brief This class represents parameter which can have value true or false + */ +class SMESHGUI_boolParameter: public SMESHGUI_dependParameter +{ +public: + SMESHGUI_boolParameter( const bool = false, + const QString& = QString::null ); + virtual ~SMESHGUI_boolParameter(); + + bool& InitValue() { return myInitValue; } + virtual Type GetType() const; + virtual bool GetNewInt( int& ) const; + virtual bool GetNewDouble( double& ) const; + virtual bool GetNewText( QString& ) const; + virtual QWidget* CreateWidget( QWidget* ) const; + virtual void InitializeWidget( QWidget* ) const; + virtual void TakeValue( QWidget* ); + + virtual QString sigValueChanged() const; + +private: + bool myInitValue, myValue; +}; + + +class QButton; + +/*! + * \brief This class represents custom table. It has only double values and + editor for every cell has validator + */ +class SMESHGUI_Table : public QTable +{ + Q_OBJECT + +public: + SMESHGUI_Table( int numRows, int numCols, QWidget* = 0, const char* = 0 ); + virtual ~SMESHGUI_Table(); + +/*! + * \brief Hides current editor of cell + */ + void stopEditing(); + + virtual QSize sizeHint() const; + +/*! + * \brief Returns parameters of double validator corresponding to cell (row,col) + */ + void validator( const int row, const int col, double&, double&, int& ); + +/*! + * \brief Sets the double validator parameters to every cell in row range [rmin,rmax] + * and column range [cmin,cmax]. + * If rmin=-1 then rmin is set to 0, if rmax=-1 then rmax = last row. + * Analogically cmin and cmax are set + */ + void setValidator( const double, const double, const int, + const int rmin = -1, const int rmax = -1, + const int cmin = -1, const int cmax = -1 ); +}; + + +/*! + * \brief This class represents frame for table and buttons + */ +class SMESHGUI_TableFrame : public QFrame +{ + Q_OBJECT + +public: +/*! + * \brief Values corresponding to buttons for table resize + */ + typedef enum { ADD_COLUMN, REMOVE_COLUMN, ADD_ROW, REMOVE_ROW } Button; + +public: + SMESHGUI_TableFrame( QWidget* ); + ~SMESHGUI_TableFrame(); + + SMESHGUI_Table* table() const; + +/*! + * \brief Changes shown state of some button for table resize + */ + void setShown( const Button, const bool ); + +/*! + * \brief Returns shown state of some button for table resize + */ + bool isShown( const Button ) const; + +private: + QButton* button( const Button ) const; + +private slots: + void onButtonClicked(); + +signals: +/*! + * \brief This signal is emitted if some of button for table resize is clicked + * Second parameter is current column for ADD_COLUMN, REMOVE_COLUMN buttons + * and current row for ADD_ROW, REMOVE_ROW buttons. Take into account that + * this object resize table ( returned by table() ) automatically + */ + void toEdit( SMESHGUI_TableFrame::Button, int ); + +private: + QButton *myAddColumn, *myRemoveColumn, *myAddRow, *myRemoveRow; + SMESHGUI_Table* myTable; +}; + + +/*! + * \brief This class represents parameter which can have two-dimensional array of values + */ +class SMESHGUI_tableParameter: public QObject, public SMESHGUI_aParameter +{ + Q_OBJECT + +public: +/*! + * \brief Creates table parameter with default value 'init' and title 'label'. + * The default value means that by default the table is filled with default value + * and if new column or row is added then it is filled with default value + */ + SMESHGUI_tableParameter( const double init = 0.0, + const QString& label = QString::null ); + virtual ~SMESHGUI_tableParameter(); + + virtual Type GetType() const; + virtual bool GetNewInt( int& ) const; + virtual bool GetNewDouble( double& ) const; + virtual bool GetNewText( QString& ) const; + virtual QWidget* CreateWidget( QWidget* ) const; + virtual void InitializeWidget( QWidget* ) const; + virtual void TakeValue( QWidget* ); + +/*! + * \brief Updates look of widget in accordance with all parameters of this object + */ + void update( QWidget* ) const; + +/*! + * \brief Returns data taken from widget. Please don't forget to call TakeValue before. + */ + void data( SMESH::double_array& ) const; + +/*! + * \brief Sets data. The InitializeWidget must be called in order to change values in widget + */ + void setData( const SMESH::double_array& ); + +/*! + * \brief Sets count of columns and updates widget + */ + void setColCount( const int, QWidget* = 0 ); + +/*! + * \brief Sets count of rows and updates widget + */ + void setRowCount( const int, QWidget* = 0 ); + +/*! + * \brief Binds count of columns to some parameter and updates widget. Take into account that + * if this parameter is changed, the update() must be called to resize table + */ + void setColCount( const SMESHGUI_aParameterPtr, QWidget* = 0 ); + +/*! + * \brief Binds count of rows to some parameter and updates widget. Take into account that + * if this parameter is changed, the update() must be called to resize table + */ + void setRowCount( const SMESHGUI_aParameterPtr, QWidget* = 0 ); + +/*! + * \brief Enables or disables to change count of columns by buttons + */ + void setEditCols( const bool ); + +/*! + * \brief Enables or disables to change count of rows by buttons + */ + void setEditRows( const bool ); + + virtual QString sigValueChanged() const; + + void setValidator( const int col, const double, const double, const int ); + void validator( const int col, double&, double&, int& ) const; + +/*! + * \brief These methods allow to read and change name of column + */ + void setColName( const int, const QString& ); + QString colName( const int ) const; + +private slots: + void onEdit( SMESHGUI_TableFrame::Button, int ); + +private: + void setItems( QWidget*, int = -1, int = -1, int = -1, int = -1 ) const; + +private: + typedef struct + { + double myMin, myMax; + int myDecimals; + } ValidatorInfo; + + typedef QMap ValidatorsMap; + +private: + int myColsInt, myRowsInt; + SMESHGUI_aParameterPtr myCols, myRows; + double myInitValue; + SMESH::double_array myData; + ValidatorsMap myValidators; + bool myEditCols, myEditRows; + QMap< int, QString > myColNames; +}; + #endif // SMESHGUI_aParameter.h