Skip to content

Commit 080bea1

Browse files
3nidsnyalldawson
authored andcommittedDec 15, 2017
saving datums transform in projet, removing in dialog ok
1 parent 3777aad commit 080bea1

7 files changed

+73
-6
lines changed
 

‎src/app/qgsdatumtransformtablemodel.cpp

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,41 @@ void QgsDatumTransformTableModel::setTransformContext( QgsCoordinateTransformCon
1212
reset();
1313
}
1414

15+
void QgsDatumTransformTableModel::removeTransform( QModelIndexList indexes )
16+
{
17+
QgsCoordinateReferenceSystem sourceCrs;
18+
QgsCoordinateReferenceSystem destinationCrs;
19+
for ( QModelIndexList::const_iterator it = indexes.constBegin(); it != indexes.constEnd(); it ++ )
20+
{
21+
if ( it->column() == SourceCrsColumn )
22+
{
23+
sourceCrs = QgsCoordinateReferenceSystem( data( *it, Qt::DisplayRole ).toString() );
24+
}
25+
if ( it->column() == DestinationCrsColumn )
26+
{
27+
destinationCrs = QgsCoordinateReferenceSystem( data( *it, Qt::DisplayRole ).toString() );
28+
}
29+
if ( sourceCrs.isValid() && destinationCrs.isValid() )
30+
{
31+
mTransformContext.removeSourceDestinationDatumTransform( sourceCrs, destinationCrs );
32+
reset();
33+
break;
34+
}
35+
}
36+
}
37+
1538

1639
int QgsDatumTransformTableModel::rowCount( const QModelIndex &parent ) const
1740
{
41+
Q_UNUSED( parent );
1842
return mTransformContext.sourceDestinationDatumTransforms().count()
1943
+ mTransformContext.sourceDatumTransforms().count()
2044
+ mTransformContext.destinationDatumTransforms().count();
2145
}
2246

2347
int QgsDatumTransformTableModel::columnCount( const QModelIndex &parent ) const
2448
{
49+
Q_UNUSED( parent );
2550
return 4;
2651
}
2752

@@ -50,17 +75,17 @@ QVariant QgsDatumTransformTableModel::data( const QModelIndex &index, int role )
5075
case SourceCrsColumn:
5176
return sourceCrs;
5277
case SourceTransformColumn:
53-
if (sourceTransform != -1)
78+
if ( sourceTransform != -1 )
5479
{
55-
return QgsCoordinateTransform::datumTransformString( sourceTransform );
80+
return QgsCoordinateTransform::datumTransformString( sourceTransform );
5681
}
5782
break;
5883
case DestinationCrsColumn:
5984
return destinationCrs;
6085
case DestinationTransformColumn:
61-
if (sourceTransform != -1)
86+
if ( sourceTransform != -1 )
6287
{
63-
return QgsCoordinateTransform::datumTransformString( destinationTransform );
88+
return QgsCoordinateTransform::datumTransformString( destinationTransform );
6489
}
6590
break;
6691
default:

‎src/app/qgsdatumtransformtablemodel.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
#include "qgis_app.h"
88
#include "qgscoordinatetransformcontext.h"
99

10+
/**
11+
* The QgsDatumTransformTableModel class is a table model to display and edit
12+
* datum transformations.
13+
*
14+
* \since 3.0
15+
*/
1016
class APP_EXPORT QgsDatumTransformTableModel : public QAbstractTableModel
1117
{
1218
Q_OBJECT
@@ -26,6 +32,11 @@ class APP_EXPORT QgsDatumTransformTableModel : public QAbstractTableModel
2632

2733
QgsCoordinateTransformContext transformContext() {return mTransformContext;}
2834

35+
/**
36+
* remove the transformation at given indexes
37+
*/
38+
void removeTransform( QModelIndexList indexes );
39+
2940
int rowCount( const QModelIndex &parent ) const override;
3041
int columnCount( const QModelIndex &parent ) const override;
3142
QVariant data( const QModelIndex &index, int role ) const override;

‎src/app/qgsoptions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
457457
//default datum transformations
458458
mSettings->beginGroup( QStringLiteral( "/Projections" ) );
459459

460-
mShowDatumTransformDialogCheckBox->setChecked( mSettings->value( QStringLiteral( "showDatumTransformDialog" ), false ).toBool() );
460+
mShowDatumTransformDialogCheckBox->setChecked( mSettings->value( QStringLiteral( "/Projections/showDatumTransformDialog" ), false ).toBool() );
461461

462462
QStringList projectionKeys = mSettings->allKeys();
463463

‎src/app/qgsprojectproperties.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,9 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
164164
mDatumTransformTableView->setSelectionMode( QAbstractItemView::SingleSelection );
165165
mDatumTransformTableView->setSelectionBehavior( QAbstractItemView::SelectRows );
166166
connect( mDatumTransformAddButton, &QToolButton::clicked, this, &QgsProjectProperties::addDatumTransform );
167+
connect( mDatumTransformRemoveButton, &QToolButton::clicked, this, &QgsProjectProperties::removeDatumTransform );
167168

168-
bool show = mSettings->value( QStringLiteral( "showDatumTransformDialog" ), false ).toBool();
169+
bool show = settings.value( QStringLiteral( "/Projections/showDatumTransformDialog" ), false ).toBool();
169170
mShowDatumTransformDialogCheckBox->setChecked( show );
170171

171172
QPolygonF mainCanvasPoly = mapCanvas->mapSettings().visiblePolygon();
@@ -820,6 +821,9 @@ void QgsProjectProperties::apply()
820821
projectionSelector->pushProjectionToFront();
821822
}
822823

