OpendTect-6_4  6.4
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
uiString Class Reference

Public Member Functions

 uiString ()
 
 uiString (const uiString &)
 no copy, ref counted More...
 
 ~uiString ()
 
uiStringset (const char *)
 
bool isSet () const
 
bool isEmpty () const
 
void setEmpty ()
 
uiStringtoLower (bool yn=true)
 
bool operator! () const
 
uiStringoperator= (const uiString &)
 no copy, ref counted More...
 
bool operator> (const uiString &b) const
 
bool operator< (const uiString &b) const
 
int size () const
 
template<class T >
uiStringarg (const T &var)
 
uiStringarg (const uiString &)
 
uiStringappend (const char *, bool withnewline=false)
 
uiStringappend (const OD::String &, bool withnewline=false)
 
uiStringappend (const uiString &, bool withnewline=false)
 
const OD::StringgetFullString (BufferString *=0) const
 
wchar_t * createWCharString () const
 
const char * getOriginalString () const
 
const ::QString & getQString () const
 
const ::QString & fillQString (QString &) const
 
void getHexEncoded (BufferString &) const
 
bool setFromHexEncoded (const char *)
 
 uiString (const char *)
 
 uiString (const OD::String &)
 
uiStringoperator= (const char *)
 
uiStringoperator= (const OD::String &)
 
bool operator== (const uiString &b) const
 Don't use, will force crash. Only here to keep TypeSet happy. More...
 
bool operator!= (const uiString &b) const
 Don't use, will force crash. Only here to keep TypeSet happy. More...
 
bool isEqualTo (const uiString &oth) const
 Do use, but only if unavoidable. More...
 
void makeIndependent ()
 If data is shared, I'll get an own copy. More...
 
 uiString (const char *original, const char *context, const char *application, const char *disambiguation, int pluralnr)
 
void setFrom (const ::QString &)
 
void addLegacyVersion (const uiString &)
 
bool translate (const ::QTranslator &,::QString &) const
 Returns true if the translation succeeded. More...
 
uiStringaddSpace (int nr=1)
 

Static Public Member Functions

static const uiStringemptyString ()
 
static const char * sODLocalizationApplication ()
 
static uiString getOrderString (int)
 

Private Member Functions

bool isCacheValid () const
 Reads hex-data and sets the translated str. More...
 
const ::QString & getQStringInternal () const
 

Static Private Member Functions

static uiString tr (const char *text, const char *disambiguation=0, int pluralnr=-1)
 
static uiString legacyTr (const char *text, const char *disambiguation=0, int pluralnr=-1)
 

Private Attributes

uiStringDatadata_
 
Threads::Lock datalock_
 Protects data_ variable. More...
 

Static Private Attributes

static const uiString emptystring_
 

Friends

class uiStringData
 

Detailed Description

String that is able to hold wide character strings for the user interface. These strings can be in different encodings and should only be used to pass text to the ui.

The string may have an original string encoded in ASCI characters, but that should only be used for object names and similar.

If the string holds N arguments, these can be replaced by arguments:

uiString string = toUiString( "%1 plus %2 is %3")
.arg( 4 )
.arg( 5 )
.arg( 4+5 );

Will result in the string "4 plus 5 is 9"

Note
As multiple uiStrings may use the same underlying data (if they are constructed with the copy constructor or the equal operator, they are not suited for other types of string operations than passing messages to the user.

The translation in OpendTect is done using Qt's subsystem for localization. A class that wishes to enable localization should:

  1. Declare the mTextTranslationClass(classname,application) in its class definition. The application is a string that identifies your application. OpendTect's internal classes use the "od" applicaiton string, and can for short use the mODTextTranslationClass macro.
  2. Use the tr() function for all translatable string. The tr() function returns a uiString() that can be passed to the ui.
  3. For functions not belonging to a class, use the od_static_tr function. Any function matching the *_static_tr will be interpreted by lupdate.
  4. Use Qt's lupdate to scan your code for localization strings. This will generate a .ts file which can be editded with Qt's Linguist program to translate the strings.
  5. The updated .ts file should be converted to a binary .qm file using Qt's lrelease application.
  6. The .qm file should be placed in data/localizations/<application>_<lang>_<country>.ts in the release. For example, a localization of OpendTect to traditional Chinese/Taiwan would be saved as od_zh_TW.qm.

Constructor & Destructor Documentation

uiString::uiString ( )
uiString::uiString ( const uiString )

no copy, ref counted

uiString::~uiString ( )
uiString::uiString ( const char *  )
uiString::uiString ( const OD::String )
uiString::uiString ( const char *  original,
const char *  context,
const char *  application,
const char *  disambiguation,
int  pluralnr 
)

Member Function Documentation

void uiString::addLegacyVersion ( const uiString )

If this string was previously known by another origial string, it can be added here. This is normally done with the legacyTr function.

uiString str = tr("New version");
str.addLegacyVersion( legacyTr("Old ver") );
uiString& uiString::addSpace ( int  nr = 1)
uiString& uiString::append ( const char *  ,
bool  withnewline = false 
)

append() functions are used to concatenate entire sentences. Otherwise you'll be in trouble because you will not know in what order args end up after translation. 'withnewline' will only add one if the first string is not empty.

uiString& uiString::append ( const OD::String ,
bool  withnewline = false 
)
uiString& uiString::append ( const uiString ,
bool  withnewline = false 
)
template<class T >
uiString & uiString::arg ( const T &  var)
inline

uiStrings should only be manipulated using the arg() functions. These replace the next N (e.g. %1) with the provided argument.

uiString& uiString::arg ( const uiString )
wchar_t* uiString::createWCharString ( ) const

The translation. Result becomes owner's and should be deleted using the [] operator.

static const uiString& uiString::emptyString ( )
inlinestatic
const :: QString& uiString::fillQString ( QString &  ) const

Fully thread-safe. Returns input

const OD::String& uiString::getFullString ( BufferString = 0) const

Results: Full string, without translation result is in a thread-safe static buffer, so copy the result before calling again. If BufferString is given, it will be filled, and static buffer won't be used.

void uiString::getHexEncoded ( BufferString ) const

Encodes translated string into a const char* buffer that can has only 0-9 A-F

static uiString uiString::getOrderString ( int  )
static
const char* uiString::getOriginalString ( ) const
const :: QString& uiString::getQString ( ) const

Returns reference, so could be unsafe

const :: QString& uiString::getQStringInternal ( ) const
private
bool uiString::isCacheValid ( ) const
private

Reads hex-data and sets the translated str.

bool uiString::isEmpty ( ) const
bool uiString::isEqualTo ( const uiString oth) const

Do use, but only if unavoidable.

bool uiString::isSet ( ) const
inline
static uiString uiString::legacyTr ( const char *  text,
const char *  disambiguation = 0,
int  pluralnr = -1 
)
inlinestaticprivate
void uiString::makeIndependent ( )

If data is shared, I'll get an own copy.

bool uiString::operator! ( ) const
inline
bool uiString::operator!= ( const uiString b) const
inline

Don't use, will force crash. Only here to keep TypeSet happy.

bool uiString::operator< ( const uiString b) const
uiString& uiString::operator= ( const uiString )

no copy, ref counted

uiString& uiString::operator= ( const char *  )
uiString& uiString::operator= ( const OD::String )

Don't use. May be depreciated. Use toUiString("My text") function instead.

bool uiString::operator== ( const uiString b) const

Don't use, will force crash. Only here to keep TypeSet happy.

bool uiString::operator> ( const uiString b) const
uiString& uiString::set ( const char *  )
void uiString::setEmpty ( )
void uiString::setFrom ( const ::QString &  )

Set the translated text no further translation will be done.

bool uiString::setFromHexEncoded ( const char *  )
int uiString::size ( ) const
static const char* uiString::sODLocalizationApplication ( )
inlinestatic
uiString& uiString::toLower ( bool  yn = true)

Set output to lowercase, if allowed by language This is applied before eventual arguments.

static uiString uiString::tr ( const char *  text,
const char *  disambiguation = 0,
int  pluralnr = -1 
)
inlinestaticprivate
bool uiString::translate ( const ::QTranslator &  ,
::QString &   
) const

Returns true if the translation succeeded.

Friends And Related Function Documentation

friend class uiStringData
friend

Member Data Documentation

uiStringData* uiString::data_
mutableprivate
Threads::Lock uiString::datalock_
mutableprivate

Protects data_ variable.

const uiString uiString::emptystring_
staticprivate

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019