Skip to content

Commit

Permalink
In the Attributes Table, the Copy button is now hooked up to the same…
Browse files Browse the repository at this point in the history
… 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/qgis@5584 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
morb_au committed Jul 11, 2006
1 parent 433b0ab commit 0ba6163
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 63 deletions.
71 changes: 35 additions & 36 deletions src/gui/qgisapp.cpp
Expand Up @@ -3211,7 +3211,7 @@ void QgisApp::attributeTable()
QgsMapLayer *layer = mMapLegend->currentLayer();
if (layer)
{
layer->table();
layer->table(this);
}
else
{
Expand Down Expand Up @@ -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();
}
}
}
}
}


Expand Down
27 changes: 21 additions & 6 deletions src/gui/qgisapp.h
Expand Up @@ -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
Expand Down Expand Up @@ -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) */
Expand Down
13 changes: 10 additions & 3 deletions src/gui/qgsattributetabledisplay.cpp
Expand Up @@ -19,6 +19,7 @@

#include "qgsattributetabledisplay.h"

#include "qgisapp.h"
#include "qgsapplication.h"
#include "qgsaddattrdialog.h"
#include "qgsdelattrdialog.h"
Expand All @@ -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();
Expand Down Expand Up @@ -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()
Expand Down
13 changes: 11 additions & 2 deletions src/gui/qgsattributetabledisplay.h
Expand Up @@ -25,6 +25,7 @@

class QgsAttributeTable;
class QgsVectorLayer;
class QgisApp;

/**
*@author Gary E.Sherman
Expand All @@ -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);
Expand Down
49 changes: 40 additions & 9 deletions src/gui/qgsclipboard.cpp
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions src/gui/qgsmaplayer.h
Expand Up @@ -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
*/
Expand Down
4 changes: 2 additions & 2 deletions src/gui/qgsvectorlayer.cpp
Expand Up @@ -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)
{
Expand All @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/gui/qgsvectorlayer.h
Expand Up @@ -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);
Expand Down

0 comments on commit 0ba6163

Please sign in to comment.