Skip to content
Permalink
Browse files

Use QgsExtentGroupBox also in raster Save as dialog

  • Loading branch information
wonder-sk committed Mar 4, 2014
1 parent 8ac3a94 commit cbf2c1a83b310700f97415e9c70c0df507664f3d
@@ -57,13 +57,23 @@ void QgsExtentGroupBox::setOutputExtent( const QgsRectangle& r, const QgsCoordin

mExtentState = state;

updateExtentStateMsg();
updateTitle();

emit extentChanged( extent );
}


void QgsExtentGroupBox::updateExtentStateMsg()
void QgsExtentGroupBox::setOutputExtentFromLineEdit()
{
mExtentState = UserExtent;

updateTitle();

emit extentChanged( outputExtent() );
}


void QgsExtentGroupBox::updateTitle()
{
QString msg;
switch ( mExtentState )
@@ -98,6 +108,12 @@ void QgsExtentGroupBox::setOutputExtentFromOriginal()
}


void QgsExtentGroupBox::setOutputExtentFromUser( const QgsRectangle& extent, const QgsCoordinateReferenceSystem& crs )
{
setOutputExtent( extent, crs, UserExtent );
}


QgsRectangle QgsExtentGroupBox::outputExtent() const
{
return QgsRectangle( mXMinLineEdit->text().toDouble(), mYMinLineEdit->text().toDouble(),
@@ -52,27 +52,33 @@ class QgsExtentGroupBox : public QgsCollapsibleGroupBox, private Ui::QgsExtentGr
//! Get the resulting extent - in output CRS coordinates
QgsRectangle outputExtent() const;

ExtentState extentState() const { return mExtentState; }

public slots:
//! set output extent to be the same as original extent (may be transformed to output CRS)
void setOutputExtentFromOriginal();

//! set output extent to be the same as current extent (may be transformed to output CRS)
void setOutputExtentFromCurrent();

//! set output extent to custom extent (may be transformed to outut CRS)
void setOutputExtentFromUser( const QgsRectangle& extent, const QgsCoordinateReferenceSystem& crs );

signals:
//! emitted when extent is changed
void extentChanged( const QgsRectangle& r );

protected slots:

void on_mXMinLineEdit_textEdited( const QString & ) { mExtentState = UserExtent; updateExtentStateMsg(); }
void on_mXMaxLineEdit_textEdited( const QString & ) { mExtentState = UserExtent; updateExtentStateMsg(); }
void on_mYMinLineEdit_textEdited( const QString & ) { mExtentState = UserExtent; updateExtentStateMsg(); }
void on_mYMaxLineEdit_textEdited( const QString & ) { mExtentState = UserExtent; updateExtentStateMsg(); }
void on_mXMinLineEdit_textEdited( const QString & ) { setOutputExtentFromLineEdit(); }
void on_mXMaxLineEdit_textEdited( const QString & ) { setOutputExtentFromLineEdit(); }
void on_mYMinLineEdit_textEdited( const QString & ) { setOutputExtentFromLineEdit(); }
void on_mYMaxLineEdit_textEdited( const QString & ) { setOutputExtentFromLineEdit(); }

protected:
void setOutputExtent( const QgsRectangle& r, const QgsCoordinateReferenceSystem& srcCrs, ExtentState state );
void updateExtentStateMsg();
void setOutputExtentFromLineEdit();
void updateTitle();

ExtentState mExtentState;

@@ -32,7 +32,7 @@ QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterLayer* rasterLa
QDialog( parent, f )
, mRasterLayer( rasterLayer ), mDataProvider( sourceProvider )
, mCurrentExtent( currentExtent ), mLayerCrs( layerCrs )
, mCurrentCrs( currentCrs ), mExtentState( OriginalExtent )
, mCurrentCrs( currentCrs )
, mResolutionState( OriginalResolution )
{
setupUi( this );
@@ -67,9 +67,6 @@ QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterLayer* rasterLa
//fill reasonable default values depending on the provider
if ( mDataProvider )
{
//extent
setOutputExtent( mDataProvider->extent(), mLayerCrs, OriginalExtent );

if ( mDataProvider->capabilities() & QgsRasterDataProvider::Size )
{
setOriginalResolution();
@@ -133,6 +130,12 @@ QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterLayer* rasterLa
{
okButton->setEnabled( false );
}

mExtentGroupBox->setOutputCrs( outputCrs() );
mExtentGroupBox->setOriginalExtent( mDataProvider->extent(), mLayerCrs );
mExtentGroupBox->setCurrentExtent( mCurrentExtent, mCurrentCrs );
mExtentGroupBox->setOutputExtentFromOriginal();
connect( mExtentGroupBox, SIGNAL( extentChanged( QgsRectangle ) ), this, SLOT( extentChanged() ) );
}

void QgsRasterLayerSaveAsDialog::setValidators()
@@ -143,10 +146,6 @@ void QgsRasterLayerSaveAsDialog::setValidators()
mRowsLineEdit->setValidator( new QIntValidator( this ) );
mMaximumSizeXLineEdit->setValidator( new QIntValidator( this ) );
mMaximumSizeYLineEdit->setValidator( new QIntValidator( this ) );
mXMinLineEdit->setValidator( new QDoubleValidator( this ) );
mXMaxLineEdit->setValidator( new QDoubleValidator( this ) );
mYMinLineEdit->setValidator( new QDoubleValidator( this ) );
mYMaxLineEdit->setValidator( new QDoubleValidator( this ) );
}

QgsRasterLayerSaveAsDialog::~QgsRasterLayerSaveAsDialog()
@@ -215,18 +214,6 @@ void QgsRasterLayerSaveAsDialog::on_mSaveAsLineEdit_textChanged( const QString&
okButton->setEnabled( QFileInfo( text ).absoluteDir().exists() );
}

void QgsRasterLayerSaveAsDialog::on_mCurrentExtentButton_clicked()
{
setOutputExtent( mCurrentExtent, mCurrentCrs, CurrentExtent );
}

void QgsRasterLayerSaveAsDialog::on_mOriginalExtentButton_clicked()
{
if ( mDataProvider )
{
setOutputExtent( mDataProvider->extent(), mLayerCrs, OriginalExtent );
}
}

void QgsRasterLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( const QString & text )
{
@@ -290,29 +277,7 @@ QStringList QgsRasterLayerSaveAsDialog::createOptions() const

QgsRectangle QgsRasterLayerSaveAsDialog::outputRectangle() const
{
return QgsRectangle( mXMinLineEdit->text().toDouble(), mYMinLineEdit->text().toDouble(), mXMaxLineEdit->text().toDouble(), mYMaxLineEdit->text().toDouble() );
}

void QgsRasterLayerSaveAsDialog::setOutputExtent( const QgsRectangle& r, const QgsCoordinateReferenceSystem& srcCrs, ExtentState state )
{
QgsRectangle extent;
if ( outputCrs() == srcCrs )
{
extent = r;
}
else
{
QgsCoordinateTransform ct( srcCrs, outputCrs() );
extent = ct.transformBoundingBox( r );
}

mXMinLineEdit->setText( QgsRasterBlock::printValue( extent.xMinimum() ) );
mXMaxLineEdit->setText( QgsRasterBlock::printValue( extent.xMaximum() ) );
mYMinLineEdit->setText( QgsRasterBlock::printValue( extent.yMinimum() ) );
mYMaxLineEdit->setText( QgsRasterBlock::printValue( extent.yMaximum() ) );

mExtentState = state;
extentChanged();
return mExtentGroupBox->outputExtent();
}

void QgsRasterLayerSaveAsDialog::hideFormat()
@@ -451,7 +416,6 @@ void QgsRasterLayerSaveAsDialog::updateResolutionStateMsg()

void QgsRasterLayerSaveAsDialog::extentChanged()
{
updateExtentStateMsg();
// Whenever extent changes with fixed size, original resolution is lost
if ( mSizeRadioButton->isChecked() )
{
@@ -460,27 +424,6 @@ void QgsRasterLayerSaveAsDialog::extentChanged()
recalcResolutionSize();
}

void QgsRasterLayerSaveAsDialog::updateExtentStateMsg()
{
QString msg;
switch ( mExtentState )
{
case OriginalExtent:
msg = tr( "layer" );
break;
case CurrentExtent:
msg = tr( "map view" );
break;
case UserExtent:
msg = tr( "user defined" );
break;
default:
break;
}
msg = tr( "Extent (current: %1)" ).arg( msg );
mExtentGroupBox->setTitle( msg );
}

void QgsRasterLayerSaveAsDialog::on_mChangeCrsPushButton_clicked()
{
QgsGenericProjectionSelector * selector = new QgsGenericProjectionSelector( this );
@@ -500,27 +443,24 @@ void QgsRasterLayerSaveAsDialog::crsChanged()
QgsDebugMsg( "Entered" );
if ( outputCrs() != mPreviousCrs )
{
mExtentGroupBox->setOutputCrs( outputCrs() );
QgsExtentGroupBox::ExtentState state = mExtentGroupBox->extentState();

// Reset extent
QgsRectangle previousExtent;
QgsCoordinateReferenceSystem previousCrs;
// We could reproject previous but that would add additional space also if
// it is was not necessary or at leas it could decrease accuracy
if ( mExtentState == OriginalExtent )
if ( state == QgsExtentGroupBox::OriginalExtent )
{
previousExtent = mDataProvider->extent();
previousCrs = mLayerCrs;
mExtentGroupBox->setOutputExtentFromOriginal();
}
else if ( mExtentState == CurrentExtent )
else if ( state == QgsExtentGroupBox::CurrentExtent )
{
previousExtent = mCurrentExtent;
previousCrs = mCurrentCrs;
mExtentGroupBox->setOutputExtentFromCurrent();
}
else
{
previousExtent = outputRectangle();
previousCrs = mPreviousCrs;
mExtentGroupBox->setOutputExtentFromUser( mExtentGroupBox->outputExtent(), mPreviousCrs );
}
setOutputExtent( previousExtent, previousCrs, mExtentState );

// Reset resolution
if ( mResolutionRadioButton->isChecked() )
@@ -39,12 +39,6 @@ class GUI_EXPORT QgsRasterLayerSaveAsDialog: public QDialog, private Ui::QgsRast
CurrentCrs,
UserCrs
};
enum ExtentState
{
OriginalExtent,
CurrentExtent,
UserExtent,
};
enum ResolutionState
{
OriginalResolution,
@@ -88,8 +82,6 @@ class GUI_EXPORT QgsRasterLayerSaveAsDialog: public QDialog, private Ui::QgsRast
void on_mRawModeRadioButton_toggled( bool );
void on_mBrowseButton_clicked();
void on_mSaveAsLineEdit_textChanged( const QString& text );
void on_mCurrentExtentButton_clicked();
void on_mOriginalExtentButton_clicked();
void on_mFormatComboBox_currentIndexChanged( const QString& text );
void on_mResolutionRadioButton_toggled( bool ) { toggleResolutionSize(); }
void on_mOriginalResolutionPushButton_clicked() { setOriginalResolution(); }
@@ -100,11 +92,6 @@ class GUI_EXPORT QgsRasterLayerSaveAsDialog: public QDialog, private Ui::QgsRast
void on_mColumnsLineEdit_textEdited( const QString & ) { mResolutionState = UserResolution; recalcResolution(); }
void on_mRowsLineEdit_textEdited( const QString & ) { mResolutionState = UserResolution; recalcResolution(); }

void on_mXMinLineEdit_textEdited( const QString & ) { mExtentState = UserExtent; extentChanged(); }
void on_mXMaxLineEdit_textEdited( const QString & ) { mExtentState = UserExtent; extentChanged(); }
void on_mYMinLineEdit_textEdited( const QString & ) { mExtentState = UserExtent; extentChanged(); }
void on_mYMaxLineEdit_textEdited( const QString & ) { mExtentState = UserExtent; extentChanged(); }

void on_mChangeCrsPushButton_clicked();

void on_mCrsComboBox_currentIndexChanged( int ) { crsChanged(); }
@@ -117,6 +104,7 @@ class GUI_EXPORT QgsRasterLayerSaveAsDialog: public QDialog, private Ui::QgsRast
void on_mTileModeCheckBox_toggled( bool toggled );
void on_mPyramidsGroupBox_toggled( bool toggled );
void populatePyramidsLevels();
void extentChanged();

private:
QgsRasterLayer* mRasterLayer;
@@ -126,14 +114,10 @@ class GUI_EXPORT QgsRasterLayerSaveAsDialog: public QDialog, private Ui::QgsRast
QgsCoordinateReferenceSystem mCurrentCrs;
QgsCoordinateReferenceSystem mUserCrs;
QgsCoordinateReferenceSystem mPreviousCrs;
ExtentState mExtentState;
ResolutionState mResolutionState;
QVector<bool> mNoDataToEdited;

void setValidators();
void setOutputExtent( const QgsRectangle& r, const QgsCoordinateReferenceSystem& srcCrs, ExtentState state );
void extentChanged();
void updateExtentStateMsg();
void toggleResolutionSize();
void setResolution( double xRes, double yRes, const QgsCoordinateReferenceSystem& srcCrs );
void setOriginalResolution();

0 comments on commit cbf2c1a

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