Showing with 35 additions and 14 deletions.
  1. +25 −13 src/datasources/ascii/asciisource.cpp
  2. +3 −1 src/libkstapp/changefiledialog.cpp
  3. +4 −0 src/libkstapp/datasourcepluginfactory.cpp
  4. +3 −0 src/libkstapp/vectordialog.cpp
38 changes: 25 additions & 13 deletions src/datasources/ascii/asciisource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,29 +207,39 @@ Kst::Object::UpdateType AsciiSource::internalDataSourceUpdate(bool read_complete
}

bool force_update = true;
bool emitProgress = true;
if (_fileSize == file.size()) {
force_update = false;
}
_fileSize = file.size();
// Don't emit status message if there is less than 10MB to parse
if (file.size() - _fileSize < 10*1024*1024) {
emitProgress = false;
}
if (read_completely) { // Update _fileSize only when we read the file completely
_fileSize = file.size();
}
_fileCreationTime_t = QFileInfo(file).created().toTime_t();

int col_count = _fieldList.size() - 1; // minus INDEX

bool new_data = false;
emit progress(0, "Searching for rows");
QFuture<bool> future = QtConcurrent::run(&_reader, &AsciiDataReader::findAllDataRows, read_completely, &file, _fileSize, col_count);
bool busy = true;
while (busy) {
if (future.isFinished()) {
new_data = future;
busy = false;
emit progress(100, "Searching for rows finished");
} else {
ms::sleep(500);
emit progress(_reader.progressValue(), i18n("%1: %2 rows found.").arg(_filename).arg(QString::number(_reader.progressRows())));
if (emitProgress) {
emit progress(0, i18n("Parsing ") + _filename);
QFuture<bool> future = QtConcurrent::run(&_reader, &AsciiDataReader::findAllDataRows, read_completely, &file, _fileSize, col_count);
bool busy = true;
while (busy) {
if (future.isFinished()) {
new_data = future;
busy = false;
emit progress(100, i18n("Parsing finished"));
} else {
ms::sleep(500);
emit progress(_reader.progressValue(), i18n("Parsing %1: %2 rows found.").arg(_filename).arg(QString::number(_reader.progressRows())));
}
}
} else {
new_data = _reader.findAllDataRows(read_completely, &file, _fileSize, col_count);
}

return (!new_data && !force_update ? NoChange : Updated);
}

Expand Down Expand Up @@ -265,6 +275,7 @@ bool AsciiSource::useSlidingWindow(qint64 bytesToRead) const
//-------------------------------------------------------------------------------------------
int AsciiSource::readField(double *v, const QString& field, int s, int n)
{
emit progress(0, i18n("Reading field: ") + field);
int read = tryReadField(v, field, s, n);

if (isTime(field)) {
Expand Down Expand Up @@ -314,6 +325,7 @@ int AsciiSource::readField(double *v, const QString& field, int s, int n)
_haveWarned = true;
}

emit progress(100, QString());
return 0;
}

Expand Down
4 changes: 3 additions & 1 deletion src/libkstapp/changefiledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,12 @@ void ChangeFileDialog::OKClicked() {

void ChangeFileDialog::apply() {
Q_ASSERT(_store);
if (!_dataSource->isValid() || _dataSource->isEmpty()) {
if (!_dataSource->isValid() /*|| _dataSource->isEmpty()*/ ) {
QMessageBox::critical(this, tr("Kst"), tr("The file could not be loaded or contains no data."), QMessageBox::Ok);
return;
}
// Hook the new datasource to the status message area to receive progress status
connect(_dataSource, SIGNAL(progress(int, QString)), kstApp->mainWindow(), SLOT(updateProgress(int, QString)));

// we need a list which preservs the order things are added, and a map to associate the duplicated
// primitive with its duplicate.
Expand Down
4 changes: 4 additions & 0 deletions src/libkstapp/datasourcepluginfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@

#include "datasourcepluginfactory.h"

#include "application.h"
#include "debug.h"
#include "datasource.h"
#include "datacollection.h"
#include "objectstore.h"
#include "datasourcepluginmanager.h"
#include "baddatasourcedialog.h"

#include <QObject>

namespace Kst {

DataSourcePluginFactory::DataSourcePluginFactory()
Expand Down Expand Up @@ -76,6 +79,7 @@ DataSourcePtr DataSourcePluginFactory::generateDataSource(ObjectStore *store, QX
dataSource = 0L;
dataSource = DataSourcePluginManager::loadSource(store, fileName, fileType);
if (dataSource) {
QObject::connect(dataSource, SIGNAL(progress(int, QString)), kstApp->mainWindow(), SLOT(updateProgress(int, QString)));
dataSource->parseProperties(propertyAttributes);
if (fileName != alternate_filename) {
dataSource->setAlternateFilename(alternate_filename);
Expand Down
3 changes: 3 additions & 0 deletions src/libkstapp/vectordialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
***************************************************************************/
#include "vectordialog.h"

#include "application.h"
#include "dialogpage.h"
#include "datasourcedialog.h"
#include "editmultiplewidget.h"
Expand Down Expand Up @@ -448,6 +449,8 @@ ObjectPtr VectorDialog::createNewDataVector() {
if (!dataSource)
return 0;

connect(dataSource, SIGNAL(progress(int, QString)), kstApp->mainWindow(), SLOT(updateProgress(int, QString)));

const QString field = _vectorTab->field();
const DataRange *dataRange = _vectorTab->dataRange();

Expand Down