00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <fstream>
00021
00022 #include <QApplication>
00023 #include <QString>
00024 #include <QStringList>
00025 #include <QClipboard>
00026
00027 #include "qgsclipboard.h"
00028 #include "qgsfeature.h"
00029 #include "qgsfield.h"
00030 #include "qgsgeometry.h"
00031 #include "qgslogger.h"
00032 #include "qgslogger.h"
00033
00034
00035 QgsClipboard::QgsClipboard()
00036 : mFeatureClipboard()
00037 {
00038 }
00039
00040 QgsClipboard::~QgsClipboard()
00041 {
00042 }
00043
00044 void QgsClipboard::replaceWithCopyOf( const QgsFieldMap& fields, QgsFeatureList& features )
00045 {
00046
00047
00048 mFeatureClipboard = features;
00049 QgsDebugMsg( "replaced QGis clipboard." );
00050
00051
00052
00053 QStringList textLines;
00054 QStringList textFields;
00055
00056
00057 textFields += "wkt_geom";
00058 for ( QgsFieldMap::const_iterator fit = fields.begin(); fit != fields.end(); ++fit )
00059 {
00060 textFields += fit->name();
00061 }
00062 textLines += textFields.join( "\t" );
00063 textFields.clear();
00064
00065
00066
00067 for ( QgsFeatureList::iterator it = features.begin(); it != features.end(); ++it )
00068 {
00069 QgsAttributeMap attributes = it->attributeMap();
00070
00071
00072
00073
00074 if ( it->geometry() )
00075 textFields += it->geometry()->exportToWkt();
00076 else
00077 textFields += "NULL";
00078
00079
00080
00081 for ( QgsAttributeMap::iterator it2 = attributes.begin(); it2 != attributes.end(); ++it2 )
00082 {
00083
00084 textFields += it2->toString();
00085 }
00086
00087 textLines += textFields.join( "\t" );
00088 textFields.clear();
00089 }
00090
00091 QString textCopy = textLines.join( "\n" );
00092
00093 QClipboard *cb = QApplication::clipboard();
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 cb->setText( textCopy, QClipboard::Selection );
00106 cb->setText( textCopy, QClipboard::Clipboard );
00107
00108 QgsDebugMsg( QString( "replaced system clipboard with: %1." ).arg( textCopy ) );
00109 }
00110
00111 QgsFeatureList QgsClipboard::copyOf()
00112 {
00113
00114 QgsDebugMsg( "returning clipboard." );
00115
00116
00117
00118 return mFeatureClipboard;
00119
00120
00121
00122 }
00123
00124 void QgsClipboard::clear()
00125 {
00126 mFeatureClipboard.clear();
00127
00128 QgsDebugMsg( "cleared clipboard." );
00129 }
00130
00131 void QgsClipboard::insert( QgsFeature& feature )
00132 {
00133 mFeatureClipboard.push_back( feature );
00134
00135 QgsDebugMsg( "inserted " + feature.geometry()->exportToWkt() );
00136 }
00137
00138 bool QgsClipboard::empty()
00139 {
00140 return mFeatureClipboard.empty();
00141 }