Skip to content

Commit 1a25348

Browse files
author
morb_au
committedJul 11, 2006
In the Attributes Table, the Copy button is now hooked up to the same editCopy() procedure that the main application uses. The copySelectedRowsToClipboard() procedure that was used in QgsAttributeTableDisplay is no longer referenced.
As part of this "merge", the main application copy will now precede its results with a row of attribute headers. Also, the editCopy() procedure and friends (editCut() and editPaste()) can now take the layer to act on, thus allowing the Attribute Table to work on a different layer to the Current Layer in the Legend. This change was done so that the Copy button in the main application AND the Copy button on the attribute table works consistently. git-svn-id: http://svn.osgeo.org/qgis/trunk@5584 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent af33fb9 commit 1a25348

File tree

8 files changed

+128
-63
lines changed

8 files changed

+128
-63
lines changed
 

‎src/gui/qgisapp.cpp

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3211,7 +3211,7 @@ void QgisApp::attributeTable()
32113211
QgsMapLayer *layer = mMapLegend->currentLayer();
32123212
if (layer)
32133213
{
3214-
layer->table();
3214+
layer->table(this);
32153215
}
32163216
else
32173217
{
@@ -3322,63 +3322,62 @@ void QgisApp::deleteVertex()
33223322
}
33233323

33243324

3325-
void QgisApp::editCut()
3325+
void QgisApp::editCut(QgsMapLayer * layerContainingSelection)
33263326
{
3327-
if (activeLayer())
3327+
QgsMapLayer * selectionLayer = (layerContainingSelection != 0) ?
3328+
(layerContainingSelection) :
3329+
(activeLayer());
3330+
3331+
if (selectionLayer)
33283332
{
33293333
// Test for feature support in this layer
3330-
QgsVectorLayer* activeVectorLayer = dynamic_cast<QgsVectorLayer*>(activeLayer());
3334+
QgsVectorLayer* selectionVectorLayer = dynamic_cast<QgsVectorLayer*>(selectionLayer);
33313335

3332-
if (activeVectorLayer != 0)
3336+
if (selectionVectorLayer != 0)
33333337
{
3334-
3335-
clipboard()->replaceWithCopyOf( *(activeVectorLayer->selectedFeatures()) );
3336-
activeVectorLayer->deleteSelectedFeatures();
3337-
}
3338-
}
3338+
clipboard()->replaceWithCopyOf( *(selectionVectorLayer->selectedFeatures()) );
3339+
selectionVectorLayer->deleteSelectedFeatures();
3340+
}
3341+
}
33393342
}
33403343

33413344

3342-
void QgisApp::editCopy()
3345+
void QgisApp::editCopy(QgsMapLayer * layerContainingSelection)
33433346
{
3344-
#ifdef QGISDEBUG
3345-
std::cerr << "QgisApp::editCopy: entered."
3346-
<< std::endl;
3347-
#endif
3348-
if (activeLayer())
3347+
QgsMapLayer * selectionLayer = (layerContainingSelection != 0) ?
3348+
(layerContainingSelection) :
3349+
(activeLayer());
3350+
3351+
if (selectionLayer)
33493352
{
3350-
#ifdef QGISDEBUG
3351-
std::cerr << "QgisApp::editCopy: has active layer, feature type " << activeLayer()->featureType() << "."
3352-
<< std::endl;
3353-
#endif
33543353
// Test for feature support in this layer
3355-
QgsVectorLayer* activeVectorLayer = dynamic_cast<QgsVectorLayer*>(activeLayer());
3354+
QgsVectorLayer* selectionVectorLayer = dynamic_cast<QgsVectorLayer*>(selectionLayer);
33563355

3357-
if (activeVectorLayer != 0)
3356+
if (selectionVectorLayer != 0)
33583357
{
3359-
#ifdef QGISDEBUG
3360-
std::cerr << "QgisApp::editCopy: has active vector layer."
3361-
<< std::endl;
3362-
#endif
3363-
clipboard()->replaceWithCopyOf( *(activeVectorLayer->selectedFeatures()) );
3364-
}
3365-
}
3358+
clipboard()->replaceWithCopyOf( *(selectionVectorLayer->selectedFeatures()) );
3359+
}
3360+
}
33663361
}
33673362

33683363

3369-
void QgisApp::editPaste()
3364+
void QgisApp::editPaste(QgsMapLayer * destinationLayer)
33703365
{
3371-
if (activeLayer())
3366+
QgsMapLayer * pasteLayer = (destinationLayer != 0) ?
3367+
(destinationLayer) :
3368+
(activeLayer());
3369+
3370+
if (pasteLayer)
33723371
{
33733372
// Test for feature support in this layer
3374-
QgsVectorLayer* activeVectorLayer = dynamic_cast<QgsVectorLayer*>(activeLayer());
3373+
QgsVectorLayer* pasteVectorLayer = dynamic_cast<QgsVectorLayer*>(pasteLayer);
33753374

3376-
if (activeVectorLayer != 0)
3375+
if (pasteVectorLayer != 0)
33773376
{
3378-
activeVectorLayer->addFeatures( clipboard()->copyOf() );
3377+
pasteVectorLayer->addFeatures( clipboard()->copyOf() );
33793378
mMapCanvas->refresh();
3380-
}
3381-
}
3379+
}
3380+
}
33823381
}
33833382

