Skip to content

Commit

Permalink
Use a proxy task when scanning for postgres column types
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 20, 2018
1 parent cea8b55 commit fd934d8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/providers/postgres/qgspgsourceselect.cpp
Expand Up @@ -28,6 +28,7 @@ email : sherman at mrcc.com
#include "qgsvectorlayer.h"
#include "qgscolumntypethread.h"
#include "qgssettings.h"
#include "qgsproxyprogresstask.h"

#include <QFileDialog>
#include <QInputDialog>
Expand Down Expand Up @@ -545,13 +546,18 @@ void QgsPgSourceSelect::btnConnect_clicked()
QApplication::setOverrideCursor( Qt::BusyCursor );

mColumnTypeThread = new QgsGeomColumnTypeThread( cmbConnections->currentText(), mUseEstimatedMetadata, cbxAllowGeometrylessTables->isChecked() );
mColumnTypeTask = new QgsProxyProgressTask( tr( "Scanning tables for %1" ).arg( cmbConnections->currentText() ) );
QgsApplication::taskManager()->addTask( mColumnTypeTask );

connect( mColumnTypeThread, &QgsGeomColumnTypeThread::setLayerType,
this, &QgsPgSourceSelect::setLayerType );
connect( mColumnTypeThread, &QThread::finished,
this, &QgsPgSourceSelect::columnThreadFinished );
connect( mColumnTypeThread, &QgsGeomColumnTypeThread::progress,
this, &QgsPgSourceSelect::progress );
mColumnTypeTask, [ = ]( int i, int n )
{
mColumnTypeTask->setProxyProgress( 100.0 * static_cast< double >( i ) / n );
} );
connect( mColumnTypeThread, &QgsGeomColumnTypeThread::progressMessage,
this, &QgsPgSourceSelect::progressMessage );

Expand All @@ -572,6 +578,8 @@ void QgsPgSourceSelect::columnThreadFinished()
delete mColumnTypeThread;
mColumnTypeThread = nullptr;
btnConnect->setText( tr( "Connect" ) );
mColumnTypeTask->finalize( true );
mColumnTypeTask = nullptr;

finishList();
}
Expand Down
3 changes: 3 additions & 0 deletions src/providers/postgres/qgspgsourceselect.h
Expand Up @@ -36,6 +36,7 @@ class QStringList;
class QgsGeomColumnTypeThread;
class QgisApp;
class QgsPgSourceSelect;
class QgsProxyProgressTask;

class QgsPgSourceSelectDelegate : public QItemDelegate
{
Expand Down Expand Up @@ -138,6 +139,8 @@ class QgsPgSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsDbS
QStringList mColumnLabels;
// Our thread for doing long running queries
QgsGeomColumnTypeThread *mColumnTypeThread = nullptr;
QgsProxyProgressTask *mColumnTypeTask = nullptr;

QgsDataSourceUri mDataSrcUri;
QStringList mSelectedTables;
bool mUseEstimatedMetadata = false;
Expand Down

0 comments on commit fd934d8

Please sign in to comment.