Skip to content

Commit

Permalink
show failure to create a new shapefile on message bar and point to me…
Browse files Browse the repository at this point in the history
…ssage log (fixes #6709)
  • Loading branch information
jef-n committed Jun 21, 2014
1 parent d2bc8fb commit 71c15f0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion python/gui/qgsnewvectorlayerdialog.sip
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class QgsNewVectorLayerDialog : QDialog

public:

// run the dialog, create the layer. Return file name if the creation was successful
// run the dialog, create the layer.
// @return fileName on success, empty string use aborted, QString::null if creation failed
static QString runAndCreateLayer( QWidget* parent = 0, QString* enc = 0 );

QgsNewVectorLayerDialog( QWidget *parent = 0, Qt::WindowFlags fl = QgisGui::ModalDialogFlags );
Expand Down
8 changes: 8 additions & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3641,6 +3641,14 @@ void QgisApp::newVectorLayer()
//todo: the last parameter will change accordingly to layer type
addVectorLayers( fileNames, enc, "file" );
}
else if( fileName.isNull() )
{
QLabel *msgLabel = new QLabel( tr( "Layer creation failed. Please check the <a href=\"#messageLog\">message log</a> for further information." ), messageBar() );
msgLabel->setWordWrap( true );
connect( msgLabel, SIGNAL( linkActivated( QString ) ), mLogDock, SLOT( show() ) );
QgsMessageBarItem *item = new QgsMessageBarItem( msgLabel, QgsMessageBar::WARNING );
messageBar()->pushItem( item );
}
}

void QgisApp::newSpatialiteLayer()
Expand Down
11 changes: 6 additions & 5 deletions src/gui/qgsnewvectorlayerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ QString QgsNewVectorLayerDialog::runAndCreateLayer( QWidget* parent, QString* pE
QgsNewVectorLayerDialog geomDialog( parent );
if ( geomDialog.exec() == QDialog::Rejected )
{
return QString();
return "";
}

QGis::WkbType geometrytype = geomDialog.selectedType();
Expand All @@ -261,7 +261,7 @@ QString QgsNewVectorLayerDialog::runAndCreateLayer( QWidget* parent, QString* pE
QString fileName = QFileDialog::getSaveFileName( 0, tr( "Save layer as..." ), lastUsedDir, filterString );
if ( fileName.isNull() )
{
return fileName;
return "";
}

if ( fileformat == "ESRI Shapefile" && !fileName.endsWith( ".shp", Qt::CaseInsensitive ) )
Expand Down Expand Up @@ -290,23 +290,24 @@ QString QgsNewVectorLayerDialog::runAndCreateLayer( QWidget* parent, QString* pE
QgsCoordinateReferenceSystem srs( crsId, QgsCoordinateReferenceSystem::InternalCrsId );
if ( !createEmptyDataSource( fileName, fileformat, enc, geometrytype, attributes, &srs ) )
{
return QString();
return QString::null;
}
}
else
{
QgsDebugMsg( "geometry type not recognised" );
return QString();
return QString::null;
}
}
else
{
QgsDebugMsg( "Resolving newEmptyDataSource(...) failed" );
return QString();
return QString::null;
}
}

if ( pEnc )
*pEnc = enc;

return fileName;
}
3 changes: 2 additions & 1 deletion src/gui/qgsnewvectorlayerdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class GUI_EXPORT QgsNewVectorLayerDialog: public QDialog, private Ui::QgsNewVect

public:

// run the dialog, create the layer. Return file name if the creation was successful
// run the dialog, create the layer.
// @return fileName on success, empty string use aborted, QString::null if creation failed
static QString runAndCreateLayer( QWidget* parent = 0, QString* enc = 0 );

QgsNewVectorLayerDialog( QWidget *parent = 0, Qt::WindowFlags fl = QgisGui::ModalDialogFlags );
Expand Down

0 comments on commit 71c15f0

Please sign in to comment.