Skip to content

Commit bc73b4e

Browse files
committed
Possibility to add / remove default transformations in options tab
1 parent 7fbc692 commit bc73b4e

File tree

3 files changed

+218
-29
lines changed

3 files changed

+218
-29
lines changed

src/app/qgsoptions.cpp

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,51 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
410410
//display the crs as friendly text rather than in wkt
411411
leProjectGlobalCrs->setText( mDefaultCrs.authid() + " - " + mDefaultCrs.description() );
412412

413+
//default datum transformations
414+
settings.beginGroup( "/Projections" );
415+
QStringList projectionKeys = settings.allKeys();
416+
417+
//collect src and dest entries that belong together
418+
QMap< QPair< QString, QString >, QPair< int, int > > transforms;
419+
QStringList::const_iterator pkeyIt = projectionKeys.constBegin();
420+
for ( ; pkeyIt != projectionKeys.constEnd(); ++pkeyIt )
421+
{
422+
if ( pkeyIt->contains( "srcTransform" ) || pkeyIt->contains( "destTransform" ) )
423+
{
424+
QStringList split = pkeyIt->split( "/" );
425+
QString srcAuthId, destAuthId;
426+
if ( split.size() > 0 )
427+
{
428+
srcAuthId = split.at( 0 );
429+
}
430+
if ( split.size() > 1 )
431+
{
432+
destAuthId = split.at( 1 ).split( "_" ).at( 0 );
433+
}
434+
435+
if ( pkeyIt->contains( "srcTransform" ) )
436+
{
437+
transforms[ qMakePair( srcAuthId, destAuthId )].first = settings.value( *pkeyIt ).toInt();
438+
}
439+
else if ( pkeyIt->contains( "destTransform" ) )
440+
{
441+
transforms[ qMakePair( srcAuthId, destAuthId )].second = settings.value( *pkeyIt ).toInt();
442+
}
443+
}
444+
}
445+
settings.endGroup();
446+
447+
QMap< QPair< QString, QString >, QPair< int, int > >::const_iterator transformIt = transforms.constBegin();
448+
for ( ; transformIt != transforms.constEnd(); ++transformIt )
449+
{
450+
const QPair< int, int >& v = transformIt.value();
451+
QTreeWidgetItem* item = new QTreeWidgetItem();
452+
item->setText( 0, transformIt.key().first );
453+
item->setText( 1, transformIt.key().second );
454+
item->setText( 2, QString::number( v.first ) );
455+
item->setText( 3, QString::number( v.second ) );
456+
mDefaultDatumTransformTreeWidget->addTopLevelItem( item );
457+
}
413458

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

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

1900+
void QgsOptions::on_mRemoveDefaultTransformButton_clicked()
1901+
{
1902+
QList<QTreeWidgetItem*> items = mDefaultDatumTransformTreeWidget->selectedItems();
1903+
for ( int i = 0; i < items.size(); ++i )
1904+
{
1905+
int idx = mDefaultDatumTransformTreeWidget->indexOfTopLevelItem( items.at( i ) );
1906+
if ( idx >= 0 )
1907+
{
1908+
delete mDefaultDatumTransformTreeWidget->takeTopLevelItem( idx );
1909+
}
1910+
}
1911+
}
1912+
1913+
void QgsOptions::on_mAddDefaultTransformButton_clicked()
1914+
{
1915+
QTreeWidgetItem* item = new QTreeWidgetItem();
1916+
item->setText( 0, "" );
1917+
item->setText( 1, "" );
1918+
item->setText( 2, "" );
1919+
item->setText( 3, "" );
1920+
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );
1921+
mDefaultDatumTransformTreeWidget->addTopLevelItem( item );
1922+
}
1923+
1924+
void QgsOptions::saveDefaultDatumTransformations()
1925+
{
1926+
QSettings s;
1927+
s.beginGroup( "/Projections" );
1928+
QStringList groupKeys = s.allKeys();
1929+
QStringList::const_iterator groupKeyIt = groupKeys.constBegin();
1930+
for ( ; groupKeyIt != groupKeys.constEnd(); ++groupKeyIt )
1931+
{
1932+
if ( groupKeyIt->contains( "srcTransform" ) || groupKeyIt->contains( "destTransform" ) )
1933+
{
1934+
s.remove( *groupKeyIt );
1935+
}
1936+
}
1937+
1938+
int nDefaultTransforms = mDefaultDatumTransformTreeWidget->topLevelItemCount();
1939+
for ( int i = 0; i < nDefaultTransforms; ++i )
1940+
{
1941+
QTreeWidgetItem* item = mDefaultDatumTransformTreeWidget->topLevelItem( i );
1942+
QString srcAuthId = item->text( 0 );
1943+
QString destAuthId = item->text( 1 );
1944+
if ( srcAuthId.isEmpty() || destAuthId.isEmpty() )
1945+
{
1946+
continue;
1947+
}
1948+
1949+
bool conversionOk;
1950+
int srcDatumTransform = item->text( 2 ).toInt( &conversionOk );
1951+
if ( conversionOk )
1952+
{
1953+
s.setValue( srcAuthId + "//" + destAuthId + "_srcTransform" , srcDatumTransform );
1954+
}
1955+
int destDatumTransform = item->text( 3 ).toInt( &conversionOk );
1956+
if ( conversionOk )
1957+
{
1958+
s.setValue( srcAuthId + "//" + destAuthId + "_destTransform" , destDatumTransform );
1959+
}
1960+
}
1961+
1962+
s.endGroup();
1963+
}
1964+

