From 6b917e09e14df14268f21ee51f767f73b6b241fc Mon Sep 17 00:00:00 2001 From: Alessandro Pasotti Date: Tue, 23 Oct 2018 20:19:19 +0200 Subject: [PATCH] Fix QgsProjectLayerGroupDialog with qgz project Maybe also fix #20134 - crash when trying to set exluded layer in QGIS Server WMS capabilities I could not reproduce the crash but QgsProjectLayerGroupDialog was broken and it was probably the root of the crash. --- src/app/qgsprojectlayergroupdialog.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/app/qgsprojectlayergroupdialog.cpp b/src/app/qgsprojectlayergroupdialog.cpp index 7f6c32e8f2b..13650c007f3 100644 --- a/src/app/qgsprojectlayergroupdialog.cpp +++ b/src/app/qgsprojectlayergroupdialog.cpp @@ -168,38 +168,43 @@ void QgsProjectLayerGroupDialog::changeProjectFile() return; } + std::unique_ptr archive; + QDomDocument projectDom; if ( QgsZipUtils::isZipFile( mProjectFileWidget->filePath() ) ) { - QgsProjectArchive archive; + + archive = qgis::make_unique(); // unzip the archive - if ( !archive.unzip( mProjectFileWidget->filePath() ) ) + if ( !archive->unzip( mProjectFileWidget->filePath() ) ) { return; } // test if zip provides a .qgs file - if ( archive.projectFile().isEmpty() ) + if ( archive->projectFile().isEmpty() ) { return; } - projectFile.setFileName( archive.projectFile() ); + projectFile.setFileName( archive->projectFile() ); if ( !projectFile.exists() ) { return; } } - - if ( !projectDom.setContent( &projectFile ) ) + QString errorMesssage; + int errorLine; + if ( !projectDom.setContent( &projectFile, &errorMesssage, &errorLine ) ) { + QgsDebugMsg( QStringLiteral( "Error reading the project file %1 at line %2: %3" ) + .arg( projectFile.fileName() ) + .arg( errorLine ) + .arg( errorMesssage ) ); return; } - - - mRootGroup->removeAllChildren(); QDomElement layerTreeElem = projectDom.documentElement().firstChildElement( QStringLiteral( "layer-tree-group" ) );