Skip to content

Commit

Permalink
Addres PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso authored and nyalldawson committed Nov 29, 2021
1 parent 7e2eaec commit 955c78e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
10 changes: 4 additions & 6 deletions src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
Expand Up @@ -160,10 +160,10 @@ QgsDelimitedTextProvider::QgsDelimitedTextProvider( const QString &uri, const Pr
if ( query.hasQueryItem( QStringLiteral( "quiet" ) ) ) mShowInvalidLines = false;

// Parse and store user-defined field types and boolean literals
const auto queryItems { query.queryItems( QUrl::ComponentFormattingOption::FullyDecoded ) };
for ( const auto &queryItem : std::as_const( queryItems ) )
const QList<QPair<QString, QString> > queryItems { query.queryItems( QUrl::ComponentFormattingOption::FullyDecoded ) };
for ( const QPair<QString, QString> &queryItem : std::as_const( queryItems ) )
{
if ( queryItem.first == QStringLiteral( "field" ) )
if ( queryItem.first.compare( QStringLiteral( "field" ), Qt::CaseSensitivity::CaseInsensitive ) == 0 )
{
const QStringList parts { queryItem.second.split( ':' ) };
if ( parts.count() == 2 )
Expand Down Expand Up @@ -600,9 +600,7 @@ void QgsDelimitedTextProvider::scanFile( bool buildIndexes, bool forceFullScan,
// Progress changed every 100 features
if ( feedback && mNumberFeatures % 100 == 0 )
{
// We don't really know the progress because the number of records is not known
// but we need to signal to the caller that the scan is progressing
feedback->setProgress( mNumberFeatures );
feedback->setProcessedCount( mNumberFeatures );
}

if ( !geomValid )
Expand Down
29 changes: 11 additions & 18 deletions src/providers/delimitedtext/qgsdelimitedtextsourceselect.cpp
Expand Up @@ -524,34 +524,34 @@ void QgsDelimitedTextSourceSelect::updateFieldLists()
// Run the scan in a separate thread
cancelScanTask();

QgsDelimitedTextFileScanTask *newTask { new QgsDelimitedTextFileScanTask( url( /* skip overridden types */ true ) ) };
mScanTask = new QgsDelimitedTextFileScanTask( url( /* skip overridden types */ true ) );
mCancelButton->show();
connect( newTask, &QgsDelimitedTextFileScanTask::scanCompleted, this, [ = ]( const QgsFields & fields )
connect( mScanTask, &QgsDelimitedTextFileScanTask::scanCompleted, this, [ = ]( const QgsFields & fields )
{
updateFieldTypes( fields );
mScanWidget->hide( );
} );

connect( newTask, &QgsDelimitedTextFileScanTask::scanStarted, this, [ = ]( const QgsFields & fields )
connect( mScanTask, &QgsDelimitedTextFileScanTask::scanStarted, this, [ = ]( const QgsFields & fields )
{
updateFieldTypes( fields );
} );

connect( mCancelButton, &QPushButton::clicked, this, &QgsDelimitedTextSourceSelect::cancelScanTask );

connect( newTask, &QgsDelimitedTextFileScanTask::progressChanged, this, [ = ]( double recordsScanned )
connect( mScanTask, &QgsDelimitedTextFileScanTask::processedCountChanged, this, [ = ]( unsigned long long recordsScanned )
{
mScanWidget->show();
mProgressLabel->setText( tr( "Column types detection in progress: %L1 records read" ).arg( static_cast<unsigned long>( recordsScanned ) ) );
mProgressLabel->setText( tr( "Column types detection in progress: %L1 records read" ).arg( static_cast<unsigned long long>( recordsScanned ) ) );
} );

// This is required because QgsTask emits a progress changed 100 when done
connect( newTask, &QgsDelimitedTextFileScanTask::taskCompleted, this, [ = ]
connect( mScanTask, &QgsDelimitedTextFileScanTask::taskCompleted, this, [ = ]
{
mScanWidget->hide( );
} );

mScanTaskId = QgsApplication::taskManager()->addTask( newTask, 100 );
QgsApplication::taskManager()->addTask( mScanTask, 100 );

// We don't know anything about a text based field other
// than its name. All fields are assumed to be text
Expand Down Expand Up @@ -948,14 +948,10 @@ QString QgsDelimitedTextSourceSelect::url( bool skipOverriddenTypes )
void QgsDelimitedTextSourceSelect::cancelScanTask()
{
// This will cancel the existing task (if any)
if ( mScanTaskId > 0 )
if ( mScanTask )
{
QgsDelimitedTextFileScanTask *task { qobject_cast<QgsDelimitedTextFileScanTask *>( QgsApplication::taskManager()->task( mScanTaskId ) ) };
if ( task )
{
task->cancel();
}
mScanTaskId = -1;
mScanTask->cancel();
mScanTask = nullptr;
}
}

Expand All @@ -966,10 +962,7 @@ bool QgsDelimitedTextFileScanTask::run()
QgsDataProvider::ProviderOptions(),
QgsDataProvider::ReadFlag::SkipFeatureCount | QgsDataProvider::ReadFlag::SkipGetExtent | QgsDataProvider::ReadFlag::SkipFullScan );

connect( &mFeedback, &QgsFeedback::progressChanged, this, [ = ]( double progress )
{
setProgress( progress );
} );
connect( &mFeedback, &QgsFeedback::processedCountChanged, this, &QgsDelimitedTextFileScanTask::processedCountChanged );

if ( provider.isValid() )
{
Expand Down
6 changes: 5 additions & 1 deletion src/providers/delimitedtext/qgsdelimitedtextsourceselect.h
Expand Up @@ -73,6 +73,10 @@ class QgsDelimitedTextFileScanTask: public QgsTask
*/
void scanStarted( const QgsFields &field );

/**
* \brief processedCountChanged is emitted when the file scan reports a change in the number of scanned rows.
*/
void processedCountChanged( unsigned long long processedCount );

private:

Expand Down Expand Up @@ -112,7 +116,7 @@ class QgsDelimitedTextSourceSelect : public QgsAbstractDataSourceWidget, private
int mMaxFields = DEFAULT_MAX_FIELDS; //!< To avoid Denial Of Service (at least in source select). Configurable through /max_fields settings sub-key.
QString mSettingsKey;
QString mLastFileType;
long mScanTaskId = -1;
QPointer<QgsDelimitedTextFileScanTask> mScanTask;
QButtonGroup *bgFileFormat = nullptr;
QButtonGroup *bgGeomType = nullptr;
void showHelp();
Expand Down

0 comments on commit 955c78e

Please sign in to comment.