1
/***************************************************************************
2
qgsclipboard.cpp - QGIS internal clipboard for storage of features
3
--------------------------------------------------------------------
5
copyright : (C) 2005 by Brendan Morley
6
email : morb at ozemail dot com dot au
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
***************************************************************************/
22
#include <QApplication>
24
#include <QStringList>
27
#include "qgsclipboard.h"
28
#include "qgsfeature.h"
30
#include "qgsgeometry.h"
31
#include "qgscoordinatereferencesystem.h"
32
#include "qgslogger.h"
33
#include "qgslogger.h"
36
QgsClipboard::QgsClipboard()
41
QgsClipboard::~QgsClipboard()
45
void QgsClipboard::replaceWithCopyOf( const QgsFieldMap& fields, QgsFeatureList& features )
48
// Replace the QGis clipboard.
49
mFeatureClipboard = features;
50
QgsDebugMsg( "replaced QGis clipboard." );
52
// Replace the system clipboard.
54
QStringList textLines;
55
QStringList textFields;
57
// first do the field names
58
textFields += "wkt_geom";
59
for ( QgsFieldMap::const_iterator fit = fields.begin(); fit != fields.end(); ++fit )
61
textFields += fit->name();
63
textLines += textFields.join( "\t" );
67
// then the field contents
68
for ( QgsFeatureList::iterator it = features.begin(); it != features.end(); ++it )
70
QgsAttributeMap attributes = it->attributeMap();
73
// TODO: Set up Paste Transformations to specify the order in which fields are added.
76
textFields += it->geometry()->exportToWkt();
80
// QgsDebugMsg("about to traverse fields.");
82
for ( QgsAttributeMap::iterator it2 = attributes.begin(); it2 != attributes.end(); ++it2 )
84
// QgsDebugMsg(QString("inspecting field '%1'.").arg(it2->toString()));
85
textFields += it2->toString();
88
textLines += textFields.join( "\t" );
92
QString textCopy = textLines.join( "\n" );
94
QClipboard *cb = QApplication::clipboard();
96
// Copy text into the clipboard
98
// With qgis running under Linux, but with a Windows based X
99
// server (Xwin32), ::Selection was necessary to get the data into
100
// the Windows clipboard (which seems contrary to the Qt
101
// docs). With a Linux X server, ::Clipboard was required.
102
// The simple solution was to put the text into both clipboards.
104
// The ::Selection setText() below one may need placing inside so
105
// #ifdef so that it doesn't get compiled under Windows.
106
cb->setText( textCopy, QClipboard::Selection );
107
cb->setText( textCopy, QClipboard::Clipboard );
109
QgsDebugMsg( QString( "replaced system clipboard with: %1." ).arg( textCopy ) );
112
QgsFeatureList QgsClipboard::copyOf()
115
QgsDebugMsg( "returning clipboard." );
117
//TODO: Slurp from the system clipboard as well.
119
return mFeatureClipboard;
121
// return mFeatureClipboard;
125
void QgsClipboard::clear()
127
mFeatureClipboard.clear();
129
QgsDebugMsg( "cleared clipboard." );
132
void QgsClipboard::insert( QgsFeature& feature )
134
mFeatureClipboard.push_back( feature );
136
QgsDebugMsg( "inserted " + feature.geometry()->exportToWkt() );
139
bool QgsClipboard::empty()
141
return mFeatureClipboard.empty();
144
QgsFeatureList QgsClipboard::transformedCopyOf( QgsCoordinateReferenceSystem destCRS )
147
QgsFeatureList featureList = copyOf();
148
QgsCoordinateTransform ct( crs(), destCRS );
150
QgsDebugMsg( "transforming clipboard." );
151
for ( QgsFeatureList::iterator iter = featureList.begin(); iter != featureList.end(); ++iter )
153
iter->geometry()->transform( ct );
159
void QgsClipboard::setCRS( QgsCoordinateReferenceSystem crs )
164
QgsCoordinateReferenceSystem QgsClipboard::crs()