Skip to content
Permalink
Browse files

adding datum transform works

  • Loading branch information
3nids authored and nyalldawson committed Nov 24, 2017
1 parent e178ffc commit 2b1f82ff357a68f1e2ab84ed986fdf893032de18
@@ -1,58 +1,96 @@
#include "qgsdatumtransformtablemodel.h"

QgsDatumTransformTableModel::QgsDatumTransformTableModel(QObject *parent)
: QAbstractTableModel(parent)
QgsDatumTransformTableModel::QgsDatumTransformTableModel( QObject *parent )
: QAbstractTableModel( parent )
{
}

void QgsDatumTransformTableModel::setTransformContext(QgsCoordinateTransformContext &context)
void QgsDatumTransformTableModel::setTransformContext( QgsCoordinateTransformContext &context )
{
mTransformContext = context;
reset();
}

int QgsDatumTransformTableModel::rowCount(const QModelIndex &parent) const

int QgsDatumTransformTableModel::rowCount( const QModelIndex &parent ) const
{
return mTransformContext.sourceDestinationDatumTransforms().count()
+ mTransformContext.sourceDatumTransforms().count()
+ mTransformContext.destinationDatumTransforms().count();
return mTransformContext.sourceDestinationDatumTransforms().count()
+ mTransformContext.sourceDatumTransforms().count()
+ mTransformContext.destinationDatumTransforms().count();
}

int QgsDatumTransformTableModel::columnCount(const QModelIndex &parent) const
int QgsDatumTransformTableModel::columnCount( const QModelIndex &parent ) const
{
return 4;
return 4;
}

QVariant QgsDatumTransformTableModel::data(const QModelIndex &index, int role) const
QVariant QgsDatumTransformTableModel::data( const QModelIndex &index, int role ) const
{
QString sourceCrs;
int sourceTransform = -1;
QString destinationCrs;
int destinationTransform = -1;

if ( index.row() < mTransformContext.sourceDestinationDatumTransforms().count() )
{
QPair< QString, QString> crses = mTransformContext.sourceDestinationDatumTransforms().keys().at( index.row() );
sourceCrs = crses.first;
destinationCrs = crses.second;
QPair< int, int> transforms = mTransformContext.sourceDestinationDatumTransforms().value( crses );
sourceTransform = transforms.first;
destinationTransform = transforms.second;
}

return QVariant();

switch ( role )
{
case Qt::DisplayRole:
switch ( index.column() )
{
case SourceCrsColumn:
return sourceCrs;
case SourceTransformColumn:
return sourceTransform;
case DestinationCrsColumn:
return destinationCrs;
case DestinationTransformColumn:
return destinationTransform;
default:
break;
}
break;
default:
break;
}

return QVariant();
}

QVariant QgsDatumTransformTableModel::headerData(int section, Qt::Orientation orientation, int role) const
QVariant QgsDatumTransformTableModel::headerData( int section, Qt::Orientation orientation, int role ) const
{
if (orientation == Qt::Vertical)
return QVariant();
if ( orientation == Qt::Vertical )
return QVariant();

switch (role) {
switch ( role )
{
case Qt::DisplayRole:
switch (section) {
case SourceCrsHeader:
return tr("Source CRS");
case SourceTransformHeader:
return tr("Source datum transform");
case DestinationCrsHeader:
return tr("Destination CRS");
case DestinationTransformHeader:
return tr("Destination datum transform");
switch ( section )
{
case SourceCrsColumn :
return tr( "Source CRS" );
case SourceTransformColumn:
return tr( "Source datum transform" );
case DestinationCrsColumn:
return tr( "Destination CRS" );
case DestinationTransformColumn:
return tr( "Destination datum transform" );
default:
break;
}
break;
break;
}
break;
default:
break;
}
break;
}

return QVariant();
return QVariant();
}
@@ -10,26 +10,29 @@
class APP_EXPORT QgsDatumTransformTableModel : public QAbstractTableModel
{
Q_OBJECT
public:

enum Headers {
SourceCrsHeader = 0,
SourceTransformHeader,
DestinationCrsHeader,
DestinationTransformHeader,
public:

enum TableColumns
{
SourceCrsColumn = 0,
SourceTransformColumn,
DestinationCrsColumn,
DestinationTransformColumn,
};

QgsDatumTransformTableModel( QObject* parent = nullptr);
QgsDatumTransformTableModel( QObject *parent = nullptr );

void setTransformContext( QgsCoordinateTransformContext &context );

public:
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
QgsCoordinateTransformContext transformContext() {return mTransformContext;}

int rowCount( const QModelIndex &parent ) const override;
int columnCount( const QModelIndex &parent ) const override;
QVariant data( const QModelIndex &index, int role ) const override;
QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;

private:

private:
QgsCoordinateTransformContext mTransformContext;
};

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

// Datum transforms
QgsDatumTransformTableModel *datumTransformTableModel = new QgsDatumTransformTableModel( this );
QgsCoordinateTransformContext context = QgsProject::instance()->transformContext();
datumTransformTableModel->setTransformContext( context );
mDatumTransformTableView->setModel( datumTransformTableModel );
mDatumTransformTableModel->setTransformContext( context );
mDatumTransformTableView->setModel( mDatumTransformTableModel );
mDatumTransformTableView->resizeColumnToContents( 0 );
mDatumTransformTableView->horizontalHeader()->show();
mDatumTransformTableView->setSelectionMode( QAbstractItemView::SingleSelection );
@@ -1233,7 +1231,10 @@ void QgsProjectProperties::addDatumTransform()
QgsDatumTransformDialog *dlg = new QgsDatumTransformDialog();
if ( dlg->exec() )
{

QPair< QPair<QgsCoordinateReferenceSystem, int>, QPair<QgsCoordinateReferenceSystem, int > > dt = dlg->selectedDatumTransforms();
QgsCoordinateTransformContext context = mDatumTransformTableModel->transformContext();
context.addSourceDestinationDatumTransform( dt.first.first, dt.second.first, dt.first.second, dt.second.second );
mDatumTransformTableModel->setTransformContext( context );
}
}

@@ -24,6 +24,7 @@
#include "qgsguiutils.h"
#include "qgshelp.h"
#include "qgis_app.h"
#include "qgsdatumtransformtablemodel.h"

class QgsMapCanvas;
class QgsRelationManagerDialog;
@@ -176,6 +177,7 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:
QgsRelationManagerDialog *mRelationManagerDlg = nullptr;
QgsMapCanvas *mMapCanvas = nullptr;
QgsStyle *mStyle = nullptr;
QgsDatumTransformTableModel *mDatumTransformTableModel = new QgsDatumTransformTableModel( this );

void populateStyles();
void editSymbol( QComboBox *cbo );
@@ -37,8 +37,6 @@ QgsDatumTransformDialog::QgsDatumTransformDialog( QgsCoordinateReferenceSystem s
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;
@@ -51,7 +49,6 @@ QgsDatumTransformDialog::QgsDatumTransformDialog( QgsCoordinateReferenceSystem s
QgsSettings settings;
restoreGeometry( settings.value( QStringLiteral( "Windows/DatumTransformDialog/geometry" ) ).toByteArray() );
mHideDeprecatedCheckBox->setChecked( settings.value( QStringLiteral( "Windows/DatumTransformDialog/hideDeprecated" ), false ).toBool() );
mRememberSelectionCheckBox->setChecked( settings.value( QStringLiteral( "Windows/DatumTransformDialog/rememberSelection" ), false ).toBool() );

mLabelSrcDescription->clear();
mLabelDstDescription->clear();
@@ -143,7 +140,6 @@ QgsDatumTransformDialog::~QgsDatumTransformDialog()
QgsSettings settings;
settings.setValue( QStringLiteral( "Windows/DatumTransformDialog/geometry" ), saveGeometry() );
settings.setValue( QStringLiteral( "Windows/DatumTransformDialog/hideDeprecated" ), mHideDeprecatedCheckBox->isChecked() );
settings.setValue( QStringLiteral( "Windows/DatumTransformDialog/rememberSelection" ), mRememberSelectionCheckBox->isChecked() );

for ( int i = 0; i < 2; i++ )
{
@@ -159,25 +155,24 @@ int QgsDatumTransformDialog::availableTransformationCount()
}


QList< int > QgsDatumTransformDialog::selectedDatumTransform()
QPair<QPair<QgsCoordinateReferenceSystem, int>, QPair<QgsCoordinateReferenceSystem, int> > QgsDatumTransformDialog::selectedDatumTransforms()
{
QList<int> list;
QTreeWidgetItem *item = mDatumTransformTreeWidget->currentItem();
QPair< QPair<QgsCoordinateReferenceSystem, int>, QPair<QgsCoordinateReferenceSystem, int > > sdt;
sdt.first.first = mSourceCrs;
sdt.second.first = mDestinationCrs;

if ( item )
{
list.reserve( 2 );
for ( int i = 0; i < 2; ++i )
{
int transformNr = item->data( i, Qt::UserRole ).toInt();
list << transformNr;
}
sdt.first.second = item->data( 0, Qt::UserRole ).toInt();
sdt.second.second = item->data( 1, Qt::UserRole ).toInt();
}
return list;
}

bool QgsDatumTransformDialog::rememberSelection() const
{
return mRememberSelectionCheckBox->isChecked();
else
{
sdt.first.second = -1;
sdt.second.second = -1;
}
return sdt;
}

bool QgsDatumTransformDialog::gridShiftTransformation( const QString &itemText ) const
@@ -252,28 +247,6 @@ void QgsDatumTransformDialog::mDatumTransformTreeWidget_currentItemChanged( QTre
mLabelDstDescription->setText( current->toolTip( 1 ) );
}

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

int srcTransform = -1;
int destTransform = -1;
const QList<int> t = selectedDatumTransform();
if ( !t.isEmpty() )
{
srcTransform = t.at( 0 );
}
if ( t.size() > 1 )
{
destTransform = t.at( 1 );
}

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

void QgsDatumTransformDialog::setSourceCrs()
{
QgsProjectionSelectionDialog *mySelector = new QgsProjectionSelectionDialog( this );
@@ -48,16 +48,15 @@ class GUI_EXPORT QgsDatumTransformDialog : public QDialog, private Ui::QgsDatumT
*/
int availableTransformationCount();

//! getter for selected datum transformations
QList< int > selectedDatumTransform();

//! dialog shall remember the selection
bool rememberSelection() const;
/**
* Returns the source and destination transforms, each being a pair of QgsCoordinateReferenceSystems and datum transform code
* \since 3.0
*/
QPair< QPair<QgsCoordinateReferenceSystem, int>, QPair<QgsCoordinateReferenceSystem, int > > selectedDatumTransforms();

private slots:
void mHideDeprecatedCheckBox_stateChanged( int state );
void mDatumTransformTreeWidget_currentItemChanged( QTreeWidgetItem *, QTreeWidgetItem * );
void accepted();
void setSourceCrs();
void setDestinationCrs();

@@ -89,13 +89,6 @@
</item>
<item row="5" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QCheckBox" name="mRememberSelectionCheckBox">
<property name="text">
<string>Remember selection</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
@@ -132,7 +125,6 @@
</widget>
<tabstops>
<tabstop>mDatumTransformTreeWidget</tabstop>
<tabstop>mRememberSelectionCheckBox</tabstop>
<tabstop>mHideDeprecatedCheckBox</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>

0 comments on commit 2b1f82f

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