Skip to content
Permalink
Browse files

[georeferencer] improve ui layout, use qgsfilewidget

  • Loading branch information
nirvn committed Dec 29, 2017
1 parent f7829db commit 63c192561833ab52ff650d1f47d3ae427d8d7ae4
@@ -20,6 +20,7 @@
#include "qgssettings.h"
#include "qgsprojectionselectiontreewidget.h"
#include "qgsapplication.h"
#include "qgsfilewidget.h"
#include "qgsrasterlayer.h"
#include "qgstransformsettingsdialog.h"
#include "qgscoordinatereferencesystem.h"
@@ -31,15 +32,54 @@ QgsTransformSettingsDialog::QgsTransformSettingsDialog( const QString &raster, c
, mCountGCPpoints( countGCPpoints )
{
setupUi( this );
connect( tbnOutputRaster, &QToolButton::clicked, this, &QgsTransformSettingsDialog::tbnOutputRaster_clicked );
connect( tbnMapFile, &QToolButton::clicked, this, &QgsTransformSettingsDialog::tbnMapFile_clicked );
connect( tbnReportFile, &QToolButton::clicked, this, &QgsTransformSettingsDialog::tbnReportFile_clicked );

QgsSettings settings;
restoreGeometry( settings.value( QStringLiteral( "/Plugin-GeoReferencer/TransformSettingsWindow/geometry" ) ).toByteArray() );

mOutputRaster->setStorageMode( QgsFileWidget::SaveFile );
if ( output.isEmpty() )
{
mOutputRaster->setFilePath( generateModifiedRasterFileName( mSourceRasterFile ) );
}
else
{
mOutputRaster->setFilePath( output );
}
mOutputRaster->setFilter( tr( "TIF files" ) + " (*.tif *.tiff *.TIF *.TIFF)" );
mOutputRaster->setDialogTitle( tr( "Destination Raster" ) );
mOutputRaster->setDefaultRoot( settings.value( QStringLiteral( "UI/lastRasterFileFilterDir" ), QDir::homePath() ).toString() );
connect( mOutputRaster, &QgsFileWidget::fileChanged, this, [ = ]
{
QgsSettings settings;
QFileInfo tmplFileInfo( mOutputRaster->filePath() );
settings.setValue( QStringLiteral( "UI/lastRasterFileFilterDir" ), tmplFileInfo.absolutePath() );
} );

mPdfMap->setStorageMode( QgsFileWidget::SaveFile );
mPdfMap->setFilter( tr( "PDF files" ) + " (*.pdf *.PDF)" );
mPdfMap->setDialogTitle( tr( "Save Map File as" ) );
mPdfMap->setDefaultRoot( settings.value( QStringLiteral( "/Plugin-GeoReferencer/lastPDFReportDir" ), QDir::homePath() ).toString() );
connect( mPdfMap, &QgsFileWidget::fileChanged, this, [ = ]
{
QgsSettings settings;
QFileInfo tmplFileInfo( mPdfMap->filePath() );
settings.setValue( QStringLiteral( "Plugin-GeoReferencer/lastPDFReportDir" ), tmplFileInfo.absolutePath() );
} );

mPdfReport->setStorageMode( QgsFileWidget::SaveFile );
mPdfReport->setFilter( tr( "PDF files" ) + " (*.pdf *.PDF)" );
mPdfReport->setDialogTitle( tr( "Save Report File as" ) );
mPdfReport->setDefaultRoot( settings.value( QStringLiteral( "/Plugin-GeoReferencer/lastPDFReportDir" ), QDir::homePath() ).toString() );
connect( mPdfReport, &QgsFileWidget::fileChanged, this, [ = ]
{
QgsSettings settings;
QFileInfo tmplFileInfo( mPdfReport->filePath() );
settings.setValue( QStringLiteral( "Plugin-GeoReferencer/lastPDFReportDir" ), tmplFileInfo.absolutePath() );
} );

connect( cmbTransformType, static_cast<void ( QComboBox::* )( const QString & )>( &QComboBox::currentIndexChanged ), this, &QgsTransformSettingsDialog::cmbTransformType_currentIndexChanged );
connect( mWorldFileCheckBox, &QCheckBox::stateChanged, this, &QgsTransformSettingsDialog::mWorldFileCheckBox_stateChanged );

QgsSettings s;
restoreGeometry( s.value( QStringLiteral( "/Plugin-GeoReferencer/TransformSettingsWindow/geometry" ) ).toByteArray() );

cmbTransformType->addItem( tr( "Linear" ), ( int )QgsGeorefTransform::Linear );
cmbTransformType->addItem( tr( "Helmert" ), ( int )QgsGeorefTransform::Helmert );
cmbTransformType->addItem( tr( "Polynomial 1" ), ( int )QgsGeorefTransform::PolynomialOrder1 );
@@ -48,8 +88,6 @@ QgsTransformSettingsDialog::QgsTransformSettingsDialog( const QString &raster, c
cmbTransformType->addItem( tr( "Thin Plate Spline" ), ( int )QgsGeorefTransform::ThinPlateSpline );
cmbTransformType->addItem( tr( "Projective" ), ( int )QgsGeorefTransform::Projective );

leOutputRaster->setText( output );

// Populate CompressionComboBox
mListCompression.append( QStringLiteral( "None" ) );
mListCompression.append( QStringLiteral( "LZW" ) );
@@ -62,27 +100,27 @@ QgsTransformSettingsDialog::QgsTransformSettingsDialog( const QString &raster, c
}
cmbCompressionComboBox->addItems( listCompressionTr );

cmbTransformType->setCurrentIndex( s.value( QStringLiteral( "/Plugin-GeoReferencer/lasttransformation" ), -1 ).toInt() );
cmbResampling->setCurrentIndex( s.value( QStringLiteral( "/Plugin-GeoReferencer/lastresampling" ), 0 ).toInt() );
cmbCompressionComboBox->setCurrentIndex( s.value( QStringLiteral( "/Plugin-GeoReferencer/lastcompression" ), 0 ).toInt() );
cmbTransformType->setCurrentIndex( settings.value( QStringLiteral( "/Plugin-GeoReferencer/lasttransformation" ), -1 ).toInt() );
cmbResampling->setCurrentIndex( settings.value( QStringLiteral( "/Plugin-GeoReferencer/lastresampling" ), 0 ).toInt() );
cmbCompressionComboBox->setCurrentIndex( settings.value( QStringLiteral( "/Plugin-GeoReferencer/lastcompression" ), 0 ).toInt() );

QString targetCRSString = s.value( QStringLiteral( "/Plugin-GeoReferencer/targetsrs" ) ).toString();
QString targetCRSString = settings.value( QStringLiteral( "/Plugin-GeoReferencer/targetsrs" ) ).toString();
QgsCoordinateReferenceSystem targetCRS = QgsCoordinateReferenceSystem::fromOgcWmsCrs( targetCRSString );
mCrsSelector->setCrs( targetCRS );

mWorldFileCheckBox->setChecked( s.value( QStringLiteral( "/Plugin-Georeferencer/word_file_checkbox" ), false ).toBool() );
mWorldFileCheckBox->setChecked( settings.value( QStringLiteral( "/Plugin-Georeferencer/word_file_checkbox" ), false ).toBool() );

cbxUserResolution->setChecked( s.value( QStringLiteral( "/Plugin-Georeferencer/user_specified_resolution" ), false ).toBool() );
cbxUserResolution->setChecked( settings.value( QStringLiteral( "/Plugin-Georeferencer/user_specified_resolution" ), false ).toBool() );
bool ok;
dsbHorizRes->setValue( s.value( QStringLiteral( "/Plugin-GeoReferencer/user_specified_resx" ), 1.0 ).toDouble( &ok ) );
dsbHorizRes->setValue( settings.value( QStringLiteral( "/Plugin-GeoReferencer/user_specified_resx" ), .0 ).toDouble( &ok ) );
if ( !ok )
dsbHorizRes->setValue( 1.0 );
dsbVerticalRes->setValue( s.value( QStringLiteral( "/Plugin-GeoReferencer/user_specified_resy" ), -1.0 ).toDouble( &ok ) );
dsbVerticalRes->setValue( settings.value( QStringLiteral( "/Plugin-GeoReferencer/user_specified_resy" ), -1.0 ).toDouble( &ok ) );
if ( !ok )
dsbHorizRes->setValue( -1.0 );

cbxZeroAsTrans->setChecked( s.value( QStringLiteral( "/Plugin-GeoReferencer/zeroastrans" ), false ).toBool() );
cbxLoadInQgisWhenDone->setChecked( s.value( QStringLiteral( "/Plugin-GeoReferencer/loadinqgis" ), false ).toBool() );
cbxZeroAsTrans->setChecked( settings.value( QStringLiteral( "/Plugin-GeoReferencer/zeroastrans" ), false ).toBool() );
cbxLoadInQgisWhenDone->setChecked( settings.value( QStringLiteral( "/Plugin-GeoReferencer/loadinqgis" ), false ).toBool() );
}

QgsTransformSettingsDialog::~QgsTransformSettingsDialog()
@@ -110,11 +148,11 @@ void QgsTransformSettingsDialog::getTransformSettings( QgsGeorefTransform::Trans
}
else
{
raster = leOutputRaster->text();
raster = mOutputRaster->filePath();
}
proj = mCrsSelector->crs();
pdfMapFile = mMapFileLineEdit->text();
pdfReportFile = mReportFileLineEdit->text();
pdfMapFile = mPdfMap->filePath();
pdfReportFile = mPdfReport->filePath();
zt = cbxZeroAsTrans->isChecked();
loadInQgis = cbxLoadInQgisWhenDone->isChecked();
resX = 0.0;
@@ -157,96 +195,40 @@ void QgsTransformSettingsDialog::changeEvent( QEvent *e )

void QgsTransformSettingsDialog::accept()
{
if ( !leOutputRaster->text().isEmpty() )
if ( !mOutputRaster->filePath().isEmpty() )
{
//if the file path is relative, make it relative to the raster file directory
QString outputRasterName = leOutputRaster->text();
QString outputRasterName = mOutputRaster->filePath();
QFileInfo rasterFileInfo( mSourceRasterFile );
QFileInfo outputFileInfo( rasterFileInfo.absoluteDir(), outputRasterName );

if ( outputFileInfo.fileName().isEmpty() || !outputFileInfo.dir().exists() )
{
QMessageBox::warning( this, tr( "Destination Raster" ), tr( "Invalid output file name." ) );
leOutputRaster->setFocus();
return;
}
if ( outputFileInfo.filePath() == mSourceRasterFile )
{
//can't overwrite input file
QMessageBox::warning( this, tr( "Destination Raster" ), tr( "Input raster can not be overwritten." ) );
leOutputRaster->setFocus();
return;
}
leOutputRaster->setText( outputFileInfo.absoluteFilePath() );
}

QgsSettings s;
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/lasttransformation" ), cmbTransformType->currentIndex() );
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/lastresampling" ), cmbResampling->currentIndex() );
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/lastcompression" ), cmbCompressionComboBox->currentIndex() );
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/targetsrs" ), mCrsSelector->crs().authid() );
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/zeroastrans" ), cbxZeroAsTrans->isChecked() );
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/loadinqgis" ), cbxLoadInQgisWhenDone->isChecked() );
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/user_specified_resolution" ), cbxUserResolution->isChecked() );
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/user_specified_resx" ), dsbHorizRes->value() );
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/user_specified_resy" ), dsbVerticalRes->value() );
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/word_file_checkbox" ), mWorldFileCheckBox->isChecked() );
QString pdfReportFileName = mReportFileLineEdit->text();
if ( !pdfReportFileName.isEmpty() )
{
QFileInfo fi( pdfReportFileName );
s.setValue( QStringLiteral( "/Plugin-GeoReferencer/lastPDFReportDir" ), fi.absolutePath() );
}
QDialog::accept();
}

void QgsTransformSettingsDialog::tbnOutputRaster_clicked()
{
QString selectedFile = leOutputRaster->text();
if ( selectedFile.isEmpty() )
{
selectedFile = generateModifiedRasterFileName( mSourceRasterFile );
mOutputRaster->setFilePath( outputFileInfo.absoluteFilePath() );
}

QString rasterFileName = QFileDialog::getSaveFileName( this, tr( "Destination Raster" ),
selectedFile, QStringLiteral( "GeoTIFF (*.tif *.tiff *.TIF *.TIFF)" ) );
if ( rasterFileName.isEmpty() )
return;

leOutputRaster->setText( rasterFileName );
leOutputRaster->setToolTip( rasterFileName );
}

void QgsTransformSettingsDialog::tbnMapFile_clicked()
{
QgsSettings s;
QString myLastUsedDir = s.value( QStringLiteral( "/Plugin-GeoReferencer/lastPDFReportDir" ), QDir::homePath() ).toString();
QString initialFile = !mMapFileLineEdit->text().isEmpty() ? mMapFileLineEdit->text() : myLastUsedDir;
QString outputFileName = QFileDialog::getSaveFileName( this, tr( "Save Map File as" ), initialFile, tr( "PDF Format" ) + " (*.pdf *PDF)" );
if ( !outputFileName.isNull() )
{
if ( !outputFileName.endsWith( QLatin1String( ".pdf" ), Qt::CaseInsensitive ) )
{
outputFileName.append( ".pdf" );
}
mMapFileLineEdit->setText( outputFileName );
}
}
QgsSettings settings;
settings.setValue( QStringLiteral( "/Plugin-GeoReferencer/lasttransformation" ), cmbTransformType->currentIndex() );
settings.setValue( QStringLiteral( "/Plugin-GeoReferencer/lastresampling" ), cmbResampling->currentIndex() );
settings.setValue( QStringLiteral( "/Plugin-GeoReferencer/lastcompression" ), cmbCompressionComboBox->currentIndex() );
settings.setValue( QStringLiteral( "/Plugin-GeoReferencer/targetsrs" ), mCrsSelector->crs().authid() );
settings.setValue( QStringLiteral( "/Plugin-GeoReferencer/zeroastrans" ), cbxZeroAsTrans->isChecked() );
settings.setValue( QStringLiteral( "/Plugin-GeoReferencer/loadinqgis" ), cbxLoadInQgisWhenDone->isChecked() );
settings.setValue( QStringLiteral( "/Plugin-GeoReferencer/user_specified_resolution" ), cbxUserResolution->isChecked() );
settings.setValue( QStringLiteral( "/Plugin-GeoReferencer/user_specified_resx" ), dsbHorizRes->value() );
settings.setValue( QStringLiteral( "/Plugin-GeoReferencer/user_specified_resy" ), dsbVerticalRes->value() );
settings.setValue( QStringLiteral( "/Plugin-GeoReferencer/word_file_checkbox" ), mWorldFileCheckBox->isChecked() );

void QgsTransformSettingsDialog::tbnReportFile_clicked()
{
QgsSettings s;
QString myLastUsedDir = s.value( QStringLiteral( "/Plugin-GeoReferencer/lastPDFReportDir" ), QDir::homePath() ).toString();
QString initialFile = !mReportFileLineEdit->text().isEmpty() ? mReportFileLineEdit->text() : myLastUsedDir;
QString outputFileName = QFileDialog::getSaveFileName( this, tr( "Save Report File as" ), initialFile, tr( "PDF Format" ) + " (*.pdf *PDF)" );
if ( !outputFileName.isNull() )
{
if ( !outputFileName.endsWith( QLatin1String( ".pdf" ), Qt::CaseInsensitive ) )
{
outputFileName.append( ".pdf" );
}
mReportFileLineEdit->setText( outputFileName );
}
QDialog::accept();
}

void QgsTransformSettingsDialog::cmbTransformType_currentIndexChanged( const QString &text )
@@ -271,8 +253,7 @@ void QgsTransformSettingsDialog::mWorldFileCheckBox_stateChanged( int state )
enableOutputRaster = false;
}
label_2->setEnabled( enableOutputRaster );
leOutputRaster->setEnabled( enableOutputRaster );
tbnOutputRaster->setEnabled( enableOutputRaster );
mOutputRaster->setEnabled( enableOutputRaster );
}

bool QgsTransformSettingsDialog::checkGCPpoints( int count, int &minGCPpoints )
@@ -42,9 +42,6 @@ class QgsTransformSettingsDialog : public QDialog, private Ui::QgsTransformSetti
void accept() override;

private slots:
void tbnOutputRaster_clicked();
void tbnMapFile_clicked();
void tbnReportFile_clicked();
void cmbTransformType_currentIndexChanged( const QString &text );
void mWorldFileCheckBox_stateChanged( int state );
QIcon getThemeIcon( const QString &name );

0 comments on commit 63c1925

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