Skip to content
Permalink
Browse files

[georef] Make plugin less frustrating to use.

Adds a message bar, and converts most message boxes to message bar
messages. Now, most transformation parameters are checked when the
transform is attempted, rather then when the transform properties
dialog is opened. This avoids the frustrating situation where the
transform settings dialog blocks you from selecting transform
parameters before adding GCPs.
  • Loading branch information
nyalldawson committed Jun 20, 2015
1 parent 06443f3 commit da548d08d430f02e3dc6545d54ea814977967dc6
@@ -64,6 +64,7 @@
#include "qgstransformsettingsdialog.h"

#include "qgsgeorefplugingui.h"
#include "qgsmessagebar.h"

QgsGeorefDockWidget::QgsGeorefDockWidget( const QString & title, QWidget * parent, Qt::WindowFlags flags )
: QDockWidget( title, parent, flags )
@@ -90,13 +91,23 @@ QgsGeorefPluginGui::QgsGeorefPluginGui( QgisInterface* theQgisInterface, QWidget
QSettings s;
restoreGeometry( s.value( "/Plugin-GeoReferencer/Window/geometry" ).toByteArray() );

QWidget *centralWidget = this->centralWidget();
mCentralLayout = new QGridLayout( centralWidget );
centralWidget->setLayout( mCentralLayout );
mCentralLayout->setContentsMargins( 0, 0, 0, 0 );

createActions();
createActionGroups();
createMenus();
createMapCanvas();
createDockWidgets();
createStatusBar();

// a bar to warn the user with non-blocking messages
mMessageBar = new QgsMessageBar( centralWidget );
mMessageBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
mCentralLayout->addWidget( mMessageBar, 0, 0, 1, 1 );

setAddPointTool();
setupConnections();
readSettings();
@@ -368,8 +379,9 @@ void QgsGeorefPluginGui::generateGDALScript()
}
}
default:
QMessageBox::information( this, tr( "Info" ), tr( "GDAL scripting is not supported for %1 transformation" )
.arg( convertTransformEnumToString( mTransformParam ) ) );
mMessageBar->pushMessage( tr( "Invalid Transform" ), tr( "GDAL scripting is not supported for %1 transformation." )
.arg( convertTransformEnumToString( mTransformParam ) )
, QgsMessageBar::WARNING, messageTimeout() );
}
}

@@ -575,7 +587,7 @@ void QgsGeorefPluginGui::saveGCPsDialog()
{
if ( mPoints.isEmpty() )
{
QMessageBox::information( this, tr( "Info" ), tr( "No GCP points to save" ) );
mMessageBar->pushMessage( tr( "No GCP Points" ), tr( "No GCP points are available to save." ), QgsMessageBar::WARNING, messageTimeout() );
return;
}

@@ -602,7 +614,7 @@ void QgsGeorefPluginGui::showRasterPropertiesDialog()
}
else
{
QMessageBox::information( this, tr( "Info" ), tr( "Please load raster to be georeferenced" ) );
mMessageBar->pushMessage( tr( "Raster Properties" ), tr( "Please load raster to be georeferenced." ), QgsMessageBar::INFO, messageTimeout() );
}
}

@@ -903,11 +915,11 @@ void QgsGeorefPluginGui::createActionGroups()
void QgsGeorefPluginGui::createMapCanvas()
{
// set up the canvas
mCanvas = new QgsMapCanvas( this, "georefCanvas" );
mCanvas = new QgsMapCanvas( this->centralWidget(), "georefCanvas" );
mCanvas->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
mCanvas->setCanvasColor( Qt::white );
mCanvas->setMinimumWidth( 400 );
setCentralWidget( mCanvas );
mCentralLayout->addWidget( mCanvas, 0, 0, 2, 1 );

// set up map tools
mToolZoomIn = new QgsMapToolZoom( mCanvas, false /* zoomOut */ );
@@ -1240,7 +1252,7 @@ void QgsGeorefPluginGui::saveGCPs()
}
else
{
QMessageBox::information( this, tr( "Info" ), tr( "Unable to open GCP points file %1" ).arg( mGCPpointsFileName ) );
mMessageBar->pushMessage( tr( "Write Error" ), tr( "Could not write to GCP points file %1." ).arg( mGCPpointsFileName ), QgsMessageBar::WARNING, messageTimeout() );
return;
}