src/app/qgsoptions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ class APP_EXPORT QgsOptions : public QgsOptionsDialogBase, private Ui::QgsOption
227227
*/
228228
void saveGdalDriverList();
229229

230+
void on_mRemoveDefaultTransformButton_clicked();
231+
void on_mAddDefaultTransformButton_clicked();
232+
230233
private:
231234
QStringList i18nList();
232235
void initContrastEnhancement( QComboBox *cbox, QString name, QString defaultVal );
@@ -240,6 +243,8 @@ class APP_EXPORT QgsOptions : public QgsOptionsDialogBase, private Ui::QgsOption
240243
*/
241244
void addCustomEnvVarRow( QString varName, QString varVal, QString varApply = QString() );
242245

246+
void saveDefaultDatumTransformations();
247+
243248
protected:
244249
QgisAppStyleSheet* mStyleSheetBuilder;
245250
QMap<QString, QVariant> mStyleSheetNewOpts;

src/ui/qgsoptionsbase.ui

Lines changed: 101 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>848</width>
10-
<height>578</height>
10+
<height>705</height>
1111
</rect>
1212
</property>
1313
<property name="minimumSize">
@@ -267,7 +267,7 @@
267267
<x>0</x>
268268
<y>0</y>
269269
<width>687</width>
270-
<height>523</height>
270+
<height>650</height>
271271
</rect>
272272
</property>
273273
<layout class="QVBoxLayout" name="verticalLayout_28">
@@ -1249,7 +1249,7 @@
12491249
<x>0</x>
12501250
<y>0</y>
12511251
<width>687</width>
1252-
<height>523</height>
1252+
<height>650</height>
12531253
</rect>
12541254
</property>
12551255
<layout class="QVBoxLayout" name="verticalLayout_27">
@@ -1577,8 +1577,8 @@
15771577
<rect>
15781578
<x>0</x>
15791579
<y>0</y>
1580-
<width>572</width>
1581-
<height>611</height>
1580+
<width>687</width>
1581+
<height>650</height>
15821582
</rect>
15831583
</property>
15841584
<layout class="QVBoxLayout" name="verticalLayout_29">
@@ -2092,8 +2092,8 @@
20922092
<rect>
20932093
<x>0</x>
20942094
<y>0</y>
2095-
<width>441</width>
2096-
<height>281</height>
2095+
<width>687</width>
2096+
<height>650</height>
20972097
</rect>
20982098
</property>
20992099
<layout class="QVBoxLayout" name="verticalLayout_25">
@@ -2438,8 +2438,8 @@
24382438
<rect>
24392439
<x>0</x>
24402440
<y>0</y>
2441-
<width>494</width>
2442-
<height>619</height>
2441+
<width>687</width>
2442+
<height>650</height>
24432443
</rect>
24442444
</property>
24452445
<layout class="QVBoxLayout" name="verticalLayout_30">
@@ -2852,8 +2852,8 @@
28522852
<rect>
28532853
<x>0</x>
28542854
<y>0</y>
2855-
<width>670</width>
2856-
<height>551</height>
2855+
<width>687</width>
2856+
<height>650</height>
28572857
</rect>
28582858
</property>
28592859
<layout class="QVBoxLayout" name="verticalLayout_31">
@@ -3354,7 +3354,7 @@
33543354
<x>0</x>
33553355
<y>0</y>
33563356
<width>687</width>
3357-
<height>523</height>
3357+
<height>650</height>
33583358
</rect>
33593359
</property>
33603360
<layout class="QVBoxLayout" name="verticalLayout_6">
@@ -3494,10 +3494,23 @@
34943494
<x>0</x>
34953495
<y>0</y>
34963496
<width>687</width>
3497-
<height>523</height>
3497+
<height>650</height>
34983498
</rect>
34993499
</property>
35003500
<layout class="QGridLayout" name="gridLayout_15">
3501+
<item row="5" column="0">
3502+
<spacer name="verticalSpacer">
3503+
<property name="orientation">
3504+
<enum>Qt::Vertical</enum>
3505+
</property>
3506+
<property name="sizeHint" stdset="0">
3507+
<size>
3508+
<width>20</width>
3509+
<height>40</height>
3510+
</size>
3511+
</property>
3512+
</spacer>
3513+
</item>
35013514
<item row="2" column="0">
35023515
<widget class="QGroupBox" name="grpProjectionBehaviour">
35033516
<property name="title">
@@ -3574,19 +3587,6 @@
35743587
</layout>
35753588
</widget>
35763589
</item>
3577-
<item row="3" column="0">
3578-
<spacer name="verticalSpacer">
3579-
<property name="orientation">
3580-
<enum>Qt::Vertical</enum>
3581-
</property>
3582-
<property name="sizeHint" stdset="0">
3583-
<size>
3584-
<width>20</width>
3585-
<height>40</height>
3586-
</size>
3587-
</property>
3588-
</spacer>
3589-
</item>
35903590
<item row="1" column="0">
35913591
<widget class="QGroupBox" name="grpOtfTransform">
35923592
<property name="title">
@@ -3644,6 +3644,78 @@
36443644
</layout>
36453645
</widget>
36463646
</item>
3647+
<item row="3" column="0">
3648+
<widget class="QGroupBox" name="mDefaultDatumTransformGroupBox">
3649+
<property name="title">
3650+
<string>Default datum transformations</string>
3651+
</property>
3652+
<layout class="QGridLayout" name="gridLayout_8">
3653+
<item row="0" column="0">
3654+
<layout class="QHBoxLayout" name="horizontalLayout_4">
3655+
<item>
3656+
<widget class="QPushButton" name="mAddDefaultTransformButton">
3657+
<property name="text">
3658+
<string/>
3659+
</property>
3660+
<property name="icon">
3661+
<iconset resource="../../images/images.qrc">
3662+
<normaloff>:/images/themes/default/symbologyAdd.png</normaloff>:/images/themes/default/symbologyAdd.png</iconset>
3663+
</property>
3664+
</widget>
3665+
</item>
3666+
<item>
3667+
<widget class="QPushButton" name="mRemoveDefaultTransformButton">
3668+
<property name="text">
3669+
<string/>
3670+
</property>
3671+
<property name="icon">
3672+
<iconset resource="../../images/images.qrc">
3673+
<normaloff>:/images/themes/default/symbologyRemove.png</normaloff>:/images/themes/default/symbologyRemove.png</iconset>
3674+
</property>
3675+
</widget>
3676+
</item>
3677+
<item>
3678+
<spacer name="horizontalSpacer_38">
3679+
<property name="orientation">
3680+
<enum>Qt::Horizontal</enum>
3681+
</property>
3682+
<property name="sizeHint" stdset="0">
3683+
<size>
3684+
<width>568</width>
3685+
<height>20</height>
3686+
</size>
3687+
</property>
3688+
</spacer>
3689+
</item>
3690+
</layout>
3691+
</item>
3692+
</layout>
3693+
</widget>
3694+
</item>
3695+
<item row="4" column="0">
3696+
<widget class="QTreeWidget" name="mDefaultDatumTransformTreeWidget">
3697+
<column>
3698+
<property name="text">
3699+
<string>Source CRS</string>
3700+
</property>
3701+
</column>
3702+
<column>
3703+
<property name="text">
3704+
<string>Destination CRS</string>
3705+
</property>
3706+
</column>
3707+
<column>
3708+
<property name="text">
3709+
<string>Source datum transform</string>
3710+
</property>
3711+
</column>
3712+
<column>
3713+
<property name="text">
3714+
<string>Destination datum transform</string>
3715+
</property>
3716+
</column>
3717+
</widget>
3718+
</item>
36473719
</layout>
36483720
</widget>
36493721
</widget>
@@ -3678,7 +3750,7 @@
36783750
<rect>
36793751
<x>0</x>
36803752
<y>0</y>
3681-
<width>265</width>
3753+
<width>216</width>
36823754
<height>197</height>
36833755
</rect>
36843756
</property>
@@ -3778,8 +3850,8 @@
37783850
<rect>
37793851
<x>0</x>
37803852
<y>0</y>
3781-
<width>469</width>
3782-
<height>556</height>
3853+
<width>687</width>
3854+
<height>650</height>
37833855
</rect>
37843856
</property>
37853857
<layout class="QVBoxLayout" name="verticalLayout_33">

0 commit comments

Comments
 (0)