19
19
#include " qgsprojectproperties.h"
20
20
21
21
// qgis includes
22
+ #include " qgsapplication.h"
23
+ #include " qgsdistancearea.h"
22
24
#include " qgisapp.h"
23
25
#include " qgscomposer.h"
24
26
#include " qgscontexthelp.h"
50
52
#include < QHeaderView> // Qt 4.4
51
53
#include < QMessageBox>
52
54
55
+ const char * QgsProjectProperties::GEO_NONE_DESC = QT_TRANSLATE_NOOP( " QgsOptions" , " None / Planimetric" );
56
+
53
57
// stdc++ includes
54
58
55
59
QgsProjectProperties::QgsProjectProperties ( QgsMapCanvas* mapCanvas, QWidget *parent, Qt::WFlags fl )
@@ -63,6 +67,8 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
63
67
connect ( this , SIGNAL ( accepted () ), this , SLOT ( apply () ) );
64
68
connect ( projectionSelector, SIGNAL ( sridSelected ( QString ) ), this , SLOT ( setMapUnitsToCurrentProjection () ) );
65
69
70
+ connect ( cmbEllipsoid, SIGNAL ( currentIndexChanged ( int ) ), this , SLOT ( updateEllipsoidUI ( int ) ) );
71
+
66
72
// /////////////////////////////////////////////////////////
67
73
// Properties stored in map canvas's QgsMapRenderer
68
74
// these ones are propagated to QgsProject by a signal
@@ -104,6 +110,34 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
104
110
105
111
cbxAbsolutePath->setCurrentIndex ( QgsProject::instance ()->readBoolEntry ( " Paths" , " /Absolute" , true ) ? 0 : 1 );
106
112
113
+ // populate combo box with ellipsoids
114
+
115
+ QgsDebugMsg ( " Setting upp ellipsoid" );
116
+
117
+ mEllipsoidIndex = 0 ;
118
+ populateEllipsoidList ();
119
+
120
+ // Reading ellipsoid from setttings
121
+ QStringList mySplitEllipsoid = QgsProject::instance ()->readEntry ( " Measure" , " /Ellipsoid" , GEO_NONE ).split ( ' :' );
122
+
123
+ int myIndex = 0 ;
124
+ for ( int i = 0 ; i < mEllipsoidList .length (); i++ )
125
+ {
126
+ if ( mEllipsoidList [ i ].acronym .startsWith ( mySplitEllipsoid[ 0 ] ) )
127
+ {
128
+ myIndex = i;
129
+ break ;
130
+ }
131
+ }
132
+ // Update paramaters if present.
133
+ if ( mySplitEllipsoid.length () >= 3 )
134
+ {
135
+ mEllipsoidList [ myIndex ].semiMajor = mySplitEllipsoid[ 1 ].toDouble ();
136
+ mEllipsoidList [ myIndex ].semiMinor = mySplitEllipsoid[ 2 ].toDouble ();
137
+ }
138
+
139
+ updateEllipsoidUI ( myIndex );
140
+
107
141
int dp = QgsProject::instance ()->readNumEntry ( " PositionPrecision" , " /DecimalPlaces" );
108
142
spinBoxDP->setValue ( dp );
109
143
@@ -507,6 +541,26 @@ void QgsProjectProperties::apply()
507
541
508
542
QgsProject::instance ()->writeEntry ( " Paths" , " /Absolute" , cbxAbsolutePath->currentIndex () == 0 );
509
543
544
+ if ( mEllipsoidList [ mEllipsoidIndex ].acronym .startsWith ( " PARAMETER" ) )
545
+ {
546
+ double major = mEllipsoidList [ mEllipsoidIndex ].semiMajor ;
547
+ double minor = mEllipsoidList [ mEllipsoidIndex ].semiMinor ;
548
+ // If the user fields have changed, use them instead.
549
+ if ( leSemiMajor->isModified () || leSemiMinor->isModified () )
550
+ {
551
+ QgsDebugMsg ( " Using paramteric major/minor" );
552
+ major = QLocale::system ().toDouble ( leSemiMajor->text () );
553
+ minor = QLocale::system ().toDouble ( leSemiMinor->text () );
554
+ }
555
+ QgsProject::instance ()->writeEntry ( " Measure" , " /Ellipsoid" , QString ( " PARAMETER:%1:%2" )
556
+ .arg ( major, 0 , ' g' , 17 )
557
+ .arg ( minor, 0 , ' g' , 17 ) );
558
+ }
559
+ else
560
+ {
561
+ QgsProject::instance ()->writeEntry ( " Measure" , " /Ellipsoid" , mEllipsoidList [ mEllipsoidIndex ].acronym );
562
+ }
563
+
510
564
// set the color for selections
511
565
QColor myColor = pbnSelectionColor->color ();
512
566
QgsProject::instance ()->writeEntry ( " Gui" , " /SelectionColorRedPart" , myColor.red () );
@@ -773,6 +827,9 @@ void QgsProjectProperties::on_cbxProjectionEnabled_stateChanged( int state )
773
827
mLayerSrsId = projectionSelector->selectedCrsId ();
774
828
projectionSelector->setSelectedCrsId ( mProjectSrsId );
775
829
}
830
+
831
+ // Enable/Disabel selector and update tool-tip
832
+ updateEllipsoidUI ( mEllipsoidIndex );
776
833
}
777
834
778
835
void QgsProjectProperties::on_cbxWFSPublied_stateChanged ( int aIdx )
@@ -1252,3 +1309,137 @@ void QgsProjectProperties::resetPythonMacros()
1252
1309
" def saveProject():\n pass\n\n " \
1253
1310
" def closeProject():\n pass\n " );
1254
1311
}
1312
+
1313
+ void QgsProjectProperties::populateEllipsoidList ()
1314
+ {
1315
+ //
1316
+ // Populate the ellipsoid list
1317
+ //
1318
+ sqlite3 *myDatabase;
1319
+ const char *myTail;
1320
+ sqlite3_stmt *myPreparedStatement;
1321
+ int myResult;
1322
+ EllipsoidDefs myItem, i;
1323
+
1324
+ myItem.acronym = GEO_NONE;
1325
+ myItem.description = tr ( GEO_NONE_DESC );
1326
+ myItem.semiMajor = 0.0 ;
1327
+ myItem.semiMinor = 0.0 ;
1328
+ mEllipsoidList .append ( myItem );
1329
+
1330
+ myItem.acronym = QString ( " PARAMETER:6370997:6370997" );
1331
+ myItem.description = tr ( " Parameters :" );
1332
+ myItem.semiMajor = 6370997.0 ;
1333
+ myItem.semiMinor = 6370997.0 ;
1334
+ mEllipsoidList .append ( myItem );
1335
+
1336
+ // check the db is available
1337
+ myResult = sqlite3_open_v2 ( QgsApplication::srsDbFilePath ().toUtf8 ().data (), &myDatabase, SQLITE_OPEN_READONLY, NULL );
1338
+ if ( myResult )
1339
+ {
1340
+ QgsDebugMsg ( QString ( " Can't open database: %1" ).arg ( sqlite3_errmsg ( myDatabase ) ) );
1341
+ // XXX This will likely never happen since on open, sqlite creates the
1342
+ // database if it does not exist.
1343
+ Q_ASSERT ( myResult == 0 );
1344
+ }
1345
+
1346
+ // Set up the query to retrieve the projection information needed to populate the ELLIPSOID list
1347
+ QString mySql = " select acronym, name, radius, parameter2 from tbl_ellipsoid order by name" ;
1348
+ myResult = sqlite3_prepare ( myDatabase, mySql.toUtf8 (), mySql.toUtf8 ().length (), &myPreparedStatement, &myTail );
1349
+ // XXX Need to free memory from the error msg if one is set
1350
+ if ( myResult == SQLITE_OK )
1351
+ {
1352
+ while ( sqlite3_step ( myPreparedStatement ) == SQLITE_ROW )
1353
+ {
1354
+ QString para1, para2;
1355
+ myItem.acronym = ( const char * )sqlite3_column_text ( myPreparedStatement, 0 );
1356
+ myItem.description = ( const char * )sqlite3_column_text ( myPreparedStatement, 1 );
1357
+
1358
+ // Copied from QgsDistanecArea. Should perhaps be moved there somehow?
1359
+ // No error checking, this values are for show only, never used in calculations.
1360
+
1361
+ // Fall-back values
1362
+ myItem.semiMajor = 0.0 ;
1363
+ myItem.semiMinor = 0.0 ;
1364
+ // Crash if no column?
1365
+ para1 = ( const char * )sqlite3_column_text ( myPreparedStatement, 2 );
1366
+ para2 = ( const char * )sqlite3_column_text ( myPreparedStatement, 3 );
1367
+ myItem.semiMajor = para1.mid ( 2 ).toDouble ();
1368
+ if ( para2.left ( 2 ) == " b=" )
1369
+ {
1370
+ myItem.semiMinor = para2.mid ( 2 ).toDouble ();
1371
+ }
1372
+ else if ( para2.left ( 3 ) == " rf=" )
1373
+ {
1374
+ double invFlattening = para2.mid ( 3 ).toDouble ();
1375
+ if ( invFlattening != 0.0 )
1376
+ {
1377
+ myItem.semiMinor = myItem.semiMajor - ( myItem.semiMajor / invFlattening );
1378
+ }
1379
+ }
1380
+ mEllipsoidList .append ( myItem );
1381
+ }
1382
+ }
1383
+
1384
+ // close the sqlite3 statement
1385
+ sqlite3_finalize ( myPreparedStatement );
1386
+ sqlite3_close ( myDatabase );
1387
+
1388
+ // Add all items to selector
1389
+
1390
+ foreach ( i, mEllipsoidList )
1391
+ {
1392
+ cmbEllipsoid->addItem ( i.description );
1393
+ }
1394
+ }
1395
+
1396
+ void QgsProjectProperties::updateEllipsoidUI ( int newIndex )
1397
+ {
1398
+ // Called whenever settings change, adjusts the UI accordingly
1399
+ // Pre-select current ellipsoid
1400
+
1401
+ // Check if CRS transformation is on, or else turn everything off
1402
+ double myMajor = mEllipsoidList [ newIndex ].semiMajor ;
1403
+ double myMinor = mEllipsoidList [ newIndex ].semiMinor ;
1404
+
1405
+ // If user has modified the radii (only possible if parametric!), before
1406
+ // changing ellipsoid, save the modified coordinates
1407
+ if ( leSemiMajor->isModified () || leSemiMinor->isModified () )
1408
+ {
1409
+ QgsDebugMsg ( " Saving major/minor" );
1410
+ mEllipsoidList [ mEllipsoidIndex ].semiMajor = QLocale::system ().toDouble ( leSemiMajor->text () );
1411
+ mEllipsoidList [ mEllipsoidIndex ].semiMinor = QLocale::system ().toDouble ( leSemiMinor->text () );
1412
+ }
1413
+
1414
+ mEllipsoidIndex = newIndex;
1415
+ leSemiMajor->setEnabled ( false );
1416
+ leSemiMinor->setEnabled ( false );
1417
+ leSemiMajor->setText ( " " );
1418
+ leSemiMinor->setText ( " " );
1419
+ if ( cbxProjectionEnabled->isChecked () )
1420
+ {
1421
+ cmbEllipsoid->setEnabled ( true );
1422
+ cmbEllipsoid->setToolTip ( " " );
1423
+ if ( mEllipsoidList [ mEllipsoidIndex ].acronym .startsWith ( " PARAMETER:" ) )
1424
+ {
1425
+ leSemiMajor->setEnabled ( true );
1426
+ leSemiMinor->setEnabled ( true );
1427
+ }
1428
+ else
1429
+ {
1430
+ leSemiMajor->setToolTip ( QString ( " Select %1 from pull-down menu to adjust radii" ).arg ( tr ( " Parameters:" ) ) );
1431
+ leSemiMinor->setToolTip ( QString ( " Select %1 from pull-down menu to adjust radii" ).arg ( tr ( " Parameters:" ) ) );
1432
+ }
1433
+ cmbEllipsoid->setCurrentIndex ( mEllipsoidIndex ); // Not always necessary
1434
+ if ( mEllipsoidList [ mEllipsoidIndex ].acronym != GEO_NONE )
1435
+ {
1436
+ leSemiMajor->setText ( QLocale::system ().toString ( myMajor, ' f' , 3 ) );
1437
+ leSemiMinor->setText ( QLocale::system ().toString ( myMinor, ' f' , 3 ) );
1438
+ }
1439
+ }
1440
+ else
1441
+ {
1442
+ cmbEllipsoid->setEnabled ( false );
1443
+ cmbEllipsoid->setToolTip ( tr ( " Can only use ellipsoidal calculations when CRS transformation is enabled" ) );
1444
+ }
1445
+ }
0 commit comments