@@ -221,9 +221,21 @@ QgsDatumTransformTableWidget::QgsDatumTransformTableWidget( QWidget *parent )
221
221
mTableView ->setAlternatingRowColors ( true );
222
222
connect ( mAddButton , &QToolButton::clicked, this , &QgsDatumTransformTableWidget::addDatumTransform );
223
223
connect ( mRemoveButton , &QToolButton::clicked, this , &QgsDatumTransformTableWidget::removeDatumTransform );
224
- connect ( mEditButton , &QToolButton::clicked, this , &QgsDatumTransformTableWidget::editDatumTransform );
224
+ connect ( mEditButton , &QToolButton::clicked, this , [ = ]
225
+ {
226
+ QModelIndexList selectedIndexes = mTableView ->selectionModel ()->selectedIndexes ();
227
+ if ( selectedIndexes.count () > 0 )
228
+ {
229
+ editDatumTransform ( selectedIndexes.at ( 0 ) );
230
+ }
231
+ } );
225
232
226
233
connect ( mTableView ->selectionModel (), &QItemSelectionModel::selectionChanged, this , &QgsDatumTransformTableWidget::selectionChanged );
234
+
235
+ connect ( mTableView , &QTableView::doubleClicked, this , [ = ]( const QModelIndex & index )
236
+ {
237
+ editDatumTransform ( index );
238
+ } );
227
239
mEditButton ->setEnabled ( false );
228
240
}
229
241
@@ -253,69 +265,47 @@ void QgsDatumTransformTableWidget::removeDatumTransform()
253
265
}
254
266
}
255
267
256
- void QgsDatumTransformTableWidget::editDatumTransform ()
268
+ void QgsDatumTransformTableWidget::editDatumTransform ( const QModelIndex &index )
257
269
{
258
- QModelIndexList selectedIndexes = mTableView ->selectionModel ()->selectedIndexes ();
259
- if ( selectedIndexes.count () > 0 )
260
- {
261
- QgsCoordinateReferenceSystem sourceCrs;
262
- QgsCoordinateReferenceSystem destinationCrs;
263
- QString proj;
264
- int sourceTransform = -1 ;
265
- int destinationTransform = -1 ;
266
- for ( QModelIndexList::const_iterator it = selectedIndexes.constBegin (); it != selectedIndexes.constEnd (); it ++ )
267
- {
268
- switch ( it->column () )
269
- {
270
- case QgsDatumTransformTableModel::SourceCrsColumn:
271
- sourceCrs = QgsCoordinateReferenceSystem ( mModel ->data ( *it, Qt::DisplayRole ).toString () );
272
- break ;
273
- case QgsDatumTransformTableModel::DestinationCrsColumn:
274
- destinationCrs = QgsCoordinateReferenceSystem ( mModel ->data ( *it, Qt::DisplayRole ).toString () );
275
- break ;
270
+ QString proj;
271
+ int sourceTransform = -1 ;
272
+ int destinationTransform = -1 ;
273
+
274
+ QgsCoordinateReferenceSystem sourceCrs = QgsCoordinateReferenceSystem ( mModel ->data ( mModel ->index ( index.row (), QgsDatumTransformTableModel::SourceCrsColumn ), Qt::DisplayRole ).toString () );
275
+ QgsCoordinateReferenceSystem destinationCrs = QgsCoordinateReferenceSystem ( mModel ->data ( mModel ->index ( index.row (), QgsDatumTransformTableModel::DestinationCrsColumn ), Qt::DisplayRole ).toString () );
276
+
276
277
#if PROJ_VERSION_MAJOR>=6
277
- case QgsDatumTransformTableModel::ProjDefinitionColumn:
278
- proj = mModel ->data ( *it, Qt::UserRole ).toString ();
279
- break ;
278
+ proj = mModel ->data ( mModel ->index ( index.row (), QgsDatumTransformTableModel::ProjDefinitionColumn ), Qt::UserRole ).toString ();
280
279
#else
281
- case QgsDatumTransformTableModel::SourceTransformColumn:
282
- sourceTransform = mModel ->data ( *it, Qt::UserRole ).toInt ();
283
- break ;
284
- case QgsDatumTransformTableModel::DestinationTransformColumn:
285
- destinationTransform = mModel ->data ( *it, Qt::UserRole ).toInt ();
286
- break ;
280
+ sourceTransform = mModel ->data ( mModel ->index ( index.row (), QgsDatumTransformTableModel::SourceTransformColumn ), Qt::UserRole ).toInt ();
281
+ destinationTransform = mModel ->data ( mModel ->index ( index.row (), QgsDatumTransformTableModel::DestinationTransformColumn ), Qt::UserRole ).toInt ();
287
282
#endif
288
- default :
289
- break ;
290
- }
291
- }
292
283
293
284
#if PROJ_VERSION_MAJOR>=6
294
- if ( sourceCrs.isValid () && destinationCrs.isValid () && !proj.isEmpty () )
285
+ if ( sourceCrs.isValid () && destinationCrs.isValid () && !proj.isEmpty () )
295
286
#else
296
- if ( sourceCrs.isValid () && destinationCrs.isValid () &&
297
- ( sourceTransform != -1 || destinationTransform != -1 ) )
287
+ if ( sourceCrs.isValid () && destinationCrs.isValid () &&
288
+ ( sourceTransform != -1 || destinationTransform != -1 ) )
298
289
#endif
290
+ {
291
+ QgsDatumTransformDialog dlg ( sourceCrs, destinationCrs, true , false , false , qMakePair ( sourceTransform, destinationTransform ), nullptr , nullptr , proj, QgisApp::instance ()->mapCanvas () );
292
+ if ( dlg.exec () )
299
293
{
300
- QgsDatumTransformDialog dlg ( sourceCrs, destinationCrs, true , false , false , qMakePair ( sourceTransform, destinationTransform ), nullptr , nullptr , proj, QgisApp::instance ()->mapCanvas () );
301
- if ( dlg.exec () )
294
+ const QgsDatumTransformDialog::TransformInfo dt = dlg.selectedDatumTransform ();
295
+ QgsCoordinateTransformContext context = mModel ->transformContext ();
296
+ if ( sourceCrs != dt.sourceCrs || destinationCrs != dt.destinationCrs )
302
297
{
303
- const QgsDatumTransformDialog::TransformInfo dt = dlg.selectedDatumTransform ();
304
- QgsCoordinateTransformContext context = mModel ->transformContext ();
305
- if ( sourceCrs != dt.sourceCrs || destinationCrs != dt.destinationCrs )
306
- {
307
- context.removeCoordinateOperation ( sourceCrs, destinationCrs );
308
- Q_NOWARN_DEPRECATED_PUSH
309
- context.removeSourceDestinationDatumTransform ( sourceCrs, destinationCrs );
310
- Q_NOWARN_DEPRECATED_POP
311
- }
312
- // QMap::insert takes care of replacing existing value
298
+ context.removeCoordinateOperation ( sourceCrs, destinationCrs );
313
299
Q_NOWARN_DEPRECATED_PUSH
314
- context.addSourceDestinationDatumTransform ( dt. sourceCrs , dt. destinationCrs , dt. sourceTransformId , dt. destinationTransformId );
300
+ context.removeSourceDestinationDatumTransform ( sourceCrs, destinationCrs );
315
301
Q_NOWARN_DEPRECATED_POP
316
- context.addCoordinateOperation ( dt.sourceCrs , dt.destinationCrs , dt.proj );
317
- mModel ->setTransformContext ( context );
318
302
}
303
+ // QMap::insert takes care of replacing existing value
304
+ Q_NOWARN_DEPRECATED_PUSH
305
+ context.addSourceDestinationDatumTransform ( dt.sourceCrs , dt.destinationCrs , dt.sourceTransformId , dt.destinationTransformId );
306
+ Q_NOWARN_DEPRECATED_POP
307
+ context.addCoordinateOperation ( dt.sourceCrs , dt.destinationCrs , dt.proj );
308
+ mModel ->setTransformContext ( context );
319
309
}
320
310
}
321
311
}
0 commit comments