mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
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
This commit is contained in:
parent
377848e2ad
commit
cc80bb4af6
@ -11932,7 +11932,8 @@ bool QgisApp::checkMemoryLayers()
|
||||
if ( !QgsSettings().value( QStringLiteral( "askToSaveMemoryLayers" ), true, QgsSettings::App ).toBool() )
|
||||
return true;
|
||||
|
||||
// check to see if there are any memory layers present (with features)
|
||||
// check to see if there are any temporary layers present (with features)
|
||||
bool hasTemporaryLayers = false;
|
||||
bool hasMemoryLayers = false;
|
||||
const QMap<QString, QgsMapLayer *> layers = QgsProject::instance()->mapLayers();
|
||||
for ( auto it = layers.begin(); it != layers.end(); ++it )
|
||||
@ -11946,10 +11947,23 @@ bool QgisApp::checkMemoryLayers()
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if ( it.value() && it.value()->isTemporary() )
|
||||
hasTemporaryLayers = true;
|
||||
}
|
||||
|
||||
if ( hasMemoryLayers )
|
||||
if ( hasTemporaryLayers )
|
||||
{
|
||||
if ( QMessageBox::warning( this,
|
||||
tr( "Close Project" ),
|
||||
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?" ),
|
||||
QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel ) == QMessageBox::Yes )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else if ( hasMemoryLayers )
|
||||
{
|
||||
// use the more specific warning for memory layers
|
||||
if ( QMessageBox::warning( this,
|
||||
tr( "Close Project" ),
|
||||
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?" ),
|
||||
|
@ -298,7 +298,7 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
|
||||
|
||||
if ( vlayer )
|
||||
{
|
||||
if ( vlayer->providerType() == QLatin1String( "memory" ) )
|
||||
if ( vlayer->isTemporary() )
|
||||
{
|
||||
QAction *actionMakePermanent = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "mActionFileSave.svg" ) ), tr( "Make Permanent…" ), menu );
|
||||
connect( actionMakePermanent, &QAction::triggered, QgisApp::instance(), [ = ] { QgisApp::instance()->makeMemoryLayerPermanent( vlayer ); } );
|
||||
|
@ -42,10 +42,10 @@ void QgsLayerTreeViewMemoryIndicatorProvider::onIndicatorClicked( const QModelIn
|
||||
|
||||
bool QgsLayerTreeViewMemoryIndicatorProvider::acceptLayer( QgsMapLayer *layer )
|
||||
{
|
||||
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
|
||||
if ( !( vlayer && vlayer->isValid() ) )
|
||||
if ( !layer )
|
||||
return false;
|
||||
return vlayer->providerType() == QLatin1String( "memory" );
|
||||
|
||||
return layer->isTemporary();
|
||||
}
|
||||
|
||||
QString QgsLayerTreeViewMemoryIndicatorProvider::iconName( QgsMapLayer *layer )
|
||||
@ -56,7 +56,9 @@ QString QgsLayerTreeViewMemoryIndicatorProvider::iconName( QgsMapLayer *layer )
|
||||
|
||||
QString QgsLayerTreeViewMemoryIndicatorProvider::tooltipText( QgsMapLayer *layer )
|
||||
{
|
||||
Q_UNUSED( layer )
|
||||
return tr( "<b>Temporary scratch layer only!</b><br>Contents will be discarded after closing this project" );
|
||||
if ( layer->providerType() == QLatin1String( "memory" ) )
|
||||
return tr( "<b>Temporary scratch layer only!</b><br>Contents will be discarded after closing this project" );
|
||||
|
||||
return tr( "<b>Temporary layer only!</b><br>Contents will be discarded after closing QGIS." );
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user