Skip to content
Permalink
Browse files

Possibility to add / remove default transformations in options tab

  • Loading branch information
mhugent committed Nov 16, 2013
1 parent 7fbc692 commit bc73b4ea72517b2847525e376f8462ca8031f049
Showing with 218 additions and 29 deletions.
  1. +112 −0 src/app/qgsoptions.cpp
  2. +5 −0 src/app/qgsoptions.h
  3. +101 −29 src/ui/qgsoptionsbase.ui
@@ -410,6 +410,51 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
//display the crs as friendly text rather than in wkt
leProjectGlobalCrs->setText( mDefaultCrs.authid() + " - " + mDefaultCrs.description() );

//default datum transformations
settings.beginGroup( "/Projections" );
QStringList projectionKeys = settings.allKeys();

//collect src and dest entries that belong together
QMap< QPair< QString, QString >, QPair< int, int > > transforms;
QStringList::const_iterator pkeyIt = projectionKeys.constBegin();
for ( ; pkeyIt != projectionKeys.constEnd(); ++pkeyIt )
{
if ( pkeyIt->contains( "srcTransform" ) || pkeyIt->contains( "destTransform" ) )
{
QStringList split = pkeyIt->split( "/" );
QString srcAuthId, destAuthId;
if ( split.size() > 0 )
{
srcAuthId = split.at( 0 );
}
if ( split.size() > 1 )
{
destAuthId = split.at( 1 ).split( "_" ).at( 0 );
}

if ( pkeyIt->contains( "srcTransform" ) )
{
transforms[ qMakePair( srcAuthId, destAuthId )].first = settings.value( *pkeyIt ).toInt();
}
else if ( pkeyIt->contains( "destTransform" ) )
{
transforms[ qMakePair( srcAuthId, destAuthId )].second = settings.value( *pkeyIt ).toInt();
}
}
}
settings.endGroup();

QMap< QPair< QString, QString >, QPair< int, int > >::const_iterator transformIt = transforms.constBegin();
for ( ; transformIt != transforms.constEnd(); ++transformIt )
{
const QPair< int, int >& v = transformIt.value();
QTreeWidgetItem* item = new QTreeWidgetItem();
item->setText( 0, transformIt.key().first );
item->setText( 1, transformIt.key().second );
item->setText( 2, QString::number( v.first ) );
item->setText( 3, QString::number( v.second ) );
mDefaultDatumTransformTreeWidget->addTopLevelItem( item );
}

// Set the units for measuring
QGis::UnitType myDisplayUnits = QGis::fromLiteral( settings.value( "/qgis/measure/displayunits", QGis::toLiteral( QGis::Meters ) ).toString() );
@@ -1196,6 +1241,8 @@ void QgsOptions::saveOptions()
{
mStyleSheetBuilder->saveToSettings( mStyleSheetNewOpts );
}

saveDefaultDatumTransformations();
}

void QgsOptions::rejectOptions()
@@ -1850,3 +1897,68 @@ void QgsOptions::saveContrastEnhancement( QComboBox *cbox, QString name )
settings.setValue( "/Raster/defaultContrastEnhancementAlgorithm/" + name, value );
}

void QgsOptions::on_mRemoveDefaultTransformButton_clicked()
{
QList<QTreeWidgetItem*> items = mDefaultDatumTransformTreeWidget->selectedItems();
for ( int i = 0; i < items.size(); ++i )
{
int idx = mDefaultDatumTransformTreeWidget->indexOfTopLevelItem( items.at( i ) );
if ( idx >= 0 )
{
delete mDefaultDatumTransformTreeWidget->takeTopLevelItem( idx );
}
}
}

void QgsOptions::on_mAddDefaultTransformButton_clicked()
{
QTreeWidgetItem* item = new QTreeWidgetItem();
item->setText( 0, "" );
item->setText( 1, "" );
item->setText( 2, "" );
item->setText( 3, "" );
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );
mDefaultDatumTransformTreeWidget->addTopLevelItem( item );
}

