MagicSmoke  $VERSION$
MLocalFormat Class Reference

localized formatter class for timestamps, numbers and money; per default it uses the local translation to format data, but can be overidden; More...

#include <misc.h>

Classes

class  Private
 

Public Types

enum  MoneyFlag { PlainMoneyFormat =0, UseThousand =1, ShowCurrencySymbol =2, DefaultFormat =UseThousand|ShowCurrencySymbol }
 

Public Member Functions

 MLocalFormat ()
 constructs a formatter object that corresponds to the default More...
 
 MLocalFormat (const MLocalFormat &)=default
 copies a formatter object inheriting its overrides More...
 
 MLocalFormat (const MOServerFormat &)
 initializes the formatter object from a server format object More...
 
virtual ~MLocalFormat ()
 deletes the formatter object More...
 
QString amText () const
 returns the text for AM in 12-hour clock format More...
 
QString currency () const
 returns the currency symbol More...
 
QString dateFormat () const
 returns the default format for dates More...
 
QString dateTimeFormat () const
 returns the default format for date/time More...
 
QChar decimalDot () const
 returns the decimal dot symbol More...
 
virtual QString formatDate (const QDate &date, QString format=QString()) const
 formats a date according to the given format, if none is given, the translation default is used More...
 
virtual QString formatDate (qint64 date, QString format=QString()) const
 formats a date according to the given format, if none is given, the translation default is used More...
 
virtual QString formatDate (const TimeStamp &date, QString format=QString()) const
 formats a date according to the given format, if none is given, the translation default is used More...
 
virtual QString formatDateTime (const QDateTime &time, QString format=QString()) const
 formats a date and time according to the given format, if none is given, the translation default is used More...
 
virtual QString formatDateTime (qint64 time, QString format=QString()) const
 formats a date and time according to the given format, if none is given, the translation default is used More...
 
virtual QString formatDateTime (const TimeStamp &time, QString format=QString()) const
 formats a date and time according to the given format, if none is given, the translation default is used More...
 
virtual QString formatMoney (qint64 num, MoneyFlags flags=DefaultFormat) const
 formats a money value More...
 
virtual QString formatMoney (qint64 num, bool usethousand) const
 formats a money value More...
 
virtual QString formatNumber (qint64) const
 formats an integer number More...
 
virtual QString formatNumber (int n) const
 formats an integer number More...
 
virtual QString formatNumber (uint n) const
 formats an integer number More...
 
virtual QString formatNumber (double num, uint decimals=4) const
 formats a floating point number, this version does not use exponential display, but adheres to the settings of local decimal dot and thousands block division More...
 
virtual QString formatTime (const QTime &time, QString format=QString()) const
 formats a time according to the given format, if none is given, the translation default is used More...
 
virtual QString formatTime (qint64 time, QString format=QString()) const
 formats a time according to the given format, if none is given, the translation default is used More...
 
virtual QString formatTime (const TimeStamp &time, QString format=QString()) const
 formats a time according to the given format, if none is given, the translation default is used More...
 
int moneyDecimals () const
 returns the amount of decimals in a money value More...
 
QString moneyNegativeSign () const
 returns the negative sign for money values More...
 
QString moneyPositiveSign () const
 returns the positive sign for money values More...
 
QRegExp moneyRegExp (bool allownegative=false, bool allowcurrency=false) const
 returns a regular expression matching money values More...
 
QStringList monthNames () const
 returns the names used for months More...
 
virtual MLocalFormatoperator= (const MLocalFormat &)=default
 copies a formatter object More...
 
QString pmText () const
 returns the text for PM in 12-hour clock format More...
 
 Q_DECLARE_FLAGS (MoneyFlags, MoneyFlag)
 
virtual double scanFloat (QString) const
 scans a floating point number and returns it, non-numerical chars are ignored More...
 
virtual qint64 scanInt (QString) const
 scans an integer number and returns the value, non-numerical chars are ignored More...
 
virtual qint64 scanMoney (QString) const
 scans a money value and returns it in cents, non-numerical chars are ignored More...
 
