Skip to content

Commit bb138ab

Browse files
author
timlinux
committed
Partial fix for loading projects with missing layers from Sunilraj at KCube. see #3468
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15332 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent b7d97ad commit bb138ab

File tree

3 files changed

+48
-10
lines changed

3 files changed

+48
-10
lines changed

src/app/legend/qgslegend.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "qgsproject.h"
3434
#include "qgsrasterlayer.h"
3535
#include "qgsvectorlayer.h"
36+
#include "qgsprojectbadlayerguihandler.h"
3637

3738
#include <QFont>
3839
#include <QDomDocument>
@@ -999,9 +1000,19 @@ bool QgsLegend::readXML( QgsLegendGroup *parent, const QDomNode &node )
9991000
bool isOpen;
10001001
QgsLegendLayer* currentLayer = readLayerFromXML( childelem, isOpen );
10011002

1003+
bool ignorePressed = QgsProjectBadLayerGuiHandler::mIgnore;
1004+
10021005
if ( !currentLayer )
1003-
return false;
1004-
1006+
{
1007+
if( ignorePressed == true )
1008+
{
1009+
continue;
1010+
}
1011+
else
1012+
{
1013+
return false;
1014+
}
1015+
}
10051016
// add to tree - either as a top-level node or a child of a group
10061017
if ( parent )
10071018
{

src/gui/qgsprojectbadlayerguihandler.cpp

+32-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <QDomDocument>
55
#include <QFileInfo>
66
#include <QMessageBox>
7+
#include <QtGui/QPushButton>
78

89
#include "qgslogger.h"
910
#include "qgisgui.h"
@@ -13,27 +14,50 @@ QgsProjectBadLayerGuiHandler::QgsProjectBadLayerGuiHandler()
1314
{
1415
}
1516

17+
bool QgsProjectBadLayerGuiHandler::mIgnore = false;
18+
1619
void QgsProjectBadLayerGuiHandler::handleBadLayers( QList<QDomNode> layers, QDomDocument projectDom )
1720
{
1821
QgsDebugMsg( QString( "%1 bad layers found" ).arg( layers.size() ) );
1922

2023
// make sure we have arrow cursor (and not a wait cursor)
2124
QApplication::setOverrideCursor( Qt::ArrowCursor );
22-
23-
if ( QMessageBox::Ok == QMessageBox::critical( NULL,
24-
tr( "QGIS Project Read Error" ),
25-
tr( "Unable to open one or more project layers\nTry to find missing layers?" ),
26-
QMessageBox::Ok | QMessageBox::Cancel ) )
25+
26+
QMessageBox messageBox;
27+
28+
QAbstractButton *ignoreButton =
29+
messageBox.addButton(tr("Ignore"),QMessageBox::ActionRole);
30+
31+
QAbstractButton *okButton = messageBox.addButton( QMessageBox :: Ok );
32+
33+
messageBox.addButton( QMessageBox :: Cancel );
34+
35+
messageBox.setWindowTitle(tr("QGIS Project Read Error"));
36+
messageBox.setText(tr("Unable to open one or more project layers\nTry to find missing layers?"));
37+
messageBox.setIcon(QMessageBox::Critical);
38+
messageBox.exec();
39+
40+
QgsProjectBadLayerGuiHandler::mIgnore = false;
41+
42+
if(messageBox.clickedButton() == okButton)
2743
{
2844
QgsDebugMsg( "want to find missing layers is true" );
29-
45+
3046
// attempt to find the new locations for missing layers
3147
// XXX vector file hard-coded -- but what if it's raster?
3248

3349
QString filter = QgsProviderRegistry::instance()->fileVectorFilters();
3450
findLayers( filter, layers );
35-
}
36-
51+
}
52+
else if (messageBox.clickedButton() == ignoreButton)
53+
{
54+
QgsProjectBadLayerGuiHandler::mIgnore = true;
55+
}
56+
else
57+
{
58+
// Do nothing
59+
}
60+
3761
QApplication::restoreOverrideCursor();
3862
}
3963

src/gui/qgsprojectbadlayerguihandler.h

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ class GUI_EXPORT QgsProjectBadLayerGuiHandler : public QObject, public QgsProjec
1919

2020
/** implementation of the handler */
2121
virtual void handleBadLayers( QList<QDomNode> layers, QDomDocument projectDom );
22+
23+
/** Flag to store the Ignore button press of MessageBox used by QgsLegend */
24+
static bool mIgnore;
2225

2326
protected:
2427

0 commit comments

Comments
 (0)