]> SALOME platform Git repositories - modules/gui.git/blob - src/QDS/QDS_Datum.h
Salome HOME
9e3052ee3f6026b450358f7a77af50a5f20dcca5
[modules/gui.git] / src / QDS / QDS_Datum.h
1 // Copyright (C) 2005  CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/
18 //
19 #ifndef QDS_DATUM_H
20 #define QDS_DATUM_H
21
22 #include "QDS.h"
23
24 #include <qobject.h>
25 #include <qstring.h>
26 #include <qvariant.h>
27 #include <qguardedptr.h>
28
29 #include <DDS_DicItem.h>
30
31 class QLabel;
32 class QWidget;
33 class QValidator;
34 class QVBoxLayout;
35 class QHBoxLayout;
36 class QGridLayout;
37
38 class Handle(DDS_Dictionary);
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::null );
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   virtual QVariant          value() const;
64
65   virtual QString           stringValue() const;
66   virtual double            doubleValue() const;
67   virtual int               integerValue() const;
68
69   QString                   text() const;
70
71   virtual bool              isEmpty() const;
72
73   virtual void              reset();
74   virtual void              clear();
75
76   virtual void              setValue( const QVariant& );
77
78   virtual void              setStringValue( const QString& );
79   virtual void              setDoubleValue( const double );
80   virtual void              setIntegerValue( const int );
81
82   virtual bool              isEnabled( const int = Control ) const;
83   virtual void              setEnabled( const bool, const int );
84
85   void                      show( const int = -1 );
86   void                      hide( const int = -1 );
87   void                      setShown( const bool, const int = -1 );
88
89   QWidget*                  widget( const int ) const;
90   void                      setFocus();
91
92   virtual bool              isValid( const bool = true, 
93                                      const QString& = QString::null,
94                                      const QString& = QString::null ) const;
95   virtual QValidator*       validator( const bool = false ) const;
96
97   void                      addTo( QVBoxLayout* );
98   void                      addTo( QHBoxLayout* );
99   void                      addTo( QGridLayout*, const int, const int, const bool = false );
100
101   virtual void              setAlignment( const int, const int = Label );
102
103   static QString            unitsToText( const QString& );
104   static QString            textToUnits( const QString& );
105
106   static QString            format( const QString&, const QString&, const bool = false );
107   static QString            format( const int, const QString&, const bool = false );
108   static QString            format( const double, const QString&, const bool = false );
109   static QString            units( const QString& );
110
111   virtual bool              eventFilter( QObject*, QEvent* );
112
113   operator QWidget*() const;
114
115 signals:
116   void                      paramChanged();
117   void                      paramChanged( QString& );
118
119 public slots:
120   void                      setEnabled( bool );
121
122 protected slots:
123   virtual void              onParamChanged();
124
125 private slots:
126   void                      onInitDatum();
127   void                      onDestroyed( QObject* );
128
129 protected:
130   QLabel*                   labelWidget() const;
131   QLabel*                   unitsWidget() const;
132   QWidget*                  controlWidget() const;
133
134   Handle(DDS_DicItem)       dicItem() const;
135   void                      setDicItem( const Handle(DDS_DicItem)& );
136
137   int                       flags() const;
138
139   void                      invalidateCache();
140
141   virtual QLabel*           createLabel( QWidget* );
142   virtual QLabel*           createUnits( QWidget* );
143   virtual QWidget*          createControl( QWidget* ) = 0;
144
145   virtual QString           getString() const = 0;
146   virtual void              setString( const QString& ) = 0;
147
148   virtual bool              validate( const QString& ) const;
149
150   QString                   prefix() const;
151   QString                   suffix() const;
152   virtual QString           minValue() const;
153   virtual QString           maxValue() const;
154
155   static QString            format( const QString&, const int, const int );
156   static QString            format( const QString&, const int, const double );
157   static QString            format( const QString&, const int, const QString& );
158
159   static QString            sprintf( const QString&, const int );
160   static QString            sprintf( const QString&, const double );
161   static QString            sprintf( const QString&, const QString& );
162
163   virtual void              unitSystemChanged( const QString& );
164
165   void                      initDatum() const;
166
167 private:
168   void                      initialize();
169
170   Wrapper*                  wrapper( QWidget* ) const;
171   Wrapper*                  wrapper( const int ) const;
172   int                       wrapperType( Wrapper* ) const;
173
174   static QString            removeAccel( const QString& );
175   static bool               isDoubleFormat( const QString& );
176   static QString            canonicalFormat( const QString& );
177   static QString            canonicalFormat( const QString&, QString& );
178
179 private:
180   typedef QGuardedPtr<QLabel>  GuardedLabel;
181   typedef QGuardedPtr<QWidget> GuardedWidget;
182
183 private:
184   QString                   myId;
185   int                       myFlags;
186   Handle(DDS_DicItem)       myDicItem;
187   QMap<int, Wrapper*>       myWrapper;
188
189   GuardedLabel              myLabel;
190   GuardedLabel              myUnits;
191   GuardedWidget             myControl;
192
193   QString                   mySourceValue;
194   QString                   myTargetValue;
195
196   bool                      myInitialised;
197
198   friend class QDS;
199 };
200
201 #endif