Skip to content

Commit

Permalink
Automatically select all layers in sublayers dialog on show
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 6, 2021
1 parent 02b04fc commit 77b6e31
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/app/qgsprovidersublayersdialog.cpp
Expand Up @@ -156,24 +156,12 @@ QgsProviderSublayersDialog::QgsProviderSublayersDialog( const QString &uri, cons

mModel->setSublayerDetails( res );
mTask = nullptr;
selectAll();
} );
QgsApplication::taskManager()->addTask( mTask.data() );
}

connect( mBtnSelectAll, &QAbstractButton::pressed, this, [ = ]
{
mLayersTree->selectionModel()->clear();
for ( int row = 0; row < mProxyModel->rowCount(); ++row )
{
const QModelIndex index = mProxyModel->index( row, 0 );
if ( !mProxyModel->data( index, static_cast< int >( QgsProviderSublayerModel::Role::IsNonLayerItem ) ).toBool() )
{
mLayersTree->selectionModel()->select( QItemSelection( mLayersTree->model()->index( index.row(), 0, index.parent() ),
mLayersTree->model()->index( index.row(), mLayersTree->model()->columnCount() - 1, index.parent() ) ),
QItemSelectionModel::Select );
}
}
} );
connect( mBtnSelectAll, &QAbstractButton::pressed, this, &QgsProviderSublayersDialog::selectAll );
connect( mBtnDeselectAll, &QAbstractButton::pressed, this, [ = ] { mLayersTree->selectionModel()->clear(); } );
connect( mLayersTree->selectionModel(), &QItemSelectionModel::selectionChanged, this, &QgsProviderSublayersDialog::treeSelectionChanged );
connect( mSearchLineEdit, &QgsFilterLineEdit::textChanged, mProxyModel, &QgsProviderSublayerProxyModel::setFilterString );
Expand All @@ -194,6 +182,7 @@ QgsProviderSublayersDialog::QgsProviderSublayersDialog( const QString &uri, cons
mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
mButtonBox->button( QDialogButtonBox::Ok )->setText( tr( "Add Layers" ) );

selectAll();
}

void QgsProviderSublayersDialog::setNonLayerItems( const QList<QgsProviderSublayerModel::NonLayerItem> &items )
Expand Down Expand Up @@ -325,3 +314,18 @@ void QgsProviderSublayersDialog::treeSelectionChanged( const QItemSelection &sel
mCbxAddToGroup->setEnabled( !selectedANonLayerItem );
mButtonBox->button( QDialogButtonBox::Ok )->setText( selectedANonLayerItem ? tr( "Open" ) : tr( "Add Layers" ) );
}

void QgsProviderSublayersDialog::selectAll()
{
mLayersTree->selectionModel()->clear();
for ( int row = 0; row < mProxyModel->rowCount(); ++row )
{
const QModelIndex index = mProxyModel->index( row, 0 );
if ( !mProxyModel->data( index, static_cast< int >( QgsProviderSublayerModel::Role::IsNonLayerItem ) ).toBool() )
{
mLayersTree->selectionModel()->select( QItemSelection( mLayersTree->model()->index( index.row(), 0, index.parent() ),
mLayersTree->model()->index( index.row(), mLayersTree->model()->columnCount() - 1, index.parent() ) ),
QItemSelectionModel::Select );
}
}
}
1 change: 1 addition & 0 deletions src/app/qgsprovidersublayersdialog.h
Expand Up @@ -71,6 +71,7 @@ class QgsProviderSublayersDialog : public QDialog, private Ui::QgsProviderSublay

private slots:
void treeSelectionChanged( const QItemSelection &, const QItemSelection & );
void selectAll();

private:

Expand Down

0 comments on commit 77b6e31

Please sign in to comment.