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