Skip to content

Commit

Permalink
Fix pasting features to new layer doesn't paste fields
Browse files Browse the repository at this point in the history
Fixes #17702
  • Loading branch information
nyalldawson committed Jan 3, 2018
1 parent 611ae95 commit 7febd1e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/app/qgsclipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ QString QgsClipboard::generateClipboardText() const

void QgsClipboard::setSystemClipboard()
{
// avoid overwriting internal clipboard - note that on Windows, the call to QClipboard::setText
// below doesn't immediately trigger QClipboard::dataChanged, and accordingly the call to
// systemClipboardChanged() is delayed. So by setting mIgnoreNextSystemClipboardChange we indicate
// that just the next call to systemClipboardChanged() should be ignored
mIgnoreNextSystemClipboardChange = true;

QString textCopy = generateClipboardText();

QClipboard *cb = QApplication::clipboard();
Expand Down Expand Up @@ -323,8 +329,22 @@ QByteArray QgsClipboard::data( const QString &mimeType ) const
return QApplication::clipboard()->mimeData()->data( mimeType );
}

QgsFields QgsClipboard::fields() const
{
if ( !mUseSystemClipboard )
return mFeatureFields;
else
return retrieveFields();
}

void QgsClipboard::systemClipboardChanged()
{
if ( mIgnoreNextSystemClipboardChange )
{
mIgnoreNextSystemClipboardChange = false;
return;
}

mUseSystemClipboard = true;
emit changed();
}
5 changes: 4 additions & 1 deletion src/app/qgsclipboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class APP_EXPORT QgsClipboard : public QObject
/**
* Source fields
*/
QgsFields fields() const { return !mUseSystemClipboard ? mFeatureFields : retrieveFields(); }
QgsFields fields() const;

private slots:

Expand Down Expand Up @@ -180,6 +180,9 @@ class APP_EXPORT QgsClipboard : public QObject
QgsCoordinateReferenceSystem mCRS;
QPointer<QgsVectorLayer> mSrcLayer;

//! True if next system clipboard change should be ignored
bool mIgnoreNextSystemClipboardChange = false;

//! True when the data from the system clipboard should be read
bool mUseSystemClipboard = false;

Expand Down

0 comments on commit 7febd1e

Please sign in to comment.