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