Skip to content

Commit 0ee3769

Browse files
committed
[FEATURE] option to avoid WKT copying from attribute table (fix 4591)
1 parent 54769b3 commit 0ee3769

File tree

4 files changed

+39
-46
lines changed

4 files changed

+39
-46
lines changed

src/app/qgsclipboard.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
* *
1616
***************************************************************************/
1717

18-
1918
#include <fstream>
2019

2120
#include <QApplication>
@@ -31,7 +30,6 @@
3130
#include "qgscoordinatereferencesystem.h"
3231
#include "qgslogger.h"
3332

34-
3533
QgsClipboard::QgsClipboard()
3634
: mFeatureClipboard()
3735
{
@@ -43,44 +41,47 @@ QgsClipboard::~QgsClipboard()
4341

4442
void QgsClipboard::replaceWithCopyOf( const QgsFieldMap& fields, QgsFeatureList& features )
4543
{
44+
QSettings settings;
45+
bool copyWKT = settings.value( "qgis/copyGeometryAsWKT", true ).toBool();
4646

4747
// Replace the QGis clipboard.
4848
mFeatureClipboard = features;
4949
QgsDebugMsg( "replaced QGis clipboard." );
5050

5151
// Replace the system clipboard.
52-
5352
QStringList textLines;
5453
QStringList textFields;
5554

5655
// first do the field names
57-
textFields += "wkt_geom";
56+
if ( copyWKT )
57+
{
58+
textFields += "wkt_geom";
59+
}
60+
5861
for ( QgsFieldMap::const_iterator fit = fields.begin(); fit != fields.end(); ++fit )
5962
{
6063
textFields += fit->name();
6164
}
6265
textLines += textFields.join( "\t" );
6366
textFields.clear();
6467

65-
6668
// then the field contents
6769
for ( QgsFeatureList::iterator it = features.begin(); it != features.end(); ++it )
6870
{
6971
QgsAttributeMap attributes = it->attributeMap();
7072

71-
7273
// TODO: Set up Paste Transformations to specify the order in which fields are added.
73-
74-
if ( it->geometry() )
75-
textFields += it->geometry()->exportToWkt();
76-
else
74+
if ( copyWKT )
7775
{
78-
QSettings settings;
79-
textFields += settings.value( "qgis/nullValue", "NULL" ).toString();
76+
if ( it->geometry() )
77+
textFields += it->geometry()->exportToWkt();
78+
else
79+
{
80+
textFields += settings.value( "qgis/nullValue", "NULL" ).toString();
81+
}
8082
}
8183

8284
// QgsDebugMsg("about to traverse fields.");
83-
//
8485
for ( QgsAttributeMap::iterator it2 = attributes.begin(); it2 != attributes.end(); ++it2 )
8586
{
8687
// QgsDebugMsg(QString("inspecting field '%1'.").arg(it2->toString()));
@@ -113,15 +114,11 @@ void QgsClipboard::replaceWithCopyOf( const QgsFieldMap& fields, QgsFeatureList&
113114

114115
QgsFeatureList QgsClipboard::copyOf()
115116
{
116-
117117
QgsDebugMsg( "returning clipboard." );
118118

119119
//TODO: Slurp from the system clipboard as well.
120120

121121
return mFeatureClipboard;
122-
123-
// return mFeatureClipboard;
124-
125122
}
126123

127124
void QgsClipboard::clear()
@@ -145,7 +142,6 @@ bool QgsClipboard::empty()
145142

146143
QgsFeatureList QgsClipboard::transformedCopyOf( QgsCoordinateReferenceSystem destCRS )
147144
{
148-
149145
QgsFeatureList featureList = copyOf();
150146
QgsCoordinateTransform ct( crs(), destCRS );
151147

src/app/qgsclipboard.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
* *
1616
***************************************************************************/
1717

18-
1918
#ifndef QGSCLIPBOARD_H
2019
#define QGSCLIPBOARD_H
2120

@@ -26,9 +25,7 @@
2625
#include "qgsfeature.h"
2726
#include "qgscoordinatereferencesystem.h"
2827

29-
3028
/**
31-
3229
\brief QGIS internal clipboard for features.
3330
3431
An internal clipboard is required so that features can be retained in
@@ -42,16 +39,11 @@
4239
of features in and out of the system clipboard (QClipboard).
4340
4441
TODO: Make it work
45-
4642
*/
4743

4844
class QgsClipboard
4945
{
50-
51-
5246
public:
53-
54-
5547
/**
5648
* Constructor for the clipboard.
5749
*/
@@ -83,7 +75,6 @@ class QgsClipboard
8375
*/
8476
void insert( QgsFeature& feature );
8577

86-
8778
/*
8879
* Returns true if the internal clipboard is empty, else false.
8980
*/
@@ -102,7 +93,6 @@ class QgsClipboard
10293
*/
10394
void setCRS( QgsCoordinateReferenceSystem crs );
10495

105-
10696
/*
10797
* Get the clipboard CRS
10898
*/
@@ -117,8 +107,6 @@ class QgsClipboard
117107
QgsFeatureList mFeatureClipboard;
118108

119109
QgsCoordinateReferenceSystem mCRS;
120-
121-
122110
};
123111

124112
#endif

src/app/qgsoptions.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
316316
cbxAddPostgisDC->setChecked( settings.value( "/qgis/addPostgisDC", false ).toBool() );
317317
cbxAddNewLayersToCurrentGroup->setChecked( settings.value( "/qgis/addNewLayersToCurrentGroup", false ).toBool() );
318318
cbxCreateRasterLegendIcons->setChecked( settings.value( "/qgis/createRasterLegendIcons", true ).toBool() );
319+
cbxCopyWKTGeomFromTable->setChecked( settings.value( "/qgis/copyGeometryAsWKT", true ).toBool() );
319320
leNullValue->setText( settings.value( "qgis/nullValue", "NULL" ).toString() );
320321

321322
cmbLegendDoubleClickAction->setCurrentIndex( settings.value( "/qgis/legendDoubleClickAction", 0 ).toInt() );
@@ -626,6 +627,7 @@ void QgsOptions::saveOptions()
626627
settings.setValue( "/qgis/addPostgisDC", cbxAddPostgisDC->isChecked() );
627628
settings.setValue( "/qgis/addNewLayersToCurrentGroup", cbxAddNewLayersToCurrentGroup->isChecked() );
628629
settings.setValue( "/qgis/createRasterLegendIcons", cbxCreateRasterLegendIcons->isChecked() );
630+
settings.setValue( "/qgis/copyGeometryAsWKT", cbxCopyWKTGeomFromTable->isChecked() );
629631
settings.setValue( "/qgis/new_layers_visible", chkAddedVisibility->isChecked() );
630632
settings.setValue( "/qgis/enable_anti_aliasing", chkAntiAliasing->isChecked() );
631633
settings.setValue( "/qgis/enable_render_caching", chkUseRenderCaching->isChecked() );

src/ui/qgsoptionsbase.ui

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
<rect>
6767
<x>0</x>
6868
<y>0</y>
69-
<width>809</width>
70-
<height>778</height>
69+
<width>787</width>
70+
<height>823</height>
7171
</rect>
7272
</property>
7373
<layout class="QGridLayout" name="gridLayout">
@@ -438,6 +438,13 @@
438438
</property>
439439
</widget>
440440
</item>
441+
<item>
442+
<widget class="QCheckBox" name="cbxCopyWKTGeomFromTable">
443+
<property name="text">
444+
<string>Copy geometry in WKT representation from attribute table</string>
445+
</property>
446+
</widget>
447+
</item>
441448
<item>
442449
<layout class="QHBoxLayout" name="horizontalLayout_5">
443450
<item>
@@ -726,8 +733,8 @@
726733
<rect>
727734
<x>0</x>
728735
<y>0</y>
729-
<width>809</width>
730-
<height>778</height>
736+
<width>614</width>
737+
<height>523</height>
731738
</rect>
732739
</property>
733740
<layout class="QGridLayout" name="gridLayout_8">
@@ -900,8 +907,8 @@
900907
<rect>
901908
<x>0</x>
902909
<y>0</y>
903-
<width>809</width>
904-
<height>778</height>
910+
<width>539</width>
911+
<height>502</height>
905912
</rect>
906913
</property>
907914
<layout class="QGridLayout" name="gridLayout_4">
@@ -1186,8 +1193,8 @@
11861193
<rect>
11871194
<x>0</x>
11881195
<y>0</y>
1189-
<width>809</width>
1190-
<height>778</height>
1196+
<width>270</width>
1197+
<height>93</height>
11911198
</rect>
11921199
</property>
11931200
<layout class="QGridLayout" name="gridLayout_10">
@@ -1261,8 +1268,8 @@
12611268
<rect>
12621269
<x>0</x>
12631270
<y>0</y>
1264-
<width>795</width>
1265-
<height>764</height>
1271+
<width>571</width>
1272+
<height>620</height>
12661273
</rect>
12671274
</property>
12681275
<layout class="QGridLayout" name="gridLayout_13">
@@ -1637,8 +1644,8 @@
16371644
<rect>
16381645
<x>0</x>
16391646
<y>0</y>
1640-
<width>809</width>
1641-
<height>778</height>
1647+
<width>425</width>
1648+
<height>417</height>
16421649
</rect>
16431650
</property>
16441651
<layout class="QGridLayout" name="gridLayout_15">
@@ -1811,8 +1818,8 @@
18111818
<rect>
18121819
<x>0</x>
18131820
<y>0</y>
1814-
<width>809</width>
1815-
<height>778</height>
1821+
<width>519</width>
1822+
<height>584</height>
18161823
</rect>
18171824
</property>
18181825
<layout class="QGridLayout" name="gridLayout_17">
@@ -1908,8 +1915,8 @@
19081915
<rect>
19091916
<x>0</x>
19101917
<y>0</y>
1911-
<width>809</width>
1912-
<height>778</height>
1918+
<width>355</width>
1919+
<height>572</height>
19131920
</rect>
19141921
</property>
19151922
<layout class="QGridLayout" name="gridLayout_20">

0 commit comments

Comments
 (0)