Skip to content
Permalink
Browse files
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
  • Loading branch information
morb_au committed Jul 11, 2006
1 parent af33fb9 commit 1a25348833027eceb238c516fdbbcdf7ff21d38c
@@ -3211,7 +3211,7 @@ void QgisApp::attributeTable()
QgsMapLayer *layer = mMapLegend->currentLayer();
if (layer)
{
layer->table();
layer->table(this);
}
else
{
@@ -3322,63 +3322,62 @@ void QgisApp::deleteVertex()
}


void QgisApp::editCut()
void QgisApp::editCut(QgsMapLayer * layerContainingSelection)
{
if (activeLayer())
QgsMapLayer * selectionLayer = (layerContainingSelection != 0) ?
(layerContainingSelection) :
(activeLayer());

if (selectionLayer)
{
// Test for feature support in this layer
QgsVectorLayer* activeVectorLayer = dynamic_cast<QgsVectorLayer*>(activeLayer());
QgsVectorLayer* selectionVectorLayer = dynamic_cast<QgsVectorLayer*>(selectionLayer);

if (activeVectorLayer != 0)
if (selectionVectorLayer != 0)
{

clipboard()->replaceWithCopyOf( *(activeVectorLayer->selectedFeatures()) );
activeVectorLayer->deleteSelectedFeatures();
}
}
clipboard()->replaceWithCopyOf( *(selectionVectorLayer->selectedFeatures()) );
selectionVectorLayer->deleteSelectedFeatures();
}
}
}


void QgisApp::editCopy()
void QgisApp::editCopy(QgsMapLayer * layerContainingSelection)
{
#ifdef QGISDEBUG
std::cerr << "QgisApp::editCopy: entered."
<< std::endl;
#endif
if (activeLayer())
QgsMapLayer * selectionLayer = (layerContainingSelection != 0) ?
(layerContainingSelection) :
(activeLayer());

if (selectionLayer)
{
#ifdef QGISDEBUG
std::cerr << "QgisApp::editCopy: has active layer, feature type " << activeLayer()->featureType() << "."
<< std::endl;
#endif
// Test for feature support in this layer
QgsVectorLayer* activeVectorLayer = dynamic_cast<QgsVectorLayer*>(activeLayer());
QgsVectorLayer* selectionVectorLayer = dynamic_cast<QgsVectorLayer*>(selectionLayer);

if (activeVectorLayer != 0)
if (selectionVectorLayer != 0)
{
#ifdef QGISDEBUG
std::cerr << "QgisApp::editCopy: has active vector layer."
<< std::endl;
#endif
clipboard()->replaceWithCopyOf( *(activeVectorLayer->selectedFeatures()) );
}
}
clipboard()->replaceWithCopyOf( *(selectionVectorLayer->selectedFeatures()) );
}
}
}


void QgisApp::editPaste()
void QgisApp::editPaste(QgsMapLayer * destinationLayer)
{
if (activeLayer())
QgsMapLayer * pasteLayer = (destinationLayer != 0) ?
(destinationLayer) :
(activeLayer());

if (pasteLayer)
{
// Test for feature support in this layer
QgsVectorLayer* activeVectorLayer = dynamic_cast<QgsVectorLayer*>(activeLayer());
QgsVectorLayer* pasteVectorLayer = dynamic_cast<QgsVectorLayer*>(pasteLayer);

if (activeVectorLayer != 0)
if (pasteVectorLayer != 0)
{
activeVectorLayer->addFeatures( clipboard()->copyOf() );
pasteVectorLayer->addFeatures( clipboard()->copyOf() );
mMapCanvas->refresh();
}
}
}
}
}


@@ -294,12 +294,7 @@ public slots:
void moveVertex();
//! activates the delete vertex tool
void deleteVertex();
//! cuts selected features on the active layer to the clipboard
void editCut();
//! copies selected features on the active layer to the clipboard
void editCopy();
//! copies features on the clipboard to the active layer
void editPaste();

//! activates the selection tool
void select();
//! refresh map canvas
@@ -346,6 +341,26 @@ public slots:
//! show the attribute table for the currently selected layer
void attributeTable();

//! cuts selected features on the active layer to the clipboard
/**
\param layerContainingSelection The layer that the selection will be taken from
(defaults to the active layer on the legend)
*/
void editCut(QgsMapLayer * layerContainingSelection = 0);
//! copies selected features on the active layer to the clipboard
/**
\param layerContainingSelection The layer that the selection will be taken from
(defaults to the active layer on the legend)
*/
void editCopy(QgsMapLayer * layerContainingSelection = 0);
//! copies features on the clipboard to the active layer
/**
\param destinationLayer The layer that the clipboard will be pasted to
(defaults to the active layer on the legend)
*/
void editPaste(QgsMapLayer * destinationLayer = 0);


signals:
/** emitted when a key is pressed and we want non widget sublasses to be able
to pick up on this (e.g. maplayer) */
@@ -19,6 +19,7 @@

#include "qgsattributetabledisplay.h"

#include "qgisapp.h"
#include "qgsapplication.h"
#include "qgsaddattrdialog.h"
#include "qgsdelattrdialog.h"
@@ -33,8 +34,10 @@
#include <QPixmap>
#include <QToolButton>

