File indexing completed on 2024-12-22 03:35:43
0001 /* 0002 File : AsciiFilterPrivate.h 0003 Project : LabPlot 0004 Description : Private implementation class for AsciiFilter. 0005 -------------------------------------------------------------------- 0006 SPDX-FileCopyrightText: 2009-2020 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 0011 #ifndef ASCIIFILTERPRIVATE_H 0012 #define ASCIIFILTERPRIVATE_H 0013 0014 class AbstractDataSource; 0015 class AbstractColumn; 0016 class AbstractAspect; 0017 class Spreadsheet; 0018 class MQTTTopic; 0019 0020 class AsciiFilterPrivate { 0021 public: 0022 explicit AsciiFilterPrivate(AsciiFilter*); 0023 0024 int isPrepared(); 0025 QString separator() const; 0026 0027 // preview 0028 QVector<QStringList> preview(const QString& fileName, int lines); 0029 QVector<QStringList> preview(QIODevice&); 0030 0031 // read 0032 void 0033 readDataFromDevice(QIODevice&, AbstractDataSource* = nullptr, AbstractFileFilter::ImportMode = AbstractFileFilter::ImportMode::Replace, int lines = -1); 0034 void readFromLiveDeviceNotFile(QIODevice&, AbstractDataSource*, AbstractFileFilter::ImportMode = AbstractFileFilter::ImportMode::Replace); 0035 qint64 readFromLiveDevice(QIODevice&, AbstractDataSource*, qint64 from = -1); 0036 void readDataFromFile(const QString& fileName, AbstractDataSource* = nullptr, AbstractFileFilter::ImportMode = AbstractFileFilter::ImportMode::Replace); 0037 0038 // write 0039 void write(const QString& fileName, AbstractDataSource*); 0040 0041 // helpers 0042 int prepareDeviceToRead(QIODevice&, size_t maxLines = std::numeric_limits<std::size_t>::max()); 0043 void initDataContainer(Spreadsheet*); 0044 QString previewValue(const QString&, AbstractColumn::ColumnMode); 0045 void setValue(int col, int row, QStringView value); 0046 QString getLine(QIODevice&); 0047 QStringList getLineString(QIODevice&); 0048 0049 #ifdef HAVE_MQTT 0050 int prepareToRead(const QString&); 0051 QVector<QStringList> preview(const QString& message); 0052 AbstractColumn::ColumnMode MQTTColumnMode() const; 0053 QString MQTTColumnStatistics(const MQTTTopic*) const; 0054 void readMQTTTopic(const QString& message, AbstractDataSource*); 0055 void setPreparedForMQTT(bool, MQTTTopic*, const QString&); 0056 #endif 0057 0058 const AsciiFilter* q; 0059 0060 QString commentCharacter{QStringLiteral("#")}; 0061 QString separatingCharacter{QStringLiteral("auto")}; 0062 QString dateTimeFormat; 0063 QLocale::Language numberFormat{QLocale::C}; 0064 QLocale locale{QLocale::C}; 0065 bool autoModeEnabled{true}; 0066 bool headerEnabled{true}; // read header from file 0067 int headerLine{1}; // line to read header from 0068 bool skipEmptyParts{false}; 0069 bool simplifyWhitespacesEnabled{false}; 0070 double nanValue{qQNaN()}; 0071 bool removeQuotesEnabled{false}; 0072 bool createIndexEnabled{false}; 0073 bool createTimestampEnabled{false}; 0074 QStringList columnNames; 0075 QVector<AbstractColumn::ColumnMode> columnModes; 0076 int startRow{1}; 0077 int endRow{-1}; 0078 int startColumn{1}; 0079 int endColumn{-1}; 0080 int mqttPreviewFirstEmptyColCount{0}; 0081 0082 // TODO: redesign and remove this later 0083 bool readingFile{false}; 0084 QString readingFileName; 0085 0086 private: 0087 static const unsigned int m_dataTypeLines = 10; // maximum lines to read for determining data types 0088 QString m_separator; 0089 int m_actualStartRow{1}; 0090 int m_actualRows{0}; 0091 int m_actualCols{0}; 0092 int m_prepared{false}; 0093 int m_columnOffset{0}; // indexes the "start column" in the datasource. Data will be imported starting from this column. 0094 std::vector<void*> m_dataContainer; // pointers to the actual data containers 0095 0096 QStringList split(const QString&, bool autoSeparator = true); 0097 QDateTime parseDateTime(const QString& string, const QString& format); 0098 }; 0099 0100 #endif