Converted project projection state handling to use qgis SRSID rather than WKT format.

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@3283 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
timlinux 2005-05-01 02:01:52 +00:00
parent 830dbca9fe
commit 8407b9e39a
9 changed files with 50 additions and 39 deletions

View File

@ -37,19 +37,22 @@ void QgsLayerProjectionSelector::pbnOK_clicked()
accept();
}
void QgsLayerProjectionSelector::setSelectedWKT(QString theWKTName)
void QgsLayerProjectionSelector::setSelectedSRSName(QString theName)
{
projectionSelector->setSelectedWKT(theWKTName);
projectionSelector->setSelectedSRSName(theName);
}
QString QgsLayerProjectionSelector::getCurrentWKT()
void QgsLayerProjectionSelector::setSelectedSRSID(long theID)
{
projectionSelector->setSelectedSRSID(theID);
}
QString QgsLayerProjectionSelector::getCurrentProj4String()
{
//@NOTE dont use getSelectedWKT as that just returns the name part!
return projectionSelector->getCurrentWKT();
return projectionSelector->getCurrentProj4String();
}
long QgsLayerProjectionSelector::getCurrentSRID()
long QgsLayerProjectionSelector::getCurrentSRSID()
{
//@NOTE dont use getSelectedWKT as that just returns the name part!
return projectionSelector->getCurrentSRID();
return projectionSelector->getCurrentSRSID();
}

View File

@ -40,9 +40,10 @@ class QgsLayerProjectionSelector :public QgsLayerProjectionSelectorBase{
public slots:
void pbnOK_clicked();
QString getCurrentWKT();
long getCurrentSRID();
void setSelectedWKT(QString theWKTName);
QString getCurrentProj4String();
long getCurrentSRSID();
void setSelectedSRSName(QString theName);
void setSelectedSRSID(long theID);
};
#endif // #ifndef QGSLAYERPROJECTIONSELECTOR_H

View File

