Skip to content

Commit

Permalink
Partial fix for loading projects with missing layers from Sunilraj at…
Browse files Browse the repository at this point in the history
… KCube. see #3468

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15332 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Mar 4, 2011
1 parent b7d97ad commit bb138ab
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
15 changes: 13 additions & 2 deletions src/app/legend/qgslegend.cpp
Expand Up @@ -33,6 +33,7 @@
#include "qgsproject.h"
#include "qgsrasterlayer.h"
#include "qgsvectorlayer.h"
#include "qgsprojectbadlayerguihandler.h"

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

bool ignorePressed = QgsProjectBadLayerGuiHandler::mIgnore;

if ( !currentLayer )
return false;

{
if( ignorePressed == true )
{
continue;
}
else
{
return false;
}
}
// add to tree - either as a top-level node or a child of a group
if ( parent )
{
Expand Down
40 changes: 32 additions & 8 deletions src/gui/qgsprojectbadlayerguihandler.cpp
Expand Up @@ -4,6 +4,7 @@
#include <QDomDocument>
#include <QFileInfo>
#include <QMessageBox>
#include <QtGui/QPushButton>

#include "qgslogger.h"
#include "qgisgui.h"
Expand All @@ -13,27 +14,50 @@ QgsProjectBadLayerGuiHandler::QgsProjectBadLayerGuiHandler()
{
}

bool QgsProjectBadLayerGuiHandler::mIgnore = false;

void QgsProjectBadLayerGuiHandler::handleBadLayers( QList<QDomNode> layers, QDomDocument projectDom )
{
QgsDebugMsg( QString( "%1 bad layers found" ).arg( layers.size() ) );

// make sure we have arrow cursor (and not a wait cursor)
QApplication::setOverrideCursor( Qt::ArrowCursor );

if ( QMessageBox::Ok == QMessageBox::critical( NULL,
tr( "QGIS Project Read Error" ),
tr( "Unable to open one or more project layers\nTry to find missing layers?" ),
QMessageBox::Ok | QMessageBox::Cancel ) )

QMessageBox messageBox;

QAbstractButton *ignoreButton =
messageBox.addButton(tr("Ignore"),QMessageBox::ActionRole);

QAbstractButton *okButton = messageBox.addButton( QMessageBox :: Ok );

messageBox.addButton( QMessageBox :: Cancel );

messageBox.setWindowTitle(tr("QGIS Project Read Error"));
messageBox.setText(tr("Unable to open one or more project layers\nTry to find missing layers?"));
messageBox.setIcon(QMessageBox::Critical);
messageBox.exec();

QgsProjectBadLayerGuiHandler::mIgnore = false;

if(messageBox.clickedButton() == okButton)
{
QgsDebugMsg( "want to find missing layers is true" );

// attempt to find the new locations for missing layers
// XXX vector file hard-coded -- but what if it's raster?

QString filter = QgsProviderRegistry::instance()->fileVectorFilters();
findLayers( filter, layers );
}

}
else if (messageBox.clickedButton() == ignoreButton)
{
QgsProjectBadLayerGuiHandler::mIgnore = true;
}
else
{
// Do nothing
}

QApplication::restoreOverrideCursor();
}

Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsprojectbadlayerguihandler.h
Expand Up @@ -19,6 +19,9 @@ class GUI_EXPORT QgsProjectBadLayerGuiHandler : public QObject, public QgsProjec

/** implementation of the handler */
virtual void handleBadLayers( QList<QDomNode> layers, QDomDocument projectDom );

/** Flag to store the Ignore button press of MessageBox used by QgsLegend */
static bool mIgnore;

protected:

Expand Down

0 comments on commit bb138ab

Please sign in to comment.