Back to index

salome-gui  6.5.0
QDS_Datum.h
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #ifndef QDS_DATUM_H
00024 #define QDS_DATUM_H
00025 
00026 #include "QDS.h"
00027 #include <QPointer>
00028 #include <QMap>
00029 #include <QLabel>
00030 
00031 class QHBoxLayout;
00032 class QVBoxLayout;
00033 class QGridLayout;
00034 class QValidator;
00035 
00036 #include <DDS_DicItem.h>
00037 
00038 class QWidget;
00039 
00040 class QDS_EXPORT QDS_Datum : public QObject, public QDS
00041 {
00042   Q_OBJECT
00043 
00044   class Wrapper;
00045 
00046 public:
00047   QDS_Datum( const QString&, QWidget* = 0, const int = All, const QString& = QString() );
00048   virtual ~QDS_Datum();
00049 
00050   QString                   id() const;
00051   int                       type() const;
00052   QString                   label() const;
00053   QString                   units() const;
00054   QString                   filter() const;
00055   QString                   format() const;
00056   QString                   longDescription() const;
00057   QString                   shortDescription() const;
00058 
00059   QString                   defaultValue() const;
00060   QString                   minimumValue() const;
00061   QString                   maximumValue() const;
00062 
00063   QStringList               options() const;
00064   QVariant                  option( const QString& ) const;
00065   QString                   optionString( const QString& ) const;
00066   double                    optionDouble( const QString& ) const;
00067   int                       optionInteger( const QString& ) const;
00068 
00069   virtual QVariant          value() const;
00070 
00071   virtual QString           stringValue() const;
00072   virtual double            doubleValue() const;
00073   virtual int               integerValue() const;
00074 
00075   QString                   text() const;
00076 
00077   virtual bool              isEmpty() const;
00078 
00079   virtual void              reset();
00080   virtual void              clear();
00081 
00082   virtual void              setValue( const QVariant& );
00083 
00084   virtual void              setStringValue( const QString& );
00085   virtual void              setDoubleValue( const double );
00086   virtual void              setIntegerValue( const int );
00087 
00088   virtual bool              isEnabled( const int = Control ) const;
00089   virtual void              setEnabled( const bool, const int );
00090 
00091   void                      show( const int = All );
00092   void                      hide( const int = All );
00093   virtual void              setShown( const bool, const int = All );
00094 
00095   QWidget*                  widget( const int ) const;
00096   void                      setFocus();
00097 
00098   virtual bool              isValid( const bool = true, 
00099                                      const QString& = QString(),
00100                                      const QString& = QString() ) const;
00101   virtual QValidator*       validator( const bool = false ) const;
00102 
00103   void                      addTo( QVBoxLayout* );
00104   void                      addTo( QHBoxLayout* );
00105   void                      addTo( QGridLayout*, const int, const int, const bool = false );
00106 
00107   virtual void              setAlignment( const int, const int = Label );
00108 
00109   static QString            unitsToText( const QString& );
00110   static QString            textToUnits( const QString& );
00111 
00112   static QString            format( const QString&, const QString&, const bool = false );
00113   static QString            format( const int, const QString&, const bool = false );
00114   static QString            format( const double, const QString&, const bool = false );
00115   static QString            units( const QString& );
00116 
00117   virtual bool              eventFilter( QObject*, QEvent* );
00118 
00119   operator QWidget*() const;
00120 
00121   bool isCustomTr() const;
00122   void enableCustomTr( const bool );
00123 
00124 signals:
00125   void                      paramChanged();
00126   void                      paramChanged( QString& );
00127 
00128 public slots:
00129   void                      setEnabled( bool );
00130 
00131 protected slots:
00132   virtual void              onParamChanged();
00133 
00134 private slots:
00135   void                      onInitDatum();
00136   void                      onDestroyed( QObject* );
00137 
00138 protected:
00139   QLabel*                   labelWidget() const;
00140   QLabel*                   unitsWidget() const;
00141   QWidget*                  controlWidget() const;
00142 
00143   Handle(DDS_DicItem)       dicItem() const;
00144   void                      setDicItem( const Handle(DDS_DicItem)& );
00145 
00146   int                       flags() const;
00147 
00148   void                      invalidateCache();
00149 
00150   virtual QLabel*           createLabel( QWidget* );
00151   virtual QLabel*           createUnits( QWidget* );
00152   virtual QWidget*          createControl( QWidget* ) = 0;
00153 
00154   virtual QString           getString() const = 0;
00155   virtual void              setString( const QString& ) = 0;
00156 
00157   virtual bool              validate( const QString& ) const;
00158 
00159   QString                   prefix() const;
00160   QString                   suffix() const;
00161   virtual QString           minValue() const;
00162   virtual QString           maxValue() const;
00163 
00164   static QString            format( const QString&, const int, const int );
00165   static QString            format( const QString&, const int, const double );
00166   static QString            format( const QString&, const int, const QString& );
00167 
00168   static QString            sprintf( const QString&, const int );
00169   static QString            sprintf( const QString&, const double );
00170   static QString            sprintf( const QString&, const QString& );
00171 
00172   virtual void              unitSystemChanged( const QString& );
00173 
00174   void                      initDatum() const;
00175 
00176 private:
00177   void                      initialize();
00178 
00179   Wrapper*                  wrapper( QWidget* ) const;
00180   Wrapper*                  wrapper( const int ) const;
00181   int                       wrapperType( Wrapper* ) const;
00182 
00183   static QString            removeAccel( const QString& );
00184   static bool               isDoubleFormat( const QString& );
00185   static QString            canonicalFormat( const QString& );
00186   static QString            canonicalFormat( const QString&, QString& );
00187 
00188 private:
00189   typedef QPointer<QLabel>  GuardedLabel;
00190   typedef QPointer<QWidget> GuardedWidget;
00191 
00192 private:
00193   QString                   myId;
00194   int                       myFlags;
00195   Handle(DDS_DicItem)       myDicItem;
00196   QMap<int, Wrapper*>       myWrapper;
00197 
00198   GuardedLabel              myLabel;
00199   GuardedLabel              myUnits;
00200   GuardedWidget             myControl;
00201 
00202   QString                   mySourceValue;
00203   QString                   myTargetValue;
00204 
00205   bool                      myInitialised, myTr;
00206 
00207   friend class QDS;
00208 };
00209 
00210 #endif