@@ -1288,11 +1300,8 @@ bool QgsGeorefPluginGui::georeference()
double pixelXSize, pixelYSize, rotation;
if ( !mGeorefTransform.getOriginScaleRotation( origin, pixelXSize, pixelYSize, rotation ) )
{
QMessageBox::information( this, tr( "Info" ),
tr( "Failed to get linear transform parameters" ) );
{
return false;
}
mMessageBar->pushMessage( tr( "Transform Failed" ), tr( "Failed to calculate linear transform parameters." ), QgsMessageBar::WARNING, messageTimeout() );
return false;
}

if ( !mWorldFileName.isEmpty() )
@@ -1336,7 +1345,7 @@ bool QgsGeorefPluginGui::georeference()
if ( res == 0 ) // fault to compute GCP transform
{
//TODO: be more specific in the error message
QMessageBox::information( this, tr( "Info" ), tr( "Failed to compute GCP transform: Transform is not solvable" ) );
mMessageBar->pushMessage( tr( "Transform Failed" ), tr( "Failed to compute GCP transform: Transform is not solvable." ), QgsMessageBar::WARNING, messageTimeout() );
return false;
}
else if ( res == -1 ) // operation canceled
@@ -1368,8 +1377,7 @@ bool QgsGeorefPluginGui::writeWorldFile( QgsPoint origin, double pixelXSize, dou
QFile file( mWorldFileName );
if ( !file.open( QIODevice::WriteOnly ) )
{
QMessageBox::critical( this, tr( "Error" ),
tr( "Could not write to %1" ).arg( mWorldFileName ) );
mMessageBar->pushMessage( tr( "Error" ), tr( "Could not write to %1." ).arg( mWorldFileName ), QgsMessageBar::CRITICAL, messageTimeout() );
return false;
}

@@ -1848,49 +1856,37 @@ bool QgsGeorefPluginGui::checkReadyGeoref()
{
if ( mRasterFileName.isEmpty() )
{
QMessageBox::information( this, tr( "Info" ), tr( "Please load raster to be georeferenced" ) );
mMessageBar->pushMessage( tr( "No Raster Loaded" ), tr( "Please load raster to be georeferenced" ), QgsMessageBar::WARNING, messageTimeout() );
return false;
}

bool ok = false;
while ( !ok )
if ( QgsGeorefTransform::InvalidTransform == mTransformParam )
{
if ( QgsGeorefTransform::InvalidTransform == mTransformParam )
{
QMessageBox::information( this, tr( "Info" ), tr( "Please set transformation type" ) );
if ( !getTransformSettings() )
return false;

continue;
}

//MH: helmert transformation without warping disabled until qgis is able to read rotated rasters efficiently
if ( mModifiedRasterFileName.isEmpty() && QgsGeorefTransform::Linear != mTransformParam /*&& QgsGeorefTransform::Helmert != mTransformParam*/ )
{
QMessageBox::information( this, tr( "Info" ), tr( "Please set output raster name" ) );
if ( !getTransformSettings() )
return false;

continue;
}

if ( mPoints.count() < ( int )mGeorefTransform.getMinimumGCPCount() )
{
QMessageBox::information( this, tr( "Info" ), tr( "%1 requires at least %2 GCPs. Please define more" )
.arg( convertTransformEnumToString( mTransformParam ) ).arg( mGeorefTransform.getMinimumGCPCount() ) );
if ( !getTransformSettings() )
return false;
QMessageBox::information( this, tr( "Info" ), tr( "Please set transformation type" ) );
getTransformSettings();
return false;
}

continue;
}
//MH: helmert transformation without warping disabled until qgis is able to read rotated rasters efficiently
if ( mModifiedRasterFileName.isEmpty() && QgsGeorefTransform::Linear != mTransformParam /*&& QgsGeorefTransform::Helmert != mTransformParam*/ )
{
QMessageBox::information( this, tr( "Info" ), tr( "Please set output raster name" ) );
getTransformSettings();
return false;
}

ok = true;
if ( mPoints.count() < ( int )mGeorefTransform.getMinimumGCPCount() )
{
mMessageBar->pushMessage( tr( "Not Enough GCPs" ), tr( "%1 transformation requires at least %2 GCPs. Please define more." )
.arg( convertTransformEnumToString( mTransformParam ) ).arg( mGeorefTransform.getMinimumGCPCount() )
, QgsMessageBar::WARNING, messageTimeout() );
return false;
}

// Update the transform if necessary
if ( !updateGeorefTransform() )
{
QMessageBox::information( this, tr( "Info" ), tr( "Failed to compute GCP transform: Transform is not solvable" ) );
mMessageBar->pushMessage( tr( "Transform Failed" ), tr( "Failed to compute GCP transform: Transform is not solvable." ), QgsMessageBar::WARNING, messageTimeout() );
// logRequaredGCPs();
return false;
}
@@ -2132,3 +2128,9 @@ void QgsGeorefPluginGui::clearGCPData()

mIface->mapCanvas()->refresh();
}

int QgsGeorefPluginGui::messageTimeout()
{
QSettings settings;
return settings.value( "/qgis/messageTimeout", 5 ).toInt();
}
@@ -38,6 +38,7 @@ class QgsMapCoordsDialog;
class QgsPoint;
class QgsRasterLayer;
class QgsRectangle;
class QgsMessageBar;

class QgsGeorefDockWidget : public QDockWidget
{
@@ -198,7 +199,9 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
/**Docks / undocks this window*/
void dockThisWindow( bool dock );

QGridLayout* mCentralLayout;

QgsMessageBar* mMessageBar;
QMenu *mPanelMenu;
QMenu *mToolbarMenu;

@@ -253,6 +256,7 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
bool mLoadInQgis;

QDockWidget* mDock;
int messageTimeout();
};

#endif
@@ -13,9 +13,7 @@
<property name="windowTitle">
<string>Georeferencer</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout"/>
</widget>
<widget class="QWidget" name="mCentralwidget"/>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
@@ -155,35 +155,21 @@ void QgsTransformSettingsDialog::changeEvent( QEvent *e )

void QgsTransformSettingsDialog::accept()
{
int minGCPpoints;
if ( checkGCPpoints( cmbTransformType->itemData( cmbTransformType->currentIndex() ).toInt(), minGCPpoints ) )
if ( !leOutputRaster->text().isEmpty() )
{
if ( leOutputRaster->text().isEmpty() && !mWorldFileCheckBox->isChecked() )
//if the file path is relative, make it relative to the raster file directory
QString outputRasterName = leOutputRaster->text();
QFileInfo rasterFileInfo( mModifiedRaster );
QFileInfo outputFileInfo( rasterFileInfo.absoluteDir(), outputRasterName );

if ( outputFileInfo.fileName().isEmpty() || !outputFileInfo.dir().exists() )
{
QMessageBox::information( this, tr( "Info" ), tr( "Please set output name" ) );
QMessageBox::warning( this, tr( "Info" ), tr( "Invalid output file name" ) );
leOutputRaster->setFocus();
return;
}
leOutputRaster->setText( outputFileInfo.absoluteFilePath() );
}
else
{
QMessageBox::information( this, tr( "Info" ), tr( "%1 requires at least %2 GCPs. Please define more" )
.arg( cmbTransformType->currentText() ).arg( minGCPpoints ) );
QSettings s;
cmbTransformType->setCurrentIndex( s.value( "/Plugin-GeoReferencer/lasttransformation", -1 ).toInt() );
return;
}

//if the file path is relative, make it relative to the raster file directory
QString outputRasterName = leOutputRaster->text();
QFileInfo rasterFileInfo( mModifiedRaster );
QFileInfo outputFileInfo( rasterFileInfo.absoluteDir(), outputRasterName );

if ( outputFileInfo.fileName().isEmpty() || !outputFileInfo.dir().exists() )
{
QMessageBox::information( this, tr( "Info" ), tr( "Invalid output file name" ) );
return;
}
leOutputRaster->setText( outputFileInfo.absoluteFilePath() );

QSettings s;
s.setValue( "/Plugin-GeoReferencer/lasttransformation", cmbTransformType->currentIndex() );

1 comment on commit da548d0

@NathanW2

This comment has been minimized.

Copy link
Member

@NathanW2 NathanW2 commented on da548d0 Jun 20, 2015

THANKS! Those dialogs. Arggg!

Please sign in to comment.
You can’t perform that action at this time.