MagicSmoke
$VERSION$
|
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 MLocalFormat & | operator= (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 |
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:
%y | two-digit year (eg. 08) |
%Y | four-digit year (eg. 1908) |
%m | month as simple number (eg. 7) |
%M | month as two digit number (eg. 07) |
%n | short name of the month (eg. Jul) |
%N | long name of the month (eg. July) |
%d | day of the month as simple number (eg. 5) |
%D | day of the month as two digit number (eg. 05) |
%w | day of the week as short name (eg. Wed) |
%W | day of the week as long name (eg. Wednesday) |
time values can be formatted with the following variables:
%h | hour as simple number (eg. 7) in 24-hour format |
%H | hour as two digit number (eg. 07) in 24-hour format |
%a | hour as simple number (eg. 7) in 12-hour format |
%A | hour as two digit number (eg. 07) in 12-hour format |
%i | minute as simple number (eg. 7) |
%I | minute as two digit number (eg. 07) |
%s | second as simple number (eg. 7) |
%S | second as two digit number (eg. 07) |
%z | milli-seconds as simple number (eg. 7) |
%Z | milli-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 |
%T | ISO timezone as +/-hhmm (eg. -0100 or +0100) |
%t | ISO timezone as +/-hh:mm (eg. -01:00 or +01:00) |
%o | timezone as abbreviation - the abbreviation comes from the background time zone DB and is not globally unique (eg. "CET") |
%O | timezone 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".
MLocalFormat::MLocalFormat | ( | ) |
constructs a formatter object that corresponds to the default
References defaultformat, and operator=().
|
default |
copies a formatter object inheriting its overrides
MLocalFormat::MLocalFormat | ( | const MOServerFormat & | s | ) |
initializes the formatter object from a server format object
References MOServerFormat::amtext, MOServerFormat::currencysymbol, MOServerFormat::currencysymbolpos, MOServerFormat::dateformat, MOServerFormat::datetimeformat, MOServerFormat::decimaldot, defaultformat, MOServerFormat::moneydecimals, MOServerFormat::moneynegative, MOServerFormat::moneynegativepos, MOServerFormat::moneypositive, MOServerFormat::moneypositivepos, MOServerFormat::months, operator=(), MOServerFormat::pmtext, setAP(), setDateTimeFormat(), setMoneyFormat(), setMoneySign(), setMonths(), setNumberFormat(), setShortMonths(), setShortWeekDays(), setTimeZone(), setWeekDays(), MOServerFormat::shortmonths, MOServerFormat::shortweekdays, MOServerFormat::thousanddigits, MOServerFormat::thousandseparator, MOServerFormat::timeformat, MOServerFormat::timezone, and MOServerFormat::weekdays.
|
virtual |
deletes the formatter object
|
protected |
References setDateTimeFormat(), setMoneyFormat(), setMonths(), setNumberFormat(), setShortMonths(), setShortWeekDays(), and setWeekDays().
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
|
virtual |
formats a date according to the given format, if none is given, the translation default is used
date | a QDate used as input, it is assumed to be local |
format | a format string |
Referenced by formatDate(), and unix2date().
|
virtual |
formats a date according to the given format, if none is given, the translation default is used
date | a unix timestamp, it is converted to the local time of this local format object |
format | a format string |
References formatDate().
|
virtual |
formats a date according to the given format, if none is given, the translation default is used
date | a timestamp, it is converted to the local time of this local format object |
format | a format string |
References formatDateTime().
|
virtual |
formats a date and time according to the given format, if none is given, the translation default is used
time | a QDateTime used as input, it is assumed to be local |
format | a format string as specified by QDateTime::toString |
Referenced by formatDate(), formatDateTime(), formatTime(), and unix2dateTime().
|
virtual |
formats a date and time according to the given format, if none is given, the translation default is used
time | a unix timestamp, it is converted to local time |
format | a format string as specified by QDateTime::toString |
References formatDateTime().
|
virtual |
formats a date and time according to the given format, if none is given, the translation default is used
time | a TimeStamp used as input, it is converted to the local time of this local format object |
format | a format string as specified by QDateTime::toString |
|
virtual |
formats a money value
num | the amount in cents |
flags | determines how the string will be formatted |
Referenced by cent2str(), and formatMoney().
|
virtual |
formats a money value
num | the amount in cents |
usethousand | if true the thousand block division is inserted |
References formatMoney(), ShowCurrencySymbol, and UseThousand.
|
virtual |
formats an integer number
Referenced by formatNumber().
|
inlinevirtual |
|
inlinevirtual |
|
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
num | the number to be formatted |
decimals | the maximum number of digits after the decimal dot |
References formatNumber().
|
virtual |
formats a time according to the given format, if none is given, the translation default is used
time | a QTime used as input, it is assumed to be local |
format | a format string |
Referenced by formatTime(), and unix2time().
|
virtual |
formats a time according to the given format, if none is given, the translation default is used
time | a unix timestamp, it is converted to local time |
format | a format string |
References formatTime().
|
virtual |
formats a time according to the given format, if none is given, the translation default is used
time | a timestamp, it is converted to the local time of this local format object |
format | a 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
allownegative | if given the resulting RegExp allows to use negative values |
allowcurrency | if given the resulting RegExp allows to use the currency symbol |
Referenced by priceRegExp().
QStringList MLocalFormat::monthNames | ( | ) | const |
returns the names used for months
|
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 | |||
) |
|
virtual |
scans a floating point number and returns it, non-numerical chars are ignored
|
virtual |
scans an integer number and returns the value, non-numerical chars are ignored
|
virtual |
scans a money value and returns it in cents, non-numerical chars are ignored
Referenced by str2cent().
|
virtual |
overrides the formatting of the AM/PM part of time display, resets to the localization if none given
Referenced by MLocalFormat().
|
virtual |
overrides the default formatting of date and time, if empty the translation default is used
Referenced by MLocalFormat().
|
static |
|
virtual |
overrides the formatting of money - the settings of numbers are re-used
digitsCents | defines 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 |
currency | defines the symbol of the currency used, the default is an empty string |
symbolBehind | defines whether the currency symbol is shown before (false) or behind (true) the numeric value |
Referenced by MLocalFormat(), and setNonLocalized().
|
virtual |
overrides the formatting of money - the settings of numbers are re-used
negative | defines the sign for negative values, the default is "-" |
positive | defines the sign for positive values, the default is an empty string |
negativePos | defines where the negative sign is printed |
positivePos | defines where the positive sign is printed |
Referenced by MLocalFormat(), and setNonLocalized().
|
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().
|
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().
|
virtual |
overrides the formatting of numbers and money;
decimal | defines 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) |
thousandDiv | defines the character used to separate blocks of digits, if QChar() is used it returns to the translation default (comma "," in default) |
digitsDiv | defines the amount of digits in a block, eg. the value 3 will format 1000 as 1,000 (none per default) |
Referenced by MLocalFormat().
|
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().
|
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().
|
virtual |
overrides the local time zone
olsonname | the name of the local timezone in Olson notation, eg. "Europe/Berlin" |
Referenced by MLocalFormat().
|
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
|
virtual |
returns the currently set time zone of this formatter
QStringList MLocalFormat::weekDayNames | ( | ) | const |
returns the names used for week days
|
staticprotected |
Referenced by MLocalFormat(), and setDefaultFormat().