mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
consider datum transformation when pasting features (fixes #16846)
This commit is contained in:
parent
bcc8e90640
commit
bae6d56388
@ -960,6 +960,7 @@ QgsDatumTransformStore {#qgis_api_break_3_0_QgsDatumTransformStore}
|
||||
|
||||
- transformation() now returns a QgsCoordinateTransform object, not a pointer. An invalid QgsCoordinateTransform will
|
||||
be returned in place of a null pointer.
|
||||
- transformation() also optional source and destination authid parameters
|
||||
|
||||
|
||||
QgsDiagram {#qgis_api_break_3_0_QgsDiagram}
|
||||
|
@ -36,12 +36,13 @@ class QgsDatumTransformStore
|
||||
:rtype: bool
|
||||
%End
|
||||
|
||||
QgsCoordinateTransform transformation( const QgsMapLayer *layer ) const;
|
||||
QgsCoordinateTransform transformation( const QgsMapLayer *layer, QString srcAuthId = QString(), QString dstAuthId = QString() ) const;
|
||||
%Docstring
|
||||
Will return transform from layer's CRS to current destination CRS.
|
||||
Will emit datumTransformInfoRequested signal if the layer has no entry.
|
||||
:return: transformation associated with layer, or an invalid QgsCoordinateTransform
|
||||
if no transform is associated with the layer
|
||||
\param srcAuthId source CRS (defaults to layer crs)
|
||||
\param dstAuthId destination CRS (defaults to store's crs)
|
||||
:rtype: QgsCoordinateTransform
|
||||
%End
|
||||
|
||||
|
@ -853,6 +853,7 @@ called when panning is in action, reset indicates end of panning
|
||||
|
||||
|
||||
|
||||
|
||||
void updateDatumTransformEntries();
|
||||
%Docstring
|
||||
Make sure the datum transform store is properly populated
|
||||
|
@ -36,6 +36,8 @@
|
||||
#include "qgsogrutils.h"
|
||||
#include "qgsjsonutils.h"
|
||||
#include "qgssettings.h"
|
||||
#include "qgisapp.h"
|
||||
#include "qgsmapcanvas.h"
|
||||
|
||||
QgsClipboard::QgsClipboard()
|
||||
: QObject()
|
||||
@ -59,6 +61,9 @@ void QgsClipboard::replaceWithCopyOf( QgsVectorLayer *src )
|
||||
mFeatureFields = src->fields();
|
||||
mFeatureClipboard = src->selectedFeatures();
|
||||
mCRS = src->crs();
|
||||
layerDestroyed();
|
||||
mSrcLayer = src;
|
||||
connect( mSrcLayer, &QObject::destroyed, this, &QgsClipboard::layerDestroyed );
|
||||
|
||||
QgsDebugMsg( "replaced QGis clipboard." );
|
||||
|
||||
@ -73,11 +78,19 @@ void QgsClipboard::replaceWithCopyOf( QgsFeatureStore &featureStore )
|
||||
mFeatureFields = featureStore.fields();
|
||||
mFeatureClipboard = featureStore.features();
|
||||
mCRS = featureStore.crs();
|
||||
disconnect( mSrcLayer, &QObject::destroyed, this, &QgsClipboard::layerDestroyed );
|
||||
mSrcLayer = nullptr;
|
||||
setSystemClipboard();
|
||||
mUseSystemClipboard = false;
|
||||
emit changed();
|
||||
}
|
||||
|
||||
void QgsClipboard::layerDestroyed()
|
||||
{
|
||||
disconnect( mSrcLayer, &QObject::destroyed, this, &QgsClipboard::layerDestroyed );
|
||||
mSrcLayer = nullptr;
|
||||
}
|
||||
|
||||
QString QgsClipboard::generateClipboardText() const
|
||||
{
|
||||
QgsSettings settings;
|
||||
@ -264,7 +277,17 @@ bool QgsClipboard::isEmpty() const
|
||||
QgsFeatureList QgsClipboard::transformedCopyOf( const QgsCoordinateReferenceSystem &destCRS, const QgsFields &fields ) const
|
||||
{
|
||||
QgsFeatureList featureList = copyOf( fields );
|
||||
QgsCoordinateTransform ct( crs(), destCRS );
|
||||
|
||||
QgsCoordinateTransform ct;
|
||||
if ( mSrcLayer )
|
||||
{
|
||||
QgisApp::instance()->mapCanvas()->getDatumTransformInfo( mSrcLayer, crs().authid(), destCRS.authid() );
|
||||
ct = QgisApp::instance()->mapCanvas()->mapSettings().datumTransformStore().transformation( mSrcLayer, crs().authid(), destCRS.authid() );
|
||||
}
|
||||
else
|
||||
{
|
||||
ct = QgsCoordinateTransform( crs(), destCRS );
|
||||
}
|
||||
|
||||
QgsDebugMsg( "transforming clipboard." );
|
||||
for ( QgsFeatureList::iterator iter = featureList.begin(); iter != featureList.end(); ++iter )
|
||||
|
@ -148,6 +148,10 @@ class APP_EXPORT QgsClipboard : public QObject
|
||||
//! Emitted when content changed
|
||||
void changed();
|
||||
|
||||
private slots:
|
||||
//! source layer destroyed
|
||||
void layerDestroyed();
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
@ -180,6 +184,7 @@ class APP_EXPORT QgsClipboard : public QObject
|
||||
QgsFeatureList mFeatureClipboard;
|
||||
QgsFields mFeatureFields;
|
||||
QgsCoordinateReferenceSystem mCRS;
|
||||
QgsVectorLayer *mSrcLayer = nullptr;
|
||||
|
||||
//! True when the data from the system clipboard should be read
|
||||
bool mUseSystemClipboard;
|
||||
|
@ -50,13 +50,15 @@ bool QgsDatumTransformStore::hasEntryForLayer( QgsMapLayer *layer ) const
|
||||
return mEntries.contains( layer->id() );
|
||||
}
|
||||
|
||||
QgsCoordinateTransform QgsDatumTransformStore::transformation( const QgsMapLayer *layer ) const
|
||||
QgsCoordinateTransform QgsDatumTransformStore::transformation( const QgsMapLayer *layer, QString srcAuthId, QString dstAuthId ) const
|
||||
{
|
||||
if ( !layer )
|
||||
return QgsCoordinateTransform();
|
||||
|
||||
QString srcAuthId = layer->crs().authid();
|
||||
QString dstAuthId = mDestCRS.authid();
|
||||
if ( srcAuthId.isEmpty() )
|
||||
srcAuthId = layer->crs().authid();
|
||||
if ( dstAuthId.isEmpty() )
|
||||
dstAuthId = mDestCRS.authid();
|
||||
|
||||
if ( srcAuthId == dstAuthId )
|
||||
{
|
||||
|
@ -45,11 +45,12 @@ class CORE_EXPORT QgsDatumTransformStore
|
||||
|
||||
/**
|
||||
* Will return transform from layer's CRS to current destination CRS.
|
||||
* Will emit datumTransformInfoRequested signal if the layer has no entry.
|
||||
* \returns transformation associated with layer, or an invalid QgsCoordinateTransform
|
||||
* if no transform is associated with the layer
|
||||
* \param srcAuthId source CRS (defaults to layer crs)
|
||||
* \param dstAuthId destination CRS (defaults to store's crs)
|
||||
*/
|
||||
QgsCoordinateTransform transformation( const QgsMapLayer *layer ) const;
|
||||
QgsCoordinateTransform transformation( const QgsMapLayer *layer, QString srcAuthId = QString(), QString dstAuthId = QString() ) const;
|
||||
|
||||
void readXml( const QDomNode &parentNode );
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user