Changeset View
Changeset View
Standalone View
Standalone View
src/widget/utils/kexidatetimeformatter.h
Show All 24 Lines | |||||
25 | #include <QDate> | 25 | #include <QDate> | ||
26 | #include <QDateTime> | 26 | #include <QDateTime> | ||
27 | #include <QVariant> | 27 | #include <QVariant> | ||
28 | 28 | | |||
29 | //! @short Date formatter used by KexiDateTableEdit and KexiDateTimeTableEdit | 29 | //! @short Date formatter used by KexiDateTableEdit and KexiDateTimeTableEdit | ||
30 | class KEXIGUIUTILS_EXPORT KexiDateFormatter | 30 | class KEXIGUIUTILS_EXPORT KexiDateFormatter | ||
31 | { | 31 | { | ||
32 | public: | 32 | public: | ||
33 | //! Creates new formatter with KDE setting for "short date" | 33 | //! Creates new formatter for the current locale settings | ||
34 | KexiDateFormatter(); | 34 | KexiDateFormatter(); | ||
35 | 35 | | |||
36 | //! Creates new formatter with given settings | 36 | //! Creates new formatter with given settings | ||
37 | //! @todo KexiDateFormatter(... settings ...); | 37 | //! @todo KexiDateFormatter(... settings ...); | ||
38 | 38 | | |||
39 | ~KexiDateFormatter(); | 39 | ~KexiDateFormatter(); | ||
40 | 40 | | |||
41 | //! Converts string \a str to date using predefined settings. | 41 | //! Converts string \a str to date using predefined settings. | ||
42 | //! \return invalid date if the conversion is impossible | 42 | //! \return invalid date if the conversion is impossible | ||
43 | QDate fromString(const QString& str, bool *ok = nullptr) const; | 43 | QDate fromString(const QString& str) const; | ||
44 | 44 | | |||
45 | /*! Converts string \a str to date using predefined settings | 45 | /*! Converts string \a str to date using predefined settings | ||
46 | and returns QVariant containing the date value. | 46 | and returns QVariant containing the date value. | ||
47 | This method does the same as fromString(const QString&) but if \a string | 47 | This method does the same as fromString(const QString&) but if \a string | ||
48 | contains invalid date representation, e.g. contains only spaces | 48 | contains invalid date representation, e.g. contains only spaces | ||
49 | and separators, null QVariant() is returned. */ | 49 | and separators, null QVariant() is returned. */ | ||
50 | QVariant stringToVariant(const QString& str, bool *ok = nullptr) const; | 50 | QVariant stringToVariant(const QString& str) const; | ||
51 | 51 | | |||
52 | //! Converts \a date to string using predefined settings. | 52 | //! Converts \a date to string using predefined settings. | ||
53 | //! \return empty string if \a date is invalid | 53 | //! \return empty string if \a date is invalid | ||
54 | QString toString(const QDate& date) const; | 54 | QString toString(const QDate& date) const; | ||
55 | 55 | | |||
56 | //! \return Input mask generated using the formatter settings. | 56 | //! \return Input mask generated using the formatter settings. | ||
57 | //! Can be used in QLineEdit::setInputMask(). | 57 | //! Can be used in QLineEdit::setInputMask(). | ||
58 | QString inputMask() const; | 58 | QString inputMask() const; | ||
59 | 59 | | |||
60 | //! \return separator for this date format, a single character like "-" or "/" | | |||
61 | QString separator() const; | | |||
62 | | ||||
63 | //! \return true if \a str contains only spaces | 60 | //! \return true if \a str contains only spaces | ||
64 | //! and separators according to the date format. | 61 | //! and separators according to the date format. | ||
65 | bool isEmpty(const QString& str) const; | 62 | bool isEmpty(const QString& str) const; | ||
66 | 63 | | |||
67 | protected: | 64 | protected: | ||
68 | //! Order of date's components (day, month, year) | 65 | //! Order of date's components (day, month, year) | ||
69 | enum Order { DMY, MDY, YMD, YDM }; | 66 | enum Order { DMY, MDY, YMD, YDM }; | ||
70 | 67 | | |||
71 | private: | 68 | private: | ||
72 | class Private; | 69 | class Private; | ||
73 | Private * const d; | 70 | Private * const d; | ||
74 | }; | 71 | }; | ||
75 | 72 | | |||
76 | 73 | | |||
77 | /*! @short Time formatter used by KexiTimeTableEdit and KexiDateTimeTableEdit | 74 | /*! @short Time formatter used by KexiTimeTableEdit and KexiDateTimeTableEdit | ||
78 | Following time formats are allowed: HH:MM:SS (24h), HH:MM (24h), HH:MM AM/PM (12h) | 75 | Following time formats are allowed: HH:MM:SS (24h), HH:MM (24h), HH:MM AM/PM (12h) | ||
79 | Separator MUST be ":" */ | 76 | Separator MUST be ":" */ | ||
80 | class KEXIGUIUTILS_EXPORT KexiTimeFormatter | 77 | class KEXIGUIUTILS_EXPORT KexiTimeFormatter | ||
81 | { | 78 | { | ||
82 | public: | 79 | public: | ||
83 | //! Creates new formatter with KDE setting for time | 80 | //! Creates new formatter for the current locale settings | ||
84 | KexiTimeFormatter(); | 81 | KexiTimeFormatter(); | ||
85 | 82 | | |||
86 | //! Creates new formatter with given settings | 83 | //! Creates new formatter with given settings | ||
87 | //! @todo KexiDateFormatter(... settings ...); | 84 | //! @todo KexiDateFormatter(... settings ...); | ||
88 | 85 | | |||
89 | ~KexiTimeFormatter(); | 86 | ~KexiTimeFormatter(); | ||
90 | 87 | | |||
91 | //! converts string \a str to time using predefined settings | 88 | //! converts string \a str to time using predefined settings | ||
92 | //! \return invalid time if the conversion is impossible | 89 | //! \return invalid time if the conversion is impossible | ||
93 | QTime fromString(const QString& str) const; | 90 | QTime fromString(const QString& str) const; | ||
94 | 91 | | |||
95 | /*! Converts string \a str to time using predefined settings | 92 | /*! Converts string \a str to time using predefined settings | ||
96 | and returns QVariant containing the time value. | 93 | and returns QVariant containing the time value. | ||
97 | This method does the same as fromString(const QString&) but if \a string | 94 | This method does the same as fromString(const QString&) but if \a string | ||
98 | contains invalid time representation, e.g. contains only spaces | 95 | contains invalid time representation, e.g. contains only spaces | ||
99 | and separators, null QVariant() is returned and @a *ok is set to false. */ | 96 | and separators, null QVariant() is returned. */ | ||
100 | QVariant stringToVariant(const QString& str, bool *ok = nullptr); | 97 | QVariant stringToVariant(const QString& str); | ||
101 | 98 | | |||
102 | //! converts \a time to string using predefined settings | 99 | //! converts \a time to string using predefined settings | ||
103 | //! \return empty string if \a time is invalid | 100 | //! \return empty string if \a time is invalid | ||
104 | QString toString(const QTime& time) const; | 101 | QString toString(const QTime& time) const; | ||
105 | 102 | | |||
106 | //! \return Input mask generated using the formatter settings. | 103 | //! \return Input mask generated using the formatter settings. | ||
107 | //! Can be used in QLineEdit::setInputMask(). | 104 | //! Can be used in QLineEdit::setInputMask(). | ||
108 | QString inputMask() const; | 105 | QString inputMask() const; | ||
▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines |