Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
UI: better information message when toggling off edition mode on a tr…
…ansaction group

Previously, we always displayed the name of the layer we toggled off, even if
it was not modified, which could be confusing.
Now we will display up to two layer names that have been modified.
  • Loading branch information
rouault authored and nyalldawson committed Sep 16, 2020
1 parent 92ed450 commit ae71913
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -10879,8 +10879,42 @@ bool QgisApp::toggleEditing( QgsMapLayer *layer, bool allowCancel )
bool isModified = false;

// Assume changes if: a) the layer reports modifications or b) its transaction group was modified
if ( vlayer->isModified() || ( tg && tg->layers().contains( vlayer ) && tg->modified() ) )
QString modifiedLayerNames;
bool hasSeveralModifiedLayers = false;
if ( tg && tg->layers().contains( vlayer ) && tg->modified() )
{
isModified = true;
std::vector<QString> vectModifiedLayerNames;
if ( vlayer->isModified() )
{
vectModifiedLayerNames.push_back( vlayer->name() );
}
for ( QgsVectorLayer *iterLayer : tg->layers() )
{
if ( iterLayer != vlayer && iterLayer->isModified() )
{
vectModifiedLayerNames.push_back( iterLayer->name() );
}
}
if ( vectModifiedLayerNames.size() == 1 )
{
modifiedLayerNames = vectModifiedLayerNames[0];
}
else if ( vectModifiedLayerNames.size() == 2 )
{
modifiedLayerNames = tr( "%1 and %2" ).arg( vectModifiedLayerNames[0] ).arg( vectModifiedLayerNames[1] );
}
else if ( vectModifiedLayerNames.size() > 2 )
{
modifiedLayerNames = tr( "%1, %2, …" ).arg( vectModifiedLayerNames[0] ).arg( vectModifiedLayerNames[1] );
}
hasSeveralModifiedLayers = vectModifiedLayerNames.size() > 1;
}
else if ( vlayer->isModified() )
{
isModified = true;
modifiedLayerNames = vlayer->name();
}

if ( !vlayer->isEditable() && !vlayer->readOnly() )
{
Expand Down Expand Up @@ -10915,7 +10949,9 @@ bool QgisApp::toggleEditing( QgsMapLayer *layer, bool allowCancel )

switch ( QMessageBox::question( nullptr,
tr( "Stop Editing" ),
tr( "Do you want to save the changes to layer %1?" ).arg( vlayer->name() ),
hasSeveralModifiedLayers ?
tr( "Do you want to save the changes to layers %1?" ).arg( modifiedLayerNames ) :
tr( "Do you want to save the changes to layer %1?" ).arg( modifiedLayerNames ),
buttons ) )
{
case QMessageBox::Cancel:
Expand Down

0 comments on commit ae71913

Please sign in to comment.