SciDAVis  1.D4
String2DateTimeFilter.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : String2DateTimeFilter.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 QString -> QDateTime.
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 STRING2DATE_TIME_FILTER_H
31 #define STRING2DATE_TIME_FILTER_H
32 
34 #include <QDateTime>
35 #include <QDate>
36 #include <QTime>
37 
48 {
49  Q_OBJECT
50 
51  public:
53  explicit String2DateTimeFilter(QString format="yyyy-MM-dd hh:mm:ss.zzz") : d_format(format) {}
55  void setFormat(const QString& format);
57 
61  QString format() const { return d_format; }
62 
65 
67 
68  virtual void writeExtraAttributes(QXmlStreamWriter * writer) const;
69  virtual bool load(XmlStreamReader * reader);
71 
72  signals:
73  void formatChanged();
74 
75  private:
78  QString d_format;
79 
80  static const char * date_formats[];
81  static const char * time_formats[];
82 
83  public:
84  virtual QDateTime dateTimeAt(int row) const;
85  virtual QDate dateAt(int row) const { return dateTimeAt(row).date(); }
86  virtual QTime timeAt(int row) const { return dateTimeAt(row).time(); }
87  virtual bool isInvalid(int row) const {
88  const AbstractColumn *col = d_inputs.value(0);
89  if (!col) return false;
90  return !(dateTimeAt(row).isValid()) || col->isInvalid(row);
91  }
92  virtual bool isInvalid(Interval<int> i) const {
93  if (!d_inputs.value(0)) return false;
94  for (int row = i.start(); row <= i.end(); row++) {
95  if (!isInvalid(row))
96  return false;
97  }
98  return true;
99  }
100  virtual QList< Interval<int> > invalidIntervals() const
101  {
102  IntervalAttribute<bool> validity;
103  if (d_inputs.value(0)) {
104  int rows = d_inputs.value(0)->rowCount();
105  for (int i=0; i<rows; i++)
106  validity.setValue(i, isInvalid(i));
107  }
108  return validity.intervals();
109  }
110 
111  protected:
113  virtual bool inputAcceptable(int, const AbstractColumn *source) {
114  return source->dataType() == SciDAVis::TypeQString;
115  }
116 };
117 
118 class String2DateTimeFilterSetFormatCmd : public QUndoCommand
119 {
120  public:
121  String2DateTimeFilterSetFormatCmd(String2DateTimeFilter* target, const QString &new_format);
122 
123  virtual void redo();
124  virtual void undo();
125 
126  private:
128  QString d_other_format;
129 };
130 
131 #endif // ifndef STRING2DATE_TIME_FILTER_H
132