Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/gui.git] / src / QDS / QDS_Datum.h
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef QDS_DATUM_H
24 #define QDS_DATUM_H
25
26 #include "QDS.h"
27 #include <QPointer>
28 #include <QMap>
29 #include <QLabel>
30
31 class QHBoxLayout;
32 class QVBoxLayout;
33 class QGridLayout;
34 class QValidator;
35
36 #include <DDS_DicItem.h>
37
38 class QWidget;
39
40 class QDS_EXPORT QDS_Datum : public QObject, public QDS
41 {
42   Q_OBJECT
43
44   class Wrapper;
45
46 public:
47   QDS_Datum( const QString&, QWidget* = 0, const int = All, const QString& = QString() );
48   virtual ~QDS_Datum();
49
50   QString                   id() const;
51   int                       type() const;
52   QString                   label() const;
53   QString                   units() const;
54   QString                   filter() const;
55   QString                   format() const;
56   QString                   longDescription() const;
57   QString                   shortDescription() const;
58
59   QString                   defaultValue() const;
60   QString                   minimumValue() const;
61   QString                   maximumValue() const;
62
63   QStringList               options() const;
64   QVariant                  option( const QString& ) const;
65   QString                   optionString( const QString& ) const;
66   double                    optionDouble( const QString& ) const;
67   int                       optionInteger( const QString& ) const;
68
69   virtual QVariant          value() const;
70
71   virtual QString           stringValue() const;
72   virtual double            doubleValue() const;
73   virtual int               integerValue() const;
74
75   QString                   text() const;
76
77   virtual bool              isEmpty() const;
78
79   virtual void              reset();
80   virtual void              clear();
81
82   virtual void              setValue( const QVariant& );
83
84   virtual void              setStringValue( const QString& );
85   virtual void              setDoubleValue( const double );
86   virtual void              setIntegerValue( const int );
87
88   virtual bool              isEnabled( const int = Control ) const;
89   virtual void              setEnabled( const bool, const int );
90
91   void                      show( const int = All );
92   void                      hide( const int = All );
93   virtual void              setShown( const bool, const int = All );
94
95   QWidget*                  widget( const int ) const;
96   void                      setFocus();
97
98   virtual bool              isValid( const bool = true, 
99                                      const QString& = QString(),
100                                      const QString& = QString() ) const;
101   virtual QValidator*       validator( const bool = false ) const;
102
103   void                      addTo( QVBoxLayout* );
104   void                      addTo( QHBoxLayout* );
105   void                      addTo( QGridLayout*, const int, const int, const bool = false );
106
107   virtual void              setAlignment( const int, const int = Label );
108
109   static QString            unitsToText( const QString& );
110   static QString            textToUnits( const QString& );
111
112   static QString            format( const QString&, const QString&, const bool = false );
113   static QString            format( const int, const QString&, const bool = false );
114   static QString            format( const double, const QString&, const bool = false );
115   static QString            units( const QString& );
116
117   virtual bool              eventFilter( QObject*, QEvent* );
118
119   operator QWidget*() const;
120
121   bool isCustomTr() const;
122   void enableCustomTr( const bool );
123
124 signals:
125   void                      paramChanged();
126   void                      paramChanged( QString& );
127
128 public slots:
129   void                      setEnabled( bool );
130
131 protected slots:
132   virtual void              onParamChanged();
133
134 private slots:
135   void                      onInitDatum();
136   void                      onDestroyed( QObject* );
137
138 protected:
139   QLabel*                   labelWidget() const;
140   QLabel*                   unitsWidget() const;
141   QWidget*                  controlWidget() const;
142
143   Handle(DDS_DicItem)       dicItem() const;
144   void                      setDicItem( const Handle(DDS_DicItem)& );
145
146   int                       flags() const;
147
148   void                      invalidateCache();
149
150   virtual QLabel*           createLabel( QWidget* );
151   virtual QLabel*           createUnits( QWidget* );
152   virtual QWidget*          createControl( QWidget* ) = 0;
153
154   virtual QString           getString() const = 0;
155   virtual void              setString( const QString& ) = 0;
156
157   virtual bool              validate( const QString& ) const;
158
159   QString                   prefix() const;
160   QString                   suffix() const;
161   virtual QString           minValue() const;
162   virtual QString           maxValue() const;
163
164   static QString            format( const QString&, const int, const int );
165   static QString            format( const QString&, const int, const double );
166   static QString            format( const QString&, const int, const QString& );
167
168   static QString            sprintf( const QString&, const int );
169   static QString            sprintf( const QString&, const double );
170   static QString            sprintf( const QString&, const QString& );
171
172   virtual void              unitSystemChanged( const QString& );
173
174   void                      initDatum() const;
175
176 private:
177   void                      initialize();
178
179   Wrapper*                  wrapper( QWidget* ) const;
180   Wrapper*                  wrapper( const int ) const;
181   int                       wrapperType( Wrapper* ) const;
182
183   static QString            removeAccel( const QString& );
184   static bool               isDoubleFormat( const QString& );
185   static QString            canonicalFormat( const QString& );
186   static QString            canonicalFormat( const QString&, QString& );
187
188 private:
189   typedef QPointer<QLabel>  GuardedLabel;
190   typedef QPointer<QWidget> GuardedWidget;
191
192 private:
193   QString                   myId;
194   int                       myFlags;
195   Handle(DDS_DicItem)       myDicItem;
196   QMap<int, Wrapper*>       myWrapper;
197
198   GuardedLabel              myLabel;
199   GuardedLabel              myUnits;
200   GuardedWidget             myControl;
201
202   QString                   mySourceValue;
203   QString                   myTargetValue;
204
205   bool                      myInitialised, myTr;
206
207   friend class QDS;
208 };
209
210 #endif