void QgsOptions::saveDefaultDatumTransformations()
{
QSettings s;
s.beginGroup( "/Projections" );
QStringList groupKeys = s.allKeys();
QStringList::const_iterator groupKeyIt = groupKeys.constBegin();
for ( ; groupKeyIt != groupKeys.constEnd(); ++groupKeyIt )
{
if ( groupKeyIt->contains( "srcTransform" ) || groupKeyIt->contains( "destTransform" ) )
{
s.remove( *groupKeyIt );
}
}

int nDefaultTransforms = mDefaultDatumTransformTreeWidget->topLevelItemCount();
for ( int i = 0; i < nDefaultTransforms; ++i )
{
QTreeWidgetItem* item = mDefaultDatumTransformTreeWidget->topLevelItem( i );
QString srcAuthId = item->text( 0 );
QString destAuthId = item->text( 1 );
if ( srcAuthId.isEmpty() || destAuthId.isEmpty() )
{
continue;
}

bool conversionOk;
int srcDatumTransform = item->text( 2 ).toInt( &conversionOk );
if ( conversionOk )
{
s.setValue( srcAuthId + "//" + destAuthId + "_srcTransform" , srcDatumTransform );
}
int destDatumTransform = item->text( 3 ).toInt( &conversionOk );
if ( conversionOk )
{
s.setValue( srcAuthId + "//" + destAuthId + "_destTransform" , destDatumTransform );
}
}

s.endGroup();
}

@@ -227,6 +227,9 @@ class APP_EXPORT QgsOptions : public QgsOptionsDialogBase, private Ui::QgsOption
*/
void saveGdalDriverList();

void on_mRemoveDefaultTransformButton_clicked();
void on_mAddDefaultTransformButton_clicked();

private:
QStringList i18nList();
void initContrastEnhancement( QComboBox *cbox, QString name, QString defaultVal );
@@ -240,6 +243,8 @@ class APP_EXPORT QgsOptions : public QgsOptionsDialogBase, private Ui::QgsOption
*/
void addCustomEnvVarRow( QString varName, QString varVal, QString varApply = QString() );

void saveDefaultDatumTransformations();

protected:
QgisAppStyleSheet* mStyleSheetBuilder;
QMap<QString, QVariant> mStyleSheetNewOpts;
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>848</width>
<height>578</height>
<height>705</height>
</rect>
</property>
<property name="minimumSize">
@@ -267,7 +267,7 @@
<x>0</x>
<y>0</y>
<width>687</width>
<height>523</height>
<height>650</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_28">
@@ -1249,7 +1249,7 @@
<x>0</x>
<y>0</y>
<width>687</width>
<height>523</height>
<height>650</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_27">
@@ -1577,8 +1577,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>572</width>
<height>611</height>
<width>687</width>
<height>650</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_29">
@@ -2092,8 +2092,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>441</width>
<height>281</height>
<width>687</width>
<height>650</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_25">
@@ -2438,8 +2438,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>494</width>
<height>619</height>
<width>687</width>
<height>650</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_30">
@@ -2852,8 +2852,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>670</width>
<height>551</height>
<width>687</width>
<height>650</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_31">
@@ -3354,7 +3354,7 @@
<x>0</x>
<y>0</y>
<width>687</width>
<height>523</height>
<height>650</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
@@ -3494,10 +3494,23 @@
<x>0</x>
<y>0</y>
<width>687</width>
<height>523</height>
<height>650</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_15">
<item row="5" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="grpProjectionBehaviour">
<property name="title">
@@ -3574,19 +3587,6 @@
</layout>
</widget>
</item>
<item row="3" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="grpOtfTransform">
<property name="title">
@@ -3644,6 +3644,78 @@
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QGroupBox" name="mDefaultDatumTransformGroupBox">
<property name="title">
<string>Default datum transformations</string>
</property>
<layout class="QGridLayout" name="gridLayout_8">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QPushButton" name="mAddDefaultTransformButton">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/symbologyAdd.png</normaloff>:/images/themes/default/symbologyAdd.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mRemoveDefaultTransformButton">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/symbologyRemove.png</normaloff>:/images/themes/default/symbologyRemove.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_38">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>568</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="4" column="0">
<widget class="QTreeWidget" name="mDefaultDatumTransformTreeWidget">
<column>
<property name="text">
<string>Source CRS</string>
</property>
</column>
<column>
<property name="text">
<string>Destination CRS</string>
</property>
</column>
<column>
<property name="text">
<string>Source datum transform</string>
</property>
</column>
<column>
<property name="text">
<string>Destination datum transform</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
</widget>
@@ -3678,7 +3750,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>265</width>
<width>216</width>
<height>197</height>
</rect>
</property>
@@ -3778,8 +3850,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>469</width>
<height>556</height>
<width>687</width>
<height>650</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_33">

9 comments on commit bc73b4e

