~valavanisalex/ubuntu/maverick/scidavis/fix-604811

« back to all changes in this revision

Viewing changes to scidavis/src/future/core/datatypes/DateTime2StringFilter.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ruben Molina
  • Date: 2009-09-06 11:34:04 UTC
  • Revision ID: james.westby@ubuntu.com-20090906113404-4awaey82l3686w4q
Tags: upstream-0.2.3
ImportĀ upstreamĀ versionĀ 0.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    File                 : DateTime2StringFilter.cpp
 
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
 
 
31
#include "DateTime2StringFilter.h"
 
32
#include "lib/XmlStreamReader.h"
 
33
#include <QXmlStreamWriter>
 
34
 
 
35
void DateTime2StringFilter::setFormat(const QString& format) 
 
36
 
37
        exec(new DateTime2StringFilterSetFormatCmd(static_cast<DateTime2StringFilter*>(this), format));
 
38
}
 
39
 
 
40
DateTime2StringFilterSetFormatCmd::DateTime2StringFilterSetFormatCmd(DateTime2StringFilter* target, const QString &new_format)
 
41
        : d_target(target), d_other_format(new_format) 
 
42
{
 
43
        if(d_target->parentAspect())
 
44
                setText(QObject::tr("%1: set date-time format to %2").arg(d_target->parentAspect()->name()).arg(new_format));
 
45
        else
 
46
                setText(QObject::tr("set date-time format to %1").arg(new_format));
 
47
}
 
48
 
 
49
void DateTime2StringFilterSetFormatCmd::redo() 
 
50
{
 
51
        QString tmp = d_target->d_format;
 
52
        d_target->d_format = d_other_format;
 
53
        d_other_format = tmp;
 
54
        emit d_target->formatChanged();
 
55
}
 
56
 
 
57
void DateTime2StringFilterSetFormatCmd::undo() 
 
58
 
59
        redo(); 
 
60
}
 
61
 
 
62
void DateTime2StringFilter::writeExtraAttributes(QXmlStreamWriter * writer) const
 
63
{
 
64
        writer->writeAttribute("format", format());
 
65
}
 
66
 
 
67
bool DateTime2StringFilter::load(XmlStreamReader * reader)
 
68
{
 
69
        QXmlStreamAttributes attribs = reader->attributes();
 
70
        QString str = attribs.value(reader->namespaceUri().toString(), "format").toString();
 
71
 
 
72
        if (AbstractSimpleFilter::load(reader))
 
73
                setFormat(str);
 
74
        else
 
75
                return false;
 
76
 
 
77
        return !reader->hasError();
 
78
}
 
79