QgsAttributeTableDisplay::QgsAttributeTableDisplay(QgsVectorLayer* layer)
: QDialog(), mLayer(layer)
QgsAttributeTableDisplay::QgsAttributeTableDisplay(QgsVectorLayer* layer, QgisApp * qgisApp)
: QDialog(),
mLayer(layer),
mQgisApp(qgisApp)
{
setupUi(this);
setTheme();
@@ -225,7 +228,11 @@ void QgsAttributeTableDisplay::removeSelection()

void QgsAttributeTableDisplay::copySelectedRowsToClipboard()
{
table()->copySelectedRows();
// Deprecated
// table()->copySelectedRows();

// Use the Application's copy method instead
mQgisApp->editCopy(mLayer);
}

void QgsAttributeTableDisplay::search()
@@ -25,6 +25,7 @@

class QgsAttributeTable;
class QgsVectorLayer;
class QgisApp;

/**
*@author Gary E.Sherman
@@ -34,13 +35,21 @@ class QgsAttributeTableDisplay:public QDialog, private Ui::QgsAttributeTableBase
{
Q_OBJECT
public:
QgsAttributeTableDisplay(QgsVectorLayer* layer);
/**
\param qgisApp This should be the QgisApp that spawned this table.
Otherwise the Copy button on this QgsAttributeTableDisplay
will not work.
*/
QgsAttributeTableDisplay(QgsVectorLayer* layer, QgisApp * qgisApp);
~QgsAttributeTableDisplay();

QgsAttributeTable *table();
void setTitle(QString title);
protected:
QgsVectorLayer* mLayer;


QgisApp * mQgisApp;

void doSearch(const QString& searchString);

virtual void closeEvent(QCloseEvent* ev);
@@ -48,44 +48,75 @@ void QgsClipboard::replaceWithCopyOf( std::vector<QgsFeature> features )
#endif

// Replace the system clipboard.

QStringList textLines;

QStringList textFields;
bool firstFeature = TRUE;

// then the field contents
for (std::vector<QgsFeature>::iterator it = features.begin();
it != features.end();
++it)
{
QStringList textFields;
std::vector<QgsFeatureAttribute> attributes = it->attributeMap();

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

for (std::vector<QgsFeatureAttribute>::iterator it2 = attributes.begin();
it2 != attributes.end();
++it2)
{
textFields += it2->fieldName();
}

textLines += textFields.join(",");
textFields.clear();
}


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

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

std::vector<QgsFeatureAttribute> attributes = it->attributeMap();

#ifdef QGISDEBUG
std::cout << "QgsClipboard::replaceWithCopyOf: about to traverse fields." << std::endl;
// std::cout << "QgsClipboard::replaceWithCopyOf: about to traverse fields." << std::endl;
#endif
for (std::vector<QgsFeatureAttribute>::iterator it2 = attributes.begin();
it2 != attributes.end();
++it2)
{
#ifdef QGISDEBUG
std::cout << "QgsClipboard::replaceWithCopyOf: inspecting field '"
<< (it2->fieldName()).toLocal8Bit().data()
<< "'." << std::endl;
// std::cout << "QgsClipboard::replaceWithCopyOf: inspecting field '"
// << (it2->fieldName()).toLocal8Bit().data()
// << "'." << std::endl;
#endif
textFields += it2->fieldValue();
}

textLines += textFields.join(",");
textFields.clear();

firstFeature = FALSE;
}

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

QClipboard *cb = QApplication::clipboard();

// Copy text into the clipboard

// With qgis running under Linux, but with a Windows based X
// server (Xwin32), ::Selection was necessary to get the data into
// the Windows clipboard (which seems contrary to the Qt
// docs). With a Linux X server, ::Clipboard was required.
// The simple solution was to put the text into both clipboards.

// The ::Selection setText() below one may need placing inside so
// #ifdef so that it doesn't get compiled under Windows.
cb->setText(textCopy, QClipboard::Selection);
cb->setText(textCopy, QClipboard::Clipboard);

#ifdef QGISDEBUG
@@ -111,11 +111,12 @@ class QgsMapLayer : public QObject
{}
;

/*! Display the attribute table for the layer
//! Display the attribute table for the layer
/**
\param qgisApp This should be the QgisApp that spawned this table.
*/
virtual void table()
{}
;
virtual void table(QgisApp * qgisApp)
{};

/*! Return the extent of the layer as a QRect
*/
@@ -967,7 +967,7 @@ void QgsVectorLayer::drawVertexMarker(int x, int y, QPainter& p)
p.drawLine(x-m, y-m, x+m, y+m);
}

void QgsVectorLayer::table()
void QgsVectorLayer::table(QgisApp * qgisApp)
{
if (tabledisplay)
{
@@ -980,7 +980,7 @@ void QgsVectorLayer::table()
{
// display the attribute table
QApplication::setOverrideCursor(Qt::waitCursor);
tabledisplay = new QgsAttributeTableDisplay(this);
tabledisplay = new QgsAttributeTableDisplay(this, qgisApp);
connect(tabledisplay, SIGNAL(deleted()), this, SLOT(invalidateTableDisplay()));
tabledisplay->table()->fillTable(this);
tabledisplay->table()->setSorting(true);
@@ -95,7 +95,10 @@ class QgsVectorLayer : public QgsMapLayer
void invertSelection();

//! Display the attribute table
void table();
/**
\param qgisApp This should be the QgisApp that spawned this table.
*/
void table(QgisApp * qgisApp);

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

0 comments on commit 1a25348

Please sign in to comment.