@ -68,8 +68,9 @@ QgsOptions::QgsOptions(QWidget *parent, const char *name) : QgsOptionsBase(paren
{
radUseGlobalProjection->setChecked(true);
}
mGlobalWKT = settings.readEntry("/qgis/projections/defaultProjectionWKT");
txtGlobalWKT->setText(mGlobalWKT);
mGlobalSRSID = settings.readNumEntry("/qgis/projections/defaultProjectionSRSID");
//! @todo changes this control name in gui to txtGlobalProjString
txtGlobalWKT->setText(QString::number(mGlobalSRSID));
}
//! Destructor
QgsOptions::~QgsOptions(){}
@ -119,7 +120,7 @@ void QgsOptions::saveOptions()
//
settings.writeEntry("/qgis/projections/defaultBehaviour", "useGlobal");
}
settings.writeEntry("/qgis/projections/defaultProjectionWKT",mGlobalWKT);
settings.writeEntry("/qgis/projections/defaultProjectionWKT",(int)mGlobalSRSID);
//all done
accept();
@ -168,16 +169,17 @@ void QgsOptions::pbnSelectProjection_clicked()
{
QSettings settings;
QgsLayerProjectionSelector * mySelector = new QgsLayerProjectionSelector();
mySelector->setSelectedWKT(mGlobalWKT);
mySelector->setSelectedSRSID(mGlobalSRSID);
if(mySelector->exec())
{
#ifdef QGISDEBUG
std::cout << "------ Global Default Projection Selection Set ----------" << std::endl;
#endif
mGlobalWKT = mySelector->getCurrentWKT();
txtGlobalWKT->setText(mGlobalWKT);
mGlobalSRSID = mySelector->getCurrentSRSID();
//! @todo changes this control name in gui to txtGlobalProjString
txtGlobalWKT->setText(mySelector->getCurrentProj4String());
#ifdef QGISDEBUG
std::cout << "------ Global Default Projection now set to ----------\n" << mGlobalWKT << std::endl;
std::cout << "------ Global Default Projection now set to ----------\n" << mGlobalSRSID << std::endl;
#endif
}
else

View File

@ -67,7 +67,7 @@ class QgsOptions :public QgsOptionsBase{
//! Pointer to our parent
QWidget *qparent;
//!Global default projection used for new layers added that have no projection
QString mGlobalWKT;
long mGlobalSRSID;
};
#endif // #ifndef QGSOPTIONS_H

View File

@ -77,9 +77,11 @@
// set the default wkt to WGS 84
// QString defaultWkt = QgsSpatialReferences::instance()->getSrsBySrid(defaultWktKey)->srText();
// the /selectedWKT entry stores the wkt entry selected in the list of projections
QString srsWkt = QgsProject::instance()->readEntry("SpatialRefSys","/selectedWKT","WGS 84");
/** Magic number for a geographic coord sys in QGIS srs.db tbl_srs.srs_id */
const long GEOSRS_ID = 2581;
long mySRSID = QgsProject::instance()->readNumEntry("SpatialRefSys","/selectedSRSID",GEOSRS_ID);
projectionSelector->setSelectedWKT(srsWkt);
projectionSelector->setSelectedSRSID(mySRSID);
//
@ -213,10 +215,10 @@ void QgsProjectProperties::apply()
if (mySRSID)
{
emit setDestSRSID(mySRSID);
// write the projection's wkt to the project settings rather
QgsProject::instance()->writeEntry("SpatialRefSys","/SRSID",(int)mySRSID);
// write the currently selected projections name to project settings
QgsProject::instance()->writeEntry("SpatialRefSys","/selectedSRID",projectionSelector->getSelectedName());
// write the projection's _id_ to the project settings rather
QgsProject::instance()->writeEntry("SpatialRefSys","/selectedSRSID",(int)mySRSID);
// write the currently selected projections _name_ to project settings
QgsProject::instance()->writeEntry("SpatialRefSys","/selectedSRSName",projectionSelector->getSelectedName());
// set the mouse display precision method and the
// number of decimal places for the manual option
// Note. Qt 3.2.3 and greater have a function selectedId() that

View File

@ -129,13 +129,13 @@ void QgsSpatialRefSys::validate()
QgsLayerProjectionSelector * mySelector = new QgsLayerProjectionSelector();
// XXX TODO: Change project to store selected CS as 'projectSRS' not 'selectedWKT'
QString myDefaultSRS =
QgsProject::instance()->readEntry("SpatialRefSys","/selectedWKT",GEOPROJ4);
mySelector->setSelectedWKT(myDefaultSRS);
long myDefaultSRS =
QgsProject::instance()->readNumEntry("SpatialRefSys","/selectedSRS",GEOSRS_ID);
mySelector->setSelectedSRSID(myDefaultSRS);
if(mySelector->exec())
{
//XXX TODO change this to use SRS_ID (qgis codes)
createFromSrid(mySelector->getCurrentSRID());
//XXX TODO handle user defined projections too
createFromSystemSrsId(mySelector->getCurrentSRSID());
}
else
{

View File

@ -45,6 +45,8 @@ class QgsSpatialRefSys
* @param bool theGeoFlag Whether this is a geographic or projected coordinate system
* @param long theSRID If available, the Postgis spatial_ref_sys identifier for this srs (defaults to 0)
* @param long theEpsg If available the ESPG identifier for this srs (defaults to 0)
*
* @note THIS CTOR WILL PROABBLY BE REMOVED!!!!!!!!!!!!!!!!
*/
QgsSpatialRefSys(long theSrsId,
QString theDescription,

View File

@ -60,17 +60,17 @@ QgsProjectionSelector::QgsProjectionSelector( QWidget* parent , const char* name
QgsProjectionSelector::~QgsProjectionSelector()
{
}
void QgsProjectionSelector::setSelectedWKT(QString theWKT)
void QgsProjectionSelector::setSelectedSRSName(QString theSRSNAme)
{
//get the srid given the wkt so we can pick the correct list item
#ifdef QGISDEBUG
std::cout << "QgsProjectionSelector::setSelectedWKT called with \n" << theWKT << std::endl;
std::cout << "QgsProjectionSelector::setSelectedSRSName called with \n" << theSRSNAme << std::endl;
#endif
//now delegate off to the rest of the work
QListViewItemIterator myIterator (lstCoordinateSystems);
while (myIterator.current())
{
if (myIterator.current()->text(0)==theWKT)
if (myIterator.current()->text(0)==theSRSNAme)
{
lstCoordinateSystems->setCurrentItem(myIterator.current());
lstCoordinateSystems->ensureItemVisible(myIterator.current());
@ -80,12 +80,13 @@ void QgsProjectionSelector::setSelectedWKT(QString theWKT)
}
}
void QgsProjectionSelector::setSelectedSRID(QString theSRID)
void QgsProjectionSelector::setSelectedSRSID(long theSRSID)
{
QString mySRSIDString=QString::number(theSRSID);
QListViewItemIterator myIterator (lstCoordinateSystems);
while (myIterator.current())
{
if (myIterator.current()->text(1)==theSRID)
if (myIterator.current()->text(1)==mySRSIDString)
{
lstCoordinateSystems->setCurrentItem(myIterator.current());
lstCoordinateSystems->ensureItemVisible(myIterator.current());
@ -111,7 +112,7 @@ QString QgsProjectionSelector::getSelectedName()
}
}
// Returns the whole wkt for the selected projection node
QString QgsProjectionSelector::getCurrentWKT()
QString QgsProjectionSelector::getCurrentProj4String()
{
// Only return the projection if there is a node in the tree
// selected that has an srid. This prevents error if the user
@ -145,7 +146,7 @@ QString QgsProjectionSelector::getCurrentWKT()
const char *pzTail;
sqlite3_stmt *ppStmt;
char *pzErrmsg;
QString sql = "select srtext from tbl_srs where srsid = ";
QString sql = "select srtext from tbl_srs where srs_id = ";
sql += lvi->text(1);
#ifdef QGISDEBUG

View File

@ -37,10 +37,10 @@ public:
void updateProjAndEllipsoidAcronyms(int theSrsid,QString theProj4String);
public slots:
void setSelectedWKT(QString theWKT);
void setSelectedSRSName(QString theSRSName);
QString getSelectedName();
void setSelectedSRID(QString theSRID);
QString getCurrentWKT();
void setSelectedSRSID(long theSRSID);
QString getCurrentProj4String();
long getCurrentSRID(); //posgis style projection identifier
long getCurrentSRSID();//qgis projection identfier