1
/***************************************************************************
2
File : DateTime2StringFilter.cpp
4
--------------------------------------------------------------------
5
Copyright : (C) 2007 by Tilman Benkert,
7
Email (use @ for *) : thzs*gmx.net, knut.franke*gmx.de
8
Description : Conversion filter QDateTime -> QString.
10
***************************************************************************/
12
/***************************************************************************
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. *
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. *
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 *
29
***************************************************************************/
31
#include "DateTime2StringFilter.h"
32
#include "lib/XmlStreamReader.h"
33
#include <QXmlStreamWriter>
35
void DateTime2StringFilter::setFormat(const QString& format)
37
exec(new DateTime2StringFilterSetFormatCmd(static_cast<DateTime2StringFilter*>(this), format));
40
DateTime2StringFilterSetFormatCmd::DateTime2StringFilterSetFormatCmd(DateTime2StringFilter* target, const QString &new_format)
41
: d_target(target), d_other_format(new_format)
43
if(d_target->parentAspect())
44
setText(QObject::tr("%1: set date-time format to %2").arg(d_target->parentAspect()->name()).arg(new_format));
46
setText(QObject::tr("set date-time format to %1").arg(new_format));
49
void DateTime2StringFilterSetFormatCmd::redo()
51
QString tmp = d_target->d_format;
52
d_target->d_format = d_other_format;
54
emit d_target->formatChanged();
57
void DateTime2StringFilterSetFormatCmd::undo()
62
void DateTime2StringFilter::writeExtraAttributes(QXmlStreamWriter * writer) const
64
writer->writeAttribute("format", format());
67
bool DateTime2StringFilter::load(XmlStreamReader * reader)
69
QXmlStreamAttributes attribs = reader->attributes();
70
QString str = attribs.value(reader->namespaceUri().toString(), "format").toString();
72
if (AbstractSimpleFilter::load(reader))
77
return !reader->hasError();