Back to index

salome-gui  6.5.0
QtxPreferenceMgr.h
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 // File:      QtxPreferenceMgr.h
00021 // Author:    Sergey TELKOV
00022 //
00023 #ifndef QTXPREFERENCEMGR_H
00024 #define QTXPREFERENCEMGR_H
00025 
00026 #ifdef WIN32
00027 #pragma warning( disable:4251 )
00028 #endif
00029 
00030 #include "Qtx.h"
00031 
00032 #include <QFont>
00033 #include <QIcon>
00034 #include <QColor>
00035 #include <QVariant>
00036 
00037 class QtxResourceMgr;
00038 class QtxPreferenceMgr;
00039 
00040 class QTX_EXPORT QtxPreferenceItem
00041 {
00042   class Updater;
00043 
00044 public:
00045   QtxPreferenceItem( QtxPreferenceItem* = 0 );
00046   QtxPreferenceItem( const QString&, QtxPreferenceItem* );
00047   QtxPreferenceItem( const QString&, const QString&, const QString&, QtxPreferenceItem* );
00048   virtual ~QtxPreferenceItem();
00049 
00050   int                       id() const;
00051   virtual int               rtti() const;
00052 
00053   QtxPreferenceItem*        rootItem() const;
00054   QtxPreferenceItem*        parentItem() const;
00055   QList<QtxPreferenceItem*> childItems( const bool = false ) const;
00056 
00057   int                       depth() const;
00058   int                       count() const;
00059   virtual bool              isEmpty() const;
00060 
00061   void                      appendItem( QtxPreferenceItem* );
00062   void                      removeItem( QtxPreferenceItem* );
00063   void                      insertItem( QtxPreferenceItem*, QtxPreferenceItem* = 0 );
00064 
00065   QIcon                     icon() const;
00066   QString                   title() const;
00067   void                      resource( QString&, QString& ) const;
00068 
00069   virtual void              setIcon( const QIcon& );
00070   virtual void              setTitle( const QString& );
00071   virtual void              setResource( const QString&, const QString& );
00072 
00073   virtual void              updateContents();
00074 
00075   QVariant                  option( const QString& ) const;
00076   void                      setOption( const QString&, const QVariant& );
00077 
00078   bool                      isEvaluateValues() const;
00079   void                      setEvaluateValues( const bool );
00080 
00081   virtual void              store() = 0;
00082   virtual void              retrieve() = 0;
00083 
00084   QString                   resourceValue() const;
00085   void                      setResourceValue( const QString& );
00086 
00087   QtxPreferenceItem*        findItem( const int, const bool = false ) const;
00088   QtxPreferenceItem*        findItem( const QString&, const bool = false ) const;
00089   QtxPreferenceItem*        findItem( const QString&, const int, const bool = false ) const;
00090 
00091   virtual QtxResourceMgr*   resourceMgr() const;
00092   virtual QtxPreferenceMgr* preferenceMgr() const;
00093 
00094   virtual void              activate();
00095   void                      ensureVisible();
00096 
00097   static int                RTTI();
00098 
00099 protected:
00100   int                       getInteger( const int = 0 ) const;
00101   double                    getDouble( const double = 0.0 ) const;
00102   bool                      getBoolean( const bool = false ) const;
00103   QColor                    getColor( const QColor& = QColor() ) const;
00104   QFont                     getFont( const QFont& = QFont() ) const;
00105   QString                   getString( const QString& = QString() ) const;
00106 
00107   void                      setInteger( const int );
00108   void                      setDouble( const double );
00109   void                      setBoolean( const bool );
00110   void                      setColor( const QColor& );
00111   void                      setFont( const QFont& );
00112   void                      setString( const QString& );
00113 
00114   virtual void              itemAdded( QtxPreferenceItem* );
00115   virtual void              itemRemoved( QtxPreferenceItem* );
00116   virtual void              itemChanged( QtxPreferenceItem* );
00117 
00118   virtual void              ensureVisible( QtxPreferenceItem* );
00119 
00120   void                      sendItemChanges();
00121 
00122   virtual void              triggerUpdate();
00123 
00124   virtual QVariant          optionValue( const QString& ) const;
00125   virtual void              setOptionValue( const QString&, const QVariant& );
00126 
00127 protected:
00128   typedef QList<QtxPreferenceItem*> ItemList;
00129 
00130 private:
00131   static int                generateId();
00132 
00133 private:
00134   int                       myId;
00135   QtxPreferenceItem*        myParent;
00136   ItemList                  myChildren;
00137 
00138   bool                      myEval;
00139   QIcon                     myIcon;
00140   QString                   myTitle;
00141   QString                   mySection;
00142   QString                   myParameter;
00143 };
00144 
00145 class QTX_EXPORT QtxPreferenceMgr : public QtxPreferenceItem
00146 {
00147 public:
00148   QtxPreferenceMgr( QtxResourceMgr* );
00149   virtual ~QtxPreferenceMgr();
00150 
00151   virtual QtxResourceMgr*   resourceMgr() const;
00152   virtual QtxPreferenceMgr* preferenceMgr() const;
00153 
00154   QVariant                  option( const int, const QString& ) const;
00155   void                      setOption( const int, const QString&, const QVariant& );
00156 
00157   virtual void              store();
00158   virtual void              retrieve();
00159 
00160   virtual void              update();
00161 
00162   virtual void              toBackup();
00163   virtual void              fromBackup();
00164 
00165 protected:
00166   typedef QMap<QtxPreferenceItem*, QString> ResourceMap;
00167 
00168   void                      resourceValues( QMap<int, QString>& ) const;
00169   void                      resourceValues( ResourceMap& ) const;
00170 
00171   void                      setResourceValues( QMap<int, QString>& ) const;
00172   void                      setResourceValues( ResourceMap& ) const;
00173 
00174   void                      differentValues( const QMap<int, QString>&, const QMap<int, QString>&,
00175                                              QMap<int, QString>&, const bool fromFirst = false ) const;
00176   void                      differentValues( const ResourceMap&, const ResourceMap&,
00177                                              ResourceMap&, const bool fromFirst = false ) const;
00178 
00179   virtual void              changedResources( const ResourceMap& );
00180 
00181 private:
00182   QtxResourceMgr*           myResMgr;
00183   ResourceMap               myBackup;
00184 };
00185 
00186 #ifdef WIN32
00187 #pragma warning( default:4251 )
00188 #endif
00189 
00190 #endif