~ubuntu-branches/ubuntu/trusty/qgis/trusty

« back to all changes in this revision

Viewing changes to src/app/qgsclipboard.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
     qgsclipboard.cpp  -  QGIS internal clipboard for storage of features
 
3
     --------------------------------------------------------------------
 
4
    begin                : 20 May, 2005
 
5
    copyright            : (C) 2005 by Brendan Morley
 
6
    email                : morb at ozemail dot com dot au
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
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.                                   *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
 
 
18
/* $Id$ */
 
19
 
 
20
#include <fstream>
 
21
 
 
22
#include <QApplication>
 
23
#include <QString>
 
24
#include <QStringList>
 
25
#include <QClipboard>
 
26
 
 
27
#include "qgsclipboard.h"
 
28
#include "qgsfeature.h"
 
29
#include "qgsfield.h"
 
30
#include "qgsgeometry.h"
 
31
#include "qgscoordinatereferencesystem.h"
 
32
#include "qgslogger.h"
 
33
#include "qgslogger.h"
 
34
 
 
35
 
 
36
QgsClipboard::QgsClipboard()
 
37
    : mFeatureClipboard()
 
38
{
 
39
}
 
40
 
 
41
QgsClipboard::~QgsClipboard()
 
42
{
 
43
}
 
44
 
 
45
void QgsClipboard::replaceWithCopyOf( const QgsFieldMap& fields, QgsFeatureList& features )
 
46
{
 
47
 
 
48
  // Replace the QGis clipboard.
 
49
  mFeatureClipboard = features;
 
50
  QgsDebugMsg( "replaced QGis clipboard." );
 
51
 
 
52
  // Replace the system clipboard.
 
53
 
 
54
  QStringList textLines;
 
55
  QStringList textFields;
 
56
 
 
57
  // first do the field names
 
58
  textFields += "wkt_geom";
 
59
  for ( QgsFieldMap::const_iterator fit = fields.begin(); fit != fields.end(); ++fit )
 
60
  {
 
61
    textFields += fit->name();
 
62
  }
 
63
  textLines += textFields.join( "\t" );
 
64
  textFields.clear();
 
65
 
 
66
 
 
67
  // then the field contents
 
68
  for ( QgsFeatureList::iterator it = features.begin(); it != features.end(); ++it )
 
69
  {
 
70
    QgsAttributeMap attributes = it->attributeMap();
 
71
 
 
72
 
 
73
    // TODO: Set up Paste Transformations to specify the order in which fields are added.
 
74
 
 
75
    if ( it->geometry() )
 
76
      textFields += it->geometry()->exportToWkt();
 
77
    else
 
78
      textFields += "NULL";
 
79
 
 
80
    // QgsDebugMsg("about to traverse fields.");
 
81
    //
 
82
    for ( QgsAttributeMap::iterator it2 = attributes.begin(); it2 != attributes.end(); ++it2 )
 
83
    {
 
84
      // QgsDebugMsg(QString("inspecting field '%1'.").arg(it2->toString()));
 
85
      textFields += it2->toString();
 
86
    }
 
87
 
 
88
    textLines += textFields.join( "\t" );
 
89
    textFields.clear();
 
90
  }
 
91
 
 
92
  QString textCopy = textLines.join( "\n" );
 
93
 
 
94
  QClipboard *cb = QApplication::clipboard();
 
95
 
 
96
  // Copy text into the clipboard
 
97
 
 
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.
 
103
 
 
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 );
 
108
 
 
109
  QgsDebugMsg( QString( "replaced system clipboard with: %1." ).arg( textCopy ) );
 
110
}
 
111
 
 
112
QgsFeatureList QgsClipboard::copyOf()
 
113
{
 
114
 
 
115
  QgsDebugMsg( "returning clipboard." );
 
116
 
 
117
  //TODO: Slurp from the system clipboard as well.
 
118
 
 
119
  return mFeatureClipboard;
 
120
 
 
121
//  return mFeatureClipboard;
 
122
 
 
123
}
 
124
 
 
125
void QgsClipboard::clear()
 
126
{
 
127
  mFeatureClipboard.clear();
 
128
 
 
129
  QgsDebugMsg( "cleared clipboard." );
 
130
}
 
131
 
 
132
void QgsClipboard::insert( QgsFeature& feature )
 
133
{
 
134
  mFeatureClipboard.push_back( feature );
 
135
 
 
136
  QgsDebugMsg( "inserted " + feature.geometry()->exportToWkt() );
 
137
}
 
138
 
 
139
bool QgsClipboard::empty()
 
140
{
 
141
  return mFeatureClipboard.empty();
 
142
}
 
143
 
 
144
QgsFeatureList QgsClipboard::transformedCopyOf( QgsCoordinateReferenceSystem destCRS )
 
145
{
 
146
 
 
147
  QgsFeatureList featureList = copyOf();
 
148
  QgsCoordinateTransform ct( crs(), destCRS );
 
149
 
 
150
  QgsDebugMsg( "transforming clipboard." );
 
151
  for ( QgsFeatureList::iterator iter = featureList.begin(); iter != featureList.end(); ++iter )
 
152
  {
 
153
    iter->geometry()->transform( ct );
 
154
  }
 
155
 
 
156
  return featureList;
 
157
}
 
158
 
 
159
void QgsClipboard::setCRS( QgsCoordinateReferenceSystem crs )
 
160
{
 
161
  mCRS = crs;
 
162
}
 
163
 
 
164
QgsCoordinateReferenceSystem QgsClipboard::crs()
 
165
{
 
166
  return mCRS;
 
167
}