virtual void setAP (QString am="--", QString pm="--")
 overrides the formatting of the AM/PM part of time display, resets to the localization if none given More...
 
virtual void setDateTimeFormat (QString dateformat=QString(), QString timeformat=QString(), QString datetimeformat=QString())
 overrides the default formatting of date and time, if empty the translation default is used More...
 
virtual void setMoneyFormat (QString currency=QString(), int digitsCents=2, bool symbolBehind=true)
 overrides the formatting of money - the settings of numbers are re-used More...
 
virtual void setMoneySign (QString negative="-", QString positive=QString(), MOServerFormat::MoneyPos negativePos=MOServerFormat::SignBeforeNum, MOServerFormat::MoneyPos positivePos=MOServerFormat::NoSign)
 overrides the formatting of money - the settings of numbers are re-used More...
 
virtual void setMonths (const QStringList &l=QStringList())
 overrides the full names of months, an empty list resets to the local translation, otherwise the list must be exactly seven entries long and starts with January More...
 
virtual void setNonLocalized ()
 overrides the formatting to be non-localized, numbers use decimal dot and no thousand separator, no currency symbol and "-" as negative sign; otherwise things stay the same; this is a helper for the shortcut methods like cent2str More...
 
virtual void setNumberFormat (QChar decimal=QChar(), QChar thousandDiv=QChar(), int digitsDiv=-1)
 overrides the formatting of numbers and money; More...
 
virtual void setShortMonths (const QStringList &l=QStringList())
 overrides the short names of months, an empty list resets to the local translation, otherwise the list must be exactly seven entries long and starts with January (Jan) More...
 
virtual void setShortWeekDays (const QStringList &l=QStringList())
 overrides the short week day names, an empty list resets to the local translation, otherwise the list must be exactly seven entries long and starts with Sunday (Sun) More...
 
virtual void setTimeZone (QString olsonname)
 overrides the local time zone More...
 
virtual void setWeekDays (const QStringList &l=QStringList())
 overrides the full names of week days, an empty list resets to the local translation, otherwise the list must be exactly seven entries long and starts with Sunday More...
 
QStringList shortMonthNames () const
 returns the names used for months More...
 
QStringList shortWeekDayNames () const
 returns the abbreviations used for week days More...
 
int thousandDigits () const
 returns the amount of digits between thousand separators More...
 
QString thousandSeparator () const
 returns the thousand separator if used, otherwise an empty string More...
 
QString timeFormat () const
 returns the default format for times More...
 
virtual QString timeZone () const
 returns the currently set time zone of this formatter More...
 
QStringList weekDayNames () const
 returns the names used for week days More...
 

Static Public Member Functions

static void setDefaultFormat (const MLocalFormat &)
 sets a new default format More...
 

Protected Member Functions

 MLocalFormat (int)
 

Static Protected Attributes

static MLocalFormat defaultformat
 

Detailed Description

localized formatter class for timestamps, numbers and money; per default it uses the local translation to format data, but can be overidden;

date values can be formatted with the following variables:

%ytwo-digit year (eg. 08)
%Yfour-digit year (eg. 1908)
%mmonth as simple number (eg. 7)
%Mmonth as two digit number (eg. 07)
%nshort name of the month (eg. Jul)
%Nlong name of the month (eg. July)
%dday of the month as simple number (eg. 5)
%Dday of the month as two digit number (eg. 05)
%wday of the week as short name (eg. Wed)
%Wday of the week as long name (eg. Wednesday)

time values can be formatted with the following variables:

