Skip to content
Permalink
Browse files
Copied ellipsoidal settings to project properties
  • Loading branch information
homann committed Nov 24, 2012
1 parent e063c23 commit 47aed17fc2ab4306754e9bb944f5a9cea5149459
Showing with 256 additions and 3 deletions.
  1. +191 −0 src/app/qgsprojectproperties.cpp
  2. +23 −0 src/app/qgsprojectproperties.h
  3. +42 −3 src/ui/qgsprojectpropertiesbase.ui
@@ -19,6 +19,8 @@
#include "qgsprojectproperties.h"

//qgis includes
#include "qgsapplication.h"
#include "qgsdistancearea.h"
#include "qgisapp.h"
#include "qgscomposer.h"
#include "qgscontexthelp.h"
@@ -50,6 +52,8 @@
#include <QHeaderView> // Qt 4.4
#include <QMessageBox>

const char * QgsProjectProperties::GEO_NONE_DESC = QT_TRANSLATE_NOOP( "QgsOptions", "None / Planimetric" );

//stdc++ includes

QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *parent, Qt::WFlags fl )
@@ -63,6 +67,8 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
connect( this, SIGNAL( accepted() ), this, SLOT( apply() ) );
connect( projectionSelector, SIGNAL( sridSelected( QString ) ), this, SLOT( setMapUnitsToCurrentProjection() ) );

connect( cmbEllipsoid, SIGNAL( currentIndexChanged( int ) ), this, SLOT( updateEllipsoidUI( int ) ) );

///////////////////////////////////////////////////////////
// Properties stored in map canvas's QgsMapRenderer
// these ones are propagated to QgsProject by a signal
@@ -104,6 +110,34 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa

cbxAbsolutePath->setCurrentIndex( QgsProject::instance()->readBoolEntry( "Paths", "/Absolute", true ) ? 0 : 1 );

// populate combo box with ellipsoids

QgsDebugMsg( "Setting upp ellipsoid" );

mEllipsoidIndex = 0;
populateEllipsoidList();

// Reading ellipsoid from setttings
QStringList mySplitEllipsoid = QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ).split( ':' );

int myIndex = 0;
for ( int i = 0; i < mEllipsoidList.length(); i++ )
{
if ( mEllipsoidList[ i ].acronym.startsWith( mySplitEllipsoid[ 0 ] ) )
{
myIndex = i;
break;
}
}
// Update paramaters if present.
if ( mySplitEllipsoid.length() >= 3 )
{
mEllipsoidList[ myIndex ].semiMajor = mySplitEllipsoid[ 1 ].toDouble();
mEllipsoidList[ myIndex ].semiMinor = mySplitEllipsoid[ 2 ].toDouble();
}

updateEllipsoidUI( myIndex );

int dp = QgsProject::instance()->readNumEntry( "PositionPrecision", "/DecimalPlaces" );
spinBoxDP->setValue( dp );

@@ -507,6 +541,26 @@ void QgsProjectProperties::apply()

QgsProject::instance()->writeEntry( "Paths", "/Absolute", cbxAbsolutePath->currentIndex() == 0 );

if ( mEllipsoidList[ mEllipsoidIndex ].acronym.startsWith( "PARAMETER" ) )
{
double major = mEllipsoidList[ mEllipsoidIndex ].semiMajor;
double minor = mEllipsoidList[ mEllipsoidIndex ].semiMinor;
// If the user fields have changed, use them instead.
if ( leSemiMajor->isModified() || leSemiMinor->isModified() )
{
QgsDebugMsg( "Using paramteric major/minor" );
major = QLocale::system().toDouble( leSemiMajor->text() );
minor = QLocale::system().toDouble( leSemiMinor->text() );
}
QgsProject::instance()->writeEntry( "Measure", "/Ellipsoid", QString( "PARAMETER:%1:%2" )
.arg( major, 0, 'g', 17 )
.arg( minor, 0, 'g', 17 ) );
}
else
{
QgsProject::instance()->writeEntry( "Measure", "/Ellipsoid", mEllipsoidList[ mEllipsoidIndex ].acronym );
}

