Skip to content
Permalink
Browse files

saving datums transform in projet, removing in dialog ok

  • Loading branch information
3nids authored and nyalldawson committed Nov 25, 2017
1 parent 3777aad commit 080bea1989b97e362be1a5ac7d6a7a8504681a0e
@@ -12,16 +12,41 @@ void QgsDatumTransformTableModel::setTransformContext( QgsCoordinateTransformCon
reset();
}

void QgsDatumTransformTableModel::removeTransform( QModelIndexList indexes )
{
QgsCoordinateReferenceSystem sourceCrs;
QgsCoordinateReferenceSystem destinationCrs;
for ( QModelIndexList::const_iterator it = indexes.constBegin(); it != indexes.constEnd(); it ++ )
{
if ( it->column() == SourceCrsColumn )
{
sourceCrs = QgsCoordinateReferenceSystem( data( *it, Qt::DisplayRole ).toString() );
}
if ( it->column() == DestinationCrsColumn )
{
destinationCrs = QgsCoordinateReferenceSystem( data( *it, Qt::DisplayRole ).toString() );
}
if ( sourceCrs.isValid() && destinationCrs.isValid() )
{
mTransformContext.removeSourceDestinationDatumTransform( sourceCrs, destinationCrs );
reset();
break;
}
}
}


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

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

@@ -50,17 +75,17 @@ QVariant QgsDatumTransformTableModel::data( const QModelIndex &index, int role )
case SourceCrsColumn:
return sourceCrs;
case SourceTransformColumn:
if (sourceTransform != -1)
if ( sourceTransform != -1 )
{
return QgsCoordinateTransform::datumTransformString( sourceTransform );
return QgsCoordinateTransform::datumTransformString( sourceTransform );
}
break;
case DestinationCrsColumn:
return destinationCrs;
case DestinationTransformColumn:
if (sourceTransform != -1)
if ( sourceTransform != -1 )
{
return QgsCoordinateTransform::datumTransformString( destinationTransform );
return QgsCoordinateTransform::datumTransformString( destinationTransform );
}
break;
default:
@@ -7,6 +7,12 @@
#include "qgis_app.h"
#include "qgscoordinatetransformcontext.h"

/**
* The QgsDatumTransformTableModel class is a table model to display and edit
* datum transformations.
*
* \since 3.0
*/
class APP_EXPORT QgsDatumTransformTableModel : public QAbstractTableModel
{
Q_OBJECT
@@ -26,6 +32,11 @@ class APP_EXPORT QgsDatumTransformTableModel : public QAbstractTableModel

QgsCoordinateTransformContext transformContext() {return mTransformContext;}

/**
* remove the transformation at given indexes
*/
void removeTransform( QModelIndexList indexes );

int rowCount( const QModelIndex &parent ) const override;
int columnCount( const QModelIndex &parent ) const override;
QVariant data( const QModelIndex &index, int role ) const override;
@@ -457,7 +457,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
//default datum transformations
mSettings->beginGroup( QStringLiteral( "/Projections" ) );

mShowDatumTransformDialogCheckBox->setChecked( mSettings->value( QStringLiteral( "showDatumTransformDialog" ), false ).toBool() );
mShowDatumTransformDialogCheckBox->setChecked( mSettings->value( QStringLiteral( "/Projections/showDatumTransformDialog" ), false ).toBool() );

QStringList projectionKeys = mSettings->allKeys();

@@ -164,8 +164,9 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
mDatumTransformTableView->setSelectionMode( QAbstractItemView::SingleSelection );
mDatumTransformTableView->setSelectionBehavior( QAbstractItemView::SelectRows );
connect( mDatumTransformAddButton, &QToolButton::clicked, this, &QgsProjectProperties::addDatumTransform );
connect( mDatumTransformRemoveButton, &QToolButton::clicked, this, &QgsProjectProperties::removeDatumTransform );

bool show = mSettings->value( QStringLiteral( "showDatumTransformDialog" ), false ).toBool();
bool show = settings.value( QStringLiteral( "/Projections/showDatumTransformDialog" ), false ).toBool();
mShowDatumTransformDialogCheckBox->setChecked( show );

QPolygonF mainCanvasPoly = mapCanvas->mapSettings().visiblePolygon();
@@ -820,6 +821,9 @@ void QgsProjectProperties::apply()
projectionSelector->pushProjectionToFront();
}

QgsCoordinateTransformContext transformContext = mDatumTransformTableModel->transformContext();
QgsProject::instance()->setTransformContext( transformContext );

// Set the project title
QgsProject::instance()->setTitle( title() );
QgsProject::instance()->setAutoTransaction( mAutoTransaction->isChecked() );
@@ -1241,6 +1245,15 @@ void QgsProjectProperties::addDatumTransform()
}
}

void QgsProjectProperties::removeDatumTransform()
{
QModelIndexList selectedIndexes = mDatumTransformTableView->selectionModel()->selectedIndexes();
if ( selectedIndexes.count() > 0 )
{
mDatumTransformTableModel->removeTransform( selectedIndexes );
}
}

void QgsProjectProperties::cbxWFSPubliedStateChanged( int aIdx )
{
QCheckBox *cb = qobject_cast<QCheckBox *>( twWFSLayers->cellWidget( aIdx, 1 ) );
@@ -73,6 +73,9 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:
//! add a new datum transform
void addDatumTransform();

//! remove currently selected datum transform
void removeDatumTransform();

/**
* Let the user add a scale to the list of project scales
* used in scale combobox instead of global ones */
@@ -45,6 +45,7 @@ QgsDatumTransformDialog::QgsDatumTransformDialog( QgsCoordinateReferenceSystem s
QApplication::setOverrideCursor( Qt::ArrowCursor );

updateTitle();
setOKButtonEnabled();

QgsSettings settings;
restoreGeometry( settings.value( QStringLiteral( "Windows/DatumTransformDialog/geometry" ) ).toByteArray() );
@@ -133,6 +134,14 @@ void QgsDatumTransformDialog::load()
delete item;
}
}

setOKButtonEnabled();
}

void QgsDatumTransformDialog::setOKButtonEnabled()
{
QTreeWidgetItem *item = mDatumTransformTreeWidget->currentItem();
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( mSourceCrs.isValid() && mDestinationCrs.isValid() && item );
}

QgsDatumTransformDialog::~QgsDatumTransformDialog()
@@ -245,6 +254,8 @@ void QgsDatumTransformDialog::mDatumTransformTreeWidget_currentItemChanged( QTre

mLabelSrcDescription->setText( current->toolTip( 0 ) );
mLabelDstDescription->setText( current->toolTip( 1 ) );

setOKButtonEnabled();
}

void QgsDatumTransformDialog::setSourceCrs()
@@ -258,6 +269,7 @@ void QgsDatumTransformDialog::setSourceCrs()
load();
}
delete mySelector;
setOKButtonEnabled();
}

void QgsDatumTransformDialog::setDestinationCrs()
@@ -271,6 +283,7 @@ void QgsDatumTransformDialog::setDestinationCrs()
load();
}
delete mySelector;
setOKButtonEnabled();
}

void QgsDatumTransformDialog::updateTitle()
@@ -66,6 +66,8 @@ class GUI_EXPORT QgsDatumTransformDialog : public QDialog, private Ui::QgsDatumT
//! 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();
void setOKButtonEnabled();


QList< QList< int > > mDatumTransforms;
QgsCoordinateReferenceSystem mSourceCrs;

0 comments on commit 080bea1

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