1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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, or (at your option) any later version.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File: QtxResourceMgr.h
24 // Author: Alexander SOLOVYOV, Sergey TELKOV
26 #ifndef QTXRESOURCEMGR_H
27 #define QTXRESOURCEMGR_H
31 #ifndef QTX_NO_INDEXED_MAP
41 #include <QStringList>
42 #include <QLinearGradient>
43 #include <QRadialGradient>
44 #include <QConicalGradient>
49 #pragma warning( disable:4251 )
52 class QTX_EXPORT QtxResourceMgr
61 #ifdef QTX_NO_INDEXED_MAP
62 typedef QMap<QString, QString> Section; //!< resource section
64 typedef IMap<QString, QString> Section; //!< resource section
67 //! Working mode; defines a way how resource manager handles user preferences
69 AllowUserValues, //!< User values are processed by the resource manager
70 IgnoreUserValues //!< User values are ignored by the resource manager
74 QtxResourceMgr( const QString&, const QString& = QString() );
75 virtual ~QtxResourceMgr();
77 QString appName() const;
78 QStringList dirList() const;
80 bool checkExisting() const;
81 virtual void setCheckExisting( const bool );
83 bool isPixmapCached() const;
84 void setIsPixmapCached( const bool );
88 WorkingMode workingMode() const;
89 void setWorkingMode( WorkingMode );
91 bool value( const QString&, const QString&, int& ) const;
92 bool value( const QString&, const QString&, double& ) const;
93 bool value( const QString&, const QString&, bool& ) const;
94 bool value( const QString&, const QString&, QColor& ) const;
95 bool value( const QString&, const QString&, QFont& ) const;
96 bool value( const QString&, const QString&, QByteArray& ) const;
97 bool value( const QString&, const QString&, QLinearGradient& ) const;
98 bool value( const QString&, const QString&, QRadialGradient& ) const;
99 bool value( const QString&, const QString&, QConicalGradient& ) const;
100 bool value( const QString&, const QString&, Qtx::BackgroundData& ) const;
101 bool value( const QString&, const QString&, QString&, const bool = true ) const;
103 int integerValue( const QString&, const QString&, const int = 0 ) const;
104 double doubleValue( const QString&, const QString&, const double = 0 ) const;
105 bool booleanValue( const QString&, const QString&, const bool = false ) const;
106 QFont fontValue( const QString&, const QString&, const QFont& = QFont() ) const;
107 QColor colorValue( const QString&, const QString&, const QColor& = QColor() ) const;
108 QString stringValue( const QString&, const QString&, const QString& = QString() ) const;
109 QByteArray byteArrayValue( const QString&, const QString&, const QByteArray& = QByteArray() ) const;
110 QLinearGradient linearGradientValue( const QString&, const QString&, const QLinearGradient& = QLinearGradient() ) const;
111 QRadialGradient radialGradientValue( const QString&, const QString&, const QRadialGradient& = QRadialGradient() ) const;
112 QConicalGradient conicalGradientValue( const QString&, const QString&, const QConicalGradient& = QConicalGradient() ) const;
113 Qtx::BackgroundData backgroundValue( const QString&, const QString&, const Qtx::BackgroundData& = Qtx::BackgroundData() ) const;
115 bool hasSection( const QString& ) const;
116 bool hasValue( const QString&, const QString& ) const;
118 void setValue( const QString&, const QString&, const int );
119 void setValue( const QString&, const QString&, const double );
120 void setValue( const QString&, const QString&, const bool );
121 void setValue( const QString&, const QString&, const QFont& );
122 void setValue( const QString&, const QString&, const QColor& );
123 void setValue( const QString&, const QString&, const QString& );
124 void setValue( const QString&, const QString&, const QByteArray& );
125 void setValue( const QString&, const QString&, const QLinearGradient& );
126 void setValue( const QString&, const QString&, const QRadialGradient& );
127 void setValue( const QString&, const QString&, const QConicalGradient& );
128 void setValue( const QString&, const QString&, const Qtx::BackgroundData& );
130 void remove( const QString& );
131 void remove( const QString&, const QString& );
133 QString currentFormat() const;
134 void setCurrentFormat( const QString& );
136 Format* format( const QString& ) const;
137 void installFormat( Format* );
138 void removeFormat( Format* );
140 QStringList options() const;
141 QString option( const QString& ) const;
142 void setOption( const QString&, const QString& );
144 QPixmap defaultPixmap() const;
145 virtual void setDefaultPixmap( const QPixmap& );
147 QString resSection() const;
148 QString langSection() const;
149 QString sectionsToken() const;
151 QPixmap loadPixmap( const QString&, const QString& ) const;
152 QPixmap loadPixmap( const QString&, const QString&, const bool ) const;
153 QPixmap loadPixmap( const QString&, const QString&, const QPixmap& ) const;
154 void loadLanguage( const QString& = QString(), const QString& = QString() );
156 void raiseTranslators( const QString& );
157 void removeTranslators( const QString& );
158 void loadTranslator( const QString&, const QString& );
159 void loadTranslators( const QString&, const QStringList& );
161 QString path( const QString&, const QString&, const QString& ) const;
164 bool import( const QString& );
167 QStringList sections() const;
168 QStringList sections(const QRegExp&) const;
169 QStringList sections(const QStringList&) const;
170 QStringList subSections(const QString&, const bool = true) const;
171 QStringList parameters( const QString& ) const;
172 QStringList parameters( const QStringList& ) const;
177 virtual void setDirList( const QStringList& );
178 virtual void setResource( const QString&, const QString&, const QString& );
180 virtual QString userFileName( const QString&, const bool = true ) const;
181 virtual QString globalFileName( const QString& ) const;
183 virtual void saved();
186 void initialize( const bool = true ) const;
187 QString substMacro( const QString&, const QMap<QChar, QString>& ) const;
190 typedef QList<Resources*> ResList;
191 typedef QList<QTranslator*> TransList;
192 typedef QList<Format*> FormatList;
193 typedef QMap<QString, QString> OptionsMap;
194 typedef QMap<QString, TransList> TransListMap;
197 QString myAppName; //!< application name
198 QStringList myDirList; //!< list of resources directories
199 FormatList myFormats; //!< list of formats
200 OptionsMap myOptions; //!< options map
201 ResList myResources; //!< resources list
202 bool myCheckExist; //!< "check existance" flag
203 TransListMap myTranslator; //!< map of loaded translators
204 QPixmap* myDefaultPix; //!< default icon
205 bool myIsPixmapCached; //!< "cached pixmaps" flag
207 bool myHasUserValues; //!< \c true if user preferences has been read
208 WorkingMode myWorkingMode; //!< working mode
210 friend class QtxResourceMgr::Format;
213 class QTX_EXPORT QtxResourceMgr::Format
216 Format( const QString& );
219 QString format() const;
221 QStringList options() const;
222 QString option( const QString& ) const;
223 void setOption( const QString&, const QString& );
225 bool load( Resources* );
226 bool save( Resources* );
229 virtual bool load( const QString&, QMap<QString, Section>& ) = 0;
230 virtual bool save( const QString&, const QMap<QString, Section>& ) = 0;
233 QString myFmt; //!< format name
234 QMap<QString, QString> myOpt; //!< options map
237 #endif // QTXRESOURCEMGR_H