MagicSmoke  $VERSION$
misc.h
Go to the documentation of this file.
1 //
2 // C++ Interface: misc
3 //
4 // Description: miscellaneous helper functions
5 //
6 //
7 // Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2008-2012
8 //
9 // Copyright: See README/COPYING.GPL files that come with this distribution
10 //
11 //
12 
13 #ifndef MAGICSMOKE_MISC_H
14 #define MAGICSMOKE_MISC_H
15 
16 #include <QDateTime>
17 #include <QString>
18 #include <QStringList>
19 #include <QRegExp>
20 
21 class TimeStamp;
22 #include <MOServerFormat>
23 #include <DPtrBase>
24 
25 #ifndef MSIFACE_EXPORT
26 #define MSIFACE_EXPORT Q_DECL_IMPORT
27 #endif
28 
30 QString MSIFACE_EXPORT htmlize(QString str);
31 
33 QString MSIFACE_EXPORT xmlize(QString str,QString newline="\n");
35 QByteArray MSIFACE_EXPORT xmlize(QByteArray str,QString newline="\n");
36 
38 QString MSIFACE_EXPORT cent2str(qint64 cent,bool localize=true);
39 
41 qint64 MSIFACE_EXPORT str2cent(QString s,bool fromlocal=true);
42 
44 QString MSIFACE_EXPORT unix2date(qint64,bool localize=true);
45 
47 QString MSIFACE_EXPORT unix2time(qint64,bool localize=true);
48 
50 QString MSIFACE_EXPORT unix2dateTime(qint64,bool localize=true);
51 
53 QRegExp MSIFACE_EXPORT priceRegExp(bool localize=true);
54 
56 QString MSIFACE_EXPORT currentDir();
57 
59 void MSIFACE_EXPORT setCurrentDir(QString);
60 
103 {
104  DECLARE_SHARED_DPTR(d);
105  public:
107  MLocalFormat();
109  MLocalFormat(const MLocalFormat&)=default;
113  virtual ~MLocalFormat();
114 
116  static void setDefaultFormat(const MLocalFormat&);
117 
119  virtual MLocalFormat& operator=(const MLocalFormat&)=default;
120 
122  virtual void setWeekDays(const QStringList&l=QStringList());
124  virtual void setShortWeekDays(const QStringList&l=QStringList());
125 
127  virtual void setMonths(const QStringList&l=QStringList());
129  virtual void setShortMonths(const QStringList&l=QStringList());
130 
136  virtual void setMoneyFormat(QString currency=QString(),int digitsCents=2, bool symbolBehind=true);
143  virtual void setMoneySign(QString negative="-",QString positive=QString(), MOServerFormat::MoneyPos negativePos=MOServerFormat::SignBeforeNum, MOServerFormat::MoneyPos positivePos=MOServerFormat::NoSign);
144 
149  virtual void setNumberFormat(QChar decimal=QChar(),QChar thousandDiv=QChar(),int digitsDiv=-1);
150 
152  virtual void setAP(QString am="--",QString pm="--");
153 
156  virtual void setTimeZone(QString olsonname);
157 
159  virtual void setDateTimeFormat(QString dateformat=QString(),QString timeformat=QString(),QString datetimeformat=QString());
160 
162  virtual QString timeZone()const;
163 
165  virtual void setNonLocalized();
166 
170  virtual QString formatDate(const QDate&date,QString format=QString())const;
174  virtual QString formatDate(qint64 date,QString format=QString())const;
178  virtual QString formatDate(const TimeStamp& date,QString format=QString())const;
179 
183  virtual QString formatTime(const QTime&time,QString format=QString())const;
187  virtual QString formatTime(qint64 time,QString format=QString())const;
191  virtual QString formatTime(const TimeStamp& time,QString format=QString())const;
192 
196  virtual QString formatDateTime(const QDateTime&time,QString format=QString())const;
200  virtual QString formatDateTime(qint64 time,QString format=QString())const;
204  virtual QString formatDateTime(const TimeStamp&time,QString format=QString())const;
205 
206 
208  virtual QString formatNumber(qint64)const;
210  virtual QString formatNumber(int n)const{return formatNumber(qint64(n));}
212  virtual QString formatNumber(uint n)const{return formatNumber(qint64(n));}
213 
217  virtual QString formatNumber(double num,uint decimals=4)const;
218 
219  enum MoneyFlag {
220  PlainMoneyFormat=0,
221  UseThousand=1,
222  ShowCurrencySymbol=2,
223 
224  DefaultFormat=UseThousand|ShowCurrencySymbol
225  };
226  Q_DECLARE_FLAGS(MoneyFlags,MoneyFlag);
227 
231  virtual QString formatMoney(qint64 num,MoneyFlags flags=DefaultFormat)const;
235  virtual QString formatMoney(qint64 num,bool usethousand)const;
236 
238  virtual qint64 scanInt(QString)const;
239 
241  virtual qint64 scanMoney(QString)const;
242 
244  virtual double scanFloat(QString)const;
245 
247  QStringList weekDayNames()const;
249  QStringList shortWeekDayNames()const;
250 
252  QStringList monthNames()const;
254  QStringList shortMonthNames()const;
255 
257  QString currency()const;
258 
260  QChar decimalDot()const;
261 
263  QString thousandSeparator()const;
264 
266  int thousandDigits()const;
267 
269  int moneyDecimals()const;
270 
272  QString amText()const;
274  QString pmText()const;
275 
277  QString moneyNegativeSign()const;
279  QString moneyPositiveSign()const;
280 
284  QRegExp moneyRegExp(bool allownegative=false,bool allowcurrency=false)const;
285 
287  QString dateFormat()const;
288 
290  QString timeFormat()const;
291 
293  QString dateTimeFormat()const;
294  protected:
296  MLocalFormat(int);
299 };
300 Q_DECLARE_OPERATORS_FOR_FLAGS(MLocalFormat::MoneyFlags);
301 
302 #endif
QString MSIFACE_EXPORT currentDir()
returns the current directory (the one last used in a file dialog)
Definition: misc.cpp:724
virtual QString formatNumber(uint n) const
formats an integer number
Definition: misc.h:212
QRegExp MSIFACE_EXPORT priceRegExp(bool localize=true)
return a (localized) regular expression that validates prices
Definition: misc.cpp:87
#define MSIFACE_EXPORT
Definition: misc.h:26
QString MSIFACE_EXPORT xmlize(QString str, QString newline="\n")
converts special XML characters into harmless &-codes, so the text can be included ...
Definition: misc.cpp:43
no sign is shown, regardless of what symbol is set
Definition: srcMOServerFormat.h:23
MoneyFlag
Definition: misc.h:219
MoneyPos
Position of the money sign in relation to number and currency symbol.
Definition: srcMOServerFormat.h:21
Q_DECLARE_OPERATORS_FOR_FLAGS(MLocalFormat::MoneyFlags)
QString MSIFACE_EXPORT cent2str(qint64 cent, bool localize=true)
converts a cent value into a (localized) string
Definition: misc.cpp:73
qint64 MSIFACE_EXPORT str2cent(QString s, bool fromlocal=true)
converts a (localized) string back into a cent value (must not contain spaces or extra dots) ...
Definition: misc.cpp:80
QString MSIFACE_EXPORT unix2dateTime(qint64, bool localize=true)
converts a unix timestamp into a date-time-string
Definition: misc.cpp:108
QString MSIFACE_EXPORT unix2date(qint64, bool localize=true)
converts a unix timestamp into a date
Definition: misc.cpp:94
virtual QString formatNumber(int n) const
formats an integer number
Definition: misc.h:210
the sign is shown before the numeric value
Definition: srcMOServerFormat.h:25
Transport class for server formatting settings. This is used by both UIs to format numbers...
Definition: srcMOServerFormat.h:15
QString MSIFACE_EXPORT unix2time(qint64, bool localize=true)
converts a unix timestamp into a time (ommitting the date)
Definition: misc.cpp:101
static MLocalFormat defaultformat
Definition: misc.h:298
QString MSIFACE_EXPORT htmlize(QString str)
converts special HTML characters into harmless &-codes, so the text can be included ...
Definition: misc.cpp:27
localized formatter class for timestamps, numbers and money; per default it uses the local translatio...
Definition: misc.h:102
void MSIFACE_EXPORT setCurrentDir(QString)
sets a new current directory (transparently handles files and directories)
Definition: misc.cpp:729