File indexing completed on 2024-12-22 03:35:43

0001 /*
0002     File                 : AsciiFilter.h
0003     Project              : LabPlot
0004     Description          : ASCII I/O-filter
0005     --------------------------------------------------------------------
0006     SPDX-FileCopyrightText: 2009-2022 Alexander Semke <alexander.semke@web.de>
0007     SPDX-FileCopyrightText: 2017-2022 Stefan Gerlach <stefan.gerlach@uni.kn>
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 #ifndef ASCIIFILTER_H
0011 #define ASCIIFILTER_H
0012 
0013 #include "backend/core/AbstractColumn.h"
0014 #include "backend/datasources/filters/AbstractFileFilter.h"
0015 
0016 class Spreadsheet;
0017 class QIODevice;
0018 class AsciiFilterPrivate;
0019 class QAbstractSocket;
0020 class MQTTTopic;
0021 class MQTTClient;
0022 
0023 class AsciiFilter : public AbstractFileFilter {
0024     Q_OBJECT
0025 
0026 public:
0027     AsciiFilter();
0028     ~AsciiFilter() override;
0029 
0030     static QStringList separatorCharacters();
0031     static QStringList commentCharacters();
0032     static QStringList dataTypes();
0033     static QStringList predefinedFilters();
0034 
0035     static QString fileInfoString(const QString&);
0036     static int columnNumber(const QString& fileName, const QString& separator = QString());
0037     static size_t lineNumber(const QString& fileName, size_t maxLines = std::numeric_limits<std::size_t>::max());
0038     size_t lineNumber(QIODevice&, size_t maxLines = std::numeric_limits<std::size_t>::max()) const; // calculate number of lines if device supports it
0039 
0040     // read data from any device
0041     void readDataFromDevice(QIODevice& device, AbstractDataSource*, AbstractFileFilter::ImportMode = AbstractFileFilter::ImportMode::Replace, int lines = -1);
0042     void readFromLiveDeviceNotFile(QIODevice& device, AbstractDataSource* dataSource);
0043     qint64 readFromLiveDevice(QIODevice& device, AbstractDataSource*, qint64 from = -1);
0044     // overloaded function to read from file
0045     void
0046     readDataFromFile(const QString& fileName, AbstractDataSource* = nullptr, AbstractFileFilter::ImportMode = AbstractFileFilter::ImportMode::Replace) override;
0047     void write(const QString& fileName, AbstractDataSource*) override;
0048 
0049     QVector<QStringList> preview(const QString& fileName, int lines);
0050     QVector<QStringList> preview(QIODevice& device);
0051 
0052 #ifdef HAVE_MQTT
0053     QVector<QStringList> preview(const QString& message);
0054     void readMQTTTopic(const QString& message, AbstractDataSource*);
0055     void setPreparedForMQTT(bool, MQTTTopic*, const QString&);
0056 #endif
0057 
0058     QString separator() const;
0059     void setCommentCharacter(const QString&);
0060     QString commentCharacter() const;
0061     void setSeparatingCharacter(const QString&);
0062     QString separatingCharacter() const;
0063     void setDateTimeFormat(const QString&);
0064     QString dateTimeFormat() const;
0065     void setNumberFormat(QLocale::Language);
0066     QLocale::Language numberFormat() const;
0067 
0068     void setAutoModeEnabled(const bool);
0069     bool isAutoModeEnabled() const;
0070     void setHeaderEnabled(const bool);
0071     void setHeaderLine(int);
0072     bool isHeaderEnabled() const;
0073     void setSkipEmptyParts(const bool);
0074     bool skipEmptyParts() const;
0075     void setSimplifyWhitespacesEnabled(const bool);
0076     bool simplifyWhitespacesEnabled() const;
0077     void setNaNValueToZero(const bool);
0078     bool NaNValueToZeroEnabled() const;
0079     void setRemoveQuotesEnabled(const bool);
0080     bool removeQuotesEnabled() const;
0081     void setCreateIndexEnabled(const bool);
0082     bool createIndexEnabled() const;
0083     void setCreateTimestampEnabled(const bool);
0084     bool createTimestampEnabled() const;
0085 
0086     void setVectorNames(const QString&);
0087     void setVectorNames(const QStringList&);
0088     QStringList vectorNames() const;
0089     QVector<AbstractColumn::ColumnMode> columnModes();
0090 
0091     void setStartRow(const int);
0092     int startRow() const;
0093     void setEndRow(const int);
0094     int endRow() const;
0095     void setStartColumn(const int);
0096     int startColumn() const;
0097     void setEndColumn(const int);
0098     int endColumn() const;
0099 
0100     void save(QXmlStreamWriter*) const override;
0101     bool load(XmlStreamReader*) override;
0102 
0103     int isPrepared();
0104 
0105 private:
0106     std::unique_ptr<AsciiFilterPrivate> const d;
0107     friend class AsciiFilterPrivate;
0108 };
0109 
0110 #endif