33843383

‎src/gui/qgisapp.h

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,7 @@ public slots:
294294
void moveVertex();
295295
//! activates the delete vertex tool
296296
void deleteVertex();
297-
//! cuts selected features on the active layer to the clipboard
298-
void editCut();
299-
//! copies selected features on the active layer to the clipboard
300-
void editCopy();
301-
//! copies features on the clipboard to the active layer
302-
void editPaste();
297+
303298
//! activates the selection tool
304299
void select();
305300
//! refresh map canvas
@@ -346,6 +341,26 @@ public slots:
346341
//! show the attribute table for the currently selected layer
347342
void attributeTable();
348343

344+
//! cuts selected features on the active layer to the clipboard
345+
/**
346+
\param layerContainingSelection The layer that the selection will be taken from
347+
(defaults to the active layer on the legend)
348+
*/
349+
void editCut(QgsMapLayer * layerContainingSelection = 0);
350+
//! copies selected features on the active layer to the clipboard
351+
/**
352+
\param layerContainingSelection The layer that the selection will be taken from
353+
(defaults to the active layer on the legend)
354+
*/
355+
void editCopy(QgsMapLayer * layerContainingSelection = 0);
356+
//! copies features on the clipboard to the active layer
357+
/**
358+
\param destinationLayer The layer that the clipboard will be pasted to
359+
(defaults to the active layer on the legend)
360+
*/
361+
void editPaste(QgsMapLayer * destinationLayer = 0);
362+
363+
349364
signals:
350365
/** emitted when a key is pressed and we want non widget sublasses to be able
351366
to pick up on this (e.g. maplayer) */

‎src/gui/qgsattributetabledisplay.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "qgsattributetabledisplay.h"
2121

22+
#include "qgisapp.h"
2223
#include "qgsapplication.h"
2324
#include "qgsaddattrdialog.h"
2425
#include "qgsdelattrdialog.h"
@@ -33,8 +34,10 @@
3334
#include <QPixmap>
3435
#include <QToolButton>
3536

