Version: 6.3.1

src/Qtx/QtxResourceMgr.h

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  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 // File:      QtxResourceMgr.h
00024 // Author:    Alexander SOLOVYOV, Sergey TELKOV
00025 //
00026 #ifndef QTXRESOURCEMGR_H
00027 #define QTXRESOURCEMGR_H
00028 
00029 #include "Qtx.h"
00030 
00031 #ifndef QTX_NO_INDEXED_MAP
00032 #include "QtxMap.h"
00033 #endif
00034 
00035 #include <QMap>
00036 #include <QList>
00037 #include <QFont>
00038 #include <QColor>
00039 #include <QPixmap>
00040 #include <QByteArray>
00041 #include <QStringList>
00042 #include <QLinearGradient>
00043 #include <QRadialGradient>
00044 #include <QConicalGradient>
00045 
00046 class QTranslator;
00047 
00048 #ifdef WIN32
00049 #pragma warning( disable:4251 )
00050 #endif
00051 
00052 class QTX_EXPORT QtxResourceMgr
00053 {
00054   class IniFormat;
00055   class XmlFormat;
00056   class Resources;
00057 
00058 public:
00059   class Format;
00060 
00061 #ifdef QTX_NO_INDEXED_MAP
00062   typedef QMap<QString, QString> Section;   
00063 #else
00064   typedef IMap<QString, QString> Section;   
00065 #endif
00066 
00068   typedef enum {
00069     AllowUserValues,       
00070     IgnoreUserValues       
00071   } WorkingMode;
00072 
00073 public:
00074   QtxResourceMgr( const QString&, const QString& = QString() );
00075   virtual ~QtxResourceMgr();
00076 
00077   QString          appName() const;
00078   QStringList      dirList() const;
00079 
00080   bool             checkExisting() const;
00081   virtual void     setCheckExisting( const bool );
00082 
00083   bool             isPixmapCached() const;
00084   void             setIsPixmapCached( const bool );
00085 
00086   void             clear();
00087 
00088   WorkingMode      workingMode() const;
00089   void             setWorkingMode( WorkingMode );
00090 
00091   bool             value( const QString&, const QString&, int& ) const;
00092   bool             value( const QString&, const QString&, double& ) const;
00093   bool             value( const QString&, const QString&, bool& ) const;
00094   bool             value( const QString&, const QString&, QColor& ) const;
00095   bool             value( const QString&, const QString&, QFont& ) const;  
00096   bool             value( const QString&, const QString&, QByteArray& ) const;  
00097   bool             value( const QString&, const QString&, QLinearGradient& ) const;  
00098   bool             value( const QString&, const QString&, QRadialGradient& ) const;  
00099   bool             value( const QString&, const QString&, QConicalGradient& ) const;  
00100   bool             value( const QString&, const QString&, QString&, const bool = true ) const;
00101 
00102   int              integerValue( const QString&, const QString&, const int = 0 ) const;
00103   double           doubleValue( const QString&, const QString&, const double = 0 ) const;
00104   bool             booleanValue( const QString&, const QString&, const bool = false ) const;
00105   QFont            fontValue( const QString&, const QString&, const QFont& = QFont() ) const;
00106   QColor           colorValue( const QString&, const QString&, const QColor& = QColor() ) const;
00107   QString          stringValue( const QString&, const QString&, const QString& = QString() ) const;
00108   QByteArray       byteArrayValue( const QString&, const QString&, const QByteArray& = QByteArray() ) const;
00109   QLinearGradient  linearGradientValue( const QString&, const QString&, const QLinearGradient& = QLinearGradient() ) const;
00110   QRadialGradient  radialGradientValue( const QString&, const QString&, const QRadialGradient& = QRadialGradient() ) const;
00111   QConicalGradient conicalGradientValue( const QString&, const QString&, const QConicalGradient& = QConicalGradient() ) const;
00112 
00113   bool             hasSection( const QString& ) const;
00114   bool             hasValue( const QString&, const QString& ) const;
00115 
00116   void             setValue( const QString&, const QString&, const int );
00117   void             setValue( const QString&, const QString&, const double );
00118   void             setValue( const QString&, const QString&, const bool );
00119   void             setValue( const QString&, const QString&, const QFont& );
00120   void             setValue( const QString&, const QString&, const QColor& );
00121   void             setValue( const QString&, const QString&, const QString& );
00122   void             setValue( const QString&, const QString&, const QByteArray& );
00123   void             setValue( const QString&, const QString&, const QLinearGradient& );
00124   void             setValue( const QString&, const QString&, const QRadialGradient& );
00125   void             setValue( const QString&, const QString&, const QConicalGradient& );
00126 
00127   void             remove( const QString& );
00128   void             remove( const QString&, const QString& );
00129 
00130   QString          currentFormat() const;
00131   void             setCurrentFormat( const QString& );
00132 
00133   Format*          format( const QString& ) const;
00134   void             installFormat( Format* );
00135   void             removeFormat( Format* );
00136 
00137   QStringList      options() const;
00138   QString          option( const QString& ) const;
00139   void             setOption( const QString&, const QString& );
00140 
00141   QPixmap          defaultPixmap() const;
00142   virtual void     setDefaultPixmap( const QPixmap& );
00143 
00144   QString          resSection() const;
00145   QString          langSection() const;
00146   QString          sectionsToken() const;
00147 
00148   QPixmap          loadPixmap( const QString&, const QString& ) const;
00149   QPixmap          loadPixmap( const QString&, const QString&, const bool ) const;
00150   QPixmap          loadPixmap( const QString&, const QString&, const QPixmap& ) const;
00151   void             loadLanguage( const QString& = QString(), const QString& = QString() );
00152 
00153   void             raiseTranslators( const QString& );
00154   void             removeTranslators( const QString& );
00155   void             loadTranslator( const QString&, const QString& );
00156   void             loadTranslators( const QString&, const QStringList& );
00157 
00158   QString          path( const QString&, const QString&, const QString& ) const;
00159 
00160   bool             load();
00161   bool             import( const QString& );
00162   bool             save();
00163 
00164   QStringList      sections() const;
00165   QStringList      sections(const QRegExp&) const;
00166   QStringList      sections(const QStringList&) const;
00167   QStringList      subSections(const QString&, const bool = true) const;
00168   QStringList      parameters( const QString& ) const;
00169   QStringList      parameters( const QStringList& ) const;
00170 
00171   void             refresh();
00172 
00173 protected:
00174   virtual void     setDirList( const QStringList& );
00175   virtual void     setResource( const QString&, const QString&, const QString& );
00176 
00177   virtual QString  userFileName( const QString&, const bool = true ) const;
00178   virtual QString  globalFileName( const QString& ) const;
00179 
00180 private:
00181   void             initialize( const bool = true ) const;
00182   QString          substMacro( const QString&, const QMap<QChar, QString>& ) const;
00183 
00184 private:
00185   typedef QList<Resources*>        ResList;
00186   typedef QList<QTranslator*>      TransList;
00187   typedef QList<Format*>           FormatList;
00188   typedef QMap<QString, QString>   OptionsMap;
00189   typedef QMap<QString, TransList> TransListMap;
00190 
00191 private:
00192   QString          myAppName;                 
00193   QStringList      myDirList;                 
00194   FormatList       myFormats;                 
00195   OptionsMap       myOptions;                 
00196   ResList          myResources;               
00197   bool             myCheckExist;              
00198   TransListMap     myTranslator;              
00199   QPixmap*         myDefaultPix;              
00200   bool             myIsPixmapCached;          
00201 
00202   bool             myHasUserValues;           
00203   WorkingMode      myWorkingMode;             
00204 
00205   friend class QtxResourceMgr::Format;
00206 };
00207 
00208 class QTX_EXPORT QtxResourceMgr::Format
00209 {
00210 public:
00211   Format( const QString& );
00212   virtual ~Format();
00213 
00214   QString                format() const;
00215 
00216   QStringList            options() const;
00217   QString                option( const QString& ) const;
00218   void                   setOption( const QString&, const QString& );
00219 
00220   bool                   load( Resources* );
00221   bool                   save( Resources* );
00222 
00223 protected:
00224   virtual bool           load( const QString&, QMap<QString, Section>& ) = 0;
00225   virtual bool           save( const QString&, const QMap<QString, Section>& ) = 0;
00226 
00227 private:
00228   QString                myFmt;    
00229   QMap<QString, QString> myOpt;    
00230 };
00231 
00232 #endif // QTXRESOURCEMGR_H
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS