Skip to content
Permalink
Browse files

modification to QgsDatumTransformationDialog to allow interaction wit…

…h CRSs
  • Loading branch information
3nids authored and nyalldawson committed Nov 23, 2017
1 parent f4eae28 commit e178ffc8ffa33925445a19132cdae213aa4fbaf8
@@ -7021,12 +7021,13 @@ void QgisApp::saveAsVectorFileGeneral( QgsVectorLayer *vlayer, bool symbologyOpt
{
//ask user about datum transformation
QgsSettings settings;
QList< QList< int > > dt = QgsCoordinateTransform::datumTransformations( vlayer->crs(), destCRS );
if ( dt.size() > 1 && settings.value( QStringLiteral( "Projections/showDatumTransformDialog" ), false ).toBool() )
QgsDatumTransformDialog *dlg = new QgsDatumTransformDialog( vlayer->crs(), destCRS );
if ( dlg->availableTransformationCount() > 1 &&
settings.value( QStringLiteral( "Projections/showDatumTransformDialog" ), false ).toBool() )
{
QgsDatumTransformDialog d( dt );
d.exec();
dlg->exec();
}
delete dlg;
ct = QgsCoordinateTransform( vlayer->crs(), destCRS, QgsProject::instance() );
}

@@ -25,6 +25,7 @@
#include "qgscomposer.h"
#include "qgscoordinatetransform.h"
#include "qgsdatumtransformtablemodel.h"
#include "qgsdatumtransformdialog.h"
#include "qgslayoutmanager.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"
@@ -156,15 +157,15 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
projectionSelector->setCrs( QgsProject::instance()->crs() );

// Datum transforms
QgsDatumTransformTableModel* datumTransformTableModel = new QgsDatumTransformTableModel(this);
QgsDatumTransformTableModel *datumTransformTableModel = new QgsDatumTransformTableModel( this );
QgsCoordinateTransformContext context = QgsProject::instance()->transformContext();
datumTransformTableModel->setTransformContext(context);
mDatumTransformTableView->setModel(datumTransformTableModel);
datumTransformTableModel->setTransformContext( context );
mDatumTransformTableView->setModel( datumTransformTableModel );
mDatumTransformTableView->resizeColumnToContents( 0 );
mDatumTransformTableView->horizontalHeader()->show();
mDatumTransformTableView->setSelectionMode( QAbstractItemView::SingleSelection );
mDatumTransformTableView->setSelectionBehavior( QAbstractItemView::SelectRows );
connect(mDatumTransformAddButton, &QToolButton::clicked, this, &QgsProjectProperties::addDatumTransform);
connect( mDatumTransformAddButton, &QToolButton::clicked, this, &QgsProjectProperties::addDatumTransform );

QPolygonF mainCanvasPoly = mapCanvas->mapSettings().visiblePolygon();
QgsGeometry g = QgsGeometry::fromQPolygonF( mainCanvasPoly );
@@ -1224,12 +1225,16 @@ void QgsProjectProperties::apply()

void QgsProjectProperties::showProjectionsTab()
{
mOptionsListWidget->setCurrentRow( 1 );
mOptionsListWidget->setCurrentRow( 1 );
}

QgsProjectProperties::addDatumTransform()
void QgsProjectProperties::addDatumTransform()
{
QgsDatumTransformDialog *dlg = new QgsDatumTransformDialog();
if ( dlg->exec() )
{

}
}

void QgsProjectProperties::cbxWFSPubliedStateChanged( int aIdx )
@@ -70,7 +70,7 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:
void showProjectionsTab();

//! add a new datum transform
addDatumTransform();
void addDatumTransform();

/**
* Let the user add a scale to the list of project scales
@@ -17,22 +17,33 @@

#include "qgsdatumtransformdialog.h"
#include "qgscoordinatetransform.h"
#include "qgsprojectionselectiondialog.h"
#include "qgslogger.h"
#include "qgssettings.h"
#include "qgsproject.h"

#include <QDir>

QgsDatumTransformDialog::QgsDatumTransformDialog( const QList< QList< int > > &dt, QWidget *parent, Qt::WindowFlags f )
QgsDatumTransformDialog::QgsDatumTransformDialog( QgsCoordinateReferenceSystem sourceCrs,
QgsCoordinateReferenceSystem destinationCrs,
QWidget *parent, Qt::WindowFlags f )
: QDialog( parent, f )
, mDt( dt )
{
setupUi( this );

connect( mHideDeprecatedCheckBox, &QCheckBox::stateChanged, this, &QgsDatumTransformDialog::mHideDeprecatedCheckBox_stateChanged );
connect( mDatumTransformTreeWidget, &QTreeWidget::currentItemChanged, this, &QgsDatumTransformDialog::mDatumTransformTreeWidget_currentItemChanged );

connect( mSourceCrsButton, &QPushButton::clicked, this, &QgsDatumTransformDialog::setSourceCrs );
connect( mDstCrsButton, &QPushButton::clicked, this, &QgsDatumTransformDialog::setDestinationCrs );

connect( buttonBox, &QDialogButtonBox::accepted, this, &QgsDatumTransformDialog::accepted );

//get list of datum transforms
mSourceCrs = sourceCrs;
mDestinationCrs = destinationCrs;
mDatumTransforms = QgsCoordinateTransform::datumTransformations( sourceCrs, destinationCrs );

QApplication::setOverrideCursor( Qt::ArrowCursor );

updateTitle();
@@ -59,8 +70,8 @@ void QgsDatumTransformDialog::load()

mDatumTransformTreeWidget->clear();

QList< QList< int > >::const_iterator it = mDt.constBegin();
for ( ; it != mDt.constEnd(); ++it )
QList< QList< int > >::const_iterator it = mDatumTransforms.constBegin();
for ( ; it != mDatumTransforms.constEnd(); ++it )
{
QTreeWidgetItem *item = new QTreeWidgetItem();
bool itemDisabled = false;
@@ -142,13 +153,12 @@ QgsDatumTransformDialog::~QgsDatumTransformDialog()
QApplication::restoreOverrideCursor();
}

void QgsDatumTransformDialog::setCrs( const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination )
int QgsDatumTransformDialog::availableTransformationCount()
{
mSrcCrs = source;
mDestCrs = destination;
updateTitle();
return mDatumTransforms.count();
}


QList< int > QgsDatumTransformDialog::selectedDatumTransform()
{
QList<int> list;
@@ -244,7 +254,7 @@ void QgsDatumTransformDialog::mDatumTransformTreeWidget_currentItemChanged( QTre

void QgsDatumTransformDialog::accepted()
{
if ( !mSrcCrs.isValid() || !mDestCrs.isValid() )
if ( !mSourceCrs.isValid() || !mDestinationCrs.isValid() )
return;

int srcTransform = -1;
@@ -260,12 +270,38 @@ void QgsDatumTransformDialog::accepted()
}

QgsCoordinateTransformContext context = QgsProject::instance()->transformContext();
context.addSourceDestinationDatumTransform( mSrcCrs, mDestCrs, srcTransform, destTransform );
context.addSourceDestinationDatumTransform( mSourceCrs, mDestinationCrs, srcTransform, destTransform );
QgsProject::instance()->setTransformContext( context );
}

void QgsDatumTransformDialog::setSourceCrs()
{
QgsProjectionSelectionDialog *mySelector = new QgsProjectionSelectionDialog( this );
if ( mySelector->exec() )
{
mSourceCrs = mySelector->crs();
updateTitle();
mDatumTransforms = QgsCoordinateTransform::datumTransformations( mSourceCrs, mDestinationCrs );
load();
}
delete mySelector;
}

void QgsDatumTransformDialog::setDestinationCrs()
{
QgsProjectionSelectionDialog *mySelector = new QgsProjectionSelectionDialog( this );
if ( mySelector->exec() )
{
mDestinationCrs = mySelector->crs();
updateTitle();
mDatumTransforms = QgsCoordinateTransform::datumTransformations( mSourceCrs, mDestinationCrs );
load();
}
delete mySelector;
}

void QgsDatumTransformDialog::updateTitle()
{
mSourceCrsButton->setText( QStringLiteral( "%1 - %2" ).arg( mSrcCrs.authid(), mSrcCrs.isValid() ? mSrcCrs.description() : tr( "unknown" ) ) );
mDstCrsButton->setText( QStringLiteral( "%1 - %2" ).arg( mDestCrs.authid(), mDestCrs.isValid() ? mDestCrs.description() : tr( "unknown" ) ) );
mSourceCrsButton->setText( QStringLiteral( "%1 - %2" ).arg( mSourceCrs.authid(), mSourceCrs.isValid() ? mSourceCrs.description() : tr( "unknown" ) ) );
mDstCrsButton->setText( QStringLiteral( "%1 - %2" ).arg( mDestinationCrs.authid(), mDestinationCrs.isValid() ? mDestinationCrs.description() : tr( "unknown" ) ) );
}
@@ -37,14 +37,16 @@ class GUI_EXPORT QgsDatumTransformDialog : public QDialog, private Ui::QgsDatumT
/**
* Constructor for QgsDatumTransformDialog.
*/
QgsDatumTransformDialog( const QList< QList< int > > &dt, QWidget *parent = nullptr, Qt::WindowFlags f = nullptr );
QgsDatumTransformDialog( QgsCoordinateReferenceSystem sourceCrs = QgsCoordinateReferenceSystem(),
QgsCoordinateReferenceSystem destinationCrs = QgsCoordinateReferenceSystem(),
QWidget *parent = nullptr, Qt::WindowFlags f = nullptr );
~QgsDatumTransformDialog();

/**
* Sets the \a source and \a destination coordinate reference systems.
* \since QGIS 3.0
* Returns the number of possible datum transformation for currently selected source and destination CRS
* \since 3.0
*/
void setCrs( const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination );
int availableTransformationCount();

//! getter for selected datum transformations
QList< int > selectedDatumTransform();
@@ -56,18 +58,19 @@ class GUI_EXPORT QgsDatumTransformDialog : public QDialog, private Ui::QgsDatumT
void mHideDeprecatedCheckBox_stateChanged( int state );
void mDatumTransformTreeWidget_currentItemChanged( QTreeWidgetItem *, QTreeWidgetItem * );
void accepted();
void setSourceCrs();
void setDestinationCrs();

private:
QgsDatumTransformDialog();
void updateTitle();
bool gridShiftTransformation( const QString &itemText ) const;
//! Returns false if the location of the grid shift files is known (PROJ_LIB) and the shift file is not there
bool testGridShiftFileAvailability( QTreeWidgetItem *item, int col ) const;
void load();

QList< QList< int > > mDt;
QgsCoordinateReferenceSystem mSrcCrs;
QgsCoordinateReferenceSystem mDestCrs;
QList< QList< int > > mDatumTransforms;
QgsCoordinateReferenceSystem mSourceCrs;
QgsCoordinateReferenceSystem mDestinationCrs;
};

#endif // QGSDATUMTRANSFORMDIALOG_H
@@ -2086,17 +2086,10 @@ void QgsMapCanvas::getDatumTransformInfo( const QgsCoordinateReferenceSystem &so
return;
}

//get list of datum transforms
const QList< QList< int > > dt = QgsCoordinateTransform::datumTransformations( source, destination );
if ( dt.size() < 2 )
{
return;
}

//if several possibilities: present dialog
QgsDatumTransformDialog d( dt );
d.setCrs( source, destination );
d.exec();
QgsDatumTransformDialog d( source, destination );
if ( d.availableTransformationCount() > 1 )
d.exec();
}

void QgsMapCanvas::zoomByFactor( double scaleFactor, const QgsPointXY *center )

0 comments on commit e178ffc

Please sign in to comment.
You can’t perform that action at this time.