%hhour as simple number (eg. 7) in 24-hour format
%Hhour as two digit number (eg. 07) in 24-hour format
%ahour as simple number (eg. 7) in 12-hour format
%Ahour as two digit number (eg. 07) in 12-hour format
%iminute as simple number (eg. 7)
%Iminute as two digit number (eg. 07)
%ssecond as simple number (eg. 7)
%Ssecond as two digit number (eg. 07)
%zmilli-seconds as simple number (eg. 7)
%Zmilli-seconds as three digit number (eg. 007)
%p"am" or "pm" according to current time, this is the one set with setAP
%P"AM" or "PM" according to current time, this is toUpper executed on the one set with setAP
%TISO timezone as +/-hhmm (eg. -0100 or +0100)
%tISO timezone as +/-hh:mm (eg. -01:00 or +01:00)
%otimezone as abbreviation - the abbreviation comes from the background time zone DB and is not globally unique (eg. "CET")
%Otimezone as Olson name (eg. "Europe/Berlin")

Any occurrence of "%%" will be translated to a literal "%" sign.

For example "%w the %d'th of %N in the year of the lord %Y at %a:%I %P" will be formatted as "Sat 19'th of June in the year of the lord 2010 at 8:29 AM".

Member Enumeration Documentation

Enumerator
PlainMoneyFormat 
UseThousand 
ShowCurrencySymbol 
DefaultFormat 

Constructor & Destructor Documentation

MLocalFormat::MLocalFormat ( )

constructs a formatter object that corresponds to the default

References defaultformat, and operator=().

MLocalFormat::MLocalFormat ( const MLocalFormat )
default

copies a formatter object inheriting its overrides

MLocalFormat::~MLocalFormat ( )
virtual

deletes the formatter object

MLocalFormat::MLocalFormat ( int  )
protected

Member Function Documentation

QString MLocalFormat::amText ( ) const

returns the text for AM in 12-hour clock format

QString MLocalFormat::currency ( ) const

returns the currency symbol

QString MLocalFormat::dateFormat ( ) const

returns the default format for dates

QString MLocalFormat::dateTimeFormat ( ) const

returns the default format for date/time

QChar MLocalFormat::decimalDot ( ) const

returns the decimal dot symbol

QString MLocalFormat::formatDate ( const QDate &  date,
QString  format = QString() 
) const
virtual

formats a date according to the given format, if none is given, the translation default is used

Parameters
datea QDate used as input, it is assumed to be local
formata format string

Referenced by formatDate(), and unix2date().

QString MLocalFormat::formatDate ( qint64  date,
QString  format = QString() 
) const
virtual

formats a date according to the given format, if none is given, the translation default is used

Parameters
datea unix timestamp, it is converted to the local time of this local format object
formata format string

References formatDate().

QString MLocalFormat::formatDate ( const TimeStamp &  date,
QString  format = QString() 
) const
virtual

formats a date according to the given format, if none is given, the translation default is used

Parameters
datea timestamp, it is converted to the local time of this local format object
formata format string

References formatDateTime().

QString MLocalFormat::formatDateTime ( const QDateTime &  time,
QString  format = QString() 
) const
virtual

formats a date and time according to the given format, if none is given, the translation default is used

Parameters
timea QDateTime used as input, it is assumed to be local
formata format string as specified by QDateTime::toString

Referenced by formatDate(), formatDateTime(), formatTime(), and unix2dateTime().

QString MLocalFormat::formatDateTime ( qint64  time,
QString  format = QString() 
) const
virtual

formats a date and time according to the given format, if none is given, the translation default is used

Parameters
timea unix timestamp, it is converted to local time
formata format string as specified by QDateTime::toString

References formatDateTime().

QString MLocalFormat::formatDateTime ( const TimeStamp &  time,
QString  format = QString() 
) const
virtual

formats a date and time according to the given format, if none is given, the translation default is used

Parameters
timea TimeStamp used as input, it is converted to the local time of this local format object
formata format string as specified by QDateTime::toString
virtual QString MLocalFormat::formatMoney ( qint64  num,
MoneyFlags  flags = DefaultFormat 
) const
virtual

formats a money value

Parameters
numthe amount in cents
flagsdetermines how the string will be formatted

Referenced by cent2str(), and formatMoney().

QString MLocalFormat::formatMoney ( qint64  num,
bool  usethousand 
) const
virtual

formats a money value

