File indexing completed on 2024-06-16 03:42:35

0001 /*
0002     File                 : DateTime2StringFilter.h
0003     Project              : LabPlot
0004     Description          : Conversion filter QDateTime -> QString.
0005     --------------------------------------------------------------------
0006     SPDX-FileCopyrightText: 2007 Tilman Benkert <thzs@gmx.net>
0007     SPDX-FileCopyrightText: 2007 Knut Franke <knut.franke@gmx.de>
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #ifndef DATE_TIME2STRING_FILTER_H
0012 #define DATE_TIME2STRING_FILTER_H
0013 
0014 #include "backend/core/AbstractSimpleFilter.h"
0015 
0016 class DateTime2StringFilterSetFormatCmd;
0017 
0018 //! Conversion filter QDateTime -> QString.
0019 class DateTime2StringFilter : public AbstractSimpleFilter {
0020     Q_OBJECT
0021 
0022 public:
0023     //! Standard constructor.
0024     explicit DateTime2StringFilter(const QString& format = QLatin1String("yyyy-MM-dd hh:mm:ss.zzz"))
0025         : m_format(format) {
0026     }
0027     //! Set the format string to be used for conversion.
0028     void setFormat(const QString& format);
0029 
0030     //! Return the format string
0031     /**
0032      * The default format string is "yyyy-MM-dd hh:mm:ss.zzz".
0033      * \sa QDate::toString()
0034      */
0035     QString format() const {
0036         return m_format;
0037     }
0038 
0039     //! Return the data type of the column
0040     AbstractColumn::ColumnMode columnMode() const override {
0041         return AbstractColumn::ColumnMode::Text;
0042     }
0043 
0044 private:
0045     friend class DateTime2StringFilterSetFormatCmd;
0046     //! The format string.
0047     QString m_format;
0048 
0049 public:
0050     QString textAt(int row) const override;
0051 
0052     //! \name XML related functions
0053     //@{
0054     void writeExtraAttributes(QXmlStreamWriter*) const override;
0055     bool load(XmlStreamReader*, bool preview) override;
0056     //@}
0057 
0058 protected:
0059     //! Using typed ports: only DateTime inputs are accepted.
0060     bool inputAcceptable(int, const AbstractColumn* source) override;
0061 };
0062 
0063 #endif // ifndef DATE_TIME2STRING_FILTER_H