Commit b1f0789a authored by Alexander Semke's avatar Alexander Semke

[json import] take the number of lines for the preview specified by the

user also for JSON files.
parent cbd71a55
...@@ -67,17 +67,17 @@ void JsonFilter::readDataFromFile(const QString& fileName, AbstractDataSource* d ...@@ -67,17 +67,17 @@ void JsonFilter::readDataFromFile(const QString& fileName, AbstractDataSource* d
d->readDataFromFile(fileName, dataSource, importMode); d->readDataFromFile(fileName, dataSource, importMode);
} }
QVector<QStringList> JsonFilter::preview(const QString& fileName) { QVector<QStringList> JsonFilter::preview(const QString& fileName, int lines) {
return d->preview(fileName); return d->preview(fileName, lines);
} }
QVector<QStringList> JsonFilter::preview(QIODevice& device) { QVector<QStringList> JsonFilter::preview(QIODevice& device, int lines) {
return d->preview(device); return d->preview(device, lines);
} }
QVector<QStringList> JsonFilter::preview(const QJsonDocument& doc) { // QVector<QStringList> JsonFilter::preview(const QJsonDocument& doc) {
return d->preview(doc); // return d->preview(doc);
} // }
/*! /*!
writes the content of the data source \c dataSource to the file \c fileName. writes the content of the data source \c dataSource to the file \c fileName.
...@@ -637,41 +637,41 @@ void JsonFilterPrivate::importData(AbstractDataSource* dataSource, AbstractFileF ...@@ -637,41 +637,41 @@ void JsonFilterPrivate::importData(AbstractDataSource* dataSource, AbstractFileF
/*! /*!
generates the preview for the file \c fileName. generates the preview for the file \c fileName.
*/ */
QVector<QStringList> JsonFilterPrivate::preview(const QString& fileName) { QVector<QStringList> JsonFilterPrivate::preview(const QString& fileName, int lines) {
KFilterDev device(fileName); KFilterDev device(fileName);
return preview(device); return preview(device, lines);
} }
/*! /*!
generates the preview for device \c device. generates the preview for device \c device.
*/ */
QVector<QStringList> JsonFilterPrivate::preview(QIODevice& device) { QVector<QStringList> JsonFilterPrivate::preview(QIODevice& device, int lines) {
const int deviceError = prepareDeviceToRead(device); const int deviceError = prepareDeviceToRead(device);
if (deviceError != 0) { if (deviceError != 0) {
DEBUG("Device error = " << deviceError); DEBUG("Device error = " << deviceError);
return QVector<QStringList>(); return QVector<QStringList>();
} }
return preview(); return preview(lines);
} }
/*! /*!
generates the preview for document \c doc. generates the preview for document \c doc.
*/ */
QVector<QStringList> JsonFilterPrivate::preview(const QJsonDocument& doc) { // QVector<QStringList> JsonFilterPrivate::preview(const QJsonDocument& doc) {
if (prepareDocumentToRead(doc) != 0) // if (prepareDocumentToRead(doc) != 0)
return QVector<QStringList>(); // return QVector<QStringList>();
return preview(); // return preview();
} // }
/*! /*!
generates the preview for document \c m_preparedDoc. generates the preview for document \c m_preparedDoc.
*/ */
QVector<QStringList> JsonFilterPrivate::preview() { QVector<QStringList> JsonFilterPrivate::preview(int lines) {
QVector<QStringList> dataStrings; QVector<QStringList> dataStrings;
const int rowOffset = startRow - 1; const int rowOffset = startRow - 1;
DEBUG("reading " << m_actualRows << " lines"); DEBUG(" Generating preview for " << qMin(lines, m_actualRows) << " lines");
for (int i = 0; i < m_actualRows; ++i) { for (int i = 0; i < qMin(lines, m_actualRows); ++i) {
QString rowName; QString rowName;
QJsonValue row; QJsonValue row;
switch (containerType) { switch (containerType) {
...@@ -729,7 +729,6 @@ QVector<QStringList> JsonFilterPrivate::preview() { ...@@ -729,7 +729,6 @@ QVector<QStringList> JsonFilterPrivate::preview() {
} }
} }
dataStrings << lineString; dataStrings << lineString;
emit q->completed(100 * i/m_actualRows);
} }
return dataStrings; return dataStrings;
} }
......
...@@ -60,9 +60,9 @@ public: ...@@ -60,9 +60,9 @@ public:
void readDataFromFile(const QString& fileName, AbstractDataSource* = nullptr, AbstractFileFilter::ImportMode = AbstractFileFilter::ImportMode::Replace) override; void readDataFromFile(const QString& fileName, AbstractDataSource* = nullptr, AbstractFileFilter::ImportMode = AbstractFileFilter::ImportMode::Replace) override;
void write(const QString& fileName, AbstractDataSource*) override; void write(const QString& fileName, AbstractDataSource*) override;
QVector<QStringList> preview(const QString& fileName); QVector<QStringList> preview(const QString& fileName, int lines);
QVector<QStringList> preview(QIODevice& device); QVector<QStringList> preview(QIODevice& device, int lines);
QVector<QStringList> preview(const QJsonDocument& doc); // QVector<QStringList> preview(const QJsonDocument& doc);
void loadFilterSettings(const QString&) override; void loadFilterSettings(const QString&) override;
void saveFilterSettings(const QString&) const override; void saveFilterSettings(const QString&) const override;
......
...@@ -60,10 +60,10 @@ public: ...@@ -60,10 +60,10 @@ public:
int lines = -1); int lines = -1);
void write(const QString& fileName, AbstractDataSource*); void write(const QString& fileName, AbstractDataSource*);
QVector<QStringList> preview(const QString& fileName); QVector<QStringList> preview(const QString& fileName, int lines);
QVector<QStringList> preview(QIODevice& device); QVector<QStringList> preview(QIODevice& device, int lines);
QVector<QStringList> preview(const QJsonDocument&); // QVector<QStringList> preview(const QJsonDocument&);
QVector<QStringList> preview(); QVector<QStringList> preview(int lines);
const JsonFilter* q; const JsonFilter* q;
QJsonModel* model; QJsonModel* model;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment