Skip to content
Permalink
Browse files

Confirm when removing hidden layers

The message now lists max 10 hidden layer names in
the confirmation dialog.
  • Loading branch information
elpaso committed Oct 29, 2020
1 parent 884bd9a commit b2e05d00cdc576f23969e143e350aa5e35114229
Showing with 37 additions and 2 deletions.
  1. +37 −2 src/app/qgisapp.cpp
@@ -11577,8 +11577,43 @@ void QgisApp::removeLayer()
}

bool shiftHeld = QApplication::queryKeyboardModifiers().testFlag( Qt::ShiftModifier );
//display a warning
if ( !shiftHeld && promptConfirmation && QMessageBox::warning( this, tr( "Remove layers and groups" ), tr( "Remove %n legend entries?", "number of legend items to remove", selectedNodes.count() ), QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )

// Check if there are any hidden layer elements and display a confirmation dialog
QStringList hiddenLayerNames;
auto harvest = [ &hiddenLayerNames ]( const QgsLayerTreeNode * parent )
{
const auto cChildren { parent->children() };
for ( const auto &c : cChildren )
{
if ( QgsLayerTree::isLayer( c ) )
{
const auto treeLayer { QgsLayerTree::toLayer( c ) };
if ( treeLayer->layer() && treeLayer->layer()->flags().testFlag( QgsMapLayer::LayerFlag::Hidden ) )
{
hiddenLayerNames.push_back( treeLayer->layer()->name( ) );
}
}
}
};

for ( const auto &n : qgis::as_const( selectedNodes ) )
{
harvest( n );
}

QString message { tr( "Remove %n legend entries?", "number of legend items to remove", selectedNodes.count() ) };
if ( ! hiddenLayerNames.isEmpty() )
{
if ( hiddenLayerNames.count( ) > 10 )
{
const int layerCount { hiddenLayerNames.count( ) };
hiddenLayerNames = hiddenLayerNames.mid( 0, 10 );
hiddenLayerNames.push_back( tr( "(%n more hidden layers)", "number of hidden layers not shown", layerCount - 10 ) );
}
message.append( tr( "The following hidden layers will be removed:\n%1" ).arg( hiddenLayerNames.join( '\n' ) ) );
}

if ( !shiftHeld && promptConfirmation && QMessageBox::warning( this, tr( "Remove layers and groups" ), message, QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
{
return;
}

0 comments on commit b2e05d0

Please sign in to comment.
You can’t perform that action at this time.