Skip to content
Permalink
Browse files

Allow double-clicking on coordinate operation to quickly select them

  • Loading branch information
nyalldawson committed Dec 19, 2019
1 parent 9664526 commit c04d4faf7fcd0bc13b4e0a92d2a31d8defc3e91a
@@ -127,6 +127,11 @@ Sets the details of the ``operation`` currently selected within the widget.
void operationChanged();
%Docstring
Emitted when the operation selected in the dialog is changed.
%End

void operationDoubleClicked();
%Docstring
Emitted when an operation is double-clicked in the widget.
%End

};
@@ -221,9 +221,21 @@ QgsDatumTransformTableWidget::QgsDatumTransformTableWidget( QWidget *parent )
mTableView->setAlternatingRowColors( true );
connect( mAddButton, &QToolButton::clicked, this, &QgsDatumTransformTableWidget::addDatumTransform );
connect( mRemoveButton, &QToolButton::clicked, this, &QgsDatumTransformTableWidget::removeDatumTransform );
connect( mEditButton, &QToolButton::clicked, this, &QgsDatumTransformTableWidget::editDatumTransform );
connect( mEditButton, &QToolButton::clicked, this, [ = ]
{
QModelIndexList selectedIndexes = mTableView->selectionModel()->selectedIndexes();
if ( selectedIndexes.count() > 0 )
{
editDatumTransform( selectedIndexes.at( 0 ) );
}
} );

connect( mTableView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &QgsDatumTransformTableWidget::selectionChanged );

connect( mTableView, &QTableView::doubleClicked, this, [ = ]( const QModelIndex & index )
{
editDatumTransform( index );
} );
mEditButton->setEnabled( false );
}

@@ -253,69 +265,47 @@ void QgsDatumTransformTableWidget::removeDatumTransform()
}
}