//set the color for selections
QColor myColor = pbnSelectionColor->color();
QgsProject::instance()->writeEntry( "Gui", "/SelectionColorRedPart", myColor.red() );
@@ -773,6 +827,9 @@ void QgsProjectProperties::on_cbxProjectionEnabled_stateChanged( int state )
mLayerSrsId = projectionSelector->selectedCrsId();
projectionSelector->setSelectedCrsId( mProjectSrsId );
}

// Enable/Disabel selector and update tool-tip
updateEllipsoidUI( mEllipsoidIndex );
}

void QgsProjectProperties::on_cbxWFSPublied_stateChanged( int aIdx )
@@ -1252,3 +1309,137 @@ void QgsProjectProperties::resetPythonMacros()
"def saveProject():\n pass\n\n" \
"def closeProject():\n pass\n" );
}

void QgsProjectProperties::populateEllipsoidList()
{
//
// Populate the ellipsoid list
//
sqlite3 *myDatabase;
const char *myTail;
sqlite3_stmt *myPreparedStatement;
int myResult;
EllipsoidDefs myItem, i;

myItem.acronym = GEO_NONE;
myItem.description = tr( GEO_NONE_DESC );
myItem.semiMajor = 0.0;
myItem.semiMinor = 0.0;
mEllipsoidList.append( myItem );

myItem.acronym = QString( "PARAMETER:6370997:6370997" );
myItem.description = tr( "Parameters :" );
myItem.semiMajor = 6370997.0;
myItem.semiMinor = 6370997.0;
mEllipsoidList.append( myItem );

//check the db is available
myResult = sqlite3_open_v2( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
if ( myResult )
{
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
// XXX This will likely never happen since on open, sqlite creates the
// database if it does not exist.
Q_ASSERT( myResult == 0 );
}

// Set up the query to retrieve the projection information needed to populate the ELLIPSOID list
QString mySql = "select acronym, name, radius, parameter2 from tbl_ellipsoid order by name";
myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
// XXX Need to free memory from the error msg if one is set
if ( myResult == SQLITE_OK )
{
while ( sqlite3_step( myPreparedStatement ) == SQLITE_ROW )
{
QString para1, para2;
myItem.acronym = ( const char * )sqlite3_column_text( myPreparedStatement, 0 );
myItem.description = ( const char * )sqlite3_column_text( myPreparedStatement, 1 );

// Copied from QgsDistanecArea. Should perhaps be moved there somehow?
// No error checking, this values are for show only, never used in calculations.

// Fall-back values
myItem.semiMajor = 0.0;
myItem.semiMinor = 0.0;
// Crash if no column?
para1 = ( const char * )sqlite3_column_text( myPreparedStatement, 2 );
para2 = ( const char * )sqlite3_column_text( myPreparedStatement, 3 );
myItem.semiMajor = para1.mid( 2 ).toDouble();
if ( para2.left( 2 ) == "b=" )
{
myItem.semiMinor = para2.mid( 2 ).toDouble();
}
else if ( para2.left( 3 ) == "rf=" )
{
double invFlattening = para2.mid( 3 ).toDouble();
if ( invFlattening != 0.0 )
{
myItem.semiMinor = myItem.semiMajor - ( myItem.semiMajor / invFlattening );
}
}
mEllipsoidList.append( myItem );
}
}

// close the sqlite3 statement
sqlite3_finalize( myPreparedStatement );
sqlite3_close( myDatabase );

// Add all items to selector

foreach ( i, mEllipsoidList )
{
cmbEllipsoid->addItem( i.description );
}
}

void QgsProjectProperties::updateEllipsoidUI( int newIndex )
{
// Called whenever settings change, adjusts the UI accordingly
// Pre-select current ellipsoid

// Check if CRS transformation is on, or else turn everything off
double myMajor = mEllipsoidList[ newIndex ].semiMajor;
double myMinor = mEllipsoidList[ newIndex ].semiMinor;

// If user has modified the radii (only possible if parametric!), before
// changing ellipsoid, save the modified coordinates
if ( leSemiMajor->isModified() || leSemiMinor->isModified() )
{
QgsDebugMsg( "Saving major/minor" );
mEllipsoidList[ mEllipsoidIndex ].semiMajor = QLocale::system().toDouble( leSemiMajor->text() );
mEllipsoidList[ mEllipsoidIndex ].semiMinor = QLocale::system().toDouble( leSemiMinor->text() );
}

mEllipsoidIndex = newIndex;
leSemiMajor->setEnabled( false );
leSemiMinor->setEnabled( false );
leSemiMajor->setText( "" );
leSemiMinor->setText( "" );
if ( cbxProjectionEnabled->isChecked() )
{
cmbEllipsoid->setEnabled( true );
cmbEllipsoid->setToolTip( "" );
if ( mEllipsoidList[ mEllipsoidIndex ].acronym.startsWith( "PARAMETER:" ) )
{
leSemiMajor->setEnabled( true );
leSemiMinor->setEnabled( true );
}
else
{
leSemiMajor->setToolTip( QString( "Select %1 from pull-down menu to adjust radii" ).arg( tr( "Parameters:" ) ) );
leSemiMinor->setToolTip( QString( "Select %1 from pull-down menu to adjust radii" ).arg( tr( "Parameters:" ) ) );
}
cmbEllipsoid->setCurrentIndex( mEllipsoidIndex ); // Not always necessary
if ( mEllipsoidList[ mEllipsoidIndex ].acronym != GEO_NONE )
{
leSemiMajor->setText( QLocale::system().toString( myMajor, 'f', 3 ) );
leSemiMinor->setText( QLocale::system().toString( myMinor, 'f', 3 ) );
}
}
else
{
cmbEllipsoid->setEnabled( false );
cmbEllipsoid->setToolTip( tr( "Can only use ellipsoidal calculations when CRS transformation is enabled" ) );
}
}
@@ -153,6 +153,12 @@ class QgsProjectProperties : public QDialog, private Ui::QgsProjectPropertiesBas
*/
void setMapUnitsToCurrentProjection();

/* Update ComboBox accorindg to the selected new index
* Also sets the new selected Ellipsoid.
* @note added in 2.0
*/
void updateEllipsoidUI( int newIndex );

signals:
//! Signal used to inform listeners that the mouse display precision may have changed
void displayPrecisionChanged();
@@ -188,4 +194,21 @@ class QgsProjectProperties : public QDialog, private Ui::QgsProjectPropertiesBas

long mProjectSrsId;
long mLayerSrsId;

// List for all ellispods, also None and Custom
struct EllipsoidDefs
{
QString acronym;
QString description;
double semiMajor;
double semiMinor;
};
QList<EllipsoidDefs> mEllipsoidList;
int mEllipsoidIndex;

//! Populates list with ellipsoids from Sqlite3 db
void populateEllipsoidList();

static const char * GEO_NONE_DESC;

};
@@ -197,6 +197,45 @@
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="btnGrpMeasureEllipsoid">
<property name="title">
<string>Measure tool</string>
</property>
<layout class="QGridLayout" name="gridLayoutMeasureTool">
<item row="1" column="0" rowspan="2">
<widget class="QLabel" name="textLabel1_8">
<property name="text">
<string>Ellipsoid for distance calculations</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="4">
<widget class="QComboBox" name="cmbEllipsoid"/>
</item>
<item row="2" column="4">
<widget class="QLineEdit" name="leSemiMinor"/>
</item>
<item row="2" column="3">
<widget class="QLabel" name="label_42">
<property name="text">
<string>Semi-minor</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLineEdit" name="leSemiMajor"/>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_41">
<property name="text">
<string>Semi-major</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="btnGrpMapUnits">
<property name="toolTip">
<string>Used when CRS transformation is turned off</string>
@@ -232,7 +271,7 @@
</layout>
</widget>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QGroupBox" name="btnGrpDegreeDisplay">
<property name="title">
<string>Degree display</string>
@@ -262,7 +301,7 @@
</layout>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QGroupBox" name="btnGrpPrecision">
<property name="title">
<string>Precision</string>
@@ -326,7 +365,7 @@
</layout>
</widget>
</item>
<item row="4" column="0">
<item row="5" column="0">
<widget class="QGroupBox" name="grpProjectScales">
<property name="title">
<string>Project scales</string>

0 comments on commit 47aed17

Please sign in to comment.