QDomElement sect = doc.createElement( sectionTag() );
sect.setAttribute( nameAttribute(), it.key() );
root.appendChild( sect );
- for ( QMap<QString, QString>::ConstIterator iter = it.data().begin(); iter != it.data().end(); ++iter )
+ for ( Section::ConstIterator iter = it.data().begin(); iter != it.data().end(); ++iter )
{
QDomElement val = doc.createElement( parameterTag() );
val.setAttribute( nameAttribute(), iter.key() );
QtxResourceMgr* that = (QtxResourceMgr*)this;
- that->myResources.append( new Resources( userFileName( appName() ) ) );
+ if ( !userFileName( appName() ).isEmpty() )
+ that->myResources.append( new Resources( userFileName( appName() ) ) );
+
for ( QStringList::const_iterator it = myDirList.begin(); it != myDirList.end(); ++it )
{
QString path = Qtx::addSlash( *it ) + globalFileName( appName() );
return;
ResListIterator resIt( myResources );
- if ( resIt.current() )
+ if ( myResources.count() > myDirList.count() && resIt.current() ) {
resIt.current()->setFile( userFileName( appName() ) );
- ++resIt;
+ ++resIt;
+ }
for ( QStringList::const_iterator it = myDirList.begin(); it != myDirList.end() && resIt.current(); ++it, ++resIt )
resIt.current()->setFile( Qtx::addSlash( *it ) + globalFileName( appName() ) );
{
initialize();
- QMap<QString, int> map;
- for ( ResListIterator it( myResources ); it.current(); ++it )
- {
+#if defined(QTX_NO_INDEXED_MAP)
+ typedef QMap<QString, int> PMap;
+#else
+ typedef IMap<QString, int> PMap;
+#endif
+ PMap pmap;
+ ResListIterator it( myResources );
+ it.toLast();
+ for ( ; it.current(); --it ) {
QStringList lst = it.current()->parameters( sec );
for ( QStringList::const_iterator itr = lst.begin(); itr != lst.end(); ++itr )
- map.insert( *itr, 0 );
+ pmap.insert( *itr, 0, false );
}
QStringList res;
- for ( QMap<QString, int>::ConstIterator iter = map.begin(); iter != map.end(); ++iter )
+ for ( PMap::ConstIterator iter = pmap.begin(); iter != pmap.end(); ++iter )
res.append( iter.key() );
return res;
for ( QStringList::const_iterator it = trList.begin(); it != trList.end(); ++it )
trs.append( substMacro( *it, substMap ).stripWhiteSpace() );
- for ( QStringList::const_iterator itr = trs.begin(); itr != trs.end(); ++itr )
- loadTranslator( prefix, *itr );
+ loadTranslators( prefix, trs );
}
}
-void QtxResourceMgr::loadTranslator( const QString& prefix, const QString& name )
+void QtxResourceMgr::loadTranslators( const QString& prefix, const QStringList& translators )
{
initialize();
QTranslator* trans = 0;
- for ( ResListIterator it( myResources ); it.current() && !trans; ++it )
- trans = it.current()->loadTranslator( resSection(), prefix, name );
+ ResListIterator it( myResources );
+ it.toLast();
+ for ( ; it.current(); --it ) {
+ for ( QStringList::const_iterator itr = translators.begin(); itr != translators.end(); ++itr ) {
+ trans = it.current()->loadTranslator( resSection(), prefix, *itr );
+ if ( trans ) {
+ if ( !myTranslator[prefix].contains( trans ) )
+ myTranslator[prefix].append( trans );
+ qApp->installTranslator( trans );
+ }
+ }
+ }
+}
- if ( !trans )
- return;
+void QtxResourceMgr::loadTranslator( const QString& prefix, const QString& name )
+{
+ initialize();
- if ( !myTranslator[prefix].contains( trans ) )
- myTranslator[prefix].append( trans );
- qApp->installTranslator( trans );
+ QTranslator* trans = 0;
+ ResListIterator it( myResources );
+ it.toLast();
+ for ( ; it.current(); --it ) {
+ trans = it.current()->loadTranslator( resSection(), prefix, name );
+ if ( trans ) {
+ if ( !myTranslator[prefix].contains( trans ) )
+ myTranslator[prefix].append( trans );
+ qApp->installTranslator( trans );
+ }
+ }
}
void QtxResourceMgr::removeTranslators( const QString& prefix )
#include <qpixmap.h>
#include <qstringlist.h>
#include <qtranslator.h>
+#include <qvaluelist.h>
class QPixmap;
class XmlFormat;
class Resources;
+ template <class Key, class Value> class IMap;
+ template <class Key, class Value> class IMapConstIterator;
+ template <class Key, class Value> class IMapIterator
+ {
+ private:
+ IMap<Key,Value>* myMap;
+ int myIndex;
+
+ public:
+ IMapIterator() : myMap( 0 ), myIndex( 0 ) { init(); }
+ IMapIterator( const IMap<Key,Value>* m ) : myMap( const_cast< IMap<Key,Value>* >( m ) ), myIndex( 0 ) { init(); }
+ IMapIterator( const IMapIterator& i ) : myMap( i.myMap ), myIndex( i.myIndex ) { init(); }
+
+ bool operator==( const IMapIterator& i ) { return !operator!=( i ); }
+ bool operator!=( const IMapIterator& i ) { return !myMap || myMap != i.myMap || myIndex != i.myIndex; }
+
+ operator bool() const { return myIndex >= 0; }
+
+ const Key& key() const { return myMap->key( myIndex ); }
+ Value& data() { return myMap->value( myIndex ); }
+ const Value& data() const { return myMap->value( myIndex ); }
+
+ Value& operator*() { return data(); }
+
+ IMapIterator& operator++() { myIndex++; init(); return *this; }
+ IMapIterator operator++( int ) { IMapIterator i = *this; myIndex++; init(); return i; }
+ IMapIterator& operator--() { myIndex--; init(); return *this; }
+ IMapIterator operator--( int ) { IMapIterator i = *this; myIndex--; init(); return i; }
+
+ private:
+ IMapIterator( const IMap<Key,Value>* m, const int index ) : myMap( const_cast< IMap<Key,Value>* >( m ) ), myIndex( index ) { init(); }
+ void init() { if ( !myMap || myIndex >= myMap->count() ) myIndex = -1; }
+
+ friend class IMap<Key,Value>;
+ friend class IMapConstIterator<Key,Value>;
+ };
+
+ template <class Key, class Value> class IMapConstIterator
+ {
+ private:
+ IMap<Key,Value>* myMap;
+ int myIndex;
+
+ public:
+ IMapConstIterator() : myMap( 0 ), myIndex( 0 ) { init(); }
+ IMapConstIterator( const IMap<Key,Value>* m ) : myMap( const_cast< IMap<Key,Value>* >( m ) ), myIndex( 0 ) { init(); }
+ IMapConstIterator( const IMapConstIterator& i ) : myMap( i.myMap ), myIndex( i.myIndex ) { init(); }
+ IMapConstIterator( const IMapIterator<Key, Value>& i ) : myMap( i.myMap ), myIndex( i.myIndex ) { init(); }
+
+ bool operator==( const IMapConstIterator& i ) { return !operator!=( i ); }
+ bool operator!=( const IMapConstIterator& i ) { return !myMap || myMap != i.myMap || myIndex != i.myIndex; }
+
+ operator bool() const { return myIndex >= 0; }
+
+ const Key& key() const { return myMap->key( myIndex ); }
+ const Value& data () const { return myMap->value( myIndex ); }
+
+ const Value& operator*() const { return data(); }
+
+ IMapConstIterator& operator++() { myIndex++; init(); return *this; }
+ IMapConstIterator operator++( int ) { IMapConstIterator i = *this; myIndex++; init(); return i; }
+ IMapConstIterator& operator--() { myIndex--; init(); return *this; }
+ IMapConstIterator operator--( int ) { IMapConstIterator i = *this; myIndex--; init(); return i; }
+
+ private:
+ IMapConstIterator( const IMap<Key,Value>* m, const int index ): myMap( const_cast< IMap<Key,Value>* >( m ) ), myIndex( index ) { init(); }
+ void init() { if ( !myMap || myIndex >= myMap->count() ) myIndex = -1; }
+
+ friend class IMap<Key,Value>;
+ };
+
+ template <class Key, class Value> class IMap
+ {
+ private:
+ QValueList<Key> myKeys;
+ QMap<Key,Value> myData;
+ Key dummyKey;
+ Value dummyValue;
+
+ public:
+ typedef IMapIterator<Key,Value> Iterator;
+ typedef IMapConstIterator<Key,Value> ConstIterator;
+ friend class Iterator;
+ friend class ConstIterator;
+
+ IMap() {}
+ IMap( const IMap& m ) : myKeys( m.myKeys ), myData( m.myData ) {}
+ IMap& operator=( const IMap& m ) { myKeys = m.myKeys; myData = m.myData; return *this; }
+
+ int count() const { return myData.count(); }
+ int size() const { return myData.count(); }
+ bool empty() const { return myData.empty(); }
+ bool isEmpty() const { return myData.empty(); }
+
+ void clear() { myKeys.clear(); myData.clear(); }
+
+ QValueList<Key> keys() const { return myKeys; }
+ QValueList<Value> values() const { QValueList<Value> l; for ( int i = 0; i < count(); i++ ) l.append( value( i ) ); return l; }
+ bool contains ( const Key& key ) const { return myData.contains( key ); }
+
+ Iterator begin() { return Iterator( this ); }
+ Iterator end() { return Iterator( this, count() ); }
+ ConstIterator begin() const { return ConstIterator( this ); }
+ ConstIterator end() const { return ConstIterator( this, count() ); }
+
+ Iterator insert( const Key& key, const Value& value, bool overwrite = true )
+ {
+ if ( myData.find( key ) == myData.end() || overwrite ) {
+ if ( myData.find( key ) != myData.end() && overwrite )
+ myKeys.remove( myKeys.find( key ) );
+ myKeys.append( key );
+ myData[ key ] = value;
+ }
+ return Iterator( this, index( key ) );
+ }
+ Iterator replace( const Key& key, const Value& value )
+ {
+ if ( myData.find( key ) == myData.end() )
+ myKeys.append( key );
+ myData[ key ] = value;
+ return Iterator( this, index( key ) );
+ }
+
+ int index( const Key& key ) const { return myKeys.findIndex( key ); }
+ Iterator at( const int index ) { return Iterator( this, index ); }
+ ConstIterator at( const int index ) const { return ConstIterator( this, index ); }
+
+ Key& key( const int index )
+ {
+ if( index < 0 || index >= myKeys.count() )
+ return dummyKey;
+ return myKeys[index];
+ }
+ Value& value( const int index )
+ {
+ if( index < 0 || index >= myKeys.count() )
+ return dummyValue;
+ return myData[ myKeys[index] ];
+ }
+ Value& operator[]( const Key& key )
+ {
+ if ( myData.find( key ) == myData.end() )
+ insert( key, Value() );
+ return myData[ key ];
+ }
+ const Value& operator[]( const Key& key ) const
+ {
+ if ( myData.find( key ) == myData.end() )
+ return dummyValue;
+ return myData[ key ];
+ }
+
+ void erase( Iterator it ) { remove( it ); }
+ void erase( const Key& key ) { remove( key ); }
+ void erase( const int index ) { remove( index ); }
+ void remove( Iterator it ) { if ( it.myMap != this ) return; remove( it.myIndex ); }
+ void remove( const Key& key ) { remove( index( key ) ); }
+ void remove( const int index )
+ {
+ if( index >= 0 && index < myKeys.count() ) {
+ myData.remove( myKeys[ index ] );
+ myKeys.remove( myKeys.at( index ) );
+ }
+ }
+ };
+
public:
class Format;
+#if defined(QTX_NO_INDEXED_MAP)
typedef QMap<QString, QString> Section;
+#else
+ typedef IMap<QString, QString> Section;
+#endif
public:
QtxResourceMgr( const QString&, const QString& = QString::null );
void raiseTranslators( const QString& );
void removeTranslators( const QString& );
void loadTranslator( const QString&, const QString& );
+ void loadTranslators( const QString&, const QStringList& );
QString path( const QString&, const QString&, const QString& ) const;