void QgsDatumTransformTableWidget::editDatumTransform()
void QgsDatumTransformTableWidget::editDatumTransform( const QModelIndex &index )
{
QModelIndexList selectedIndexes = mTableView->selectionModel()->selectedIndexes();
if ( selectedIndexes.count() > 0 )
{
QgsCoordinateReferenceSystem sourceCrs;
QgsCoordinateReferenceSystem destinationCrs;
QString proj;
int sourceTransform = -1;
int destinationTransform = -1;
for ( QModelIndexList::const_iterator it = selectedIndexes.constBegin(); it != selectedIndexes.constEnd(); it ++ )
{
switch ( it->column() )
{
case QgsDatumTransformTableModel::SourceCrsColumn:
sourceCrs = QgsCoordinateReferenceSystem( mModel->data( *it, Qt::DisplayRole ).toString() );
break;
case QgsDatumTransformTableModel::DestinationCrsColumn:
destinationCrs = QgsCoordinateReferenceSystem( mModel->data( *it, Qt::DisplayRole ).toString() );
break;
QString proj;
int sourceTransform = -1;
int destinationTransform = -1;

QgsCoordinateReferenceSystem sourceCrs = QgsCoordinateReferenceSystem( mModel->data( mModel->index( index.row(), QgsDatumTransformTableModel::SourceCrsColumn ), Qt::DisplayRole ).toString() );
QgsCoordinateReferenceSystem destinationCrs = QgsCoordinateReferenceSystem( mModel->data( mModel->index( index.row(), QgsDatumTransformTableModel::DestinationCrsColumn ), Qt::DisplayRole ).toString() );

#if PROJ_VERSION_MAJOR>=6
case QgsDatumTransformTableModel::ProjDefinitionColumn:
proj = mModel->data( *it, Qt::UserRole ).toString();
break;
proj = mModel->data( mModel->index( index.row(), QgsDatumTransformTableModel::ProjDefinitionColumn ), Qt::UserRole ).toString();
#else
case QgsDatumTransformTableModel::SourceTransformColumn:
sourceTransform = mModel->data( *it, Qt::UserRole ).toInt();
break;
case QgsDatumTransformTableModel::DestinationTransformColumn:
destinationTransform = mModel->data( *it, Qt::UserRole ).toInt();
break;
sourceTransform = mModel->data( mModel->index( index.row(), QgsDatumTransformTableModel::SourceTransformColumn ), Qt::UserRole ).toInt();
destinationTransform = mModel->data( mModel->index( index.row(), QgsDatumTransformTableModel::DestinationTransformColumn ), Qt::UserRole ).toInt();
#endif
default:
break;
}
}

#if PROJ_VERSION_MAJOR>=6
if ( sourceCrs.isValid() && destinationCrs.isValid() && !proj.isEmpty() )
if ( sourceCrs.isValid() && destinationCrs.isValid() && !proj.isEmpty() )
#else
if ( sourceCrs.isValid() && destinationCrs.isValid() &&
( sourceTransform != -1 || destinationTransform != -1 ) )
if ( sourceCrs.isValid() && destinationCrs.isValid() &&
( sourceTransform != -1 || destinationTransform != -1 ) )
#endif
{
QgsDatumTransformDialog dlg( sourceCrs, destinationCrs, true, false, false, qMakePair( sourceTransform, destinationTransform ), nullptr, nullptr, proj, QgisApp::instance()->mapCanvas() );
if ( dlg.exec() )
{
QgsDatumTransformDialog dlg( sourceCrs, destinationCrs, true, false, false, qMakePair( sourceTransform, destinationTransform ), nullptr, nullptr, proj, QgisApp::instance()->mapCanvas() );
if ( dlg.exec() )
const QgsDatumTransformDialog::TransformInfo dt = dlg.selectedDatumTransform();
QgsCoordinateTransformContext context = mModel->transformContext();
if ( sourceCrs != dt.sourceCrs || destinationCrs != dt.destinationCrs )
{
const QgsDatumTransformDialog::TransformInfo dt = dlg.selectedDatumTransform();
QgsCoordinateTransformContext context = mModel->transformContext();
if ( sourceCrs != dt.sourceCrs || destinationCrs != dt.destinationCrs )
{
context.removeCoordinateOperation( sourceCrs, destinationCrs );
Q_NOWARN_DEPRECATED_PUSH
context.removeSourceDestinationDatumTransform( sourceCrs, destinationCrs );
Q_NOWARN_DEPRECATED_POP
}
// QMap::insert takes care of replacing existing value
context.removeCoordinateOperation( sourceCrs, destinationCrs );
Q_NOWARN_DEPRECATED_PUSH
context.addSourceDestinationDatumTransform( dt.sourceCrs, dt.destinationCrs, dt.sourceTransformId, dt.destinationTransformId );
context.removeSourceDestinationDatumTransform( sourceCrs, destinationCrs );
Q_NOWARN_DEPRECATED_POP
context.addCoordinateOperation( dt.sourceCrs, dt.destinationCrs, dt.proj );
mModel->setTransformContext( context );
}
// QMap::insert takes care of replacing existing value
Q_NOWARN_DEPRECATED_PUSH
context.addSourceDestinationDatumTransform( dt.sourceCrs, dt.destinationCrs, dt.sourceTransformId, dt.destinationTransformId );
Q_NOWARN_DEPRECATED_POP
context.addCoordinateOperation( dt.sourceCrs, dt.destinationCrs, dt.proj );
mModel->setTransformContext( context );
}
}
}
@@ -99,7 +99,7 @@ class APP_EXPORT QgsDatumTransformTableWidget : public QWidget, private Ui::QgsD
void removeDatumTransform();

//! edit currently selected datum transform
void editDatumTransform();
void editDatumTransform( const QModelIndex &index );

private slots:

@@ -79,6 +79,7 @@ QgsCoordinateOperationWidget::QgsCoordinateOperationWidget( QWidget *parent )
connect( mHideDeprecatedCheckBox, &QCheckBox::stateChanged, this, [ = ] { loadAvailableOperations(); } );
connect( mShowSupersededCheckBox, &QCheckBox::toggled, this, &QgsCoordinateOperationWidget::showSupersededToggled );
connect( mCoordinateOperationTableWidget, &QTableWidget::currentItemChanged, this, &QgsCoordinateOperationWidget::tableCurrentItemChanged );
connect( mCoordinateOperationTableWidget, &QTableWidget::itemDoubleClicked, this, &QgsCoordinateOperationWidget::operationDoubleClicked );

mLabelSrcDescription->clear();
mLabelDstDescription->clear();
@@ -140,6 +140,11 @@ class GUI_EXPORT QgsCoordinateOperationWidget : public QWidget, private Ui::QgsC
*/
void operationChanged();

/**
* Emitted when an operation is double-clicked in the widget.
*/
void operationDoubleClicked();

private slots:

void tableCurrentItemChanged( QTableWidgetItem *, QTableWidgetItem * );
@@ -142,6 +142,19 @@ QgsDatumTransformDialog::QgsDatumTransformDialog( const QgsCoordinateReferenceSy
deets.sourceTransformId = selectedDatumTransforms.first;
deets.destinationTransformId = selectedDatumTransforms.second;
mCoordinateOperationsWidget->setSelectedOperation( deets );

connect( mCoordinateOperationsWidget, &QgsCoordinateOperationWidget::operationDoubleClicked, this, [ = ]
{

#if PROJ_VERSION_MAJOR>=6
if ( mCoordinateOperationsWidget->sourceCrs().isValid() && mCoordinateOperationsWidget->destinationCrs().isValid()
&& mCoordinateOperationsWidget->selectedOperation().isAvailable )
accept();
#else
if ( mCoordinateOperationsWidget->sourceCrs().isValid() && mCoordinateOperationsWidget->destinationCrs().isValid() && mCoordinateOperationsWidget->hasSelection() )
accept();
#endif
} );
}

void QgsDatumTransformDialog::setOKButtonEnabled()

0 comments on commit c04d4fa

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