Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE] option to avoid WKT copying from attribute table (fix 4591)
  • Loading branch information
alexbruy committed Mar 24, 2012
1 parent 54769b3 commit 0ee3769
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 46 deletions.
32 changes: 14 additions & 18 deletions src/app/qgsclipboard.cpp
Expand Up @@ -15,7 +15,6 @@
* *
***************************************************************************/


#include <fstream>

#include <QApplication>
Expand All @@ -31,7 +30,6 @@
#include "qgscoordinatereferencesystem.h"
#include "qgslogger.h"


QgsClipboard::QgsClipboard()
: mFeatureClipboard()
{
Expand All @@ -43,44 +41,47 @@ QgsClipboard::~QgsClipboard()

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

// Replace the QGis clipboard.
mFeatureClipboard = features;
QgsDebugMsg( "replaced QGis clipboard." );

// Replace the system clipboard.

QStringList textLines;
QStringList textFields;

// first do the field names
textFields += "wkt_geom";
if ( copyWKT )
{
textFields += "wkt_geom";
}

for ( QgsFieldMap::const_iterator fit = fields.begin(); fit != fields.end(); ++fit )
{
textFields += fit->name();
}
textLines += textFields.join( "\t" );
textFields.clear();


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


// TODO: Set up Paste Transformations to specify the order in which fields are added.

if ( it->geometry() )
textFields += it->geometry()->exportToWkt();
else
if ( copyWKT )
{
QSettings settings;
textFields += settings.value( "qgis/nullValue", "NULL" ).toString();
if ( it->geometry() )
textFields += it->geometry()->exportToWkt();
else
{
textFields += settings.value( "qgis/nullValue", "NULL" ).toString();
}
}

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

QgsFeatureList QgsClipboard::copyOf()
{

QgsDebugMsg( "returning clipboard." );

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

return mFeatureClipboard;

// return mFeatureClipboard;

}

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

QgsFeatureList QgsClipboard::transformedCopyOf( QgsCoordinateReferenceSystem destCRS )
{

QgsFeatureList featureList = copyOf();
QgsCoordinateTransform ct( crs(), destCRS );

Expand Down
12 changes: 0 additions & 12 deletions src/app/qgsclipboard.h
Expand Up @@ -15,7 +15,6 @@
* *
***************************************************************************/


#ifndef QGSCLIPBOARD_H
#define QGSCLIPBOARD_H

Expand All @@ -26,9 +25,7 @@
#include "qgsfeature.h"
#include "qgscoordinatereferencesystem.h"


/**
\brief QGIS internal clipboard for features.
An internal clipboard is required so that features can be retained in
Expand All @@ -42,16 +39,11 @@
of features in and out of the system clipboard (QClipboard).
TODO: Make it work
*/

class QgsClipboard
{


public:


/**
* Constructor for the clipboard.
*/
Expand Down Expand Up @@ -83,7 +75,6 @@ class QgsClipboard
*/
void insert( QgsFeature& feature );


/*
* Returns true if the internal clipboard is empty, else false.
*/
Expand All @@ -102,7 +93,6 @@ class QgsClipboard
*/
void setCRS( QgsCoordinateReferenceSystem crs );


/*
* Get the clipboard CRS
*/
Expand All @@ -117,8 +107,6 @@ class QgsClipboard
QgsFeatureList mFeatureClipboard;

QgsCoordinateReferenceSystem mCRS;


};

#endif
2 changes: 2 additions & 0 deletions src/app/qgsoptions.cpp
Expand Up @@ -316,6 +316,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
cbxAddPostgisDC->setChecked( settings.value( "/qgis/addPostgisDC", false ).toBool() );
cbxAddNewLayersToCurrentGroup->setChecked( settings.value( "/qgis/addNewLayersToCurrentGroup", false ).toBool() );
cbxCreateRasterLegendIcons->setChecked( settings.value( "/qgis/createRasterLegendIcons", true ).toBool() );
cbxCopyWKTGeomFromTable->setChecked( settings.value( "/qgis/copyGeometryAsWKT", true ).toBool() );
leNullValue->setText( settings.value( "qgis/nullValue", "NULL" ).toString() );

cmbLegendDoubleClickAction->setCurrentIndex( settings.value( "/qgis/legendDoubleClickAction", 0 ).toInt() );
Expand Down Expand Up @@ -626,6 +627,7 @@ void QgsOptions::saveOptions()
settings.setValue( "/qgis/addPostgisDC", cbxAddPostgisDC->isChecked() );
settings.setValue( "/qgis/addNewLayersToCurrentGroup", cbxAddNewLayersToCurrentGroup->isChecked() );
settings.setValue( "/qgis/createRasterLegendIcons", cbxCreateRasterLegendIcons->isChecked() );
settings.setValue( "/qgis/copyGeometryAsWKT", cbxCopyWKTGeomFromTable->isChecked() );
settings.setValue( "/qgis/new_layers_visible", chkAddedVisibility->isChecked() );
settings.setValue( "/qgis/enable_anti_aliasing", chkAntiAliasing->isChecked() );
settings.setValue( "/qgis/enable_render_caching", chkUseRenderCaching->isChecked() );
Expand Down
39 changes: 23 additions & 16 deletions src/ui/qgsoptionsbase.ui
Expand Up @@ -66,8 +66,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>809</width>
<height>778</height>
<width>787</width>
<height>823</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
Expand Down Expand Up @@ -438,6 +438,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbxCopyWKTGeomFromTable">
<property name="text">
<string>Copy geometry in WKT representation from attribute table</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
Expand Down Expand Up @@ -726,8 +733,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>809</width>
<height>778</height>
<width>614</width>
<height>523</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_8">
Expand Down Expand Up @@ -900,8 +907,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>809</width>
<height>778</height>
<width>539</width>
<height>502</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_4">
Expand Down Expand Up @@ -1186,8 +1193,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>809</width>
<height>778</height>
<width>270</width>
<height>93</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_10">
Expand Down Expand Up @@ -1261,8 +1268,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>795</width>
<height>764</height>
<width>571</width>
<height>620</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_13">
Expand Down Expand Up @@ -1637,8 +1644,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>809</width>
<height>778</height>
<width>425</width>
<height>417</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_15">
Expand Down Expand Up @@ -1811,8 +1818,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>809</width>
<height>778</height>
<width>519</width>
<height>584</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_17">
Expand Down Expand Up @@ -1908,8 +1915,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>809</width>
<height>778</height>
<width>355</width>
<height>572</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_20">
Expand Down

0 comments on commit 0ee3769

Please sign in to comment.