Parameters
numthe amount in cents
usethousandif true the thousand block division is inserted

References formatMoney(), ShowCurrencySymbol, and UseThousand.

QString MLocalFormat::formatNumber ( qint64  n) const
virtual

formats an integer number

Referenced by formatNumber().

virtual QString MLocalFormat::formatNumber ( int  n) const
inlinevirtual

formats an integer number

References formatNumber().

Referenced by formatNumber().

virtual QString MLocalFormat::formatNumber ( uint  n) const
inlinevirtual

formats an integer number

References formatNumber().

Referenced by formatNumber().

QString MLocalFormat::formatNumber ( double  num,
uint  decimals = 4 
) const
virtual

formats a floating point number, this version does not use exponential display, but adheres to the settings of local decimal dot and thousands block division

Parameters
numthe number to be formatted
decimalsthe maximum number of digits after the decimal dot

References formatNumber().

QString MLocalFormat::formatTime ( const QTime &  time,
QString  format = QString() 
) const
virtual

formats a time according to the given format, if none is given, the translation default is used

Parameters
timea QTime used as input, it is assumed to be local
formata format string

Referenced by formatTime(), and unix2time().

QString MLocalFormat::formatTime ( qint64  time,
QString  format = QString() 
) const
virtual

formats a time according to the given format, if none is given, the translation default is used

Parameters
timea unix timestamp, it is converted to local time
formata format string

References formatTime().

QString MLocalFormat::formatTime ( const TimeStamp &  time,
QString  format = QString() 
) const
virtual

formats a time according to the given format, if none is given, the translation default is used

Parameters
timea timestamp, it is converted to the local time of this local format object
formata format string

References formatDateTime().

int MLocalFormat::moneyDecimals ( ) const

returns the amount of decimals in a money value

QString MLocalFormat::moneyNegativeSign ( ) const

returns the negative sign for money values

QString MLocalFormat::moneyPositiveSign ( ) const

returns the positive sign for money values

QRegExp MLocalFormat::moneyRegExp ( bool  allownegative = false,
bool  allowcurrency = false 
) const

returns a regular expression matching money values

Parameters
allownegativeif given the resulting RegExp allows to use negative values
allowcurrencyif given the resulting RegExp allows to use the currency symbol

Referenced by priceRegExp().

QStringList MLocalFormat::monthNames ( ) const

returns the names used for months

virtual MLocalFormat& MLocalFormat::operator= ( const MLocalFormat )
virtualdefault

copies a formatter object

Referenced by MLocalFormat().

QString MLocalFormat::pmText ( ) const

returns the text for PM in 12-hour clock format

MLocalFormat::Q_DECLARE_FLAGS ( MoneyFlags  ,
MoneyFlag   
)
double MLocalFormat::scanFloat ( QString  num) const
virtual

scans a floating point number and returns it, non-numerical chars are ignored

qint64 MLocalFormat::scanInt ( QString  num) const
virtual

scans an integer number and returns the value, non-numerical chars are ignored

qint64 MLocalFormat::scanMoney ( QString  num) const
virtual

scans a money value and returns it in cents, non-numerical chars are ignored

Referenced by str2cent().

void MLocalFormat::setAP ( QString  am = "--",
QString  pm = "--" 
)
virtual

overrides the formatting of the AM/PM part of time display, resets to the localization if none given

Referenced by MLocalFormat().

void MLocalFormat::setDateTimeFormat ( QString  dateformat = QString(),
QString  timeformat = QString(),
QString  datetimeformat = QString() 
)
virtual

overrides the default formatting of date and time, if empty the translation default is used

Referenced by MLocalFormat().

void MLocalFormat::setDefaultFormat ( const MLocalFormat f)
static

sets a new default format

References defaultformat.

Referenced by MSInterface::initialize().

void MLocalFormat::setMoneyFormat ( QString  currency = QString(),
int  digitsCents = 2,
bool  symbolBehind = true 
)
virtual

overrides the formatting of money - the settings of numbers are re-used

