Skip to content

Commit fcf78fb

Browse files
committedNov 11, 2019
Extend temporary layer warning to include layers stored inside
a user's temporary folder, e.g. the "/tmp" folder on Linux This can lead to irretrievable data loss. Fixes #32582 (cherry picked from commit cc80bb4)
1 parent ab80e6d commit fcf78fb

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11785,7 +11785,8 @@ bool QgisApp::checkMemoryLayers()
1178511785
if ( !QgsSettings().value( QStringLiteral( "askToSaveMemoryLayers" ), true, QgsSettings::App ).toBool() )
1178611786
return true;
1178711787

11788-
// check to see if there are any memory layers present (with features)
11788+
// check to see if there are any temporary layers present (with features)
11789+
bool hasTemporaryLayers = false;
1178911790
bool hasMemoryLayers = false;
1179011791
const QMap<QString, QgsMapLayer *> layers = QgsProject::instance()->mapLayers();
1179111792
for ( auto it = layers.begin(); it != layers.end(); ++it )
@@ -11799,10 +11800,23 @@ bool QgisApp::checkMemoryLayers()
1179911800
break;
1180011801
}
1180111802
}
11803+
else if ( it.value() && it.value()->isTemporary() )
11804+
hasTemporaryLayers = true;
1180211805
}
1180311806

11804-
if ( hasMemoryLayers )
11807+
if ( hasTemporaryLayers )
1180511808
{
11809+
if ( QMessageBox::warning( this,
11810+
tr( "Close Project" ),
11811+
tr( "This project includes one or more temporary layers. These layers are not permanently saved and their contents will be lost. Are you sure you want to proceed?" ),
11812+
QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel ) == QMessageBox::Yes )
11813+
return true;
11814+
else
11815+
return false;
11816+
}
11817+
else if ( hasMemoryLayers )
11818+
{
11819+
// use the more specific warning for memory layers
1180611820
if ( QMessageBox::warning( this,
1180711821
tr( "Close Project" ),
1180811822
tr( "This project includes one or more temporary scratch layers. These layers are not saved to disk and their contents will be permanently lost. Are you sure you want to proceed?" ),

‎src/app/qgsapplayertreeviewmenuprovider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
298298

299299
if ( vlayer )
300300
{
301-
if ( vlayer->providerType() == QLatin1String( "memory" ) )
301+
if ( vlayer->isTemporary() )
302302
{
303303
QAction *actionMakePermanent = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "mActionFileSave.svg" ) ), tr( "Make Permanent…" ), menu );
304304
connect( actionMakePermanent, &QAction::triggered, QgisApp::instance(), [ = ] { QgisApp::instance()->makeMemoryLayerPermanent( vlayer ); } );

‎src/app/qgslayertreeviewmemoryindicator.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ void QgsLayerTreeViewMemoryIndicatorProvider::onIndicatorClicked( const QModelIn
4242

4343
bool QgsLayerTreeViewMemoryIndicatorProvider::acceptLayer( QgsMapLayer *layer )
4444
{
45-
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
46-
if ( !( vlayer && vlayer->isValid() ) )
45+
if ( !layer )
4746
return false;
48-
return vlayer->providerType() == QLatin1String( "memory" );
47+
48+
return layer->isTemporary();
4949
}
5050

5151
QString QgsLayerTreeViewMemoryIndicatorProvider::iconName( QgsMapLayer *layer )
@@ -56,7 +56,9 @@ QString QgsLayerTreeViewMemoryIndicatorProvider::iconName( QgsMapLayer *layer )
5656

5757
QString QgsLayerTreeViewMemoryIndicatorProvider::tooltipText( QgsMapLayer *layer )
5858
{
59-
Q_UNUSED( layer )
60-
return tr( "<b>Temporary scratch layer only!</b><br>Contents will be discarded after closing this project" );
59+
if ( layer->providerType() == QLatin1String( "memory" ) )
60+
return tr( "<b>Temporary scratch layer only!</b><br>Contents will be discarded after closing this project" );
61+
62+
return tr( "<b>Temporary layer only!</b><br>Contents will be discarded after closing QGIS." );
6163
}
6264

0 commit comments

Comments
 (0)