@@ -73,19 +73,33 @@ QgsAlignRasterDialog::QgsAlignRasterDialog( QWidget *parent )
7373 connect ( mBtnRemove , SIGNAL ( clicked ( bool ) ), this , SLOT ( removeLayer () ) );
7474 connect ( mBtnEdit , SIGNAL ( clicked ( bool ) ), this , SLOT ( editLayer () ) );
7575
76- connect ( mCboReferenceLayer , SIGNAL ( currentIndexChanged ( int ) ), this , SLOT ( updateConfigFromReferenceLayer () ) );
76+ connect ( mCboReferenceLayer , SIGNAL ( currentIndexChanged ( int ) ), this , SLOT ( referenceLayerChanged () ) );
7777 connect ( mCrsSelector , SIGNAL ( crsChanged ( QgsCoordinateReferenceSystem ) ), this , SLOT ( destinationCrsChanged () ) );
78+ connect ( mSpinCellSizeX , SIGNAL ( valueChanged ( double ) ), this , SLOT ( updateParametersFromReferenceLayer () ) );
79+ connect ( mSpinCellSizeY , SIGNAL ( valueChanged ( double ) ), this , SLOT ( updateParametersFromReferenceLayer () ) );
80+ connect ( mSpinGridOffsetX , SIGNAL ( valueChanged ( double ) ), this , SLOT ( updateParametersFromReferenceLayer () ) );
81+ connect ( mSpinGridOffsetY , SIGNAL ( valueChanged ( double ) ), this , SLOT ( updateParametersFromReferenceLayer () ) );
82+
83+ connect ( mChkCustomCRS , SIGNAL ( clicked ( bool ) ), this , SLOT ( updateCustomCRS () ) );
84+ connect ( mChkCustomCellSize , SIGNAL ( clicked ( bool ) ), this , SLOT ( updateCustomCellSize () ) );
85+ connect ( mChkCustomGridOffset , SIGNAL ( clicked ( bool ) ), this , SLOT ( updateCustomGridOffset () ) );
7886
7987 mClipExtentGroupBox ->setChecked ( false );
8088 mClipExtentGroupBox ->setCollapsed ( true );
8189 mClipExtentGroupBox ->setTitleBase ( tr ( " Clip to Extent" ) );
90+ QgsMapCanvas* mc = QgisApp::instance ()->mapCanvas ();
91+ mClipExtentGroupBox ->setCurrentExtent ( mc->extent (), mc->mapSettings ().destinationCrs () );
8292 connect ( mClipExtentGroupBox , SIGNAL ( extentChanged ( QgsRectangle ) ), this , SLOT ( clipExtentChanged () ) );
8393
8494 // TODO: auto-detect reference layer
8595
8696 connect ( buttonBox, SIGNAL ( accepted () ), this , SLOT ( runAlign () ) );
8797
8898 populateLayersView ();
99+
100+ updateCustomCRS ();
101+ updateCustomCellSize ();
102+ updateCustomGridOffset ();
89103}
90104
91105QgsAlignRasterDialog::~QgsAlignRasterDialog ()
@@ -130,6 +144,67 @@ void QgsAlignRasterDialog::updateAlignedRasterInfo()
130144 mEditOutputSize ->setText ( msg );
131145}
132146
147+ void QgsAlignRasterDialog::updateParametersFromReferenceLayer ()
148+ {
149+ QString customCRSWkt;
150+ QSizeF customCellSize;
151+ QPointF customGridOffset ( -1 , -1 );
152+
153+ int index = mCboReferenceLayer ->currentIndex ();
154+ if ( index < 0 )
155+ return ;
156+
157+ QgsAlignRaster::RasterInfo refInfo ( mAlign ->rasters ().at ( index ).inputFilename );
158+ if ( !refInfo.isValid () )
159+ return ;
160+
161+ // get custom values from the GUI (if any)
162+ if ( mChkCustomCRS ->isChecked () )
163+ {
164+ QgsCoordinateReferenceSystem refCRS ( QString::fromAscii ( refInfo.crs () ) );
165+ if ( refCRS != mCrsSelector ->crs () )
166+ customCRSWkt = mCrsSelector ->crs ().toWkt ();
167+ }
168+
169+ if ( mChkCustomCellSize ->isChecked () )
170+ {
171+ customCellSize = QSizeF ( mSpinCellSizeX ->value (), mSpinCellSizeY ->value () );
172+ }
173+
174+ if ( mChkCustomGridOffset ->isChecked () )
175+ {
176+ customGridOffset = QPointF ( mSpinGridOffsetX ->value (), mSpinGridOffsetY ->value () );
177+ }
178+
179+ // calculate the parameters which are not customized already
180+ bool res = mAlign ->setParametersFromRaster ( refInfo, customCRSWkt, customCellSize, customGridOffset );
181+
182+ // refresh values that may have changed
183+ if ( res )
184+ {
185+ QgsCoordinateReferenceSystem destCRS ( mAlign ->destinationCRS () );
186+ mClipExtentGroupBox ->setOutputCrs ( destCRS );
187+ if ( !mChkCustomCRS ->isChecked () )
188+ {
189+ mCrsSelector ->setCrs ( destCRS );
190+ }
191+ }
192+ if ( !mChkCustomCellSize ->isChecked () )
193+ {
194+ QSizeF cellSize = mAlign ->cellSize ();
195+ mSpinCellSizeX ->setValue ( cellSize.width () );
196+ mSpinCellSizeY ->setValue ( cellSize.height () );
197+ }
198+ if ( !mChkCustomGridOffset ->isChecked () )
199+ {
200+ QPointF gridOffset = mAlign ->gridOffset ();
201+ mSpinGridOffsetX ->setValue ( gridOffset.x () );
202+ mSpinGridOffsetY ->setValue ( gridOffset.y () );
203+ }
204+
205+ updateAlignedRasterInfo ();
206+ }
207+
133208
134209void QgsAlignRasterDialog::addLayer ()
135210{
@@ -185,7 +260,7 @@ void QgsAlignRasterDialog::editLayer()
185260 populateLayersView ();
186261}
187262
188- void QgsAlignRasterDialog::updateConfigFromReferenceLayer ()
263+ void QgsAlignRasterDialog::referenceLayerChanged ()
189264{
190265 int index = mCboReferenceLayer ->currentIndex ();
191266 if ( index < 0 )
@@ -195,25 +270,11 @@ void QgsAlignRasterDialog::updateConfigFromReferenceLayer()
195270 if ( !refInfo.isValid () )
196271 return ;
197272
198- mAlign ->setParametersFromRaster ( refInfo );
199-
200- QgsCoordinateReferenceSystem destCRS ( mAlign ->destinationCRS () );
201- mCrsSelector ->setCrs ( destCRS );
202-
203- QSizeF cellSize = mAlign ->cellSize ();
204- mSpinCellSizeX ->setValue ( cellSize.width () );
205- mSpinCellSizeY ->setValue ( cellSize.height () );
273+ QgsCoordinateReferenceSystem layerCRS ( QString::fromAscii ( refInfo.crs () ) );
274+ mCrsSelector ->setLayerCrs ( layerCRS );
275+ mClipExtentGroupBox ->setOriginalExtent ( refInfo.extent (), layerCRS );
206276
207- QPointF gridOffset = mAlign ->gridOffset ();
208- mSpinGridOffsetX ->setValue ( gridOffset.x () );
209- mSpinGridOffsetY ->setValue ( gridOffset.y () );
210-
211- QgsMapCanvas* mc = QgisApp::instance ()->mapCanvas ();
212- mClipExtentGroupBox ->setCurrentExtent ( mc->extent (), mc->mapSettings ().destinationCrs () );
213- mClipExtentGroupBox ->setOriginalExtent ( refInfo.extent (), QgsCoordinateReferenceSystem ( QString::fromAscii ( refInfo.crs () ) ) );
214- mClipExtentGroupBox ->setOutputCrs ( destCRS );
215-
216- updateAlignedRasterInfo ();
277+ updateParametersFromReferenceLayer ();
217278}
218279
219280
@@ -230,23 +291,7 @@ void QgsAlignRasterDialog::destinationCrsChanged()
230291 if ( !refInfo.isValid () )
231292 return ;
232293
233- if ( !mAlign ->setParametersFromRaster ( refInfo, mCrsSelector ->crs ().toWkt () ) )
234- {
235- QMessageBox::warning ( this , tr ( " Align Rasters" ), tr ( " Cannot reproject reference layer to the chosen destination CRS.\n\n Please select a different CRS" ) );
236- return ;
237- }
238-
239- QSizeF cellSize = mAlign ->cellSize ();
240- mSpinCellSizeX ->setValue ( cellSize.width () );
241- mSpinCellSizeY ->setValue ( cellSize.height () );
242-
243- QPointF gridOffset = mAlign ->gridOffset ();
244- mSpinGridOffsetX ->setValue ( gridOffset.x () );
245- mSpinGridOffsetY ->setValue ( gridOffset.y () );
246-
247- mClipExtentGroupBox ->setOutputCrs ( mCrsSelector ->crs () );
248-
249- updateAlignedRasterInfo ();
294+ updateParametersFromReferenceLayer ();
250295}
251296
252297void QgsAlignRasterDialog::clipExtentChanged ()
@@ -256,6 +301,26 @@ void QgsAlignRasterDialog::clipExtentChanged()
256301 updateAlignedRasterInfo ();
257302}
258303
304+ void QgsAlignRasterDialog::updateCustomCRS ()
305+ {
306+ mCrsSelector ->setEnabled ( mChkCustomCRS ->isChecked () );
307+ updateParametersFromReferenceLayer ();
308+ }
309+
310+ void QgsAlignRasterDialog::updateCustomCellSize ()
311+ {
312+ mSpinCellSizeX ->setEnabled ( mChkCustomCellSize ->isChecked () );
313+ mSpinCellSizeY ->setEnabled ( mChkCustomCellSize ->isChecked () );
314+ updateParametersFromReferenceLayer ();
315+ }
316+
317+ void QgsAlignRasterDialog::updateCustomGridOffset ()
318+ {
319+ mSpinGridOffsetX ->setEnabled ( mChkCustomGridOffset ->isChecked () );
320+ mSpinGridOffsetY ->setEnabled ( mChkCustomGridOffset ->isChecked () );
321+ updateParametersFromReferenceLayer ();
322+ }
323+
259324
260325void QgsAlignRasterDialog::runAlign ()
261326{
0 commit comments