Parameters
digitsCentsdefines how many digits are used for sub-amounts (cents), if zero no cents are used, normal are the values 0, 2 and 3; the default is 2
currencydefines the symbol of the currency used, the default is an empty string
symbolBehinddefines whether the currency symbol is shown before (false) or behind (true) the numeric value

Referenced by MLocalFormat(), and setNonLocalized().

void MLocalFormat::setMoneySign ( QString  negative = "-",
QString  positive = QString(),
MOServerFormat::MoneyPos  negativePos = MOServerFormat::SignBeforeNum,
MOServerFormat::MoneyPos  positivePos = MOServerFormat::NoSign 
)
virtual

overrides the formatting of money - the settings of numbers are re-used

Parameters
negativedefines the sign for negative values, the default is "-"
positivedefines the sign for positive values, the default is an empty string
negativePosdefines where the negative sign is printed
positivePosdefines where the positive sign is printed

Referenced by MLocalFormat(), and setNonLocalized().

void MLocalFormat::setMonths ( const QStringList &  l = QStringList())
virtual

overrides the full names of months, an empty list resets to the local translation, otherwise the list must be exactly seven entries long and starts with January

Referenced by MLocalFormat().

void MLocalFormat::setNonLocalized ( )
virtual

overrides the formatting to be non-localized, numbers use decimal dot and no thousand separator, no currency symbol and "-" as negative sign; otherwise things stay the same; this is a helper for the shortcut methods like cent2str

References setMoneyFormat(), and setMoneySign().

Referenced by cent2str(), priceRegExp(), str2cent(), unix2date(), unix2dateTime(), and unix2time().

void MLocalFormat::setNumberFormat ( QChar  decimal = QChar(),
QChar  thousandDiv = QChar(),
int  digitsDiv = -1 
)
virtual

overrides the formatting of numbers and money;

Parameters
decimaldefines the character used to separate decimals from the main body, if QChar() is used it returns to the translation default (a dot "." in default localization)
thousandDivdefines the character used to separate blocks of digits, if QChar() is used it returns to the translation default (comma "," in default)
digitsDivdefines the amount of digits in a block, eg. the value 3 will format 1000 as 1,000 (none per default)

Referenced by MLocalFormat().

void MLocalFormat::setShortMonths ( const QStringList &  l = QStringList())
virtual

overrides the short names of months, an empty list resets to the local translation, otherwise the list must be exactly seven entries long and starts with January (Jan)

Referenced by MLocalFormat().

void MLocalFormat::setShortWeekDays ( const QStringList &  l = QStringList())
virtual

overrides the short week day names, an empty list resets to the local translation, otherwise the list must be exactly seven entries long and starts with Sunday (Sun)

Referenced by MLocalFormat().

void MLocalFormat::setTimeZone ( QString  olsonname)
virtual

overrides the local time zone

Parameters
olsonnamethe name of the local timezone in Olson notation, eg. "Europe/Berlin"

Referenced by MLocalFormat().

void MLocalFormat::setWeekDays ( const QStringList &  l = QStringList())
virtual

overrides the full names of week days, an empty list resets to the local translation, otherwise the list must be exactly seven entries long and starts with Sunday

Referenced by MLocalFormat().

QStringList MLocalFormat::shortMonthNames ( ) const

returns the names used for months

QStringList MLocalFormat::shortWeekDayNames ( ) const

returns the abbreviations used for week days

int MLocalFormat::thousandDigits ( ) const

returns the amount of digits between thousand separators

QString MLocalFormat::thousandSeparator ( ) const

returns the thousand separator if used, otherwise an empty string

QString MLocalFormat::timeFormat ( ) const

returns the default format for times

QString MLocalFormat::timeZone ( ) const
virtual

returns the currently set time zone of this formatter

QStringList MLocalFormat::weekDayNames ( ) const

returns the names used for week days

Member Data Documentation

MLocalFormat MLocalFormat::defaultformat
staticprotected

Referenced by MLocalFormat(), and setDefaultFormat().


The documentation for this class was generated from the following files: