Skip to content

Commit ae71913

Browse files
rouaultnyalldawson
authored andcommittedSep 16, 2020
UI: better information message when toggling off edition mode on a transaction 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.
1 parent 92ed450 commit ae71913

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10879,8 +10879,42 @@ bool QgisApp::toggleEditing( QgsMapLayer *layer, bool allowCancel )
1087910879
bool isModified = false;
1088010880

1088110881
// Assume changes if: a) the layer reports modifications or b) its transaction group was modified
10882-
if ( vlayer->isModified() || ( tg && tg->layers().contains( vlayer ) && tg->modified() ) )
10882+
QString modifiedLayerNames;
10883+
bool hasSeveralModifiedLayers = false;
10884+
if ( tg && tg->layers().contains( vlayer ) && tg->modified() )
10885+
{
10886+
isModified = true;
10887+
std::vector<QString> vectModifiedLayerNames;
10888+
if ( vlayer->isModified() )
10889+
{
10890+
vectModifiedLayerNames.push_back( vlayer->name() );
10891+
}
10892+
for ( QgsVectorLayer *iterLayer : tg->layers() )
10893+
{
10894+
if ( iterLayer != vlayer && iterLayer->isModified() )
10895+
{
10896+
vectModifiedLayerNames.push_back( iterLayer->name() );
10897+
}
10898+
}
10899+
if ( vectModifiedLayerNames.size() == 1 )
10900+
{
10901+
modifiedLayerNames = vectModifiedLayerNames[0];
10902+
}
10903+
else if ( vectModifiedLayerNames.size() == 2 )
10904+
{
10905+
modifiedLayerNames = tr( "%1 and %2" ).arg( vectModifiedLayerNames[0] ).arg( vectModifiedLayerNames[1] );
10906+
}
10907+
else if ( vectModifiedLayerNames.size() > 2 )
10908+
{
10909+
modifiedLayerNames = tr( "%1, %2, …" ).arg( vectModifiedLayerNames[0] ).arg( vectModifiedLayerNames[1] );
10910+
}
10911+
hasSeveralModifiedLayers = vectModifiedLayerNames.size() > 1;
10912+
}
10913+
else if ( vlayer->isModified() )
10914+
{
1088310915
isModified = true;
10916+
modifiedLayerNames = vlayer->name();
10917+
}
1088410918

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

1091610950
switch ( QMessageBox::question( nullptr,
1091710951
tr( "Stop Editing" ),
10918-
tr( "Do you want to save the changes to layer %1?" ).arg( vlayer->name() ),
10952+
hasSeveralModifiedLayers ?
10953+
tr( "Do you want to save the changes to layers %1?" ).arg( modifiedLayerNames ) :
10954+
tr( "Do you want to save the changes to layer %1?" ).arg( modifiedLayerNames ),
1091910955
buttons ) )
1092010956
{
1092110957
case QMessageBox::Cancel:

0 commit comments

Comments
 (0)
Please sign in to comment.