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)  

DateTime2StringFilter.h
Go to the documentation of this file.
1 
12 
30 #ifndef DATE_TIME2STRING_FILTER_H
31 #define DATE_TIME2STRING_FILTER_H
32 
34 #include <QDateTime>
35 #include <QRegExp>
36 
38 
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 
59 
60  signals:
61  void formatChanged();
62 
63  private:
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:
113  QString d_other_format;
114 };
115 
116 #endif // ifndef DATE_TIME2STRING_FILTER_H
117 
DateTime2StringFilterSetFormatCmd::d_target
DateTime2StringFilter * d_target
Definition: DateTime2StringFilter.h:112
DateTime2StringFilter::formatChanged
void formatChanged()
DateTime2StringFilter::setFormat
void setFormat(const QString &format)
Set the format string to be used for conversion.
Definition: DateTime2StringFilter.cpp:35
SciDAVis::TypeQString
@ TypeQString
Definition: globals.h:79
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
DateTime2StringFilterSetFormatCmd::d_other_format
QString d_other_format
Definition: DateTime2StringFilter.h:113
AbstractSimpleFilter.h
DateTime2StringFilter::inputAcceptable
virtual bool inputAcceptable(int, const AbstractColumn *source)
Using typed ports: only DateTime inputs are accepted.
Definition: DateTime2StringFilter.h:98
DateTime2StringFilter
Conversion filter QDateTime -> QString.
Definition: DateTime2StringFilter.h:41
AbstractColumn::dataType
virtual SciDAVis::ColumnDataType dataType() const =0
Return the data type of the column.
DateTime2StringFilterSetFormatCmd::undo
virtual void undo()
Definition: DateTime2StringFilter.cpp:57
DateTime2StringFilterSetFormatCmd::redo
virtual void redo()
Definition: DateTime2StringFilter.cpp:49
DateTime2StringFilter::writeExtraAttributes
virtual void writeExtraAttributes(QXmlStreamWriter *writer) const
Override this in derived classes if they have other attributes than filter_name.
Definition: DateTime2StringFilter.cpp:62
DateTime2StringFilter::textAt
virtual QString textAt(int row) const
Return the content of row 'row'.
Definition: DateTime2StringFilter.h:69
DateTime2StringFilter::dataType
virtual SciDAVis::ColumnDataType dataType() const
Return the data type of the column.
Definition: DateTime2StringFilter.h:58
DateTime2StringFilter::load
virtual bool load(XmlStreamReader *reader)
Load from XML.
Definition: DateTime2StringFilter.cpp:67
DateTime2StringFilter::format
QString format() const
Return the format string.
Definition: DateTime2StringFilter.h:55
DateTime2StringFilterSetFormatCmd
Definition: DateTime2StringFilter.h:104
DateTime2StringFilterSetFormatCmd::DateTime2StringFilterSetFormatCmd
DateTime2StringFilterSetFormatCmd(DateTime2StringFilter *target, const QString &new_format)
Definition: DateTime2StringFilter.cpp:40
AbstractSimpleFilter
Simplified filter interface for filters with only one output port.
Definition: AbstractSimpleFilter.h:129
SciDAVis::TypeQDateTime
@ TypeQDateTime
Definition: globals.h:80
DateTime2StringFilter::DateTime2StringFilter
DateTime2StringFilter(QString format="yyyy-MM-dd hh:mm:ss.zzz")
Standard constructor.
Definition: DateTime2StringFilter.h:46
AbstractFilter::d_inputs
QVector< const AbstractColumn * > d_inputs
The data sources connected to my input ports.
Definition: AbstractFilter.h:275
DateTime2StringFilter::d_format
QString d_format
The format string.
Definition: DateTime2StringFilter.h:66
AbstractColumn
Interface definition for data with column logic.
Definition: AbstractColumn.h:82