Skip to content
Permalink
Browse files
Various changes relating to projection selector: Renamed QgsLayerProj…
…ectionSelector to QgsGenericProjectionSelector so that it can be used in other contexts too. Added setSelectedEpsg call to projection selector. Added setMessage() call to generic projection selector. Updated python bindings accordingly.

git-svn-id: http://svn.osgeo.org/qgis/trunk@9011 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Aug 7, 2008
1 parent 4f015a3 commit aa896df17a5a3265ab9709f5144f90581ce3c52b
@@ -10,7 +10,7 @@

%Include qgisinterface.sip
%Include qgsencodingfiledialog.sip
%Include qgslayerprojectionselector.sip
%Include qgsgenericprojectionselector.sip
%Include qgsmapcanvas.sip
%Include qgsmapcanvasitem.sip
%Include qgsmapcanvasmap.sip
@@ -1,32 +1,37 @@

/**
* \class QgsLayerProjectionSelector
* \brief Set Projection system for a layer
* \class QgsGenericProjectionSelector
* \brief A generic dialog to prompt the user for a Coordinate Reference System
*/

class QgsLayerProjectionSelector : QDialog //, private Ui::QgsLayerProjectionSelectorBase
class QgsGenericProjectionSelector : QDialog //, private Ui::QgsGenericProjectionSelectorBase
{
%TypeHeaderCode
#include <qgslayerprojectionselector.h>
#include <qgsgenericprojectionselector.h>
%End

public:
/**
* Constructor
*/
QgsLayerProjectionSelector(QWidget *parent = 0,
QgsGenericProjectionSelector(QWidget *parent = 0,
Qt::WFlags fl = QgisGui::ModalDialogFlags);

//! Destructor
~QgsLayerProjectionSelector();
~QgsGenericProjectionSelector();

public slots:
QString getCurrentProj4String();
long getCurrentSRSID();
long getCurrentEpsg();
/** If no paramter is passed, the message will be a generic
* 'define the CRS for this layer'.
*/
void setMessage(QString theMessage="");

QString getSelectedProj4String();
long getSelectedSRSID();
long getSelectedEpsg();

void setSelectedSRSName(QString theName);
void setSelectedSRSID(long theID);
void setSelectedEpsg(long theID);

/**
* \brief filters this dialog by the given CRSs
@@ -54,22 +54,24 @@ class QgsProjectionSelector: QWidget //, private Ui::QgsProjectionSelectorBase
const QString stringSQLSafe(const QString theSQL);

//! Gets the current EPSG-style projection identifier
long getCurrentEpsg();
long getSelectedEpsg();

public slots:
void setSelectedSRSName(QString theSRSName);

QString getSelectedName();

void setSelectedSRSID(long theSRSID);

void setSelectedEpsg(long epsg);

QString getCurrentProj4String();
QString getSelectedProj4String();

//! Gets the current PostGIS-style projection identifier
long getCurrentSRID();
long getSelectedSRID();

//! Gets the current QGIS projection identfier
long getCurrentSRSID();
long getSelectedSRSID();

/**
* \brief filters this widget by the given CRSs
@@ -96,7 +96,7 @@
#include "qgsfeature.h"
#include "qgsgeomtypedialog.h"
#include "qgshelpviewer.h"
#include "qgslayerprojectionselector.h"
#include "qgsgenericprojectionselector.h"
#include "qgslegend.h"
#include "qgslegendlayerfile.h"
#include "qgslegendlayer.h"
@@ -264,7 +264,8 @@ static void customSrsValidation_(QgsSpatialRefSys* srs)
//@note this class is not a descendent of QWidget so we cant pass
//it in the ctor of the layer projection selector

QgsLayerProjectionSelector * mySelector = new QgsLayerProjectionSelector();
QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector();
mySelector->setMessage(); //shows a generic message
proj4String = QgsProject::instance()->readEntry("SpatialRefSys","//ProjectSRSProj4String",GEOPROJ4);
QgsSpatialRefSys defaultSRS;
if(defaultSRS.createFromProj4(proj4String))
@@ -274,8 +275,8 @@ static void customSrsValidation_(QgsSpatialRefSys* srs)

if(mySelector->exec())
{
QgsDebugMsg("Layer srs set from dialog: " + QString::number(mySelector->getCurrentSRSID()));
srs->createFromProj4(mySelector->getCurrentProj4String());
QgsDebugMsg("Layer srs set from dialog: " + QString::number(mySelector->getSelectedSRSID()));
srs->createFromProj4(mySelector->getSelectedProj4String());
srs->debugPrint();
}
else
@@ -20,7 +20,7 @@
#include "qgsoptions.h"
#include "qgis.h"
#include "qgisapp.h"
#include "qgslayerprojectionselector.h"
#include "qgsgenericprojectionselector.h"
#include "qgsspatialrefsys.h"

#include <QFileDialog>
@@ -365,7 +365,7 @@ void QgsOptions::saveOptions()
void QgsOptions::on_pbnSelectProjection_clicked()
{
QSettings settings;
QgsLayerProjectionSelector * mySelector = new QgsLayerProjectionSelector(this);
QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector(this);

//find out srs id of current proj4 string
QgsSpatialRefSys refSys;
@@ -380,7 +380,7 @@ void QgsOptions::on_pbnSelectProjection_clicked()
std::cout << "------ Global Default Projection Selection Set ----------" << std::endl;
#endif
//! @todo changes this control name in gui to txtGlobalProjString
txtGlobalWKT->setText(mySelector->getCurrentProj4String());
txtGlobalWKT->setText(mySelector->getSelectedProj4String());
#ifdef QGISDEBUG
std::cout << "------ Global Default Projection now set to ----------\n" << mGlobalSRSID << std::endl;
#endif
@@ -245,15 +245,15 @@ void QgsProjectProperties::apply()
// selected that has an srid. This prevents error if the user
// selects a top-level node rather than an actual coordinate
// system
long mySRSID = projectionSelector->getCurrentSRSID();
long mySRSID = projectionSelector->getSelectedSRSID();
if (mySRSID)
{
QgsSpatialRefSys srs(mySRSID, QgsSpatialRefSys::QGIS_SRSID);
myRender->setDestinationSrs(srs);

// write the currently selected projections _proj string_ to project settings
std::cout << "SpatialRefSys/ProjectSRSProj4String: " << projectionSelector->getCurrentProj4String().toLocal8Bit().data() << std::endl;
QgsProject::instance()->writeEntry("SpatialRefSys","/ProjectSRSProj4String",projectionSelector->getCurrentProj4String());
std::cout << "SpatialRefSys/ProjectSRSProj4String: " << projectionSelector->getSelectedProj4String().toLocal8Bit().data() << std::endl;
QgsProject::instance()->writeEntry("SpatialRefSys","/ProjectSRSProj4String",projectionSelector->getSelectedProj4String());

// Set the map units to the projected coordinates if we are projecting
if (isProjected())
@@ -20,7 +20,7 @@
#include "qgisapp.h"
#include "qgscoordinatetransform.h"
#include "qgsrasterlayerproperties.h"
#include "qgslayerprojectionselector.h"
#include "qgsgenericprojectionselector.h"
#include "qgsproject.h"
#include "qgsrasterbandstats.h"
#include "qgsrasterlayer.h"
@@ -1704,11 +1704,11 @@ void QgsRasterLayerProperties::on_pbnAddValuesManually_clicked()
void QgsRasterLayerProperties::on_pbnChangeSpatialRefSys_clicked()
{

QgsLayerProjectionSelector * mySelector = new QgsLayerProjectionSelector(this);
QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector(this);
mySelector->setSelectedSRSID(mRasterLayer->srs().srsid());
if(mySelector->exec())
{
QgsSpatialRefSys srs(mySelector->getCurrentSRSID(), QgsSpatialRefSys::QGIS_SRSID);
QgsSpatialRefSys srs(mySelector->getSelectedSRSID(), QgsSpatialRefSys::QGIS_SRSID);
mRasterLayer->setSrs(srs);
}
else
@@ -18,7 +18,7 @@

#include "qgsserversourceselect.h"

#include "qgslayerprojectionselector.h"
#include "qgsgenericprojectionselector.h"

#include "qgsnewhttpconnection.h"
#include "qgsnumericsortlistviewitem.h"
@@ -429,8 +429,9 @@ void QgsServerSourceSelect::on_btnChangeSpatialRefSys_clicked()

QSet<QString> crsFilter = mWmsProvider->supportedCrsForLayers(m_selectedLayers);

QgsLayerProjectionSelector * mySelector =
new QgsLayerProjectionSelector(this);
QgsGenericProjectionSelector * mySelector =
new QgsGenericProjectionSelector(this);
mySelector->setMessage();

mySelector->setOgcWmsCrsFilter(crsFilter);

@@ -443,15 +444,15 @@ void QgsServerSourceSelect::on_btnChangeSpatialRefSys_clicked()

if (mySelector->exec())
{
m_Epsg = mySelector->getCurrentEpsg();
m_Epsg = mySelector->getSelectedEpsg();
}
else
{
// NOOP
}

labelCoordRefSys->setText( descriptionForEpsg(m_Epsg) );
// labelCoordRefSys->setText( mySelector->getCurrentProj4String() );
// labelCoordRefSys->setText( mySelector->getSelectedProj4String() );

delete mySelector;

@@ -27,7 +27,7 @@
#include "qgsgraduatedsymboldialog.h"
#include "qgslabeldialog.h"
#include "qgslabel.h"
#include "qgslayerprojectionselector.h"
#include "qgsgenericprojectionselector.h"
#include "qgslogger.h"
#include "qgsproject.h"
#include "qgssinglesymboldialog.h"
@@ -609,11 +609,12 @@ QString QgsVectorLayerProperties::getMetadata()

void QgsVectorLayerProperties::on_pbnChangeSpatialRefSys_clicked()
{
QgsLayerProjectionSelector * mySelector = new QgsLayerProjectionSelector(this);
QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector(this);
mySelector->setMessage();
mySelector->setSelectedSRSID(layer->srs().srsid());
if(mySelector->exec())
{
QgsSpatialRefSys srs(mySelector->getCurrentSRSID(), QgsSpatialRefSys::QGIS_SRSID);
QgsSpatialRefSys srs(mySelector->getSelectedSRSID(), QgsSpatialRefSys::QGIS_SRSID);
layer->setSrs(srs);
}
else
@@ -9,7 +9,7 @@ qgsdetaileditemwidget.cpp
qgsdetaileditemdata.cpp
qgsencodingfiledialog.cpp
qgsfiledropedit.cpp
qgslayerprojectionselector.cpp
qgsgenericprojectionselector.cpp
qgsmapcanvas.cpp
qgsmapcanvasitem.cpp
qgsmapcanvasmap.cpp
@@ -32,7 +32,7 @@ qgsdetaileditemdelegate.h
qgsdetaileditemwidget.h
qgisinterface.h
qgsencodingfiledialog.h
qgslayerprojectionselector.h
qgsgenericprojectionselector.h
qgsmapcanvas.h
qgsmapoverviewcanvas.h
qgsmaptoolemitpoint.h
@@ -101,7 +101,7 @@ qgscolorbutton.h
qgscursors.h
qgsencodingfiledialog.h
qgsfiledropedit.h
qgslayerprojectionselector.h
qgsgenericprojectionselector.h
qgsmapcanvas.h
qgsmapcanvasitem.h
qgsmapcanvasmap.h
@@ -0,0 +1,101 @@
/***************************************************************************
qgsgenericprojectionselector.cpp
Set user defined CRS using projection selector widget
-------------------
begin : May 28, 2004
copyright : (C) 2004 by Gary E.Sherman
email : sherman at mrcc.com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id$ */
#include "qgsgenericprojectionselector.h"
#include <QApplication>

/**
* \class QgsGenericProjectionSelector
* \brief A generic dialog to prompt the user for a Coordinate Reference System
*/
QgsGenericProjectionSelector::QgsGenericProjectionSelector(QWidget *parent,
Qt::WFlags fl)
: QDialog(parent, fl)
{
setupUi(this);


connect(pbnOK, SIGNAL(clicked()), this, SLOT( accept()));
//we will show this only when a message is set
textEdit->hide();
QApplication::restoreOverrideCursor();
}

void QgsGenericProjectionSelector::setMessage(QString theMessage)
{
//short term kludge to make the layer selector default to showing
//a layer projection selection message. If you want the selector
if (theMessage.isEmpty())
{
// Set up text edit pane
QString format("<h2>%1</h2>%2 %3");
QString header = tr("Define this layer's projection:");
QString sentence1 = tr("This layer appears to have no projection specification.");
QString sentence2 = tr("By default, this layer will now have its projection set to that of the project"
", but you may override this by selecting a different projection below.");
textEdit->setHtml(format.arg(header).arg(sentence1)
.arg(sentence2));
}
else
{
textEdit->setHtml(theMessage);
}
textEdit->show();

}
//! Destructor
QgsGenericProjectionSelector::~QgsGenericProjectionSelector()
{}

void QgsGenericProjectionSelector::setSelectedSRSName(QString theName)
{
projectionSelector->setSelectedSRSName(theName);
}

void QgsGenericProjectionSelector::setSelectedSRSID(long theID)
{
projectionSelector->setSelectedSRSID(theID);
}

void QgsGenericProjectionSelector::setSelectedEpsg(long theID)
{
projectionSelector->setSelectedEpsg(theID);
}

QString QgsGenericProjectionSelector::getSelectedProj4String()
{
//@NOTE dont use getSelectedWKT as that just returns the name part!
return projectionSelector->getSelectedProj4String();
}

long QgsGenericProjectionSelector::getSelectedSRSID()
{
//@NOTE dont use getSelectedWKT as that just returns the name part!
return projectionSelector->getSelectedSRSID();
}

long QgsGenericProjectionSelector::getSelectedEpsg()
{
return projectionSelector->getSelectedEpsg();
}

void QgsGenericProjectionSelector::setOgcWmsCrsFilter(QSet<QString> crsFilter)
{
projectionSelector->setOgcWmsCrsFilter(crsFilter);
}

0 comments on commit aa896df

Please sign in to comment.