@gioman

This comment has been minimized.

Copy link
Contributor

@gioman gioman replied Nov 17, 2013

Hi Marco, I'm trying to add a Datum Transformation in the general options, but after clicking "ok" and reopening the dialog the line I added does not show. When adding a line it is not clear (at least on my Linux Desktop) that the line was added and ready to be filled.

Another suggestion would be to use the standard QGIS dialog to allow select the source/destination CRS.

Another thing is about the datum transformation parameters, how do they have to be written for ntv2 grids?

thanks in advance!

@mhugent

This comment has been minimized.

Copy link
Contributor Author

@mhugent mhugent replied Nov 18, 2013

The datum transformation itself has to be added to srs.db (see the entries for the Swiss and NZ grid shift as examples). I know, it would be cool to have a dialog to add it graphically, but maybe it will come in the future.

The option page is only for the default datum transformations (to avoid popping up the dialog every time). And the main purpose here is to delete entries easily (without editing the conf file in a text editor).

@gioman

This comment has been minimized.

Copy link
Contributor

@gioman gioman replied Nov 18, 2013

ok got it. Here is a first list of transformations from Datum 73, Datum Lisboa and ETRS89-PTTM06. They seems repeated but are not. There are the official NTV2 grids (http://www.igeo.pt/produtos/geodesia/Grelhas_NTv2.htm) and other grids that are widely used (http://www.fc.up.pt/pessoas/jagoncal/coordenadas/). I guess that the users will have to put manually the grids inside the /proj folder, right?

INSERT INTO tbl_datum_transform (
coord_op_code,
source_crs_code,
target_crs_code,
coord_op_method_code,
p1
)
VALUES (
100003,
27493,
3763,
9615,
'pt73_e89.gsb'
);

INSERT INTO tbl_datum_transform (
coord_op_code,
source_crs_code,
target_crs_code,
coord_op_method_code,
p1
)
VALUES (
100004,
20790,
3763,
9615,
'ptLX_e89.gsb'
);

INSERT INTO tbl_datum_transform (
coord_op_code,
source_crs_code,
target_crs_code,
coord_op_method_code,
p1
)
VALUES (
100005,
20791,
3763,
9615,
'ptLX_e89.gsb'
);

INSERT INTO tbl_datum_transform (
coord_op_code,
source_crs_code,
target_crs_code,
coord_op_method_code,
p1
)
VALUES (
100006,
27493,
3763,
9615,
'D73_ETRS89_geo.gsb'
);

INSERT INTO tbl_datum_transform (
coord_op_code,
source_crs_code,
target_crs_code,
coord_op_method_code,
p1
)
VALUES (
100007,
20790,
3763,
9615,
'DLX_ETRS89_geo.gsb'
);

INSERT INTO tbl_datum_transform (
coord_op_code,
source_crs_code,
target_crs_code,
coord_op_method_code,
p1
)
VALUES (
100008,
20791,
3763,
9615,
'DLX_ETRS89_geo.gsb'
);

@mhugent

This comment has been minimized.

Copy link
Contributor Author

@mhugent mhugent replied Nov 18, 2013

Thanks, Giovanni, will apply those soon.
Yes, the user needs to put the files into the proj-dir manually. In case PROJ_LIB env var is set (usually the case on win), the datum transform dialog checks if the .gsb is really there (and grays out the entry if not)

@gioman

This comment has been minimized.

Copy link
Contributor

@gioman gioman replied Nov 18, 2013

Hi Marco, thanks to you.

I have seen the datum transformation dialog pop out also when adding geometryless tables (CSV), maybe this is not wanted(?).

Cheers!

@gioman

This comment has been minimized.

Copy link
Contributor

@gioman gioman replied Nov 21, 2013

Hi Marco, should I make a pull request instead of a comment in this commit?

@mhugent

This comment has been minimized.

Copy link
Contributor Author

@mhugent mhugent replied Nov 21, 2013

SQL is applied to srs.db. Thanks, Giovanni!

@gioman

This comment has been minimized.

Copy link
Contributor

@gioman gioman replied Nov 21, 2013

Thanks Marco! I will start test them asap.

Do you want me to file a ticket about the fact that the datum transformation dialog shows also when adding geometryless layers? Or may be it was already fixed? Cheers!

@mhugent

This comment has been minimized.

Copy link
Contributor Author

@mhugent mhugent replied Nov 21, 2013

Yes, please fill a ticket.

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