SciDAVis
1.D4
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
scidavis
src
future
core
datatypes
DateTime2StringFilter.h
Go to the documentation of this file.
1
/***************************************************************************
2
File : DateTime2StringFilter.h
3
Project : SciDAVis
4
--------------------------------------------------------------------
5
Copyright : (C) 2007 by Tilman Benkert,
6
Knut Franke
7
Email (use @ for *) : thzs*gmx.net, knut.franke*gmx.de
8
Description : Conversion filter QDateTime -> QString.
9
10
***************************************************************************/
11
12
/***************************************************************************
13
* *
14
* This program is free software; you can redistribute it and/or modify *
15
* it under the terms of the GNU General Public License as published by *
16
* the Free Software Foundation; either version 2 of the License, or *
17
* (at your option) any later version. *
18
* *
19
* This program is distributed in the hope that it will be useful, *
20
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
21
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22
* GNU General Public License for more details. *
23
* *
24
* You should have received a copy of the GNU General Public License *
25
* along with this program; if not, write to the Free Software *
26
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
27
* Boston, MA 02110-1301 USA *
28
* *
29
***************************************************************************/
30
#ifndef DATE_TIME2STRING_FILTER_H
31
#define DATE_TIME2STRING_FILTER_H
32
33
#include "
core/AbstractSimpleFilter.h
"
34
#include <QDateTime>
35
#include <QRegExp>
36
37
class
DateTime2StringFilterSetFormatCmd
;
38
40
class
DateTime2StringFilter
:
public
AbstractSimpleFilter
41
{
42
Q_OBJECT
43
44
public
:
46
explicit
DateTime2StringFilter
(QString
format
=
"yyyy-MM-dd hh:mm:ss.zzz"
) :
d_format
(
format
) {}
48
void
setFormat
(
const
QString&
format
);
49
51
55
QString
format
()
const
{
return
d_format
; }
56
58
virtual
SciDAVis::ColumnDataType
dataType
()
const
{
return
SciDAVis::TypeQString
; }
59
60
signals:
61
void
formatChanged
();
62
63
private
:
64
friend
class
DateTime2StringFilterSetFormatCmd
;
66
QString
d_format
;
67
68
public
:
69
virtual
QString
textAt
(
int
row)
const
{
70
if
(!
d_inputs
.value(0))
return
QString();
71
QDateTime input_value =
d_inputs
.value(0)->dateTimeAt(row);
72
if
(!input_value.date().isValid() && input_value.time().isValid())
73
input_value.setDate(QDate(1900,1,1));
74
#if QT_VERSION < 0x040302 // the bug seems to be fixed in Qt 4.3.2
75
// QDate::toString produces shortened year numbers for "yyyy"
76
// in violation of ISO 8601 and ambiguous with respect to "yy" format
77
QString
format
(
d_format
);
78
format.replace(
"yyyy"
,
"YYYYyyyyYYYY"
);
79
QString result = input_value.toString(format);
80
result.replace(QRegExp(
"YYYY(-)?(\\d\\d\\d\\d)YYYY"
),
"\\1\\2"
);
81
result.replace(QRegExp(
"YYYY(-)?(\\d\\d\\d)YYYY"
),
"\\10\\2"
);
82
result.replace(QRegExp(
"YYYY(-)?(\\d\\d)YYYY"
),
"\\100\\2"
);
83
result.replace(QRegExp(
"YYYY(-)?(\\d)YYYY"
),
"\\1000\\2"
);
84
return
result;
85
#else
86
return
input_value.toString(
d_format
);
87
#endif
88
}
89
91
92
virtual
void
writeExtraAttributes
(QXmlStreamWriter * writer)
const
;
93
virtual
bool
load
(
XmlStreamReader
* reader);
95
96
protected
:
98
virtual
bool
inputAcceptable
(
int
,
const
AbstractColumn
*source) {
99
return
source->
dataType
() ==
SciDAVis::TypeQDateTime
;
100
}
101
};
102
103
class
DateTime2StringFilterSetFormatCmd
:
public
QUndoCommand
104
{
105
public
:
106
DateTime2StringFilterSetFormatCmd
(
DateTime2StringFilter
* target,
const
QString &new_format);
107
108
virtual
void
redo
();
109
virtual
void
undo
();
110
111
private
:
112
DateTime2StringFilter
*
d_target
;
113
QString
d_other_format
;
114
};
115
116
#endif // ifndef DATE_TIME2STRING_FILTER_H
117
Generated by
1.8.1