Skip to content
Permalink
Browse files
Fix select sublayers dialog model can seem to get stuck calculating
geometry types for data sources which have no records
  • Loading branch information
nyalldawson committed Aug 19, 2021
1 parent 011aa46 commit 6012cafe6470862d69b18ee8ef8fbc26fee6cdaf
Showing with 16 additions and 3 deletions.
  1. +9 −2 src/app/qgsprovidersublayersdialog.cpp
  2. +7 −1 src/app/qgsprovidersublayersdialog.h
@@ -47,7 +47,7 @@ QVariant QgsProviderSublayerDialogModel::data( const QModelIndex &index, int rol
{
const QgsProviderSublayerDetails details = mSublayers.at( index.row() );

if ( details.type() == QgsMapLayerType::VectorLayer && details.wkbType() == QgsWkbTypes::Unknown )
if ( details.type() == QgsMapLayerType::VectorLayer && details.wkbType() == QgsWkbTypes::Unknown && !mGeometryTypesResolved )
{
switch ( role )
{
@@ -83,7 +83,7 @@ Qt::ItemFlags QgsProviderSublayerDialogModel::flags( const QModelIndex &index )
{
const QgsProviderSublayerDetails details = mSublayers.at( index.row() );

if ( details.type() == QgsMapLayerType::VectorLayer && details.wkbType() == QgsWkbTypes::Unknown )
if ( details.type() == QgsMapLayerType::VectorLayer && details.wkbType() == QgsWkbTypes::Unknown && !mGeometryTypesResolved )
{
// unknown geometry item can't be selected
return Qt::ItemFlags();
@@ -92,6 +92,12 @@ Qt::ItemFlags QgsProviderSublayerDialogModel::flags( const QModelIndex &index )
return QgsProviderSublayerModel::flags( index );
}

void QgsProviderSublayerDialogModel::setGeometryTypesResolved( bool resolved )
{
mGeometryTypesResolved = resolved;
emit dataChanged( index( 0, 0 ), index( rowCount( QModelIndex() ), columnCount() ) );
}

QgsProviderSublayersDialog::QgsProviderSublayersDialog( const QString &uri, const QString &filePath, const QList<QgsProviderSublayerDetails> initialDetails, const QList<QgsMapLayerType> &acceptableTypes, QWidget *parent, Qt::WindowFlags fl )
: QDialog( parent, fl )
{
@@ -155,6 +161,7 @@ QgsProviderSublayersDialog::QgsProviderSublayersDialog( const QString &uri, cons
} ), res.end() );

mModel->setSublayerDetails( res );
mModel->setGeometryTypesResolved( true );
mTask = nullptr;
selectAll();
} );
@@ -39,6 +39,12 @@ class QgsProviderSublayerDialogModel : public QgsProviderSublayerModel
QVariant data( const QModelIndex &index, int role ) const override;
Qt::ItemFlags flags( const QModelIndex &index ) const override;

void setGeometryTypesResolved( bool resolved );

private:

bool mGeometryTypesResolved = false;


};

@@ -75,7 +81,7 @@ class QgsProviderSublayersDialog : public QDialog, private Ui::QgsProviderSublay

private:

QgsProviderSublayerModel *mModel = nullptr;
QgsProviderSublayerDialogModel *mModel = nullptr;
QgsProviderSublayerProxyModel *mProxyModel = nullptr;
QPointer< QgsProviderSublayerTask > mTask;
QString mFilePath;

0 comments on commit 6012caf

Please sign in to comment.