scidavis  2.3.0
About: SciDAVis is a free application for Scientific Data Analysis and Visualization (a fork off of QtiPlot).
  Fossies Dox: scidavis-2.3.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

String2DateTimeFilter.h
Go to the documentation of this file.
1 
12 
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 
String2DateTimeFilter::date_formats
static const char * date_formats[]
Definition: String2DateTimeFilter.h:80
String2DateTimeFilterSetFormatCmd::undo
virtual void undo()
Definition: String2DateTimeFilter.cpp:152
String2DateTimeFilter::isInvalid
virtual bool isInvalid(int row) const
Return whether a certain row contains an invalid value
Definition: String2DateTimeFilter.h:87
String2DateTimeFilter::writeExtraAttributes
virtual void writeExtraAttributes(QXmlStreamWriter *writer) const
Override this in derived classes if they have other attributes than filter_name.
Definition: String2DateTimeFilter.cpp:112
String2DateTimeFilter::dateTimeAt
virtual QDateTime dateTimeAt(int row) const
Set the content of row 'row'.
Definition: String2DateTimeFilter.cpp:63
SciDAVis::TypeQString
@ TypeQString
Definition: globals.h:79
String2DateTimeFilter::dateAt
virtual QDate dateAt(int row) const
Return the date part of row 'row'.
Definition: String2DateTimeFilter.h:85
XmlStreamReader
XML stream parser that supports errors as well as warnings.
Definition: XmlStreamReader.h:42
SciDAVis::ColumnDataType
ColumnDataType
Column data type.
Definition: globals.h:77
String2DateTimeFilter::setFormat
void setFormat(const QString &format)
Set the format string to be used for conversion.
Definition: String2DateTimeFilter.cpp:130
String2DateTimeFilter::format
QString format() const
Return the format string.
Definition: String2DateTimeFilter.h:61
AbstractSimpleFilter.h
IntervalAttribute< bool >
A class representing an interval-based attribute (bool version)
Definition: IntervalAttribute.h:198
AbstractColumn::dataType
virtual SciDAVis::ColumnDataType dataType() const =0
Return the data type of the column.
String2DateTimeFilterSetFormatCmd::d_other_format
QString d_other_format
Definition: String2DateTimeFilter.h:128
String2DateTimeFilter::load
virtual bool load(XmlStreamReader *reader)
Load from XML.
Definition: String2DateTimeFilter.cpp:117
String2DateTimeFilterSetFormatCmd
Definition: String2DateTimeFilter.h:119
String2DateTimeFilter::dataType
virtual SciDAVis::ColumnDataType dataType() const
Return the data type of the column.
Definition: String2DateTimeFilter.h:64
IntervalAttribute< bool >::setValue
void setValue(Interval< int > i, bool value=true)
Definition: IntervalAttribute.h:210
String2DateTimeFilterSetFormatCmd::d_target
String2DateTimeFilter * d_target
Definition: String2DateTimeFilter.h:127
String2DateTimeFilter::time_formats
static const char * time_formats[]
Definition: String2DateTimeFilter.h:81
String2DateTimeFilterSetFormatCmd::redo
virtual void redo()
Definition: String2DateTimeFilter.cpp:144
String2DateTimeFilter::timeAt
virtual QTime timeAt(int row) const
Return the time part of row 'row'.
Definition: String2DateTimeFilter.h:86
String2DateTimeFilter::isInvalid
virtual bool isInvalid(Interval< int > i) const
Return whether a certain interval of rows contains only invalid values
Definition: String2DateTimeFilter.h:92
IntervalAttribute< bool >::intervals
QList< Interval< int > > intervals() const
Definition: IntervalAttribute.h:292
String2DateTimeFilter::String2DateTimeFilter
String2DateTimeFilter(QString format="yyyy-MM-dd hh:mm:ss.zzz")
Standard constructor.
Definition: String2DateTimeFilter.h:53
String2DateTimeFilter::inputAcceptable
virtual bool inputAcceptable(int, const AbstractColumn *source)
Using typed ports: only string inputs are accepted.
Definition: String2DateTimeFilter.h:113
AbstractSimpleFilter
Simplified filter interface for filters with only one output port.
Definition: AbstractSimpleFilter.h:129
SciDAVis::TypeQDateTime
@ TypeQDateTime
Definition: globals.h:80
String2DateTimeFilter
Conversion filter QString -> QDateTime.
Definition: String2DateTimeFilter.h:48
String2DateTimeFilter::invalidIntervals
virtual QList< Interval< int > > invalidIntervals() const
Return all intervals of invalid rows.
Definition: String2DateTimeFilter.h:100
AbstractColumn::isInvalid
virtual bool isInvalid(int row) const
Return whether a certain row contains an invalid value
Definition: AbstractColumn.h:154
Interval< int >
AbstractFilter::d_inputs
QVector< const AbstractColumn * > d_inputs
The data sources connected to my input ports.
Definition: AbstractFilter.h:275
String2DateTimeFilter::formatChanged
void formatChanged()
String2DateTimeFilter::d_format
QString d_format
The format string.
Definition: String2DateTimeFilter.h:78
String2DateTimeFilterSetFormatCmd::String2DateTimeFilterSetFormatCmd
String2DateTimeFilterSetFormatCmd(String2DateTimeFilter *target, const QString &new_format)
Definition: String2DateTimeFilter.cpp:135
AbstractColumn
Interface definition for data with column logic.
Definition: AbstractColumn.h:82