File indexing completed on 2025-01-19 04:46:30

0001 /*
0002   SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
0003 
0004   SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "qcsvreader.h"
0010 
0011 #include <QThread>
0012 
0013 class CsvParser : public QThread, public QCsvBuilderInterface
0014 {
0015     Q_OBJECT
0016 
0017 public:
0018     explicit CsvParser(QObject *parent);
0019     ~CsvParser() override;
0020 
0021     void load(QIODevice *device);
0022 
0023     void begin() override;
0024     void beginLine() override;
0025     void field(const QString &data, uint row, uint column) override;
0026     void endLine() override;
0027     void end() override;
0028     void error(const QString &errorMsg) override;
0029 
0030     QCsvReader *reader()
0031     {
0032         return mReader;
0033     }
0034 
0035 Q_SIGNALS:
0036     void columnCountChanged(int columns);
0037     void rowCountChanged(int rows);
0038     void dataChanged(const QString &data, int row, int column);
0039     void ended();
0040 
0041 protected:
0042     void run() override;
0043 
0044 private:
0045     QCsvReader *const mReader;
0046     QIODevice *mDevice = nullptr;
0047     int mRowCount = 0;
0048     int mColumnCount = 0;
0049     int mCacheCounter = 0;
0050 };