Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

rtkformatter.h

00001 /*<<<<<COPYRIGHT*/
00002 /*
00003  * RTK The report toolkit
00004  * Copyright (C) 2003 Francisco Santiago Capel Torres
00005 
00006  * rtkformatter.h String and number formatting with locale
00007  * 
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  */
00019 /*>>>>>COPYRIGHT*/
00020 
00021 #ifndef RTKFORMATTER_H
00022 #define RTKFORMATTER_H
00023 
00024 #include <time.h>
00025 
00026 #include "rtknamespace.h"
00027 #include "rtkmoney.h"
00028 #include "rtkvariant.h"
00029 #include "rtkregconfig.h"
00030 
00031 namespace RTK
00032 {
00033 
00037 class Formatter
00038 {
00039 
00040 public:
00041         Formatter(const RegConfig &regcfg, char blank_char = ' ');
00042         
00043         String format(const String &text, const String &format, const String &mask) const;
00044         String format(int val, const String &format, const String &mask) const;
00045         String format(double val, const String &format, const String &mask) const;
00046         String format(const Money &val, const String &format, const String &mask) const;
00047         String format(const QDate &adate, const String &format, const String &mask) const;
00048         String format(const QTime &atime, const String &format, const String &mask) const;
00049         String format(const QDateTime &adatetime, const String &format, const String &mask) const;
00050         String format(const Variant &avalue, const String &format, 
00051                         const String &mask, Variant::Type valuetype = Variant::Invalid) const;
00052         
00053         int unMaskInt(const String &text, const String &mask) const;
00054         int unFormatInt(const String &text, const String &format) const;
00055         double unMaskDouble(const String &text, const String &mask) const;
00056         double unFormatDouble(const String &text, const String &format) const;
00057         Money unMaskMoney(const String &text, const String &mask) const;
00058         Money unFormatMoney(const String &text, const String &format) const;
00059         QDateTime unMaskDateTime(const String &text, const String &mask, Variant::Type valuetype = Variant::tDateTime ) const;
00060         QDateTime unFormatDateTime(const String &text, const String &format, Variant::Type valuetype = Variant::tDateTime ) const;
00061 
00062         String mask(const char *text, Variant::Type valuetype, const char *mask) const;
00063         String mask(int val, Variant::Type valuetype, const char *mask) const;
00064         String mask(double valValue, Variant::Type valuetype, const char *mask) const;
00065         String mask(const QDateTime &adate, Variant::Type valuetype, const char *mask) const;
00066         String mask(const Variant &avalue, Variant::Type valuetype, const char *mask) const;
00067 
00068         // formatea un texto y mantiene la posicion del cursor
00069         String mask_inedit(const char *origtext, Variant::Type valuetype, const char *mask,
00070                         int start_pos, int *position) const;
00071         
00072         void setBlankChar(char blank_char);
00073         char getBlankChar() const;
00074                 
00075 #ifdef MASK_TIMET       
00076         String mask(time_t adate, Variant::Type valuetype, const char *mask) const;
00077         String format(time_t adate, Variant::Type valuetype, const char *format, const char *mask) const;
00078         time_t unFormatTimeT(const char *text, Variant::Type valuetype, const char *format, const char *mask) const;
00079         time_t unMaskTimeT(const char *text, Variant::Type valuetype, const char *mask) const;
00080 #endif  
00081         
00082         
00083 private:
00084                 RegConfig mRegConfig;
00085         char mBlankChar;
00086 
00087         String formatLocaleCurrency(String text, double value) const;
00088         
00089         
00090         char maskalfa_nth(Variant::Type valuetype, const char *pmask, int pos) const;
00091         int maskalfa_len(const char *pmask) const;
00092         bool maskalfa_iseditable(Variant::Type valuetype, const char *pmask, int pos) const;
00093         int maskalfa_firsteditable(Variant::Type valuetype, const char *pmask) const;
00094         int maskalfa_previouseditable(Variant::Type valuetype, const char *pmask, int pos) const;
00095         int maskalfa_nexteditable(Variant::Type valuetype, const char *pmask, int pos) const;
00096         int maskalfa_lasteditable(Variant::Type valuetype, const char *pmask) const;
00097         char maskalfa_defaultchar(Variant::Type valuetype, const char *pmask, int pos) const;
00098         int maskalfa_match(Variant::Type valuetype, char text, const char *pmask, int pos) const;
00099         String maskalfa_mask(const char *text, Variant::Type valuetype, const char *mask,
00100                               int startpos=-1, int *position=NULL) const;
00101 
00102         String formatDate(const char *p_text, Variant::Type valuetype, const char *p_format, const char *p_mask) const;
00103 
00104         int masknum_match(Variant::Type valuetype, char text, char mask) const;
00105         char masknum_defaultchar(Variant::Type valuetype, char mask) const;
00106         char *masknum_dupmask(char *start, char *end, int maxlen) const;
00107         String masknum_mask(const char *text, Variant::Type valuetype, const char *mask, int startpos=-1, int *position=NULL) const;
00108 };
00109 
00110 }; // namespace
00111 
00112 #endif // RTKFORMATTER_H
00113 

Generated on Tue Feb 22 14:44:37 2005 for RTK. Report ToolKit by  doxygen 1.3.9.1