36-
QgsAttributeTableDisplay::QgsAttributeTableDisplay(QgsVectorLayer* layer)
37-
: QDialog(), mLayer(layer)
37+
QgsAttributeTableDisplay::QgsAttributeTableDisplay(QgsVectorLayer* layer, QgisApp * qgisApp)
38+
: QDialog(),
39+
mLayer(layer),
40+
mQgisApp(qgisApp)
3841
{
3942
setupUi(this);
4043
setTheme();
@@ -225,7 +228,11 @@ void QgsAttributeTableDisplay::removeSelection()
225228

226229
void QgsAttributeTableDisplay::copySelectedRowsToClipboard()
227230
{
228-
table()->copySelectedRows();
231+
// Deprecated
232+
// table()->copySelectedRows();
233+
234+
// Use the Application's copy method instead
235+
mQgisApp->editCopy(mLayer);
229236
}
230237

231238
void QgsAttributeTableDisplay::search()

‎src/gui/qgsattributetabledisplay.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
class QgsAttributeTable;
2727
class QgsVectorLayer;
28+
class QgisApp;
2829

2930
/**
3031
*@author Gary E.Sherman
@@ -34,13 +35,21 @@ class QgsAttributeTableDisplay:public QDialog, private Ui::QgsAttributeTableBase
3435
{
3536
Q_OBJECT
3637
public:
37-
QgsAttributeTableDisplay(QgsVectorLayer* layer);
38+
/**
39+
\param qgisApp This should be the QgisApp that spawned this table.
40+
Otherwise the Copy button on this QgsAttributeTableDisplay
41+
will not work.
42+
*/
43+
QgsAttributeTableDisplay(QgsVectorLayer* layer, QgisApp * qgisApp);
3844
~QgsAttributeTableDisplay();
45+
3946
QgsAttributeTable *table();
4047
void setTitle(QString title);
4148
protected:
4249
QgsVectorLayer* mLayer;
43-
50+
51+
QgisApp * mQgisApp;
52+
4453
void doSearch(const QString& searchString);
4554

4655
virtual void closeEvent(QCloseEvent* ev);

‎src/gui/qgsclipboard.cpp

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,44 +48,75 @@ void QgsClipboard::replaceWithCopyOf( std::vector<QgsFeature> features )
4848
#endif
4949

5050
// Replace the system clipboard.
51-
51+
5252
QStringList textLines;
53-
53+
QStringList textFields;
54+
bool firstFeature = TRUE;
55+
56+
// then the field contents
5457
for (std::vector<QgsFeature>::iterator it = features.begin();
5558
it != features.end();
5659
++it)
5760
{
58-
QStringList textFields;
61+
std::vector<QgsFeatureAttribute> attributes = it->attributeMap();
62+
63+
// first do the field names
64+
if (firstFeature)
65+
{
66+
textFields += "wkt_geom";
67+
68+
for (std::vector<QgsFeatureAttribute>::iterator it2 = attributes.begin();
69+
it2 != attributes.end();
70+
++it2)
71+
{
72+
textFields += it2->fieldName();
73+
}
74+
75+
textLines += textFields.join(",");
76+
textFields.clear();
77+
}
78+
5979

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

6282
textFields += it->geometry()->wkt();
6383

64-
std::vector<QgsFeatureAttribute> attributes = it->attributeMap();
65-
6684
#ifdef QGISDEBUG
67-
std::cout << "QgsClipboard::replaceWithCopyOf: about to traverse fields." << std::endl;
85+
// std::cout << "QgsClipboard::replaceWithCopyOf: about to traverse fields." << std::endl;
6886
#endif
6987
for (std::vector<QgsFeatureAttribute>::iterator it2 = attributes.begin();
7088
it2 != attributes.end();
7189
++it2)
7290
{
7391
#ifdef QGISDEBUG
74-
std::cout << "QgsClipboard::replaceWithCopyOf: inspecting field '"
75-
<< (it2->fieldName()).toLocal8Bit().data()
76-
<< "'." << std::endl;
92+
// std::cout << "QgsClipboard::replaceWithCopyOf: inspecting field '"
93+
// << (it2->fieldName()).toLocal8Bit().data()
94+
// << "'." << std::endl;
7795
#endif
7896
textFields += it2->fieldValue();
7997
}
8098

8199
textLines += textFields.join(",");
100+
textFields.clear();
101+
102+
firstFeature = FALSE;
82103
}
83104

84105
QString textCopy = textLines.join("\n");
85106

86107
QClipboard *cb = QApplication::clipboard();
87108

88109
// Copy text into the clipboard
110+
111+
// With qgis running under Linux, but with a Windows based X
112+
// server (Xwin32), ::Selection was necessary to get the data into
113+
// the Windows clipboard (which seems contrary to the Qt
114+
// docs). With a Linux X server, ::Clipboard was required.
115+
// The simple solution was to put the text into both clipboards.
116+
117+
// The ::Selection setText() below one may need placing inside so
118+
// #ifdef so that it doesn't get compiled under Windows.
119+
cb->setText(textCopy, QClipboard::Selection);
89120
cb->setText(textCopy, QClipboard::Clipboard);
90121

91122
#ifdef QGISDEBUG

‎src/gui/qgsmaplayer.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,12 @@ class QgsMapLayer : public QObject
111111
{}
112112
;
113113

114-
/*! Display the attribute table for the layer
114+
//! Display the attribute table for the layer
115+
/**
116+
\param qgisApp This should be the QgisApp that spawned this table.
115117
*/
116-
virtual void table()
117-
{}
118-
;
118+
virtual void table(QgisApp * qgisApp)
119+
{};
119120

120121
/*! Return the extent of the layer as a QRect
121122
*/

‎src/gui/qgsvectorlayer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ void QgsVectorLayer::drawVertexMarker(int x, int y, QPainter& p)
967967
p.drawLine(x-m, y-m, x+m, y+m);
968968
}
969969

970-
void QgsVectorLayer::table()
970+
void QgsVectorLayer::table(QgisApp * qgisApp)
971971
{
972972
if (tabledisplay)
973973
{
@@ -980,7 +980,7 @@ void QgsVectorLayer::table()
980980
{
981981
// display the attribute table
982982
QApplication::setOverrideCursor(Qt::waitCursor);
983-
tabledisplay = new QgsAttributeTableDisplay(this);
983+
tabledisplay = new QgsAttributeTableDisplay(this, qgisApp);
984984
connect(tabledisplay, SIGNAL(deleted()), this, SLOT(invalidateTableDisplay()));
985985
tabledisplay->table()->fillTable(this);
986986
tabledisplay->table()->setSorting(true);

‎src/gui/qgsvectorlayer.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ class QgsVectorLayer : public QgsMapLayer
9595
void invertSelection();
9696

9797
//! Display the attribute table
98-
void table();
98+
/**
99+
\param qgisApp This should be the QgisApp that spawned this table.
100+
*/
101+
void table(QgisApp * qgisApp);
99102

100103
//! Set the primary display field to be used in the identify results dialog
101104
void setDisplayField(QString fldName=0);

0 commit comments

Comments
 (0)
Please sign in to comment.