Skip to content
Permalink
Browse files

In case PROJ_LIB is set, disable grid shifts if .gsb file are not there

  • Loading branch information
mhugent committed Nov 12, 2013
1 parent 7c7d837 commit faea6347e77673e540435d25264894a01fe85e36
Showing with 66 additions and 0 deletions.
  1. +63 −0 src/gui/qgsdatumtransformdialog.cpp
  2. +3 −0 src/gui/qgsdatumtransformdialog.h
@@ -17,6 +17,7 @@

#include "qgsdatumtransformdialog.h"
#include "qgscoordinatetransform.h"
#include <QDir>

QgsDatumTransformDialog::QgsDatumTransformDialog( const QString& layerName, const QList< QList< int > >& dt, QWidget* parent, Qt::WindowFlags f ): QDialog( parent, f )
{
@@ -26,6 +27,8 @@ QgsDatumTransformDialog::QgsDatumTransformDialog( const QString& layerName, cons
for ( ; it != dt.constEnd(); ++it )
{
QTreeWidgetItem* item = new QTreeWidgetItem();
bool itemDisabled = false;

for ( int i = 0; i < 2; ++i )
{
if ( i >= it->size() )
@@ -39,7 +42,13 @@ QgsDatumTransformDialog::QgsDatumTransformDialog( const QString& layerName, cons
{
item->setText( i, QgsCoordinateTransform::datumTransformString( nr ) );
}

if ( gridShiftTransformation( item->text( i ) ) && !testGridShiftFileAvailability( item, i ) )
{
itemDisabled = true;
}
}
item->setDisabled( itemDisabled );
mDatumTransformTreeWidget->addTopLevelItem( item );
}
}
@@ -75,3 +84,57 @@ bool QgsDatumTransformDialog::rememberSelection() const
{
return mRememberSelectionCheckBox->isChecked();
}

bool QgsDatumTransformDialog::gridShiftTransformation( const QString& itemText ) const
{
return ( !itemText.isEmpty() && !itemText.contains( "towgs84", Qt::CaseInsensitive ) );
}

bool QgsDatumTransformDialog::testGridShiftFileAvailability( QTreeWidgetItem* item, int col ) const
{
if ( !item )
{
return true;
}

QString itemText = item->text( col );
if ( itemText.isEmpty() )
{
return true;
}

char* projLib = getenv( "PROJ_LIB" );
if ( !projLib ) //no information about installation directory
{
return true;
}

QStringList itemEqualSplit = itemText.split( "=" );
QString filename;
for ( int i = 1; i < itemEqualSplit.size(); ++i )
{
if ( i > 1 )
{
filename.append( "=" );
}
filename.append( itemEqualSplit.at( i ) );
}

QDir projDir( projLib );
if ( projDir.exists() )
{
//look if filename in directory
QStringList fileList = projDir.entryList();
QStringList::const_iterator fileIt = fileList.constBegin();
for ( ; fileIt != fileList.constEnd(); ++fileIt )
{
if ( *fileIt == filename )
{
return true;
}
}
item->setToolTip( col, tr( "File '%1' not found in directory '%2'" ).arg( filename ).arg( projDir.absolutePath() ) );
return false; //not found in PROJ_LIB directory
}
return true;
}
@@ -32,6 +32,9 @@ class GUI_EXPORT QgsDatumTransformDialog: public QDialog, private Ui::QgsDatumTr

private:
QgsDatumTransformDialog();
bool gridShiftTransformation( const QString& itemText ) const;
/**Returns false if the location of the grid shift files is known (PROJ_LIB) and the shift file is not there*/
bool testGridShiftFileAvailability( QTreeWidgetItem* item, int col ) const;
};

#endif // QGSDATUMTRANSFORMDIALOG_H

0 comments on commit faea634

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