824+
QgsCoordinateTransformContext transformContext = mDatumTransformTableModel->transformContext();
825+
QgsProject::instance()->setTransformContext( transformContext );
826+
823827
// Set the project title
824828
QgsProject::instance()->setTitle( title() );
825829
QgsProject::instance()->setAutoTransaction( mAutoTransaction->isChecked() );
@@ -1241,6 +1245,15 @@ void QgsProjectProperties::addDatumTransform()
12411245
}
12421246
}
12431247

1248+
void QgsProjectProperties::removeDatumTransform()
1249+
{
1250+
QModelIndexList selectedIndexes = mDatumTransformTableView->selectionModel()->selectedIndexes();
1251+
if ( selectedIndexes.count() > 0 )
1252+
{
1253+
mDatumTransformTableModel->removeTransform( selectedIndexes );
1254+
}
1255+
}
1256+
12441257
void QgsProjectProperties::cbxWFSPubliedStateChanged( int aIdx )
12451258
{
12461259
QCheckBox *cb = qobject_cast<QCheckBox *>( twWFSLayers->cellWidget( aIdx, 1 ) );

‎src/app/qgsprojectproperties.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:
7373
//! add a new datum transform
7474
void addDatumTransform();
7575

76+
//! remove currently selected datum transform
77+
void removeDatumTransform();
78+
7679
/**
7780
* Let the user add a scale to the list of project scales
7881
* used in scale combobox instead of global ones */

‎src/gui/qgsdatumtransformdialog.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ QgsDatumTransformDialog::QgsDatumTransformDialog( QgsCoordinateReferenceSystem s
4545
QApplication::setOverrideCursor( Qt::ArrowCursor );
4646

4747
updateTitle();
48+
setOKButtonEnabled();
4849

4950
QgsSettings settings;
5051
restoreGeometry( settings.value( QStringLiteral( "Windows/DatumTransformDialog/geometry" ) ).toByteArray() );
@@ -133,6 +134,14 @@ void QgsDatumTransformDialog::load()
133134
delete item;
134135
}
135136
}
137+
138+
setOKButtonEnabled();
139+
}
140+
141+
void QgsDatumTransformDialog::setOKButtonEnabled()
142+
{
143+
QTreeWidgetItem *item = mDatumTransformTreeWidget->currentItem();
144+
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( mSourceCrs.isValid() && mDestinationCrs.isValid() && item );
136145
}
137146

138147
QgsDatumTransformDialog::~QgsDatumTransformDialog()
@@ -245,6 +254,8 @@ void QgsDatumTransformDialog::mDatumTransformTreeWidget_currentItemChanged( QTre
245254

246255
mLabelSrcDescription->setText( current->toolTip( 0 ) );
247256
mLabelDstDescription->setText( current->toolTip( 1 ) );
257+
258+
setOKButtonEnabled();
248259
}
249260

250261
void QgsDatumTransformDialog::setSourceCrs()
@@ -258,6 +269,7 @@ void QgsDatumTransformDialog::setSourceCrs()
258269
load();
259270
}
260271
delete mySelector;
272+
setOKButtonEnabled();
261273
}
262274

263275
void QgsDatumTransformDialog::setDestinationCrs()
@@ -271,6 +283,7 @@ void QgsDatumTransformDialog::setDestinationCrs()
271283
load();
272284
}
273285
delete mySelector;
286+
setOKButtonEnabled();
274287
}
275288

276289
void QgsDatumTransformDialog::updateTitle()

‎src/gui/qgsdatumtransformdialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class GUI_EXPORT QgsDatumTransformDialog : public QDialog, private Ui::QgsDatumT
6666
//! Returns false if the location of the grid shift files is known (PROJ_LIB) and the shift file is not there
6767
bool testGridShiftFileAvailability( QTreeWidgetItem *item, int col ) const;
6868
void load();
69+
void setOKButtonEnabled();
70+
6971

7072
QList< QList< int > > mDatumTransforms;
7173
QgsCoordinateReferenceSystem mSourceCrs;

0 commit comments

Comments
 (0)
Please sign in to comment.